Kaynağa Gözat

预警规则再优化

zhaoxian 4 yıl önce
ebeveyn
işleme
74a7c50ef3

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

@@ -195,17 +195,20 @@ 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(ruleGroup, ruleBaseList, thresholdJn, indicators, matchData, complianceList);
+                        CombinationRule(ruleBaseList, thresholdJn, indicators, matchData, complianceList);
                     }
                     }
                 }
                 }
             } else {
             } else {
                 boolean isGroup = "group".equals(ruleGroup.getRuleType());
                 boolean isGroup = "group".equals(ruleGroup.getRuleType());
                 //匹配组合规则
                 //匹配组合规则
                 if (isGroup) {
                 if (isGroup) {
-                    CombinationRule(ruleGroup, ruleBaseList, thresholdObj, indicators, matchData, complianceList);
+                    CombinationRule(ruleBaseList, thresholdObj, indicators, matchData, complianceList);
                     //匹配单规则
                     //匹配单规则
                 } else {
                 } else {
                     RuleBase ruleBase = ruleBaseList.get(0);
                     RuleBase ruleBase = ruleBaseList.get(0);
+                    if (Check.isNull(ruleBase)) {
+                        continue;
+                    }
                     //指标对象
                     //指标对象
                     JSONObject indicator = indicators.getJSONObject(ruleBase.getIndicatorCode());
                     JSONObject indicator = indicators.getJSONObject(ruleBase.getIndicatorCode());
                     //指标阈值
                     //指标阈值
@@ -222,7 +225,6 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
                             String value = obj.getString(ruleBase.getIndicatorCode());
                             String value = obj.getString(ruleBase.getIndicatorCode());
                             if (MatchLogic.matchCondition(indicator.getString("dataType"), ruleBase.getRuleCondition(), threshold, value, obj)) {
                             if (MatchLogic.matchCondition(indicator.getString("dataType"), ruleBase.getRuleCondition(), threshold, value, obj)) {
                                 complianceList.add(obj);
                                 complianceList.add(obj);
-//                                sendMsg(ruleGroup, obj, type, accountName);
                             }
                             }
                         }
                         }
                     }
                     }
@@ -248,7 +250,7 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
      * @throws
      * @throws
      * @author ZHAOXA
      * @author ZHAOXA
      */
      */
-    private void CombinationRule(RuleGroup ruleGroup, 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) {
         //符合规则的数据集
         //符合规则的数据集
         JSONArray targetDatas = new JSONArray();
         JSONArray targetDatas = new JSONArray();
         JSONArray planDatas = new JSONArray();
         JSONArray planDatas = new JSONArray();
@@ -263,10 +265,34 @@ 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) || "unlimited".equals(threshold)) {
-                continue;
+                if (!Check.isNull(accountDatas)) {
+                    accountDatas = null;
+                }
+                if (!Check.isNull(planDatas)) {
+                    planDatas = null;
+                }
+                if (!Check.isNull(creativeDatas)) {
+                    creativeDatas = null;
+                }
+                if (!Check.isNull(targetDatas)) {
+                    targetDatas = null;
+                }
+                break;
             }
             }
             JSONArray dimensionData = matchData.getJSONArray(ruleBase.getRuleDimension());
             JSONArray dimensionData = matchData.getJSONArray(ruleBase.getRuleDimension());
             if (Check.isNull(dimensionData)) {
             if (Check.isNull(dimensionData)) {
+                if (!Check.isNull(accountDatas)) {
+                    accountDatas = null;
+                }
+                if (!Check.isNull(planDatas)) {
+                    planDatas = null;
+                }
+                if (!Check.isNull(creativeDatas)) {
+                    creativeDatas = null;
+                }
+                if (!Check.isNull(targetDatas)) {
+                    targetDatas = null;
+                }
                 break;
                 break;
             }
             }
             //账户维度数据
             //账户维度数据
