zxl
11 小时以前 3b0516a2959e25576e4f3fda697a3b025d06c8c9
ycl-server/src/main/java/com/ycl/utils/CheckPointUtil.java
@@ -49,11 +49,18 @@
     * @return
     */
    public TMonitorResult check(TMonitorResult monitor,Integer times) {
        //        TMonitorResult(deptId=202, ip=51.95.48.18, online=0,
//            onlineStr=null, pingOnline=true, pingOnlineStr=null,
//            checkCount=1, offLineCount=0, offLineTimeStr=null,
//            monitorType=3, name=DX_R三中大门前路段左侧人行道2_全景,
//            workOrder=null, pointId=null, createWorkOrder=null, dynamicColumnList=null),
        // 先检测能否访问该ip的网页
        ResponseEntity<String> res = null;
        String prefix = "http://";
        if ("127.0.0.1".equals(monitor.getIp())) {
            monitor.setPingOnline(Boolean.FALSE);
            log.error("ip有误"+monitor.getIp());
            return monitor;
        }
        try {
@@ -84,11 +91,7 @@
            map = new HashMap<>();
        }
        if (!monitor.getPingOnline()) {
            try {
                reachable = InetAddress.getByName(monitor.getIp()).isReachable(5000);
            } catch (IOException e) {
                e.printStackTrace();
            }
            reachable = checkPing(monitor, reachable);
            monitor.setPingOnline(reachable);
        }
        if (!monitor.getPingOnline()) {
@@ -98,19 +101,17 @@
            Date now = new Date();
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            offTimeList.add(dateFormat.format(now));
            monitor.setOffLineTimeStr(offTimeList);
            //到达产生工单的阈值次数
            if (continueOffTimes>=times) {
                //产生了工单才会存储离线时间,存储最近一次产生工单的这几个离线时间点
                monitor.setOffLineTimeStr(offTimeList);
                monitor.setCreateWorkOrder(Boolean.TRUE);
                //产生了一次工单则清除
                continueOffTimes = 0;
                offTimeList = new ArrayList<>();
            }
        }else {
            //如果在线了,清空连续离线次数,清空离线时间
            continueOffTimes = 0;
            offTimeList = new ArrayList<>();
        }
        map.put("checkTimes", checkTimes);
        map.put("offLineTimes", offLineTimes);
@@ -119,9 +120,26 @@
        redisTemplate.opsForHash().put(RedisConstant.ONLINE_KEY, monitor.getNo(), map);
        monitor.setCheckCount(checkTimes);
        monitor.setOffLineCount(offLineTimes);
        return monitor;
    }
    private boolean checkPing(TMonitorResult monitor, boolean reachable) {
        try {
            int[] sleepTimes = {5000, 15000, 30000};
            for (int sleepTime : sleepTimes) {
                reachable = InetAddress.getByName(monitor.getIp()).isReachable(5000);
                if (reachable) {
                    break;
                }
                Thread.sleep(sleepTime);
            }
        } catch (Exception e) {
            log.error("Ping异常",e);
        }
        return reachable;
    }
    /**
     * 监测点位在线