소스 검색

设备同步 修改逻辑增加

jingyuanchao 11 달 전
부모
커밋
f873b1f78d

+ 22 - 0
soc-api/soc-api-system/src/main/java/com/xunmei/system/api/enums/DeviceSyncStatus.java

@@ -0,0 +1,22 @@
+package com.xunmei.system.api.enums;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+/**
+ * @author jingyuanchao
+ * @date 2024/11/22 10:00
+ */
+@Getter
+@AllArgsConstructor
+public enum DeviceSyncStatus {
+
+    //0:未同步,1:下发中,2:下发成功,3:下发失败
+    NOT_SYNC(0, "未同步"),
+    SYNCING(1, "下发中"),
+    SYNC_SUCCESS(2, "下发成功"),
+    SYNC_FAIL(3, "下发失败");
+    private Integer code;
+    private String desc;
+
+}

+ 1 - 1
soc-api/soc-api-system/src/main/java/com/xunmei/system/api/util/LogUtils.java

@@ -193,7 +193,7 @@ public class LogUtils {
     /**
      * 同步设备到主机
      */
-    public  static  final Logger SYNC_DEVICE_TO_HOST=LoggerFactory.getLogger("syncDeviceToHost");
+    public  static  final Logger SYNC_DEVICE =LoggerFactory.getLogger("syncDevice");
 
 
     /**

+ 9 - 18
soc-modules/soc-modules-host/src/main/java/com/xunmei/host/iot/service/impl/IotDeviceInfoExtendServiceImpl.java

@@ -4,14 +4,13 @@ import cn.hutool.core.util.ObjectUtil;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.xunmei.common.redis.utils.RedisUtils;
+import com.xunmei.common.core.constant.Constants;
 import com.xunmei.host.iot.mapper.IotDeviceInfoExtendMapper;
 import com.xunmei.host.iot.service.IIotDeviceInfoExtendService;
 import com.xunmei.system.api.domain.iot.IotDeviceInfoExtend;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
-import java.time.Duration;
 import java.util.List;
 
 @Service
@@ -27,19 +26,11 @@ public class IotDeviceInfoExtendServiceImpl extends ServiceImpl<IotDeviceInfoExt
      */
     @Override
     public IotDeviceInfoExtend selectByDeviceId(Long deviceId) {
-        String key = EXTEND_DEVICE_KEY + deviceId;
-        IotDeviceInfoExtend extend = RedisUtils.getCacheObject(key);
-        if(extend == null){
-            QueryWrapper<IotDeviceInfoExtend> qw = new QueryWrapper();
-            qw.lambda().eq(IotDeviceInfoExtend::getDeviceId, deviceId);
-            IotDeviceInfoExtend one = getOne(qw);
-            if(one != null){
-                RedisUtils.setCacheObject(key,one);
-            }
-            return one;
-        }
+        QueryWrapper<IotDeviceInfoExtend> qw = new QueryWrapper();
+        qw.lambda().eq(IotDeviceInfoExtend::getDeviceId, deviceId);
+        qw.lambda().last(Constants.LIMIT1);
 
-        return extend;
+        return getOne(qw);
     }
 
     /**
@@ -51,9 +42,9 @@ public class IotDeviceInfoExtendServiceImpl extends ServiceImpl<IotDeviceInfoExt
     public void saveIotDeviceExtends(List<IotDeviceInfoExtend> data) {
         if(ObjectUtil.isNotEmpty(data)){
             saveBatch(data);
-            for (IotDeviceInfoExtend extend : data) {
+            /*for (IotDeviceInfoExtend extend : data) {
                 RedisUtils.setCacheObject(EXTEND_DEVICE_KEY + extend.getDeviceId(),extend, Duration.ofMillis(1000 * 60 * 60));
-            }
+            }*/
         }
     }
 
