Kaynağa Gözat

设备同步:新增页面通道信息编辑

jingyuanchao 11 ay önce
ebeveyn
işleme
a35cc57f51

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

@@ -686,6 +686,7 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
         info.setDeviceProduct(baseInfo.getProductName());
         info.setDeviceType(type);
         info.setNetStatus("0");
+        info.setSyncStatus(DeviceSyncStatus.SYNC_SUCCESS.getCode());
         info.setIotToken(serverInfo.getIotCode());
         info.setDeviceName(baseInfo.getDeviceName());
         info.setOrgName(serverInfo.getOrgName());
@@ -707,6 +708,7 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
         info.setDeviceProduct(baseInfo.getProductName());
         info.setDeviceType(type);
         info.setNetStatus("0");
+        info.setSyncStatus(DeviceSyncStatus.SYNC_SUCCESS.getCode());
         info.setDeviceName(baseInfo.getDeviceName());
         info.setUpdateTime(new Date());
         info.setUpdateBy("system");
@@ -732,6 +734,7 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
         info.setOrgName(serverInfo.getOrgName());
         info.setOrgPath(serverInfo.getOrgPath());
         info.setNetStatus("0");
+        info.setSyncStatus(DeviceSyncStatus.SYNC_SUCCESS.getCode());
         info.setUpdateBy("system");
         info.setCreateTime(new Date());
         info.setCreateBy("system");
@@ -745,6 +748,7 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
         channelInfo.setEnable(subDeviceInfo.getIsDeleted());
         channelInfo.setDeviceName(subDeviceInfo.getDeviceName());
         channelInfo.setUpdateTime(new Date());
+        channelInfo.setSyncStatus(DeviceSyncStatus.SYNC_SUCCESS.getCode());
         BaseDeviceTypeEnum baseDeviceTypeEnum = BaseDeviceTypeEnum.valueOf(subDeviceInfo.getSubType());
         channelInfo.setDeviceType(baseDeviceTypeEnum.getCode());
         if (ObjectUtil.equal(ProductEnums.FSU_GATEWAY, ProductEnums.getByProductByName(hostInfo.getDeviceProduct()))) {

+ 1 - 3
soc-modules/soc-modules-host/src/main/java/com/xunmei/host/websocket/service/impl/WebsocketServiceImpl.java

@@ -2,7 +2,6 @@ package com.xunmei.host.websocket.service.impl;
 
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
-import com.xunmei.common.core.domain.iot.domain.IotWebsocketMsg;
 import com.xunmei.common.redis.utils.RedisUtils;
 import com.xunmei.host.north.service.IotWebsocketMsgService;
 import com.xunmei.host.websocket.constant.WebSocketConstants;
@@ -41,8 +40,7 @@ public class WebsocketServiceImpl implements WebsocketService {
         }
         LogUtils.WEBSOCKET_MSG.info("获取设备基础信息,目标主机code:{}", JSON.toJSONString(set));
         for (String token : set) {
-            final IotWebsocketMsg iotWebsocketMsg = websocketMsgService.proactiveSendAndSaveMsg(token, result);
-            sendMsgByTokens(iotWebsocketMsg, token);
+            sendMsgByTokens(result, token);
         }
     }
 

+ 5 - 0
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/dto/deviceInfo/EditDvrHostDeviceDto.java

@@ -1,10 +1,14 @@
 package com.xunmei.iot.dto.deviceInfo;
 
+import com.xunmei.iot.vo.deviceInfo.ChannelInfoVo;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.AllArgsConstructor;
 import lombok.Data;
 import lombok.NoArgsConstructor;
 
+import java.util.ArrayList;
+import java.util.List;
+
 @Data
 @NoArgsConstructor
 @AllArgsConstructor
@@ -43,4 +47,5 @@ public class EditDvrHostDeviceDto {
     @ApiModelProperty(value = "是否启用",notes = "0:未启用 1:启用")
     private Integer enable;
 
+    private List<ChannelInfoVo> childrenInfos = new ArrayList<>();
 }

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

@@ -29,10 +29,7 @@ import com.xunmei.iot.mapper.IotDeviceInfoMapper;
 import com.xunmei.iot.mapper.IotServerProductMapper;
 import com.xunmei.iot.service.IIotDeviceInfoService;
 import com.xunmei.iot.service.IotDeviceInfoExtendService;
-import com.xunmei.iot.vo.deviceInfo.DeviceDetailInfoVo;
-import com.xunmei.iot.vo.deviceInfo.DvrHostDeviceInfoVo;
-import com.xunmei.iot.vo.deviceInfo.IotDeviceInfoPageVo;
-import com.xunmei.iot.vo.deviceInfo.NetHostDeviceInfoVo;
+import com.xunmei.iot.vo.deviceInfo.*;
 import com.xunmei.system.api.RemoteHostService;
 import com.xunmei.system.api.RemoteOrgService;
 import com.xunmei.system.api.domain.SysOrg;
@@ -196,6 +193,20 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
         resp.setServerIp(extend.getNetAddress());
         resp.setServerPort(extend.getPort().toString());
 
+        LambdaQueryWrapper<IotDeviceInfo> channelWrapper = new LambdaQueryWrapper<>();
+        channelWrapper.eq(IotDeviceInfo::getHostCode, deviceInfo.getDeviceCode());
+        channelWrapper.select(IotDeviceInfo::getId, IotDeviceInfo::getDeviceCode, IotDeviceInfo::getDeviceName, IotDeviceInfo::getEnable);
+        List<IotDeviceInfo> channelList = baseMapper.selectList(channelWrapper);
+        channelList.stream().map(r -> {
+            final ChannelInfoVo vo = new ChannelInfoVo();
+            vo.setId(r.getId());
+            vo.setChannelCode(r.getDeviceCode());
+            vo.setChannelName(r.getDeviceName());
+            vo.setEnable(r.getEnable());
+            return vo;
+        }).forEach(resp::addChildren);
+
+
         return resp;
     }
 
