【代码新增】IoT:完善 IotRuleSceneServiceImpl 的规则匹配计算,isTriggerConditionParameterMatched 函数有点长,= = 捉摸咋优化下

This commit is contained in:
YunaiV
2025-02-02 22:08:34 +08:00
parent a4be3bb84d
commit 910bb6ca3c
4 changed files with 153 additions and 50 deletions

View File

@@ -16,29 +16,42 @@ import java.util.Arrays;
@Getter
public enum IotRuleSceneTriggerConditionParameterOperatorEnum implements ArrayValuable<String> {
EQUALS("=", "%s == %s"),
NOT_EQUALS("!=", "%s != %s"),
EQUALS("=", "#source == #value"),
NOT_EQUALS("!=", "!(#source == #value)"),
GREATER_THAN(">", "%s > %s"),
GREATER_THAN_OR_EQUALS(">=", "%s >= %s"),
GREATER_THAN(">", "#source > #value"),
GREATER_THAN_OR_EQUALS(">=", "#source >= #value"),
LESS_THAN("<", "%s < %s"),
LESS_THAN_OR_EQUALS("<=", "%s <= %s"),
LESS_THAN("<", "#source < #value"),
LESS_THAN_OR_EQUALS("<=", "#source <= #value"),
IN("in", "%s in { %s }"),
NOT_IN("not in", "%s not in { %s }"),
IN("in", "#values.contains(#source)"),
NOT_IN("not in", "!(#values.contains(#source))"),
BETWEEN("between", "(%s >= %s) && (%s <= %s)"),
NOT_BETWEEN("not between", "!(%s between %s and %s)"),
BETWEEN("between", "(#source >= #values.get(0)) && (#source <= #values.get(1))"),
NOT_BETWEEN("not between", "(#source < #values.get(0)) || (#source > #values.get(1))"),
LIKE("like", "%s like %s"), // 字符串匹配
NOT_NULL("not null", ""); // 非空
LIKE("like", "#source.contains(#value)"), // 字符串匹配
NOT_NULL("not null", "#source != null && #source.length() > 0"); // 非空
private final String operator;
private final String springExpression;
public static final String[] ARRAYS = Arrays.stream(values()).map(IotRuleSceneTriggerConditionParameterOperatorEnum::getOperator).toArray(String[]::new);
/**
* Spring 表达式 - 原始值
*/
public static final String SPRING_EXPRESSION_SOURCE = "source";
/**
* Spring 表达式 - 目标值
*/
public static final String SPRING_EXPRESSION_VALUE = "value";
/**
* Spring 表达式 - 目标值数组
*/
public static final String SPRING_EXPRESSION_VALUE_List = "values";
public static IotRuleSceneTriggerConditionParameterOperatorEnum operatorOf(String operator) {
return ArrayUtil.firstMatch(item -> item.getOperator().equals(operator), values());
}