Jelajahi Sumber

告警阶段提交

yf_zn 10 bulan lalu
induk
melakukan
3841d63407

+ 25 - 0
src/main/java/com/yunfeiyun/agmp/iots/warn/mapper/IotWarnBussinessMapper.java

@@ -1,6 +1,7 @@
 package com.yunfeiyun.agmp.iots.warn.mapper;
 
 import com.yunfeiyun.agmp.iot.common.domain.IotWarncount;
+import com.yunfeiyun.agmp.iot.common.domain.IotWarnlog;
 
 public interface IotWarnBussinessMapper {
     /**
@@ -11,4 +12,28 @@ public interface IotWarnBussinessMapper {
      * @return
      */
     IotWarncount selectIotWarnCountByDevAndConfig(String devId, String configId);
+
+    /**
+     * 增加重复次数
+     *
+     * @param devId
+     * @param configId
+     * @return
+     */
+    int incrementReCount(String devId, String configId);
+
+
+    /**
+     * 重置重复次数
+     *
+     * @return
+     */
+    int resetReCount();
+
+    /**
+     * 插入预警记录
+     *
+     * @return
+     */
+    int insertWarnRecord(IotWarnlog iotWarnlog);
 }

+ 9 - 1
src/main/java/com/yunfeiyun/agmp/iots/warn/model/WarnResult.java

@@ -24,7 +24,15 @@ public class WarnResult {
      */
     private String configId;
     /**
-     * 配置对象
+     * 上报的数据,冗余存储
+     */
+    private String reportData;
+    /**
+     * 配置的重复次数阀值
+     */
+    private int targetReCount;
+    /**
+     * 配置对象,待定,尽量先不存对象,将必要的存储定义该类中
      */
     private Object config;
 

+ 38 - 2
src/main/java/com/yunfeiyun/agmp/iots/warn/service/IotWarnBussinessService.java

@@ -1,12 +1,14 @@
 package com.yunfeiyun.agmp.iots.warn.service;
 
 import com.yunfeiyun.agmp.iot.common.domain.IotWarncount;
+import com.yunfeiyun.agmp.iot.common.domain.IotWarnlog;
 import com.yunfeiyun.agmp.iots.warn.mapper.IotWarnBussinessMapper;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 @Service
 public class IotWarnBussinessService {
+
     @Autowired
     private IotWarnBussinessMapper iotWarncountMapper;
 
@@ -17,7 +19,41 @@ public class IotWarnBussinessService {
      * @param configId
      * @return
      */
-    public IotWarncount selectIotWarnCountByDevAndConfig(String devId, String configId) {
-        return iotWarncountMapper.selectIotWarnCountByDevAndConfig(devId, configId);
+    public Long selectIotWarnCountByDevAndConfig(String devId, String configId) {
+        IotWarncount iotWarncount = iotWarncountMapper.selectIotWarnCountByDevAndConfig(devId, configId);
+        if (iotWarncount == null) {
+
+        }
+        return iotWarncount.getWctCount();
+    }
+
+    /**
+     * 增加重复次数
+     *
+     * @param devId
+     * @param configId
+     * @return
+     */
+    int incrementReCount(String devId, String configId) {
+        return iotWarncountMapper.incrementReCount(devId, configId);
     }
+
+    /**
+     * 重置重复次数
+     *
+     * @return
+     */
+    int resetReCount() {
+        return iotWarncountMapper.resetReCount();
+    }
+
+    /**
+     * 插入预警记录
+     *
+     * @return
+     */
+    int insertWarnRecord(IotWarnlog iotWarnlog) {
+        return iotWarncountMapper.insertWarnRecord(iotWarnlog);
+    }
+
 }

+ 14 - 5
src/main/java/com/yunfeiyun/agmp/iots/warn/service/ReCountService.java

@@ -21,17 +21,22 @@ public class ReCountService {
         // 触发了预警,进行校验处理
         if (warnResult.isTriggered()) {
             // 当前的获取重复次数
-            int reCount = 5;
+            Long reCount = iotWarnBussinessService.selectIotWarnCountByDevAndConfig(warnResult.getDevId(), warnResult.getConfigId());
             // 加 1
-            reCount += 1;
             // 设定的重复次数阀值
-            int targetReCount = 10;
+            int targetReCount = warnResult.getTargetReCount();
             //达到阀值,进入产生预警记录
-            if (reCount >= targetReCount) {
-                // 预警入库 todo
+            if (reCount + 1 > targetReCount) {
+                // 超多阀值,直接存储
+            } else if (reCount + 1 == targetReCount) {
+                // 达到阀值,直接存储,并增加数值
+                iotWarnBussinessService.incrementReCount(warnResult.getDevId(), warnResult.getConfigId());
             } else {
                 //没法达到阀值
+                iotWarnBussinessService.incrementReCount(warnResult.getDevId(), warnResult.getConfigId());
             }
+
+
         } else {
             //没有触发,则清除之前的
             cleanReCount(warnResult.getDevId(), warnResult.getConfigId());
@@ -40,6 +45,10 @@ public class ReCountService {
     }
 
 
+    public void incrementReCount(WarnResult warnResult) {
+
+    }
+
     /**
      * @param devId
      * @param configId

+ 11 - 0
src/main/resources/mapper/IotWarnBusinessMapper.xml

@@ -4,6 +4,17 @@
         "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.yunfeiyun.agmp.iots.warn.mapper.IotWarnBussinessMapper">
 
+    <insert id="insertWarnRecord">
+
+    </insert>
+    <update id="incrementReCount">
+
+    </update>
+
+    <update id="resetReCount">
+
+    </update>
+
 
     <select id="selectIotWarnCountByDevAndConfig"
             resultType="com.yunfeiyun.agmp.iot.common.domain.IotWarncount">