Selaa lähdekoodia

fix: 封禁列表用户处理修复可能的userId重复而导致的分组异常;redis键采用新格式已减少无关子服务响应

hidewnd 2 viikkoa sitten
vanhempi
commit
55c03e5662

+ 38 - 22
yt-agent/agent-service/src/main/java/com/ytpm/service/impl/RiskServiceImpl.java

@@ -87,7 +87,8 @@ public class RiskServiceImpl implements RiskService {
      */
     @Override
     public Result<?> lockUser(AgentUserInfo curUser, String userId, String appId) {
-        redisService.setTimeOutStr("lock_"+userId,appId,1000);
+        String key = StrUtil.format("{}_lock_{}", appId, userId);
+        redisService.setTimeOutStr(key, appId, 1000);
         addBannedRecord(userId,curUser,appId,24,BannedTypeEnum.CHANNEL.getDesc()+"禁止登录");
         return Result.resultOk(RepMessage.LOCK_USER_SUCCESS);
     }
@@ -97,10 +98,12 @@ public class RiskServiceImpl implements RiskService {
      */
     @Override
     public Result<?> banned(RiskBannedParam param,AgentUserInfo curUser) {
-        redisService.setTimeOutStr("lock_"+param.getUserId(),param.getAppId(),1000);
-        addBannedRecord(param.getUserId(),curUser,param.getAppId(),param.getBannedLimit()*24,param.getBannedReason());
+        String key = StrUtil.format("{}_lock_{}", param.getAppId(), param.getUserId());
+        redisService.setTimeOutStr(key, param.getAppId(), 1000);
+        addBannedRecord(param.getUserId(), curUser, param.getAppId(), param.getBannedLimit() * 24, param.getBannedReason());
         //预设24小时过期key 用于解锁用户
-        redisService.setTimeOutHoursStr("unlock_"+param.getUserId(),param.getAppId(),param.getBannedLimit() * 24L);
+        key = StrUtil.format("{}_unlock__{}", param.getAppId(), param.getUserId());
+        redisService.setTimeOutHoursStr(key, param.getAppId(), param.getBannedLimit() * 24L);
         return Result.resultOk(RepMessage.ALREADY_RISK_USER);
     }
 
@@ -114,11 +117,15 @@ public class RiskServiceImpl implements RiskService {
             return Result.resultErr("请选择封禁用户");
         }
         String[] split = param.getUserIds().split(",");
+        String lockFormat = "{}_lock_{}";
+        String unlockFormat = "{}_unlock_{}";
         for (String userId : split) { // 为避免大量解锁的key再同一时间过期, 这里采用随机数
-            redisService.setTimeOutStr("lock_"+userId,param.getAppId(),RandomUtil.randomInt(500, 2000));
-            addBannedRecord(userId,curUser,param.getAppId(),param.getBannedLimit()*24, param.getBannedReason());
+            redisService.setTimeOutStr(StrUtil.format(lockFormat, param.getAppId(), userId),
+                    param.getAppId(), RandomUtil.randomInt(500, 2000));
+            addBannedRecord(userId, curUser, param.getAppId(), param.getBannedLimit() * 24, param.getBannedReason());
             //预设20-24小时过期key 用于解锁用户
-            redisService.setTimeOutHoursStr("unlock_"+userId,param.getAppId(),param.getBannedLimit() * RandomUtil.randomLong(20, 24));
+            redisService.setTimeOutHoursStr(StrUtil.format(unlockFormat, param.getAppId(), userId),
+                    param.getAppId(), param.getBannedLimit() * RandomUtil.randomLong(20, 24));
         }
         return Result.resultOk(RepMessage.ALREADY_RISK_USER);
     }
@@ -133,9 +140,12 @@ public class RiskServiceImpl implements RiskService {
         }
         String[] split = param.getUserIds().split(",");
         RiskUserStatusParam riskUserStatusParam;
+        String unlockFormat = "{}_unlock_{}";
+        String lockFormat = "{}_lock_{}";
         for (String userId : split) {
             //批量解封用户并增加解封记录
-            redisService.setTimeOutStr("unlock_"+userId,param.getAppId(),RandomUtil.randomInt(500, 2000));
+            redisService.setTimeOutStr(StrUtil.format(unlockFormat, param.getAppId(), userId),
+                    param.getAppId(),RandomUtil.randomInt(500, 2000));
             YtPlatformBanned lastBanned = riskMapper.getLastBanned(userId);
             riskUserStatusParam = new RiskUserStatusParam();
             riskUserStatusParam.setAgentId(curUser.getUserId());
@@ -144,7 +154,8 @@ public class RiskServiceImpl implements RiskService {
             riskUserStatusParam.setReason(param.getDeblockingReason());
             addDeblockingRecord(lastBanned,riskUserStatusParam);
             //查询用户id 在redis中是否存在未处理的 lock_ 清除掉
-            redisService.del("lock_"+userId);
+            redisService.del("lock_" + userId);
+            redisService.del(StrUtil.format(lockFormat, param.getAppId(), userId));
         }
         return Result.resultOk(RepMessage.PROCESS_SUCCESS);
     }
@@ -178,7 +189,7 @@ public class RiskServiceImpl implements RiskService {
             List<YtDyzUser> data = dealWithFeignData(issuedAppList,appUserParam);
             setBannedLoginInfo(bannedList,data);
         }
-        return ResultTable.resultTableOk(new PageInfo<RiskBannedListView>(bannedList));
+        return ResultTable.resultTableOk(new PageInfo<>(bannedList));
     }
 
     /**
@@ -290,7 +301,7 @@ public class RiskServiceImpl implements RiskService {
             }
             String oldValue = valueMap.get(listParam.getConfigId());
             if (!StrUtil.emptyIfNull(oldValue).equals(StrUtil.emptyIfNull(listParam.getConfigVal()))) {
-                YtRiskTemplateLog log = new  YtRiskTemplateLog();;
+                YtRiskTemplateLog log = new YtRiskTemplateLog();
                 log.setTemplateId(old.getTemplateId());
                 log.setTemplateCode(old.getTemplateCode());
                 log.setConfigId(listParam.getConfigId());
@@ -327,7 +338,7 @@ public class RiskServiceImpl implements RiskService {
             log.error(e.getMessage());
             throw new CustomerException(e.getMessage());
         }
-        return ResultTable.resultTableOk(new PageInfo<RiskConfigView>(configList));
+        return ResultTable.resultTableOk(new PageInfo<>(configList));
     }
 
     /**
@@ -385,7 +396,7 @@ public class RiskServiceImpl implements RiskService {
             log.error(e.getMessage());
             throw new CustomerException(e.getMessage());
         }
-        return ResultTable.resultTableOk(new PageInfo<RiskConfigView>(configList));
+        return ResultTable.resultTableOk(new PageInfo<>(configList));
     }
 
     /**
@@ -432,26 +443,28 @@ public class RiskServiceImpl implements RiskService {
         YtDyzUser appUser = new YtDyzUser();
         appUser.setUserId(param.getUserId());
         appUser.setUserStatus(param.getUserStatus());
+        String lockKey = StrUtil.format("{}_lock_{}", param.getAppId(), param.getUserId());
+        String unlockKey = StrUtil.format("{}_unlock_{}", param.getAppId(), param.getUserId());
         switch (param.getUserStatus()){
             case 2:
                 appUser.setRiskReason(param.getReason());
                 //1s锁定用户,并设置 24小时后进行解锁
-                redisService.setTimeOutStr("lock_"+userId,param.getAppId(),1000);
-                redisService.setTimeOutHoursStr("unlock_"+userId,param.getAppId(),24);
+                redisService.setTimeOutStr(lockKey, param.getAppId(), 1000);
+                redisService.setTimeOutHoursStr(unlockKey, param.getAppId(), 24);
                 break;
             case 3: //增加封禁记录
                 appUser.setRiskReason(param.getReason());
                 addBannedRecord(userId,curUser,param.getAppId(),param.getBannedLimit()*24, param.getReason());
                 //1s锁定用户,并设置 24小时后进行解锁
-                redisService.setTimeOutStr("lock_"+userId,param.getAppId(),1000);
-                redisService.setTimeOutHoursStr("unlock_"+userId,param.getAppId(),param.getBannedLimit()*24L);
+                redisService.setTimeOutStr(lockKey, param.getAppId(), 1000);
+                redisService.setTimeOutHoursStr(unlockKey, param.getAppId(), param.getBannedLimit() * 24L);
                 break;
             default: //解禁
                 YtPlatformBanned banned = riskMapper.getLastBanned(userId);
                 if(Objects.nonNull(banned)){
                     addDeblockingRecord(banned,param);
                 }
-                redisService.setTimeOutStr("unlock_"+userId,param.getAppId(),1000);
+                redisService.setTimeOutStr(unlockKey, param.getAppId(), 1000);
         }
     }
     /**
@@ -506,14 +519,17 @@ public class RiskServiceImpl implements RiskService {
             view.setUserStatus(dyzUser.getUserStatus());
         }
     }
+
     /**
      * 设置封禁用户信息
      */
