2026-06-24 f4bd1f3c89d906131495a0aca5aaf82966378510
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package cn.iocoder.yudao.module.iot.enums.rule;
 
import cn.hutool.core.util.ArrayUtil;
import cn.iocoder.yudao.framework.common.core.ArrayValuable;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
 
import java.util.Arrays;
 
/**
 * IoT 场景触发条件的操作符枚举
 *
 * @author 芋道源码
 */
@RequiredArgsConstructor
@Getter
public enum IotSceneRuleConditionOperatorEnum implements ArrayValuable<String> {
 
    EQUALS("=", "#source == #value"),
    NOT_EQUALS("!=", "!(#source == #value)"),
 
    GREATER_THAN(">", "#source > #value"),
    GREATER_THAN_OR_EQUALS(">=", "#source >= #value"),
 
    LESS_THAN("<", "#source < #value"),
    LESS_THAN_OR_EQUALS("<=", "#source <= #value"),
 
    IN("in", "#values.contains(#source)"),
    NOT_IN("not in", "!(#values.contains(#source))"),
 
    BETWEEN("between", "(#source >= #values.get(0)) && (#source <= #values.get(1))"),
    NOT_BETWEEN("not between", "(#source < #values.get(0)) || (#source > #values.get(1))"),
 
    LIKE("like", "#source.contains(#value)"), // 字符串匹配
    NOT_NULL("not null", "#source != null && #source.length() > 0"), // 非空
 
    // ========== 特殊:不放在字典里 ==========
 
    DATE_TIME_GREATER_THAN("date_time_>", "#source > #value"), // 在时间之后:时间戳
    DATE_TIME_LESS_THAN("date_time_<", "#source < #value"), // 在时间之前:时间戳
    DATE_TIME_BETWEEN("date_time_between", // 在时间之间:时间戳
            "(#source >= #values.get(0)) && (#source <= #values.get(1))"),
 
    TIME_GREATER_THAN("time_>", "#source.isAfter(#value)"), // 在当日时间之后:HH:mm:ss
    TIME_LESS_THAN("time_<", "#source.isBefore(#value)"), // 在当日时间之前:HH:mm:ss
    TIME_BETWEEN("time_between", // 在当日时间之间:HH:mm:ss
            "(#source >= #values.get(0)) && (#source <= #values.get(1))"),
 
    ;
 
    private final String operator;
    private final String springExpression;
 
    public static final String[] ARRAYS = Arrays.stream(values()).map(IotSceneRuleConditionOperatorEnum::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 IotSceneRuleConditionOperatorEnum operatorOf(String operator) {
        return ArrayUtil.firstMatch(item -> item.getOperator().equals(operator), values());
    }
 
    @Override
    public String[] array() {
        return ARRAYS;
    }
 
}