|
@@ -2,6 +2,9 @@ package com.tzld.piaoquan.risk.control.service.impl;
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.tzld.piaoquan.risk.control.config.QywxConfig;
|
|
import com.tzld.piaoquan.risk.control.config.QywxConfig;
|
|
|
|
|
+import com.tzld.piaoquan.risk.control.dao.mapper.WorkWechatRoomInfoMapper;
|
|
|
|
|
+import com.tzld.piaoquan.risk.control.model.po.WorkWechatRoomInfo;
|
|
|
|
|
+import com.tzld.piaoquan.risk.control.model.po.WorkWechatRoomInfoExample;
|
|
|
import com.tzld.piaoquan.risk.control.model.qywx.RoomListResponse;
|
|
import com.tzld.piaoquan.risk.control.model.qywx.RoomListResponse;
|
|
|
import com.tzld.piaoquan.risk.control.model.qywx.UserListFromAdPlatformModel;
|
|
import com.tzld.piaoquan.risk.control.model.qywx.UserListFromAdPlatformModel;
|
|
|
import com.tzld.piaoquan.risk.control.util.HttpClientUtil;
|
|
import com.tzld.piaoquan.risk.control.util.HttpClientUtil;
|
|
@@ -21,18 +24,18 @@ public class RiskRuleConfigService {
|
|
|
private static final int USER_COUNT_THRESHOLD = 1; //生效人数阈值
|
|
private static final int USER_COUNT_THRESHOLD = 1; //生效人数阈值
|
|
|
private static final int USER_COUNT_THRESHOLD_FOR_ANOMALY_USER_RATIO = 30; //大于30人才触发是否关闭判断
|
|
private static final int USER_COUNT_THRESHOLD_FOR_ANOMALY_USER_RATIO = 30; //大于30人才触发是否关闭判断
|
|
|
private static final float ANOMALY_USER_RATIO = 0.2f; //异常用户比例20%
|
|
private static final float ANOMALY_USER_RATIO = 0.2f; //异常用户比例20%
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private WorkWechatRoomInfoMapper mapper;
|
|
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private QywxConfig config;
|
|
private QywxConfig config;
|
|
|
@Value("${qywx.corpid}")
|
|
@Value("${qywx.corpid}")
|
|
|
private long corpid;
|
|
private long corpid;
|
|
|
private static final HttpPoolClient httpPoolClientDefault = HttpClientUtil.create(10000, 10000, 2000, 5000, 5, 10000);
|
|
private static final HttpPoolClient httpPoolClientDefault = HttpClientUtil.create(10000, 10000, 2000, 5000, 5, 10000);
|
|
|
-
|
|
|
|
|
@Value("${getUserList.url:https://api.piaoquantv.com/ad/platform/wechat/group/groupUserDetailData}")
|
|
@Value("${getUserList.url:https://api.piaoquantv.com/ad/platform/wechat/group/groupUserDetailData}")
|
|
|
private String getUserList;
|
|
private String getUserList;
|
|
|
Map<String, List<RoomListResponse.RoomInfo>> getKickOpenedRoom(Map<String, List<RoomListResponse.RoomInfo>> tobeOperate) {
|
|
Map<String, List<RoomListResponse.RoomInfo>> getKickOpenedRoom(Map<String, List<RoomListResponse.RoomInfo>> tobeOperate) {
|
|
|
Map<String, List<RoomListResponse.RoomInfo>> filteredMap = new HashMap<>();
|
|
Map<String, List<RoomListResponse.RoomInfo>> filteredMap = new HashMap<>();
|
|
|
-
|
|
|
|
|
for (Map.Entry<String, List<RoomListResponse.RoomInfo>> entry : tobeOperate.entrySet()) {
|
|
for (Map.Entry<String, List<RoomListResponse.RoomInfo>> entry : tobeOperate.entrySet()) {
|
|
|
List<RoomListResponse.RoomInfo> filteredRooms = new ArrayList<>();
|
|
List<RoomListResponse.RoomInfo> filteredRooms = new ArrayList<>();
|
|
|
|
|
|
|
@@ -53,17 +56,31 @@ public class RiskRuleConfigService {
|
|
|
|
|
|
|
|
|
|
|
|
|
//防止误踢,只有满足存在五个正常群人数才会生效
|
|
//防止误踢,只有满足存在五个正常群人数才会生效
|
|
|
- public FixedRuleResult getFixedRulesForThisChat(String chatId) {
|
|
|
|
|
|
|
+ public FixedRuleResult getFixedRulesForThisChat(String chatId, String roomId) {
|
|
|
FixedRuleResult ruleResult = new FixedRuleResult();
|
|
FixedRuleResult ruleResult = new FixedRuleResult();
|
|
|
|
|
+ WorkWechatRoomInfoExample example = new WorkWechatRoomInfoExample();
|
|
|
|
|
+ example.createCriteria().andRoomIdEqualTo(roomId);
|
|
|
|
|
+ List<WorkWechatRoomInfo> examples = mapper.selectByExample(example);
|
|
|
|
|
+ if (examples == null || examples.isEmpty()) {
|
|
|
|
|
+ log.error("getFixedRulesForThisChat, no room found for roomId: {}", roomId);
|
|
|
|
|
+ return ruleResult;
|
|
|
|
|
+ }
|
|
|
|
|
+ WorkWechatRoomInfo roomInfo = examples.get(0);
|
|
|
|
|
+ long roomUpdateTime = roomInfo.getUpdateTime().getTime()/1000;
|
|
|
|
|
+ log.info("getFixedRulesForThisChat, roomId: {}, roomUpdateTime: {}", roomId, roomUpdateTime);
|
|
|
List<UserListFromAdPlatformModel.ChatMember> memberList = getUserListFromAdPlatform(chatId);
|
|
List<UserListFromAdPlatformModel.ChatMember> memberList = getUserListFromAdPlatform(chatId);
|
|
|
if (memberList == null || memberList.isEmpty()) {
|
|
if (memberList == null || memberList.isEmpty()) {
|
|
|
log.error("checkIfOpenedForFixedRules, memberList is empty for chatId: {}", chatId);
|
|
log.error("checkIfOpenedForFixedRules, memberList is empty for chatId: {}", chatId);
|
|
|
return ruleResult;
|
|
return ruleResult;
|
|
|
} else {
|
|
} else {
|
|
|
- int size = memberList.size();//群总数,包括异常和正常
|
|
|
|
|
- //memberList中isAbnormal是0代表正常用户
|
|
|
|
|
|
|
+ //开关开启后的加入的数量
|
|
|
|
|
+ int size = (int) memberList.stream()
|
|
|
|
|
+ .filter(member -> member.getJoinTime() != null && member.getJoinTime() > roomUpdateTime)
|
|
|
|
|
+ .count();;//群总数,包括异常和正常
|
|
|
|
|
+ //memberList中isAbnormal是0代表正常用户,判断joinTime是否大于updateTime
|
|
|
int normalSize = (int) memberList.stream()
|
|
int normalSize = (int) memberList.stream()
|
|
|
- .filter(member -> member.getIsAbnormal() == 0)
|
|
|
|
|
|
|
+ .filter(member -> member.getIsAbnormal() == 0).filter(
|
|
|
|
|
+ member -> member.getJoinTime() != null && member.getJoinTime() > roomUpdateTime)
|
|
|
.count();
|
|
.count();
|
|
|
ruleResult.normalCount = normalSize;
|
|
ruleResult.normalCount = normalSize;
|
|
|
ruleResult.abnormalCount = size - normalSize;
|
|
ruleResult.abnormalCount = size - normalSize;
|
|
@@ -88,9 +105,7 @@ public class RiskRuleConfigService {
|
|
|
log.info("checkIfOpenedForFixedRules, chatId: {}, size: {}, normalSize: {}, not enough normal users", chatId, size, normalSize);
|
|
log.info("checkIfOpenedForFixedRules, chatId: {}, size: {}, normalSize: {}, not enough normal users", chatId, size, normalSize);
|
|
|
return ruleResult;
|
|
return ruleResult;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|