Forráskód Böngészése

预警规则匹配逻辑——调优

zhaoxian 4 éve
szülő
commit
59efaa7002

+ 4 - 4
module-alarm/src/main/java/cn/com/ctop/alarm/modules/mapper/xml/RuleAccountThresholdMapper.xml

@@ -5,17 +5,17 @@
     <select id="selectByAccountId" resultType="cn.com.ctop.alarm.modules.entity.RuleAccountThreshold">
        SELECT * FROM ctop_rule_account_threshold
        WHERE account_id = #{accountId}
-       AND  batch_no =''
+       AND  (batch_no ='' or batch_no is null)
     </select>
     <select id="selectGroupIdsByAccountId" resultType="java.lang.Long">
        SELECT group_id FROM `ctop_rule_account_threshold`
-        WHERE  batch_no !=''
+        WHERE (batch_no !='' and batch_no is null)
         and  account_id = #{accountId}
         group by group_id
     </select>
     <select id="selectbatchNosByGroupIdId" resultType="java.lang.String">
        SELECT batch_no FROM `ctop_rule_account_threshold`
-        WHERE  batch_no !=''
+        WHERE  (batch_no !='' and batch_no is null)
         and account_id = #{accountId}
         and group_id = #{groupId}
         GROUP BY batch_no
@@ -31,7 +31,7 @@
     select   batch_no from ctop_rule_account_threshold
     where  account_id = #{accountId}
     and group_id = #{groupId}
-    and batch_no !=''
+    and (batch_no !='' and batch_no is null)
     group by batch_no
     </select>
 </mapper>

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

@@ -152,7 +152,7 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
             accountName = userAllocations.getAuthName();
         }
         try {
-            if (!Check.isNull(notCopyGroups)) {
+            if (!Check.isNull(notCopyGroups) && !Check.isNull(notCopythreshold)) {
                 checkRuleGroups(notCopyGroups, notCopythreshold, indicators, matchData, type, false, accountName);
             }
             if (isCopy && !Check.isNull(isCopythreshold)) {
@@ -187,8 +187,10 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
             if (isCopy) {
                 JSONObject batchNo = thresholdObj.getJSONObject(ruleGroup.getId().toString());
                 for (Map.Entry<String, Object> entry : batchNo.entrySet()) {
-                    JSONObject thresholdMap = (JSONObject) entry.getValue();
-                    CombinationRule(ruleGroup, ruleBaseList, thresholdMap, indicators, matchData, type, accountName);
+                    JSONObject thresholdJn = (JSONObject) entry.getValue();
+                    if (!Check.isNull(thresholdJn)) {
+                        CombinationRule(ruleGroup, ruleBaseList, thresholdJn, indicators, matchData, type, accountName);
+                    }
                 }
             } else {
                 boolean isGroup = "group".equals(ruleGroup.getRuleType());
@@ -203,8 +205,7 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
                     //指标阈值
                     String threshold = thresholdObj.getString(ruleBase.getId().toString());
                     //阈值为空时,或者阈值为“unlimited”(不限),不执行该规则
-                    if (Check.isNull(threshold) || "unlimited".equals(threshold)) {
-                        log.warn("阈值为空/不限,该规则({})不执行", ruleBase.getId());
+                    if (Check.isNull(threshold) || threshold.contains("unlimited")) {
                         continue;
                     }
                     //维度数据
@@ -255,11 +256,11 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
                 continue;
             }
             JSONArray dimensionData = matchData.getJSONArray(ruleBase.getRuleDimension());
+            if (Check.isNull(dimensionData)) {
+                break;
+            }
             //账户维度数据
             if ("account".equals(ruleBase.getRuleDimension())) {
-                if (Check.isNull(dimensionData)) {
-                    return;
-                }
                 JSONObject accountEntity = dimensionData.getJSONObject(0);
                 if (MatchLogic.matchCondition(dataType, ruleBase.getRuleCondition(), threshold, accountEntity.getString(ruleBase.getIndicatorCode()), accountEntity)) {
                     accountDatas.add(accountEntity);
@@ -309,7 +310,7 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
      * @author ZHAOXA
      */
     private JSONArray getOKData(JSONArray ruleDatas, JSONArray dimensionData, RuleBase ruleBase, String type, String threshold) {
-        if (ruleDatas.size() > 0) {
+        if (!Check.isNull(ruleDatas)) {
             JSONArray okData = new JSONArray();
             for (int i = 0; i < ruleDatas.size(); i++) {
                 JSONObject targetEntity = dimensionData.getJSONObject(i);
@@ -366,8 +367,8 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
         } else {
             //TODO
             ISendMessageService sendMessageService = this.sendMessageService;
-//            sendMessageService.sendMessage(user.getString("id"), msg);
-            sendMessageService.sendMessage("1b3deb8258e84df994f1371a51cfc14a", msg);
+            sendMessageService.sendMessage(user.getString("id"), msg);
+//            sendMessageService.sendMessage("1b3deb8258e84df994f1371a51cfc14a", msg);
             //113dee46c7df464da78c07a985e92cd1 于蒙
         }
         log.debug("账户{}的{}预警已发送", accountId, ruleGroup.getGroupName());
@@ -376,6 +377,15 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
             send.setAlarmDetail(msg);
             send.setAlarmStatus(NoEn.NO1.valueStr());
             send.setEventRuleId(ruleGroup.getId());
+            if (msg.contains("预警账户")) {
+                send.setMetricValueCode("account");
+                if (msg.contains("预警计划")) {
+                    send.setMetricValueCode("plan");
+                    if (msg.contains("预警创意")) {
+                        send.setMetricValueCode("creative");
+                    }
+                }
+            }
             send.setAlarmCondition(ruleGroup.getGroupName());
             send.setUserId(user.getString("id"));
             alarmEventSendMapper.insert(send);