فهرست منبع

预警规则-快手相关逻辑

zhaoxian 4 سال پیش
والد
کامیت
c139e0769e

+ 63 - 28
module-alarm/src/main/java/cn/com/ctop/alarm/modules/constant/MatchLogic.java

@@ -65,7 +65,6 @@ public class MatchLogic {
                 }
                 }
             } else if ("string".equals(type)) {
             } else if ("string".equals(type)) {
                 if (threshold.contains("[")) {
                 if (threshold.contains("[")) {
-                    boolean flag = false;
                     List<String> thresholds = strToList(threshold);
                     List<String> thresholds = strToList(threshold);
                     if ("equal".equals(condition)) {
                     if ("equal".equals(condition)) {
                         return value.equals(thresholds.get(0));
                         return value.equals(thresholds.get(0));
@@ -83,7 +82,6 @@ public class MatchLogic {
                             }
                             }
                         }
                         }
                     }
                     }
-                    return flag;
                 } else {
                 } else {
                     switch (condition) {
                     switch (condition) {
                         case "equal":
                         case "equal":
@@ -96,52 +94,48 @@ public class MatchLogic {
                             return !value.contains(threshold);
                             return !value.contains(threshold);
                         default:
                         default:
                             log.warn("关系不匹配 type={},condition={},threshold={},value={},", type, condition, threshold, value);
                             log.warn("关系不匹配 type={},condition={},threshold={},value={},", type, condition, threshold, value);
-                            break;
+                            return false;
                     }
                     }
                 }
                 }
             } else {
             } else {
-                String logicalType = indicator.getString("logicalType");
-                if (NoEn.NO1.valueStr().equals(logicalType)) {
-                    if (value.contains("[") && threshold.contains("[")) {
-                        List<String> values = strToList(value);
-                        List<String> thresholds = strToList(threshold);
-                        if (values.size() != thresholds.size()) {
-                            return true;
-                        }
+                if (value.contains("[") && threshold.contains("[")) {
+                    List<String> values = strToList(value);
+                    List<String> thresholds = strToList(threshold);
+                    //包含 任一存在则报警
+                    if ("contain".equals(condition)) {
                         for (String v : values) {
                         for (String v : values) {
-                            if (!threshold.contains(v)) {
+                            if (threshold.contains(v)) {
                                 return true;
                                 return true;
                             }
                             }
                         }
                         }
                     } else {
                     } else {
-                        if ("contain".equals(condition)) {
-                            return threshold.contains(value);
-                        } else {
-                            return !threshold.contains(value);
-                        }
-                    }
-                } else {
-                    if (value.contains("[") && threshold.contains("[")) {
-                        List<String> values = strToList(value);
-                        if ("contain".equals(condition)) {
+                        String logicalType = indicator.getString("logicalType");
+                        //排除人群包、流量排除包逻辑
+                        if (NoEn.NO1.valueStr().equals(logicalType)) {
+                            //不包含,所选必须都存在,否则报警
+                            if (values.size() != thresholds.size()) {
+                                return true;
+                            }
                             for (String v : values) {
                             for (String v : values) {
                                 if (!threshold.contains(v)) {
                                 if (!threshold.contains(v)) {
                                     return true;
                                     return true;
                                 }
                                 }
                             }
                             }
                         } else {
                         } else {
+                            //不包含,任一存在不报警,都不存在则报警
                             for (String v : values) {
                             for (String v : values) {
                                 if (threshold.contains(v)) {
                                 if (threshold.contains(v)) {
-                                    return true;
+                                    return false;
                                 }
                                 }
                             }
                             }
+                            return true;
                         }
                         }
+                    }
+                } else {
+                    if ("contain".equals(condition)) {
+                        return threshold.contains(value);
                     } else {
                     } else {
-                        if ("contain".equals(condition)) {
-                            return threshold.contains(value);
-                        } else {
-                            return !threshold.contains(value);
-                        }
+                        return !threshold.contains(value);
                     }
                     }
                 }
                 }
             }
             }
@@ -276,4 +270,45 @@ public class MatchLogic {
         }
         }
         return sendData;
         return sendData;
     }
     }
+
+    /**
+     * 快手匹配达标数据
+     *
+     * @param
+     * @return com.alibaba.fastjson.JSONArray
+     * @throws
+     * @author ZHAOXA
+     */
+    public static JSONArray getKuaiShouSendData(JSONArray accountDatas, JSONArray groupDatas, JSONArray planDatas, JSONArray creativeDatas, JSONArray targetDatas) {
+        JSONArray sendData = new JSONArray();
+        if (!Check.isNull(accountDatas) && Check.isNull(groupDatas) && Check.isNull(planDatas) && Check.isNull(creativeDatas) && Check.isNull(targetDatas)) {
+            sendData = accountDatas;
+        } else {
+            if (Check.isNull(groupDatas)) {
+                if (!Check.isNull(planDatas) && Check.isNull(creativeDatas) && Check.isNull(targetDatas)) {
+                    sendData = planDatas;
+                } else if (Check.isNull(planDatas) && !Check.isNull(creativeDatas) && Check.isNull(targetDatas)) {
+                    sendData = creativeDatas;
+                } else if (Check.isNull(planDatas) && Check.isNull(creativeDatas) && !Check.isNull(targetDatas)) {
+                    sendData = targetDatas;
+                }
+            } else {
+                if (Check.isNull(planDatas) && Check.isNull(creativeDatas) && Check.isNull(targetDatas)) {
+                    sendData = groupDatas;
+                } else if (!Check.isNull(targetDatas)) {
+                    for (int i = 0; i < groupDatas.size(); i++) {
+                        Long gGroupId = groupDatas.getJSONObject(i).getLong("groupId");
+                        for (int k = 0; k < targetDatas.size(); k++) {
+                            Long tgGroupId = targetDatas.getJSONObject(k).getLong("groupId");
+                            if (tgGroupId == gGroupId) {
+                                sendData.add(creativeDatas.getJSONObject(k));
+                            }
+                        }
+                    }
+                }
+            }
+        }
+        return sendData;
+    }
+
 }
 }

