瀏覽代碼

北向代码提交

jingyuanchao 1 年之前
父節點
當前提交
5f0a0b6a4c

+ 7 - 35
soc-modules/soc-modules-mediator/src/main/java/com/xunmei/mediator/api/service/EquipmentSyncService.java

@@ -65,7 +65,7 @@ public class EquipmentSyncService {
      * @param
      */
     @Transactional(rollbackFor = Exception.class)
-    public void saveDeviceData( List<DeviceDto> pages,String msgId) {
+    public void saveDeviceData(List<DeviceDto> pages, String msgId) {
 
         String key = "base_info_equipment_" + DateUtil.format(new Date(), "yyyy-MM-dd");
         /**
@@ -73,18 +73,11 @@ public class EquipmentSyncService {
          * 导致第一次执行正常,第二次执行报错。故添加一个判断限制在10分钟内有多个请求
          */
         Boolean isExist = stringRedisTemplate.hasKey(key);
-        if (Boolean.FALSE.equals(isExist)) {
-            this.stringRedisTemplate.opsForValue().set(key, key);
-            this.stringRedisTemplate.expire(key, 10, TimeUnit.MINUTES);
-        } else {
+        if (Boolean.TRUE.equals(isExist)) {
             return;
         }
-
-       /* Map<String, Brand> brands = new HashMap<>();
-        List<Brand> bds = brandDao.list();
-        for (Brand bd : bds) {
-            brands.put(bd.getName(), bd);
-        }*/
+        this.stringRedisTemplate.opsForValue().set(key, key);
+        this.stringRedisTemplate.expire(key, 10, TimeUnit.MINUTES);
 
         /**
          * 获取所有传递过来的数据
@@ -97,7 +90,7 @@ public class EquipmentSyncService {
         Map<String, MediatorCategory> categorys = new HashMap<>();
         List<IotDevice> olds = new ArrayList();
         List<IotDevice> list = new ArrayList<>();
-        Map<String, List<IotDevice>> rel = analysisDeviceList(pages, orgs, categorys,msgId);
+        Map<String, List<IotDevice>> rel = analysisDeviceList(pages, orgs, categorys, msgId);
         olds.addAll(rel.get("olds"));
         list.addAll(rel.get("list"));
         //第一步逻辑删除数据,逻辑删除
@@ -114,30 +107,15 @@ public class EquipmentSyncService {
             this.iIotDeviceService.batchInsertDevice(list);
         }
         this.northStatisticsSyncService.saveOrUpdateBaseCountByDataType(DataType.deviceCount.getIndex(), list.size() + olds.size(), true);
-
-
-    }
-
-
-    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
-    public void deleteChannel(String equipmentId, Long orgId, MediatorCategory category) {
-     /*   UpdateWrapper<SysDevice> uw = new UpdateWrapper<>();
-        uw.set("deleted", 1);
-        uw.lambda().eq(SysDevice::getHostCode, equipmentId);
-        uw.lambda().eq(SysDevice::getOrgId, orgId);
-        uw.lambda().eq(SysDevice::getCategoryId, category.getId());
-        deviceService.update(uw);*/
-        // productDeviceService.updateDeviceData(equipmentId,orgId,category.getId(),1)
     }
 
-
     /**
      * 解析每一页的数据
      *
      * @param
      * @return
      */
-    private Map<String, List<IotDevice>> analysisDeviceList(List<DeviceDto> dtos, Map<String, Map<String, Object>> orgs, Map<String, MediatorCategory> categorys,String msgId) {
+    private Map<String, List<IotDevice>> analysisDeviceList(List<DeviceDto> dtos, Map<String, Map<String, Object>> orgs, Map<String, MediatorCategory> categorys, String msgId) {
         Map<String, List<IotDevice>> rel = new HashMap<>();
 
         /**
@@ -228,14 +206,8 @@ public class EquipmentSyncService {
             } else {
                 list.add(device);
             }
-
-
         }
-
-        if (errors.size() > 0) {
-            northErrorService.saveErrorData(errors);
-        }
-
+        northErrorService.saveErrorData(errors);
         rel.put("olds", olds);
         rel.put("list", list);
 

+ 33 - 56
soc-modules/soc-modules-mediator/src/main/java/com/xunmei/mediator/api/service/impl/IotAlarmSubSystemServiceImpl.java

@@ -288,57 +288,45 @@ public class IotAlarmSubSystemServiceImpl extends ServiceImpl<IotAlarmSubsystemM
             ReceiveErrorDto.error("报警主机子系统及防区信息为空");
             return;
         }
-        List<NorthError> errors = new ArrayList<>();
-        List<IotAlarmSubsystem> protectionList = new ArrayList<>();
-        List<IotAlarmDefenceArea> sensorList = new ArrayList<>();
-        List<IotAlarmSubsystem> deviceList = new ArrayList<>();
-        //获取机构列表
-        final List<SysOrgVO> orgList = RedisUtils.getCacheList(CacheConstants.ORG_CACHE_LIST_KEY);
-        //获取category列表
-        List<MediatorCategory> categorys = categoryService.list();
         //查询报警主机主机设备列表
         List<IotDevice> devices = iotDeviceService.findByCategory(CategoryDataEnum.ALARM_HOST_DEVICE.getId());
-        checkParam(defenceareaList, msgId, errors, orgList, categorys, devices, deviceList, protectionList, sensorList);
+        checkParam(defenceareaList, msgId, devices);
     }
 
-    private void checkParam(List<DefenceAreaDto> defenceareaList, String msgId, List<NorthError> errors, List<SysOrgVO> orgList, List<MediatorCategory> categorys, List<IotDevice> devices, List<IotAlarmSubsystem> deviceList, List<IotAlarmSubsystem> protectionList, List<IotAlarmDefenceArea> sensorList) {
+    private void checkParam(List<DefenceAreaDto> defenceareaList, String msgId, List<IotDevice> devices) {
+        //获取category列表
+        List<MediatorCategory> categorys = categoryService.list();
+        final List<SysOrgVO> orgList = RedisUtils.getCacheList(CacheConstants.ORG_CACHE_LIST_KEY);
+        List<NorthError> errors = new ArrayList<>();
+        List<IotAlarmDefenceArea> sensorList = new ArrayList<>();
+        List<IotAlarmSubsystem> protectionList = new ArrayList<>();
         NorthError error = null;
         for (DefenceAreaDto dto : defenceareaList) {
-            SysOrgVO org = null;
+            SysOrgVO org;
             if (StringUtils.isEmpty(dto.getOrganizationGuid())) {
-                error = new NorthError(msgId, "/api/data/defenceareaList"
-                        , dto, "参数非法:未传organizationGuid");
+                error = new NorthError(msgId, "/api/data/defenceareaList", dto, "参数非法:未传organizationGuid");
                 errors.add(error);
                 continue;
-            } else {
-                List<SysOrgVO> orgs = orgList.stream().filter(r -> r.getGuid().equals(dto.getOrganizationGuid())).collect(Collectors.toList()); //orgDao.findByGuid(dto.getOrganizationGuid());
-                if (orgs.size() == 0) {
-                    error = new NorthError(msgId, "/api/data/defenceareaList"
-                            , dto, "orgGUID:" + dto.getOrganizationGuid() + "不正确");
-                    errors.add(error);
-                    continue;
-                } else {
-                    org = orgs.get(0);
-                }
             }
-
+            final Optional<SysOrgVO> optional = orgList.stream().filter(r -> r.getGuid().equals(dto.getOrganizationGuid())).findFirst();//orgDao.findByGuid(dto.getOrganizationGuid());
+            if (!optional.isPresent()) {
+                error = new NorthError(msgId, "/api/data/defenceareaList", dto, "orgGUID:" + dto.getOrganizationGuid() + "不正确");
+                errors.add(error);
+                continue;
+            }
+            org = optional.get();
             if (StringUtils.isEmpty(dto.getDefenceareaCode())) {
-                error = new NorthError(msgId, "/api/data/defenceareaList"
-                        , dto, "参数非法:未传defenceareaCode");
+                error = new NorthError(msgId, "/api/data/defenceareaList", dto, "参数非法:未传defenceareaCode");
                 errors.add(error);
                 continue;
             }
-
             if (StringUtils.isEmpty(dto.getDefenceareaName())) {
-                error = new NorthError(msgId, "/api/data/defenceareaList"
-                        , dto, "参数非法:未传defenceareaName");
+                error = new NorthError(msgId, "/api/data/defenceareaList", dto, "参数非法:未传defenceareaName");
                 errors.add(error);
                 continue;
             }
-
             if (StringUtils.isEmpty(dto.getAlarmHostCode())) {
-                error = new NorthError(msgId, "/api/data/defenceareaList"
-                        , dto, "参数非法:未传alarmHostCode");
+                error = new NorthError(msgId, "/api/data/defenceareaList", dto, "参数非法:未传alarmHostCode");
                 errors.add(error);
                 continue;
             }
@@ -351,65 +339,56 @@ public class IotAlarmSubSystemServiceImpl extends ServiceImpl<IotAlarmSubsystemM
             } else {*/
             for (SensorDto sensorDto : dto.getSensorArray()) {
                 if (StringUtils.isEmpty(sensorDto.getInputName())) {
-                    error = new NorthError(msgId, "/api/data/defenceareaList"
-                            , dto, "参数非法:未传InputName");
+                    error = new NorthError(msgId, "/api/data/defenceareaList", dto, "参数非法:未传InputName");
                     errors.add(error);
                     continue;
                 }
                 if (sensorDto.getInputIndex() == null) {
-                    error = new NorthError(msgId, "/api/data/defenceareaList"
-                            , dto, "参数非法:未传InputIndex");
+                    error = new NorthError(msgId, "/api/data/defenceareaList", dto, "参数非法:未传InputIndex");
                     errors.add(error);
                     continue;
                 }
                 if (StringUtils.isEmpty(sensorDto.getModuleAddress())) {
-                    error = new NorthError(msgId, "/api/data/defenceareaList"
-                            , dto, "参数非法:未传ModuleAddress");
+                    error = new NorthError(msgId, "/api/data/defenceareaList", dto, "参数非法:未传ModuleAddress");
                     errors.add(error);
                     continue;
                 }
                 if (StringUtils.isEmpty(sensorDto.getSensorType())) {
-                    error = new NorthError(msgId, "/api/data/defenceareaList"
-                            , dto, "参数非法:未传SensorType");
+                    error = new NorthError(msgId, "/api/data/defenceareaList", dto, "参数非法:未传SensorType");
                     errors.add(error);
                     continue;
                 }
                 if (StringUtils.isEmpty(sensorDto.getSensorTypeName())) {
-                    error = new NorthError(msgId, "/api/data/defenceareaList"
-                            , dto, "参数非法:未传SensorTypeName");
+                    error = new NorthError(msgId, "/api/data/defenceareaList", dto, "参数非法:未传SensorTypeName");
                     errors.add(error);
+                    continue;
                 }
-
                 List<MediatorCategory> categorysa = categorys.stream().filter(r -> r.getName().equals(sensorDto.getSensorTypeName())).collect(Collectors.toList());//categoryDao.getOne(qw);
                 if (categorysa.size() == 0) {
-                    error = new NorthError(msgId, "/api/data/defenceareaList"
-                            , dto, "参数非法:没有找到设备类型,默认归到其他类型中");
+                    error = new NorthError(msgId, "/api/data/defenceareaList", dto, "参数非法:没有找到设备类型,默认归到其他类型中");
                     errors.add(error);
                 }
             }
             // }
-            SysOrgVO finalOrg = org;
-            List<IotDevice> devicesa = devices.stream().filter(r -> r.getEquipmentCode().equals(dto.getAlarmHostCode()) && r.getOrgId().equals(finalOrg.getId())).collect(Collectors.toList());
+            List<IotDevice> devicesa = devices.stream().filter(r -> r.getEquipmentCode().equals(dto.getAlarmHostCode()) && r.getOrgId().equals(org.getId())).collect(Collectors.toList());
             if (devicesa.size() == 0) {
-                error = new NorthError(msgId, "/api/data/defenceareaList"
-                        , dto, "参数非法:没有找到报警主机");
+                error = new NorthError(msgId, "/api/data/defenceareaList", dto, "参数非法:没有找到报警主机");
                 errors.add(error);
                 continue;
             }
             Map<String, Object> map = this.protectionBuild(dto, org);
             protectionList.add((IotAlarmSubsystem) map.get("protection"));
             List<IotAlarmDefenceArea> list = (List<IotAlarmDefenceArea>) map.get("sensorList");
-            if (ObjectUtil.isNotEmpty(list)) {
-                sensorList.addAll(list);
-            }
-
+            sensorList.addAll(list);
         }
 
         northErrorService.saveErrorData(errors);
         baseMapper.updateAllDelete();
         this.saveOrUpdateBatch(protectionList);
         defenceAreaMapper.delete(new LambdaQueryWrapper<>());
-        defenceAreService.saveOrUpdateBatch(sensorList);
+        if (ObjectUtil.isNotEmpty(sensorList)) {
+            defenceAreService.saveOrUpdateBatch(sensorList);
+        }
         this.northStatisticsSyncService.saveOrUpdateBaseCountByDataType(DataType.protectionCount.getIndex(), defenceareaList.size(), true);
     }
 
@@ -441,7 +420,6 @@ public class IotAlarmSubSystemServiceImpl extends ServiceImpl<IotAlarmSubsystemM
             return map;
         }
         List<IotAlarmDefenceArea> list = new ArrayList<>();
-        List<IotAlarmDefenceArea> list1 = new ArrayList<>();
         List<IotAlarmDefenceArea> sensorList = defenceAreService.findBySubSystemCode(dto.getDefenceareaCode());
         for (SensorDto sensorDto : dto.getSensorArray()) {
             IotAlarmDefenceArea sensor = new IotAlarmDefenceArea();
@@ -479,7 +457,6 @@ public class IotAlarmSubSystemServiceImpl extends ServiceImpl<IotAlarmSubsystemM
             }
         }
         map.put("sensorList", list);
-        map.put("deviceList", list1);
         return map;
     }
 }

