From 8adcac210151d894722f9c311e91f94ab76a9b1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A5=88=E7=A7=91=E6=96=AF=EF=BC=88NexIoT=EF=BC=89?= <16120872+nexiot@user.noreply.gitee.com> Date: Fri, 26 Sep 2025 20:47:18 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E9=BB=98=E8=AE=A4=E4=B8=8D?= =?UTF-8?q?=E5=90=8C=E6=AD=A5rulego=EF=BC=9B=E9=83=A8=E5=88=86=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E7=BA=A7=E5=88=AB=E8=B0=83=E6=95=B4=E4=B8=BAdebug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/DashboardStatisticsTask.java | 24 ++++---- .../service/impl/IoTDeviceShadowService.java | 34 +++++------ .../service/task/ShadowFlushScheduler.java | 8 +-- .../protocol/third/MQTTStatisticsLogger.java | 10 ++-- .../cn/universal/monitor/ThreadMonitor.java | 2 +- .../web/context/IotServiceImplFactory.java | 59 ------------------- .../src/main/resources/application.properties | 2 +- 7 files changed, 40 insertions(+), 99 deletions(-) delete mode 100644 cn-universal-web/src/main/java/cn/universal/web/context/IotServiceImplFactory.java diff --git a/cn-universal-framework/cn-universal-dm/src/main/java/cn/universal/dm/device/service/DashboardStatisticsTask.java b/cn-universal-framework/cn-universal-dm/src/main/java/cn/universal/dm/device/service/DashboardStatisticsTask.java index 25086b0..ad651b0 100644 --- a/cn-universal-framework/cn-universal-dm/src/main/java/cn/universal/dm/device/service/DashboardStatisticsTask.java +++ b/cn-universal-framework/cn-universal-dm/src/main/java/cn/universal/dm/device/service/DashboardStatisticsTask.java @@ -65,7 +65,7 @@ public class DashboardStatisticsTask implements ApplicationRunner { log.warn("[仪表盘统计] 本地缓存中无活跃平台,使用默认平台列表"); } - log.info("[仪表盘统计] 获取到 {} 个活跃平台: {}", platforms.size(), platforms); + log.debug("[仪表盘统计] 获取到 {} 个活跃平台: {}", platforms.size(), platforms); return platforms; } catch (Exception e) { @@ -78,7 +78,7 @@ public class DashboardStatisticsTask implements ApplicationRunner { /** 应用启动时初始化统计数据 */ @Override public void run(ApplicationArguments args) throws Exception { - log.info("[仪表盘统计] 应用启动,开始初始化统计数据"); + log.debug("[仪表盘统计] 应用启动,开始初始化统计数据"); try { // 延迟5秒执行,确保所有组件都已初始化 @@ -87,7 +87,7 @@ public class DashboardStatisticsTask implements ApplicationRunner { // 执行一次初始刷新 refreshDatabaseStatisticsWithLock(); - log.info("[仪表盘统计] 统计数据初始化完成"); + log.debug("[仪表盘统计] 统计数据初始化完成"); } catch (Exception e) { log.error("[仪表盘统计] 统计数据初始化失败", e); } @@ -112,7 +112,7 @@ public class DashboardStatisticsTask implements ApplicationRunner { long lastTime = Long.parseLong(lastExecutionTime); long currentTime = System.currentTimeMillis(); if (currentTime - lastTime < MIN_EXECUTION_INTERVAL * 1000) { - log.info("[仪表盘统计] 距离上次执行时间不足{}秒,跳过本次执行", MIN_EXECUTION_INTERVAL); + log.debug("[仪表盘统计] 距离上次执行时间不足{}秒,跳过本次执行", MIN_EXECUTION_INTERVAL); return; } } catch (NumberFormatException e) { @@ -132,7 +132,7 @@ public class DashboardStatisticsTask implements ApplicationRunner { if (Boolean.TRUE.equals(lockAcquired)) { try { - log.info("[仪表盘统计] 获取到分布式锁,开始执行10分钟数据库刷新"); + log.debug("[仪表盘统计] 获取到分布式锁,开始执行10分钟数据库刷新"); LocalDate todayDate = LocalDate.now(); @@ -151,7 +151,7 @@ public class DashboardStatisticsTask implements ApplicationRunner { LOCK_TIMEOUT, TimeUnit.SECONDS); - log.info("[仪表盘统计] 10分钟数据库刷新完成"); + log.debug("[仪表盘统计] 10分钟数据库刷新完成"); } catch (Exception e) { log.error("[仪表盘统计] 10分钟数据库刷新失败", e); } finally { @@ -160,7 +160,7 @@ public class DashboardStatisticsTask implements ApplicationRunner { log.debug("[仪表盘统计] 释放分布式锁"); } } else { - log.info("[仪表盘统计] 未获取到分布式锁,跳过本次执行"); + log.debug("[仪表盘统计] 未获取到分布式锁,跳过本次执行"); } } @@ -208,9 +208,9 @@ public class DashboardStatisticsTask implements ApplicationRunner { platformTotal.getMetricValue()); // 执行前记录 - log.info("[仪表盘统计] 准备执行recordStatistics,平台: {}", platform); + log.debug("[仪表盘统计] 准备执行recordStatistics,平台: {}", platform); dashboardService.recordStatistics(platformTotal); - log.info("[仪表盘统计] recordStatistics执行完成,平台: {}", platform); + log.debug("[仪表盘统计] recordStatistics执行完成,平台: {}", platform); // 更新平台推送消息数 IoTDashboardStatistics platformPush = @@ -399,7 +399,7 @@ public class DashboardStatisticsTask implements ApplicationRunner { /** 手动刷新统计数据 */ public void manualRefreshStatistics() { - log.info("[仪表盘统计] 手动触发统计数据刷新"); + log.debug("[仪表盘统计] 手动触发统计数据刷新"); refreshDatabaseStatisticsWithLock(); } @@ -426,12 +426,12 @@ public class DashboardStatisticsTask implements ApplicationRunner { /** 清理重复的统计数据 */ public void cleanupDuplicateStatistics(LocalDate date) { try { - log.info("[仪表盘统计] 开始清理{}的重复统计数据", date); + log.debug("[仪表盘统计] 开始清理{}的重复统计数据", date); // 删除指定日期的所有统计数据 int deletedCount = dashboardStatisticsMapper.deleteByDate(date); - log.info("[仪表盘统计] 清理完成,删除了{}条重复记录", deletedCount); + log.debug("[仪表盘统计] 清理完成,删除了{}条重复记录", deletedCount); } catch (Exception e) { log.error("[仪表盘统计] 清理重复统计数据失败", e); } diff --git a/cn-universal-framework/cn-universal-dm/src/main/java/cn/universal/dm/device/service/impl/IoTDeviceShadowService.java b/cn-universal-framework/cn-universal-dm/src/main/java/cn/universal/dm/device/service/impl/IoTDeviceShadowService.java index 83bf50d..0f8edc5 100644 --- a/cn-universal-framework/cn-universal-dm/src/main/java/cn/universal/dm/device/service/impl/IoTDeviceShadowService.java +++ b/cn-universal-framework/cn-universal-dm/src/main/java/cn/universal/dm/device/service/impl/IoTDeviceShadowService.java @@ -110,19 +110,19 @@ public class IoTDeviceShadowService { // 1. 最大延迟时间检查 if (timeSinceLastFlush > MAX_DELAY_MS) { - log.info("[ShadowFlush] 最大延迟强制刷盘: iotId={}, 延迟时间={}ms", iotId, timeSinceLastFlush); + log.debug("[ShadowFlush] 最大延迟强制刷盘: iotId={}, 延迟时间={}ms", iotId, timeSinceLastFlush); return now + FORCE_FLUSH_DELAY_MS; } // 2. 最小间隔检查 if (timeSinceLastFlush >= MIN_INTERVAL_MS) { - log.info("[ShadowFlush] 最小间隔强制刷盘: iotId={}, 间隔时间={}ms", iotId, timeSinceLastFlush); + log.debug("[ShadowFlush] 最小间隔强制刷盘: iotId={}, 间隔时间={}ms", iotId, timeSinceLastFlush); return now + FORCE_FLUSH_DELAY_MS; } // 3. 版本号检查 if (checkVersionThreshold(iotId)) { - log.info("[ShadowFlush] 版本号强制刷盘: iotId={}", iotId); + log.debug("[ShadowFlush] 版本号强制刷盘: iotId={}", iotId); return now + FORCE_FLUSH_DELAY_MS; } @@ -245,14 +245,14 @@ public class IoTDeviceShadowService { IoTDevicePropertiesBO entity = new IoTDevicePropertiesBO(); Long ts = finalShadow.getMetadata() != null - && finalShadow.getMetadata().getReported() != null - && finalShadow.getMetadata().getReported().getJSONObject(s.getId()) - != null + && finalShadow.getMetadata().getReported() != null + && finalShadow.getMetadata().getReported().getJSONObject(s.getId()) + != null ? finalShadow - .getMetadata() - .getReported() - .getJSONObject(s.getId()) - .getLong("timestamp") + .getMetadata() + .getReported() + .getJSONObject(s.getId()) + .getLong("timestamp") : DateUtil.currentSeconds(); entity.setDesireValue(finalDesireProperties.get(s.getId())); entity.withValue(s.getValueType(), obj); @@ -313,13 +313,13 @@ public class IoTDeviceShadowService { entity.withValue(s.getValueType(), obj); entity.setTimestamp( finalShadow.getMetadata() != null - && finalShadow.getMetadata().getReported() != null - && finalShadow.getMetadata().getReported().getJSONObject(s.getId()) != null + && finalShadow.getMetadata().getReported() != null + && finalShadow.getMetadata().getReported().getJSONObject(s.getId()) != null ? finalShadow - .getMetadata() - .getReported() - .getJSONObject(s.getId()) - .getLong("timestamp") + .getMetadata() + .getReported() + .getJSONObject(s.getId()) + .getLong("timestamp") : DateUtil.currentSeconds()); } else { entity.withValue(s.getValueType(), null); @@ -638,7 +638,7 @@ public class IoTDeviceShadowService { && (currentVersion - dbVersion) >= VERSION_THRESHOLD; } else { // 数据库记录不存在:立即触发刷盘(创建记录) - log.info("[ShadowFlush] 数据库记录不存在,立即刷盘: iotId={}, currentVersion={}", iotId, currentVersion); + log.debug("[ShadowFlush] 数据库记录不存在,立即刷盘: iotId={}, currentVersion={}", iotId, currentVersion); return true; } } catch (Exception e) { diff --git a/cn-universal-framework/cn-universal-dm/src/main/java/cn/universal/dm/device/service/task/ShadowFlushScheduler.java b/cn-universal-framework/cn-universal-dm/src/main/java/cn/universal/dm/device/service/task/ShadowFlushScheduler.java index 780a65e..efc52e9 100644 --- a/cn-universal-framework/cn-universal-dm/src/main/java/cn/universal/dm/device/service/task/ShadowFlushScheduler.java +++ b/cn-universal-framework/cn-universal-dm/src/main/java/cn/universal/dm/device/service/task/ShadowFlushScheduler.java @@ -87,7 +87,7 @@ public class ShadowFlushScheduler { long now = System.currentTimeMillis(); String instanceId = instanceIdProvider.getInstanceId(); - log.info("[ShadowFlush] 开始设备影子扫描: scanTime={}, instanceId={}", now, instanceId); + log.debug("[ShadowFlush] 开始设备影子扫描: scanTime={}, instanceId={}", now, instanceId); // 使用分布式锁工具类执行任务,确保集群环境下只有一个实例执行 Integer result = @@ -95,7 +95,7 @@ public class ShadowFlushScheduler { lockKey, lockWaitTime, lockLeaseTime, TimeUnit.SECONDS, this::executeFlushTask); if (result != null) { - log.info( + log.debug( "[ShadowFlush] 影子扫描完成: processed={}, cost={}ms, instanceId={}", result, (System.currentTimeMillis() - now), @@ -380,7 +380,7 @@ public class ShadowFlushScheduler { // 获取缓存数据 Map cacheData = getCacheData(dueIds); if (cacheData.isEmpty()) { - log.warn("[ShadowFlush] 缓存数据为空,跳过刷盘: dueIds={}, instanceId={}", dueIds, instanceId); + log.debug("[ShadowFlush] 缓存数据为空,跳过刷盘: dueIds={}, instanceId={}", dueIds, instanceId); return 0; } @@ -428,7 +428,7 @@ public class ShadowFlushScheduler { 10, // 持有10秒 TimeUnit.SECONDS, () -> { - log.info("[ShadowFlush] 测试锁获取成功,当前时间: {}", DateUtil.now()); + log.debug("[ShadowFlush] 测试锁获取成功,当前时间: {}", DateUtil.now()); try { Thread.sleep(2000); // 模拟处理时间 } catch (InterruptedException e) { diff --git a/cn-universal-protocol/cn-universal-mqtt-protocol/src/main/java/cn/universal/mqtt/protocol/third/MQTTStatisticsLogger.java b/cn-universal-protocol/cn-universal-mqtt-protocol/src/main/java/cn/universal/mqtt/protocol/third/MQTTStatisticsLogger.java index 7e84bf3..87dfd66 100644 --- a/cn-universal-protocol/cn-universal-mqtt-protocol/src/main/java/cn/universal/mqtt/protocol/third/MQTTStatisticsLogger.java +++ b/cn-universal-protocol/cn-universal-mqtt-protocol/src/main/java/cn/universal/mqtt/protocol/third/MQTTStatisticsLogger.java @@ -126,8 +126,8 @@ public class MQTTStatisticsLogger { // 性能指标 MqttMetricsSnapshot snapshot = metricsCollector.getSnapshot(); - log.info("[MQTT_STATS] ========== MQTT 统计信息 [{}] ==========", timestamp); - log.info("[MQTT_STATS] 配置统计: {}", configStats); + log.debug("[MQTT_STATS] ========== MQTT 统计信息 [{}] ==========", timestamp); + log.debug("[MQTT_STATS] 配置统计: {}", configStats); double connectionRate = allStatus.size() > 0 ? (effectiveConnected * 100.0 / allStatus.size()) : 0.0; log.info( @@ -138,13 +138,13 @@ public class MQTTStatisticsLogger { systemCoveredCount, errorCount, String.format("%.2f", connectionRate)); - log.info( + log.debug( "[MQTT_STATS] 性能指标: 消息处理={}, 平均延迟={}ms, 错误率={}%", snapshot.getTotalMessageCount(), snapshot.getAverageProcessingTime(), String.format("%.2f", snapshot.getErrorRate())); - log.info("[MQTT_STATS] 系统MQTT: {}", sysMQTTManager.isEnabled() ? "已启用" : "未启用"); - log.info("[MQTT_STATS] ================================================="); + log.debug("[MQTT_STATS] 系统MQTT: {}", sysMQTTManager.isEnabled() ? "已启用" : "未启用"); + log.debug("[MQTT_STATS] ================================================="); } catch (Exception e) { log.error("[MQTT_STATS] 获取基础统计信息失败: ", e); diff --git a/cn-universal-web/src/main/java/cn/universal/monitor/ThreadMonitor.java b/cn-universal-web/src/main/java/cn/universal/monitor/ThreadMonitor.java index c888993..1559cad 100644 --- a/cn-universal-web/src/main/java/cn/universal/monitor/ThreadMonitor.java +++ b/cn-universal-web/src/main/java/cn/universal/monitor/ThreadMonitor.java @@ -70,7 +70,7 @@ public class ThreadMonitor { // 定期打印线程统计信息 if (System.currentTimeMillis() % 300000 < 30000) { // 每5分钟打印一次 - log.info( + log.debug( "线程统计 - 总数: {}, 守护线程: {}, 峰值: {}", threadMXBean.getThreadCount(), threadMXBean.getDaemonThreadCount(), diff --git a/cn-universal-web/src/main/java/cn/universal/web/context/IotServiceImplFactory.java b/cn-universal-web/src/main/java/cn/universal/web/context/IotServiceImplFactory.java deleted file mode 100644 index 8a7b1d2..0000000 --- a/cn-universal-web/src/main/java/cn/universal/web/context/IotServiceImplFactory.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * - * Copyright (c) 2025, IoT-Universal. All Rights Reserved. - * - * @Description: 本文件由 Aleo 开发并拥有版权,未经授权严禁擅自商用、复制或传播。 - * @Author: Aleo - * @Email: wo8335224@gmail.com - * @Wechat: outlookFil - * - * - */ - -package cn.universal.web.context; // package cn.universal.context; -// -// import cn.universal.core.third.IDown; -// import cn.universal.core.third.IUP; -// import java.util.HashMap; -// import java.util.Map; -// import lombok.extern.slf4j.Slf4j; -// import org.springframework.beans.BeansException; -// import org.springframework.context.ApplicationContext; -// import org.springframework.context.ApplicationContextAware; -// import org.springframework.stereotype.Component; -// -/// ** -// * 多实现路由 -// * -// * @Author Aleo -// * @version 1.0 -// * @since 2025/8/12 19:11 -// */ -// @Component -// @Slf4j -// public class IoTDownlFactory implements ApplicationContextAware { -// -// private static Map iDownMap = new HashMap<>(); -// private static Map iupMap = new HashMap<>(); -// -// @Override -// public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { -// //处理下行 -// Map downMap = applicationContext.getBeansOfType(IDown.class); -// downMap.forEach((key, value) -> iDownMap.put(value.name(), value)); -// log.info("init IDown third ,[{}]", iDownMap); -// //处理上行 -// Map upMap = applicationContext.getBeansOfType(IUP.class); -// upMap.forEach((key, value) -> iupMap.put(value.name(), value)); -// log.info("init IUP third ,[{}]", iupMap); -// -// } -// -// public static T getIDown(String code) { -// return (T) iDownMap.get(code); -// } -// -// public static T getIUP(String code) { -// return (T) iupMap.get(code); -// } -// } diff --git a/cn-universal-web/src/main/resources/application.properties b/cn-universal-web/src/main/resources/application.properties index dd4e905..c89d863 100644 --- a/cn-universal-web/src/main/resources/application.properties +++ b/cn-universal-web/src/main/resources/application.properties @@ -112,7 +112,7 @@ rulego.web.base-url=http://rule.192886.xyz:81/# rulego.api.base-url=http://192.168.31.194:9090 rulego.api.token=${RULEGO_API_TOKEN:2af255ea5618467d914c67a8beeca31d} # RuleGo同步配置 -rulego.sync.enabled=true +rulego.sync.enabled=false rulego.sync.interval=300000 rulego.sync.log-cleanup-enabled=true rulego.sync.log-retention-days=30 -- Gitee