|  | @@ -6,13 +6,18 @@ import java.io.OutputStream;
 | 
	
		
			
				|  |  |  import java.io.UnsupportedEncodingException;
 | 
	
		
			
				|  |  |  import java.net.URLEncoder;
 | 
	
		
			
				|  |  |  import java.util.*;
 | 
	
		
			
				|  |  | +import java.util.concurrent.TimeUnit;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  import cn.hutool.core.io.IoUtil;
 | 
	
		
			
				|  |  |  import cn.hutool.core.util.ObjectUtil;
 | 
	
		
			
				|  |  |  import com.alibaba.excel.EasyExcel;
 | 
	
		
			
				|  |  |  import com.alibaba.nacos.common.utils.CollectionUtils;
 | 
	
		
			
				|  |  | +import com.xunmei.common.core.constant.CacheConstants;
 | 
	
		
			
				|  |  | +import com.xunmei.common.core.constant.Constants;
 | 
	
		
			
				|  |  |  import com.xunmei.common.core.constant.ErrorMsgConstants;
 | 
	
		
			
				|  |  |  import com.xunmei.common.core.constant.SecurityConstants;
 | 
	
		
			
				|  |  | +import com.xunmei.common.core.domain.mediator.domain.MediatorCategory;
 | 
	
		
			
				|  |  | +import com.xunmei.common.core.domain.mediator.vo.EquipmentOrgVo;
 | 
	
		
			
				|  |  |  import com.xunmei.common.core.domain.retrieval.vo.CoreMonitoringRetrievalTaskExcelVo;
 | 
	
		
			
				|  |  |  import com.xunmei.common.core.exception.ServiceException;
 | 
	
		
			
				|  |  |  import com.xunmei.common.core.utils.DateHelper;
 | 
	
	
		
			
				|  | @@ -22,12 +27,18 @@ import com.xunmei.system.api.RemoteMediatorService;
 | 
	
		
			
				|  |  |  import com.xunmei.system.api.RemoteProtectionService;
 | 
	
		
			
				|  |  |  import com.xunmei.system.api.domain.SysDevice;
 | 
	
		
			
				|  |  |  import com.xunmei.system.api.domain.SysDictData;
 | 
	
		
			
				|  |  | +import com.xunmei.system.api.domain.SysOperLog;
 | 
	
		
			
				|  |  |  import com.xunmei.system.api.domain.SysOrg;
 | 
	
		
			
				|  |  | +import com.xunmei.system.api.domain.north.NorthError;
 | 
	
		
			
				|  |  |  import com.xunmei.system.api.dto.ProtectionDTO;
 | 
	
		
			
				|  |  |  import com.xunmei.system.api.dto.SysDeviceInnerListDto;
 | 
	
		
			
				|  |  | +import com.xunmei.system.api.dto.device.DeviceDto;
 | 
	
		
			
				|  |  |  import com.xunmei.system.api.dto.device.DeviceReceivePageDto;
 | 
	
		
			
				|  |  |  import com.xunmei.system.api.dto.protection.ReceiveErrorDto;
 | 
	
		
			
				|  |  |  import com.xunmei.system.api.enums.DataType;
 | 
	
		
			
				|  |  | +import com.xunmei.system.api.enums.DeviceOnlineStatus;
 | 
	
		
			
				|  |  | +import com.xunmei.system.api.enums.DeviceStatus;
 | 
	
		
			
				|  |  | +import com.xunmei.system.api.enums.DeviceType;
 | 
	
		
			
				|  |  |  import com.xunmei.system.api.function.RemoteCallHandlerExecutor;
 | 
	
		
			
				|  |  |  import com.xunmei.system.api.util.LogUtils;
 | 
	
		
			
				|  |  |  import com.xunmei.system.api.vo.ProtectionVO;
 | 
	
	
		
			
				|  | @@ -39,6 +50,7 @@ import com.xunmei.system.vo.area.VideoVO;
 | 
	
		
			
				|  |  |  import org.apache.commons.lang3.StringUtils;
 | 
	
		
			
				|  |  |  import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 | 
	
		
			
				|  |  |  import org.springframework.beans.factory.annotation.Autowired;
 | 
	
		
			
				|  |  | +import org.springframework.data.redis.core.RedisTemplate;
 | 
	
		
			
				|  |  |  import org.springframework.stereotype.Component;
 | 
	
		
			
				|  |  |  import org.springframework.stereotype.Service;
 | 
	
		
			
				|  |  |  import com.xunmei.system.service.ISysOrgService;
 | 
	
	
		
			
				|  | @@ -70,6 +82,8 @@ public class SysDeviceServiceImpl extends ServiceImpl<SysDeviceMapper, SysDevice
 | 
	
		
			
				|  |  |      private RemoteProtectionService remoteProtectionService;
 | 
	
		
			
				|  |  |      @Autowired
 | 
	
		
			
				|  |  |      private RemoteMediatorService remoteMediatorService;
 | 
	
		
			
				|  |  | +    @Autowired
 | 
	
		
			
				|  |  | +    private RedisTemplate redisTemplate;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  |      public TableDataInfo<SysDevice> selectPage(SysDevice sysDevice) {
 | 
	
	
		
			
				|  | @@ -350,7 +364,7 @@ public class SysDeviceServiceImpl extends ServiceImpl<SysDeviceMapper, SysDevice
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  |      public SysDevice findByHostCode(String code) {
 | 
	
		
			
				|  |  | -        return lambdaQuery().eq(SysDevice::getHostCode, code).last("limit 1").one();
 | 
	
		
			
				|  |  | +        return lambdaQuery().eq(SysDevice::getHostCode, code).last(Constants.LIMIT1).one();
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Override
 | 
	
	
		
			
				|  | @@ -379,4 +393,163 @@ public class SysDeviceServiceImpl extends ServiceImpl<SysDeviceMapper, SysDevice
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          return ReceiveErrorDto.success();
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    public ReceiveErrorDto saveChannel(List<DeviceDto> deviceDtoList, String branchId, String msgId) {
 | 
	
		
			
				|  |  | +        if (org.apache.commons.collections4.CollectionUtils.isEmpty(deviceDtoList)) {
 | 
	
		
			
				|  |  | +            return ReceiveErrorDto.error("通道数据为空");
 | 
	
		
			
				|  |  | +        } else {
 | 
	
		
			
				|  |  | +            MediatorCategory category = remoteMediatorService.findCategoryByCodeAndParentId("18", -1L,SecurityConstants.INNER);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            DeviceDto deviceDto;
 | 
	
		
			
				|  |  | +            List<NorthError> errors = new ArrayList<>();
 | 
	
		
			
				|  |  | +            List<SysDevice> list = new ArrayList<>();
 | 
	
		
			
				|  |  | +            String equipmentId = null;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            deviceDto = deviceDtoList.get(0);
 | 
	
		
			
				|  |  | +            equipmentId = deviceDto.getEquipmentCode();
 | 
	
		
			
				|  |  | +            final SysOrg org = orgService.findByGuid(deviceDto.getOrganizationGuid());
 | 
	
		
			
				|  |  | +            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);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            for (int i = 0; i < deviceDtoList.size(); i++) {
 | 
	
		
			
				|  |  | +                deviceDto = deviceDtoList.get(i);
 | 
	
		
			
				|  |  | +                if (StringUtils.isEmpty(deviceDto.getEquipmentCode())) {
 | 
	
		
			
				|  |  | +                    NorthError error = new NorthError(msgId, branchId, "/data/channelList"
 | 
	
		
			
				|  |  | +                            , deviceDto, "equipmentCode 为空");
 | 
	
		
			
				|  |  | +                    errors.add(error);
 | 
	
		
			
				|  |  | +                    continue;
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                if (StringUtils.isEmpty(deviceDto.getOrganizationGuid())) {
 | 
	
		
			
				|  |  | +                    NorthError error = new NorthError(msgId, branchId, "/data/channelList"
 | 
	
		
			
				|  |  | +                            , deviceDto, "organizationGuid 为空");
 | 
	
		
			
				|  |  | +                    errors.add(error);
 | 
	
		
			
				|  |  | +                    continue;
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                if (StringUtils.isEmpty(deviceDto.getChannelCode())) {
 | 
	
		
			
				|  |  | +                    NorthError error = new NorthError(msgId, branchId, "/data/channelList"
 | 
	
		
			
				|  |  | +                            , deviceDto, "channelCode 为空");
 | 
	
		
			
				|  |  | +                    errors.add(error);
 | 
	
		
			
				|  |  | +                    continue;
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                if (StringUtils.isEmpty(deviceDto.getChannelName())) {
 | 
	
		
			
				|  |  | +                    NorthError error = new NorthError(msgId, branchId, "/data/channelList"
 | 
	
		
			
				|  |  | +                            , deviceDto, "channelName 为空");
 | 
	
		
			
				|  |  | +                    errors.add(error);
 | 
	
		
			
				|  |  | +                    continue;
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                if (org == null) {
 | 
	
		
			
				|  |  | +                    NorthError error = new NorthError(msgId, branchId, "/data/channelList"
 | 
	
		
			
				|  |  | +                            , deviceDto, "orgGUID:" + deviceDto.getOrganizationGuid() + " 不正确");
 | 
	
		
			
				|  |  | +                    errors.add(error);
 | 
	
		
			
				|  |  | +                    continue;
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                /**
 | 
	
		
			
				|  |  | +                 * 逻辑删除数据
 | 
	
		
			
				|  |  | +                 */
 | 
	
		
			
				|  |  | +                //修改成单独事务执行
 | 
	
		
			
				|  |  | +                //equipmentSyncService.deleteChannel(equipmentId,org.getId(),category);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                /**
 | 
	
		
			
				|  |  | +                 * 先不做数据处理,先缓存所有待处理的数据,然后每5分钟处理一次缓存数据
 | 
	
		
			
				|  |  | +                 */
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                deviceDto.setOrg(org);
 | 
	
		
			
				|  |  | +                SysDevice host = this.findByCodeAndOrgId(deviceDto.getEquipmentCode(), org.getId());
 | 
	
		
			
				|  |  | +                if (host == null) {
 | 
	
		
			
				|  |  | +                    NorthError error = new NorthError(msgId, branchId, "/data/channelList"
 | 
	
		
			
				|  |  | +                            , deviceDto, "equipmentCode:" + deviceDto.getEquipmentCode() + "该主机code不存在");
 | 
	
		
			
				|  |  | +                    errors.add(error);
 | 
	
		
			
				|  |  | +                    continue;
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                SysDevice device = getChannelDevice(deviceDto, category);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                list.add(device);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            //this.northStatisticsSyncService.saveOrUpdateAllBaseCountByDataType(DataType.channelCount,list.size());
 | 
	
		
			
				|  |  | +            //deviceDao.saveOrUpdateBatch(list);
 | 
	
		
			
				|  |  | +            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) {
 | 
	
		
			
				|  |  | +                remoteMediatorService.saveErrorData(errors,SecurityConstants.INNER);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            return ReceiveErrorDto.success();
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private SysDevice getChannelDevice(DeviceDto deviceDto, MediatorCategory category) {
 | 
	
		
			
				|  |  | +        SysDevice device = new SysDevice();
 | 
	
		
			
				|  |  | +        SysDevice old = this.findByHostCodeAndCodeAndOrgId(deviceDto.getEquipmentCode(), deviceDto.getChannelCode(), deviceDto.getOrg().getId());
 | 
	
		
			
				|  |  | +        if (old != null) {
 | 
	
		
			
				|  |  | +            device = old;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        device.setDeviceName(deviceDto.getChannelName());
 | 
	
		
			
				|  |  | +        device.setDeviceType(String.valueOf(DeviceType.Camera.ordinal()));
 | 
	
		
			
				|  |  | +        device.setHostCode(deviceDto.getEquipmentCode());
 | 
	
		
			
				|  |  | +        device.setOrgId(deviceDto.getOrg().getId());
 | 
	
		
			
				|  |  | +        device.setOrgPath(deviceDto.getOrg().getPath());
 | 
	
		
			
				|  |  | +        device.setOrgName(deviceDto.getOrg().getName());
 | 
	
		
			
				|  |  | +        device.setStatus(DeviceStatus.ENABLE.ordinal());
 | 
	
		
			
				|  |  | +        device.setChannelId(deviceDto.getChannelCode());
 | 
	
		
			
				|  |  | +        device.setIp(deviceDto.getNetAddress());
 | 
	
		
			
				|  |  | +        device.setOnlineStatus(DeviceOnlineStatus.UNKNOW.ordinal());
 | 
	
		
			
				|  |  | +        Date date = new Date();
 | 
	
		
			
				|  |  | +        device.setUpdateTime(date);
 | 
	
		
			
				|  |  | +        device.setCreateTime(date);
 | 
	
		
			
				|  |  | +        if (category != null) {
 | 
	
		
			
				|  |  | +            device.setCategoryId(category.getId());
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        device.setSource(1);
 | 
	
		
			
				|  |  | +        device.setDelFlag("0");
 | 
	
		
			
				|  |  | +        return device;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    public SysDevice findByHostCodeAndCodeAndOrgId(String equipmentCode, String channelCode, Long orgId) {
 | 
	
		
			
				|  |  | +        return lambdaQuery()
 | 
	
		
			
				|  |  | +                .eq(SysDevice::getHostCode, equipmentCode)
 | 
	
		
			
				|  |  | +                .eq(SysDevice::getChannelId, channelCode)
 | 
	
		
			
				|  |  | +                .eq(SysDevice::getOrgId, orgId)
 | 
	
		
			
				|  |  | +                .last(Constants.LIMIT1)
 | 
	
		
			
				|  |  | +                .one();
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    public SysDevice findByCodeAndOrgId(String code, Long orgId) {
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        return lambdaQuery()
 | 
	
		
			
				|  |  | +                .eq(SysDevice::getChannelId, code)
 | 
	
		
			
				|  |  | +                .eq(SysDevice::getOrgId, orgId)
 | 
	
		
			
				|  |  | +                .last(Constants.LIMIT1)
 | 
	
		
			
				|  |  | +                .one();
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  |  }
 |