ソースを参照

基础信息同步bug处理

jingyuanchao 1 年間 前
コミット
ccccc83862

+ 13 - 8
soc-modules/soc-modules-host/src/main/java/com/xunmei/host/iot/service/impl/IotDeviceInfoServiceImpl.java

@@ -173,10 +173,10 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
     private void updateCache(IotDeviceInfo info, int type) {
         String key = "";
         if (type == 1) {
-            key = DeviceCacheEnum.IOT_BASE_DEVICE_INFO.getCode() + info.getIotToken() + "_" + info.getDeviceType() + "_" + info.getDeviceCode();
+            key = DeviceCacheEnum.IOT_BASE_DEVICE_INFO.getCode() + info.getIotToken() + "_" + info.getDeviceType() + "_" + info.getDeviceType() + "_" + info.getDeviceCode();
         }
         if (type == 2) {
-            key = DeviceCacheEnum.IOT_CHANNEL_INFO.getCode() + info.getIotToken() + "_" + info.getHostCode() + "_" + info.getDeviceCode();
+            key = DeviceCacheEnum.IOT_CHANNEL_INFO.getCode() + info.getIotToken() + "_" + info.getHostCode() + "_" + info.getDeviceType() + "_" + info.getDeviceCode();
         }
         RedisUtils.setCacheObject(key, info, Duration.ofMillis(1000 * 60 * 60));
     }
@@ -257,11 +257,11 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
 
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public void deviceStatusChange(List<DeviceStatusInfo> statusInfos,IotServerInfo serverInfo) {
+    public void deviceStatusChange(List<DeviceStatusInfo> statusInfos, IotServerInfo serverInfo) {
         if (ObjectUtil.isEmpty(statusInfos)) {
             return;
         }
-        for (DeviceStatusInfo statusInfo : statusInfos){
+        for (DeviceStatusInfo statusInfo : statusInfos) {
 
             IotDeviceInfo deviceInfo = this.selectByTokenProductAndDeviceCode(serverInfo.getIotCode(), statusInfo.getProductName(), statusInfo.getDeviceCode());
             if (ObjectUtil.isEmpty(deviceInfo)) {
@@ -303,7 +303,7 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
         Object data = req.getData();
         JSONArray dataArray = (JSONArray) data;
         if (ObjectUtil.isEmpty(dataArray)) {
-            return WebsocketResult.replySuccess(req.getTopic(),req.getId(), req.getProductName(), req.getDeviceName());
+            return WebsocketResult.replySuccess(req.getTopic(), req.getId(), req.getProductName(), req.getDeviceName());
         }
         String token = req.getToken();
         IotServerInfo serverInfo = iotServerInfoService.selectByToken(token);
@@ -322,15 +322,19 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
                 handleAlarmHostDeviceInfo(dataList, serverInfo);
                 /*lockAndExecute(lockKey, () -> handleDvsAndFSUDeviceInfo(dataList, serverInfo));
                 lockAndExecute(key, () -> handleAlarmHostDeviceInfo(dataList, serverInfo));*/
-                return WebsocketResult.replySuccess(req.getTopic(),req.getId(), req.getProductName(), req.getDeviceName());
+                return WebsocketResult.replySuccess(req.getTopic(), req.getId(), req.getProductName(), req.getDeviceName());
             case WebSocketConstants.DEVICES_STATUS_EVENT:
                 List<DeviceStatusInfo> statusInfos = dataArray.toJavaList(DeviceStatusInfo.class);
-                deviceStatusChange(statusInfos,serverInfo);
+                deviceStatusChange(statusInfos, serverInfo);
                 break;
             default:
                 break;
         }
+        /*final RedissonClient client = RedisUtils.getClient();
+        final boolean lock = client.getLock(event + req.getToken()).tryLock();
+        if (lock) {
 
+        }*/
         return null;
     }
 
@@ -505,7 +509,8 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
             }
             //处理通道或者动环传感器信息
             for (SubDeviceInfo subDeviceInfo : subDeviceList) {
-                IotDeviceInfo channelInfo = selectByTypeAndHostAndCode(serverInfo.getIotCode(), subDeviceInfo.getParentCode(), dvsBaseInfo.getProductName(), subDeviceInfo.getDeviceCode());
+                String productName = Arrays.asList(ProductEnums.FSU_GATEWAY.getProductName()).contains(dvsBaseInfo.getProductName()) ? subDeviceInfo.getType() : dvsBaseInfo.getProductName();
+                IotDeviceInfo channelInfo = selectByTypeAndHostAndCode(serverInfo.getIotCode(), subDeviceInfo.getParentCode(), productName, subDeviceInfo.getDeviceCode());
 
                 if (ObjectUtil.isNull(channelInfo)) {
                     IotDeviceInfo channel = createChannelInfo(subDeviceInfo, serverInfo, hostInfo);