+ 107 - 78
module-alarm/src/main/java/cn/com/ctop/alarm/modules/service/impl/RuleGroupServiceImpl.java

@@ -80,8 +80,6 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
     @Autowired
     @Autowired
     private IKuaiShouUpdateService kuaiShouUpdateService;
     private IKuaiShouUpdateService kuaiShouUpdateService;
     @Autowired
     @Autowired
-    private ICtopOauthTokenService oauthTokenService;
-    @Autowired
     private IRuleDataAccountService ruleDataAccountService;
     private IRuleDataAccountService ruleDataAccountService;
     @Autowired
     @Autowired
     private AlarmEventSendMapper alarmEventSendMapper;
     private AlarmEventSendMapper alarmEventSendMapper;
@@ -92,7 +90,7 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
     @Autowired
     @Autowired
     private IByteDanceCreativeService byteDanceCreativeService;
     private IByteDanceCreativeService byteDanceCreativeService;
     @Autowired
     @Autowired
-    private ICtopOauthTokenService ctopOauthTokenService;
+    private ICtopOauthTokenService tokenService;
 
 
     private JSONObject userObj = null;
     private JSONObject userObj = null;
     private final static String ACCOUNT = "account";
     private final static String ACCOUNT = "account";
@@ -140,16 +138,21 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
      */
      */
     private void matchAlarmRules(Map<Long, Object> ruleGroupMap, JSONObject indicators, RuleAccountTemplate templates) {
     private void matchAlarmRules(Map<Long, Object> ruleGroupMap, JSONObject indicators, RuleAccountTemplate templates) {
         userObj = new JSONObject();
         userObj = new JSONObject();
-        //查询匹配数据
-        JSONObject matchData = getRuleData(templates.getAccountId());
-        if (Check.isNull(matchData)) {
-            log.warn("查询匹配数据失败");
-            return;
-        }
         boolean isCopy = false;
         boolean isCopy = false;
         Map<Long, Object> map = (Map<Long, Object>) ruleGroupMap.get(templates.getTemplateId());
         Map<Long, Object> map = (Map<Long, Object>) ruleGroupMap.get(templates.getTemplateId());
-        //媒体类型 1:头条2:快手
         Integer type = (Integer) map.get("type");
         Integer type = (Integer) map.get("type");
+        JSONObject matchData = null;
+        //媒体类型 1:头条2:快手
+        if (NoEn.NO1.valueInt() == type || NoEn.NO3.valueInt() == type) {
+            //查询抖音匹配数据
+            matchData = getRuleData(templates.getAccountId());
+        } else {
+            //TODO 获取快手数据
+        }
+        if (Check.isNull(matchData)) {
+            log.warn("获取匹配数据失败");
+            return;
+        }
         //常规规则+阈值
         //常规规则+阈值
         List<RuleGroup> notCopyGroups = (List<RuleGroup>) map.get("notCopy");
         List<RuleGroup> notCopyGroups = (List<RuleGroup>) map.get("notCopy");
         JSONObject notCopythreshold = getThreshold(templates.getAccountId(), isCopy);
         JSONObject notCopythreshold = getThreshold(templates.getAccountId(), isCopy);
@@ -205,14 +208,14 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
                 for (Map.Entry<String, Object> entry : batchNo.entrySet()) {
                 for (Map.Entry<String, Object> entry : batchNo.entrySet()) {
                     JSONObject thresholdJn = (JSONObject) entry.getValue();
                     JSONObject thresholdJn = (JSONObject) entry.getValue();
                     if (!Check.isNull(thresholdJn)) {
                     if (!Check.isNull(thresholdJn)) {
-                        CombinationRule(ruleBaseList, thresholdJn, indicators, matchData, complianceList);
+                        CombinationRule(ruleBaseList, thresholdJn, indicators, matchData, complianceList, type);
                     }
                     }
                 }
                 }
             } else {
             } else {
                 boolean isGroup = "group".equals(ruleGroup.getRuleType());
                 boolean isGroup = "group".equals(ruleGroup.getRuleType());
                 //匹配组合规则
                 //匹配组合规则
                 if (isGroup) {
                 if (isGroup) {
-                    CombinationRule(ruleBaseList, thresholdObj, indicators, matchData, complianceList);
+                    CombinationRule(ruleBaseList, thresholdObj, indicators, matchData, complianceList, type);
                     //匹配单规则
                     //匹配单规则
                 } else {
                 } else {
                     RuleBase ruleBase = ruleBaseList.get(0);
                     RuleBase ruleBase = ruleBaseList.get(0);
@@ -241,7 +244,7 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
                 }
                 }
             }
             }
             if (!Check.isNull(complianceList)) {
             if (!Check.isNull(complianceList)) {
-                getAndSendMessag(complianceList, ruleGroup, accountName);
+                getAndSendMessag(complianceList, ruleGroup, accountName, type);
             }
             }
         }
         }
     }
     }
@@ -260,8 +263,9 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
      * @throws
      * @throws
      * @author ZHAOXA
      * @author ZHAOXA
      */
      */
