From a4a904acc5f4de80d30eafe19dd97f3cc8f56a0b Mon Sep 17 00:00:00 2001
From: zxl <763096477@qq.com>
Date: 星期一, 29 九月 2025 17:17:34 +0800
Subject: [PATCH] 新问题 25-9-28
---
ycl-server/src/main/java/com/ycl/task/PlatformTask.java | 43 +++++++++++++++++++++++++------------------
1 files changed, 25 insertions(+), 18 deletions(-)
diff --git a/ycl-server/src/main/java/com/ycl/task/PlatformTask.java b/ycl-server/src/main/java/com/ycl/task/PlatformTask.java
index ab38afb..88a6f7c 100644
--- a/ycl-server/src/main/java/com/ycl/task/PlatformTask.java
+++ b/ycl-server/src/main/java/com/ycl/task/PlatformTask.java
@@ -12,8 +12,11 @@
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
+import javax.swing.text.DateFormatter;
import java.io.IOException;
import java.net.InetAddress;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.List;
import java.util.Objects;
@@ -44,11 +47,11 @@
private static final String DICT_TYPE = "platform_online";
- private static final ExecutorService executorService = new ThreadPoolExecutor(8,
- 24,
+ private static final ExecutorService executorService = new ThreadPoolExecutor(16,
+ 64,
5000,
TimeUnit.SECONDS,
- new ArrayBlockingQueue<>(10),
+ new ArrayBlockingQueue<>(1000),
new ThreadPoolExecutor.CallerRunsPolicy()
);
@@ -68,17 +71,21 @@
for (int tryTimes = 1; tryTimes < 3; tryTimes++) {
// 涓夌鏈猵ing閫氶噸璇曚竴娆★紝濡傛灉涓嶈鎵嶆墸鍒�
reachable = InetAddress.getByName(platform.getPlatformIP()).isReachable(3000);
- if (! reachable && tryTimes == 0) {
- continue;
- }
- if (! reachable) {
- // 濡傛灉ping涓嶉�氾紝绂荤嚎鏃堕暱鍔�5绉�
- redisTemplate.opsForValue().increment(REDIS_KEY_PREFIX + platform.getPlatformIP(), 5);
- log.warn(platform.getPlatformName() + "骞冲彴鏈猵ing閫�");
+ if (reachable) {
+ break;
}
}
+ if (!reachable) {
+ // 濡傛灉ping涓嶉�氾紝绂荤嚎鏃堕暱鍔�5绉�
+ LocalDateTime localDateTime = LocalDateTime.now();
+ DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+ String todayTime = localDateTime.format(dateTimeFormatter);
+ //姣忔redis绱5s
+ redisTemplate.opsForValue().increment(REDIS_KEY_PREFIX + todayTime + platform.getPlatformIP(), 5);
+ log.warn(platform.getPlatformName() + "骞冲彴鏈猵ing閫�");
+ }
} catch (Exception e) {
- log.error("妫�鏌ュ钩鍙拌繛閫氭�ф椂鍙戠敓閿欒", e);
+ log.error("妫�鏌ュ钩鍙拌繛閫氭�ф椂鍙戠敓d閿欒", e);
}
});
}
@@ -94,25 +101,25 @@
.list();
// 灏唈ava.util.Date杞崲涓簀ava.sql.Date
java.sql.Date sqlDate = new java.sql.Date(new Date().getTime());
-
+ LocalDateTime localDateTime = LocalDateTime.now();
+ DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+ String todayTime = localDateTime.format(dateTimeFormatter);
for (Platform platform : platformList) {
- Object outLineTime = redisTemplate.opsForValue().get(REDIS_KEY_PREFIX + platform.getPlatformIP());
+ Object outLineTime = redisTemplate.opsForValue().get(REDIS_KEY_PREFIX + todayTime + platform.getPlatformIP());
Integer outlineTimeSed = Objects.isNull(outLineTime) ? 0 : (Integer) outLineTime;
PlatformOnline one = new LambdaQueryChainWrapper<>(platformOnlineService.getBaseMapper())
- .eq(PlatformOnline::getPlatformIp, platform.getPlatformIP())
+ .eq(PlatformOnline::getPlatformId, platform.getId())
.eq(PlatformOnline::getCreateDate, sqlDate)
.one();
if (Objects.isNull(one)) {
one = new PlatformOnline();
- one.setPlatformIp(platform.getPlatformIP());
- one.setPlatformName(platform.getPlatformName());
+ one.setPlatformId(platform.getId());
one.setCreateDate(sqlDate);
one.setTodayOutlineSed(outlineTimeSed);
} else {
one.setTodayOutlineSed(one.getTodayOutlineSed() + outlineTimeSed);
}
- one.setPlatformIp(platform.getPlatformIP());
- one.setPlatformName(platform.getPlatformName());
+ one.setPlatformId(platform.getId());
one.setCreateDate(sqlDate);
platformOnlineService.saveOrUpdate(one);
--
Gitblit v1.8.0