| | |
| | | /** |
| | | * 点位在线PING检测 |
| | | */ |
| | | //TODO:点位在线(修改逻辑只针对工单) |
| | | public void pointOnline() throws ExecutionException, InterruptedException { |
| | | log.info("开始检测点位在线"); |
| | | Integer times = 2; |
| | |
| | | for (TMonitorResult result : monitorList) { |
| | | TMonitorResult mongoData = mongoMap.get(result.getNo()); |
| | | if(mongoData!=null){ |
| | | result.setOffLineTime(mongoData.getOffLineTime()); |
| | | result.setOffLineTimeStr(mongoData.getOffLineTimeStr()); |
| | | } |
| | | } |
| | | List<TMonitorResult> dataList = new ArrayList<>(48); |
| | |
| | | return thread.call(); // 假设 OnlineCheckThread 实现了 Callable 接口 |
| | | }, executorService) |
| | | .orTimeout(60, TimeUnit.SECONDS) |
| | | //出现异常 |
| | | .exceptionally(ex -> { |
| | | if (ex instanceof TimeoutException) { |
| | | log.error("任务执行超时:"+monitor.getIp()); |
| | | } else { |
| | | log.error("任务执行异常:"+monitor.getIp() + ex); |
| | | log.error("任务执行异常:"+monitor.getIp() +ex); |
| | | ex.printStackTrace(); |
| | | } |
| | | int checkTimes = 1; |
| | | int offLineTimes = 1; |
| | | Map<String, Object> map = (Map<String, Object>) redisTemplate.opsForHash().get(RedisConstant.ONLINE_KEY, monitor.getIp()); |
| | | if (!CollectionUtils.isEmpty(map)) { |
| | | checkTimes = (Integer) map.get("checkTimes") + 1; |
| | | offLineTimes = (Integer) map.get("offLineTimes"); |
| | | } |
| | | 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); |
| | | } |
| | | return monitor; // 返回失败的结果 |
| | | 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()); |
| | | |
| | |
| | | try { |
| | | allOf.get(60, TimeUnit.SECONDS); // 给予额外的5秒来收集结果 |
| | | } catch (TimeoutException e) { |
| | | log.warn("部分任务未在指定时间内完成"); |
| | | log.error("部分任务未在指定时间内完成"); |
| | | } catch (Exception e2){ |
| | | log.error("数据收集异常"+e2); |
| | | } |
| | |
| | | .map(CompletableFuture::join) |
| | | .filter(Objects::nonNull) |
| | | .collect(Collectors.toList()); |
| | | //筛选出ping离线的设备,更改数据库为离线 |
| | | //筛选出ping离线的设备,更改数据库为离线,并且更新纯车辆或纯人脸的设备的在线状态(这部分设备不会拉流检测) |
| | | Date now = new Date(); |
| | | List<UpdateOnlineVO> willUpdateList = dataList.stream().filter(result->!result.getPingOnline()).map(item -> { |
| | | List<UpdateOnlineVO> onlineUpdateList = dataList.stream().map(item -> { |
| | | UpdateOnlineVO vo = new UpdateOnlineVO(); |
| | | vo.setOnline(ApiConstants.UY_OnlineSite_Offline); |
| | | if(item.getPingOnline()) { |
| | | vo.setOnline(ApiConstants.UY_OnlineSite_Online); |
| | | }else if(!item.getPingOnline()){ |
| | | vo.setOnline(ApiConstants.UY_OnlineSite_Offline); |
| | | } |
| | | vo.setIp(item.getIp()); |
| | | vo.setUpdateTime(now); |
| | | return vo; |
| | | }).collect(Collectors.toList()); |
| | | monitorMapper.updateOnline(willUpdateList); |
| | | monitorMapper.updateOnline(onlineUpdateList); |
| | | //存放到mongo |
| | | if (!CollectionUtils.isEmpty(dataList)) { |
| | | //如果存在之前的数据先删除 |