-    private void CombinationRule(List<RuleBase> ruleBaseList, JSONObject thresholdObj, JSONObject indicators, JSONObject matchData, JSONArray complianceList) {
+    private void CombinationRule(List<RuleBase> ruleBaseList, JSONObject thresholdObj, JSONObject indicators, JSONObject matchData, JSONArray complianceList, Integer type) {
         //符合规则的数据集
         //符合规则的数据集
+        JSONArray groupDatas = new JSONArray();
         JSONArray targetDatas = new JSONArray();
         JSONArray targetDatas = new JSONArray();
         JSONArray planDatas = new JSONArray();
         JSONArray planDatas = new JSONArray();
         JSONArray creativeDatas = new JSONArray();
         JSONArray creativeDatas = new JSONArray();
@@ -272,7 +276,7 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
             //指标阈值
             //指标阈值
             String threshold = thresholdObj.getString(ruleBase.getId().toString());
             String threshold = thresholdObj.getString(ruleBase.getId().toString());
             //阈值为空时,或者阈值为“unlimited”(不限),不执行该规则
             //阈值为空时,或者阈值为“unlimited”(不限),不执行该规则
-            if (Check.isNull(threshold) || "unlimited".equals(threshold)) {
+            if (Check.isNull(threshold) || threshold.contains("unlimited")) {
                 if (!Check.isNull(accountDatas)) {
                 if (!Check.isNull(accountDatas)) {
                     accountDatas = null;
                     accountDatas = null;
                 }
                 }
@@ -285,6 +289,9 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
                 if (!Check.isNull(targetDatas)) {
                 if (!Check.isNull(targetDatas)) {
                     targetDatas = null;
                     targetDatas = null;
                 }
                 }
+                if (!Check.isNull(groupDatas)) {
+                    groupDatas = null;
+                }
                 break;
                 break;
             }
             }
             JSONArray dimensionData = matchData.getJSONArray(ruleBase.getRuleDimension());
             JSONArray dimensionData = matchData.getJSONArray(ruleBase.getRuleDimension());
@@ -301,6 +308,9 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
                 if (!Check.isNull(targetDatas)) {
                 if (!Check.isNull(targetDatas)) {
                     targetDatas = null;
                     targetDatas = null;
                 }
                 }
+                if (!Check.isNull(groupDatas)) {
+                    groupDatas = null;
+                }
                 break;
                 break;
             }
             }
             //账户维度数据
             //账户维度数据
@@ -323,6 +333,9 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
                     if (!Check.isNull(targetDatas)) {
                     if (!Check.isNull(targetDatas)) {
                         targetDatas = null;
                         targetDatas = null;
                     }
                     }
+                    if (!Check.isNull(groupDatas)) {
+                        groupDatas = null;
+                    }
                     break;
                     break;
                 }
                 }
             } else if (PLAN.equals(ruleBase.getRuleDimension())) {
             } else if (PLAN.equals(ruleBase.getRuleDimension())) {
@@ -340,6 +353,9 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
                     if (!Check.isNull(targetDatas)) {
                     if (!Check.isNull(targetDatas)) {
                         targetDatas = null;
                         targetDatas = null;
                     }
                     }
+                    if (!Check.isNull(groupDatas)) {
+                        groupDatas = null;
+                    }
                     break;
                     break;
                 }
                 }
             } else if (CREATIVE.equals(ruleBase.getRuleDimension())) {
             } else if (CREATIVE.equals(ruleBase.getRuleDimension())) {
@@ -357,6 +373,9 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
                     if (!Check.isNull(targetDatas)) {
                     if (!Check.isNull(targetDatas)) {
                         targetDatas = null;
                         targetDatas = null;
                     }
                     }
+                    if (!Check.isNull(groupDatas)) {
+                        groupDatas = null;
+                    }
                     break;
                     break;
                 }
                 }
             } else if ("target".equals(ruleBase.getRuleDimension())) {
             } else if ("target".equals(ruleBase.getRuleDimension())) {
@@ -374,12 +393,40 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
                     if (!Check.isNull(targetDatas)) {
                     if (!Check.isNull(targetDatas)) {
                         targetDatas = null;
                         targetDatas = null;
                     }
                     }
+                    if (!Check.isNull(groupDatas)) {
+                        groupDatas = null;
+                    }
+                    break;
+                }
+            } else if ("group".equals(ruleBase.getRuleDimension())) {
+                groupDatas = getOKData(groupDatas, dimensionData, ruleBase, indicator, threshold);
+                if (Check.isNull(targetDatas)) {
+                    if (!Check.isNull(accountDatas)) {
+                        accountDatas = null;
+                    }
+                    if (!Check.isNull(planDatas)) {
+                        planDatas = null;
+                    }
+                    if (!Check.isNull(creativeDatas)) {
+                        creativeDatas = null;
+                    }
+                    if (!Check.isNull(targetDatas)) {
+                        targetDatas = null;
+                    }
+                    if (!Check.isNull(groupDatas)) {
+                        groupDatas = null;
+                    }
                     break;
                     break;
                 }
                 }
             }
             }
         }
         }
         //获取达标可发送的数据
         //获取达标可发送的数据
-        JSONArray sendData = MatchLogic.getSendData(accountDatas, planDatas, creativeDatas, targetDatas);
+        JSONArray sendData = null;
+        if (NoEn.NO1.valueInt() == type || NoEn.NO3.valueInt() == type) {
+            sendData = MatchLogic.getSendData(accountDatas, planDatas, creativeDatas, targetDatas);
+        } else {
+            sendData = MatchLogic.getKuaiShouSendData(accountDatas, groupDatas, planDatas, creativeDatas, targetDatas);
+        }
         if (!Check.isNull(sendData)) {
         if (!Check.isNull(sendData)) {
             complianceList.addAll(sendData);
             complianceList.addAll(sendData);
         }
         }
@@ -417,7 +464,7 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
         return ruleDatas;
         return ruleDatas;
     }
     }
 
 
