Przeglądaj źródła

维护在离线状态

xucaiqin 2 lat temu
rodzic
commit
dd890c7b0a

+ 1 - 0
iot-framework/iot-starter-redis/src/main/java/com/middle/platform/redis/constant/CacheConstant.java

@@ -12,6 +12,7 @@ public interface CacheConstant {
     String TOPIC_CACHE = "topic:%s";
     String PRODUCT_CACHE = "product:%s:%s";
     String DEVICE_CACHE = "device:%s";
+    String ONLINE_CACHE = "online:%s";
     String MOD_CACHE = "mod:%s";
     String CLOUD_CACHE = "cloud:%s";
 

+ 1 - 0
iot-module/iot-module-data/iot-module-data-biz/src/main/java/com/middle/platform/data/biz/service/DataAnalyseService.java

@@ -36,6 +36,7 @@ public class DataAnalyseService {
      * @param payload
      */
     public void rawData(String msgId, ProductVo productVo, Object payload) {
+        cacheService.setKey(String.format(CacheConstant.ONLINE_CACHE, productVo.getGuid()), LocalDateTime.now());
         Object o = cacheService.getKey(String.format(CacheConstant.TD_ORG_CACHE, productVo.getCode(), productVo.getGuid()));
         if (Objects.isNull(o)) {
             taosMapper.createOriginalTable(productVo.getGuid(), productVo.getCode());

+ 8 - 0
iot-module/iot-module-manage/iot-module-manage-biz/src/main/java/com/middle/platform/manage/biz/service/IotDeviceService.java

@@ -66,6 +66,10 @@ public class IotDeviceService {
         iotProductVos.forEach(a -> {
             Optional.ofNullable(userApi.queryUser(a.getCreateBy())).ifPresent(userCache -> a.setCreateByLabel(userCache.getName()));
             Optional.ofNullable(userApi.queryUser(a.getUpdateBy())).ifPresent(userCache -> a.setUpdateByLabel(userCache.getName()));
+            Optional.ofNullable(cacheService.getKey(String.format(CacheConstant.ONLINE_CACHE, a.getGuid()))).ifPresent(t -> {
+                a.setOnlineTime((LocalDateTime) t);
+                a.setStatus(1);
+            });
         });
         return new PageRes<>(pageInfo, iotProductVos);
     }
@@ -154,6 +158,10 @@ public class IotDeviceService {
         Optional.ofNullable(dictApi.query(DictType.REPORT_PROTOCOL_TYPE, String.valueOf(detail.getReportProtocol()))).ifPresent(cache -> detail.setReportProtocolLabel(cache.getLabel()));
         Optional.ofNullable(dictApi.query(DictType.VENDORS_TYPE, String.valueOf(detail.getVendors()))).ifPresent(cache -> detail.setVendorsLabel(cache.getLabel()));
         Optional.ofNullable(dictApi.query(DictType.DATA_FORMAT_TYPE, String.valueOf(detail.getDataFormat()))).ifPresent(cache -> detail.setDataFormatLabel(cache.getLabel()));
+        Optional.ofNullable(cacheService.getKey(String.format(CacheConstant.ONLINE_CACHE, detail.getGuid()))).ifPresent(t -> {
+            detail.setOnlineTime((LocalDateTime) t);
+            detail.setStatus(1);
+        });
         return detail;
     }