Selaa lähdekoodia

预警规则-流量排除包、排除人群包逻辑修改

zhaoxian 4 vuotta sitten
vanhempi
commit
a7ed8dc924

+ 36 - 12
module-alarm/src/main/java/cn/com/ctop/alarm/modules/constant/MatchLogic.java

@@ -4,6 +4,7 @@ import cn.com.ctop.alarm.modules.entity.RuleGroup;
 import cn.com.ctop.common.module.utils.Check;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import com.xxl.job.core.enums.NoEn;
 import lombok.extern.slf4j.Slf4j;
 
 import java.math.BigDecimal;
@@ -29,7 +30,9 @@ public class MatchLogic {
      * @throws
      * @author ZHAOXA
      */
-    public static boolean matchCondition(String type, String condition, String threshold, String value, JSONObject obj) {
+    public static boolean matchCondition(JSONObject indicator, String condition, String threshold, String value, JSONObject obj) {
+        //阈值数据类型类型
+        String type = indicator.getString("dataType");
         try {
             if (Check.isNull(threshold) || "[]".equals(threshold)) {
                 return false;
@@ -96,29 +99,50 @@ public class MatchLogic {
                     }
                 }
             } 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 (value.contains("[") && threshold.contains("[")) {
+                        List<String> values = strToList(value);
+                        List<String> thresholds = strToList(threshold);
+                        if (values.size() != thresholds.size()) {
+                            return true;
+                        }
                         for (String v : values) {
                             if (!threshold.contains(v)) {
                                 return true;
                             }
                         }
                     } else {
-                        for (String v : values) {
-                            if (threshold.contains(v)) {
-                                return true;
-                            }
+                        if ("contain".equals(condition)) {
+                            return threshold.contains(value);
+                        } else {
+                            return !threshold.contains(value);
                         }
                     }
                 } else {
-                    if ("contain".equals(condition)) {
-                        return threshold.contains(value);
+                    if (value.contains("[") && threshold.contains("[")) {
+                        List<String> values = strToList(value);
+                        if ("contain".equals(condition)) {
+                            for (String v : values) {
+                                if (!threshold.contains(v)) {
+                                    return true;
+                                }
+                            }
+                        } else {
+                            for (String v : values) {
+                                if (threshold.contains(v)) {
+                                    return true;
+                                }
+                            }
+                        }
                     } else {
-                        return !threshold.contains(value);
+                        if ("contain".equals(condition)) {
+                            return threshold.contains(value);
+                        } else {
+                            return !threshold.contains(value);
+                        }
                     }
                 }
-
             }
         } catch (Exception e) {
             log.error("条件匹配异常,入参为:type={},condition={},threshold={},value={},", type, condition, threshold, value, e);

+ 4 - 0
module-alarm/src/main/java/cn/com/ctop/alarm/modules/entity/RuleIndicator.java

@@ -80,6 +80,10 @@ public class RuleIndicator {
      */
     @Excel(name = "对应数据表名称", width = 15)
     @ApiModelProperty(value = "对应数据表名称")
+    /**
+     * 逻辑类型,针对流量排除包、排除人群包标识
+     */
+    private Integer logicalType;
     private String tableName;
     private Integer status;
     private Integer sort;

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

@@ -223,7 +223,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.getString("dataType"), ruleBase.getRuleCondition(), threshold, value, obj)) {
+                            if (MatchLogic.matchCondition(indicator, ruleBase.getRuleCondition(), threshold, value, obj)) {
                                 complianceList.add(obj);
                             }
                         }
@@ -259,8 +259,6 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
         for (RuleBase ruleBase : ruleBaseList) {
             //指标对象
             JSONObject indicator = indicators.getJSONObject(ruleBase.getIndicatorCode());
-            //阈值类型
-            String dataType = indicator.getString("dataType");
             //指标阈值
             String threshold = thresholdObj.getString(ruleBase.getId().toString());
             //阈值为空时,或者阈值为“unlimited”(不限),不执行该规则
@@ -298,7 +296,7 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
             //账户维度数据
             if (ACCOUNT.equals(ruleBase.getRuleDimension())) {
                 JSONObject accountEntity = dimensionData.getJSONObject(0);
-                if (MatchLogic.matchCondition(dataType, ruleBase.getRuleCondition(), threshold, accountEntity.getString(ruleBase.getIndicatorCode()), accountEntity)) {
+                if (MatchLogic.matchCondition(indicator, ruleBase.getRuleCondition(), threshold, accountEntity.getString(ruleBase.getIndicatorCode()), accountEntity)) {
                     accountDatas.add(accountEntity);
                 } else {
                     if (!Check.isNull(accountDatas)) {
@@ -316,7 +314,7 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
                     break;
                 }
             } else if (PLAN.equals(ruleBase.getRuleDimension())) {
-                planDatas = getOKData(planDatas, dimensionData, ruleBase, dataType, threshold);
+                planDatas = getOKData(planDatas, dimensionData, ruleBase, indicator, threshold);
                 if (Check.isNull(planDatas)) {
                     if (!Check.isNull(accountDatas)) {
                         accountDatas = null;
@@ -333,7 +331,7 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
                     break;
                 }
             } else if (CREATIVE.equals(ruleBase.getRuleDimension())) {
-                creativeDatas = getOKData(creativeDatas, dimensionData, ruleBase, dataType, threshold);
+                creativeDatas = getOKData(creativeDatas, dimensionData, ruleBase, indicator, threshold);
                 if (Check.isNull(creativeDatas)) {
                     if (!Check.isNull(accountDatas)) {
                         accountDatas = null;
@@ -350,7 +348,7 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
                     break;
                 }
             } else if ("target".equals(ruleBase.getRuleDimension())) {
-                targetDatas = getOKData(targetDatas, dimensionData, ruleBase, dataType, threshold);
+                targetDatas = getOKData(targetDatas, dimensionData, ruleBase, indicator, threshold);
                 if (Check.isNull(targetDatas)) {
                     if (!Check.isNull(accountDatas)) {
                         accountDatas = null;
@@ -385,13 +383,13 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
      * @throws
      * @author ZHAOXA
      */
-    private JSONArray getOKData(JSONArray ruleDatas, JSONArray dimensionData, RuleBase ruleBase, String type, String threshold) {
+    private JSONArray getOKData(JSONArray ruleDatas, JSONArray dimensionData, RuleBase ruleBase, JSONObject indicator, String threshold) {
         if (!Check.isNull(ruleDatas)) {
             JSONArray okData = new JSONArray();
             for (int i = 0; i < ruleDatas.size(); i++) {
                 JSONObject targetEntity = dimensionData.getJSONObject(i);
                 String value = targetEntity.getString(ruleBase.getIndicatorCode());
-                if (MatchLogic.matchCondition(type, ruleBase.getRuleCondition(), threshold, value, targetEntity)) {
+                if (MatchLogic.matchCondition(indicator, ruleBase.getRuleCondition(), threshold, value, targetEntity)) {
                     okData.add(targetEntity);
                 }
             }
@@ -400,7 +398,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(type, ruleBase.getRuleCondition(), threshold, value, targetEntity)) {
+            if (MatchLogic.matchCondition(indicator, ruleBase.getRuleCondition(), threshold, value, targetEntity)) {
                 ruleDatas.add(targetEntity);
             }
         }