-    private void getAndSendMessag(JSONArray complianceList, RuleGroup ruleGroup, String accountName) {
+    private void getAndSendMessag(JSONArray complianceList, RuleGroup ruleGroup, String accountName, Integer mediaType) {
         Long accountId = complianceList.getJSONObject(0).getLong("accountId");
         Long accountId = complianceList.getJSONObject(0).getLong("accountId");
         if (Check.isNull(accountId)) {
         if (Check.isNull(accountId)) {
             return;
             return;
@@ -437,7 +484,7 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
                         isNullCreativeJoiner.add(obj.getString("creativeId"));
                         isNullCreativeJoiner.add(obj.getString("creativeId"));
                     } else {
                     } else {
                         String message = MatchLogic.getMessage(ruleGroup.getGroupName(), accountId, accountName, CREATIVE, isNullCreativeJoiner.toString(), isNull);
                         String message = MatchLogic.getMessage(ruleGroup.getGroupName(), accountId, accountName, CREATIVE, isNullCreativeJoiner.toString(), isNull);
-                        sendMsg(message, ruleGroup, user, CREATIVE, isNullCreativeJoiner.toString(), accountId);
+                        sendMsg(message, ruleGroup, user, CREATIVE, isNullCreativeJoiner.toString(), accountId, mediaType);
                         isNullCreativeJoiner = new StringJoiner(",");
                         isNullCreativeJoiner = new StringJoiner(",");
                         isNullCreativeJoiner.add(obj.getString("creativeId"));
                         isNullCreativeJoiner.add(obj.getString("creativeId"));
                     }
                     }
@@ -446,13 +493,13 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
                         isNullPlanJoiner.add(obj.getString("planId"));
                         isNullPlanJoiner.add(obj.getString("planId"));
                     } else {
                     } else {
                         String msg = MatchLogic.getMessage(ruleGroup.getGroupName(), accountId, accountName, PLAN, isNullPlanJoiner.toString(), isNull);
                         String msg = MatchLogic.getMessage(ruleGroup.getGroupName(), accountId, accountName, PLAN, isNullPlanJoiner.toString(), isNull);
-                        sendMsg(msg, ruleGroup, user, PLAN, isNullPlanJoiner.toString(), accountId);
+                        sendMsg(msg, ruleGroup, user, PLAN, isNullPlanJoiner.toString(), accountId, mediaType);
                         isNullPlanJoiner = new StringJoiner(",");
                         isNullPlanJoiner = new StringJoiner(",");
                         isNullPlanJoiner.add(obj.getString("planId"));
                         isNullPlanJoiner.add(obj.getString("planId"));
                     }
                     }
                 } else {
                 } else {
                     String msg = MatchLogic.getMessage(ruleGroup.getGroupName(), accountId, accountName, null, null, isNull);
                     String msg = MatchLogic.getMessage(ruleGroup.getGroupName(), accountId, accountName, null, null, isNull);
-                    sendMsg(msg, ruleGroup, user, ACCOUNT, null, accountId);
+                    sendMsg(msg, ruleGroup, user, ACCOUNT, null, accountId, mediaType);
                 }
                 }
             } else {
             } else {
                 if (!Check.isNull(obj.getString("creativeId"))) {
                 if (!Check.isNull(obj.getString("creativeId"))) {
@@ -461,7 +508,7 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
                         creativeJoiner.add(obj.getString("creativeId"));
                         creativeJoiner.add(obj.getString("creativeId"));
                     } else {
                     } else {
                         String message = MatchLogic.getMessage(ruleGroup.getGroupName(), accountId, accountName, CREATIVE, creativeJoiner.toString(), isNull);
                         String message = MatchLogic.getMessage(ruleGroup.getGroupName(), accountId, accountName, CREATIVE, creativeJoiner.toString(), isNull);
-                        sendMsg(message, ruleGroup, user, CREATIVE, creativeJoiner.toString(), accountId);
+                        sendMsg(message, ruleGroup, user, CREATIVE, creativeJoiner.toString(), accountId, mediaType);
                         creativeJoiner = new StringJoiner(",");
                         creativeJoiner = new StringJoiner(",");
                         creativeJoiner.add(obj.getString("creativeId"));
                         creativeJoiner.add(obj.getString("creativeId"));
                     }
                     }
@@ -470,31 +517,31 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
                         planJoiner.add(obj.getString("planId"));
                         planJoiner.add(obj.getString("planId"));
                     } else {
                     } else {
                         String msg = MatchLogic.getMessage(ruleGroup.getGroupName(), accountId, accountName, PLAN, planJoiner.toString(), isNull);
                         String msg = MatchLogic.getMessage(ruleGroup.getGroupName(), accountId, accountName, PLAN, planJoiner.toString(), isNull);
-                        sendMsg(msg, ruleGroup, user, PLAN, planJoiner.toString(), accountId);
+                        sendMsg(msg, ruleGroup, user, PLAN, planJoiner.toString(), accountId, mediaType);
                         planJoiner = new StringJoiner(",");
                         planJoiner = new StringJoiner(",");
                         planJoiner.add(obj.getString("planId"));
                         planJoiner.add(obj.getString("planId"));
                     }
                     }
                 } else {
                 } else {
                     String msg = MatchLogic.getMessage(ruleGroup.getGroupName(), accountId, accountName, null, null, isNull);
                     String msg = MatchLogic.getMessage(ruleGroup.getGroupName(), accountId, accountName, null, null, isNull);
-                    sendMsg(msg, ruleGroup, user, ACCOUNT, null, accountId);
+                    sendMsg(msg, ruleGroup, user, ACCOUNT, null, accountId, mediaType);
                 }
                 }
             }
             }
         }
         }
         if (!Check.isNull(creativeJoiner.toString())) {
         if (!Check.isNull(creativeJoiner.toString())) {
             String creativeMsg = MatchLogic.getMessage(ruleGroup.getGroupName(), accountId, accountName, CREATIVE, creativeJoiner.toString(), false);
             String creativeMsg = MatchLogic.getMessage(ruleGroup.getGroupName(), accountId, accountName, CREATIVE, creativeJoiner.toString(), false);
-            sendMsg(creativeMsg, ruleGroup, user, CREATIVE, creativeJoiner.toString(), accountId);
+            sendMsg(creativeMsg, ruleGroup, user, CREATIVE, creativeJoiner.toString(), accountId, mediaType);
         }
         }
         if (!Check.isNull(planJoiner.toString())) {
         if (!Check.isNull(planJoiner.toString())) {
             String planMsg = MatchLogic.getMessage(ruleGroup.getGroupName(), accountId, accountName, PLAN, planJoiner.toString(), false);
             String planMsg = MatchLogic.getMessage(ruleGroup.getGroupName(), accountId, accountName, PLAN, planJoiner.toString(), false);
-            sendMsg(planMsg, ruleGroup, user, PLAN, planJoiner.toString(), accountId);
+            sendMsg(planMsg, ruleGroup, user, PLAN, planJoiner.toString(), accountId, mediaType);
         }
         }
         if (!Check.isNull(isNullCreativeJoiner.toString())) {
         if (!Check.isNull(isNullCreativeJoiner.toString())) {
             String isNullCreativeMsg = MatchLogic.getMessage(ruleGroup.getGroupName(), accountId, accountName, CREATIVE, isNullCreativeJoiner.toString(), true);
             String isNullCreativeMsg = MatchLogic.getMessage(ruleGroup.getGroupName(), accountId, accountName, CREATIVE, isNullCreativeJoiner.toString(), true);
-            sendMsg(isNullCreativeMsg, ruleGroup, user, CREATIVE, isNullCreativeJoiner.toString(), accountId);
+            sendMsg(isNullCreativeMsg, ruleGroup, user, CREATIVE, isNullCreativeJoiner.toString(), accountId, mediaType);
         }
         }
         if (!Check.isNull(isNullPlanJoiner.toString())) {
         if (!Check.isNull(isNullPlanJoiner.toString())) {
             String isNullPlanMsg = MatchLogic.getMessage(ruleGroup.getGroupName(), accountId, accountName, PLAN, isNullPlanJoiner.toString(), true);
             String isNullPlanMsg = MatchLogic.getMessage(ruleGroup.getGroupName(), accountId, accountName, PLAN, isNullPlanJoiner.toString(), true);
-            sendMsg(isNullPlanMsg, ruleGroup, user, PLAN, isNullPlanJoiner.toString(), accountId);
+            sendMsg(isNullPlanMsg, ruleGroup, user, PLAN, isNullPlanJoiner.toString(), accountId, mediaType);
         }
         }
     }
     }
 
 