@@ -275,29 +301,72 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
                 if (MatchLogic.matchCondition(dataType, ruleBase.getRuleCondition(), threshold, accountEntity.getString(ruleBase.getIndicatorCode()), accountEntity)) {
                 if (MatchLogic.matchCondition(dataType, ruleBase.getRuleCondition(), threshold, accountEntity.getString(ruleBase.getIndicatorCode()), accountEntity)) {
                     accountDatas.add(accountEntity);
                     accountDatas.add(accountEntity);
                 } else {
                 } else {
-                    log.warn("匹配规则组({}),账户维度数据不符合直接跳过", ruleGroup.getId());
-                    break;
-                }
-                if (Check.isNull(accountDatas)) {
+                    if (!Check.isNull(accountDatas)) {
+                        accountDatas = null;
+                    }
+                    if (!Check.isNull(planDatas)) {
+                        planDatas = null;
+                    }
+                    if (!Check.isNull(creativeDatas)) {
+                        creativeDatas = null;
+                    }
+                    if (!Check.isNull(targetDatas)) {
+                        targetDatas = null;
+                    }
                     break;
                     break;
                 }
                 }
             } else if (PLAN.equals(ruleBase.getRuleDimension())) {
             } else if (PLAN.equals(ruleBase.getRuleDimension())) {
                 planDatas = getOKData(planDatas, dimensionData, ruleBase, dataType, threshold);
                 planDatas = getOKData(planDatas, dimensionData, ruleBase, dataType, threshold);
                 if (Check.isNull(planDatas)) {
                 if (Check.isNull(planDatas)) {
+                    if (!Check.isNull(accountDatas)) {
+                        accountDatas = null;
+                    }
+                    if (!Check.isNull(planDatas)) {
+                        planDatas = null;
+                    }
+                    if (!Check.isNull(creativeDatas)) {
+                        creativeDatas = null;
+                    }
+                    if (!Check.isNull(targetDatas)) {
+                        targetDatas = null;
+                    }
                     break;
                     break;
                 }
                 }
             } else if (CREATIVE.equals(ruleBase.getRuleDimension())) {
             } else if (CREATIVE.equals(ruleBase.getRuleDimension())) {
                 creativeDatas = getOKData(creativeDatas, dimensionData, ruleBase, dataType, threshold);
                 creativeDatas = getOKData(creativeDatas, dimensionData, ruleBase, dataType, threshold);
                 if (Check.isNull(creativeDatas)) {
                 if (Check.isNull(creativeDatas)) {
+                    if (!Check.isNull(accountDatas)) {
+                        accountDatas = null;
+                    }
+                    if (!Check.isNull(planDatas)) {
+                        planDatas = null;
+                    }
+                    if (!Check.isNull(creativeDatas)) {
+                        creativeDatas = null;
+                    }
+                    if (!Check.isNull(targetDatas)) {
+                        targetDatas = null;
+                    }
                     break;
                     break;
                 }
                 }
             } else if ("target".equals(ruleBase.getRuleDimension())) {
             } else if ("target".equals(ruleBase.getRuleDimension())) {
                 targetDatas = getOKData(targetDatas, dimensionData, ruleBase, dataType, threshold);
                 targetDatas = getOKData(targetDatas, dimensionData, ruleBase, dataType, threshold);
                 if (Check.isNull(targetDatas)) {
                 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;
+                    }
                     break;
                     break;
                 }
                 }
             }
             }
-
         }
         }
         //获取达标可发送的数据
         //获取达标可发送的数据
         JSONArray sendData = MatchLogic.getSendData(accountDatas, planDatas, creativeDatas, targetDatas);
         JSONArray sendData = MatchLogic.getSendData(accountDatas, planDatas, creativeDatas, targetDatas);
@@ -461,7 +530,7 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
 //                    sendMessageService.sendMessage("1b3deb8258e84df994f1371a51cfc14a", msg + i);
 //                    sendMessageService.sendMessage("1b3deb8258e84df994f1371a51cfc14a", msg + i);
 //                    Thread.sleep(2000);
 //                    Thread.sleep(2000);
 //                }
 //                }
-                sendMessageService.sendMessage(user.getString("id"), msg);
+                sendMessageService.sendMessage("1b3deb8258e84df994f1371a51cfc14a", msg);
                 Thread.sleep(200);
                 Thread.sleep(200);
             }
             }
             if (!Check.isNull(msg)) {
             if (!Check.isNull(msg)) {