-    private void setBannedLoginInfo(List<RiskBannedListView> bannedList,List<YtDyzUser> data) {
-        Map<String, YtDyzUser> collect = data.stream().collect(Collectors.toMap(YtDyzUser::getUserId, o->o));
+    private void setBannedLoginInfo(List<RiskBannedListView> bannedList, List<YtDyzUser> data) {
+        Map<String, YtDyzUser> collectMap = data.stream().collect(Collectors.toMap(
+                item-> StrUtil.format("{}_{}", item.getAppId(), item.getUserId()), o -> o));
         for (RiskBannedListView view : bannedList) {
-            if(!collect.containsKey(view.getUserId()))continue;
-            YtDyzUser dyzUser = collect.get(view.getUserId());
+            String key = StrUtil.format("{}_{}", view.getAppId(), view.getUserId());
+            if(!collectMap.containsKey(key))continue;
+            YtDyzUser dyzUser = collectMap.get(key);
             List<YtDyzLoginRecord> recordList = dyzUser.getLoginRecordList();
             if(CollUtil.isNotEmpty(recordList)){
                 view.setPhoneModel(recordList.get(0).getDeviceModel());

+ 6 - 4
yt-question/yt-question-service/src/main/java/com/ytpm/question/dao/AppUserMapper.java

@@ -15,7 +15,6 @@ import com.ytpm.middle.view.AppUserHourVO;
 import com.ytpm.middle.view.UserRankingListVO;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
-import org.springframework.beans.factory.annotation.Value;
 
 import java.math.BigDecimal;
 import java.util.Date;
@@ -118,9 +117,6 @@ public interface AppUserMapper {
      */
     void updateAppConfig(YtAppDefaultConfig defaultConfig);
 
-
-
-
     /**
      * 根据应用统计广告数
      */
@@ -211,8 +207,14 @@ public interface AppUserMapper {
      */
     YtDyzUser getByDeviceAndDitch(@Param("deviceId") String deviceId,@Param("ditchId")Long ditchId);
 
+    /**
+     * 查询用户平台ID
+     */
     String getPlatformByDeviceId(@Param("deviceId")String deviceId);
 
+    /**
+     * 更新用户统计信息:收益,视频播放数,
+     */
     void updateTotal(@Param("userId") String userId, @Param("videoCount") int videoCount, @Param("revenue") BigDecimal revenue);
 
     /**