Kaynağa Gözat

Merge branch 'V0.1.1_test' of http://10.87.21.221:8000/jzyd_yyds/soc into V0.1.1_test

jiawuxian 1 yıl önce
ebeveyn
işleme
6f8126cbaa

+ 3 - 0
soc-api/soc-api-system/src/main/java/com/xunmei/system/api/RemoteProtectionService.java

@@ -22,4 +22,7 @@ public interface RemoteProtectionService {
     public ProtectionVO getByDeviceId(@RequestParam("deviceId")Long deviceId, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
     @GetMapping("/resumption/protection/delByDeviceId")
     public int delByDeviceId(@RequestParam("deviceId")Long deviceId, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
+
+    @GetMapping("/resumption/protection/checkExitDevice")
+    public int checkExitDevice(@RequestParam("orgId")Long orgId, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
 }

+ 4 - 1
soc-api/soc-api-system/src/main/java/com/xunmei/system/api/factory/RemoteProtectionFallbackFactory.java

@@ -1,7 +1,6 @@
 package com.xunmei.system.api.factory;
 
 import com.xunmei.common.core.web.domain.AjaxResult;
-import com.xunmei.system.api.RemoteOrgService;
 import com.xunmei.system.api.RemoteProtectionService;
 import com.xunmei.system.api.dto.ProtectionDTO;
 import com.xunmei.system.api.vo.ProtectionVO;
@@ -37,6 +36,10 @@ public class RemoteProtectionFallbackFactory implements FallbackFactory<RemotePr
                 return 0;
             }
 
+            @Override
+            public int checkExitDevice(Long orgId, String source) {
+                return 0;
+            }
         };
     }
 }

+ 6 - 1
soc-modules/soc-modules-core/src/main/java/com/xunmei/core/resumption/controller/ProtectionController.java

@@ -2,13 +2,13 @@ package com.xunmei.core.resumption.controller;
 
 import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.util.ObjectUtil;
+import com.xunmei.common.core.domain.iot.domain.IotAlarmSubsystem;
 import com.xunmei.common.core.exception.ServiceException;
 import com.xunmei.common.core.web.controller.BaseController;
 import com.xunmei.common.core.web.domain.AjaxResult;
 import com.xunmei.common.core.web.page.TableDataInfo;
 import com.xunmei.common.security.annotation.InnerAuth;
 import com.xunmei.common.security.annotation.RequiresPermissions;
-import com.xunmei.common.core.domain.iot.domain.IotAlarmSubsystem;
 import com.xunmei.core.resumption.dto.protection.ProtectionEditDto;
 import com.xunmei.core.resumption.dto.protection.ProtectionLogPageDto;
 import com.xunmei.core.resumption.dto.protection.ProtectionPageDto;
