yf_zn 9 месяцев назад
Родитель
Сommit
bb6ce6303c

+ 12 - 3
src/main/java/com/yunfeiyun/agmp/iots/warn/job/WarnJob.java

@@ -14,11 +14,20 @@ public class WarnJob {
     private ReCountService reCountService;
 
     /**
-     * 每天凌晨12点清除重复次数
+     * 每天凌晨12点清除重复次数...
      */
     @Scheduled(cron = "0 0 0 * * ?")
-    public void resetReCount() {
-        log.info("【设备预警】定时清空所有重复次数");
+    public void resetReCount24() {
+        log.info("【设备预警】定时清空所有重复次数,0 0 * * * ? 每天凌晨12点清除重复次数");
+        reCountService.resetAllReCount();
+    }
+
+    /**
+     * 每2时执行一次...
+     */
+    @Scheduled(cron = "* * 0/2 * * ? ")
+    public void resetReCount2() {
+        log.info("【设备预警】定时清空所有重复次数,临时配置,* * 0/2 * * ?  每2时执行一次");
         reCountService.resetAllReCount();
     }
 }

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

@@ -34,6 +34,8 @@ public interface IotWarnBussinessMapper {
      */
     int resetReCount();
 
+    List<IotWarncount> getAllReCount();
+
     /**
      * 插入预警记录
      *

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

@@ -36,7 +36,7 @@ public class IotWarnBussinessService {
             log.info("从缓存中获取到重复次数: {}", count);
             return count;
         }
-        IotWarncount iotWarncount  = iotWarncountMapper.selectIotWarnCountByDevAndConfig(devId, configId);
+        IotWarncount iotWarncount = iotWarncountMapper.selectIotWarnCountByDevAndConfig(devId, configId);
         if (iotWarncount == null) {
             log.warn("数据库中未找到设备ID: {}, 配置ID: {} 的重复次数数据", devId, configId);
             return null;
@@ -76,7 +76,15 @@ public class IotWarnBussinessService {
 
     public int resetReCount() {
         log.info("重置所有重复次数");
-        redisCacheManager.deleteObject(RedisCacheKey.IOT_WARN_RE_COUNTS, "*");
+        List<IotWarncount> iotWarncounts = iotWarncountMapper.getAllReCount();
+        for (IotWarncount iotWarncount : iotWarncounts) {
+            try {
+                redisCacheManager.deleteObject(RedisCacheKey.IOT_WARN_RE_COUNTS, iotWarncount.getWcBid() + ":" + iotWarncount.getDevBid());
+                log.info("重置所有重复次数:配置id:{},设备id{},成功", iotWarncount.getWcBid() , iotWarncount.getDevBid());
+            } catch (Exception e) {
+                log.info("重置所有重复次数:配置id:{},设备id{},异常:{}", iotWarncount.getWcBid() , iotWarncount.getDevBid(), e);
+            }
+        }
         int result = iotWarncountMapper.resetReCount();
         log.info("重置所有重复次数结果: {}", result);
         return result;

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

@@ -96,4 +96,7 @@
                 AND wc.devtypeBid = #{devtypeBid}
             </if>
     </select>
+    <select id="getAllReCount" resultType="com.yunfeiyun.agmp.iot.common.domain.IotWarncount">
+        select  * from IotWarncount
+    </select>
 </mapper>