Commit 9c6c1584e7fdf065f81335070b6eb1fd2645cfe5
1 parent
94abcdff
perf:【IoT 物联网】优化 CurrentTimeConditionMatcher 时间条件匹配器 switch 兼容 jdk8
Showing
1 changed file
with
20 additions
and
17 deletions
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 |
| 123 | 123 | isDateTimeOperator(operatorEnum); |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | - // TODO @puhui999:switch 兼容下 jdk8 | |
| 127 | 126 | /** |
| 128 | 127 | * 匹配日期时间(时间戳) |
| 129 | 128 | * 直接实现时间戳比较逻辑 |
| ... | ... | @@ -131,15 +130,17 @@ public class CurrentTimeConditionMatcher implements IotSceneRuleConditionMatcher |
| 131 | 130 | private boolean matchDateTime(long currentTimestamp, IotSceneRuleConditionOperatorEnum operatorEnum, String param) { |
| 132 | 131 | try { |
| 133 | 132 | long targetTimestamp = Long.parseLong(param); |
| 134 | - return switch (operatorEnum) { | |
| 135 | - case DATE_TIME_GREATER_THAN -> currentTimestamp > targetTimestamp; | |
| 136 | - case DATE_TIME_LESS_THAN -> currentTimestamp < targetTimestamp; | |
| 137 | - case DATE_TIME_BETWEEN -> matchDateTimeBetween(currentTimestamp, param); | |
| 138 | - default -> { | |
| 133 | + switch (operatorEnum) { | |
| 134 | + case DATE_TIME_GREATER_THAN: | |
| 135 | + return currentTimestamp > targetTimestamp; | |
| 136 | + case DATE_TIME_LESS_THAN: | |
| 137 | + return currentTimestamp < targetTimestamp; | |
| 138 | + case DATE_TIME_BETWEEN: | |
| 139 | + return matchDateTimeBetween(currentTimestamp, param); | |
| 140 | + default: | |
| 139 | 141 | log.warn("[matchDateTime][operatorEnum({}) 不支持的日期时间操作符]", operatorEnum); |
| 140 | - yield false; | |
| 141 | - } | |
| 142 | - }; | |
| 142 | + return false; | |
| 143 | + } | |
| 143 | 144 | } catch (Exception e) { |
| 144 | 145 | log.error("[matchDateTime][operatorEnum({}) param({}) 日期时间匹配异常]", operatorEnum, param, e); |
| 145 | 146 | return false; |
| ... | ... | @@ -167,15 +168,17 @@ public class CurrentTimeConditionMatcher implements IotSceneRuleConditionMatcher |
| 167 | 168 | private boolean matchTime(LocalTime currentTime, IotSceneRuleConditionOperatorEnum operatorEnum, String param) { |
| 168 | 169 | try { |
| 169 | 170 | LocalTime targetTime = parseTime(param); |
| 170 | - return switch (operatorEnum) { | |
| 171 | - case TIME_GREATER_THAN -> currentTime.isAfter(targetTime); | |
| 172 | - case TIME_LESS_THAN -> currentTime.isBefore(targetTime); | |
| 173 | - case TIME_BETWEEN -> matchTimeBetween(currentTime, param); | |
| 174 | - default -> { | |
| 171 | + switch (operatorEnum) { | |
| 172 | + case TIME_GREATER_THAN: | |
| 173 | + return currentTime.isAfter(targetTime); | |
| 174 | + case TIME_LESS_THAN: | |
| 175 | + return currentTime.isBefore(targetTime); | |
| 176 | + case TIME_BETWEEN: | |
| 177 | + return matchTimeBetween(currentTime, param); | |
| 178 | + default: | |
| 175 | 179 | log.warn("[matchTime][operatorEnum({}) 不支持的时间操作符]", operatorEnum); |
| 176 | - yield false; | |
| 177 | - } | |
| 178 | - }; | |
| 180 | + return false; | |
| 181 | + } | |
| 179 | 182 | } catch (Exception e) { |
| 180 | 183 | log.error("[matchTime][][operatorEnum({}) param({}) 时间解析异常]", operatorEnum, param, e); |
| 181 | 184 | return false; | ... | ... |