@@ -203,20 +214,28 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
     @Transactional(rollbackFor = Exception.class)
     public Integer editDvrHostDevice(EditDvrHostDeviceDto req) {
         Long deviceId = req.getId();
+        IotDeviceInfo deviceInfo;
         SysOrg sysOrg = orgService.selectOrgById(req.getOrgId(), SecurityConstants.INNER);
         int effect = 0;
         if (deviceId == null) {
-            IotDeviceInfo deviceInfo = new IotDeviceInfo();
+            deviceInfo = new IotDeviceInfo();
             buildDeviceInfo(deviceInfo, req, sysOrg);
             effect = baseMapper.insert(deviceInfo);
             deviceId = deviceInfo.getId();
         } else {
-            IotDeviceInfo deviceInfo = baseMapper.selectById(deviceId);
-            if (deviceInfo != null) {
-                buildDeviceInfo(deviceInfo, req, sysOrg);
-            }
+            deviceInfo = baseMapper.selectById(deviceId);
+            buildDeviceInfo(deviceInfo, req, sysOrg);
             effect = baseMapper.updateById(deviceInfo);
         }
+        if (ObjectUtil.isNotEmpty(req.getChildrenInfos())) {
+            for (ChannelInfoVo childrenInfo : req.getChildrenInfos()) {
+                final LambdaUpdateWrapper<IotDeviceInfo> wrapper = new LambdaUpdateWrapper<>();
+                wrapper.eq(IotDeviceInfo::getId, childrenInfo.getId());
+                wrapper.set(IotDeviceInfo::getDeviceName, childrenInfo.getChannelName());
+                wrapper.set(IotDeviceInfo::getEnable, childrenInfo.getEnable());
+                baseMapper.update(null, wrapper);
+            }
+        }
 
         extendService.updateByDeviceId(deviceId, req);
         return effect;
@@ -228,14 +247,14 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
         deviceInfo.setDeviceProduct(req.getDeviceProduct());
         IotServerProduct product = baseMapper.selectProduct(req.getDeviceProduct());
         SysMultiLayerDictionary dictionary = baseMapper.selectMultiLayerDictionaryByName(product.getProducer());
-        if (dictionary!=null){
+        if (dictionary != null) {
             deviceInfo.setDeviceBrand(dictionary.getId());
         }
         deviceInfo.setDeviceModel(req.getModels());
         deviceInfo.setEnable(req.getEnable());
         deviceInfo.setDeleted(0);
         deviceInfo.setSyncStatus(DeviceSyncStatus.NOT_SYNC.getCode());
-        if (deviceInfo.getId()==null){
+        if (deviceInfo.getId() == null) {
             deviceInfo.setOrgId(req.getOrgId());
             deviceInfo.setOrgName(sysOrg.getShortName());
             deviceInfo.setOrgPath(sysOrg.getPath());
@@ -507,7 +526,8 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
             deviceInfo = new IotDeviceInfo();
             deviceInfo.setCreateTime(new Date());
             deviceInfo.setCreateBy(sysUser.getId().toString());
-            deviceInfo.setIotToken(req.getIotCode()); deviceInfo.setOrgId(sysOrg.getId());
+            deviceInfo.setIotToken(req.getIotCode());
+            deviceInfo.setOrgId(sysOrg.getId());
             deviceInfo.setOrgName(sysOrg.getShortName());
             deviceInfo.setOrgPath(sysOrg.getPath());
             deviceInfo.setDeleted(0);
@@ -558,7 +578,7 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
         final LambdaUpdateWrapper<IotDeviceInfo> wrapper = new LambdaUpdateWrapper<>();
         wrapper.eq(IotDeviceInfo::getId, id);
         wrapper.set(IotDeviceInfo::getSyncStatus, DeviceSyncStatus.SYNCING.getCode());
-        baseMapper.update(null,wrapper);
+        baseMapper.update(null, wrapper);
         remoteHostService.syncDeviceToHost(id);
         return 1;
     }

+ 22 - 0
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/vo/deviceInfo/ChannelInfoVo.java

@@ -0,0 +1,22 @@
+package com.xunmei.iot.vo.deviceInfo;
+
+import lombok.Data;
+
+/**
+ *
+ * @author jingyuanchao
+ * @date 2024/11/22 15:26
+ */
+
+
+@Data
+public class ChannelInfoVo {
+
+    private Long id;
+
+    private String channelName;
+
+    private String channelCode;
+
+    private Integer enable;
+}

+ 8 - 1
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/vo/deviceInfo/DvrHostDeviceInfoVo.java

@@ -5,6 +5,9 @@ import lombok.AllArgsConstructor;
 import lombok.Data;
 import lombok.NoArgsConstructor;
 
+import java.util.ArrayList;
+import java.util.List;
+
 /**
  * @author jingyuanchao
  * @date 2024/11/18 13:57
@@ -44,10 +47,14 @@ public class DvrHostDeviceInfoVo {
     @ApiModelProperty(value = "设备型号")
     private String models;
 
-    @ApiModelProperty(value = "是否启用",notes = "0:未启用 1:启用")
+    @ApiModelProperty(value = "是否启用", notes = "0:未启用 1:启用")
     private Integer enable;
 
 
+    private List<ChannelInfoVo> childrenInfos = new ArrayList<>();
 
 
+    public void addChildren(ChannelInfoVo childrenInfo) {
+        this.childrenInfos.add(childrenInfo);
+    }
 }