Browse Source

1、补充了MIN方法;
2、重构了TagInfo中获取DoubleTsData的方法;

songwenbin 1 year ago
parent
commit
b519a8532c

+ 16 - 0
alarm/custom/src/main/java/com/gyee/wisdom/alarm/model/TagInfo.java

@@ -93,4 +93,20 @@ public class TagInfo {
     public long getLocalLastUpdateTime(){
         return this.localTs;
     }
+
+    public DoubleTsData getDoubleTsData() {
+        if (doubleTsData != null)
+            return doubleTsData;
+
+        if (longTsData != null) {
+            return  new DoubleTsData(longTsData.getTs(),(short)0, (double)longTsData.getLongValue());
+        }
+
+        if (booleanTsData != null) {
+            double dvalue = booleanTsData.getBooleanValue()?1:0;
+            return  new DoubleTsData(booleanTsData.getTs(),(short)0, dvalue);
+        }
+
+        return null;
+    }
 }

+ 3 - 0
alarm/custom/src/main/java/com/gyee/wisdom/alarm/rule/AlarmFunction.java

@@ -127,6 +127,9 @@ public class AlarmFunction {
                 else if (subExp.getFunType() != null && subExp.getFunType().equals("MAX")) {
                     aFun = new AlarmFunctionMAX(subExp, tType, tId);
                 }
+                else if (subExp.getFunType() != null && subExp.getFunType().equals("MIN")) {
+                    aFun = new AlarmFunctionMIN(subExp, tType, tId);
+                }
                 else if (subExp.getFunType() != null && subExp.getFunType().equals("AVG")) {
                     aFun = new AlarmFunctionAVG(subExp, tType, tId);
                 }

+ 6 - 0
alarm/custom/src/main/java/com/gyee/wisdom/alarm/rule/AlarmFunctionMAX.java

@@ -25,6 +25,12 @@ public class AlarmFunctionMAX extends AlarmFunction {
 
         for (int i = 0; i < this.getAlarmExpression().getVarList().size(); i++) {
             TagInfo tagInfo = this.getTagInfo(this.getAlarmExpression().getVarList().get(i));
+
+            if (tagInfo == null) {
+                continue;
+            }
+
+            //System.out.println("@@@@@" + this.getAlarmExpression().getVarList().get(i));
             if (!maxValue.isPresent()) {
                 maxValue = Optional.of(tagInfo.getDoubleTsData().getDoubleValue());
             } else {

+ 35 - 0
alarm/custom/src/main/java/com/gyee/wisdom/alarm/rule/AlarmFunctionMIN.java

@@ -0,0 +1,35 @@
+package com.gyee.wisdom.alarm.rule;
+
+import com.gyee.wisdom.alarm.model.TagInfo;
+import com.gyee.wisdom.alarm.rule.expression.AlarmExpression;
+
+import java.util.Optional;
+
+
+public class AlarmFunctionMIN extends AlarmFunction {
+    public AlarmFunctionMIN(AlarmExpression alarmExpression, ThingType tType, String tId) {
+        super(alarmExpression, tType, tId);
+    }
+
+    @Override
+    public Object explain() {
+        if (this.getAlarmExpression().getVarList() == null || this.getAlarmExpression().getVarList().size() < 1)
+            return 0;
+
+        Optional<Double> minValue = Optional.empty();
+
+        for (int i = 0; i < this.getAlarmExpression().getVarList().size(); i++) {
+            TagInfo tagInfo = this.getTagInfo(this.getAlarmExpression().getVarList().get(i));
+            if (!minValue.isPresent()) {
+                minValue = Optional.of(tagInfo.getDoubleTsData().getDoubleValue());
+            } else {
+                if (minValue.get() >= tagInfo.getDoubleTsData().getDoubleValue()) {
+                    minValue = Optional.of(tagInfo.getDoubleTsData().getDoubleValue());
+                }
+            }
+        }
+
+        return minValue.get().doubleValue();
+    }
+
+}

+ 1 - 0
alarm/custom/src/main/java/com/gyee/wisdom/alarm/rule/AlarmRule.java

@@ -179,6 +179,7 @@ public class AlarmRule {
                         System.out.print(obj.toString());
                     }
                 } catch (Exception ex) {
+                   // ex.printStackTrace();
                     log.error("自定义报警规则执行时出错!"+fun.getThingId()+"--"+this.alertRule.getId()+"----"+this.alertRule.getName()+"------" + ex.getMessage());
                 }
             }

+ 1 - 0
alarm/custom/src/main/java/com/gyee/wisdom/alarm/rule/expression/Analyzer.java

@@ -17,6 +17,7 @@ public class Analyzer {
         add("MR");
         add("MAR");
         add("MAX");
+        add("MIN");
         add("AVG");
     }};
 

+ 3 - 3
alarm/custom/src/main/resources/application.yaml

@@ -8,7 +8,7 @@ spring:
     show-sql: false
   datasource:
     driver-class-name: oracle.jdbc.OracleDriver
-    url: jdbc:oracle:thin:@123.60.213.70:1521:gdnxfd
+    url: jdbc:oracle:thin:@192.168.1.105:1521:gdnxfd
     username: nxfdprod
     password: gdnxfd123
 #    driver-class-name: com.mysql.jdbc.Driver
@@ -29,9 +29,9 @@ spring:
 calculate:
   config:
     #服务地址  ws://localhost:8011/wisdom
-    serviceUrl: http://127.0.0.1:8011/ts
+    serviceUrl: http://192.168.1.82:8011/ts
     #服务地址  ws://localhost:8011/wisdom
-    shardingServiceUrl: http://192.168.100.204:8075
+    shardingServiceUrl: http://192.168.1.18:8075
     #扫描线程轮询时间(单位:毫秒)
     readThreadInterval: 1000
     #计算线程轮询时间(单位:毫秒)