ソースを参照

预警规则判断优化

zhaoxian 4 年 前
コミット
946d607c43

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

@@ -31,10 +31,10 @@ public class MatchLogic {
      */
     public static boolean matchCondition(String type, String condition, String threshold, String value, JSONObject obj) {
         try {
-            if (Check.isNull(threshold)) {
+            if (Check.isNull(threshold) || "[]".equals(threshold)) {
                 return false;
             }
-            if (Check.isNull(value)) {
+            if (Check.isNull(value) || "[]".equals(value)) {
                 obj.put("isNull", true);
                 return true;
             }
@@ -60,18 +60,40 @@ public class MatchLogic {
                         break;
                 }
             } else if ("string".equals(type)) {
-                switch (condition) {
-                    case "equal":
-                        return value.equals(threshold);
-                    case "not_equal":
-                        return !value.equals(threshold);
-                    case "contain":
-                        return threshold.contains(value);
-                    case "no_contain":
-                        return !threshold.contains(value);
-                    default:
-                        log.warn("关系不匹配 type={},condition={},threshold={},value={},", type, condition, threshold, value);
-                        break;
+                if (threshold.contains("[")) {
+                    boolean flag = false;
+                    List<String> thresholds = strToList(threshold);
+                    if ("equal".equals(condition)) {
+                        return value.equals(thresholds.get(0));
+                    } else if ("not_equal".equals(condition)) {
+                        return !value.equals(thresholds.get(0));
+                    }
+                    for (String thro : thresholds) {
+                        if ("contain".equals(condition)) {
+                            if (value.contains(thro)) {
+                                return true;
+                            }
+                        } else if ("no_contain".equals(condition)) {
+                            if (!value.contains(thro)) {
+                                return true;
+                            }
+                        }
+                    }
+                    return flag;
+                } else {
+                    switch (condition) {
+                        case "equal":
+                            return value.equals(threshold);
+                        case "not_equal":
+                            return !value.equals(threshold);
+                        case "contain":
+                            return value.contains(threshold);
+                        case "no_contain":
+                            return !value.contains(threshold);
+                        default:
+                            log.warn("关系不匹配 type={},condition={},threshold={},value={},", type, condition, threshold, value);
+                            break;
+                    }
                 }
             } else {
                 if (value.contains("[") && threshold.contains("[")) {
@@ -228,9 +250,5 @@ public class MatchLogic {
             }
         }
         return sendData;
-
-
     }
-
-
 }