浏览代码

删除设备代码提交

jingyuanchao 11 月之前
父节点
当前提交
d3c37ca9cb

+ 7 - 0
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/controller/IotDeviceInfoController.java

@@ -97,4 +97,11 @@ public class IotDeviceInfoController {
         deviceInfoService.syncDevice(id);
         return AjaxResult.success();
     }
+
+    @ApiOperation("删除设备")
+    @GetMapping({"/deletedDevice/{id}"})
+    AjaxResult deletedDevice(@PathVariable Long id) {
+        deviceInfoService.deletedDevice(id);
+        return AjaxResult.success();
+    }
 }

+ 3 - 0
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/mapper/IotAlarmDefenceAreaMapper.java

@@ -21,4 +21,7 @@ public interface IotAlarmDefenceAreaMapper extends BaseMapper<IotAlarmDefenceAre
     void updateDeleted(@Param("alarmHostCode") String alarmHostCode, @Param("subSystemCode") String subSystemCode);
 
     void updateDeletedByIds(@Param("ids") List<Long> ids);
+
+    void updateDeletedByAlarmHostCode(@Param("iotToken") String iotToken, @Param("deviceCode") String deviceCode);
+
 }

+ 3 - 0
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/mapper/IotAlarmSubsystemMapper.java

@@ -12,4 +12,7 @@ public interface IotAlarmSubsystemMapper extends BaseMapper<IotAlarmSubsystem> {
     List<DeviceDetailInfoVo> getByDeviceCodeAndIotToken(@Param("deviceCode") String deviceCode, @Param("iotToken") String iotToken);
 
     void updateDeletedByIds(@Param("ids") List<Long> subSystemIds);
+
+    void updateDeletedByAlarmHostCode(@Param("iotToken") String iotToken, @Param("deviceCode") String deviceCode);
+
 }

+ 3 - 0
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/mapper/IotDeviceInfoMapper.java

@@ -31,4 +31,7 @@ public interface IotDeviceInfoMapper extends BaseMapper<IotDeviceInfo> {
 
     SysMultiLayerDictionary selectMultiLayerDictionaryByName(@Param("name") String name);
 
+    void updateDeletedDvrAndChannel(@Param("iotCode") String iotCode, @Param("deviceProduct") String deviceProduct, @Param("deviceCode") String deviceCode);
+
+    void updateDeletedById(@Param("deviceInfoId") Long deviceInfoId);
 }

+ 1 - 0
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/service/IIotDeviceInfoService.java

@@ -48,4 +48,5 @@ public interface IIotDeviceInfoService extends IService<IotDeviceInfo> {
 
     Integer syncDevice(Long id);
 
+    void deletedDevice(Long deviceId);
 }

+ 1 - 0
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/service/IotDeviceInfoExtendService.java

@@ -18,6 +18,7 @@ public interface IotDeviceInfoExtendService extends IService<IotDeviceInfoExtend
     IotDeviceInfoExtend findByDeviceId(Long deviceId);
 
     boolean removeByDeviceId(Long deviceId);
+    boolean updateDeletedByDeviceId(Long deviceId);
 
     void updateNetHostExtendByDeviceId(Long deviceId, EditNetHostDeviceDto req);
 }

+ 9 - 0
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/service/IotDeviceInfoExtendServiceImpl.java

@@ -2,6 +2,7 @@ package com.xunmei.iot.service;
 
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.core.toolkit.IdWorker;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.xunmei.common.core.constant.Constants;
@@ -80,6 +81,14 @@ public class IotDeviceInfoExtendServiceImpl extends ServiceImpl<IotDeviceInfoExt
     }
 
     @Override
