jingyuanchao 11 сар өмнө
parent
commit
7b84440e9c

+ 3 - 0
soc-api/soc-api-system/src/main/java/com/xunmei/system/api/domain/iot/IotDeviceInfo.java

@@ -41,4 +41,7 @@ public class IotDeviceInfo extends BaseEntity {
 
     @ApiModelProperty("0:启用,1:禁用")
     private Integer enable;
+
+    @ApiModelProperty(value = "同步状态",notes = "0:未同步,1:下发中,2:下发成功,3:下发失败")
+    private Integer syncStatus;
 }

+ 1 - 0
soc-common/soc-common-redis/src/main/java/com/xunmei/common/redis/enums/RedisDelayQueueEnum.java

@@ -14,6 +14,7 @@ import lombok.NoArgsConstructor;
 public enum RedisDelayQueueEnum {
 
     WEBSOCKET_MSG_RETRY("WEBSOCKET_MSG_RETRY","websocket消息重试队列", "iotWebsocketMsgServiceImpl"),
+    DEVICE_SYNC_STATUS_MONITOR("DEVICE_SYNC_STATUS_MONITOR","设备同步状态监测", "IotDeviceInfoServiceImpl"),
 
     ;
 

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

@@ -6,6 +6,7 @@ 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;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -44,6 +45,7 @@ import com.xunmei.host.websocket.enums.DeviceCacheEnum;
 import com.xunmei.host.websocket.enums.DeviceNetStatusEnum;
 import com.xunmei.host.websocket.enums.ProductEnums;
 import com.xunmei.host.websocket.enums.TopicTypeEnums;
+import com.xunmei.host.websocket.redis.delay.RedisDelayQueueHandle;
 import com.xunmei.host.websocket.service.RouterService;
 import com.xunmei.host.websocket.service.WebsocketService;
 import com.xunmei.system.api.domain.iot.IotDeviceInfo;
@@ -69,7 +71,7 @@ import java.util.stream.Stream;
 
 @Service
 @Slf4j
-public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, IotDeviceInfo> implements IIotDeviceInfoService, RouterService {
+public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, IotDeviceInfo> implements IIotDeviceInfoService, RouterService, RedisDelayQueueHandle {
 
     @Autowired
     private IIotDeviceInfoExtendService iIotDeviceInfoExtendService;
@@ -942,12 +944,27 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
         if (ObjectUtil.isEmpty(iotCode)) {
             return;
         }
+
         final String topic = TopicTypeEnums.formatUrl(TopicTypeEnums.PRODUCT_SERVICE_INVOKE.getUrl(), WebSocketConstants.DETECTION_HOST, WebSocketConstants.DETECTION_HOST_DEVICE);
         final WebsocketResult result = WebsocketResult.invokeHostServer(topic, new JSONObject(), WebSocketConstants.CHANGE_DEVICE, eto);
         websocketService.sendMsgByTokens(result, iotCode);
     }
 
     @Override
+    public void execute(Object o) {
+        final Long deviceId = Long.valueOf(String.valueOf(o));
+        final IotDeviceInfo deviceInfo = getById(deviceId);
+        if (deviceInfo == null) {
+            return;
+        }
+        if (deviceInfo.getSyncStatus() != 2) {
+            final LambdaUpdateWrapper<IotDeviceInfo> wrapper = new LambdaUpdateWrapper<>();
+            wrapper.eq(IotDeviceInfo::getId, deviceId);
+            wrapper.set(IotDeviceInfo::getSyncStatus, 3);
+        }
+    }
+
+    @Override
     public void syncDeviceToHost(Long id) {
         final IotDeviceInfo deviceInfo = getById(id);
         if (ObjectUtil.isEmpty(deviceInfo)) {

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

@@ -206,9 +206,6 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
         if (deviceId == null) {
             IotDeviceInfo deviceInfo = new IotDeviceInfo();
             buildDeviceInfo(deviceInfo, req, sysOrg);
-            deviceInfo.setId(IdWorker.getId());
-            deviceInfo.setCreateTime(new Date());
-            deviceInfo.setCreateBy(SecurityUtils.getLoginUser().getSysUser().getId().toString());
             effect = baseMapper.insert(deviceInfo);
             deviceId = deviceInfo.getId();
         } else {
@@ -227,24 +224,29 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
         deviceInfo.setDeviceName(req.getDeviceName());
         deviceInfo.setDeviceType(BaseDeviceTypeEnum.Dvs.getCode());
         deviceInfo.setDeviceProduct(req.getDeviceProduct());
-        if (ObjectUtil.isEmpty(deviceInfo.getDeviceCode())) {
-            deviceInfo.setDeviceCode(generalDeviceCode(BaseDeviceTypeEnum.Dvs, null));
-        }
         IotServerProduct product = baseMapper.selectProduct(req.getDeviceProduct());
         SysMultiLayerDictionary dictionary = baseMapper.selectMultiLayerDictionaryByName(product.getProducer());
         if (dictionary!=null){
             deviceInfo.setDeviceBrand(dictionary.getId());
         }
         deviceInfo.setDeviceModel(req.getModels());
-        deviceInfo.setIotToken(req.getIotCode());
-        deviceInfo.setOrgId(req.getOrgId());
         deviceInfo.setEnable(req.getEnable());
         deviceInfo.setDeleted(0);
-        deviceInfo.setNetStatus("0");
+        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());
+            deviceInfo.setCreateBy(SecurityUtils.getLoginUser().getSysUser().getId().toString());
+            deviceInfo.setId(IdWorker.getId());
+        }
         deviceInfo.setUpdateTime(new Date());
         deviceInfo.setUpdateBy(SecurityUtils.getLoginUser().getSysUser().getName());
-        deviceInfo.setOrgName(sysOrg.getShortName());
-        deviceInfo.setOrgPath(sysOrg.getPath());
+
     }
 
     @Override
@@ -418,6 +420,7 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
         deviceInfo.setIotToken(req.getIotCode());
         deviceInfo.setOrgId(req.getOrgId());
         deviceInfo.setEnable(req.getEnable());
+        deviceInfo.setSyncStatus(0);
         deviceInfo.setDeleted(0);
         deviceInfo.setCreateTime(new Date());
         deviceInfo.setUpdateTime(new Date());
@@ -496,39 +499,36 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
         final SysUser sysUser = SecurityUtils.getLoginUser().getSysUser();
         final SysOrg sysOrg = orgService.selectSysOrgById(req.getOrgId(), SecurityConstants.INNER);
         IotDeviceInfo deviceInfo;
+        final BaseDeviceTypeEnum typeEnum = BaseDeviceTypeEnum.getEnumByCode(req.getDeviceType());
+        JSONObject JSB = new JSONObject();
         if (req.getId() == null) {
             deviceInfo = new IotDeviceInfo();
             deviceInfo.setCreateTime(new Date());
             deviceInfo.setCreateBy(sysUser.getId().toString());
+            deviceInfo.setIotToken(req.getIotCode()); deviceInfo.setOrgId(sysOrg.getId());
+            deviceInfo.setOrgName(sysOrg.getShortName());
+            deviceInfo.setOrgPath(sysOrg.getPath());
+            deviceInfo.setDeleted(0);
+            switch (typeEnum) {
+                case Host_Talk:
+                    deviceInfo.setDeviceProduct("TALK_HOST");
+                    JSB.put("deviceProduct", deviceInfo.getDeviceProduct());
+                    deviceInfo.setDeviceCode(generalDeviceCode(BaseDeviceTypeEnum.Host_Talk, JSB));
+                    break;
+                case Host_Door:
+                    deviceInfo.setDeviceProduct("DOOR_HOST");
+                    JSB.put("deviceProduct", deviceInfo.getDeviceProduct());
+                    deviceInfo.setDeviceCode(generalDeviceCode(BaseDeviceTypeEnum.Host_Door, JSB));
+                    break;
+                default:
+                    break;
+            }
         } else {
             deviceInfo = getById(req.getId());
         }
         BeanUtil.copyProperties(req, deviceInfo);
-        deviceInfo.setIotToken(req.getIotCode());
-        final BaseDeviceTypeEnum typeEnum = BaseDeviceTypeEnum.getEnumByCode(req.getDeviceType());
-        JSONObject JSB = new JSONObject();
-        switch (typeEnum) {
-            case Host_Talk:
-                deviceInfo.setDeviceProduct("TALK_HOST");
-                JSB.put("deviceProduct", deviceInfo.getDeviceProduct());
-                deviceInfo.setDeviceCode(generalDeviceCode(BaseDeviceTypeEnum.Host_Talk, JSB));
-
-                break;
-            case Host_Door:
-                deviceInfo.setDeviceProduct("DOOR_HOST");
-                JSB.put("deviceProduct", deviceInfo.getDeviceProduct());
-                deviceInfo.setDeviceCode(generalDeviceCode(BaseDeviceTypeEnum.Host_Door, JSB));
-                break;
-            default:
-                break;
-        }
-
         deviceInfo.setUpdateTime(new Date());
         deviceInfo.setUpdateBy(sysUser.getId().toString());
-        deviceInfo.setOrgId(sysOrg.getId());
-        deviceInfo.setOrgName(sysOrg.getShortName());
-        deviceInfo.setOrgPath(sysOrg.getPath());
-        deviceInfo.setDeleted(0);
         saveOrUpdate(deviceInfo);
         extendService.updateNetHostExtendByDeviceId(deviceInfo.getId(), req);
         return 1;