Browse Source

Merge branch 'V0.0.6-iot' of http://10.87.21.221:8000/jzyd_yyds/soc into V0.0.6-iot

jiawuxian 1 year ago
parent
commit
1b7b6e9374

+ 49 - 23
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/service/impl/IotAlarmRuleSourceServiceImpl.java

@@ -5,11 +5,14 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.xunmei.common.core.constant.CacheConstants;
 import com.xunmei.common.core.domain.iot.domain.IotSensor;
 import com.xunmei.common.core.domain.mediator.domain.IotAlarmRule;
 import com.xunmei.common.core.domain.mediator.domain.IotAlarmRuleSource;
+import com.xunmei.common.core.enums.OrgTypeEnum;
 import com.xunmei.common.core.utils.IDHelper;
 import com.xunmei.common.core.utils.StringUtils;
+import com.xunmei.common.redis.utils.RedisUtils;
 import com.xunmei.iot.dto.alarm.IotAlarmRuleSourceDetailDto;
 import com.xunmei.iot.dto.alarm.IotAlarmRuleSourceDeviceBatchJoin;
 import com.xunmei.iot.dto.alarm.IotAlarmRuleSourceDeviceDto;
@@ -22,14 +25,12 @@ import com.xunmei.iot.mapper.IotAlarmRuleSourceMapper;
 import com.xunmei.iot.mapper.IotCommonSensorMapper;
 import com.xunmei.iot.service.IotAlarmRuleSourceService;
 import com.xunmei.iot.vo.alarm.*;
+import com.xunmei.system.api.vo.SysOrgVO;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.function.Function;
 import java.util.stream.Collectors;
 
@@ -60,33 +61,56 @@ public class IotAlarmRuleSourceServiceImpl extends ServiceImpl<IotAlarmRuleSourc
         //2.获取告警规则对应有哪些设备的告警属性规则。
         List<ProductTypeDataVo> productTypeDataVos = iotAlarmRuleSourceMapper.selectRuleDevice(detailVo.getRuleId());
         //3.处理其他sql获取不了的数据
+        final List<SysOrgVO> cacheList = RedisUtils.getCacheList(CacheConstants.ORG_CACHE_LIST_KEY);
         for (ProductTypeDataVo pdv : productTypeDataVos) {
-            dealDevice(pdv);
+            dealDevice(pdv, cacheList);
         }
         iotAlarmRuleSourceDetailVo.setTypeDataList(productTypeDataVos);
         return iotAlarmRuleSourceDetailVo;
     }
 
     @Override