@@ -66,9 +57,9 @@ public class IotDeviceInfoExtendServiceImpl extends ServiceImpl<IotDeviceInfoExt
     public void updateIotDeviceExtends(List<IotDeviceInfoExtend> data) {
         if(ObjectUtil.isNotEmpty(data)){
             updateBatchById(data);
-            for (IotDeviceInfoExtend extend : data) {
+            /*for (IotDeviceInfoExtend extend : data) {
                 RedisUtils.setCacheObject(EXTEND_DEVICE_KEY + extend.getDeviceId(),extend, Duration.ofMillis(1000 * 60 * 60));
-            }
+            }*/
         }
     }
 

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

@@ -5,7 +5,6 @@ import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.core.toolkit.IdWorker;
@@ -53,6 +52,7 @@ import com.xunmei.host.websocket.service.RouterService;
 import com.xunmei.host.websocket.service.WebsocketService;
 import com.xunmei.system.api.domain.iot.IotDeviceInfo;
 import com.xunmei.system.api.domain.iot.IotDeviceInfoExtend;
+import com.xunmei.system.api.enums.DeviceSyncStatus;
 import com.xunmei.system.api.util.LogUtils;
 import io.netty.util.internal.StringUtil;
 import lombok.extern.slf4j.Slf4j;
@@ -105,28 +105,14 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
      * @return
      */
     public IotDeviceInfo selectByTypeAndCode(String token, String deviceType, String product, String deviceCode) {
-        /**
-         * RedisUtils,加入缓存机制
-         */
-        String key = DeviceCacheEnum.IOT_BASE_DEVICE_INFO.getCode() + token + "_" + deviceType + "_" + product + "_" + deviceCode;
-        IotDeviceInfo info = RedisUtils.getCacheObject(key);
-        if (info == null) {
-            QueryWrapper<IotDeviceInfo> qw = new QueryWrapper();
-            qw.lambda()
-                    .eq(IotDeviceInfo::getIotToken, token)
-                    .eq(IotDeviceInfo::getDeviceProduct, product)
-                    .eq(IotDeviceInfo::getDeviceType, deviceType)
-                    .eq(IotDeviceInfo::getDeviceCode, deviceCode)
-                    .orderByDesc(IotDeviceInfo::getUpdateTime)
-                    .last(Constants.LIMIT1);
-            IotDeviceInfo one = getOne(qw);
-            if (one != null) {
-                updateCache(one, 1);
-                return one;
-            }
-        }
-
-        return info;
+        LambdaQueryWrapper<IotDeviceInfo> qw = new LambdaQueryWrapper<>();
+        qw.eq(IotDeviceInfo::getIotToken, token)
+                .eq(IotDeviceInfo::getDeviceProduct, product)
+                .eq(IotDeviceInfo::getDeviceType, deviceType)
+                .eq(IotDeviceInfo::getDeviceCode, deviceCode)
+                .orderByDesc(IotDeviceInfo::getUpdateTime)
+                .last(Constants.LIMIT1);
+        return baseMapper.selectOne(qw);
     }
 
     /**
@@ -136,24 +122,14 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
      * @return
      */
     public IotDeviceInfo selectByTypeAndHostAndCode(String token, String hostCode, String product, String deviceCode) {
-
-        String key = DeviceCacheEnum.IOT_CHANNEL_INFO.getCode() + token + "_" + hostCode + "_" + product + "_" + deviceCode;
-        IotDeviceInfo info = RedisUtils.getCacheObject(key);
-        if (info == null) {
-            QueryWrapper<IotDeviceInfo> qw = new QueryWrapper();
-            qw.lambda().eq(IotDeviceInfo::getIotToken, token)
-                    .eq(IotDeviceInfo::getHostCode, hostCode)
-                    .eq(IotDeviceInfo::getDeviceProduct, product)
-                    .eq(IotDeviceInfo::getDeviceCode, deviceCode)
-                    .orderByDesc(IotDeviceInfo::getUpdateTime)
-                    .last(Constants.LIMIT1);
-            IotDeviceInfo one = getOne(qw);
-            if (one != null) {
-                updateCache(one, 2);
-                return one;
-            }
-        }
-        return info;
+        LambdaQueryWrapper<IotDeviceInfo> qw = new LambdaQueryWrapper<>();
+        qw.eq(IotDeviceInfo::getIotToken, token)
+                .eq(IotDeviceInfo::getHostCode, hostCode)
+                .eq(IotDeviceInfo::getDeviceProduct, product)
+                .eq(IotDeviceInfo::getDeviceCode, deviceCode)
+                .orderByDesc(IotDeviceInfo::getUpdateTime)
+                .last(Constants.LIMIT1);
+        return baseMapper.selectOne(qw);
     }
 
     @Override
@@ -161,9 +137,9 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
     public void updateDvsDevice(List<IotDeviceInfo> data) {
         if (ObjectUtil.isNotEmpty(data)) {
             updateBatchById(data);
-            for (IotDeviceInfo info : data) {
+           /* for (IotDeviceInfo info : data) {
                 updateCache(info, 1);
-            }
+            }*/
         }
     }
 
@@ -174,9 +150,9 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
             return;
         }
         updateBatchById(channels);
-        for (IotDeviceInfo info : channels) {
+        /*for (IotDeviceInfo info : channels) {
             updateCache(info, 2);
-        }
+        }*/
     }
 
     @Override
@@ -186,9 +162,9 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
             return;
         }
         saveBatch(data);
