浏览代码

人群包、流量包逻辑修改

zhaoxian 4 年之前
父节点
当前提交
5e9ec9bdde

+ 38 - 19
module-alarm/src/main/java/cn/com/ctop/alarm/modules/constant/MatchLogic.java

@@ -9,6 +9,7 @@ import lombok.extern.slf4j.Slf4j;
 
 import java.math.BigDecimal;
 import java.util.ArrayList;
+import java.util.Comparator;
 import java.util.List;
 
 /**
@@ -18,7 +19,6 @@ import java.util.List;
  */
 @Slf4j
 public class MatchLogic {
-
     /**
      * @param type      数据类型
      * @param condition 条件
@@ -28,7 +28,7 @@ public class MatchLogic {
      * @throws
      * @author ZHAOXA
      */
-    public static boolean matchCondition(JSONObject indicator, String condition, String threshold, String value, JSONObject obj) {
+    public static boolean matchCondition(JSONObject indicator, String condition, String threshold, String value, JSONObject obj, String indicatorCode) {
         //阈值数据类型类型
         String type = indicator.getString("dataType");
         try {
@@ -104,36 +104,55 @@ public class MatchLogic {
                  包含逻辑通用: 任一存在则报警
                  */
                 if (value.contains("[") && threshold.contains("[")) {
+                    String logicalType = indicator.getString("logicalType");
                     List<String> values = strToList(value);
                     List<String> thresholds = strToList(threshold);
                     //包含 任一存在则报警
                     if ("contain".equals(condition)) {
-                        for (String thr : thresholds) {
-                            if (values.contains(thr)) {
-                                return true;
+                        //人群包、流量包判断的是对象
+                        if (NoEn.NO1.valueStr().equals(logicalType) || "retargetingTagsInclude".equals(indicatorCode) || "population".equals(indicatorCode)) {
+                            for (String thr : thresholds) {
+                                if (values.contains(thr)) {
+                                    return true;
+                                }
+                            }
+                        } else {
+                            for (String thr : thresholds) {
+                                if (values.toString().contains(thr)) {
+                                    return true;
+                                }
                             }
                         }
                     } else {
-                        String logicalType = indicator.getString("logicalType");
-                        //排除人群包、流量排除包逻辑
+                        //排除人群包、流量排除包逻辑,不包含,所选必须都存在,否则报警
                         if (NoEn.NO1.valueStr().equals(logicalType)) {
-                            //不包含,所选必须都存在,否则报警
                             if (values.size() != thresholds.size()) {
                                 return true;
                             }
-                            for (String thr : thresholds) {
-                                if (!values.contains(thr)) {
-                                    return true;
-                                }
-                            }
+                            values.sort(Comparator.comparing(String::hashCode));
+                            thresholds.sort(Comparator.comparing(String::hashCode));
+                            return !values.toString().equals(thresholds.toString());
+
                         } else {
-                            boolean flag = true;
                             //不包含,阈值中,存在任一目标则不报警,都不存在时则报警,出现阈值之外的亦报警
-                            for (String thr : thresholds) {
-                                if (values.contains(thr)) {
-                                    flag = false;
-                                } else {
-                                    return true;
+                            boolean flag = true;
+                            if ("retargetingTagsInclude".equals(indicatorCode) || "population".equals(indicatorCode)) {
+                                //人群包判断是否存在该对象
+                                for (String thr : thresholds) {
+                                    if (values.contains(thr)) {
+                                        flag = false;
+                                    } else {
+                                        return true;
+                                    }
+                                }
+                            } else {
+                                //判断是否存在关键字。
+                                for (String thr : thresholds) {
+                                    if (values.toString().contains(thr)) {
+                                        flag = false;
+                                    } else {
+                                        return true;
+                                    }
                                 }
                             }
                             return flag;

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

@@ -249,7 +249,7 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
                         for (int i = 0; i < dimensionData.size(); i++) {
                             JSONObject obj = dimensionData.getJSONObject(i);
                             String value = obj.getString(ruleBase.getIndicatorCode());
-                            if (MatchLogic.matchCondition(indicator, ruleBase.getRuleCondition(), threshold, value, obj)) {
+                            if (MatchLogic.matchCondition(indicator, ruleBase.getRuleCondition(), threshold, value, obj, ruleBase.getIndicatorCode())) {
                                 complianceList.add(obj);
                             }
                         }
@@ -329,7 +329,7 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
             //账户维度数据
             if (ACCOUNT.equals(ruleBase.getRuleDimension())) {
                 JSONObject accountEntity = dimensionData.getJSONObject(0);
-                if (MatchLogic.matchCondition(indicator, ruleBase.getRuleCondition(), threshold, accountEntity.getString(ruleBase.getIndicatorCode()), accountEntity)) {
+                if (MatchLogic.matchCondition(indicator, ruleBase.getRuleCondition(), threshold, accountEntity.getString(ruleBase.getIndicatorCode()), accountEntity, ruleBase.getIndicatorCode())) {
                     if (Check.isNull(accountDatas)) {
                         accountDatas.add(accountEntity);
                     }
@@ -461,7 +461,7 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
             for (int i = 0; i < ruleDatas.size(); i++) {
                 JSONObject targetEntity = ruleDatas.getJSONObject(i);
                 String value = targetEntity.getString(ruleBase.getIndicatorCode());
-                if (MatchLogic.matchCondition(indicator, ruleBase.getRuleCondition(), threshold, value, targetEntity)) {
+                if (MatchLogic.matchCondition(indicator, ruleBase.getRuleCondition(), threshold, value, targetEntity, ruleBase.getIndicatorCode())) {
                     okData.add(targetEntity);
                 }
             }
@@ -470,7 +470,7 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
         for (int i = 0; i < dimensionData.size(); i++) {
             JSONObject targetEntity = dimensionData.getJSONObject(i);
             String value = targetEntity.getString(ruleBase.getIndicatorCode());
-            if (MatchLogic.matchCondition(indicator, ruleBase.getRuleCondition(), threshold, value, targetEntity)) {
+            if (MatchLogic.matchCondition(indicator, ruleBase.getRuleCondition(), threshold, value, targetEntity, ruleBase.getIndicatorCode())) {
                 ruleDatas.add(targetEntity);
             }
         }