@@ -509,22 +556,24 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
      * @throws
      * @throws
      * @author ZHAOXA
      * @author ZHAOXA
      */
      */
-    private void sendMsg(String msg, RuleGroup ruleGroup, JSONObject user, String type, String ids, Long accountId) {
+    private void sendMsg(String msg, RuleGroup ruleGroup, JSONObject user, String type, String ids, Long accountId, Integer mediaType) {
         try {
         try {
             boolean isPause = "PAUSE".equals(ruleGroup.getOperate());
             boolean isPause = "PAUSE".equals(ruleGroup.getOperate());
             if (isPause) {
             if (isPause) {
                 //type 1:头条2:快手
                 //type 1:头条2:快手
-                if (NoEn.NO1.valueStr().equals(type)) {
-                    isPause = touTiaoshutDown(accountId, ids, type);
+                if (NoEn.NO1.valueInt() == mediaType || NoEn.NO3.valueInt() == mediaType) {
+                    msg = touTiaoshutDown(accountId, ids, type, msg);
                 } else {
                 } else {
                     msg = kuaiShoushutDown(accountId, ids, type, user.getString("id"), msg);
                     msg = kuaiShoushutDown(accountId, ids, type, user.getString("id"), msg);
-                    if (msg.getBytes().length >= 2048) {
-                        msg = msg.replace(",", ",");
-                    }
                 }
                 }
-            }
-            if (isPause) {
-                msg += "现已被关停,请您及时查看并调整!";
+                if (msg.getBytes().length >= 2000) {
+                    msg = msg.replace(",", ",");
+                }
+                if (ACCOUNT.equals(type)) {
+                    msg += "请您及时查看并调整!";
+                } else {
+                    msg += "现已被关停,请您及时查看并调整!";
+                }
             } else {
             } else {
                 msg += "请您及时查看并调整!";
                 msg += "请您及时查看并调整!";
             }
             }
@@ -538,13 +587,13 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
             } else if ("TEL".equals(sendType)) {
             } else if ("TEL".equals(sendType)) {
 
 
             } else {
             } else {
-//                sendMessageService.sendMessage("1b3deb8258e84df994f1371a51cfc14a", msg);
-                sendMessageService.sendMessage(user.getString("id"), msg);
+                sendMessageService.sendMessage("1b3deb8258e84df994f1371a51cfc14a", msg);
+//                sendMessageService.sendMessage(user.getString("id"), msg);
                 Thread.sleep(200);
                 Thread.sleep(200);
             }
             }
             if (!Check.isNull(msg)) {
             if (!Check.isNull(msg)) {
                 AlarmEventSend send = new AlarmEventSend();
                 AlarmEventSend send = new AlarmEventSend();
-                send.setUserId(user.getString("id"));
+                send.setUserId(user.getString("realname").concat("_").concat(user.getString("id")));
                 send.setAlarmDetail(msg.replace("<br/>", ","));
                 send.setAlarmDetail(msg.replace("<br/>", ","));
                 send.setAlarmStatus(NoEn.NO1.valueStr());
                 send.setAlarmStatus(NoEn.NO1.valueStr());
                 send.setGroupId(ruleGroup.getId());
                 send.setGroupId(ruleGroup.getId());
@@ -591,7 +640,7 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
      * @author ZHAOXA
      * @author ZHAOXA
      */
      */
     private String kuaiShoushutDown(Long accountId, String ids, String type, String userId, String msg) {
     private String kuaiShoushutDown(Long accountId, String ids, String type, String userId, String msg) {
-        CtopOauthToken token = oauthTokenService.getTokenByAccountId(accountId);
+        CtopOauthToken token = tokenService.getTokenByAccountId(accountId);
         Map<String, Object> updateMap = new HashMap<>();
         Map<String, Object> updateMap = new HashMap<>();
         if (!Check.isNull(token) && !Check.isNull(ids)) {
         if (!Check.isNull(token) && !Check.isNull(ids)) {
             String[] idSplit = ids.split(",");
             String[] idSplit = ids.split(",");
@@ -601,7 +650,7 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
                     if (!(boolean) updateMap.get("success")) {
                     if (!(boolean) updateMap.get("success")) {
                         msg = msg.replace(id, id + "(F)");
                         msg = msg.replace(id, id + "(F)");
                     }
                     }
-                } else {
+                } else if (PLAN.equals(type)) {
                     updateMap = kuaiShouUpdateService.updateCampaignStatus(token.getAccessToken(), accountId, Long.valueOf(id), NoEn.NO2.valueInt(), userId);
                     updateMap = kuaiShouUpdateService.updateCampaignStatus(token.getAccessToken(), accountId, Long.valueOf(id), NoEn.NO2.valueInt(), userId);
                     if (!(boolean) updateMap.get("success")) {
                     if (!(boolean) updateMap.get("success")) {
                         msg = msg.replace(id, id + "(F)");
                         msg = msg.replace(id, id + "(F)");
@@ -620,57 +669,37 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
      * @throws
      * @throws
      * @author ZHAOXA
      * @author ZHAOXA
      */
      */
-    private boolean touTiaoshutDown(Long accountId, String ids, String type) {
-        Boolean flag = false;
+    private String touTiaoshutDown(Long accountId, String ids, String type, String msg) {
         try {
         try {
             Map<String, Object> result = new HashMap<>();
             Map<String, Object> result = new HashMap<>();
             if (!Check.isNull(ids)) {
             if (!Check.isNull(ids)) {
                 String[] split = ids.split(",");
                 String[] split = ids.split(",");
-                JSONArray planId = new JSONArray();
-                //最大更新100条数据,做拆分
-                if (split.length > 100) {
-                    JSONArray planId2 = new JSONArray();
-                    StringJoiner str = new StringJoiner(",");
-                    StringJoiner str2 = new StringJoiner(",");
-                    for (int i = 0; i < split.length; i++) {
-                        if (i > 99) {
-                            str2.add(split[i]);
-                            planId2.add(split[i]);
-                        } else {
-                            str.add(split[i]);
-                            planId.add(split[i]);
-                        }
-                    }
+                if (!Check.isNull(split)) {
                     if (PLAN.equals(type)) {
                     if (PLAN.equals(type)) {
-                        CtopOauthToken token = ctopOauthTokenService.getTokenByAccountId(accountId);
-                        result = byteDanceAdvertisePlanService.updateAdvertiserPlanStatus(token, planId, "AD_STATUS_DISABLE");
-                        if (planId2.size() > 0) {
-                            result = byteDanceAdvertisePlanService.updateAdvertiserPlanStatus(token, planId2, "AD_STATUS_DISABLE");
-                        }
-                    } else {
-                        result = byteDanceCreativeService.advertiserCreativeUpdateStatus(accountId, str.toString(), "disable");
-                        if (str2.length() > 0) {
-                            result = byteDanceCreativeService.advertiserCreativeUpdateStatus(accountId, str2.toString(), "disable");
+                        CtopOauthToken token = tokenService.getTokenByAccountId(accountId);
+                        for (String id : split) {
+                            JSONArray idArray = new JSONArray();
+                            idArray.add(id);
+                            result = byteDanceAdvertisePlanService.updateAdvertiserPlanStatus(token, idArray, "AD_STATUS_DISABLE");
+                            if (Check.isNull(result.get("code")) || (int) result.get("code") != 0) {
+                                msg = msg.replace(id, id + "(F)");
+                            }
                         }
                         }
-                    }
-                    //低于100条数据,直接执行
-                } else {
-                    if (PLAN.equals(type)) {
+                    } else if (CREATIVE.equals(type)) {
+                        CtopOauthToken creativeToken = tokenService.getOauthTokenByAccountId(accountId + "");
                         for (String id : split) {
                         for (String id : split) {
-                            planId.add(id);
+                            result = byteDanceCreativeService.advertiserCreativeUpdateStatus(creativeToken, accountId, id, "disable");
+                            if (Check.isNull(result.get("code")) || (int) result.get("code") != 0) {
+                                msg = msg.replace(id, id + "(F)");
+                            }
                         }
                         }
-                        CtopOauthToken token = ctopOauthTokenService.getTokenByAccountId(accountId);
-                        result = byteDanceAdvertisePlanService.updateAdvertiserPlanStatus(token, planId, "AD_STATUS_DISABLE");
-                    } else {
-                        result = byteDanceCreativeService.advertiserCreativeUpdateStatus(accountId, ids.replace(",", ","), "disable");
                     }
                     }
                 }
                 }
-                flag = !Check.isNull(result.get("code")) && (int) result.get("code") == 0;
             }
             }
         } catch (Exception e) {
         } catch (Exception e) {
             log.error("头条账户:{},关停{}失败", accountId, type, e);
             log.error("头条账户:{},关停{}失败", accountId, type, e);
         }
         }
-        return flag;
+        return msg;
     }
     }
 
 
 
 

+ 44 - 35
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/material/controller/ByteDanceCreativeController.java

@@ -17,7 +17,14 @@ import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
 import lombok.extern.slf4j.Slf4j;
 import org.jeecg.common.api.vo.Result;
 import org.jeecg.common.api.vo.Result;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.*;
+import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.PutMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
 
 
 import java.util.Arrays;
 import java.util.Arrays;
 import java.util.HashMap;
 import java.util.HashMap;
@@ -38,7 +45,8 @@ import java.util.stream.Collectors;
 public class ByteDanceCreativeController {
 public class ByteDanceCreativeController {
     @Autowired
     @Autowired
     private IByteDanceCreativeService byteDanceCreativeService;
     private IByteDanceCreativeService byteDanceCreativeService;
-
+    @Autowired
+    ICtopOauthTokenService tokenService;
     /**
     /**
      * 分页列表查询
      * 分页列表查询
      *
      *
@@ -52,38 +60,38 @@ public class ByteDanceCreativeController {
     public Result<IPage<ByteDanceCreative>> queryPageList(
     public Result<IPage<ByteDanceCreative>> queryPageList(
             @RequestParam(name = "planId", required = false) Long planId,
             @RequestParam(name = "planId", required = false) Long planId,
             @RequestParam(name = "accountId", defaultValue = "0") Long accountId,
             @RequestParam(name = "accountId", defaultValue = "0") Long accountId,
-            @RequestParam(name = "status",required = false) String status,
+            @RequestParam(name = "status", required = false) String status,
             @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
             @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
             @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
             @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
-            @RequestParam(name="startDate",defaultValue = "",required = false)String startDate,
-            @RequestParam(name="endDate",defaultValue = "",required = false)String endDate,
-            @RequestParam(name = "name",defaultValue = "",required = false)String name) {
+            @RequestParam(name = "startDate", defaultValue = "", required = false) String startDate,
+            @RequestParam(name = "endDate", defaultValue = "", required = false) String endDate,
+            @RequestParam(name = "name", defaultValue = "", required = false) String name) {
         Result<IPage<ByteDanceCreative>> result = new Result<>();
         Result<IPage<ByteDanceCreative>> result = new Result<>();
         QueryWrapper<ByteDanceCreative> queryWrapper = new QueryWrapper<>();
         QueryWrapper<ByteDanceCreative> queryWrapper = new QueryWrapper<>();
-        if(null!=startDate&&!"".equals(startDate.trim())){
-            queryWrapper.ge("creative_create_time",startDate+" 00:00:00");
+        if (null != startDate && !"".equals(startDate.trim())) {
+            queryWrapper.ge("creative_create_time", startDate + " 00:00:00");
         }
         }
-        if(null!=accountId){
-            queryWrapper.eq("account_id",accountId);
+        if (null != accountId) {
+            queryWrapper.eq("account_id", accountId);
         }
         }
-        if(null!=planId&&planId!=0){
-            queryWrapper.eq("plan_id",planId);
+        if (null != planId && planId != 0) {
+            queryWrapper.eq("plan_id", planId);
         }
         }
-        if(null!=endDate&&!"".equals(endDate.trim())){
-            queryWrapper.le("creative_create_time",endDate+" 23:59:59");
+        if (null != endDate && !"".equals(endDate.trim())) {
+            queryWrapper.le("creative_create_time", endDate + " 23:59:59");
         }
         }
-        if(null!=name&&!"".equals(name.trim())){
-            queryWrapper.like("title",name);
+        if (null != name && !"".equals(name.trim())) {
+            queryWrapper.like("title", name);
         }
         }
-        if(null!=status&&!"".equals(status.trim())){
-            queryWrapper.eq("opt_status","CREATIVE_STATUS_"+status);
+        if (null != status && !"".equals(status.trim())) {
+            queryWrapper.eq("opt_status", "CREATIVE_STATUS_" + status);
         }
         }
         queryWrapper.orderByDesc("creative_create_time");
         queryWrapper.orderByDesc("creative_create_time");
         Page<ByteDanceCreative> page = new Page<>(pageNo, pageSize);
         Page<ByteDanceCreative> page = new Page<>(pageNo, pageSize);
         IPage<ByteDanceCreative> pageList = byteDanceCreativeService.page(page, queryWrapper);
         IPage<ByteDanceCreative> pageList = byteDanceCreativeService.page(page, queryWrapper);
         List<ByteDanceCreative> records = pageList.getRecords();
         List<ByteDanceCreative> records = pageList.getRecords();
-        if(null!=records&&!records.isEmpty()){
-            List<ByteDanceCreative> creatives = records.stream().map(creative-> creative.setCreateStatus("CREATIVE_STATUS_ENABLE".equalsIgnoreCase(creative.getOptStatus()))).collect(Collectors.toList());
+        if (null != records && !records.isEmpty()) {
+            List<ByteDanceCreative> creatives = records.stream().map(creative -> creative.setCreateStatus("CREATIVE_STATUS_ENABLE".equalsIgnoreCase(creative.getOptStatus()))).collect(Collectors.toList());
             pageList.setRecords(creatives);
             pageList.setRecords(creatives);
         }
         }
         result.setSuccess(true);
         result.setSuccess(true);
@@ -114,18 +122,20 @@ public class ByteDanceCreativeController {
 
 
     /**
     /**
      * 修改广告组状态
      * 修改广告组状态
+     *
      * @return
      * @return
      */
      */
     @PostMapping("/editStatus")
     @PostMapping("/editStatus")
-    public Map<String,Object> editStatus(@RequestParam(name = "accountId",defaultValue = "0")Long accountId,
-                                         @RequestParam(name = "ids") String ids,
-                                         @RequestParam(name = "status")String status){
-        Map<String,Object>result = new HashMap();
-        if(null == accountId||accountId==0||null == ids|| "".equals(ids.trim())||null==status|| "".equals(status.trim())){
+    public Map<String, Object> editStatus(@RequestParam(name = "accountId", defaultValue = "0") Long accountId,
+                                          @RequestParam(name = "ids") String ids,
+                                          @RequestParam(name = "status") String status) {
+        Map<String, Object> result = new HashMap();
+        if (null == accountId || accountId == 0 || null == ids || "".equals(ids.trim()) || null == status || "".equals(status.trim())) {
             ResultMapUtils.setResultMap(result, StatusCode.COMMON_PARAM_ERROR);
             ResultMapUtils.setResultMap(result, StatusCode.COMMON_PARAM_ERROR);
             return result;
             return result;
         }
         }
-        return byteDanceCreativeService.advertiserCreativeUpdateStatus(accountId,ids,status);
+        CtopOauthToken cTopOauthToken = tokenService.getOauthTokenByAccountId(accountId + "");
+        return byteDanceCreativeService.advertiserCreativeUpdateStatus(cTopOauthToken, accountId, ids, status);
     }
     }
 
 
     /**
     /**
@@ -155,19 +165,18 @@ public class ByteDanceCreativeController {
     }
     }
 
 
     @PostMapping("/detail")
     @PostMapping("/detail")
-    public Map<String,Object>creativeDetail(@RequestParam(name = "planId",required = true,defaultValue = "0") Long planId,
-                                            @RequestParam(name = "accountId",required = true,defaultValue = "0") Long accountId){
-        Map<String,Object>result = new HashMap<>();
+    public Map<String, Object> creativeDetail(@RequestParam(name = "planId", required = true, defaultValue = "0") Long planId,
+                                              @RequestParam(name = "accountId", required = true, defaultValue = "0") Long accountId) {
+        Map<String, Object> result = new HashMap<>();
         CtopOauthToken token = tokenService.getTokenByAccountId(accountId);
         CtopOauthToken token = tokenService.getTokenByAccountId(accountId);
-        if(null == token){
-            ResultMapUtils.setResultMap(result,StatusCode.COMMON_PARAM_ERROR);
+        if (null == token) {
+            ResultMapUtils.setResultMap(result, StatusCode.COMMON_PARAM_ERROR);
             return result;
             return result;
         }
         }
-        return byteDanceCreativeService.getCreativeDetail(token,planId);
+        return byteDanceCreativeService.getCreativeDetail(token, planId);
     }
     }
 
 
-    @Autowired
-    ICtopOauthTokenService tokenService;
+
 
 
     /**
     /**
      * 通过id删除
      * 通过id删除
@@ -230,7 +239,7 @@ public class ByteDanceCreativeController {
     }
     }
 
 
     @PostMapping("/updateCreative")
     @PostMapping("/updateCreative")
-    public Map<String,Object>updateCreative(@RequestBody JSONObject data){
+    public Map<String, Object> updateCreative(@RequestBody JSONObject data) {
         return byteDanceCreativeService.updateCreative(data);
         return byteDanceCreativeService.updateCreative(data);
     }
     }
 }
 }

+ 1 - 1
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/material/service/IByteDanceCreativeService.java

@@ -20,7 +20,7 @@ public interface IByteDanceCreativeService extends IService<ByteDanceCreative> {
 
 
     Map<String, Object> getAdvertiserCreative(CtopOauthToken token, String ids, String date);
     Map<String, Object> getAdvertiserCreative(CtopOauthToken token, String ids, String date);
 
 
-    Map<String, Object> advertiserCreativeUpdateStatus(Long accountId, String creativeIds, String optStatus);
+    Map<String, Object> advertiserCreativeUpdateStatus(CtopOauthToken cTopOauthToken,Long accountId, String creativeIds, String optStatus);
 
 
     void replaceBatch(List<ByteDanceCreative> creatives);
     void replaceBatch(List<ByteDanceCreative> creatives);
 
 

+ 1 - 2
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/material/service/impl/ByteDanceCreativeServiceImpl.java

@@ -45,7 +45,7 @@ public class ByteDanceCreativeServiceImpl extends ServiceImpl<ByteDanceCreativeM
      * @return
      * @return
      */
      */
     @Override
     @Override
-    public Map<String, Object> advertiserCreativeUpdateStatus(Long accountId, String creativeIds, String optStatus) {
+    public Map<String, Object> advertiserCreativeUpdateStatus(CtopOauthToken cTopOauthToken,Long accountId, String creativeIds, String optStatus) {
         Map<String, Object> resultMap = new HashMap<>();
         Map<String, Object> resultMap = new HashMap<>();
         JSONArray ids = new JSONArray();
         JSONArray ids = new JSONArray();
         String[] getCreativeIds = creativeIds.split(StringUtils.COMMA);
         String[] getCreativeIds = creativeIds.split(StringUtils.COMMA);
@@ -54,7 +54,6 @@ public class ByteDanceCreativeServiceImpl extends ServiceImpl<ByteDanceCreativeM
                 ids.add(Long.parseLong(getCreativeIds[i]));
                 ids.add(Long.parseLong(getCreativeIds[i]));
             }
             }
         }
         }
-        CtopOauthToken cTopOauthToken = tokenService.getOauthTokenByAccountId(accountId+"");
         //2: 根据token以及用户id获取用户信息数据
         //2: 根据token以及用户id获取用户信息数据
         String url = PropertiesUtils.getValue("bytedance_config", "bytedance_api_url") + PropertiesUtils.getValue("bytedance_config", "bytedance_v2_creative_update_status");
         String url = PropertiesUtils.getValue("bytedance_config", "bytedance_api_url") + PropertiesUtils.getValue("bytedance_config", "bytedance_v2_creative_update_status");
         Map<String, String> headers = new HashMap<>();
         Map<String, String> headers = new HashMap<>();