-        for (IotDeviceInfo info : data) {
+        /*for (IotDeviceInfo info : data) {
             updateCache(info, 1);
-        }
+        }*/
     }
 
     @Override
@@ -198,9 +174,9 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
             return;
         }
         saveBatch(data);
-        for (IotDeviceInfo info : data) {
+        /*for (IotDeviceInfo info : data) {
             updateCache(info, 2);
-        }
+        }*/
     }
 
 
@@ -250,9 +226,9 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
     public void saveHostDevice(List<IotDeviceInfo> data) {
         if (ObjectUtil.isNotEmpty(data)) {
             saveBatch(data);
-            for (IotDeviceInfo info : data) {
+            /*for (IotDeviceInfo info : data) {
                 updateCache(info, 1);
-            }
+            }*/
         }
     }
 
@@ -261,9 +237,9 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
     public void updateHostDevice(List<IotDeviceInfo> data) {
         if (ObjectUtil.isNotEmpty(data)) {
             updateBatchById(data);
-            for (IotDeviceInfo info : data) {
+            /*for (IotDeviceInfo info : data) {
                 updateCache(info, 1);
-            }
+            }*/
         }
     }
 
@@ -355,6 +331,7 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
         //设备状态数据
         result.add(WebSocketConstants.DEVICES_STATUS_EVENT);
         result.add(WebSocketConstants.INCREMENT_DEVICES_EVENT);
+        result.add(WebSocketConstants.INCREMENT_DEVICES_RESULT_EVENT);
         return result.toString();
     }
 
@@ -408,22 +385,23 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
 
     private void dealPushDeviceResult(Object obj) {
         final DevicePushResult result = JSON.parseObject(obj.toString(), DevicePushResult.class);
-        LogUtils.WEBSOCKET_MSG.info("主机上报处理平台下发设备{}结果:{}", result.getDeviceName(), result);
+        LogUtils.SYNC_DEVICE.info("主机上报处理平台下发设备{}结果:{}", result.getDeviceName(), result);
         if (BaseDeviceTypeEnum.Dvs.name().equals(result.getDeviceType()) && WebSocketConstants.INSERT.equals(result.getPushType())) {
             //新增DVR的上报结果不在这里处理, 需要等待摄像头上报后修改设备同步状态
+            //如果新增DVR失败,那么会等redis延迟队列去处理设备的同步状态为失败
             return;
         }
         if (ObjectUtil.equal(result.getStatusCode(), HttpStatus.SUCCESS)) {
-            updateDeviceSyncStatus(result.getDeviceId(), 2);
+            updateDeviceSyncStatus(result.getDeviceId(), DeviceSyncStatus.SYNC_SUCCESS);
         } else {
-            updateDeviceSyncStatus(result.getDeviceId(), 3);
+            updateDeviceSyncStatus(result.getDeviceId(), DeviceSyncStatus.SYNC_FAIL);
         }
     }
 
-    private void updateDeviceSyncStatus(Long id, int status) {
+    private void updateDeviceSyncStatus(Long id, DeviceSyncStatus status) {
         if (RedisDelayedQueueUtil.removeDelayedQueue(id, RedisDelayQueueEnum.DEVICE_SYNC_STATUS_MONITOR.getCode())) {
             final LambdaUpdateWrapper<IotDeviceInfo> wrapper = new LambdaUpdateWrapper<>();
-            wrapper.eq(IotDeviceInfo::getId, id).set(IotDeviceInfo::getSyncStatus, status);
+            wrapper.eq(IotDeviceInfo::getId, id).set(IotDeviceInfo::getSyncStatus, status.getCode());
             baseMapper.update(null, wrapper);
         }
     }
@@ -443,7 +421,7 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
             updateHostInfo(baseInfo, hostInfo, code);
             updateById(hostInfo);
         }
-        updateCache(hostInfo, 1);
+        //updateCache(hostInfo, 1);
         //删除主机扩展信息
         iIotDeviceInfoExtendService.deletedExtendByDeviceId(hostInfo.getId());
 
@@ -471,9 +449,9 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
                 updateChannelInfo(subDeviceInfo, channelInfo, hostInfo);
                 updateChnnelList.add(channelInfo);
             }
