From d22bbb827940050d4df2bf3fb16dae79eba91d4e Mon Sep 17 00:00:00 2001
From: fuliqi <fuliqi@qq.com>
Date: 星期二, 12 十一月 2024 18:45:15 +0800
Subject: [PATCH] 批量审核bug,离线时间点回显
---
ycl-server/src/main/java/com/ycl/utils/CheckPointUtil.java | 153 ++++++++++++++++++++++++++++++++++++++++++++++----
1 files changed, 139 insertions(+), 14 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 e74f2c9..cc5fa17 100644
--- a/ycl-server/src/main/java/com/ycl/utils/CheckPointUtil.java
+++ b/ycl-server/src/main/java/com/ycl/utils/CheckPointUtil.java
@@ -1,7 +1,16 @@
package com.ycl.utils;
+import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
+import com.ycl.platform.domain.entity.DeviceInfo;
+import com.ycl.platform.domain.entity.TMonitor;
import com.ycl.platform.domain.result.SYS.TMonitorResult;
+import com.ycl.platform.domain.vo.CheckResult;
+import com.ycl.platform.domain.vo.CheckUtil;
+import com.ycl.platform.mapper.DeviceInfoMapper;
+import com.ycl.platform.mapper.TMonitorMapper;
+import com.ycl.platform.service.WorkOrderService;
import com.ycl.utils.http.SelfHttpUtil;
+import com.ycl.utils.uuid.IdUtils;
import constant.RedisConstant;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@@ -15,9 +24,8 @@
import java.io.IOException;
import java.net.InetAddress;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Objects;
+import java.net.UnknownHostException;
+import java.util.*;
/**
* @author xp
@@ -29,8 +37,10 @@
public class CheckPointUtil {
private final RedisTemplate redisTemplate;
-
private final SelfHttpUtil selfHttpUtil;
+ private final DeviceInfoMapper deviceInfoMapper;
+ private final WorkOrderService workOrderService;
+ private final TMonitorMapper monitorMapper;
/**
* 鐩戞祴鐐逛綅鍦ㄧ嚎宸ュ叿绫�
@@ -38,20 +48,18 @@
*/
public TMonitorResult check(TMonitorResult monitor) {
// 鍏堟娴嬭兘鍚﹁闂ip鐨勭綉椤�
- ResponseEntity<Object> res = null;
- log.info("鐩戞祴IP锛�" + monitor.getIp());
+ ResponseEntity<String> res = null;
String prefix = "http://";
if ("127.0.0.1".equals(monitor.getIp())) {
- monitor.setOnline(Boolean.FALSE);
+ monitor.setPingOnline(Boolean.FALSE);
return monitor;
}
try {
res = selfHttpUtil.get(prefix + monitor.getIp(), null, null);
- monitor.setOnline(Objects.nonNull(res) && HttpStatus.OK == res.getStatusCode());
+ monitor.setPingOnline(Objects.nonNull(res) && HttpStatus.OK == res.getStatusCode());
} catch (Exception e) {
- monitor.setOnline(Boolean.FALSE);
+ monitor.setPingOnline(Boolean.FALSE);
}
-
// 濡傛灉http寰楀埌鐨勪笉鍦ㄧ嚎锛岄偅涔堝啀ping涓�涓�
boolean reachable = false;
Integer checkTimes = 1;
@@ -63,16 +71,21 @@
} else {
map = new HashMap<>();
}
- if (!monitor.getOnline()) {
+
+ if (!monitor.getPingOnline()) {
try {
- reachable = InetAddress.getByName(monitor.getIp()).isReachable(3000);
+ reachable = InetAddress.getByName(monitor.getIp()).isReachable(5000);
} catch (IOException e) {
e.printStackTrace();
}
- monitor.setOnline(reachable);
+ monitor.setPingOnline(reachable);
}
- if (!monitor.getOnline()) {
+ if (!monitor.getPingOnline()) {
offLineTimes++;
+ List<Date> offLineTime = monitor.getOffLineTime();
+ if(CollectionUtils.isEmpty(offLineTime)) offLineTime = new ArrayList<>();
+ offLineTime.add(new Date());
+ monitor.setOffLineTime(offLineTime);
}
map.put("checkTimes", checkTimes);
map.put("offLineTimes", offLineTimes);
@@ -81,4 +94,116 @@
monitor.setOffLineCount(offLineTimes);
return monitor;
}
+
+
+ /**
+ * 鐩戞祴鐐逛綅鍦ㄧ嚎
+ * @return
+ */
+ public CheckResult webCheck(CheckUtil checkUtil) {
+ CheckResult result = new CheckResult();
+ List<TMonitor> ips = new LambdaQueryChainWrapper<>(monitorMapper)
+ .eq(TMonitor::getSerialNumber, checkUtil.getSerialNumber())
+ .list();
+ if (ips.size() < 1) {
+ result.setStatus("鍥芥爣鐮佹湭鏌ユ壘鍒癐P");
+ return result;
+ }
+ checkUtil.setIp(ips.get(0).getIp());
+
+ log.info("鐩戞祴IP锛�" + checkUtil.getIp());
+ String prefix = "http://";
+ if ("127.0.0.1".equals(checkUtil.getIp())) {
+ result.setStatus("ip寮傚父");
+ return result;
+ }
+ boolean webReachable = false;
+ try {
+ 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());
+ webReachable = Boolean.FALSE;
+ }
+ // ping
+ boolean pingReachable = false;
+ try {
+ InetAddress inet = InetAddress.getByName(checkUtil.getIp());
+ pingReachable = inet.isReachable(5000); // 5000姣瓒呮椂鏃堕棿
+ } catch (UnknownHostException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ String imgUrl = "";
+ if(pingReachable || webReachable) {
+ // 鏌ュ嚭鍥芥爣璁惧锛屽氨涓�鏉℃暟鎹�
+ List<DeviceInfo> gbDevices = new LambdaQueryChainWrapper<>(deviceInfoMapper)
+ .orderByDesc(DeviceInfo::getUpdateTime)
+ .last("limit 1")
+ .list();
+ if (!CollectionUtils.isEmpty(gbDevices)) {
+ try {
+ imgUrl = workOrderService.getFrameImgByDevice(gbDevices.get(0).getDeviceId(), checkUtil.getSerialNumber(), IdUtils.workOrderNO(new Date(), "99999"));
+ result.setImg(imgUrl);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ String status = "";
+ if (! webReachable) {
+ status += "璁惧web璁块棶澶辫触锛�";
+ }else if(webReachable){
+ status += "璁惧web璁块棶姝e父锛�";
+ }
+
+ if (! pingReachable) {
+ status += "璁惧ip鏈猵ing閫氾紱";
+ }else if(pingReachable){
+ status += "璁惧ipPing姝e父锛�";
+ }
+
+ if (StringUtils.isEmpty(imgUrl)) {
+ status += "鏈幏鍙栧埌鍥剧墖";
+ }else {
+ status += "鑾峰彇鍥剧墖姝e父";
+ }
+ result.setStatus(status);
+ return result;
+ }
+
+ /**
+ * ping
+ *
+ * @return
+ */
+ public CheckResult ping(CheckUtil checkUtil) {
+ CheckResult result = new CheckResult();
+
+ log.info("鐩戞祴IP锛�" + checkUtil.getIp());
+ String prefix = "http://";
+ if ("127.0.0.1".equals(checkUtil.getIp())) {
+ result.setStatus("ip寮傚父");
+ return result;
+ }
+ // ping
+ boolean pingReachable = false;
+ try {
+ InetAddress inet = InetAddress.getByName(checkUtil.getIp());
+ pingReachable = inet.isReachable(5000); // 5000姣瓒呮椂鏃堕棿
+ } catch (UnknownHostException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ String status = "";
+ if (! pingReachable) {
+ status += "ip鏈猵ing閫氾紱";
+ }else {
+ status += "鎴愬姛";
+ }
+ result.setStatus(status);
+ return result;
+ }
}
--
Gitblit v1.8.0