mirror of
https://gitee.com/zhijiantianya/ruoyi-vue-pro.git
synced 2026-03-22 05:07:17 +08:00
perf:【IoT 物联网】优化 CurrentTimeConditionMatcher 时间条件匹配器 switch 兼容 jdk8
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user