From 9c6c1584e7fdf065f81335070b6eb1fd2645cfe5 Mon Sep 17 00:00:00 2001 From: puhui999 Date: Sun, 24 Aug 2025 12:04:08 +0800 Subject: [PATCH] =?UTF-8?q?perf:=E3=80=90IoT=20=E7=89=A9=E8=81=94=E7=BD=91?= =?UTF-8?q?=E3=80=91=E4=BC=98=E5=8C=96=20CurrentTimeConditionMatcher=20?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E6=9D=A1=E4=BB=B6=E5=8C=B9=E9=85=8D=E5=99=A8?= =?UTF-8?q?=20switch=20=E5=85=BC=E5=AE=B9=20jdk8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CurrentTimeConditionMatcher.java | 37 ++++++++++--------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/scene/matcher/condition/CurrentTimeConditionMatcher.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/scene/matcher/condition/CurrentTimeConditionMatcher.java index 0daf4eefd5..d96e450428 100644 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/scene/matcher/condition/CurrentTimeConditionMatcher.java +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/scene/matcher/condition/CurrentTimeConditionMatcher.java @@ -123,7 +123,6 @@ public class CurrentTimeConditionMatcher implements IotSceneRuleConditionMatcher isDateTimeOperator(operatorEnum); } - // TODO @puhui999:switch 兼容下 jdk8 /** * 匹配日期时间(时间戳) * 直接实现时间戳比较逻辑 @@ -131,15 +130,17 @@ public class CurrentTimeConditionMatcher implements IotSceneRuleConditionMatcher private boolean matchDateTime(long currentTimestamp, IotSceneRuleConditionOperatorEnum operatorEnum, String param) { try { long targetTimestamp = Long.parseLong(param); - return switch (operatorEnum) { - case DATE_TIME_GREATER_THAN -> currentTimestamp > targetTimestamp; - case DATE_TIME_LESS_THAN -> currentTimestamp < targetTimestamp; - case DATE_TIME_BETWEEN -> matchDateTimeBetween(currentTimestamp, param); - default -> { + switch (operatorEnum) { + case DATE_TIME_GREATER_THAN: + return currentTimestamp > targetTimestamp; + case DATE_TIME_LESS_THAN: + return currentTimestamp < targetTimestamp; + case DATE_TIME_BETWEEN: + return matchDateTimeBetween(currentTimestamp, param); + default: log.warn("[matchDateTime][operatorEnum({}) 不支持的日期时间操作符]", operatorEnum); - yield false; - } - }; + return false; + } } catch (Exception e) { log.error("[matchDateTime][operatorEnum({}) param({}) 日期时间匹配异常]", operatorEnum, param, e); return false; @@ -167,15 +168,17 @@ public class CurrentTimeConditionMatcher implements IotSceneRuleConditionMatcher private boolean matchTime(LocalTime currentTime, IotSceneRuleConditionOperatorEnum operatorEnum, String param) { try { LocalTime targetTime = parseTime(param); - return switch (operatorEnum) { - case TIME_GREATER_THAN -> currentTime.isAfter(targetTime); - case TIME_LESS_THAN -> currentTime.isBefore(targetTime); - case TIME_BETWEEN -> matchTimeBetween(currentTime, param); - default -> { + switch (operatorEnum) { + case TIME_GREATER_THAN: + return currentTime.isAfter(targetTime); + case TIME_LESS_THAN: + return currentTime.isBefore(targetTime); + case TIME_BETWEEN: + return matchTimeBetween(currentTime, param); + default: log.warn("[matchTime][operatorEnum({}) 不支持的时间操作符]", operatorEnum); - yield false; - } - }; + return false; + } } catch (Exception e) { log.error("[matchTime][][operatorEnum({}) param({}) 时间解析异常]", operatorEnum, param, e); return false;