lihui001 3 gadi atpakaļ
vecāks
revīzija
0cf50c1d88

+ 14 - 0
zoniot-water/zoniot-water-xxl-client/src/main/java/com/zcxk/water/xxl/common/Constants.java

@@ -0,0 +1,14 @@
+package com.zcxk.water.xxl.common;
+
+/**
+ * @author Andy
+ * @date 2021-09-22 10:34
+ */
+public class Constants {
+
+    /**
+     * 小时
+     */
+    public static final  String HOUR = "%s:00:00";
+
+}

+ 4 - 1
zoniot-water/zoniot-water-xxl-client/src/main/java/com/zcxk/water/xxl/common/RedisConstants.java

@@ -7,9 +7,12 @@ package com.zcxk.water.xxl.common;
 public class RedisConstants {
 
     /**
-     * 系统标识符
+     * 调度最后存放的数据
      */
     public static final String DISPATCH_PLAN_LAST_DATA = "dispatch:plan:last:%s";
 
+    /**
+     * 调度实时数据
+     */
     public static final String DISPATCH_PLAN_DATA = "dispatch:plan:%s";
 }

+ 8 - 0
zoniot-water/zoniot-water-xxl-client/src/main/java/com/zcxk/water/xxl/jobs/DispatchPlanJob.java

@@ -49,10 +49,18 @@ public class DispatchPlanJob extends BaseJob {
 
     @XxlJob("checkDeviceStateJob")
     public ReturnT<String> execute(String string) {
+        redisUtil.set("test", "111");
+        redisUtil.setExpire("test", 10 * 1000);
         sendCommand();
         return ReturnT.SUCCESS;
     }
 
+    @PostConstruct
+    public void test(){
+        redisUtil.set("test", "111");
+        redisUtil.setExpire("test", 10);
+    }
+
     /**
     * 发送物联网命令
     * @author Andy

+ 16 - 7
zoniot-water/zoniot-water-xxl-client/src/main/java/com/zcxk/water/xxl/mq/DispatchReportHandler.java

@@ -15,6 +15,7 @@ import com.zcxk.water.core.entity.MonitorDataEntity;
 import com.zcxk.water.core.entity.MonitorDataValueEntity;
 import com.zcxk.water.core.entity.mongo.DispatchPlanDataEntity;
 import com.zcxk.water.core.entity.mongo.DispatchPlanReportEntity;
+import com.zcxk.water.xxl.common.Constants;
 import com.zcxk.water.xxl.common.RedisConstants;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang.StringUtils;
@@ -54,7 +55,15 @@ public class DispatchReportHandler {
     @Resource
     private DispatchPlanClient dispatchPlanClient;
 
-    private static String HOUR = "%s:00:00";
+    /**
+     * 2小时
+     */
+    private static int HOURS_2 = 60 * 60 * 2;
+
+    /**
+     * 2天
+     */
+    private static int DAYS_2  = 60 * 60 * 24 * 2;
 
     @Async
     public void handler(MonitorDataEntity monitorDataEntity, JSONObject receiveData, Date receiveDateTime) {
@@ -88,26 +97,26 @@ public class DispatchReportHandler {
                 dispatchPlanDataEntity.setReportTime(receiveDateTime);
                 dispatchPlanDataEntity.setValueType(deviceParmEntity.getParmType() == 2 ? ValueTypeEnum.BOOLEAN.getCode() : ValueTypeEnum.NUMBER.getCode());
                 dispatchPlanDataDao.saveDispatchPlan(dispatchPlanDataEntity);
-                saveReport(dispatchPlanDataEntity);
+                this.saveReport(dispatchPlanDataEntity);
             }
         }
     }
 
     private void saveReport(DispatchPlanDataEntity dispatchPlanDataEntity){
-        String md5Key       = String.format(RedisConstants.DISPATCH_PLAN_DATA, getMd5ByCurrentTime(dispatchPlanDataEntity));
+        String md5Key       = String.format(RedisConstants.DISPATCH_PLAN_DATA, getMd5ByCurrentHour(dispatchPlanDataEntity));
         String md5LastKey   = String.format(RedisConstants.DISPATCH_PLAN_LAST_DATA, getMd5(dispatchPlanDataEntity));
         String value = redisUtil.get(md5Key);
         redisUtil.set(md5LastKey, dispatchPlanDataEntity.getDataValue());
-        redisUtil.setExpire(md5LastKey, 10 * 1000);
+        redisUtil.setExpire(md5LastKey, DAYS_2);
         if (StringUtils.isNotEmpty(value)) {
             return;
         }
         redisUtil.set(md5Key, dispatchPlanDataEntity.getDataValue());
-        redisUtil.setExpire(md5Key, 1000 * 10 );
+        redisUtil.setExpire(md5Key, HOURS_2 );
         DispatchPlanReportEntity dispatchPlanReportEntity = new DispatchPlanReportEntity();
         BeanCopyUtils.copyProperties(dispatchPlanDataEntity, dispatchPlanReportEntity, DispatchPlanReportEntity.class);
         dispatchPlanReportEntity.setStatDay(DateUtil.getDate(new Date()));
-        dispatchPlanReportEntity.setStatHour(String.format(HOUR, DateUtil.getHour()));
+        dispatchPlanReportEntity.setStatHour(String.format(Constants.HOUR, DateUtil.getHour()));
         dispatchPlanReportDao.saveReportEntity(dispatchPlanReportEntity);
     }
 
@@ -118,7 +127,7 @@ public class DispatchReportHandler {
         return Md5.hash(builder.toString());
     }
 
-    protected String getMd5ByCurrentTime(DispatchPlanDataEntity entity){
+    protected String getMd5ByCurrentHour(DispatchPlanDataEntity entity){
         StringBuilder builder = new StringBuilder();
         builder.append(entity.getTenantId()).append(entity.getDeviceId()).append(entity.getDeviceCode())
                 .append(entity.getAttributeId()).append(entity.getParamType()).append(DateUtil.getHour());