| | |
| | | import com.ycl.utils.CheckPointUtil; |
| | | import com.ycl.utils.DateUtils; |
| | | import constant.ApiConstants; |
| | | import constant.CheckConstants; |
| | | import constant.RedisConstant; |
| | | import enumeration.ErrorType; |
| | | import enumeration.general.WorkOrderStatusEnum; |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.data.mongodb.core.MongoTemplate; |
| | | import org.springframework.data.mongodb.core.query.Criteria; |
| | |
| | | item.setNo(item.getDeviceId()); |
| | | } |
| | | }); |
| | | pointService.setDeviceTagByGB(records); |
| | | pointService.setDeviceTagByGB(records, CheckConstants.Rule_Category_Video); |
| | | //存放在mongo中 |
| | | mongoTemplate.insertAll(records); |
| | | // 工单生成 |
| | |
| | | item.setNo(item.getSerialNumber().getShowValue()); |
| | | } |
| | | }); |
| | | pointService.setDeviceTagByGB(records); |
| | | pointService.setDeviceTagByGB(records,CheckConstants.Rule_Category_Or); |
| | | pointService.setNew(records); |
| | | //存放在mongo中 |
| | | mongoTemplate.insertAll(records); |
| | |
| | | |
| | | /** |
| | | * 点位在线PING检测 |
| | | * 任务会先执行一次优云同步,然后执行ping检测 |
| | | * online字段来自于优云,pingOnline为主动ping检测的。存入mongo给数据中心查阅 |
| | | */ |
| | | public void pointOnline() throws ExecutionException, InterruptedException { |
| | | log.info("开始检测点位在线"); |
| | |
| | | log.error("请配置离线次数,此次设置为默认值2"); |
| | | } |
| | | // 先查出设备IP集合,剔除掉在线情况是未知的,并且只检测正在考核的设备避免多余工单 |
| | | //TODO:需要把海康和优云的任务的时间调到ping之前 |
| | | List<TMonitorResult> monitorList = monitorMapper.getDistinctIP(); |
| | | //补充错误时间点 |
| | | Query onlineQuery = new Query(Criteria.where("mongoCreateTime").gte(DateUtils.getDayStart(new Date())).lt(DateUtils.getDayEnd(new Date()))); |
| | | Map<String, TMonitorResult> mongoMap = mongoTemplate.find(onlineQuery, TMonitorResult.class).stream().collect(Collectors.toMap(TMonitorResult::getNo, Function.identity())); |
| | | Map<String, TMonitorResult> mongoMap = mongoTemplate.find(onlineQuery, TMonitorResult.class) |
| | | .stream() |
| | | .collect(Collectors.toMap(TMonitorResult::getNo, Function.identity(), (existing, replacement) -> replacement)); |
| | | for (TMonitorResult result : monitorList) { |
| | | TMonitorResult mongoData = mongoMap.get(result.getNo()); |
| | | if(mongoData!=null){ |
| | |
| | | ex.printStackTrace(); |
| | | } |
| | | return null; |
| | | // int checkTimes = 1; |
| | | // int offLineTimes = 1; |
| | | // Map<String, Object> map = (Map<String, Object>) redisTemplate.opsForHash().get(RedisConstant.ONLINE_KEY, monitor.getNo()); |
| | | // if (!CollectionUtils.isEmpty(map)) { |
| | | // checkTimes = (Integer) map.get("checkTimes") + 1; |
| | | // offLineTimes = (Integer) map.get("offLineTimes"); |
| | | // }else { |
| | | // map = new HashMap<>(); |
| | | // } |
| | | // monitor.setPingOnline(Boolean.FALSE); |
| | | // monitor.setCheckCount(checkTimes); |
| | | // monitor.setOffLineCount(offLineTimes); |
| | | // List<Date> offLineTime = monitor.getOffLineTime(); |
| | | // if(CollectionUtils.isEmpty(offLineTime)) offLineTime = new ArrayList<>(); |
| | | // offLineTime.add(new Date()); |
| | | // monitor.setOffLineTime(offLineTime); |
| | | // if (monitor.getOffLineCount() >= time) { |
| | | // WorkOrder workOrder = new WorkOrder(); |
| | | // workOrder.setSerialNumber(monitor.getNo()); |
| | | // List<String> errList = new ArrayList<>(); |
| | | // errList.add(ErrorType.DEVICE_OFFLINE.getValue()); |
| | | // workOrder.setErrorTypeList(errList); |
| | | // workOrder.setStatus(WorkOrderStatusEnum.DISTRIBUTED); |
| | | // monitor.setWorkOrder(workOrder); |
| | | // } |
| | | // map.put("checkTimes", checkTimes); |
| | | // map.put("offLineTimes", offLineTimes); |
| | | // redisTemplate.opsForHash().put(RedisConstant.ONLINE_KEY, monitor.getNo(), map); |
| | | // return monitor; // 返回失败的结果 |
| | | |
| | | })) |
| | | .collect(Collectors.toList()); |
| | | |
| | |
| | | } |
| | | //存放到mongo |
| | | if (!CollectionUtils.isEmpty(dataList)) { |
| | | List<TMonitorResult> mongoList = new ArrayList<>(); |
| | | dataList.forEach(item->{ |
| | | String monitorType = item.getMonitorType(); |
| | | //同一个设备多个类型每个类型存一条数据,以此在保留数据的情况下区分省厅标签 |
| | | if(StringUtils.isNotEmpty(monitorType)){ |
| | | String[] monitors = monitorType.split("/"); |
| | | for (String type : monitors) { |
| | | TMonitorResult mongoData = new TMonitorResult(); |
| | | BeanUtils.copyProperties(item,mongoData); |
| | | mongoData.setMonitorType(type); |
| | | if("1".equals(type)){ |
| | | mongoData.setProvinceTag(mongoData.getProvinceTagVideo()); |
| | | }else if("2".equals(type)){ |
| | | mongoData.setProvinceTag(mongoData.getProvinceTagCar()); |
| | | }else if("3".equals(type)){ |
| | | mongoData.setProvinceTag(mongoData.getProvinceTagFace()); |
| | | } |
| | | mongoList.add(mongoData); |
| | | } |
| | | } |
| | | }); |
| | | //如果存在之前的数据先删除 |
| | | Query query = new Query(Criteria.where("mongoCreateTime").gte(DateUtils.getDayStart(new Date())).lt(DateUtils.getDayEnd(new Date()))); |
| | | DeleteResult result = mongoTemplate.remove(query, TMonitorResult.class); |
| | | //存放在mongo中 |
| | | mongoTemplate.insertAll(dataList); |
| | | mongoTemplate.insertAll(mongoList); |
| | | } |
| | | //工单(同一IP只生成一个工单) |
| | | List<WorkOrder> workOrderList = dataList.stream() |
| | |
| | | item.setNo(item.getDeviceId()); |
| | | } |
| | | }); |
| | | pointService.setDeviceTagByGB(records); |
| | | //貌似这里可以忽略省厅标签因为项目展示的后面ping的时候存的数据 |
| | | pointService.setDeviceTagByGB(records,CheckConstants.Rule_Category_Video); |
| | | //存放在mongo中 |
| | | mongoTemplate.insertAll(records); |
| | | //更新point表在线状态 |
| | |
| | | } |
| | | }); |
| | | //打标签 |
| | | pointService.setDeviceTagByGB(records); |
| | | pointService.setDeviceTagByGB(records,CheckConstants.Rule_Category_Video); |
| | | //存放在mongo中 |
| | | mongoTemplate.insertAll(records); |
| | | // // 工单生成 |