Explorar o código

登录风控统计次数优化

marxjaw hai 4 meses
pai
achega
ce037fa8ba

+ 5 - 1
yt-app/app-service/src/main/java/com/ytpm/controller/WxController.java

@@ -108,7 +108,10 @@ public class WxController {
         setExtInfo(old,wxUserInfo.getHeadimgurl());
         //调用风控服务校验默认风控配置
         old.setRiskCode("313");
-        riskFeign.checkRisk(old);
+        Result<?> result = riskFeign.checkRisk(old);
+        if(result.getCode()!=200){
+            throw new CustomerException(result.getMessage());
+        }
         // 添加用户登录记录
         addLoginRecord(param,openid);
         return Result.resultOk(RepMessage.LOGIN_SUCCESS, old);
@@ -180,6 +183,7 @@ public class WxController {
         old.setTodayAnswerCount(questionMapper.getAnswerCount(old.getUserId(),1));
         old.setHistoryAnswerCount(questionMapper.getAnswerCount(old.getUserId(),2));
         old.setAnswerRecordList(questionMapper.getAnswerRecords(old.getUserId()));
+        old.setLoginRecordList(loginRecordMapper.getLoginRecords(old.getWxOpenId()));
     }
 
     /**

+ 15 - 16
yt-risk/risk-manage/src/main/java/com/ytpm/service/impl/RiskServiceImpl.java

@@ -424,21 +424,20 @@ public class RiskServiceImpl extends ReflectUtil implements RiskService {
         instance.add(Calendar.DATE, -Integer.parseInt(configMap.get("days")));
         Date yesterday = instance.getTime();
         //拿到同IP登录次数
-        long count = recordList.stream()
-                .peek(s->s.setLoginIp(s.getLoginIp().substring(0,Integer.parseInt(configMap.get("ipPrefix")))))
-                .filter(
-                s -> s.getLoginTime().after(yesterday) && s.getLoginTime().before(new Date())
-        ).count();
-        int intCount = Math.toIntExact(count);
+        List<YtDyzLoginRecord> dayLoginList = recordList.stream().filter(
+                s -> s.getLoginTime().after(yesterday) &&
+                        s.getLoginTime().before(new Date())).collect(Collectors.toList());
+        int intCount = 0;
+        if(!dayLoginList.isEmpty()){
+            for (YtDyzLoginRecord loginRecord : dayLoginList) {
+                loginRecord.setLoginIp(loginRecord.getLoginIp()
+                        .substring(0,Integer.parseInt(configMap.get("ipPrefix"))));
+            }
+            intCount = Math.toIntExact(dayLoginList.stream().map(YtDyzLoginRecord::getLoginIp).distinct().count());
+        }
         int ipSameCount = Integer.parseInt(configMap.get("ipSameCount"));
         if(intCount > ipSameCount){//校验同IP登录次数大于预设值,锁定用户
-            YtDyzUser newDyzUser = new YtDyzUser();
-            newDyzUser.setUserId(dyzUser.getUserId());
-            newDyzUser.setUserStatus(UserStatusEnum.LOCK.getCode());
-            newDyzUser.setRiskCode("313");
-            newDyzUser.setRiskReason("风控编码313");
-            appFeign.updateUserInfo(newDyzUser);
-            throw new CustomerException("当前用户已被风控!");
+            riskLockUser(dyzUser.getUserId(), "313","系统判定登录IP限制","当前用户已被风控!");
         }
     }
 
@@ -495,7 +494,7 @@ public class RiskServiceImpl extends ReflectUtil implements RiskService {
             //获取最先的两条
             BigDecimal reduce = revenues.stream().map(YtDyzAdRecord::getRevenue).reduce(BigDecimal.ZERO, BigDecimal::add);
             if(income.compareTo(reduce)<0){
-                riskLockUser(userId, "746","最低收益限制","用户已被风控,风控编码:746");
+                riskLockUser(userId, "746","系统判定小于最低收益限制","用户已被风控,风控编码:746");
             }
         }
     }
@@ -518,7 +517,7 @@ public class RiskServiceImpl extends ReflectUtil implements RiskService {
                     s -> (s.getEcpm().compareTo(BigDecimal.valueOf(haveCount))) > 0).count();
             int exact = Math.toIntExact(count);
             if(count>exact){
-                riskLockUser(userId, "742","激励视频ecpm值控制","用户已被风控,风控编码:742");
+                riskLockUser(userId, "742","系统判定激励视频ecpm值过低","用户已被风控,风控编码:742");
 
             }
         }
@@ -534,7 +533,7 @@ public class RiskServiceImpl extends ReflectUtil implements RiskService {
         next.setRiskCode(riskCode);
         next.setRiskReason(tempName);
         appFeign.updateUserInfo(next);
-        //TODO 创建一次性定时任务用于24小时候解锁用户
+        //创建一次性定时任务用于24小时后解锁用户
         ScheduledExecutorService scheduled  = Executors.newSingleThreadScheduledExecutor();
         scheduled.schedule(()->{
             YtDyzUser user = new YtDyzUser();

+ 1 - 1
yt-risk/risk-manage/src/main/resources/mapper/RiskConfigMapper.xml

@@ -195,7 +195,7 @@
         from yt_app_class
         where enabled = 1 and app_id = #{appId}
     </select>
-    <select id="getByCode" resultType="com.ytpm.risk.view.RiskTemplateView">
+    <select id="getByCode" resultMap="RiskTemplateViewMap">
         SELECT
             rt.template_id,
             rt.template_code,