+    public boolean updateDeletedByDeviceId(Long deviceId) {
+        LambdaUpdateWrapper<IotDeviceInfoExtend> wrapper = new LambdaUpdateWrapper<>();
+        wrapper.eq(IotDeviceInfoExtend::getDeviceId, deviceId);
+        wrapper.set(IotDeviceInfoExtend::getDeleted, 1);
+        return update(wrapper);
+    }
+
+    @Override
     public void updateNetHostExtendByDeviceId(Long deviceId, EditNetHostDeviceDto req) {
         removeByDeviceId(deviceId);
         IotDeviceInfoExtend extend = new IotDeviceInfoExtend();

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

@@ -335,7 +335,7 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
         SysOrg sysOrg = orgService.selectOrgById(req.getOrgId(), SecurityConstants.INNER);
 
         if (deviceId == null) {
-             deviceId = addAlarmHostDevice(req, sysOrg);
+            deviceId = addAlarmHostDevice(req, sysOrg);
             return 1;
         }
         updateAddAlarmHostDevice(req);
@@ -583,4 +583,46 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
         remoteHostService.syncDeviceToHost(id);
         return 1;
     }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void deletedDevice(Long deviceId) {
+        final IotDeviceInfo deviceInfo = getById(deviceId);
+        if (deviceInfo == null) {
+            throw new RuntimeException("设备不存在");
+        }
+        final BaseDeviceTypeEnum enums = BaseDeviceTypeEnum.getEnumByCode(deviceInfo.getDeviceType());
+        switch (enums) {
+            case Dvs:
+                deletedDvr(deviceInfo);
+                break;
+            case AlarmHost:
+                deletedAlarmHost(deviceInfo);
+                break;
+            case Host_Talk:
+            case Host_Door:
+                deletedNetHost(deviceInfo);
+                break;
+            default:
+                break;
+
+        }
+        extendService.updateDeletedByDeviceId(deviceId);
+
+    }
+
+    private void deletedDvr(IotDeviceInfo deviceInfo) {
+        baseMapper.updateDeletedDvrAndChannel(deviceInfo.getIotToken(), deviceInfo.getDeviceProduct(), deviceInfo.getDeviceCode());
+
+    }
+
+    private void deletedAlarmHost(IotDeviceInfo deviceInfo) {
+        baseMapper.updateDeletedById(deviceInfo.getId());
+        subsystemMapper.updateDeletedByAlarmHostCode(deviceInfo.getIotToken(), deviceInfo.getDeviceCode());
+        defenceAreaMapper.updateDeletedByAlarmHostCode(deviceInfo.getIotToken(), deviceInfo.getDeviceCode());
+    }
+
+    private void deletedNetHost(IotDeviceInfo deviceInfo) {
+        baseMapper.updateDeletedById(deviceInfo.getId());
+    }
 }

+ 4 - 0
soc-modules/soc-modules-iot/src/main/resources/mapper/IotAlarmDefenceAreaMapper.xml

@@ -15,4 +15,8 @@
             #{id}
         </foreach>
     </update>
+
+    <update id="updateDeletedByAlarmHostCode">
+        update iot_alarm_defence_area set deleted = 1 where iot_token=#{iotToken} and alarm_host_code=#{deviceCode}
+    </update>
 </mapper>

+ 4 - 0
soc-modules/soc-modules-iot/src/main/resources/mapper/IotAlarmSubsystemMapper.xml

@@ -21,4 +21,8 @@
                 #{id}
             </foreach>
     </update>
+
+    <update id="updateDeletedByAlarmHostCode">
+        update iot_alarm_subsystem set deleted = 1 where iot_token=#{iotToken} and alarm_host_code=#{deviceCode}
+    </update>
 </mapper>

+ 16 - 0
soc-modules/soc-modules-iot/src/main/resources/mapper/IotDeviceInfoMapper.xml

@@ -121,4 +121,20 @@
             resultType="com.xunmei.common.core.domain.device.domain.SysMultiLayerDictionary">
         select * from sys_multi_layer_dictionary where name=#{name} limit 1
     </select>
+
+    <update id="updateDeletedDvrAndChannel">
+        update iot_device_info
+        set deleted=1
+        where iot_token = #{iotCode}
+          and (
+                (device_product = #{deviceProduct} and device_code = #{deviceCode})
+                or host_code = #{deviceCode}
+            )
+    </update>
+
+    <update id="updateDeletedById">
+        update iot_device_info
+        set deleted=1
+        where id = #{deviceInfoId}
+    </update>
 </mapper>