From 64efb660b2c119c00432434c0f651f8996483f18 Mon Sep 17 00:00:00 2001 From: fuliqi <fuliqi@qq.com> Date: 星期五, 21 二月 2025 15:51:13 +0800 Subject: [PATCH] OSD大华数据格式+数据中心重点标签统计数 --- ycl-server/src/main/java/com/ycl/task/PlatformTask.java | 50 +++++++++++++++++++++++++++----------------------- 1 files changed, 27 insertions(+), 23 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 e0ed630..f9ca8df 100644 --- a/ycl-server/src/main/java/com/ycl/task/PlatformTask.java +++ b/ycl-server/src/main/java/com/ycl/task/PlatformTask.java @@ -1,7 +1,9 @@ package com.ycl.task; import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; +import com.ycl.platform.domain.entity.Platform; import com.ycl.platform.domain.entity.PlatformOnline; +import com.ycl.platform.mapper.PlatformMapper; import com.ycl.platform.service.PlatformOnlineService; import com.ycl.system.entity.SysDictData; import com.ycl.system.service.impl.SysDictTypeServiceImpl; @@ -32,7 +34,7 @@ public class PlatformTask { private final RedisTemplate redisTemplate; - private final SysDictTypeServiceImpl dictTypeService; + private final PlatformMapper platformMapper; private final PlatformOnlineService platformOnlineService; /** @@ -42,11 +44,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() ); @@ -56,25 +58,27 @@ * @throws IOException */ public void ping() { - List<SysDictData> platformList = dictTypeService.selectDictDataByType(DICT_TYPE); - for (SysDictData platform : platformList) { + List<Platform> platformList = new LambdaQueryChainWrapper<>(platformMapper) + .isNotNull(Platform::getPlatformIP) + .list(); + for (Platform platform : platformList) { executorService.submit(() -> { try { Boolean reachable = Boolean.FALSE; for (int tryTimes = 1; tryTimes < 3; tryTimes++) { // 涓夌鏈猵ing閫氶噸璇曚竴娆★紝濡傛灉涓嶈鎵嶆墸鍒� - reachable = InetAddress.getByName(platform.getDictValue()).isReachable(3000); - if (! reachable && tryTimes == 0) { - continue; - } - if (! reachable) { - // 濡傛灉ping涓嶉�氾紝绂荤嚎鏃堕暱鍔�5绉� - redisTemplate.opsForValue().increment(REDIS_KEY_PREFIX + platform.getDictValue(), 5); - log.warn(platform.getDictLabel() + "骞冲彴鏈猵ing閫�"); + reachable = InetAddress.getByName(platform.getPlatformIP()).isReachable(3000); + if (reachable) { + break; } } + if (!reachable) { + // 濡傛灉ping涓嶉�氾紝绂荤嚎鏃堕暱鍔�5绉� + redisTemplate.opsForValue().increment(REDIS_KEY_PREFIX + platform.getPlatformIP(), 5); + log.warn(platform.getPlatformName() + "骞冲彴鏈猵ing閫�"); + } } catch (Exception e) { - log.error("妫�鏌ュ钩鍙拌繛閫氭�ф椂鍙戠敓閿欒", e); + log.error("妫�鏌ュ钩鍙拌繛閫氭�ф椂鍙戠敓d閿欒", e); } }); } @@ -85,28 +89,28 @@ * */ public void synToMySQL() { - List<SysDictData> platformList = dictTypeService.selectDictDataByType(DICT_TYPE); + List<Platform> platformList = new LambdaQueryChainWrapper<>(platformMapper) + .isNotNull(Platform::getPlatformIP) + .list(); // 灏唈ava.util.Date杞崲涓簀ava.sql.Date java.sql.Date sqlDate = new java.sql.Date(new Date().getTime()); - for (SysDictData platform : platformList) { - Object outLineTime = redisTemplate.opsForValue().get(REDIS_KEY_PREFIX + platform.getDictValue()); + for (Platform platform : platformList) { + Object outLineTime = redisTemplate.opsForValue().get(REDIS_KEY_PREFIX + platform.getPlatformIP()); Integer outlineTimeSed = Objects.isNull(outLineTime) ? 0 : (Integer) outLineTime; PlatformOnline one = new LambdaQueryChainWrapper<>(platformOnlineService.getBaseMapper()) - .eq(PlatformOnline::getPlatformIp, platform.getDictValue()) + .eq(PlatformOnline::getPlatformId, platform.getId()) .eq(PlatformOnline::getCreateDate, sqlDate) .one(); if (Objects.isNull(one)) { one = new PlatformOnline(); - one.setPlatformIp(platform.getDictValue()); - one.setPlatformName(platform.getDictLabel()); + one.setPlatformId(platform.getId()); one.setCreateDate(sqlDate); one.setTodayOutlineSed(outlineTimeSed); } else { one.setTodayOutlineSed(one.getTodayOutlineSed() + outlineTimeSed); } - one.setPlatformIp(platform.getDictValue()); - one.setPlatformName(platform.getDictLabel()); + one.setPlatformId(platform.getId()); one.setCreateDate(sqlDate); platformOnlineService.saveOrUpdate(one); -- Gitblit v1.8.0