|  | @@ -0,0 +1,373 @@
 | 
	
		
			
				|  |  | +package com.xunmei.mediator.api.service.impl;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +import com.alibaba.fastjson.JSON;
 | 
	
		
			
				|  |  | +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 | 
	
		
			
				|  |  | +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 | 
	
		
			
				|  |  | +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.constant.Constants;
 | 
	
		
			
				|  |  | +import com.xunmei.common.core.constant.SecurityConstants;
 | 
	
		
			
				|  |  | +import com.xunmei.common.core.domain.mediator.domain.MediatorCategory;
 | 
	
		
			
				|  |  | +import com.xunmei.common.core.domain.protect.domain.IotDefenceAre;
 | 
	
		
			
				|  |  | +import com.xunmei.common.core.domain.protect.domain.IotSubSystem;
 | 
	
		
			
				|  |  | +import com.xunmei.common.core.util.BeanHelper;
 | 
	
		
			
				|  |  | +import com.xunmei.common.core.utils.DateUtils;
 | 
	
		
			
				|  |  | +import com.xunmei.common.core.utils.IDHelper;
 | 
	
		
			
				|  |  | +import com.xunmei.common.redis.utils.RedisUtils;
 | 
	
		
			
				|  |  | +import com.xunmei.mediator.api.mapper.IotSubSystemMapper;
 | 
	
		
			
				|  |  | +import com.xunmei.mediator.api.service.*;
 | 
	
		
			
				|  |  | +import com.xunmei.system.api.RemoteDeviceService;
 | 
	
		
			
				|  |  | +import com.xunmei.system.api.RemoteOrgService;
 | 
	
		
			
				|  |  | +import com.xunmei.system.api.domain.SysDevice;
 | 
	
		
			
				|  |  | +import com.xunmei.system.api.domain.north.NorthError;
 | 
	
		
			
				|  |  | +import com.xunmei.system.api.dto.protection.DefenceAreaDto;
 | 
	
		
			
				|  |  | +import com.xunmei.system.api.dto.protection.DefenceareaPageDto;
 | 
	
		
			
				|  |  | +import com.xunmei.system.api.dto.protection.ReceiveErrorDto;
 | 
	
		
			
				|  |  | +import com.xunmei.system.api.dto.protection.SensorDto;
 | 
	
		
			
				|  |  | +import com.xunmei.system.api.enums.DataType;
 | 
	
		
			
				|  |  | +import com.xunmei.system.api.util.LogUtils;
 | 
	
		
			
				|  |  | +import com.xunmei.system.api.vo.SysOrgVO;
 | 
	
		
			
				|  |  | +import org.apache.commons.collections4.CollectionUtils;
 | 
	
		
			
				|  |  | +import org.apache.commons.lang3.StringUtils;
 | 
	
		
			
				|  |  | +import org.springframework.data.redis.core.RedisTemplate;
 | 
	
		
			
				|  |  | +import org.springframework.stereotype.Service;
 | 
	
		
			
				|  |  | +import sun.management.Sensor;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +import javax.annotation.Resource;
 | 
	
		
			
				|  |  | +import java.util.*;
 | 
	
		
			
				|  |  | +import java.util.concurrent.TimeUnit;
 | 
	
		
			
				|  |  | +import java.util.stream.Collectors;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +/**
 | 
	
		
			
				|  |  | + * <p>
 | 
	
		
			
				|  |  | + * 服务实现类
 | 
	
		
			
				|  |  | + * </p>
 | 
	
		
			
				|  |  | + *
 | 
	
		
			
				|  |  | + * @author oygj
 | 
	
		
			
				|  |  | + * @since 2024-01-29
 | 
	
		
			
				|  |  | + */
 | 
	
		
			
				|  |  | +@Service
 | 
	
		
			
				|  |  | +public class IotSubSystemServiceImpl extends ServiceImpl<IotSubSystemMapper, IotSubSystem> implements IIotSubSystemService {
 | 
	
		
			
				|  |  | +    @Resource
 | 
	
		
			
				|  |  | +    RemoteOrgService orgService;
 | 
	
		
			
				|  |  | +    @Resource
 | 
	
		
			
				|  |  | +    RedisTemplate redisTemplate;
 | 
	
		
			
				|  |  | +    @Resource
 | 
	
		
			
				|  |  | +    NorthStatisticsSyncService northStatisticsSyncService;
 | 
	
		
			
				|  |  | +    @Resource
 | 
	
		
			
				|  |  | +    IMediatorCategoryService categoryService;
 | 
	
		
			
				|  |  | +    @Resource
 | 
	
		
			
				|  |  | +    RemoteDeviceService deviceService;
 | 
	
		
			
				|  |  | +    @Resource
 | 
	
		
			
				|  |  | +    private IIotDefenceAreService defenceAreService;
 | 
	
		
			
				|  |  | +    @Resource
 | 
	
		
			
				|  |  | +    private NorthErrorService northErrorService;
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    public IotSubSystem findByCodeAndOrgId(String defenceAreaCode, Long orgId) {
 | 
	
		
			
				|  |  | +        return lambdaQuery()
 | 
	
		
			
				|  |  | +                .eq(IotSubSystem::getSubSystemCode, defenceAreaCode)
 | 
	
		
			
				|  |  | +                .eq(IotSubSystem::getOrgId, orgId)
 | 
	
		
			
				|  |  | +                .last(Constants.LIMIT1)
 | 
	
		
			
				|  |  | +                .one();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    public ReceiveErrorDto defenceAreaList(DefenceareaPageDto request, String branchId, String msgId) {
 | 
	
		
			
				|  |  | +        String packageGuid = request.getPackageGuid();
 | 
	
		
			
				|  |  | +        if (StringUtils.isEmpty(packageGuid)) {
 | 
	
		
			
				|  |  | +            return ReceiveErrorDto.error("packageGuid参数非法");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        Long totalPage = request.getTotalPage();
 | 
	
		
			
				|  |  | +        if (totalPage == null) {
 | 
	
		
			
				|  |  | +            return ReceiveErrorDto.error("totalPage参数非法");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        if (CollectionUtils.isEmpty(request.getData())) {
 | 
	
		
			
				|  |  | +            return ReceiveErrorDto.error("报警主机子系统及防区信息为空");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        boolean completed = this.isCompleted(request);
 | 
	
		
			
				|  |  | +        LogUtils.BASE_INFO_DEFENCEAREA.info("判断是否获取全部报警主机子系统及防区信息分页数据:{}", completed);
 | 
	
		
			
				|  |  | +        if (completed) {
 | 
	
		
			
				|  |  | +            LogUtils.BASE_INFO_DEFENCEAREA.info("获取全部的报警主机子系统及防区信息,开始数据处理界面!");
 | 
	
		
			
				|  |  | +            List<DefenceAreaDto> defenceareaList = new ArrayList<>();
 | 
	
		
			
				|  |  | +            for (int i = 1; i <= totalPage; i++) {
 | 
	
		
			
				|  |  | +                String ak = packageGuid + "_" + i;
 | 
	
		
			
				|  |  | +                Object obj = this.redisTemplate.opsForValue().get(ak);
 | 
	
		
			
				|  |  | +                List<DefenceAreaDto> defenceareaDtos = JSON.parseArray((String) obj, DefenceAreaDto.class);
 | 
	
		
			
				|  |  | +                if (defenceareaDtos != null) {
 | 
	
		
			
				|  |  | +                    defenceareaList.addAll(defenceareaDtos);
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            for (int i = 1; i <= totalPage; i++) {
 | 
	
		
			
				|  |  | +                String ak = packageGuid + "_" + i;
 | 
	
		
			
				|  |  | +                this.redisTemplate.delete(ak);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            //protectionDao.updateAllDelete();
 | 
	
		
			
				|  |  | +            this.northStatisticsSyncService.saveOrUpdateBaseCountByDataType(DataType.protectionCount.getIndex(), defenceareaList.size(), false);
 | 
	
		
			
				|  |  | +            new Thread(() -> {
 | 
	
		
			
				|  |  | +                this.saveAndUpdate(defenceareaList, branchId, msgId);
 | 
	
		
			
				|  |  | +            }).start();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        return ReceiveErrorDto.success();
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    public ReceiveErrorDto saveAndUpdate(List<DefenceAreaDto> defenceareaList, String branchId, String msgId) {
 | 
	
		
			
				|  |  | +        if (CollectionUtils.isEmpty(defenceareaList)) {
 | 
	
		
			
				|  |  | +            return ReceiveErrorDto.error("报警主机子系统及防区信息为空");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        List<NorthError> errors = new ArrayList<>();
 | 
	
		
			
				|  |  | +        List<IotSubSystem> protectionList = new ArrayList<>();
 | 
	
		
			
				|  |  | +        List<IotDefenceAre> sensorList = new ArrayList<>();
 | 
	
		
			
				|  |  | +        List<IotSubSystem> deviceList = new ArrayList<>();
 | 
	
		
			
				|  |  | +        //获取机构列表
 | 
	
		
			
				|  |  | +        final List<SysOrgVO> orgList = RedisUtils.getCacheList(CacheConstants.ORG_CACHE_LIST_KEY);
 | 
	
		
			
				|  |  | +        //获取category列表
 | 
	
		
			
				|  |  | +        List<MediatorCategory> categorys = categoryService.list();
 | 
	
		
			
				|  |  | +        //查询报警主机主机设备列表
 | 
	
		
			
				|  |  | +        List<SysDevice> devices = deviceService.findAlarmHostDevice(3713671920926720L, SecurityConstants.INNER);
 | 
	
		
			
				|  |  | +        checkParam(defenceareaList, branchId, msgId, errors, orgList, categorys, devices, deviceList, protectionList,sensorList);
 | 
	
		
			
				|  |  | +        return ReceiveErrorDto.success();
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private void checkParam(List<DefenceAreaDto> defenceareaList, String branchId, String msgId, List<NorthError> errors, List<SysOrgVO> orgList, List<MediatorCategory> categorys, List<SysDevice> devices, List<IotSubSystem> deviceList, List<IotSubSystem> protectionList, List<IotDefenceAre> sensorList) {
 | 
	
		
			
				|  |  | +        NorthError error = null;
 | 
	
		
			
				|  |  | +        for (DefenceAreaDto dto : defenceareaList) {
 | 
	
		
			
				|  |  | +            SysOrgVO org = null;
 | 
	
		
			
				|  |  | +            if (StringUtils.isEmpty(dto.getOrganizationGuid())) {
 | 
	
		
			
				|  |  | +                error = new NorthError(msgId, branchId, "/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, branchId, "/api/data/defenceareaList"
 | 
	
		
			
				|  |  | +                            , dto, "orgGUID:" + dto.getOrganizationGuid() + "不正确");
 | 
	
		
			
				|  |  | +                    errors.add(error);
 | 
	
		
			
				|  |  | +                    continue;
 | 
	
		
			
				|  |  | +                } else {
 | 
	
		
			
				|  |  | +                    org = orgs.get(0);
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            if (StringUtils.isEmpty(dto.getDefenceAreaCode())) {
 | 
	
		
			
				|  |  | +                error = new NorthError(msgId, branchId, "/api/data/defenceareaList"
 | 
	
		
			
				|  |  | +                        , dto, "参数非法:未传defenceareaCode");
 | 
	
		
			
				|  |  | +                errors.add(error);
 | 
	
		
			
				|  |  | +                continue;
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            if (StringUtils.isEmpty(dto.getDefenceAreaName())) {
 | 
	
		
			
				|  |  | +                error = new NorthError(msgId, branchId, "/api/data/defenceareaList"
 | 
	
		
			
				|  |  | +                        , dto, "参数非法:未传defenceareaName");
 | 
	
		
			
				|  |  | +                errors.add(error);
 | 
	
		
			
				|  |  | +                continue;
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            if (StringUtils.isEmpty(dto.getAlarmHostCode())) {
 | 
	
		
			
				|  |  | +                error = new NorthError(msgId, branchId, "/api/data/defenceareaList"
 | 
	
		
			
				|  |  | +                        , dto, "参数非法:未传alarmHostCode");
 | 
	
		
			
				|  |  | +                errors.add(error);
 | 
	
		
			
				|  |  | +                continue;
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            if (dto.getSensorArray() == null || dto.getSensorArray().size() == 0) {
 | 
	
		
			
				|  |  | +                error = new NorthError(msgId, branchId, "/api/data/defenceareaList"
 | 
	
		
			
				|  |  | +                        , dto, "参数非法:未传sensorArray");
 | 
	
		
			
				|  |  | +                errors.add(error);
 | 
	
		
			
				|  |  | +                //continue;
 | 
	
		
			
				|  |  | +            } else {
 | 
	
		
			
				|  |  | +                List<SensorDto> sensorArray = dto.getSensorArray();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                for (SensorDto sensorDto : sensorArray) {
 | 
	
		
			
				|  |  | +                    if (StringUtils.isEmpty(sensorDto.getInputName())) {
 | 
	
		
			
				|  |  | +                        error = new NorthError(msgId, branchId, "/api/data/defenceareaList"
 | 
	
		
			
				|  |  | +                                , dto, "参数非法:未传InputName");
 | 
	
		
			
				|  |  | +                        errors.add(error);
 | 
	
		
			
				|  |  | +                        continue;
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                    if (sensorDto.getInputIndex() == null) {
 | 
	
		
			
				|  |  | +                        error = new NorthError(msgId, branchId, "/api/data/defenceareaList"
 | 
	
		
			
				|  |  | +                                , dto, "参数非法:未传InputIndex");
 | 
	
		
			
				|  |  | +                        errors.add(error);
 | 
	
		
			
				|  |  | +                        continue;
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                    if (StringUtils.isEmpty(sensorDto.getModuleAddress())) {
 | 
	
		
			
				|  |  | +                        error = new NorthError(msgId, branchId, "/api/data/defenceareaList"
 | 
	
		
			
				|  |  | +                                , dto, "参数非法:未传ModuleAddress");
 | 
	
		
			
				|  |  | +                        errors.add(error);
 | 
	
		
			
				|  |  | +                        continue;
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                    if (StringUtils.isEmpty(sensorDto.getSensorType())) {
 | 
	
		
			
				|  |  | +                        error = new NorthError(msgId, branchId, "/api/data/defenceareaList"
 | 
	
		
			
				|  |  | +                                , dto, "参数非法:未传SensorType");
 | 
	
		
			
				|  |  | +                        errors.add(error);
 | 
	
		
			
				|  |  | +                        continue;
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                    if (StringUtils.isEmpty(sensorDto.getSensorTypeName())) {
 | 
	
		
			
				|  |  | +                        error = new NorthError(msgId, branchId, "/api/data/defenceareaList"
 | 
	
		
			
				|  |  | +                                , dto, "参数非法:未传SensorTypeName");
 | 
	
		
			
				|  |  | +                        errors.add(error);
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                    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, branchId, "/api/data/defenceareaList"
 | 
	
		
			
				|  |  | +                                , dto, "参数非法:没有找到设备类型,默认归到其他类型中");
 | 
	
		
			
				|  |  | +                        errors.add(error);
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            SysOrgVO finalOrg = org;
 | 
	
		
			
				|  |  | +            SysDevice device = null;
 | 
	
		
			
				|  |  | +            List<SysDevice> devicesa = devices.stream().filter(r -> r.getHostCode().equals(dto.getAlarmHostCode()) && r.getOrgId().equals(finalOrg.getId())).collect(Collectors.toList());
 | 
	
		
			
				|  |  | +            if (devicesa == null || devicesa.size() == 0) {
 | 
	
		
			
				|  |  | +                error = new NorthError(msgId, branchId, "/api/data/defenceareaList"
 | 
	
		
			
				|  |  | +                        , dto, "参数非法:没有找到报警主机");
 | 
	
		
			
				|  |  | +                errors.add(error);
 | 
	
		
			
				|  |  | +                continue;
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            Map<String, Object> map = this.protectionBuild(dto, org);
 | 
	
		
			
				|  |  | +            if (map != null) {
 | 
	
		
			
				|  |  | +                protectionList.add((IotSubSystem) map.get("protection"));
 | 
	
		
			
				|  |  | +                List<IotDefenceAre> list = (List<IotDefenceAre>) map.get("sensorList");
 | 
	
		
			
				|  |  | +                if (list != null && list.size() > 0) {
 | 
	
		
			
				|  |  | +                    sensorList.addAll(list);
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        try {
 | 
	
		
			
				|  |  | +            //删除传感器表中的数据
 | 
	
		
			
				|  |  | +            defenceAreService.remove(new LambdaQueryWrapper<>());
 | 
	
		
			
				|  |  | +        } catch (Exception e) {
 | 
	
		
			
				|  |  | +            log.error("删除传感器表中的数据失败,失败原因:" + e.getMessage(), e);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        if (errors.size() > 0) {
 | 
	
		
			
				|  |  | +            northErrorService.saveErrorData(errors);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        try {
 | 
	
		
			
				|  |  | +            baseMapper.updateAllDelete();
 | 
	
		
			
				|  |  | +        } catch (Exception e) {
 | 
	
		
			
				|  |  | +            log.error("修改子系统为逻辑删除失败,失败原因:" + e.getMessage(), e);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        try {
 | 
	
		
			
				|  |  | +            this.saveOrUpdateBatch(protectionList);
 | 
	
		
			
				|  |  | +        } catch (Exception e) {
 | 
	
		
			
				|  |  | +            log.error("更新子系统数据失败,失败原因:" + e.getMessage(), e);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        try {
 | 
	
		
			
				|  |  | +            defenceAreService.saveOrUpdateBatch(sensorList);
 | 
	
		
			
				|  |  | +        } catch (Exception e) {
 | 
	
		
			
				|  |  | +            log.error("更新t_sensor表传感器数据失败,失败原因:" + e.getMessage(), e);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        this.northStatisticsSyncService.saveOrUpdateBaseCountByDataType(DataType.protectionCount.getIndex(), defenceareaList.size(), true);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    public Map<String, Object> protectionBuild(DefenceAreaDto dto, SysOrgVO org) {
 | 
	
		
			
				|  |  | +        Map<String, Object> map = new HashMap<>();
 | 
	
		
			
				|  |  | +        IotSubSystem protection = null;
 | 
	
		
			
				|  |  | +        IotSubSystem old = this.findByCodeAndOrgId(dto.getDefenceAreaCode(), org.getId());
 | 
	
		
			
				|  |  | +        if (old != null) {
 | 
	
		
			
				|  |  | +            protection = old;
 | 
	
		
			
				|  |  | +        } else {
 | 
	
		
			
				|  |  | +            protection = new IotSubSystem();
 | 
	
		
			
				|  |  | +            protection.setId(IDHelper.id());
 | 
	
		
			
				|  |  | +            protection.setCreateTime(DateUtils.toLocalDateTime(new Date()));
 | 
	
		
			
				|  |  | +            protection.setStatus(2);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        protection.setDeleted(0);
 | 
	
		
			
				|  |  | +        protection.setAlarmHostCode(dto.getAlarmHostCode());
 | 
	
		
			
				|  |  | +        protection.setSubSystemCode(dto.getDefenceAreaCode());
 | 
	
		
			
				|  |  | +        protection.setSubSystemName(dto.getDefenceAreaName());
 | 
	
		
			
				|  |  | +        protection.setOrgId(org.getId());
 | 
	
		
			
				|  |  | +        protection.setOrgName(org.getName());
 | 
	
		
			
				|  |  | +        protection.setOrgPath(org.getPath());
 | 
	
		
			
				|  |  | +        map.put("protection", protection);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        List<SensorDto> sensorArray = dto.getSensorArray();
 | 
	
		
			
				|  |  | +        if (sensorArray != null && sensorArray.size() > 0) {
 | 
	
		
			
				|  |  | +            List<IotDefenceAre> list = new ArrayList<>();
 | 
	
		
			
				|  |  | +            List<IotDefenceAre> list1 = new ArrayList<>();
 | 
	
		
			
				|  |  | +            List<IotDefenceAre> sensorList=  defenceAreService.findBySubSystemCode(dto.getDefenceAreaCode());
 | 
	
		
			
				|  |  | +            for (SensorDto sensorDto : sensorArray) {
 | 
	
		
			
				|  |  | +                IotDefenceAre sensor = new IotDefenceAre();
 | 
	
		
			
				|  |  | +                sensor.setAlarmHostCode(dto.getAlarmHostCode());
 | 
	
		
			
				|  |  | +                sensor.setSubSystemCode(dto.getDefenceAreaCode());
 | 
	
		
			
				|  |  | +                sensor.setDefenceAreaName(dto.getDefenceAreaName());
 | 
	
		
			
				|  |  | +                sensor.setOrgId(org.getId());
 | 
	
		
			
				|  |  | +                sensor.setOrgName(org.getName());
 | 
	
		
			
				|  |  | +                sensor.setOrgPath(org.getPath());
 | 
	
		
			
				|  |  | +                sensor.setDefenceAreaIndex(sensorDto.getInputIndex());
 | 
	
		
			
				|  |  | +                sensor.setDefenceAreaName(sensorDto.getInputName());
 | 
	
		
			
				|  |  | +                //sensor.setModuleAddress(sensorDto.getModuleAddress());
 | 
	
		
			
				|  |  | +                sensor.setSensorType(sensorDto.getSensorType());
 | 
	
		
			
				|  |  | +                sensor.setSensorTypeName(sensorDto.getSensorTypeName());
 | 
	
		
			
				|  |  | +                //sensor.setStrDeviceId(dto.getDefenceAreaCode() + sensorDto.getInputIndex());
 | 
	
		
			
				|  |  | +                String strDeviceId = dto.getDefenceAreaCode() + sensorDto.getInputIndex();
 | 
	
		
			
				|  |  | +                final Optional<IotDefenceAre> optional = sensorList.stream()
 | 
	
		
			
				|  |  | +                        .filter(r -> r.getOrgId().equals(org.getId()))
 | 
	
		
			
				|  |  | +                        .filter(r -> r.getAlarmHostCode().equals(dto.getAlarmHostCode()))
 | 
	
		
			
				|  |  | +                        .filter(r -> r.getSubSystemCode().equals(dto.getDefenceAreaCode()))
 | 
	
		
			
				|  |  | +                        .filter(r -> r.getDefenceAreaIndex().equals(sensorDto.getInputIndex()))
 | 
	
		
			
				|  |  | +                        .max(Comparator.comparing(IotDefenceAre::getUpdateTime));
 | 
	
		
			
				|  |  | +                if (optional.isPresent()) {
 | 
	
		
			
				|  |  | +                    final IotDefenceAre iotDefenceAre = optional.get();
 | 
	
		
			
				|  |  | +                    BeanHelper.copyProperties(iotDefenceAre, sensor);
 | 
	
		
			
				|  |  | +                    list.add(iotDefenceAre);
 | 
	
		
			
				|  |  | +                } else {
 | 
	
		
			
				|  |  | +                    sensor.setId(IDHelper.id());
 | 
	
		
			
				|  |  | +                    sensor.setStatusValue("unKnown");
 | 
	
		
			
				|  |  | +                    sensor.setStatusText("未知");
 | 
	
		
			
				|  |  | +                    list.add(sensor);
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            map.put("sensorList", list);
 | 
	
		
			
				|  |  | +            map.put("deviceList", list1);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        return map;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    public boolean isCompleted(DefenceareaPageDto request) {
 | 
	
		
			
				|  |  | +        String guid = request.getPackageGuid();
 | 
	
		
			
				|  |  | +        Long currPage = request.getCurrPage();
 | 
	
		
			
				|  |  | +        Long totalPage = request.getTotalPage();
 | 
	
		
			
				|  |  | +        List<DefenceAreaDto> defenceareaList = request.getData();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        /**
 | 
	
		
			
				|  |  | +         * 生成每一页的redis key值
 | 
	
		
			
				|  |  | +         */
 | 
	
		
			
				|  |  | +        String key = guid + "_" + currPage;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        /**
 | 
	
		
			
				|  |  | +         * 判断是否已经获取到该分页数据,如果已获取到,则直接返回
 | 
	
		
			
				|  |  | +         */
 | 
	
		
			
				|  |  | +        Boolean isExist = redisTemplate.hasKey(key);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        if (!isExist) {
 | 
	
		
			
				|  |  | +            String data = JSON.toJSONString(defenceareaList);
 | 
	
		
			
				|  |  | +            this.redisTemplate.opsForValue().set(key, data);
 | 
	
		
			
				|  |  | +            this.redisTemplate.expire(key, 1, TimeUnit.DAYS);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        //判断是否完整
 | 
	
		
			
				|  |  | +        for (int i = 1; i <= totalPage; i++) {
 | 
	
		
			
				|  |  | +            String ak = guid + "_" + i;
 | 
	
		
			
				|  |  | +            Boolean isOk = redisTemplate.hasKey(ak);
 | 
	
		
			
				|  |  | +            if (!isOk) {
 | 
	
		
			
				|  |  | +                return false;
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        return true;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +}
 |