Procházet zdrojové kódy

iots 告警阶段提交

yf_zn před 10 měsíci
rodič
revize
2d0dc63129

+ 18 - 0
src/main/java/com/yunfeiyun/agmp/iots/warn/model/WarnResult.java

@@ -7,8 +7,26 @@ import lombok.Data;
  */
 @Data
 public class WarnResult {
+    /**
+     * 是否触发预警
+     */
     private boolean isTriggered;
+    /**
+     * 预警消息
+     */
     private String message;
+    /**
+     * 设备id
+     */
+    private String devId;
+    /**
+     * 配置id
+     */
+    private String configId;
+    /**
+     * 配置对象
+     */
+    private Object config;
 
     public WarnResult(boolean isTriggered, String message) {
         this.isTriggered = isTriggered;

+ 49 - 0
src/main/java/com/yunfeiyun/agmp/iots/warn/service/ReCountService.java

@@ -0,0 +1,49 @@
+package com.yunfeiyun.agmp.iots.warn.service;
+
+import com.yunfeiyun.agmp.iots.warn.model.WarnResult;
+import org.springframework.stereotype.Service;
+
+/**
+ * 重复次数服务
+ */
+@Service
+public class ReCountService {
+
+    public void handlerMessage(WarnResult warnResult) {
+        // 触发了预警,进行瑞校验处理
+        if (warnResult.isTriggered()) {
+            // 当前的获取重复次数
+            int reCount = 5;
+            // 加 1
+            reCount += 1;
+            // 设定的重复次数阀值
+            int targetReCount = 10;
+            //达到阀值,进入产生预警记录
+            if (reCount >= targetReCount) {
+                // 预警入库 todo
+            } else {
+                //没法达到阀值
+            }
+        } else {
+            //没有触发,则清除之前的
+            cleanReCount(warnResult.getDevId(), warnResult.getConfigId());
+        }
+
+    }
+
+
+    /**
+     * @param devId
+     * @param configId
+     */
+    public void cleanReCount(String devId, String configId) {
+        //如果之前有值,这次没触发,清除缓存,清除数据库重复次数为0
+        //1. 从缓存获取,如果为空,查数据库,并把值放到缓存
+        long cacheCount = 0;
+        //2. 缓存为0,不能是空,因为如果是空,会查数据库
+        if (cacheCount != 0) {
+            //清除缓存,清除数据库,是设置为0
+        }
+    }
+
+}

+ 5 - 2
src/main/java/com/yunfeiyun/agmp/iots/warn/service/WarnService.java

@@ -5,6 +5,7 @@ import com.yunfeiyun.agmp.iot.common.enums.EnumWarnRuleOp;
 import com.yunfeiyun.agmp.iots.warn.model.WarnResult;
 import com.yunfeiyun.agmp.iots.warn.util.CompareUtil;
 import com.yunfeiyun.agmp.iots.warn.util.WarnMessageBuilderUtil;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
 import org.springframework.stereotype.Service;
 
@@ -22,6 +23,9 @@ public class WarnService {
     @Resource(name = "threadPoolTaskExecutor")
     private ThreadPoolTaskExecutor threadPoolTaskExecutor;
 
+    @Autowired
+    private ReCountService reCountService;
+
     /**
      * 统一处理上报数据
      *
@@ -78,8 +82,7 @@ public class WarnService {
      */
     void handleWarnRecord(WarnResult warnResult) {
         if (warnResult.isTriggered()) {
-            //进行预警重复次数处理机制
-            //入库 todo
+            reCountService.handlerMessage(warnResult);
         }
     }