+ 1 - 2
soc-modules/soc-modules-mediator/src/main/java/com/xunmei/mediator/api/service/impl/IotDeviceServiceImpl.java

@@ -95,8 +95,7 @@ public class IotDeviceServiceImpl extends ServiceImpl<IotDeviceMapper, IotDevice
         if (totalPage == null) {
             return ReceiveErrorDto.error("totalPage参数非法");
         }
-
-        if (org.apache.commons.collections4.CollectionUtils.isEmpty(deviceReceivePageDto.getData())) {
+        if (ObjectUtil.isEmpty(deviceReceivePageDto.getData())) {
             return ReceiveErrorDto.error("设备信息数据为空");
         }
         final List<DeviceDto> list = RedisCheckRepeatDataUtil.isCompleted(deviceReceivePageDto, DeviceDto.class);

+ 77 - 84
soc-modules/soc-modules-mediator/src/main/java/com/xunmei/mediator/api/service/impl/IotDvrChannelServiceImpl.java

@@ -70,107 +70,100 @@ public class IotDvrChannelServiceImpl extends ServiceImpl<IotDvrChannelMapper, I
 
     @Override
     public ReceiveErrorDto saveChannel(List<DeviceDto> deviceDtoList, String msgId) {
-        if (org.apache.commons.collections4.CollectionUtils.isEmpty(deviceDtoList)) {
+        if (ObjectUtil.isEmpty(deviceDtoList)) {
             return ReceiveErrorDto.error("通道数据为空");
-        } else {
-            MediatorCategory category = categoryService.findCategoryByCodeAndParentId("18", -1L);
-
-            DeviceDto deviceDto;
-            List<NorthError> errors = new ArrayList<>();
-            List<IotDvrChannel> list = new ArrayList<>();
-            String equipmentId = null;
-
-            deviceDto = deviceDtoList.get(0);
-            equipmentId = deviceDto.getEquipmentCode();
-            final SysOrg org = orgService.findByCode(deviceDto.getOrganizationGuid(), SecurityConstants.INNER);
-            String UK = UUID.randomUUID().toString();
-
-            if (org != null) {
-                //制作一个随时变化的key
-                Boolean flag = redisTemplate.hasKey(CacheConstants.CHANNEL_KEY);
-                if (!flag) {
-                    //判断是否存在这个key
-                    this.redisTemplate.opsForValue().set(CacheConstants.CHANNEL_KEY, UK);
-                } else {
-                    UK = (String) this.redisTemplate.opsForValue().get(CacheConstants.CHANNEL_KEY);
-                }
-                //根据变化的key,缓存数据,供定时任务使用
-                EquipmentOrgVo eov = new EquipmentOrgVo();
-                eov.setEquipmentCode(equipmentId);
-                eov.setOrgId(org.getId());
-                redisTemplate.opsForList().rightPush(UK, eov);
-                redisTemplate.expire(UK, 1, TimeUnit.HOURS);
+        }
+        MediatorCategory category = categoryService.findCategoryByCodeAndParentId("18", -1L);
+
+        DeviceDto deviceDto;
+        List<NorthError> errors = new ArrayList<>();
+        List<IotDvrChannel> list = new ArrayList<>();
+        deviceDto = deviceDtoList.get(0);
+        final SysOrg org = orgService.findByCode(deviceDto.getOrganizationGuid(), SecurityConstants.INNER);
+        String UK = UUID.randomUUID().toString();
+        if (org != null) {
+            //制作一个随时变化的key
+            Boolean flag = redisTemplate.hasKey(CacheConstants.CHANNEL_KEY);
+            if (!flag) {
+                //判断是否存在这个key
+                this.redisTemplate.opsForValue().set(CacheConstants.CHANNEL_KEY, UK);
+            } else {
+                UK = (String) this.redisTemplate.opsForValue().get(CacheConstants.CHANNEL_KEY);
             }
+            //根据变化的key,缓存数据,供定时任务使用
+            EquipmentOrgVo eov = new EquipmentOrgVo();
+            eov.setEquipmentCode(deviceDto.getEquipmentCode());
+            eov.setOrgId(org.getId());
+            redisTemplate.opsForList().rightPush(UK, eov);
+            redisTemplate.expire(UK, 1, TimeUnit.HOURS);
+        }
 
-            for (int i = 0; i < deviceDtoList.size(); i++) {
-                deviceDto = deviceDtoList.get(i);
-                if (StringUtils.isEmpty(deviceDto.getEquipmentCode())) {
-                    NorthError error = new NorthError(msgId, "/data/channelList"
-                            , deviceDto, "equipmentCode 为空");
-                    errors.add(error);
-                    continue;
-                }
-
-                if (StringUtils.isEmpty(deviceDto.getOrganizationGuid())) {
-                    NorthError error = new NorthError(msgId, "/data/channelList"
-                            , deviceDto, "organizationGuid 为空");
-                    errors.add(error);
-                    continue;
-                }
+        for (int i = 0; i < deviceDtoList.size(); i++) {
+            deviceDto = deviceDtoList.get(i);
+            if (StringUtils.isEmpty(deviceDto.getEquipmentCode())) {
+                NorthError error = new NorthError(msgId, "/data/channelList"
+                        , deviceDto, "equipmentCode 为空");
+                errors.add(error);
+                continue;
+            }
 
-                if (StringUtils.isEmpty(deviceDto.getChannelCode())) {
-                    NorthError error = new NorthError(msgId, "/data/channelList"
-                            , deviceDto, "channelCode 为空");
-                    errors.add(error);
-                    continue;
-                }
+            if (StringUtils.isEmpty(deviceDto.getOrganizationGuid())) {
+                NorthError error = new NorthError(msgId, "/data/channelList"
+                        , deviceDto, "organizationGuid 为空");
+                errors.add(error);
+                continue;
+            }
 
-                if (StringUtils.isEmpty(deviceDto.getChannelName())) {
-                    NorthError error = new NorthError(msgId, "/data/channelList"
-                            , deviceDto, "channelName 为空");
-                    errors.add(error);
-                    continue;
-                }
+            if (StringUtils.isEmpty(deviceDto.getChannelCode())) {
+                NorthError error = new NorthError(msgId, "/data/channelList"
+                        , deviceDto, "channelCode 为空");
+                errors.add(error);
+                continue;
+            }
 
+            if (StringUtils.isEmpty(deviceDto.getChannelName())) {
+                NorthError error = new NorthError(msgId, "/data/channelList"
+                        , deviceDto, "channelName 为空");
+                errors.add(error);
+                continue;
+            }
 
-                if (org == null) {
-                    NorthError error = new NorthError(msgId, "/data/channelList"
-                            , deviceDto, "orgGUID:" + deviceDto.getOrganizationGuid() + " 不正确");
-                    errors.add(error);
-                    continue;
-                }
 
+            if (org == null) {
+                NorthError error = new NorthError(msgId, "/data/channelList"
+                        , deviceDto, "orgGUID:" + deviceDto.getOrganizationGuid() + " 不正确");
+                errors.add(error);
+                continue;
+            }
 
-                /**
-                 * 先不做数据处理,先缓存所有待处理的数据,然后每5分钟处理一次缓存数据
-                 */
 
+            /**
+             * 先不做数据处理,先缓存所有待处理的数据,然后每5分钟处理一次缓存数据
+             */
 
-                deviceDto.setOrg(org);
-                IotDevice host = iIotDeviceService.findByHostCode(deviceDto.getEquipmentCode(), org.getId());
-                if (host == null) {
-                    NorthError error = new NorthError(msgId, "/data/channelList"
-                            , deviceDto, "equipmentCode:" + deviceDto.getEquipmentCode() + "该主机code不存在");
-                    errors.add(error);
-                    continue;
-                }
 
-                IotDvrChannel device = getChannelDevice(deviceDto, category);
+            deviceDto.setOrg(org);
+            IotDevice host = iIotDeviceService.findByHostCode(deviceDto.getEquipmentCode(), org.getId());
+            if (host == null) {
+                NorthError error = new NorthError(msgId, "/data/channelList"
+                        , deviceDto, "equipmentCode:" + deviceDto.getEquipmentCode() + "该主机code不存在");
+                errors.add(error);
+                continue;
+            }
 
-                list.add(device);
+            IotDvrChannel device = getChannelDevice(deviceDto, category);
 
-            }
+            list.add(device);
 
-            if (list.size() > 0) {
-                redisTemplate.opsForList().rightPushAll(UK + CacheConstants.AFTER_DATA, list);
-                redisTemplate.expire(UK + CacheConstants.AFTER_DATA, 1, TimeUnit.HOURS);
-            }
-            if (errors.size() > 0) {
-                northErrorService.saveErrorData(errors);
-            }
+        }
 
-            return ReceiveErrorDto.success();
+        if (list.size() > 0) {
+            redisTemplate.opsForList().rightPushAll(UK + CacheConstants.AFTER_DATA, list);
+            redisTemplate.expire(UK + CacheConstants.AFTER_DATA, 1, TimeUnit.HOURS);
         }
+        northErrorService.saveErrorData(errors);
+
+        return ReceiveErrorDto.success();
     }
 
     private IotDvrChannel getChannelDevice(DeviceDto deviceDto, MediatorCategory category) {