From 5086e1225f55d18491b04b8f5c8638bde4c710c7 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Tue, 13 Jan 2026 23:04:28 +0800 Subject: [PATCH] =?UTF-8?q?review=EF=BC=9A=E3=80=90iot=E3=80=91=E2=80=9C?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=86=E4=B8=80=E4=BA=9B=20Iot=20=E6=A8=A1?= =?UTF-8?q?=E5=9D=97=20TODO=20=E6=8F=90=E5=88=B0=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../rule/data/action/IotWebSocketDataRuleAction.java | 8 +++++--- .../iot/service/rule/data/action/tcp/IotTcpClient.java | 2 ++ .../rule/data/action/websocket/IotWebSocketClient.java | 1 + .../iot/service/rule/scene/IotSceneRuleServiceImpl.java | 5 +---- .../trigger/IotDevicePropertyPostTriggerMatcher.java | 1 + 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/data/action/IotWebSocketDataRuleAction.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/data/action/IotWebSocketDataRuleAction.java index 5e2750980c..c0445df906 100644 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/data/action/IotWebSocketDataRuleAction.java +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/data/action/IotWebSocketDataRuleAction.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.iot.service.rule.data.action; +import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.module.iot.core.mq.message.IotDeviceMessage; import cn.iocoder.yudao.module.iot.dal.dataobject.rule.config.IotDataSinkWebSocketConfig; import cn.iocoder.yudao.module.iot.enums.rule.IotDataSinkTypeEnum; @@ -28,11 +29,11 @@ public class IotWebSocketDataRuleAction extends @Override protected IotWebSocketClient initProducer(IotDataSinkWebSocketConfig config) throws Exception { - // 1.1 参数校验 - if (config.getServerUrl() == null || config.getServerUrl().trim().isEmpty()) { + // 1. 参数校验 + if (StrUtil.isBlank(config.getServerUrl())) { throw new IllegalArgumentException("WebSocket 服务器地址不能为空"); } - if (!config.getServerUrl().startsWith("ws://") && !config.getServerUrl().startsWith("wss://")) { + if (!StrUtil.startWithAny(config.getServerUrl(), "ws://", "wss://")) { throw new IllegalArgumentException("WebSocket 服务器地址必须以 ws:// 或 wss:// 开头"); } @@ -61,6 +62,7 @@ public class IotWebSocketDataRuleAction extends protected void execute(IotDeviceMessage message, IotDataSinkWebSocketConfig config) throws Exception { try { // 1.1 获取或创建 WebSocket 客户端 + // TODO @puhui999:需要加锁,保证必须连接上; IotWebSocketClient webSocketClient = getProducer(config); // 1.2 检查连接状态,如果断开则重新连接 if (!webSocketClient.isConnected()) { diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/data/action/tcp/IotTcpClient.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/data/action/tcp/IotTcpClient.java index b417dca5a2..15b57b5405 100644 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/data/action/tcp/IotTcpClient.java +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/data/action/tcp/IotTcpClient.java @@ -31,6 +31,7 @@ public class IotTcpClient { private final Integer connectTimeoutMs; private final Integer readTimeoutMs; private final Boolean ssl; + // TODO @puhui999:sslCertPath 是不是没在用? private final String sslCertPath; private final String dataFormat; @@ -47,6 +48,7 @@ public class IotTcpClient { this.readTimeoutMs = readTimeoutMs != null ? readTimeoutMs : IotDataSinkTcpConfig.DEFAULT_READ_TIMEOUT_MS; this.ssl = ssl != null ? ssl : IotDataSinkTcpConfig.DEFAULT_SSL; this.sslCertPath = sslCertPath; + // TODO @puhui999:可以使用 StrUtil.defaultIfBlank 方法简化 this.dataFormat = dataFormat != null ? dataFormat : IotDataSinkTcpConfig.DEFAULT_DATA_FORMAT; } diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/data/action/websocket/IotWebSocketClient.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/data/action/websocket/IotWebSocketClient.java index bed197657f..2f55d6ee74 100644 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/data/action/websocket/IotWebSocketClient.java +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/data/action/websocket/IotWebSocketClient.java @@ -45,6 +45,7 @@ public class IotWebSocketClient implements WebSocket.Listener { /** * 连接到 WebSocket 服务器 */ + @SuppressWarnings("resource") public void connect() throws Exception { if (connected.get()) { log.warn("[connect][WebSocket 客户端已经连接,无需重复连接]"); diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/scene/IotSceneRuleServiceImpl.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/scene/IotSceneRuleServiceImpl.java index eb70b30480..f96bc9f450 100644 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/scene/IotSceneRuleServiceImpl.java +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/scene/IotSceneRuleServiceImpl.java @@ -406,10 +406,7 @@ public class IotSceneRuleServiceImpl implements IotSceneRuleService { */ private void updateLastTriggerTime(Long id) { try { - IotSceneRuleDO updateObj = new IotSceneRuleDO() - .setId(id) - .setLastTriggerTime(LocalDateTime.now()); - sceneRuleMapper.updateById(updateObj); + sceneRuleMapper.updateById(new IotSceneRuleDO().setId(id).setLastTriggerTime(LocalDateTime.now())); } catch (Exception e) { log.error("[updateLastTriggerTime][规则场景编号({}) 更新最后触发时间异常]", id, e); } diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/scene/matcher/trigger/IotDevicePropertyPostTriggerMatcher.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/scene/matcher/trigger/IotDevicePropertyPostTriggerMatcher.java index f5d461275b..d653c9c42e 100644 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/scene/matcher/trigger/IotDevicePropertyPostTriggerMatcher.java +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/scene/matcher/trigger/IotDevicePropertyPostTriggerMatcher.java @@ -38,6 +38,7 @@ public class IotDevicePropertyPostTriggerMatcher implements IotSceneRuleTriggerM // 1.3 检查消息中是否包含触发器指定的属性标识符 // 注意:属性上报可能同时上报多个属性,所以需要判断 trigger.getIdentifier() 是否在 message 的 params 中 + // TODO @puhui999:可以考虑 notXXX 方法,简化代码(尽量取反) if (!IotDeviceMessageUtils.containsIdentifier(message, trigger.getIdentifier())) { IotSceneRuleMatcherHelper.logTriggerMatchFailure(message, trigger, "消息中不包含属性: " + trigger.getIdentifier());