| | |
| | | import com.ycl.system.service.ISysDictDataService; |
| | | import com.ycl.utils.DateUtils; |
| | | import constant.RedisConstant; |
| | | import enumeration.general.AreaDeptEnum; |
| | | import enumeration.general.ImportantTagEnum; |
| | | import enumeration.general.PointStatus; |
| | | import enumeration.general.ProvinceTagEnum; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.mongodb.core.MongoTemplate; |
| | |
| | | private YwPointService ywPointService; |
| | | @Autowired |
| | | private RedisTemplate redisTemplate; |
| | | |
| | | //同步mongodb一机一档到数据库 |
| | | public void synchronize() { |
| | | Query query = new Query(Criteria.where("mongoCreateTime").gte(DateUtils.getDayStart(new Date())).lt(DateUtils.getDayEnd(new Date()))); |
| | | List<OneMachineFileResult> oneMachineFileResults = mongoTemplate.find(query, OneMachineFileResult.class); |
| | | //数据库monitor表数据 |
| | | List<String> serialNumberInBase = monitorService.selectTMonitorList(null).stream().map(TMonitorVO::getSerialNumber).collect(Collectors.toList()); |
| | | //准备插入数据库的数据 |
| | | //准备插入设备表的数据 |
| | | List<TMonitor> monitorList = new ArrayList<>(); |
| | | //准备插入点位表的数据 |
| | | List<YwPoint> ywPointList = new ArrayList<>(); |
| | | //新的数据,原数据库中不存在的数据 |
| | | Set<TMonitor> newMonitorList = new HashSet<>(); |
| | | //点位数据 |
| | | Map<String, YwPoint> pointMap = ywPointService.list(new QueryWrapper<YwPoint>()).stream().collect(Collectors.toMap(YwPoint::getSerialNumber, Function.identity())); |
| | | //TODO:插入点位表 |
| | | //TODO:解析区域、补充deptId |
| | | //TODO:解析重点点位 |
| | | //重点点位集合字典(解析SXJCJQY字段) |
| | | SysDictData sysDictData = new SysDictData(); |
| | | sysDictData.setDictType("platform_important_site"); |
| | |
| | | List<String> importantSite = DictDataList.stream().map(SysDictData::getDictValue).collect(Collectors.toList()); |
| | | for (OneMachineFileResult result : oneMachineFileResults) { |
| | | TMonitor monitor = getMonitor(result); |
| | | YwPoint point = getPoint(result,pointMap,importantSite); |
| | | YwPoint point = getPoint(result, pointMap, importantSite); |
| | | monitorList.add(monitor); |
| | | //比对筛选出新的数据 |
| | | if(!CollectionUtils.isEmpty(serialNumberInBase) && !serialNumberInBase.contains(result.getSBBM())){ |
| | | if (!CollectionUtils.isEmpty(serialNumberInBase) && !serialNumberInBase.contains(result.getSBBM())) { |
| | | newMonitorList.add(monitor); |
| | | } |
| | | } |
| | | //插入数据库 |
| | | if(!CollectionUtils.isEmpty(monitorList)){ |
| | | if (!CollectionUtils.isEmpty(monitorList)) { |
| | | monitorService.deleteTMonitorById(null); |
| | | monitorService.saveBatch(monitorList); |
| | | } |
| | |
| | | |
| | | } |
| | | |
| | | private YwPoint getPoint(OneMachineFileResult result, Map<String, YwPoint> pointMap,List<String> importantSite) { |
| | | private YwPoint getPoint(OneMachineFileResult result, Map<String, YwPoint> pointMap, List<String> importantSite) { |
| | | YwPoint ywPoint = new YwPoint(); |
| | | if(pointMap.containsKey(result.getSBBM())){ |
| | | if (pointMap.containsKey(result.getSBBM())) { |
| | | ywPoint = pointMap.get(result.getSBBM()); |
| | | }else { |
| | | ywPoint.setPointName(result.getSBMC()); |
| | | ywPoint.setStatus(PointStatus.WAIT.getDesc()); |
| | | ywPoint.setSerialNumber(result.getSBBM()); |
| | | ywPoint.setImportantTag(ImportantTagEnum.Normal); |
| | | ywPoint.setProvinceTag(ProvinceTagEnum.Normal); |
| | | ywPoint.setCreateTime(new Date()); |
| | | ywPoint.setUpdateTime(new Date()); |
| | | } |
| | | //比对是否是重点点位 |
| | | if(importantSite.contains(result.getSBBM())){ |
| | | |
| | | if (importantSite.contains(result.getSBBM())) { |
| | | ywPoint.setImportantTag(ImportantTagEnum.Important); |
| | | } |
| | | |
| | | //解析deptId |
| | | //区域行政编码 |
| | | String areaCode = result.getSBBM().substring(0, 6); |
| | | Integer deptId = AreaDeptEnum.fromCode(areaCode).getDeptId(); |
| | | if (deptId != null) { |
| | | ywPoint.setDeptId(Long.valueOf(deptId + "")); |
| | | } |
| | | return ywPoint; |
| | | } |
| | | |