From 2a2885f45160b4048a27e75d5be03ba9232c7363 Mon Sep 17 00:00:00 2001
From: fuliqi <fuliqi@qq.com>
Date: 星期二, 10 九月 2024 17:34:42 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'
---
ycl-server/src/main/java/com/ycl/thread/OnlineCheckThread.java | 129 +++++++++++++++++++++++++++++++++++++++++++
1 files changed, 129 insertions(+), 0 deletions(-)
diff --git a/ycl-server/src/main/java/com/ycl/thread/OnlineCheckThread.java b/ycl-server/src/main/java/com/ycl/thread/OnlineCheckThread.java
new file mode 100644
index 0000000..a3c762d
--- /dev/null
+++ b/ycl-server/src/main/java/com/ycl/thread/OnlineCheckThread.java
@@ -0,0 +1,129 @@
+package com.ycl.thread;
+
+import com.ycl.platform.domain.entity.TMonitor;
+import com.ycl.platform.domain.entity.WorkOrder;
+import com.ycl.platform.domain.vo.OnlineThreadVO;
+import com.ycl.platform.domain.vo.UpdateOnlineVO;
+import com.ycl.utils.http.SelfHttpUtil;
+import constant.RedisConstant;
+import enumeration.ErrorType;
+import enumeration.general.WorkOrderStatusEnum;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Objects;
+import java.util.concurrent.Callable;
+
+/**
+ * @author锛歺p
+ * @date锛�2024/9/10 11:43
+ */
+@Slf4j
+public class OnlineCheckThread implements Callable<OnlineThreadVO> {
+
+ private TMonitor monitor;
+
+ private RedisTemplate redisTemplate;
+
+ private SelfHttpUtil selfHttpUtil;
+
+ private Integer times;
+
+ public OnlineCheckThread(TMonitor monitor, RedisTemplate redisTemplate, SelfHttpUtil selfHttpUtil, Integer times) {
+ this.monitor = monitor;
+ this.redisTemplate = redisTemplate;
+ this.selfHttpUtil = selfHttpUtil;
+ this.times = times;
+ }
+
+ public Integer getTimes() {
+ return times;
+ }
+
+ public void setTimes(Integer times) {
+ this.times = times;
+ }
+
+ public SelfHttpUtil getSelfHttpUtil() {
+ return selfHttpUtil;
+ }
+
+ public void setSelfHttpUtil(SelfHttpUtil selfHttpUtil) {
+ this.selfHttpUtil = selfHttpUtil;
+ }
+
+ public TMonitor getMonitor() {
+ return monitor;
+ }
+
+ public void setMonitor(TMonitor monitor) {
+ this.monitor = monitor;
+ }
+
+ public RedisTemplate getRedisTemplate() {
+ return redisTemplate;
+ }
+
+ public void setRedisTemplate(RedisTemplate redisTemplate) {
+ this.redisTemplate = redisTemplate;
+ }
+
+ @Override
+ public OnlineThreadVO call() throws Exception {
+ // 鍏堟娴嬭兘鍚﹁闂ip鐨勭綉椤�
+ ResponseEntity<Object> res = null;
+ OnlineThreadVO vo = new OnlineThreadVO();
+ vo.setIp(monitor.getIp());
+ log.info("鐩戞祴IP锛�" + monitor.getIp());
+ String prefix = "http://";
+ if ("127.0.0.1".equals(monitor.getIp())) {
+ vo.setOnline(Boolean.FALSE);
+ return vo;
+ }
+ try {
+ res = selfHttpUtil.get(prefix + monitor.getIp(), null, null);
+ vo.setOnline(Objects.nonNull(res) && HttpStatus.OK == res.getStatusCode());
+ } catch (Exception e) {
+ vo.setOnline(Boolean.FALSE);
+ }
+
+ // 濡傛灉http寰楀埌鐨勪笉鍦ㄧ嚎锛岄偅涔堝啀ping涓�涓�
+ boolean reachable = false;
+ if (!vo.getOnline()) {
+ try {
+ reachable = InetAddress.getByName(monitor.getIp()).isReachable(3000);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ vo.setOnline(reachable);
+ }
+ if (!vo.getOnline()) {
+ Integer outLineTimes = (Integer) redisTemplate.opsForHash().get(RedisConstant.ONLINE_KEY, monitor.getIp());
+ if (Objects.isNull(outLineTimes)) {
+ outLineTimes = 1;
+ } else {
+ outLineTimes += 1;
+ }
+ redisTemplate.opsForHash().put(RedisConstant.ONLINE_KEY, monitor.getIp(), outLineTimes);
+ // 涓�澶╁唴鐩戞祴鍒扮绾�1娆′互涓婏紝鐢熸垚宸ュ崟
+ if (outLineTimes >= times) {
+ WorkOrder workOrder = new WorkOrder();
+ workOrder.setSerialNumber(monitor.getSerialNumber());
+ List<String> errList = new ArrayList<>();
+ errList.add(ErrorType.DEVICE_OFFLINE.getValue());
+ workOrder.setErrorTypeList(errList);
+ workOrder.setStatus(WorkOrderStatusEnum.DISTRIBUTED);
+ vo.setWorkOrder(workOrder);
+ }
+ }
+ return vo;
+ }
+
+}
--
Gitblit v1.8.0