-    public Page<IotAlarmRuleSourceDeviceVo> selectDeviceList(IotAlarmRuleSourceDeviceDto param)throws Exception {
+    public Page<IotAlarmRuleSourceDeviceVo> selectDeviceList(IotAlarmRuleSourceDeviceDto param) throws Exception {
         Page<IotAlarmRuleSourceDeviceVo> page = new Page<>();
         page.setSize(param.getSize());
         page.setCurrent(param.getPage());
         Page<IotAlarmRuleSourceDeviceVo> result = iotAlarmRuleSourceMapper.selectDeviceList(page, param);
+        final List<IotAlarmRuleSourceDeviceVo> records = result.getRecords();
+        if (ObjectUtil.isEmpty(records)) {
+            return result;
+        }
+        final List<SysOrgVO> cacheList = RedisUtils.getCacheList(CacheConstants.ORG_CACHE_LIST_KEY);
+
+        for (IotAlarmRuleSourceDeviceVo record : records) {
+            final String orgName = dealOrgName(cacheList, record.getOrgPath(), record.getOrgName());
+            record.setOrgName(orgName);
+        }
         return result;
     }
 
+
+    private String dealOrgName(List<SysOrgVO> cacheList, String orgPath, String orgName) {
+        List<String> orgNameList = new ArrayList<>();
+        final List<Long> collect = Arrays.stream(orgPath.split("-")).map(Long::parseLong).collect(Collectors.toList());
+        //地区名称
+        cacheList.stream().filter(org -> collect.contains(org.getId()) && OrgTypeEnum.DIQU_HANG_SHE.getCode().equals(org.getType())).findFirst().ifPresent(org -> orgNameList.add(org.getShortName()));
+        //行社名称
+        cacheList.stream().filter(org -> collect.contains(org.getId()) && OrgTypeEnum.HANG_SHE.getCode().equals(org.getType())).findFirst().ifPresent(org -> orgNameList.add(org.getShortName()));
+        orgNameList.add(orgName);
+        return String.join("-", orgNameList);
+    }
+
     @Override
     @Transactional(rollbackFor = Exception.class)
     public void updateRuleAndProductDevice(IotAlarmRuleSourceDetailVo detailDto) throws Exception {
         //删除设备绑定数据
         LambdaQueryWrapper<IotAlarmRuleSource> qw = new LambdaQueryWrapper<IotAlarmRuleSource>();
-        qw.eq(IotAlarmRuleSource::getRuleId,detailDto.getRuleId());
+        qw.eq(IotAlarmRuleSource::getRuleId, detailDto.getRuleId());
         iotAlarmRuleSourceMapper.delete(qw);
 
         //重新绑定设置
         List<ProductTypeDataVo> deviceData = detailDto.getTypeDataList();
-        if(ObjectUtil.isEmpty(deviceData)){
+        if (ObjectUtil.isEmpty(deviceData)) {
             return;
         }
         IotAlarmRuleSource ruleSource = null;
@@ -106,9 +130,9 @@ public class IotAlarmRuleSourceServiceImpl extends ServiceImpl<IotAlarmRuleSourc
                 for (ProductDeviceTempVo deviceTempVo : productType.getDeviceTempList()) {
                     //查询当前设备是否有其他规则绑定,如果有则删除,解绑
                     QueryWrapper<IotAlarmRuleSource> iqw = new QueryWrapper<>();
-                    iqw.lambda().eq(IotAlarmRuleSource::getOrgId,deviceTempVo.getOrgId())
-                            .eq(IotAlarmRuleSource::getValue,deviceTempVo.getDeviceId())
-                            .eq(IotAlarmRuleSource::getSourceType,productType.getType());
+                    iqw.lambda().eq(IotAlarmRuleSource::getOrgId, deviceTempVo.getOrgId())
+                            .eq(IotAlarmRuleSource::getValue, deviceTempVo.getDeviceId())
+                            .eq(IotAlarmRuleSource::getSourceType, productType.getType());
                     iotAlarmRuleSourceMapper.delete(iqw);
                     ruleSource.setId(IDHelper.id());
                     ruleSource.setOrgId(deviceTempVo.getOrgId());
@@ -135,7 +159,7 @@ public class IotAlarmRuleSourceServiceImpl extends ServiceImpl<IotAlarmRuleSourc
                 IotSensor productDevice = (IotSensor) hashMap.get(deviceId);
                 if (productDevice == null) {
                     QueryWrapper<IotSensor> qw = new QueryWrapper<>();
-                    qw.lambda().eq(IotSensor::getDeviceCode,deviceId).eq(IotSensor::getDeleted,0);
+                    qw.lambda().eq(IotSensor::getDeviceCode, deviceId).eq(IotSensor::getDeleted, 0);
                     hashMap.put(deviceId, productDevice);
                 }
                 String code = productDevice.getDeviceType();
@@ -166,37 +190,39 @@ public class IotAlarmRuleSourceServiceImpl extends ServiceImpl<IotAlarmRuleSourc
 
     /**
      * 处理每种类型的数据
+     *
      * @param pdv
      * @return
      */
-    private void dealDevice(ProductTypeDataVo pdv){
+    private void dealDevice(ProductTypeDataVo pdv, List<SysOrgVO> cacheList) {
         String valueType = pdv.getValueType();
 
-        if(StringUtils.isEmpty(valueType)){
+        if (StringUtils.isEmpty(valueType)) {
             //未配置设备关联时
             pdv.setIsAllDeviceEnable(false);
             pdv.setValueType(ValueTypeEnum.Device.getText());
-        }else{
-            if(ValueTypeEnum.AllDevice.getText().equals(valueType)){
+        } else {
+            if (ValueTypeEnum.AllDevice.getText().equals(valueType)) {
                 //配置按设备类型关联时
                 pdv.setIsAllDeviceEnable(true);
             }
 
-            if(ValueTypeEnum.Device.getText().equals(valueType)){
+            if (ValueTypeEnum.Device.getText().equals(valueType)) {
                 //配置具体设备关联时
                 List<ProductDeviceTempVo> deviceTempList = pdv.getDeviceTempList();
                 //获取对应的设备id
                 List<String> deviceIds = deviceTempList.stream().map(ProductDeviceTempVo::getDeviceId).collect(Collectors.toList());
 
                 List<IotSensor> iotSensors = iotCommonSensorMapper.selectByIds(deviceIds);
-                Map<String, IotSensor> deviceIdAndName = iotSensors.stream().collect(Collectors.toMap(IotSensor::getDeviceCode, Function.identity()));
+                // CONCAT(org_id,'-',device_code) as device_code
+                final Map<String, IotSensor> deviceIdAndName = iotSensors.stream().collect(Collectors.toMap(IotSensor::getDeviceCode, Function.identity()));
                 for (ProductDeviceTempVo ptv : deviceTempList) {
-                    IotSensor iotSensor = deviceIdAndName.get(ptv.getDeviceId());
-                    if( iotSensor!= null){
-                        ptv.setDeviceName(iotSensor.getDeviceName());
-                        ptv.setOrgName(iotSensor.getOrgName());
+                    final IotSensor sensor = deviceIdAndName.get(ptv.getStrDeviceId());
+                    if (sensor != null) {
+                        ptv.setDeviceName(sensor.getDeviceName());
+                        final String orgName = dealOrgName(cacheList, sensor.getOrgPath(), sensor.getOrgName());
+                        ptv.setOrgName(orgName);
                     }
-
                 }
             }
         }

+ 3 - 0
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/vo/alarm/ProductDeviceTempVo.java

@@ -2,6 +2,7 @@ package com.xunmei.iot.vo.alarm;
 
 import com.fasterxml.jackson.databind.annotation.JsonSerialize;
 import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
+import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 
 /**
@@ -15,6 +16,8 @@ public class ProductDeviceTempVo {
      * 设备id
      */
     private String deviceId;
+    @ApiModelProperty(value = "设备唯一id",notes = "临时拼接,由机构id+传感器code")
+    private String strDeviceId;
     /**
      * 设备名称
      */

+ 3 - 1
soc-modules/soc-modules-iot/src/main/resources/mapper/IotAlarmRuleSourceMapper.xml

@@ -20,6 +20,7 @@
         <result property="typeText" column="type_text"/>
         <collection property="deviceTempList" ofType="com.xunmei.iot.vo.alarm.ProductDeviceTempVo">
             <result property="deviceId" column="device_id"/>
+            <result property="strDeviceId" column="strDeviceId"/>
             <result property="orgId" column="org_id"/>
             <result property="orgName" column="org_name"/>
             <result property="orgPath" column="org_path"/>
@@ -33,6 +34,7 @@
             d.source_type_des as type_text,
             b.value_type,
             b.`value` AS device_id,
+            concat(b.org_id,'-',b.value) as strDeviceId,
             b.org_id,
             c.`name` AS org_name,
             c.path AS org_path
@@ -49,7 +51,7 @@
         d.device_name AS deviceName,
         d.org_id AS orgId,
         d.org_path AS orgPath,
-        CONCAT(b.affiliated_area,'-',b.affiliated_bank,'-',b.short_name) as org_name
+        b.short_name as org_name
         FROM
         iot_sensor d
         LEFT JOIN sys_org b ON d.org_id = b.id

+ 4 - 3
soc-modules/soc-modules-iot/src/main/resources/mapper/IotSensorMapper.xml

@@ -89,10 +89,11 @@
     <select id="selectByIds" resultType="com.xunmei.common.core.domain.iot.domain.IotSensor">
         SELECT
         org_id,
-        CONCAT(b.affiliated_area,'-',b.affiliated_bank,'-',b.short_name) as org_name,
-        device_name,
+        org_path,
+        b.short_name as org_name,
+        device_name as deviceName,
         infos AS info,
-        device_code
+        CONCAT(org_id,'-',device_code) as deviceCode
         FROM
         iot_sensor a
         LEFT JOIN sys_org b ON a.org_id = b.id

+ 11 - 12
soc-modules/soc-modules-mediator/src/main/java/com/xunmei/mediator/api/service/EquipmentSyncService.java

@@ -28,6 +28,7 @@ import java.text.SimpleDateFormat;
 import java.time.LocalDateTime;
 import java.util.*;
 import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
 
 /**
  * 重写设备equipment 分页同步逻辑
@@ -59,8 +60,8 @@ public class EquipmentSyncService {
      */
     @Transactional(rollbackFor = Exception.class)
     public void saveDeviceData(List<DeviceDto> pages, String msgId) {
-
-        String key = "base_info_equipment_" + DateUtil.format(new Date(), "yyyy-MM-dd");
+        final String organizationGuid = pages.get(0).getOrganizationGuid();
+        String key = "base_info_equipment_" + DateUtil.format(new Date(), "yyyy-MM-dd") + "_" + organizationGuid;
         /**
          * 主机可能会在短时间发送两次不同包,但是数据一样的信息过来
          * 导致第一次执行正常,第二次执行报错。故添加一个判断限制在10分钟内有多个请求
@@ -80,14 +81,12 @@ public class EquipmentSyncService {
          */
         Map<String, Map<String, Object>> orgs = new HashMap<>();
 
-        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);
-        olds.addAll(rel.get("olds"));
-        list.addAll(rel.get("list"));
+        Map<String, List<IotDevice>> rel = analysisDeviceList(pages, orgs, msgId);
+        final List<IotDevice> olds = rel.get("olds");
+        final List<IotDevice> list = rel.get("list");
+        final List<Long> orgIdList = rel.values().stream().flatMap(Collection::stream).map(IotDevice::getOrgId).distinct().collect(Collectors.toList());
         //第一步逻辑删除数据,逻辑删除
-        this.iIotDeviceService.updateDeviceDeleted();
+        this.iIotDeviceService.updateDeviceDeleted(orgIdList);
 
 
         //第二步查询数据,如果存在则更新,如果不存在,则新增
@@ -108,7 +107,7 @@ public class EquipmentSyncService {
      * @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, String msgId) {
         Map<String, List<IotDevice>> rel = new HashMap<>();
 
         /**
@@ -189,7 +188,7 @@ public class EquipmentSyncService {
                     datum.setOrg(theOrg);
                 }
             }
-            Map<String, Object> map = resolveDevice(datum, categorys);
+            Map<String, Object> map = resolveDevice(datum);
 
 
             IotDevice device = (IotDevice) map.get("device");
@@ -214,7 +213,7 @@ public class EquipmentSyncService {
      * @param datum
      * @return
      */
-    private Map<String, Object> resolveDevice(DeviceDto datum, Map<String, MediatorCategory> categorys) {
+    private Map<String, Object> resolveDevice(DeviceDto datum) {
         Map<String, Object> map = new HashMap<>();
         IotDevice device = new IotDevice();
         map.put("isOld", 0);

+ 1 - 1
soc-modules/soc-modules-mediator/src/main/java/com/xunmei/mediator/api/service/IIotDeviceService.java

@@ -22,7 +22,7 @@ public interface IIotDeviceService extends IService<IotDevice> {
 
     IotDevice findByHostCode(String equipmentCode, Long orgId);
 
-    void updateDeviceDeleted();
+    void updateDeviceDeleted(List<Long> orgIdList);
 
 
     void batchUpdateDevice(List<IotDevice> olds);

+ 3 - 1
soc-modules/soc-modules-mediator/src/main/java/com/xunmei/mediator/api/service/IotSensorService.java

@@ -7,6 +7,8 @@ import com.xunmei.system.api.dto.SensorDto;
 import com.xunmei.system.api.dto.SensorStatusDto;
 import com.xunmei.system.api.dto.protection.ReceiveErrorDto;
 
+import java.util.List;
+
 /**
  * <p>
  *  服务类
@@ -22,5 +24,5 @@ public interface IotSensorService extends IService<IotSensor> {
     ReceiveErrorDto saveDirectHostStatus(DataPageDto<SensorStatusDto> statuses, String msgId);
      void saveStatusAsync(DataPageDto<SensorStatusDto> request, String msgId);
 
-    void updateDelByOrgId(Long orgId);
+    void updateDelByOrgId( List<Long> orgIdList );
 }

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

@@ -3,6 +3,7 @@ package com.xunmei.mediator.api.service.impl;
 import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.util.ObjectUtil;
 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.CacheConstants;
@@ -305,6 +306,7 @@ public class IotAlarmSubSystemServiceImpl extends ServiceImpl<IotAlarmSubsystemM
         List<IotAlarmDefenceArea> sensorList = new ArrayList<>();
         List<IotAlarmSubsystem> protectionList = new ArrayList<>();
         NorthError error = null;
+        List<Long> orgIdList = new ArrayList<>();
         for (DefenceAreaDto dto : defenceareaList) {
             SysOrgVO org;
             if (StringUtils.isEmpty(dto.getOrganizationGuid())) {
@@ -319,6 +321,7 @@ public class IotAlarmSubSystemServiceImpl extends ServiceImpl<IotAlarmSubsystemM
                 continue;
             }
             org = optional.get();
+            orgIdList.add(org.getId());
             if (StringUtils.isEmpty(dto.getDefenceareaCode())) {
                 error = new NorthError(msgId, "/api/data/defenceareaList", dto, "参数非法:未传defenceareaCode");
                 errors.add(error);
@@ -396,17 +399,29 @@ public class IotAlarmSubSystemServiceImpl extends ServiceImpl<IotAlarmSubsystemM
         }
 
         northErrorService.saveErrorData(errors);
-        subsystemMapper.updateAllDelete();
+        //逻辑删除机构下所有的子系统和防区
+        this.updateAllDelete(orgIdList);
         if (ObjectUtil.isNotEmpty(protectionList)) {
             this.saveOrUpdateBatch(protectionList);
         }
-        defenceAreaMapper.delete(new LambdaQueryWrapper<>());
         if (ObjectUtil.isNotEmpty(sensorList)) {
             defenceAreService.saveOrUpdateBatch(sensorList);
         }
         this.northStatisticsSyncService.saveOrUpdateBaseCountByDataType(DataType.protectionCount.getIndex(), defenceareaList.size(), true);
     }
 
+    private void updateAllDelete(List<Long> orgIdLIst){
+        LambdaUpdateWrapper<IotAlarmSubsystem> updateWrapper=new LambdaUpdateWrapper<IotAlarmSubsystem>();
+        updateWrapper.in(IotAlarmSubsystem::getOrgId,orgIdLIst);
+        updateWrapper.set(IotAlarmSubsystem::getDeleted,1);
+        this.update(updateWrapper);
+
+        LambdaUpdateWrapper<IotAlarmDefenceArea> defenceAreaLambdaUpdateWrapper=new LambdaUpdateWrapper<IotAlarmDefenceArea>();
+        defenceAreaLambdaUpdateWrapper.in(IotAlarmDefenceArea::getOrgId,orgIdLIst);
+        defenceAreaLambdaUpdateWrapper.set(IotAlarmDefenceArea::getDeleted,1);
+        defenceAreService.update(defenceAreaLambdaUpdateWrapper);
+    }
+
     public Map<String, Object> protectionBuild(DefenceAreaDto dto, SysOrgVO org) {
         Map<String, Object> map = new HashMap<>();
         IotAlarmSubsystem protection = null;

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

@@ -62,12 +62,13 @@ public class IotDeviceServiceImpl extends ServiceImpl<IotDeviceMapper, IotDevice
 
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public void updateDeviceDeleted() {
+    public void updateDeviceDeleted(List<Long> orgIdList) {
         final LambdaUpdateWrapper<IotDevice> wrapper = new LambdaUpdateWrapper<>();
         wrapper.eq(IotDevice::getSource, 1);
+        wrapper.in(IotDevice::getOrgId, orgIdList);
         wrapper.in(IotDevice::getCategoryId,
                 CategoryDataEnum.MONITOR_HOST_DEVICE.getId(),
-                 CategoryDataEnum.ALARM_HOST_DEVICE.getId(),
+                CategoryDataEnum.ALARM_HOST_DEVICE.getId(),
                 CategoryDataEnum.TALK_HOST_DEVICE.getId(),
                 CategoryDataEnum.DOOR_HOST_DEVICE.getId());
         wrapper.set(IotDevice::getDeleted, 1);

+ 9 - 10
soc-modules/soc-modules-mediator/src/main/java/com/xunmei/mediator/api/service/impl/IotDvrDiskServiceImpl.java

@@ -1,11 +1,15 @@
 package com.xunmei.mediator.api.service.impl;
 
+import cn.hutool.core.map.MapUtil;
 import cn.hutool.core.util.NumberUtil;
 import cn.hutool.core.util.ObjectUtil;
 import com.alibaba.fastjson2.JSON;
 import com.alibaba.nacos.common.utils.JacksonUtils;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.xunmei.common.core.constant.CacheConstants;
+import com.xunmei.common.core.domain.iot.domain.IotAlarmDefenceArea;
 import com.xunmei.common.core.domain.iot.domain.IotDevice;
 import com.xunmei.common.core.domain.iot.domain.IotDvrDisk;
 import com.xunmei.common.core.domain.iot.domain.IotDvrHardDiskDetection;
@@ -56,7 +60,6 @@ public class IotDvrDiskServiceImpl extends ServiceImpl<IotDvrDiskMapper, IotDvrD
     private IIotDeviceService iotDeviceService;
 
 
-
     @Override
     @Transactional(rollbackFor = Exception.class)
     public void updateStatusByDiskDetection(IotDvrHardDiskDetection videoRecorderHardDiskDetection) {
@@ -107,19 +110,15 @@ public class IotDvrDiskServiceImpl extends ServiceImpl<IotDvrDiskMapper, IotDvrD
         List<NorthError> errors = (List<NorthError>) map.get("errors");
 
         List<IotDvrDisk> dvrdisks = (List<IotDvrDisk>) map.get("dvrdisks");
-
+        final List<Long> orgIdLIst = dvrdisks.stream().map(IotDvrDisk::getOrgId).distinct().collect(Collectors.toList());
         this.northStatisticsSyncService.saveOrUpdateBaseCountByDataType(DataType.dvrdiskCount.getIndex(), dvrdisks.size(), false);
 
         northErrorService.saveErrorData(errors);
         if (ObjectUtil.isNotEmpty(dvrdisks)) {
-
-            try {
-                baseMapper.delete(null);
-                this.saveBatch(dvrdisks);
-            } catch (Exception e) {
-                LogUtils.BASE_INFO_DVR_DISK.error("批量保存dvrdisk失败,失败原因:{}", e.getMessage());
-                throw new RuntimeException(e.getMessage());
-            }
+            LambdaQueryWrapper<IotDvrDisk> wrapper = new LambdaQueryWrapper<IotDvrDisk>();
+            wrapper.in(IotDvrDisk::getOrgId, orgIdLIst);
+            this.remove(wrapper);
+            this.saveOrUpdateBatch(dvrdisks);
         }
     }
 

+ 13 - 7
soc-modules/soc-modules-mediator/src/main/java/com/xunmei/mediator/api/service/impl/IotSensorServiceImpl.java

@@ -5,9 +5,11 @@ import com.alibaba.fastjson2.JSON;
 import com.alibaba.fastjson2.JSONArray;
 import com.alibaba.fastjson2.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.xunmei.common.core.constant.DictConstants;
 import com.xunmei.common.core.constant.SecurityConstants;
+import com.xunmei.common.core.domain.iot.domain.IotAlarmDefenceArea;
 import com.xunmei.common.core.domain.iot.domain.IotSensor;
 import com.xunmei.common.core.domain.iot.domain.IotSensorLog;
 import com.xunmei.common.core.enums.CategoryDataEnum;
@@ -68,16 +70,20 @@ public class IotSensorServiceImpl extends ServiceImpl<IotSensorMapper, IotSensor
 
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public void updateDelByOrgId(Long orgId) {
-        if (ObjectUtil.isNull(orgId)) {
+    public void updateDelByOrgId(List<Long> orgIdList) {
+        if (ObjectUtil.isEmpty(orgIdList)) {
             return;
         }
-        final List<IotSensor> sensors = baseMapper.selectList(new LambdaQueryWrapper<IotSensor>().eq(IotSensor::getSource, 1).eq(IotSensor::getOrgId, orgId));
+        final List<IotSensor> sensors = baseMapper.selectList(new LambdaQueryWrapper<IotSensor>().eq(IotSensor::getSource, 1).in(IotSensor::getOrgId, orgIdList));
         final List<String> collect = sensors.stream().map(IotSensor::getDeviceCode).distinct().collect(Collectors.toList());
         if (ObjectUtil.isNotEmpty(collect)) {
-            iotSensorLogService.remove(new LambdaQueryWrapper<IotSensorLog>().eq(IotSensorLog::getOrgId, orgId).in(IotSensorLog::getDeviceCode, collect));
+            iotSensorLogService.remove(new LambdaQueryWrapper<IotSensorLog>().in(IotSensorLog::getOrgId, orgIdList).in(IotSensorLog::getDeviceCode, collect));
         }
-        baseMapper.updateDelByOrgId(orgId);
+
+        LambdaUpdateWrapper<IotSensor> wrapper = new LambdaUpdateWrapper<IotSensor>();
+        wrapper.in(IotSensor::getOrgId, orgIdList);
+        wrapper.set(IotSensor::getDeleted, 1);
+        this.update(wrapper);
     }
 
     @Override
@@ -214,8 +220,8 @@ public class IotSensorServiceImpl extends ServiceImpl<IotSensorMapper, IotSensor
 
                 return dto;
             }
-            final Long orgId = devices.get(0).getOrgId();
-            this.updateDelByOrgId(orgId);
+            final List<Long> orgIdList = devices.stream().map(IotSensor::getOrgId).distinct().collect(Collectors.toList());
+            this.updateDelByOrgId(orgIdList);
             this.saveOrUpdateBatch(devices);
         }
         return dto;