|  | @@ -21,14 +21,19 @@ import com.xunmei.common.core.enums.CategoryDataEnum;
 | 
	
		
			
				|  |  |  import com.xunmei.common.core.util.BeanHelper;
 | 
	
		
			
				|  |  |  import com.xunmei.common.core.utils.IDHelper;
 | 
	
		
			
				|  |  |  import com.xunmei.common.redis.utils.RedisUtils;
 | 
	
		
			
				|  |  | +import com.xunmei.mediator.api.mapper.IotAlarmSubsystemMapper;
 | 
	
		
			
				|  |  |  import com.xunmei.mediator.api.mapper.MediatorTimeTemplateMapper;
 | 
	
		
			
				|  |  |  import com.xunmei.mediator.api.mapper.ProtectionLogMapper;
 | 
	
		
			
				|  |  | -import com.xunmei.mediator.api.mapper.IotAlarmSubsystemMapper;
 | 
	
		
			
				|  |  |  import com.xunmei.mediator.api.service.*;
 | 
	
		
			
				|  |  | +import com.xunmei.mediator.util.RedisCheckRepeatDataUtil;
 | 
	
		
			
				|  |  |  import com.xunmei.system.api.RemoteOrgService;
 | 
	
		
			
				|  |  |  import com.xunmei.system.api.domain.SysOrg;
 | 
	
		
			
				|  |  |  import com.xunmei.system.api.domain.north.NorthError;
 | 
	
		
			
				|  |  | -import com.xunmei.system.api.dto.protection.*;
 | 
	
		
			
				|  |  | +import com.xunmei.system.api.dto.DataPageDto;
 | 
	
		
			
				|  |  | +import com.xunmei.system.api.dto.protection.DefenceAreaDto;
 | 
	
		
			
				|  |  | +import com.xunmei.system.api.dto.protection.ProtectionEditDto;
 | 
	
		
			
				|  |  | +import com.xunmei.system.api.dto.protection.ReceiveErrorDto;
 | 
	
		
			
				|  |  | +import com.xunmei.system.api.dto.protection.SensorDto;
 | 
	
		
			
				|  |  |  import com.xunmei.system.api.enums.AlarmRuleExpressOperateEnum;
 | 
	
		
			
				|  |  |  import com.xunmei.system.api.enums.DataType;
 | 
	
		
			
				|  |  |  import com.xunmei.system.api.enums.ProtectionStatus;
 | 
	
	
		
			
				|  | @@ -37,7 +42,6 @@ import com.xunmei.system.api.vo.SysOrgVO;
 | 
	
		
			
				|  |  |  import lombok.extern.slf4j.Slf4j;
 | 
	
		
			
				|  |  |  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 org.springframework.transaction.annotation.Transactional;
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -46,7 +50,6 @@ import java.time.LocalDateTime;
 | 
	
		
			
				|  |  |  import java.time.ZoneId;
 | 
	
		
			
				|  |  |  import java.time.format.DateTimeFormatter;
 | 
	
		
			
				|  |  |  import java.util.*;
 | 
	
		
			
				|  |  | -import java.util.concurrent.TimeUnit;
 | 
	
		
			
				|  |  |  import java.util.stream.Collectors;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -66,8 +69,6 @@ public class IotAlarmSubSystemServiceImpl extends ServiceImpl<IotAlarmSubsystemM
 | 
	
		
			
				|  |  |      @Resource
 | 
	
		
			
				|  |  |      RemoteOrgService orgService;
 | 
	
		
			
				|  |  |      @Resource
 | 
	
		
			
				|  |  | -    RedisTemplate redisTemplate;
 | 
	
		
			
				|  |  | -    @Resource
 | 
	
		
			
				|  |  |      NorthStatisticsSyncService northStatisticsSyncService;
 | 
	
		
			
				|  |  |      @Resource
 | 
	
		
			
				|  |  |      IMediatorCategoryService categoryService;
 | 
	
	
		
			
				|  | @@ -83,7 +84,6 @@ public class IotAlarmSubSystemServiceImpl extends ServiceImpl<IotAlarmSubsystemM
 | 
	
		
			
				|  |  |      private IMediatorAlarmRuleSourceService alarmRuleSourceService;
 | 
	
		
			
				|  |  |      @Resource
 | 
	
		
			
				|  |  |      private IMediatorAlarmRuleExpressService alarmRuleExpressService;
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  |      public IotAlarmSubsystem findByCodeAndOrgId(String defenceAreaCode, Long orgId) {
 | 
	
		
			
				|  |  |          return lambdaQuery()
 | 
	
	
		
			
				|  | @@ -211,7 +211,7 @@ public class IotAlarmSubSystemServiceImpl extends ServiceImpl<IotAlarmSubsystemM
 | 
	
		
			
				|  |  |          this.saveOrUpdate(protection);
 | 
	
		
			
				|  |  |          this.northStatisticsSyncService.saveOrUpdateBusinessCountByDateAndDataType(DateUtil.today(), DataType.protectionStatusCount.getIndex(), 1L);
 | 
	
		
			
				|  |  |          this.saveProtectionLog(protection);
 | 
	
		
			
				|  |  | -        this.writeValue(device, protection);
 | 
	
		
			
				|  |  | +        //this.writeValue(device, protection);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  /*
 | 
	
		
			
				|  |  |          //动环告警处理
 | 
	
	
		
			
				|  | @@ -247,7 +247,7 @@ public class IotAlarmSubSystemServiceImpl extends ServiceImpl<IotAlarmSubsystemM
 | 
	
		
			
				|  |  |          protectionLogMapper.insert(protectionLog);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    public void writeValue(final IotDevice device, final IotAlarmSubsystem protection) {
 | 
	
		
			
				|  |  | +   /* public void writeValue(final IotDevice device, final IotAlarmSubsystem protection) {
 | 
	
		
			
				|  |  |          Map data = null;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          try {
 | 
	
	
		
			
				|  | @@ -259,7 +259,7 @@ public class IotAlarmSubSystemServiceImpl extends ServiceImpl<IotAlarmSubsystemM
 | 
	
		
			
				|  |  |          String key = this.toKey(device.getOrgId(), Integer.parseInt(device.getDeviceType()));
 | 
	
		
			
				|  |  |          this.redisTemplate.boundHashOps(key).put(device.getId(), data);
 | 
	
		
			
				|  |  |          log.info("[ {} ][ {} ][ {} ] 数据 ==> [ {} ]", new Object[]{device.getOrgId(), device.getDeviceType(), device.getId(), data});
 | 
	
		
			
				|  |  | -    }
 | 
	
		
			
				|  |  | +    }*/
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      private String toKey(final Long orgId, Integer deviceType) {
 | 
	
		
			
				|  |  |          return "device_" + orgId + "_" + deviceType + "_data_map";
 | 
	
	
		
			
				|  | @@ -371,8 +371,9 @@ public class IotAlarmSubSystemServiceImpl extends ServiceImpl<IotAlarmSubsystemM
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  | -    public ReceiveErrorDto defenceAreaList(DefenceareaPageDto request, String branchId, String msgId) {
 | 
	
		
			
				|  |  | +    public ReceiveErrorDto defenceAreaList(DataPageDto<DefenceAreaDto> request, String branchId, String msgId) {
 | 
	
		
			
				|  |  |          String packageGuid = request.getPackageGuid();
 | 
	
		
			
				|  |  |          if (StringUtils.isEmpty(packageGuid)) {
 | 
	
		
			
				|  |  |              return ReceiveErrorDto.error("packageGuid参数非法");
 | 
	
	
		
			
				|  | @@ -385,22 +386,12 @@ public class IotAlarmSubSystemServiceImpl extends ServiceImpl<IotAlarmSubsystemM
 | 
	
		
			
				|  |  |          if (CollectionUtils.isEmpty(request.getData())) {
 | 
	
		
			
				|  |  |              return ReceiveErrorDto.error("报警主机子系统及防区信息为空");
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | -        boolean completed = this.isCompleted(request);
 | 
	
		
			
				|  |  | -        LogUtils.BASE_INFO_DEFENCEAREA.info("判断是否获取全部报警主机子系统及防区信息分页数据:{}", completed);
 | 
	
		
			
				|  |  | -        if (!completed) {
 | 
	
		
			
				|  |  | +        final List<DefenceAreaDto> defenceareaList = RedisCheckRepeatDataUtil.isCompleted(request,DefenceAreaDto.class);
 | 
	
		
			
				|  |  | +        LogUtils.BASE_INFO_DEFENCEAREA.info("判断是否获取全部报警主机子系统及防区信息分页数据:{}", defenceareaList.size() > 0);
 | 
	
		
			
				|  |  | +        if (ObjectUtil.isEmpty(defenceareaList)) {
 | 
	
		
			
				|  |  |              return ReceiveErrorDto.error("尚未获取全部报警主机子系统及防区信息分页数据,暂不处理!");
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          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);
 | 
	
		
			
				|  |  | -            if (ObjectUtil.isNotEmpty(obj)){
 | 
	
		
			
				|  |  | -                List<DefenceAreaDto> defenceareaDtos = JSON.parseArray((String) obj, DefenceAreaDto.class);
 | 
	
		
			
				|  |  | -                defenceareaList.addAll(defenceareaDtos);
 | 
	
		
			
				|  |  | -                redisTemplate.delete(ak);
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  |          this.northStatisticsSyncService.saveOrUpdateBaseCountByDataType(DataType.protectionCount.getIndex(), defenceareaList.size(), false);
 | 
	
		
			
				|  |  |          new Thread(() -> {
 | 
	
		
			
				|  |  |              this.saveAndUpdate(defenceareaList, branchId, msgId);
 | 
	
	
		
			
				|  | @@ -516,50 +507,26 @@ public class IotAlarmSubSystemServiceImpl extends ServiceImpl<IotAlarmSubsystemM
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |              SysOrgVO finalOrg = org;
 | 
	
		
			
				|  |  | -            IotDevice device = null;
 | 
	
		
			
				|  |  |              List<IotDevice> devicesa = devices.stream().filter(r -> r.getEquipmentCode().equals(dto.getAlarmHostCode()) && r.getOrgId().equals(finalOrg.getId())).collect(Collectors.toList());
 | 
	
		
			
				|  |  | -            if (devicesa == null || devicesa.size() == 0) {
 | 
	
		
			
				|  |  | +            if (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((IotAlarmSubsystem) map.get("protection"));
 | 
	
		
			
				|  |  | -                List<IotAlarmDefenceArea> list = (List<IotAlarmDefenceArea>) map.get("sensorList");
 | 
	
		
			
				|  |  | -                if (list != null && list.size() > 0) {
 | 
	
		
			
				|  |  | -                    sensorList.addAll(list);
 | 
	
		
			
				|  |  | -                }
 | 
	
		
			
				|  |  | +            protectionList.add((IotAlarmSubsystem) map.get("protection"));
 | 
	
		
			
				|  |  | +            List<IotAlarmDefenceArea> list = (List<IotAlarmDefenceArea>) map.get("sensorList");
 | 
	
		
			
				|  |  | +            if (ObjectUtil.isNotEmpty(list)) {
 | 
	
		
			
				|  |  | +                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);
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | +        defenceAreService.remove(new LambdaQueryWrapper<>());
 | 
	
		
			
				|  |  | +        northErrorService.saveErrorData(errors);
 | 
	
		
			
				|  |  | +        baseMapper.updateAllDelete();
 | 
	
		
			
				|  |  | +        this.saveOrUpdateBatch(protectionList);
 | 
	
		
			
				|  |  | +        defenceAreService.saveOrUpdateBatch(sensorList);
 | 
	
		
			
				|  |  |          this.northStatisticsSyncService.saveOrUpdateBaseCountByDataType(DataType.protectionCount.getIndex(), defenceareaList.size(), true);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -574,7 +541,9 @@ public class IotAlarmSubSystemServiceImpl extends ServiceImpl<IotAlarmSubsystemM
 | 
	
		
			
				|  |  |              protection.setId(IDHelper.id());
 | 
	
		
			
				|  |  |              protection.setCreateTime(new Date());
 | 
	
		
			
				|  |  |              protection.setStatus(2);
 | 
	
		
			
				|  |  | +            protection.setSource(1);
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | +        protection.setUpdateTime(new Date());
 | 
	
		
			
				|  |  |          protection.setDeleted(0);
 | 
	
		
			
				|  |  |          protection.setAlarmHostCode(dto.getAlarmHostCode());
 | 
	
		
			
				|  |  |          protection.setCode(dto.getDefenceareaCode());
 | 
	
	
		
			
				|  | @@ -598,13 +567,13 @@ public class IotAlarmSubSystemServiceImpl extends ServiceImpl<IotAlarmSubsystemM
 | 
	
		
			
				|  |  |                  sensor.setOrgId(org.getId());
 | 
	
		
			
				|  |  |                  sensor.setOrgName(org.getName());
 | 
	
		
			
				|  |  |                  sensor.setOrgPath(org.getPath());
 | 
	
		
			
				|  |  | +                sensor.setOrganizationGuid(dto.getOrganizationGuid());
 | 
	
		
			
				|  |  |                  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();
 | 
	
		
			
				|  |  | +                sensor.setDeleted(0);
 | 
	
		
			
				|  |  |                  final Optional<IotAlarmDefenceArea> optional = sensorList.stream()
 | 
	
		
			
				|  |  |                          .filter(r -> r.getOrgId().equals(org.getId()))
 | 
	
		
			
				|  |  |                          .filter(r -> r.getAlarmHostCode().equals(dto.getAlarmHostCode()))
 | 
	
	
		
			
				|  | @@ -614,11 +583,14 @@ public class IotAlarmSubSystemServiceImpl extends ServiceImpl<IotAlarmSubsystemM
 | 
	
		
			
				|  |  |                  if (optional.isPresent()) {
 | 
	
		
			
				|  |  |                      final IotAlarmDefenceArea iotDefenceAre = optional.get();
 | 
	
		
			
				|  |  |                      BeanHelper.copyProperties(iotDefenceAre, sensor);
 | 
	
		
			
				|  |  | +                    iotDefenceAre.setUpdateTime(LocalDateTime.now());
 | 
	
		
			
				|  |  |                      list.add(iotDefenceAre);
 | 
	
		
			
				|  |  |                  } else {
 | 
	
		
			
				|  |  |                      sensor.setId(IDHelper.id());
 | 
	
		
			
				|  |  |                      sensor.setState("unKnown");
 | 
	
		
			
				|  |  |                      sensor.setStateText("未知");
 | 
	
		
			
				|  |  | +                    sensor.setCreateTime(LocalDateTime.now());
 | 
	
		
			
				|  |  | +                    sensor.setDeleted(0);
 | 
	
		
			
				|  |  |                      list.add(sensor);
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |              }
 | 
	
	
		
			
				|  | @@ -629,39 +601,5 @@ public class IotAlarmSubSystemServiceImpl extends ServiceImpl<IotAlarmSubsystemM
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          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;
 | 
	
		
			
				|  |  | -    }
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 |