@@ -90,6 +90,11 @@ class ProtectionController extends BaseController {
     public int delByDeviceId(Long deviceId){
         return protectionService.delByDeviceId(deviceId);
     }
+    @InnerAuth
+    @GetMapping("/checkExitDevice")
+    public int checkExitDevice(Long orgId){
+        return protectionService.checkExitDevice(orgId);
+    }
     @ApiOperation(value = "防区详情")
     @GetMapping("{id}")
     @RequiresPermissions({"device:protection:query"})

+ 3 - 0
soc-modules/soc-modules-core/src/main/java/com/xunmei/core/resumption/service/IProtectionService.java

@@ -58,6 +58,9 @@ public interface IProtectionService extends IService<IotAlarmSubsystem> {
 
     boolean updateSubSystemInBook(Long id, Integer inBook);
 
+    int checkExitDevice(Long orgId);
+
+
 
 //    MePage<pageSensorVo> pageSensorList(pageSensorDto request);
 

+ 6 - 0
soc-modules/soc-modules-core/src/main/java/com/xunmei/core/resumption/service/impl/ProtectionServiceImpl.java

@@ -134,6 +134,7 @@ public class ProtectionServiceImpl extends ServiceImpl<ProtectionMapper, IotAlar
             throw new RuntimeException("防区名称重复");
         }
         IotAlarmSubsystem protection = new IotAlarmSubsystem();
+        protection.setSource(0);
         if (dto.getId() != null) {
             protection = getById(dto.getId());
             BeanUtil.copyProperties(dto, protection);
@@ -294,6 +295,11 @@ public class ProtectionServiceImpl extends ServiceImpl<ProtectionMapper, IotAlar
     }
 
     @Override
+    public int checkExitDevice(Long orgId) {
+        return lambdaQuery().eq(IotAlarmSubsystem::getOrgId, orgId).eq(IotAlarmSubsystem::getSource,1).eq(IotAlarmSubsystem::getDeleted, 0).count().intValue();
+    }
+
+    @Override
     public List<Map<String, List<Map<String, Object>>>> selectDataByOrgId(Long orgId, Date date) {
 
 

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

@@ -719,6 +719,7 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
 
     private void dealAlarmSubSystem(SubDeviceInfo subSystemInfo, IotAlarmSubsystem info, IotServerInfo serverInfo) {
         info.setDeleted(0);
+        info.setSource(1);
         info.setName(subSystemInfo.getDeviceName());
         info.setUpdateBy("system");
         info.setUpdateTime(LocalDateTime.now());

+ 1 - 1
soc-modules/soc-modules-system/src/main/java/com/xunmei/system/service/ISysDeviceService.java

@@ -55,7 +55,7 @@ public interface ISysDeviceService extends IService<SysDevice> {
      * @return
      */
     SysDevice checkName(Long orgId, String name);
-    boolean checkAssetNoRepeat(Long orgId, String assetNo);
+    boolean checkAssetNoRepeat(Long orgId, String assetNo,Long deviceId);
 
     /**
      * 新增【设备管理】

+ 21 - 11
soc-modules/soc-modules-system/src/main/java/com/xunmei/system/service/impl/SysDeviceServiceImpl.java

@@ -235,8 +235,12 @@ public class SysDeviceServiceImpl extends ServiceImpl<SysDeviceMapper, SysDevice
     }
 
     @Override
-    public boolean checkAssetNoRepeat(Long orgId, String assetNo) {
-        final Long count = lambdaQuery().eq(SysDevice::getOrgId, orgId).eq(SysDevice::getAssetNo, assetNo).count();
+    public boolean checkAssetNoRepeat(Long orgId, String assetNo, Long deviceId) {
+        final Long count = lambdaQuery()
+                .eq(SysDevice::getOrgId, orgId)
+                .eq(SysDevice::getAssetNo, assetNo)
+                .ne(deviceId != null, SysDevice::getId, deviceId)
+                .count();
         return count <= 0;
     }
 
@@ -261,14 +265,15 @@ public class SysDeviceServiceImpl extends ServiceImpl<SysDeviceMapper, SysDevice
         if (null != sysDevice1) {
             throw new RuntimeException("设备名称重复");
         }
-        if (!checkAssetNoRepeat(sysDevice.getOrgId(), sysDevice.getAssetNo())) {
+        if (!checkAssetNoRepeat(sysDevice.getOrgId(), sysDevice.getAssetNo(),null)) {
             throw new RuntimeException("资产编号重复");
         }
         int insert = sysDeviceMapper.insert(sysDevice);
-        /**
-         * 这块逻辑代码,上层出错时,会导致新增设备出错
-         */
-        if ("6".equals(sysDevice.getDeviceType()) && ObjectUtil.isNull(sysDevice.getBusinessDeviceId())) {
+        //如果已经存在了主机同步上来的子系统,那么设备新增的就不能再同步到子系统表去
+        final int exitDevice = remoteProtectionService.checkExitDevice(sysOrg.getId(), SecurityConstants.INNER);
+
+        //未报废的子系统且当前机构不存在主机同步子系统的情况下才需要同步到子系统表
+        if ("6".equals(sysDevice.getDeviceType()) && sysDevice.getDeviceStatus() != 3 && exitDevice == 0) {
             ProtectionDTO protectionDTO = new ProtectionDTO();
             protectionDTO.setName(sysDevice.getDeviceName());
             protectionDTO.setOrgPath(sysOrg.getPath());
@@ -334,14 +339,16 @@ public class SysDeviceServiceImpl extends ServiceImpl<SysDeviceMapper, SysDevice
      */
     @Override
     public int updateSysDevice(SysDevice sysDevice) {
-        if (!checkAssetNoRepeat(sysDevice.getOrgId(), sysDevice.getAssetNo())) {
+        if (!checkAssetNoRepeat(sysDevice.getOrgId(), sysDevice.getAssetNo(),sysDevice.getId())) {
             throw new RuntimeException("资产编号重复");
         }
         sysDevice.setUpdateTime(DateUtils.getNowDate());
         sysDevice.setUpdateBy(SecurityUtils.getUsername());
         SysOrg sysOrg = orgService.selectSysOrgById(sysDevice.getOrgId());
         sysDevice.setOrgName(sysOrg.getShortName());
-        if (sysDevice.getDeviceType().equals("1")) {
+        //如果已经存在了主机同步上来的子系统,那么设备新增的就不能再同步到子系统表去
+        final int exitDevice = remoteProtectionService.checkExitDevice(sysDevice.getOrgId(), SecurityConstants.INNER);
+        if ("6".equals(sysDevice.getDeviceType()) && ObjectUtil.isNull(sysDevice.getBusinessDeviceId()) && exitDevice == 0) {
             ProtectionVO byDeviceId = remoteProtectionService.getByDeviceId(sysDevice.getId(), SecurityConstants.INNER);
             ProtectionDTO protectionDTO = new ProtectionDTO();
             if (null != byDeviceId) {
@@ -359,6 +366,9 @@ public class SysDeviceServiceImpl extends ServiceImpl<SysDeviceMapper, SysDevice
         if (null != sysDevice1 && !sysDevice1.getId().equals(sysDevice.getId())) {
             throw new RuntimeException("设备名称重复");
         }
+        if (sysDevice.getDeviceStatus() == 3) {
+            remoteProtectionService.delByDeviceId(sysDevice.getId(), SecurityConstants.INNER);
+        }
         return sysDeviceMapper.updateById(sysDevice);
     }
 
@@ -465,7 +475,7 @@ public class SysDeviceServiceImpl extends ServiceImpl<SysDeviceMapper, SysDevice
         if (StringUtils.isEmpty(assetNo)) {
             msgList.add("资产编号为空");
         } else {
-            if (device.getOrgId() != null && !checkAssetNoRepeat(device.getOrgId(), assetNo)) {
+            if (device.getOrgId() != null && !checkAssetNoRepeat(device.getOrgId(), assetNo,null)) {
                 msgList.add("资产编号重复");
             } else {
                 device.setAssetNo(assetNo);
@@ -545,7 +555,7 @@ public class SysDeviceServiceImpl extends ServiceImpl<SysDeviceMapper, SysDevice
         String address = deviceExport.getAddress();
         if (StringUtils.isEmpty(address)) {
             msgList.add("安装位置未填写");
-        }else {
+        } else {
             device.setAddress(address);
         }
         String checkTimeStr = deviceExport.getCheckTime();