Przeglądaj źródła

增加测试类

lixing 3 lat temu
rodzic
commit
fb689a6f69
1 zmienionych plików z 18 dodań i 0 usunięć
  1. 18 0
      src/main/java/test/com/persagy/service/Test.java

+ 18 - 0
src/main/java/test/com/persagy/service/Test.java

@@ -1,5 +1,10 @@
 package test.com.persagy.service;
 
+import com.googlecode.aviator.AviatorEvaluator;
+import com.googlecode.aviator.Expression;
+
+import java.util.HashMap;
+
 /**
  * 类说明
  *
@@ -7,7 +12,20 @@ package test.com.persagy.service;
  * @version V1.0 2021/11/27 1:15 下午
  **/
 public class Test {
+    private static boolean checkExpression(String expression, HashMap<String, Object> paramMap) {
+        Expression triggerExp = AviatorEvaluator.compile(expression, false);
+        // 执行报警条件公式,得到触发和恢复结果
+        return (Boolean) triggerExp.execute(paramMap);
+    }
     public static void main(String[] args) {
+        String expression = "Y>PClose&&X>=PClose&&(X<(1-0.02)*Y) && math.abs(X-Y) > seq.max(seq.list(decimal(PClose),decimal(1)))";
 
+        HashMap<String, Object> paramMap = new HashMap<>();
+        paramMap.put("X", 9.564593429662636);
+        paramMap.put("Y", 0.0);
+        paramMap.put("PClose", 1.5);
+        //		paramMap.put("EnergyData", 6.125);
+        //		paramMap.put("Pclose", 5.0);
+        System.out.println(checkExpression(expression, paramMap));
     }
 }