From 3b0516a2959e25576e4f3fda697a3b025d06c8c9 Mon Sep 17 00:00:00 2001 From: zxl <763096477@qq.com> Date: 星期二, 24 六月 2025 14:09:07 +0800 Subject: [PATCH] 每日录像可用指标添加日志,修改大屏为查看当前月平均 --- ycl-server/src/main/java/com/ycl/utils/CheckPointUtil.java | 87 ++++++++++++++++++++++++++++++++++--------- 1 files changed, 69 insertions(+), 18 deletions(-) diff --git a/ycl-server/src/main/java/com/ycl/utils/CheckPointUtil.java b/ycl-server/src/main/java/com/ycl/utils/CheckPointUtil.java index a3fbf48..cc25556 100644 --- a/ycl-server/src/main/java/com/ycl/utils/CheckPointUtil.java +++ b/ycl-server/src/main/java/com/ycl/utils/CheckPointUtil.java @@ -25,6 +25,7 @@ import java.io.IOException; import java.net.InetAddress; import java.net.UnknownHostException; +import java.text.SimpleDateFormat; import java.util.*; /** @@ -44,14 +45,22 @@ /** * 鐩戞祴鐐逛綅鍦ㄧ嚎宸ュ叿绫� + * * @return */ - public TMonitorResult check(TMonitorResult monitor) { + 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 { @@ -64,35 +73,77 @@ boolean reachable = false; Integer checkTimes = 1; Integer offLineTimes = 0; - Map<String, Object> map = (Map<String, Object>) redisTemplate.opsForHash().get(RedisConstant.ONLINE_KEY, monitor.getIp()); - if (!CollectionUtils.isEmpty(map)) { + Integer continueOffTimes = 0; + List<String> offTimeList = new ArrayList<>(); + // 浠嶳edis鑾峰彇鏁版嵁鏃惰繘琛岀被鍨嬪畨鍏ㄧ殑杞崲 + Map<String, Object> map = null; + Object mapObj = redisTemplate.opsForHash().get(RedisConstant.ONLINE_KEY, monitor.getNo()); + if (mapObj != null) { + map = (Map<String, Object>) mapObj; checkTimes = (Integer) map.get("checkTimes") + 1; offLineTimes = (Integer) map.get("offLineTimes"); + continueOffTimes = (Integer) map.get("continueOffTimes"); + Object offTimeListObj = map.get("offTimeList"); + if (offTimeListObj instanceof List) { + offTimeList = new ArrayList<>((List<String>) offTimeListObj); + } } else { 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()) { offLineTimes++; + continueOffTimes++; + //璁板綍绂荤嚎鏃堕棿 + 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.setCreateWorkOrder(Boolean.TRUE); + //浜х敓浜嗕竴娆″伐鍗曞垯娓呴櫎 + continueOffTimes = 0; + } + }else { + //濡傛灉鍦ㄧ嚎浜嗭紝娓呯┖杩炵画绂荤嚎娆℃暟锛屾竻绌虹绾挎椂闂� + continueOffTimes = 0; } map.put("checkTimes", checkTimes); map.put("offLineTimes", offLineTimes); - redisTemplate.opsForHash().put(RedisConstant.ONLINE_KEY, monitor.getIp(), map); + map.put("continueOffTimes", continueOffTimes); + map.put("offTimeList", offTimeList); + 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; } /** * 鐩戞祴鐐逛綅鍦ㄧ嚎 + * * @return */ public CheckResult webCheck(CheckUtil checkUtil) { @@ -117,7 +168,7 @@ ResponseEntity<String> res = selfHttpUtil.get(prefix + checkUtil.getIp(), null, null); webReachable = Objects.nonNull(res) && HttpStatus.OK == res.getStatusCode(); } catch (Exception e) { - log.info("妫�娴媤eb寮傚父"+e.getMessage()); + log.info("妫�娴媤eb寮傚父" + e.getMessage()); webReachable = Boolean.FALSE; } // ping @@ -131,7 +182,7 @@ e.printStackTrace(); } String imgUrl = ""; - if(pingReachable || webReachable) { + if (pingReachable || webReachable) { // 鏌ュ嚭鍥芥爣璁惧锛屽氨涓�鏉℃暟鎹� List<DeviceInfo> gbDevices = new LambdaQueryChainWrapper<>(deviceInfoMapper) .orderByDesc(DeviceInfo::getUpdateTime) @@ -147,21 +198,21 @@ } } String status = ""; - if (! webReachable) { + if (!webReachable) { status += "璁惧web璁块棶澶辫触锛�"; - }else if(webReachable){ + } else if (webReachable) { status += "璁惧web璁块棶姝e父锛�"; } - if (! pingReachable) { + if (!pingReachable) { status += "璁惧ip鏈猵ing閫氾紱"; - }else if(pingReachable){ + } else if (pingReachable) { status += "璁惧ipPing姝e父锛�"; } if (StringUtils.isEmpty(imgUrl)) { status += "鏈幏鍙栧埌鍥剧墖"; - }else { + } else { status += "鑾峰彇鍥剧墖姝e父"; } result.setStatus(status); @@ -193,9 +244,9 @@ e.printStackTrace(); } String status = ""; - if (! pingReachable) { + if (!pingReachable) { status += "ip鏈猵ing閫氾紱"; - }else { + } else { status += "鎴愬姛"; } result.setStatus(status); -- Gitblit v1.8.0