Commit 1ad4e08cb83ce4b1d1fdeb53df07715de44bd9a3
1 parent
a17d4bb2
reactor:【IoT 物联网】增加 IotRuleScene2DO 新的定义,对标阿里云 IoT 的「事件响应」
Showing
12 changed files
with
399 additions
and
45 deletions
yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/device/IotDeviceMessageTypeEnum.java
yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/rule/IotRuleSceneActionTypeEnum.java
| ... | ... | @@ -15,8 +15,33 @@ import java.util.Arrays; |
| 15 | 15 | @Getter |
| 16 | 16 | public enum IotRuleSceneActionTypeEnum implements ArrayValuable<Integer> { |
| 17 | 17 | |
| 18 | - DEVICE_CONTROL(1), // 设备执行 | |
| 18 | + // TODO @芋艿:后续“对应”部分,要 @下,等包结构梳理完; | |
| 19 | + /** | |
| 20 | + * 设备属性设置 | |
| 21 | + * | |
| 22 | + * 对应 IotDeviceMessageMethodEnum.DEVICE_PROPERTY_SET | |
| 23 | + */ | |
| 24 | + DEVICE_PROPERTY_SET(1), | |
| 25 | + /** | |
| 26 | + * 设备服务调用 | |
| 27 | + * | |
| 28 | + * 对应 IotDeviceMessageMethodEnum.DEVICE_SERVICE_INVOKE | |
| 29 | + */ | |
| 30 | + DEVICE_SERVICE_INVOKE(2), | |
| 31 | + | |
| 32 | + /** | |
| 33 | + * 告警触发 | |
| 34 | + */ | |
| 35 | + ALERT_TRIGGER(100), | |
| 36 | + /** | |
| 37 | + * 告警恢复 | |
| 38 | + */ | |
| 39 | + ALERT_RECOVER(101), | |
| 40 | + | |
| 41 | + @Deprecated | |
| 19 | 42 | ALERT(2), // 告警执行 |
| 43 | + | |
| 44 | + @Deprecated | |
| 20 | 45 | DATA_BRIDGE(3); // 桥接执行 |
| 21 | 46 | |
| 22 | 47 | private final Integer type; | ... | ... |
yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/rule/IotRuleSceneTriggerConditionParameterOperatorEnum.java renamed to yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/rule/IotRuleSceneConditionOperatorEnum.java
| ... | ... | @@ -8,13 +8,13 @@ import lombok.RequiredArgsConstructor; |
| 8 | 8 | import java.util.Arrays; |
| 9 | 9 | |
| 10 | 10 | /** |
| 11 | - * IoT 场景触发条件参数的操作符枚举 | |
| 11 | + * IoT 场景触发条件的操作符枚举 | |
| 12 | 12 | * |
| 13 | 13 | * @author 芋道源码 |
| 14 | 14 | */ |
| 15 | 15 | @RequiredArgsConstructor |
| 16 | 16 | @Getter |
| 17 | -public enum IotRuleSceneTriggerConditionParameterOperatorEnum implements ArrayValuable<String> { | |
| 17 | +public enum IotRuleSceneConditionOperatorEnum implements ArrayValuable<String> { | |
| 18 | 18 | |
| 19 | 19 | EQUALS("=", "#source == #value"), |
| 20 | 20 | NOT_EQUALS("!=", "!(#source == #value)"), |
| ... | ... | @@ -32,12 +32,28 @@ public enum IotRuleSceneTriggerConditionParameterOperatorEnum implements ArrayVa |
| 32 | 32 | NOT_BETWEEN("not between", "(#source < #values.get(0)) || (#source > #values.get(1))"), |
| 33 | 33 | |
| 34 | 34 | LIKE("like", "#source.contains(#value)"), // 字符串匹配 |
| 35 | - NOT_NULL("not null", "#source != null && #source.length() > 0"); // 非空 | |
| 35 | + NOT_NULL("not null", "#source != null && #source.length() > 0"), // 非空 | |
| 36 | + | |
| 37 | + // ========== 特殊:不放在字典里 ========== | |
| 38 | + | |
| 39 | + // TODO @puhui999:@芋艿:需要测试下 | |
| 40 | + DATE_TIME_GREATER_THAN("date_time_>", "#source > #value"), // 在时间之后:时间戳 | |
| 41 | + DATE_TIME_LESS_THAN("date_time_<", "#source < #value"), // 在时间之前:时间戳 | |
| 42 | + DATE_TIME_BETWEEN("date_time_between", // 在时间之间:时间戳 | |
| 43 | + "(#source >= #values.get(0)) && (#source <= #values.get(1))"), | |
| 44 | + | |
| 45 | + // TODO @puhui999:@芋艿:需要测试下 | |
| 46 | + TIME_GREATER_THAN("time_>", "#source.isAfter(#value)"), // 在当日时间之后:HH:mm:ss | |
| 47 | + TIME_LESS_THAN("time_<", "#source.isBefore(#value)"), // 在当日时间之前:HH:mm:ss | |
| 48 | + TIME_BETWEEN("time_between", // 在当日时间之间:HH:mm:ss | |
| 49 | + "(#source >= #values.get(0)) && (#source <= #values.get(1))"), | |
| 50 | + | |
| 51 | + ; | |
| 36 | 52 | |
| 37 | 53 | private final String operator; |
| 38 | 54 | private final String springExpression; |
| 39 | 55 | |
| 40 | - public static final String[] ARRAYS = Arrays.stream(values()).map(IotRuleSceneTriggerConditionParameterOperatorEnum::getOperator).toArray(String[]::new); | |
| 56 | + public static final String[] ARRAYS = Arrays.stream(values()).map(IotRuleSceneConditionOperatorEnum::getOperator).toArray(String[]::new); | |
| 41 | 57 | |
| 42 | 58 | /** |
| 43 | 59 | * Spring 表达式 - 原始值 |
| ... | ... | @@ -52,7 +68,7 @@ public enum IotRuleSceneTriggerConditionParameterOperatorEnum implements ArrayVa |
| 52 | 68 | */ |
| 53 | 69 | public static final String SPRING_EXPRESSION_VALUE_LIST = "values"; |
| 54 | 70 | |
| 55 | - public static IotRuleSceneTriggerConditionParameterOperatorEnum operatorOf(String operator) { | |
| 71 | + public static IotRuleSceneConditionOperatorEnum operatorOf(String operator) { | |
| 56 | 72 | return ArrayUtil.firstMatch(item -> item.getOperator().equals(operator), values()); |
| 57 | 73 | } |
| 58 | 74 | ... | ... |
yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/rule/IotRuleSceneConditionTypeEnum.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.iot.enums.rule; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.common.core.ArrayValuable; | |
| 4 | +import lombok.Getter; | |
| 5 | +import lombok.RequiredArgsConstructor; | |
| 6 | + | |
| 7 | +import java.util.Arrays; | |
| 8 | + | |
| 9 | +/** | |
| 10 | + * IoT 条件类型枚举 | |
| 11 | + * | |
| 12 | + * @author 芋道源码 | |
| 13 | + */ | |
| 14 | +@RequiredArgsConstructor | |
| 15 | +@Getter | |
| 16 | +public enum IotRuleSceneConditionTypeEnum implements ArrayValuable<Integer> { | |
| 17 | + | |
| 18 | + DEVICE_STATE(1, "设备状态"), | |
| 19 | + DEVICE_PROPERTY(2, "设备属性"), | |
| 20 | + | |
| 21 | + CURRENT_TIME(100, "当前时间"), | |
| 22 | + | |
| 23 | + ; | |
| 24 | + | |
| 25 | + private final Integer type; | |
| 26 | + private final String name; | |
| 27 | + | |
| 28 | + public static final Integer[] ARRAYS = Arrays.stream(values()).map(IotRuleSceneConditionTypeEnum::getType).toArray(Integer[]::new); | |
| 29 | + | |
| 30 | + @Override | |
| 31 | + public Integer[] array() { | |
| 32 | + return ARRAYS; | |
| 33 | + } | |
| 34 | + | |
| 35 | +} | ... | ... |
yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/rule/IotRuleSceneTriggerTypeEnum.java
| ... | ... | @@ -9,14 +9,47 @@ import java.util.Arrays; |
| 9 | 9 | /** |
| 10 | 10 | * IoT 场景流转的触发类型枚举 |
| 11 | 11 | * |
| 12 | + * 为什么不直接使用 IotDeviceMessageMethodEnum 呢? | |
| 13 | + * 原因是,物模型属性上报,存在批量上报的情况,不只对应一个 method!!! | |
| 14 | + * | |
| 12 | 15 | * @author 芋道源码 |
| 13 | 16 | */ |
| 14 | 17 | @RequiredArgsConstructor |
| 15 | 18 | @Getter |
| 16 | 19 | public enum IotRuleSceneTriggerTypeEnum implements ArrayValuable<Integer> { |
| 17 | 20 | |
| 18 | - DEVICE(1), // 设备触发 | |
| 19 | - TIMER(2); // 定时触发 | |
| 21 | + @Deprecated | |
| 22 | + DEVICE(1), // 设备触发 // TODO @puhui999:@芋艿:这个可以作废 | |
| 23 | + | |
| 24 | + // TODO @芋艿:后续“对应”部分,要 @下,等包结构梳理完; | |
| 25 | + /** | |
| 26 | + * 设备上下线变更 | |
| 27 | + * | |
| 28 | + * 对应 IotDeviceMessageMethodEnum.STATE_UPDATE | |
| 29 | + */ | |
| 30 | + DEVICE_STATE_UPDATE(1), | |
| 31 | + /** | |
| 32 | + * 物模型属性上报 | |
| 33 | + * | |
| 34 | + * 对应 IotDeviceMessageMethodEnum.DEVICE_PROPERTY_POST | |
| 35 | + */ | |
| 36 | + DEVICE_PROPERTY_POST(2), | |
| 37 | + /** | |
| 38 | + * 设备事件上报 | |
| 39 | + * | |
| 40 | + * 对应 IotDeviceMessageMethodEnum.DEVICE_EVENT_POST | |
| 41 | + */ | |
| 42 | + DEVICE_EVENT_POST(3), | |
| 43 | + /** | |
| 44 | + * 设备服务调用 | |
| 45 | + * | |
| 46 | + * 对应 IotDeviceMessageMethodEnum.DEVICE_SERVICE_INVOKE | |
| 47 | + */ | |
| 48 | + DEVICE_SERVICE_INVOKE(4), | |
| 49 | + | |
| 50 | + TIMER(100) // 定时触发 | |
| 51 | + | |
| 52 | + ; | |
| 20 | 53 | |
| 21 | 54 | private final Integer type; |
| 22 | 55 | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/rule/IotAlertConfig.java renamed to yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/rule/IotAlertConfigDO.java
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/rule/IotAlertRecordDO.java
| ... | ... | @@ -34,13 +34,13 @@ public class IotAlertRecordDO extends BaseDO { |
| 34 | 34 | /** |
| 35 | 35 | * 告警名称 |
| 36 | 36 | * |
| 37 | - * 冗余 {@link IotAlertConfig#getName()} | |
| 37 | + * 冗余 {@link IotAlertConfigDO#getName()} | |
| 38 | 38 | */ |
| 39 | 39 | private Long configId; |
| 40 | 40 | /** |
| 41 | 41 | * 告警名称 |
| 42 | 42 | * |
| 43 | - * 冗余 {@link IotAlertConfig#getName()} | |
| 43 | + * 冗余 {@link IotAlertConfigDO#getName()} | |
| 44 | 44 | */ |
| 45 | 45 | private String name; |
| 46 | 46 | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/rule/IotRuleScene2DO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.iot.dal.dataobject.rule; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.tenant.core.db.TenantBaseDO; | |
| 4 | +import cn.iocoder.yudao.module.iot.core.mq.message.IotDeviceMessage; | |
| 5 | +import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO; | |
| 6 | +import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductDO; | |
| 7 | +import cn.iocoder.yudao.module.iot.dal.dataobject.thingmodel.IotThingModelDO; | |
| 8 | +import cn.iocoder.yudao.module.iot.enums.rule.IotRuleSceneActionTypeEnum; | |
| 9 | +import cn.iocoder.yudao.module.iot.enums.rule.IotRuleSceneConditionOperatorEnum; | |
| 10 | +import cn.iocoder.yudao.module.iot.enums.rule.IotRuleSceneConditionTypeEnum; | |
| 11 | +import cn.iocoder.yudao.module.iot.enums.rule.IotRuleSceneTriggerTypeEnum; | |
| 12 | +import com.baomidou.mybatisplus.annotation.KeySequence; | |
| 13 | +import com.baomidou.mybatisplus.annotation.TableField; | |
| 14 | +import com.baomidou.mybatisplus.annotation.TableId; | |
| 15 | +import com.baomidou.mybatisplus.annotation.TableName; | |
| 16 | +import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler; | |
| 17 | +import lombok.AllArgsConstructor; | |
| 18 | +import lombok.Builder; | |
| 19 | +import lombok.Data; | |
| 20 | +import lombok.NoArgsConstructor; | |
| 21 | + | |
| 22 | +import java.util.List; | |
| 23 | + | |
| 24 | +// TODO @puhui999:还是在 IotRuleSceneDO 里搞,这里主要可以看到变化字段哈。 | |
| 25 | +/** | |
| 26 | + * IoT 场景联动 DO | |
| 27 | + * | |
| 28 | + * @author 芋道源码 | |
| 29 | + */ | |
| 30 | +@TableName(value = "iot_rule_scene2", autoResultMap = true) | |
| 31 | +@KeySequence("iot_rule_scene_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 | |
| 32 | +@Data | |
| 33 | +@Builder | |
| 34 | +@NoArgsConstructor | |
| 35 | +@AllArgsConstructor | |
| 36 | +public class IotRuleScene2DO extends TenantBaseDO { | |
| 37 | + | |
| 38 | + /** | |
| 39 | + * 设备编号 - 全部设备 | |
| 40 | + */ | |
| 41 | + public static final Long DEVICE_ID_ALL = 0L; | |
| 42 | + | |
| 43 | + /** | |
| 44 | + * 场景编号 | |
| 45 | + */ | |
| 46 | + @TableId | |
| 47 | + private Long id; | |
| 48 | + /** | |
| 49 | + * 场景名称 | |
| 50 | + */ | |
| 51 | + private String name; | |
| 52 | + /** | |
| 53 | + * 场景描述 | |
| 54 | + */ | |
| 55 | + private String description; | |
| 56 | + /** | |
| 57 | + * 场景状态 | |
| 58 | + * | |
| 59 | + * 枚举 {@link cn.iocoder.yudao.framework.common.enums.CommonStatusEnum} | |
| 60 | + */ | |
| 61 | + private Integer status; | |
| 62 | + | |
| 63 | + /** | |
| 64 | + * 场景定义配置 | |
| 65 | + */ | |
| 66 | + @TableField(typeHandler = JacksonTypeHandler.class) | |
| 67 | + private List<Trigger> triggers; | |
| 68 | + | |
| 69 | + /** | |
| 70 | + * 场景动作配置 | |
| 71 | + */ | |
| 72 | + @TableField(typeHandler = JacksonTypeHandler.class) | |
| 73 | + private List<Action> actions; | |
| 74 | + | |
| 75 | + /** | |
| 76 | + * 场景定义配置 | |
| 77 | + */ | |
| 78 | + @Data | |
| 79 | + public static class Trigger { | |
| 80 | + | |
| 81 | + // ========== 事件部分 ========== | |
| 82 | + | |
| 83 | + /** | |
| 84 | + * 场景事件类型 | |
| 85 | + * | |
| 86 | + * 枚举 {@link IotRuleSceneTriggerTypeEnum} | |
| 87 | + * 1. {@link IotRuleSceneTriggerTypeEnum#DEVICE_STATE_UPDATE} 时,operator 非空,并且 value 为在线状态 | |
| 88 | + * 2. {@link IotRuleSceneTriggerTypeEnum#DEVICE_PROPERTY_POST} | |
| 89 | + * {@link IotRuleSceneTriggerTypeEnum#DEVICE_EVENT_POST} 时,identifier、operator 非空,并且 value 为属性值 | |
| 90 | + * 3. {@link IotRuleSceneTriggerTypeEnum#DEVICE_EVENT_POST} | |
| 91 | + * {@link IotRuleSceneTriggerTypeEnum#DEVICE_SERVICE_INVOKE} 时,identifier 非空,但是 operator、value 为空 | |
| 92 | + * 4. {@link IotRuleSceneTriggerTypeEnum#TIMER} 时,conditions 非空,并且设备无关(无需 productId、deviceId 字段) | |
| 93 | + */ | |
| 94 | + private Integer type; | |
| 95 | + | |
| 96 | + /** | |
| 97 | + * 产品编号 | |
| 98 | + * | |
| 99 | + * 关联 {@link IotProductDO#getId()} | |
| 100 | + */ | |
| 101 | + private Long productId; | |
| 102 | + /** | |
| 103 | + * 设备编号 | |
| 104 | + * | |
| 105 | + * 关联 {@link IotDeviceDO#getId()} | |
| 106 | + * 特殊:如果为 0,则是全部 | |
| 107 | + */ | |
| 108 | + private Long deviceId; | |
| 109 | + /** | |
| 110 | + * 物模型标识符 | |
| 111 | + * | |
| 112 | + * 对应:{@link IotThingModelDO#getIdentifier()} | |
| 113 | + */ | |
| 114 | + private String identifier; | |
| 115 | + /** | |
| 116 | + * 操作符 | |
| 117 | + * | |
| 118 | + * 枚举 {@link IotRuleSceneConditionOperatorEnum} | |
| 119 | + */ | |
| 120 | + private String operator; | |
| 121 | + /** | |
| 122 | + * 参数(属性值、在线状态) | |
| 123 | + * | |
| 124 | + * 如果有多个值,则使用 "," 分隔,类似 "1,2,3"。 | |
| 125 | + * 例如说,{@link IotRuleSceneConditionOperatorEnum#IN}、{@link IotRuleSceneConditionOperatorEnum#BETWEEN} | |
| 126 | + */ | |
| 127 | + private String value; | |
| 128 | + | |
| 129 | + /** | |
| 130 | + * CRON 表达式 | |
| 131 | + */ | |
| 132 | + private String cronExpression; | |
| 133 | + | |
| 134 | + // ========== 条件部分 ========== | |
| 135 | + | |
| 136 | + /** | |
| 137 | + * 触发条件分组(状态条件分组)的数组 | |
| 138 | + * | |
| 139 | + * 第一层 List:分组与分组之间,是“或”的关系 | |
| 140 | + * 第二层 List:条件与条件之间,是“且”的关系 | |
| 141 | + */ | |
| 142 | + private List<List<TriggerCondition>> conditionGroups; | |
| 143 | + | |
| 144 | + } | |
| 145 | + | |
| 146 | + /** | |
| 147 | + * 触发条件(状态条件) | |
| 148 | + */ | |
| 149 | + @Data | |
| 150 | + public static class TriggerCondition { | |
| 151 | + | |
| 152 | + /** | |
| 153 | + * 触发条件类型 | |
| 154 | + * | |
| 155 | + * 枚举 {@link IotRuleSceneConditionTypeEnum} | |
| 156 | + * 1. {@link IotRuleSceneConditionTypeEnum#DEVICE_STATE} 时,operator 非空,并且 value 为在线状态 | |
| 157 | + * 2. {@link IotRuleSceneConditionTypeEnum#DEVICE_PROPERTY} 时,identifier、operator 非空,并且 value 为属性值 | |
| 158 | + * 3. {@link IotRuleSceneConditionTypeEnum#CURRENT_TIME} 时,operator 非空(使用 DATE_TIME_ 和 TIME_ 部分),并且 value 非空 | |
| 159 | + */ | |
| 160 | + private Integer type; | |
| 161 | + | |
| 162 | + /** | |
| 163 | + * 产品编号 | |
| 164 | + * | |
| 165 | + * 关联 {@link IotProductDO#getId()} | |
| 166 | + */ | |
| 167 | + private Long productId; | |
| 168 | + /** | |
| 169 | + * 设备编号 | |
| 170 | + * | |
| 171 | + * 关联 {@link IotDeviceDO#getId()} | |
| 172 | + */ | |
| 173 | + private Long deviceId; | |
| 174 | + /** | |
| 175 | + * 标识符(属性) | |
| 176 | + * | |
| 177 | + * 关联 {@link IotThingModelDO#getIdentifier()} | |
| 178 | + */ | |
| 179 | + private String identifier; | |
| 180 | + /** | |
| 181 | + * 操作符 | |
| 182 | + * | |
| 183 | + * 枚举 {@link IotRuleSceneConditionOperatorEnum} | |
| 184 | + */ | |
| 185 | + private String operator; | |
| 186 | + /** | |
| 187 | + * 参数 | |
| 188 | + * | |
| 189 | + * 如果有多个值,则使用 "," 分隔,类似 "1,2,3"。 | |
| 190 | + * 例如说,{@link IotRuleSceneConditionOperatorEnum#IN}、{@link IotRuleSceneConditionOperatorEnum#BETWEEN} | |
| 191 | + */ | |
| 192 | + private String param; | |
| 193 | + | |
| 194 | + } | |
| 195 | + | |
| 196 | + /** | |
| 197 | + * 场景动作配置 | |
| 198 | + */ | |
| 199 | + @Data | |
| 200 | + public static class Action { | |
| 201 | + | |
| 202 | + /** | |
| 203 | + * 执行类型 | |
| 204 | + * | |
| 205 | + * 枚举 {@link IotRuleSceneActionTypeEnum} | |
| 206 | + * 1. {@link IotRuleSceneActionTypeEnum#DEVICE_PROPERTY_SET} 时,params 非空 | |
| 207 | + * {@link IotRuleSceneActionTypeEnum#DEVICE_SERVICE_INVOKE} 时,params 非空 | |
| 208 | + * 2. {@link IotRuleSceneActionTypeEnum#ALERT_TRIGGER} 时,alertConfigId 为空,因为是 {@link IotAlertConfigDO} 里面关联它 | |
| 209 | + * 3. {@link IotRuleSceneActionTypeEnum#ALERT_RECOVER} 时,alertConfigId 非空 | |
| 210 | + */ | |
| 211 | + private Integer type; | |
| 212 | + | |
| 213 | + /** | |
| 214 | + * 产品编号 | |
| 215 | + * | |
| 216 | + * 关联 {@link IotProductDO#getId()} | |
| 217 | + */ | |
| 218 | + private Long productId; | |
| 219 | + /** | |
| 220 | + * 设备编号 | |
| 221 | + * | |
| 222 | + * 关联 {@link IotDeviceDO#getId()} | |
| 223 | + */ | |
| 224 | + private Long deviceId; | |
| 225 | + /** | |
| 226 | + * 请求参数 | |
| 227 | + * | |
| 228 | + * 一般来说,对应 {@link IotDeviceMessage#getParams()} 请求参数 | |
| 229 | + */ | |
| 230 | + private Object params; | |
| 231 | + | |
| 232 | + /** | |
| 233 | + * 告警配置编号 | |
| 234 | + * | |
| 235 | + * 关联 {@link IotAlertConfigDO#getId()} | |
| 236 | + */ | |
| 237 | + private Long alertConfigId; | |
| 238 | + | |
| 239 | + } | |
| 240 | + | |
| 241 | +} | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/rule/IotRuleSceneDO.java
| ... | ... | @@ -7,7 +7,7 @@ import cn.iocoder.yudao.module.iot.dal.dataobject.thingmodel.IotThingModelDO; |
| 7 | 7 | import cn.iocoder.yudao.module.iot.enums.device.IotDeviceMessageIdentifierEnum; |
| 8 | 8 | import cn.iocoder.yudao.module.iot.enums.device.IotDeviceMessageTypeEnum; |
| 9 | 9 | import cn.iocoder.yudao.module.iot.enums.rule.IotRuleSceneActionTypeEnum; |
| 10 | -import cn.iocoder.yudao.module.iot.enums.rule.IotRuleSceneTriggerConditionParameterOperatorEnum; | |
| 10 | +import cn.iocoder.yudao.module.iot.enums.rule.IotRuleSceneConditionOperatorEnum; | |
| 11 | 11 | import cn.iocoder.yudao.module.iot.enums.rule.IotRuleSceneTriggerTypeEnum; |
| 12 | 12 | import com.baomidou.mybatisplus.annotation.KeySequence; |
| 13 | 13 | import com.baomidou.mybatisplus.annotation.TableField; |
| ... | ... | @@ -163,7 +163,7 @@ public class IotRuleSceneDO extends TenantBaseDO { |
| 163 | 163 | /** |
| 164 | 164 | * 操作符 |
| 165 | 165 | * |
| 166 | - * 枚举 {@link IotRuleSceneTriggerConditionParameterOperatorEnum} | |
| 166 | + * 枚举 {@link IotRuleSceneConditionOperatorEnum} | |
| 167 | 167 | */ |
| 168 | 168 | private String operator; |
| 169 | 169 | |
| ... | ... | @@ -171,7 +171,7 @@ public class IotRuleSceneDO extends TenantBaseDO { |
| 171 | 171 | * 比较值 |
| 172 | 172 | * |
| 173 | 173 | * 如果有多个值,则使用 "," 分隔,类似 "1,2,3"。 |
| 174 | - * 例如说,{@link IotRuleSceneTriggerConditionParameterOperatorEnum#IN}、{@link IotRuleSceneTriggerConditionParameterOperatorEnum#BETWEEN} | |
| 174 | + * 例如说,{@link IotRuleSceneConditionOperatorEnum#IN}、{@link IotRuleSceneConditionOperatorEnum#BETWEEN} | |
| 175 | 175 | */ |
| 176 | 176 | private String value; |
| 177 | 177 | |
| ... | ... | @@ -193,7 +193,7 @@ public class IotRuleSceneDO extends TenantBaseDO { |
| 193 | 193 | /** |
| 194 | 194 | * 设备控制 |
| 195 | 195 | * |
| 196 | - * 必填:当 {@link #type} 为 {@link IotRuleSceneActionTypeEnum#DEVICE_CONTROL} 时 | |
| 196 | + * 必填:当 {@link #type} 为 {@link IotRuleSceneActionTypeEnum#DEVICE_PROPERTY_SET} 时 | |
| 197 | 197 | */ |
| 198 | 198 | private ActionDeviceControl deviceControl; |
| 199 | 199 | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/IotRuleSceneServiceImpl.java
| ... | ... | @@ -23,7 +23,7 @@ import cn.iocoder.yudao.module.iot.dal.mysql.rule.IotRuleSceneMapper; |
| 23 | 23 | import cn.iocoder.yudao.module.iot.enums.device.IotDeviceMessageIdentifierEnum; |
| 24 | 24 | import cn.iocoder.yudao.module.iot.enums.device.IotDeviceMessageTypeEnum; |
| 25 | 25 | import cn.iocoder.yudao.module.iot.enums.rule.IotRuleSceneActionTypeEnum; |
| 26 | -import cn.iocoder.yudao.module.iot.enums.rule.IotRuleSceneTriggerConditionParameterOperatorEnum; | |
| 26 | +import cn.iocoder.yudao.module.iot.enums.rule.IotRuleSceneConditionOperatorEnum; | |
| 27 | 27 | import cn.iocoder.yudao.module.iot.enums.rule.IotRuleSceneTriggerTypeEnum; |
| 28 | 28 | import cn.iocoder.yudao.module.iot.framework.job.core.IotSchedulerManager; |
| 29 | 29 | import cn.iocoder.yudao.module.iot.job.rule.IotRuleSceneJob; |
| ... | ... | @@ -127,57 +127,57 @@ public class IotRuleSceneServiceImpl implements IotRuleSceneService { |
| 127 | 127 | condition01.setParameters(CollUtil.newArrayList()); |
| 128 | 128 | // IotRuleSceneDO.TriggerConditionParameter parameter010 = new IotRuleSceneDO.TriggerConditionParameter(); |
| 129 | 129 | // parameter010.setIdentifier("width"); |
| 130 | -// parameter010.setOperator(IotRuleSceneTriggerConditionParameterOperatorEnum.EQUALS.getOperator()); | |
| 130 | +// parameter010.setOperator(IotRuleSceneConditionOperatorEnum.EQUALS.getOperator()); | |
| 131 | 131 | // parameter010.setValue("abc"); |
| 132 | 132 | // condition01.getParameters().add(parameter010); |
| 133 | 133 | IotRuleSceneDO.TriggerConditionParameter parameter011 = new IotRuleSceneDO.TriggerConditionParameter(); |
| 134 | 134 | parameter011.setIdentifier("width"); |
| 135 | - parameter011.setOperator(IotRuleSceneTriggerConditionParameterOperatorEnum.EQUALS.getOperator()); | |
| 135 | + parameter011.setOperator(IotRuleSceneConditionOperatorEnum.EQUALS.getOperator()); | |
| 136 | 136 | parameter011.setValue("1"); |
| 137 | 137 | condition01.getParameters().add(parameter011); |
| 138 | 138 | IotRuleSceneDO.TriggerConditionParameter parameter012 = new IotRuleSceneDO.TriggerConditionParameter(); |
| 139 | 139 | parameter012.setIdentifier("width"); |
| 140 | - parameter012.setOperator(IotRuleSceneTriggerConditionParameterOperatorEnum.NOT_EQUALS.getOperator()); | |
| 140 | + parameter012.setOperator(IotRuleSceneConditionOperatorEnum.NOT_EQUALS.getOperator()); | |
| 141 | 141 | parameter012.setValue("2"); |
| 142 | 142 | condition01.getParameters().add(parameter012); |
| 143 | 143 | IotRuleSceneDO.TriggerConditionParameter parameter013 = new IotRuleSceneDO.TriggerConditionParameter(); |
| 144 | 144 | parameter013.setIdentifier("width"); |
| 145 | - parameter013.setOperator(IotRuleSceneTriggerConditionParameterOperatorEnum.GREATER_THAN.getOperator()); | |
| 145 | + parameter013.setOperator(IotRuleSceneConditionOperatorEnum.GREATER_THAN.getOperator()); | |
| 146 | 146 | parameter013.setValue("0"); |
| 147 | 147 | condition01.getParameters().add(parameter013); |
| 148 | 148 | IotRuleSceneDO.TriggerConditionParameter parameter014 = new IotRuleSceneDO.TriggerConditionParameter(); |
| 149 | 149 | parameter014.setIdentifier("width"); |
| 150 | - parameter014.setOperator(IotRuleSceneTriggerConditionParameterOperatorEnum.GREATER_THAN_OR_EQUALS.getOperator()); | |
| 150 | + parameter014.setOperator(IotRuleSceneConditionOperatorEnum.GREATER_THAN_OR_EQUALS.getOperator()); | |
| 151 | 151 | parameter014.setValue("0"); |
| 152 | 152 | condition01.getParameters().add(parameter014); |
| 153 | 153 | IotRuleSceneDO.TriggerConditionParameter parameter015 = new IotRuleSceneDO.TriggerConditionParameter(); |
| 154 | 154 | parameter015.setIdentifier("width"); |
| 155 | - parameter015.setOperator(IotRuleSceneTriggerConditionParameterOperatorEnum.LESS_THAN.getOperator()); | |
| 155 | + parameter015.setOperator(IotRuleSceneConditionOperatorEnum.LESS_THAN.getOperator()); | |
| 156 | 156 | parameter015.setValue("2"); |
| 157 | 157 | condition01.getParameters().add(parameter015); |
| 158 | 158 | IotRuleSceneDO.TriggerConditionParameter parameter016 = new IotRuleSceneDO.TriggerConditionParameter(); |
| 159 | 159 | parameter016.setIdentifier("width"); |
| 160 | - parameter016.setOperator(IotRuleSceneTriggerConditionParameterOperatorEnum.LESS_THAN_OR_EQUALS.getOperator()); | |
| 160 | + parameter016.setOperator(IotRuleSceneConditionOperatorEnum.LESS_THAN_OR_EQUALS.getOperator()); | |
| 161 | 161 | parameter016.setValue("2"); |
| 162 | 162 | condition01.getParameters().add(parameter016); |
| 163 | 163 | IotRuleSceneDO.TriggerConditionParameter parameter017 = new IotRuleSceneDO.TriggerConditionParameter(); |
| 164 | 164 | parameter017.setIdentifier("width"); |
| 165 | - parameter017.setOperator(IotRuleSceneTriggerConditionParameterOperatorEnum.IN.getOperator()); | |
| 165 | + parameter017.setOperator(IotRuleSceneConditionOperatorEnum.IN.getOperator()); | |
| 166 | 166 | parameter017.setValue("1,2,3"); |
| 167 | 167 | condition01.getParameters().add(parameter017); |
| 168 | 168 | IotRuleSceneDO.TriggerConditionParameter parameter018 = new IotRuleSceneDO.TriggerConditionParameter(); |
| 169 | 169 | parameter018.setIdentifier("width"); |
| 170 | - parameter018.setOperator(IotRuleSceneTriggerConditionParameterOperatorEnum.NOT_IN.getOperator()); | |
| 170 | + parameter018.setOperator(IotRuleSceneConditionOperatorEnum.NOT_IN.getOperator()); | |
| 171 | 171 | parameter018.setValue("0,2,3"); |
| 172 | 172 | condition01.getParameters().add(parameter018); |
| 173 | 173 | IotRuleSceneDO.TriggerConditionParameter parameter019 = new IotRuleSceneDO.TriggerConditionParameter(); |
| 174 | 174 | parameter019.setIdentifier("width"); |
| 175 | - parameter019.setOperator(IotRuleSceneTriggerConditionParameterOperatorEnum.BETWEEN.getOperator()); | |
| 175 | + parameter019.setOperator(IotRuleSceneConditionOperatorEnum.BETWEEN.getOperator()); | |
| 176 | 176 | parameter019.setValue("1,3"); |
| 177 | 177 | condition01.getParameters().add(parameter019); |
| 178 | 178 | IotRuleSceneDO.TriggerConditionParameter parameter020 = new IotRuleSceneDO.TriggerConditionParameter(); |
| 179 | 179 | parameter020.setIdentifier("width"); |
| 180 | - parameter020.setOperator(IotRuleSceneTriggerConditionParameterOperatorEnum.NOT_BETWEEN.getOperator()); | |
| 180 | + parameter020.setOperator(IotRuleSceneConditionOperatorEnum.NOT_BETWEEN.getOperator()); | |
| 181 | 181 | parameter020.setValue("2,3"); |
| 182 | 182 | condition01.getParameters().add(parameter020); |
| 183 | 183 | trigger01.getConditions().add(condition01); |
| ... | ... | @@ -194,7 +194,7 @@ public class IotRuleSceneServiceImpl implements IotRuleSceneService { |
| 194 | 194 | condition03.setParameters(CollUtil.newArrayList()); |
| 195 | 195 | IotRuleSceneDO.TriggerConditionParameter parameter030 = new IotRuleSceneDO.TriggerConditionParameter(); |
| 196 | 196 | parameter030.setIdentifier("width"); |
| 197 | - parameter030.setOperator(IotRuleSceneTriggerConditionParameterOperatorEnum.EQUALS.getOperator()); | |
| 197 | + parameter030.setOperator(IotRuleSceneConditionOperatorEnum.EQUALS.getOperator()); | |
| 198 | 198 | parameter030.setValue("1"); |
| 199 | 199 | trigger01.getConditions().add(condition03); |
| 200 | 200 | ruleScene01.getTriggers().add(trigger01); |
| ... | ... | @@ -202,7 +202,7 @@ public class IotRuleSceneServiceImpl implements IotRuleSceneService { |
| 202 | 202 | ruleScene01.setActions(CollUtil.newArrayList()); |
| 203 | 203 | // 设备控制 |
| 204 | 204 | IotRuleSceneDO.ActionConfig action01 = new IotRuleSceneDO.ActionConfig(); |
| 205 | - action01.setType(IotRuleSceneActionTypeEnum.DEVICE_CONTROL.getType()); | |
| 205 | + action01.setType(IotRuleSceneActionTypeEnum.DEVICE_PROPERTY_SET.getType()); | |
| 206 | 206 | IotRuleSceneDO.ActionDeviceControl actionDeviceControl01 = new IotRuleSceneDO.ActionDeviceControl(); |
| 207 | 207 | actionDeviceControl01.setProductKey("4aymZgOTOOCrDKRT"); |
| 208 | 208 | actionDeviceControl01.setDeviceNames(ListUtil.of("small")); |
| ... | ... | @@ -266,7 +266,7 @@ public class IotRuleSceneServiceImpl implements IotRuleSceneService { |
| 266 | 266 | scene.setTriggers(ListUtil.toList(triggerConfig)); |
| 267 | 267 | // 动作 |
| 268 | 268 | IotRuleSceneDO.ActionConfig action01 = new IotRuleSceneDO.ActionConfig(); |
| 269 | - action01.setType(IotRuleSceneActionTypeEnum.DEVICE_CONTROL.getType()); | |
| 269 | + action01.setType(IotRuleSceneActionTypeEnum.DEVICE_PROPERTY_SET.getType()); | |
| 270 | 270 | IotRuleSceneDO.ActionDeviceControl iotRuleSceneActionDeviceControl01 = new IotRuleSceneDO.ActionDeviceControl(); |
| 271 | 271 | iotRuleSceneActionDeviceControl01.setProductKey("4aymZgOTOOCrDKRT"); |
| 272 | 272 | iotRuleSceneActionDeviceControl01.setDeviceNames(ListUtil.of("small")); |
| ... | ... | @@ -366,8 +366,8 @@ public class IotRuleSceneServiceImpl implements IotRuleSceneService { |
| 366 | 366 | private boolean isTriggerConditionParameterMatched(IotDeviceMessage message, IotRuleSceneDO.TriggerConditionParameter parameter, |
| 367 | 367 | IotRuleSceneDO ruleScene, IotRuleSceneDO.TriggerConfig trigger) { |
| 368 | 368 | // 1.1 校验操作符是否合法 |
| 369 | - IotRuleSceneTriggerConditionParameterOperatorEnum operator = | |
| 370 | - IotRuleSceneTriggerConditionParameterOperatorEnum.operatorOf(parameter.getOperator()); | |
| 369 | + IotRuleSceneConditionOperatorEnum operator = | |
| 370 | + IotRuleSceneConditionOperatorEnum.operatorOf(parameter.getOperator()); | |
| 371 | 371 | if (operator == null) { |
| 372 | 372 | log.error("[isTriggerConditionParameterMatched][规则场景编号({}) 的触发器({}) 存在错误的操作符({})]", |
| 373 | 373 | ruleScene.getId(), trigger, parameter.getOperator()); |
| ... | ... | @@ -382,24 +382,24 @@ public class IotRuleSceneServiceImpl implements IotRuleSceneService { |
| 382 | 382 | // 2.1 构建 Spring 表达式的变量 |
| 383 | 383 | Map<String, Object> springExpressionVariables = new HashMap<>(); |
| 384 | 384 | try { |
| 385 | - springExpressionVariables.put(IotRuleSceneTriggerConditionParameterOperatorEnum.SPRING_EXPRESSION_SOURCE, messageValue); | |
| 386 | - springExpressionVariables.put(IotRuleSceneTriggerConditionParameterOperatorEnum.SPRING_EXPRESSION_VALUE, parameter.getValue()); | |
| 385 | + springExpressionVariables.put(IotRuleSceneConditionOperatorEnum.SPRING_EXPRESSION_SOURCE, messageValue); | |
| 386 | + springExpressionVariables.put(IotRuleSceneConditionOperatorEnum.SPRING_EXPRESSION_VALUE, parameter.getValue()); | |
| 387 | 387 | List<String> parameterValues = StrUtil.splitTrim(parameter.getValue(), CharPool.COMMA); |
| 388 | - springExpressionVariables.put(IotRuleSceneTriggerConditionParameterOperatorEnum.SPRING_EXPRESSION_VALUE_LIST, parameterValues); | |
| 388 | + springExpressionVariables.put(IotRuleSceneConditionOperatorEnum.SPRING_EXPRESSION_VALUE_LIST, parameterValues); | |
| 389 | 389 | // 特殊:解决数字的比较。因为 Spring 是基于它的 compareTo 方法,对数字的比较存在问题! |
| 390 | - if (ObjectUtils.equalsAny(operator, IotRuleSceneTriggerConditionParameterOperatorEnum.BETWEEN, | |
| 391 | - IotRuleSceneTriggerConditionParameterOperatorEnum.NOT_BETWEEN, | |
| 392 | - IotRuleSceneTriggerConditionParameterOperatorEnum.GREATER_THAN, | |
| 393 | - IotRuleSceneTriggerConditionParameterOperatorEnum.GREATER_THAN_OR_EQUALS, | |
| 394 | - IotRuleSceneTriggerConditionParameterOperatorEnum.LESS_THAN, | |
| 395 | - IotRuleSceneTriggerConditionParameterOperatorEnum.LESS_THAN_OR_EQUALS) | |
| 390 | + if (ObjectUtils.equalsAny(operator, IotRuleSceneConditionOperatorEnum.BETWEEN, | |
| 391 | + IotRuleSceneConditionOperatorEnum.NOT_BETWEEN, | |
| 392 | + IotRuleSceneConditionOperatorEnum.GREATER_THAN, | |
| 393 | + IotRuleSceneConditionOperatorEnum.GREATER_THAN_OR_EQUALS, | |
| 394 | + IotRuleSceneConditionOperatorEnum.LESS_THAN, | |
| 395 | + IotRuleSceneConditionOperatorEnum.LESS_THAN_OR_EQUALS) | |
| 396 | 396 | && NumberUtil.isNumber(messageValue) |
| 397 | 397 | && NumberUtils.isAllNumber(parameterValues)) { |
| 398 | - springExpressionVariables.put(IotRuleSceneTriggerConditionParameterOperatorEnum.SPRING_EXPRESSION_SOURCE, | |
| 398 | + springExpressionVariables.put(IotRuleSceneConditionOperatorEnum.SPRING_EXPRESSION_SOURCE, | |
| 399 | 399 | NumberUtil.parseDouble(messageValue)); |
| 400 | - springExpressionVariables.put(IotRuleSceneTriggerConditionParameterOperatorEnum.SPRING_EXPRESSION_VALUE, | |
| 400 | + springExpressionVariables.put(IotRuleSceneConditionOperatorEnum.SPRING_EXPRESSION_VALUE, | |
| 401 | 401 | NumberUtil.parseDouble(parameter.getValue())); |
| 402 | - springExpressionVariables.put(IotRuleSceneTriggerConditionParameterOperatorEnum.SPRING_EXPRESSION_VALUE_LIST, | |
| 402 | + springExpressionVariables.put(IotRuleSceneConditionOperatorEnum.SPRING_EXPRESSION_VALUE_LIST, | |
| 403 | 403 | convertList(parameterValues, NumberUtil::parseDouble)); |
| 404 | 404 | } |
| 405 | 405 | // 2.2 计算 Spring 表达式 | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/action/IotRuleSceneDeviceControlAction.java
| ... | ... | @@ -49,7 +49,7 @@ public class IotRuleSceneDeviceControlAction implements IotRuleSceneAction { |
| 49 | 49 | |
| 50 | 50 | @Override |
| 51 | 51 | public IotRuleSceneActionTypeEnum getType() { |
| 52 | - return IotRuleSceneActionTypeEnum.DEVICE_CONTROL; | |
| 52 | + return IotRuleSceneActionTypeEnum.DEVICE_PROPERTY_SET; | |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | } | ... | ... |
yudao-module-iot/yudao-module-iot-core/src/main/java/cn/iocoder/yudao/module/iot/core/enums/IotDeviceMessageMethodEnum.java
| ... | ... | @@ -19,9 +19,12 @@ public enum IotDeviceMessageMethodEnum implements ArrayValuable<String> { |
| 19 | 19 | |
| 20 | 20 | // ========== 设备状态 ========== |
| 21 | 21 | |
| 22 | + // TODO @芋艿:要合并下;thing.state.update | |
| 22 | 23 | STATE_ONLINE("thing.state.online", "设备上线", true), |
| 23 | 24 | STATE_OFFLINE("thing.state.offline", "设备下线", true), |
| 24 | 25 | |
| 26 | + STATE_UPDATE("thing.state.update", "设备状态更新", true), | |
| 27 | + | |
| 25 | 28 | // ========== 设备属性 ========== |
| 26 | 29 | // 可参考:https://help.aliyun.com/zh/iot/user-guide/device-properties-events-and-services |
| 27 | 30 | ... | ... |