-            updateCache(channelInfo, 2);
+           // updateCache(channelInfo, 2);
         }
-        updateDeviceSyncStatus(hostInfo.getId(), 2);
+        updateDeviceSyncStatus(hostInfo.getId(), DeviceSyncStatus.SYNC_SUCCESS);
         batchDealIotDeviceInfo(Lists.newLinkedList(), addChnnelList, true);
         batchDealIotDeviceInfo(Lists.newLinkedList(), updateChnnelList, false);
     }
@@ -822,9 +800,9 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
         if (collect.isEmpty()) {
             return;
         }
-        for (IotDeviceInfo info : collect) {
+       /* for (IotDeviceInfo info : collect) {
             updateCache(info, 1);
-        }
+        }*/
 
     }
 
@@ -833,9 +811,9 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
         if (collect.isEmpty()) {
             return;
         }
-        for (IotDeviceInfo info : collect) {
+        /*for (IotDeviceInfo info : collect) {
             updateCache(info, 2);
-        }
+        }*/
     }
 
     private IotAlarmSubsystem createAlarmSubSystem(SubDeviceInfo subSystemInfo, IotServerInfo serverInfo) {
@@ -985,11 +963,12 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
         if (deviceInfo == null) {
             return;
         }
-        if (deviceInfo.getSyncStatus() != 2) {
+        if (!Objects.equals(deviceInfo.getSyncStatus(), DeviceSyncStatus.SYNC_SUCCESS.getCode())) {
             final LambdaUpdateWrapper<IotDeviceInfo> wrapper = new LambdaUpdateWrapper<>();
             wrapper.eq(IotDeviceInfo::getId, deviceId);
-            wrapper.set(IotDeviceInfo::getSyncStatus, 3);
+            wrapper.set(IotDeviceInfo::getSyncStatus, DeviceSyncStatus.SYNC_FAIL.getCode());
             baseMapper.update(null, wrapper);
+            LogUtils.SYNC_DEVICE.info("延迟队列任务触发,修改设备[ {} ]同步状态为失败", deviceInfo.getDeviceName());
         }
     }
 
@@ -997,7 +976,7 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
     public void syncDeviceToHost(Long id) {
         final IotDeviceInfo deviceInfo = getById(id);
         if (ObjectUtil.isEmpty(deviceInfo)) {
-            LogUtils.SYNC_DEVICE_TO_HOST.error("设备信息为空,id:{}", id);
+            LogUtils.SYNC_DEVICE.error("设备信息为空,id:{}", id);
         }
         final BaseDeviceTypeEnum deviceTypeEnum = BaseDeviceTypeEnum.getEnumByCode(deviceInfo.getDeviceType());
         JSONObject param = null;
@@ -1022,15 +1001,11 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
         final WebsocketResult result = WebsocketResult.invokeHostServer(topic, new JSONObject(), WebSocketConstants.PUSH_DEVICES_SERVICES, param);
         websocketService.sendMsgByTokens(result, deviceInfo.getIotToken());
         monitorSyncStatus(deviceInfo);
+        LogUtils.SYNC_DEVICE.info("同步设备[ {} ]至主机 [ {} ],设备类型:{}", deviceInfo.getDeviceName(), deviceInfo.getIotToken(), deviceTypeEnum.getDesc());
     }
 
     private void monitorSyncStatus(IotDeviceInfo deviceInfo) {
         final LocalDateTime time = LocalDateTime.now().plusMinutes(5);
-  /*      final JSONObject object = new JSONObject();
-        object.put("deviceId", deviceInfo.getId());
-        object.put("iotCode", deviceInfo.getId());
-        object.put("deviceProduct", deviceInfo.getId());
-        object.put("deviceCode", deviceInfo.getId());*/
         RedisDelayedQueueUtil.addDelayQueue(deviceInfo.getId(), time, RedisDelayQueueEnum.DEVICE_SYNC_STATUS_MONITOR.getCode());
     }
 
@@ -1041,6 +1016,7 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
 
     private JSONObject deviceInfoToJSB(IotDeviceInfo iotDeviceInfo, IotDeviceInfoExtend extend) {
         JSONObject jsonObject = new JSONObject();
+        jsonObject.put("deviceId", iotDeviceInfo.getId());
         jsonObject.put("deviceType", BaseDeviceTypeEnum.Dvs.name());
         jsonObject.put("deviceProduct", iotDeviceInfo.getDeviceProduct());
         final SysMultiLayerDictionary dictionary = baseMapper.selectSysMultiLayerDictionaryById(iotDeviceInfo.getDeviceBrand());

+ 5 - 14
soc-modules/soc-modules-host/src/main/java/com/xunmei/host/protection/service/impl/IotAlarmDefenceAreaServiceImpl.java

@@ -268,16 +268,7 @@ public class IotAlarmDefenceAreaServiceImpl extends ServiceImpl<IotAlarmDefenceA
 
     @Override
     public IotAlarmDefenceArea getBySubSystemCodeAndDeviceName(String iotToken, String deviceName, String subSystemId, String inputIndex) {
-        String key = DeviceCacheEnum.IOT_DEFENCE_AREA.getCode() + iotToken + "_" + deviceName + "_" + subSystemId + "_" + inputIndex;
-        IotAlarmDefenceArea info = RedisUtils.getCacheObject(key);
-        if (info == null){
-            IotAlarmDefenceArea defenceArea = iotAlarmDefenceAreaMapper.getBySubSystemCodeAndDeviceName(iotToken, deviceName, String.valueOf(subSystemId),Integer.parseInt(inputIndex));
-            if (defenceArea != null){
-                updateDefenceAreaCache(defenceArea);
-                return defenceArea;
-            }
-        }
-        return info;
+        return iotAlarmDefenceAreaMapper.getBySubSystemCodeAndDeviceName(iotToken, deviceName, String.valueOf(subSystemId),Integer.parseInt(inputIndex));
     }
 
     @Override
@@ -285,9 +276,9 @@ public class IotAlarmDefenceAreaServiceImpl extends ServiceImpl<IotAlarmDefenceA
     public void saveDefenceAreaInfos(List<IotAlarmDefenceArea> list) {
         if (!list.isEmpty()){
             saveBatch(list);
-            for (IotAlarmDefenceArea data : list) {
+            /*for (IotAlarmDefenceArea data : list) {
                 updateDefenceAreaCache(data);
-            }
+            }*/
         }
     }
 
@@ -296,9 +287,9 @@ public class IotAlarmDefenceAreaServiceImpl extends ServiceImpl<IotAlarmDefenceA
     public void updateDefenceAreaInfos(List<IotAlarmDefenceArea> list) {
         if (!list.isEmpty()){
             updateBatchById(list);
-            for (IotAlarmDefenceArea data : list) {
+            /*for (IotAlarmDefenceArea data : list) {
                 updateDefenceAreaCache(data);
-            }
+            }*/
         }
     }
 

+ 10 - 27
soc-modules/soc-modules-host/src/main/java/com/xunmei/host/protection/service/impl/IotAlarmHostServiceImpl.java

@@ -4,6 +4,7 @@ import cn.hutool.core.util.ObjectUtil;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.google.common.collect.Lists;
 import com.xunmei.common.core.constant.ErrorMsgConstants;
@@ -14,7 +15,6 @@ import com.xunmei.common.core.enums.iot.DeviceTypeEnum;
 import com.xunmei.common.core.util.BeanHelper;
 import com.xunmei.common.core.utils.IDHelper;
 import com.xunmei.common.core.utils.JacksonUtils;
-import com.xunmei.common.redis.utils.RedisUtils;
 import com.xunmei.host.alarm.mapper.IotAlarmDataMapper;
 import com.xunmei.host.alarm.mapper.IotAlarmSystemFieldMapper;
 import com.xunmei.host.enums.AlarmDataTypeEnum;
@@ -31,7 +31,6 @@ import com.xunmei.host.protection.vo.IotPropertiesRes;
 import com.xunmei.host.websocket.constant.WebSocketConstants;
 import com.xunmei.host.websocket.dto.WebsocketExecuteReq;
 import com.xunmei.host.websocket.dto.WebsocketResult;
-import com.xunmei.host.websocket.enums.DeviceCacheEnum;
 import com.xunmei.host.websocket.enums.ProductEnums;
 import com.xunmei.host.websocket.service.RouterService;
 import com.xunmei.host.websocket.utils.WebSocketUtils;
@@ -50,7 +49,6 @@ import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
 import java.io.Serializable;
-import java.time.Duration;
 import java.time.LocalDateTime;
 import java.util.*;
 
@@ -337,7 +335,7 @@ public class IotAlarmHostServiceImpl implements IIotAlarmHostService, RouterServ
     }
 
     @Override
-    @Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRES_NEW)
+    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
     public WebsocketResult execute(WebsocketExecuteReq req) {
         final String event = req.getEvent();
         JSONObject jsb;
@@ -623,29 +621,14 @@ public class IotAlarmHostServiceImpl implements IIotAlarmHostService, RouterServ
     }
 
     private IotAlarmDefenceArea selectByTypeAndCode(String token, String deviceType, String product, String deviceCode, String moduleAddress, String index) {
-        /**
-         * RedisUtils,加入缓存机制
-         */
-        String key = DeviceCacheEnum.IOT_BASE_DEVICE_INFO.getCode() + token + "_" + deviceType + "_" + product + "_" + deviceCode + "_" + moduleAddress + "_" + index;
-        IotAlarmDefenceArea info = RedisUtils.getCacheObject(key);
-        if (info == null) {
-            QueryWrapper<IotAlarmDefenceArea> qw = new QueryWrapper();
-            qw.lambda()
-                    .eq(IotAlarmDefenceArea::getIotToken, token)
-                    .eq(IotAlarmDefenceArea::getAlarmHostCode, deviceCode)
-                    .eq(IotAlarmDefenceArea::getModuleAddress, moduleAddress)
-                    .eq(IotAlarmDefenceArea::getDefenceAreaIndex, index)
-                    .eq(IotAlarmDefenceArea::getDeleted, 0)
-                    .last("limit 1");
-            IotAlarmDefenceArea one = iotAlarmDefenceAreaMapper.selectOne(qw);
-            if (one != null) {
-                //更新缓存
-                RedisUtils.setCacheObject(key, one, Duration.ofMillis(1000 * 60 * 60));
-                return one;
-            }
-        }
-
-        return info;
+        LambdaQueryWrapper<IotAlarmDefenceArea> qw = new LambdaQueryWrapper<>();
+        qw.eq(IotAlarmDefenceArea::getIotToken, token)
+                .eq(IotAlarmDefenceArea::getAlarmHostCode, deviceCode)
+                .eq(IotAlarmDefenceArea::getModuleAddress, moduleAddress)
+                .eq(IotAlarmDefenceArea::getDefenceAreaIndex, index)
+                .eq(IotAlarmDefenceArea::getDeleted, 0)
+                .last("limit 1");
+        return iotAlarmDefenceAreaMapper.selectOne(qw);
     }
 
 

+ 5 - 14
soc-modules/soc-modules-host/src/main/java/com/xunmei/host/protection/service/impl/IotAlarmSubSystemServiceImpl.java

@@ -243,16 +243,7 @@ public class IotAlarmSubSystemServiceImpl extends ServiceImpl<IotAlarmSubsystemM
 
     @Override
     public IotAlarmSubsystem getByDeviceNameAndSubSystemId(String iotToken, String deviceName, String subSystemId) {
-        String key = DeviceCacheEnum.IOT_SUB_SYSTEM.getCode() + iotToken + "_" + deviceName + "_" + subSystemId;
-        IotAlarmSubsystem info = RedisUtils.getCacheObject(key);
-        if (info == null) {
-            IotAlarmSubsystem subsystem = iotAlarmSubsystemMapper.getByDeviceNameAndSubSystemId(iotToken, deviceName, String.valueOf(subSystemId));
-            if (subsystem != null) {
-                updateSubSystemCache(subsystem);
-                return subsystem;
-            }
-        }
-        return info;
+        return  iotAlarmSubsystemMapper.getByDeviceNameAndSubSystemId(iotToken, deviceName, String.valueOf(subSystemId));
     }
 
     @Override
@@ -260,9 +251,9 @@ public class IotAlarmSubSystemServiceImpl extends ServiceImpl<IotAlarmSubsystemM
     public void saveSubSystemInfos(List<IotAlarmSubsystem> list) {
         if (!list.isEmpty()) {
             saveBatch(list);
-            for (IotAlarmSubsystem data : list) {
+           /* for (IotAlarmSubsystem data : list) {
                 updateSubSystemCache(data);
-            }
+            }*/
         }
     }
 
@@ -271,9 +262,9 @@ public class IotAlarmSubSystemServiceImpl extends ServiceImpl<IotAlarmSubsystemM
     public void updateSubSystemInfos(List<IotAlarmSubsystem> list) {
         if (!list.isEmpty()) {
             updateBatchById(list);
-            for (IotAlarmSubsystem data : list) {
+           /* for (IotAlarmSubsystem data : list) {
                 updateSubSystemCache(data);
-            }
+            }*/
         }
     }
 

+ 4 - 4
soc-modules/soc-modules-host/src/main/resources/logback.xml

@@ -252,11 +252,11 @@
     </appender>
 
     <!--  同步设备到主机  -->
-    <appender name="syncDeviceToHost" class="ch.qos.logback.core.rolling.RollingFileAppender">
+    <appender name="syncDevice" class="ch.qos.logback.core.rolling.RollingFileAppender">
         <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
             <maxFileSize>${max.file.size}</maxFileSize>
             <!--日志文件输出的文件名-->
-            <FileNamePattern>${LOG_HOME}/syncDeviceToHost/%d{yyyy-MM-dd}-%i.log</FileNamePattern>
+            <FileNamePattern>${LOG_HOME}/syncDevice/%d{yyyy-MM-dd}-%i.log</FileNamePattern>
             <!--日志文件保留天数-->
             <maxHistory>${max.history}</maxHistory>
             <totalSizeCap>${total.size.cap}</totalSizeCap>
@@ -342,9 +342,9 @@
         <!--上面appender元素的name值。为了和logger的name属性做区分,我故意写的不一样-->
         <appender-ref ref="wsMsgRetryLog"/>
     </logger>
-    <logger name="syncDeviceToHost" additivity="false" level="info">
+    <logger name="syncDevice" additivity="false" level="info">
         <!--上面appender元素的name值。为了和logger的name属性做区分,我故意写的不一样-->
-        <appender-ref ref="wsMsgRetryLog"/>
+        <appender-ref ref="syncDevice"/>
     </logger>
 
     <logger name="socketDvsTemplateLog" additivity="false" level="info">

+ 4 - 3
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/service/impl/IotDeviceInfoServiceImpl.java

@@ -39,6 +39,7 @@ import com.xunmei.system.api.domain.SysOrg;
 import com.xunmei.system.api.domain.SysUser;
 import com.xunmei.system.api.domain.iot.IotDeviceInfo;
 import com.xunmei.system.api.domain.iot.IotDeviceInfoExtend;
+import com.xunmei.system.api.enums.DeviceSyncStatus;
 import org.redisson.api.RLock;
 import org.redisson.api.RedissonClient;
 import org.springframework.beans.BeanUtils;
@@ -233,12 +234,12 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
         deviceInfo.setDeviceModel(req.getModels());
         deviceInfo.setEnable(req.getEnable());
         deviceInfo.setDeleted(0);
+        deviceInfo.setSyncStatus(DeviceSyncStatus.NOT_SYNC.getCode());
         if (deviceInfo.getId()==null){
             deviceInfo.setOrgId(req.getOrgId());
             deviceInfo.setOrgName(sysOrg.getShortName());
             deviceInfo.setOrgPath(sysOrg.getPath());
             deviceInfo.setNetStatus("0");
-            deviceInfo.setSyncStatus(0);
             deviceInfo.setIotToken(req.getIotCode());
             deviceInfo.setDeviceCode(generalDeviceCode(BaseDeviceTypeEnum.Dvs, null));
             deviceInfo.setCreateTime(new Date());
@@ -421,7 +422,7 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
         deviceInfo.setIotToken(req.getIotCode());
         deviceInfo.setOrgId(req.getOrgId());
         deviceInfo.setEnable(req.getEnable());
-        deviceInfo.setSyncStatus(0);
+        deviceInfo.setSyncStatus(DeviceSyncStatus.NOT_SYNC.getCode());
         deviceInfo.setDeleted(0);
         deviceInfo.setCreateTime(new Date());
         deviceInfo.setUpdateTime(new Date());
@@ -556,7 +557,7 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
     public Integer syncDevice(Long id) {
         final LambdaUpdateWrapper<IotDeviceInfo> wrapper = new LambdaUpdateWrapper<>();
         wrapper.eq(IotDeviceInfo::getId, id);
-        wrapper.set(IotDeviceInfo::getSyncStatus, 1);
+        wrapper.set(IotDeviceInfo::getSyncStatus, DeviceSyncStatus.SYNCING.getCode());
         baseMapper.update(null,wrapper);
         remoteHostService.syncDeviceToHost(id);
         return 1;