Commit f118d66006d7e9f1ac7ef39177022692b19612bd
1 parent
6d6547be
【代码优化】IoT: 规则场景 config 抽离
Showing
13 changed files
with
298 additions
and
246 deletions
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/vo/scene/IotRuleSceneRespVO.java
| 1 | 1 | package cn.iocoder.yudao.module.iot.controller.admin.rule.vo.scene; |
| 2 | 2 | |
| 3 | +import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.scene.config.IotRuleSceneActionConfig; | |
| 4 | +import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.scene.config.IotRuleSceneTriggerConfig; | |
| 3 | 5 | import io.swagger.v3.oas.annotations.media.Schema; |
| 4 | 6 | import lombok.Data; |
| 5 | 7 | |
| 6 | 8 | import java.time.LocalDateTime; |
| 9 | +import java.util.List; | |
| 7 | 10 | |
| 8 | 11 | @Schema(description = "管理后台 - IoT 规则场景(场景联动) Response VO") |
| 9 | 12 | @Data |
| ... | ... | @@ -22,10 +25,10 @@ public class IotRuleSceneRespVO { |
| 22 | 25 | private Integer status; |
| 23 | 26 | |
| 24 | 27 | @Schema(description = "触发器数组", requiredMode = Schema.RequiredMode.REQUIRED) |
| 25 | - private String triggers; | |
| 28 | + private List<IotRuleSceneTriggerConfig> triggers; | |
| 26 | 29 | |
| 27 | 30 | @Schema(description = "执行器数组", requiredMode = Schema.RequiredMode.REQUIRED) |
| 28 | - private String actions; | |
| 31 | + private List<IotRuleSceneActionConfig> actions; | |
| 29 | 32 | |
| 30 | 33 | @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) |
| 31 | 34 | private LocalDateTime createTime; | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/vo/scene/IotRuleSceneSaveReqVO.java
| ... | ... | @@ -2,11 +2,15 @@ package cn.iocoder.yudao.module.iot.controller.admin.rule.vo.scene; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 4 | 4 | import cn.iocoder.yudao.framework.common.validation.InEnum; |
| 5 | +import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.scene.config.IotRuleSceneActionConfig; | |
| 6 | +import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.scene.config.IotRuleSceneTriggerConfig; | |
| 5 | 7 | import io.swagger.v3.oas.annotations.media.Schema; |
| 6 | 8 | import jakarta.validation.constraints.NotEmpty; |
| 7 | 9 | import jakarta.validation.constraints.NotNull; |
| 8 | 10 | import lombok.Data; |
| 9 | 11 | |
| 12 | +import java.util.List; | |
| 13 | + | |
| 10 | 14 | @Schema(description = "管理后台 - IoT 规则场景(场景联动)新增/修改 Request VO") |
| 11 | 15 | @Data |
| 12 | 16 | public class IotRuleSceneSaveReqVO { |
| ... | ... | @@ -28,10 +32,10 @@ public class IotRuleSceneSaveReqVO { |
| 28 | 32 | |
| 29 | 33 | @Schema(description = "触发器数组", requiredMode = Schema.RequiredMode.REQUIRED) |
| 30 | 34 | @NotEmpty(message = "触发器数组不能为空") |
| 31 | - private String triggers; | |
| 35 | + private List<IotRuleSceneTriggerConfig> triggers; | |
| 32 | 36 | |
| 33 | 37 | @Schema(description = "执行器数组", requiredMode = Schema.RequiredMode.REQUIRED) |
| 34 | 38 | @NotEmpty(message = "执行器数组不能为空") |
| 35 | - private String actions; | |
| 39 | + private List<IotRuleSceneActionConfig> actions; | |
| 36 | 40 | |
| 37 | 41 | } |
| 38 | 42 | \ No newline at end of file | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/vo/scene/config/IotRuleSceneActionConfig.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.iot.controller.admin.rule.vo.scene.config; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotDataBridgeDO; | |
| 4 | +import cn.iocoder.yudao.module.iot.enums.rule.IotRuleSceneActionTypeEnum; | |
| 5 | +import lombok.Data; | |
| 6 | + | |
| 7 | +/** | |
| 8 | + * 执行器配置 | |
| 9 | + * | |
| 10 | + * @author 芋道源码 | |
| 11 | + */ | |
| 12 | +@Data | |
| 13 | +public class IotRuleSceneActionConfig { | |
| 14 | + | |
| 15 | + /** | |
| 16 | + * 执行类型 | |
| 17 | + * | |
| 18 | + * 枚举 {@link IotRuleSceneActionTypeEnum} | |
| 19 | + */ | |
| 20 | + private Integer type; | |
| 21 | + | |
| 22 | + /** | |
| 23 | + * 设备控制 | |
| 24 | + * | |
| 25 | + * 必填:当 {@link #type} 为 {@link IotRuleSceneActionTypeEnum#DEVICE_CONTROL} 时 | |
| 26 | + */ | |
| 27 | + private IotRuleSceneActionDeviceControl deviceControl; | |
| 28 | + | |
| 29 | + /** | |
| 30 | + * 数据桥接编号 | |
| 31 | + * | |
| 32 | + * 必填:当 {@link #type} 为 {@link IotRuleSceneActionTypeEnum#DATA_BRIDGE} 时 | |
| 33 | + * 关联:{@link IotDataBridgeDO#getId()} | |
| 34 | + */ | |
| 35 | + private Long dataBridgeId; | |
| 36 | + | |
| 37 | +} | |
| 0 | 38 | \ No newline at end of file | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/vo/scene/config/IotRuleSceneActionDeviceControl.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.iot.controller.admin.rule.vo.scene.config; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO; | |
| 4 | +import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductDO; | |
| 5 | +import cn.iocoder.yudao.module.iot.enums.device.IotDeviceMessageIdentifierEnum; | |
| 6 | +import cn.iocoder.yudao.module.iot.enums.device.IotDeviceMessageTypeEnum; | |
| 7 | +import lombok.Data; | |
| 8 | + | |
| 9 | +import java.util.List; | |
| 10 | +import java.util.Map; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * 执行设备控制 | |
| 14 | + * | |
| 15 | + * @author 芋道源码 | |
| 16 | + */ | |
| 17 | +@Data | |
| 18 | +public class IotRuleSceneActionDeviceControl { | |
| 19 | + | |
| 20 | + /** | |
| 21 | + * 产品标识 | |
| 22 | + * | |
| 23 | + * 关联 {@link IotProductDO#getProductKey()} | |
| 24 | + */ | |
| 25 | + private String productKey; | |
| 26 | + /** | |
| 27 | + * 设备名称数组 | |
| 28 | + * | |
| 29 | + * 关联 {@link IotDeviceDO#getDeviceName()} | |
| 30 | + */ | |
| 31 | + private List<String> deviceNames; | |
| 32 | + | |
| 33 | + /** | |
| 34 | + * 消息类型 | |
| 35 | + * | |
| 36 | + * 枚举 {@link IotDeviceMessageTypeEnum#PROPERTY}、{@link IotDeviceMessageTypeEnum#SERVICE} | |
| 37 | + */ | |
| 38 | + private String type; | |
| 39 | + /** | |
| 40 | + * 消息标识符 | |
| 41 | + * | |
| 42 | + * 枚举 {@link IotDeviceMessageIdentifierEnum} | |
| 43 | + * | |
| 44 | + * 1. 属性设置:对应 {@link IotDeviceMessageIdentifierEnum#PROPERTY_SET} | |
| 45 | + * 2. 服务调用:对应 {@link IotDeviceMessageIdentifierEnum#SERVICE_INVOKE} | |
| 46 | + */ | |
| 47 | + private String identifier; | |
| 48 | + | |
| 49 | + /** | |
| 50 | + * 具体数据 | |
| 51 | + * | |
| 52 | + * 1. 属性设置:在 {@link #type} 是 {@link IotDeviceMessageTypeEnum#PROPERTY} 时,对应 properties | |
| 53 | + * 2. 服务调用:在 {@link #type} 是 {@link IotDeviceMessageTypeEnum#SERVICE} 时,对应 params | |
| 54 | + */ | |
| 55 | + private Map<String, Object> data; | |
| 56 | + | |
| 57 | +} | |
| 0 | 58 | \ No newline at end of file | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/vo/scene/config/IotRuleSceneTriggerCondition.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.iot.controller.admin.rule.vo.scene.config; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.module.iot.enums.device.IotDeviceMessageIdentifierEnum; | |
| 4 | +import cn.iocoder.yudao.module.iot.enums.device.IotDeviceMessageTypeEnum; | |
| 5 | +import lombok.Data; | |
| 6 | + | |
| 7 | +import java.util.List; | |
| 8 | + | |
| 9 | +/** | |
| 10 | + * 触发条件 | |
| 11 | + * | |
| 12 | + * @author 芋道源码 | |
| 13 | + */ | |
| 14 | +@Data | |
| 15 | +public class IotRuleSceneTriggerCondition { | |
| 16 | + | |
| 17 | + /** | |
| 18 | + * 消息类型 | |
| 19 | + * | |
| 20 | + * 枚举 {@link IotDeviceMessageTypeEnum} | |
| 21 | + */ | |
| 22 | + private String type; | |
| 23 | + /** | |
| 24 | + * 消息标识符 | |
| 25 | + * | |
| 26 | + * 枚举 {@link IotDeviceMessageIdentifierEnum} | |
| 27 | + */ | |
| 28 | + private String identifier; | |
| 29 | + | |
| 30 | + /** | |
| 31 | + * 参数数组 | |
| 32 | + * | |
| 33 | + * 参数与参数之间,是“或”的关系 | |
| 34 | + */ | |
| 35 | + private List<IotRuleSceneTriggerConditionParameter> parameters; | |
| 36 | + | |
| 37 | +} | |
| 0 | 38 | \ No newline at end of file | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/vo/scene/config/IotRuleSceneTriggerConditionParameter.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.iot.controller.admin.rule.vo.scene.config; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.module.iot.dal.dataobject.thingmodel.IotThingModelDO; | |
| 4 | +import cn.iocoder.yudao.module.iot.enums.rule.IotRuleSceneTriggerConditionParameterOperatorEnum; | |
| 5 | +import lombok.Data; | |
| 6 | + | |
| 7 | +/** | |
| 8 | + * 触发条件参数 | |
| 9 | + * | |
| 10 | + * @author 芋道源码 | |
| 11 | + */ | |
| 12 | +@Data | |
| 13 | +public class IotRuleSceneTriggerConditionParameter { | |
| 14 | + | |
| 15 | + /** | |
| 16 | + * 标识符(属性、事件、服务) | |
| 17 | + * | |
| 18 | + * 关联 {@link IotThingModelDO#getIdentifier()} | |
| 19 | + */ | |
| 20 | + private String identifier; | |
| 21 | + | |
| 22 | + /** | |
| 23 | + * 操作符 | |
| 24 | + * | |
| 25 | + * 枚举 {@link IotRuleSceneTriggerConditionParameterOperatorEnum} | |
| 26 | + */ | |
| 27 | + private String operator; | |
| 28 | + | |
| 29 | + /** | |
| 30 | + * 比较值 | |
| 31 | + * | |
| 32 | + * 如果有多个值,则使用 "," 分隔,类似 "1,2,3"。 | |
| 33 | + * 例如说,{@link IotRuleSceneTriggerConditionParameterOperatorEnum#IN}、{@link IotRuleSceneTriggerConditionParameterOperatorEnum#BETWEEN} | |
| 34 | + */ | |
| 35 | + private String value; | |
| 36 | + | |
| 37 | +} | |
| 0 | 38 | \ No newline at end of file | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/vo/scene/config/IotRuleSceneTriggerConfig.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.iot.controller.admin.rule.vo.scene.config; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO; | |
| 4 | +import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductDO; | |
| 5 | +import cn.iocoder.yudao.module.iot.enums.rule.IotRuleSceneTriggerTypeEnum; | |
| 6 | +import lombok.Data; | |
| 7 | + | |
| 8 | +import java.util.List; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * 触发器配置 | |
| 12 | + * | |
| 13 | + * @author 芋道源码 | |
| 14 | + */ | |
| 15 | +@Data | |
| 16 | +public class IotRuleSceneTriggerConfig { | |
| 17 | + | |
| 18 | + /** | |
| 19 | + * 触发类型 | |
| 20 | + * | |
| 21 | + * 枚举 {@link IotRuleSceneTriggerTypeEnum} | |
| 22 | + */ | |
| 23 | + private Integer type; | |
| 24 | + | |
| 25 | + /** | |
| 26 | + * 产品标识 | |
| 27 | + * | |
| 28 | + * 关联 {@link IotProductDO#getProductKey()} | |
| 29 | + */ | |
| 30 | + private String productKey; | |
| 31 | + /** | |
| 32 | + * 设备名称数组 | |
| 33 | + * | |
| 34 | + * 关联 {@link IotDeviceDO#getDeviceName()} | |
| 35 | + */ | |
| 36 | + private List<String> deviceNames; | |
| 37 | + | |
| 38 | + /** | |
| 39 | + * 触发条件数组 | |
| 40 | + * | |
| 41 | + * 必填:当 {@link #type} 为 {@link IotRuleSceneTriggerTypeEnum#DEVICE} 时 | |
| 42 | + * 条件与条件之间,是“或”的关系 | |
| 43 | + */ | |
| 44 | + private List<IotRuleSceneTriggerCondition> conditions; | |
| 45 | + | |
| 46 | + /** | |
| 47 | + * CRON 表达式 | |
| 48 | + * | |
| 49 | + * 必填:当 {@link #type} 为 {@link IotRuleSceneTriggerTypeEnum#TIMER} 时 | |
| 50 | + */ | |
| 51 | + private String cronExpression; | |
| 52 | + | |
| 53 | +} | |
| 0 | 54 | \ No newline at end of file | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/rule/IotRuleSceneDO.java
| 1 | 1 | package cn.iocoder.yudao.module.iot.dal.dataobject.rule; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.tenant.core.db.TenantBaseDO; |
| 4 | -import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO; | |
| 5 | -import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductDO; | |
| 6 | -import cn.iocoder.yudao.module.iot.dal.dataobject.thingmodel.IotThingModelDO; | |
| 7 | -import cn.iocoder.yudao.module.iot.enums.device.IotDeviceMessageIdentifierEnum; | |
| 8 | -import cn.iocoder.yudao.module.iot.enums.device.IotDeviceMessageTypeEnum; | |
| 9 | -import cn.iocoder.yudao.module.iot.enums.rule.IotRuleSceneActionTypeEnum; | |
| 10 | -import cn.iocoder.yudao.module.iot.enums.rule.IotRuleSceneTriggerConditionParameterOperatorEnum; | |
| 11 | -import cn.iocoder.yudao.module.iot.enums.rule.IotRuleSceneTriggerTypeEnum; | |
| 4 | +import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.scene.config.IotRuleSceneActionConfig; | |
| 5 | +import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.scene.config.IotRuleSceneTriggerConfig; | |
| 12 | 6 | import com.baomidou.mybatisplus.annotation.KeySequence; |
| 13 | 7 | import com.baomidou.mybatisplus.annotation.TableField; |
| 14 | 8 | import com.baomidou.mybatisplus.annotation.TableId; |
| 15 | 9 | import com.baomidou.mybatisplus.annotation.TableName; |
| 16 | 10 | import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler; |
| 17 | -import lombok.*; | |
| 11 | +import lombok.AllArgsConstructor; | |
| 12 | +import lombok.Builder; | |
| 13 | +import lombok.Data; | |
| 14 | +import lombok.NoArgsConstructor; | |
| 18 | 15 | |
| 19 | 16 | import java.util.List; |
| 20 | -import java.util.Map; | |
| 21 | 17 | |
| 22 | 18 | /** |
| 23 | 19 | * IoT 规则场景(场景联动) DO |
| ... | ... | @@ -56,188 +52,12 @@ public class IotRuleSceneDO extends TenantBaseDO { |
| 56 | 52 | * 触发器数组 |
| 57 | 53 | */ |
| 58 | 54 | @TableField(typeHandler = JacksonTypeHandler.class) |
| 59 | - private List<TriggerConfig> triggers; | |
| 55 | + private List<IotRuleSceneTriggerConfig> triggers; | |
| 60 | 56 | |
| 61 | 57 | /** |
| 62 | 58 | * 执行器数组 |
| 63 | 59 | */ |
| 64 | 60 | @TableField(typeHandler = JacksonTypeHandler.class) |
| 65 | - private List<ActionConfig> actions; | |
| 66 | - | |
| 67 | - /** | |
| 68 | - * 触发器配置 | |
| 69 | - */ | |
| 70 | - @Data | |
| 71 | - public static class TriggerConfig { | |
| 72 | - | |
| 73 | - /** | |
| 74 | - * 触发类型 | |
| 75 | - * | |
| 76 | - * 枚举 {@link IotRuleSceneTriggerTypeEnum} | |
| 77 | - */ | |
| 78 | - private Integer type; | |
| 79 | - | |
| 80 | - /** | |
| 81 | - * 产品标识 | |
| 82 | - * | |
| 83 | - * 关联 {@link IotProductDO#getProductKey()} | |
| 84 | - */ | |
| 85 | - private String productKey; | |
| 86 | - /** | |
| 87 | - * 设备名称数组 | |
| 88 | - * | |
| 89 | - * 关联 {@link IotDeviceDO#getDeviceName()} | |
| 90 | - */ | |
| 91 | - private List<String> deviceNames; | |
| 92 | - | |
| 93 | - /** | |
| 94 | - * 触发条件数组 | |
| 95 | - * | |
| 96 | - * 必填:当 {@link #type} 为 {@link IotRuleSceneTriggerTypeEnum#DEVICE} 时 | |
| 97 | - * 条件与条件之间,是“或”的关系 | |
| 98 | - */ | |
| 99 | - private List<TriggerCondition> conditions; | |
| 100 | - | |
| 101 | - /** | |
| 102 | - * CRON 表达式 | |
| 103 | - * | |
| 104 | - * 必填:当 {@link #type} 为 {@link IotRuleSceneTriggerTypeEnum#TIMER} 时 | |
| 105 | - */ | |
| 106 | - private String cronExpression; | |
| 107 | - | |
| 108 | - } | |
| 109 | - | |
| 110 | - /** | |
| 111 | - * 触发条件 | |
| 112 | - */ | |
| 113 | - @Data | |
| 114 | - public static class TriggerCondition { | |
| 115 | - | |
| 116 | - /** | |
| 117 | - * 消息类型 | |
| 118 | - * | |
| 119 | - * 枚举 {@link IotDeviceMessageTypeEnum} | |
| 120 | - */ | |
| 121 | - private String type; | |
| 122 | - /** | |
| 123 | - * 消息标识符 | |
| 124 | - * | |
| 125 | - * 枚举 {@link IotDeviceMessageIdentifierEnum} | |
| 126 | - */ | |
| 127 | - private String identifier; | |
| 128 | - | |
| 129 | - /** | |
| 130 | - * 参数数组 | |
| 131 | - * | |
| 132 | - * 参数与参数之间,是“或”的关系 | |
| 133 | - */ | |
| 134 | - private List<TriggerConditionParameter> parameters; | |
| 135 | - | |
| 136 | - } | |
| 137 | - | |
| 138 | - /** | |
| 139 | - * 触发条件参数 | |
| 140 | - */ | |
| 141 | - @Data | |
| 142 | - public static class TriggerConditionParameter { | |
| 143 | - | |
| 144 | - /** | |
| 145 | - * 标识符(属性、事件、服务) | |
| 146 | - * | |
| 147 | - * 关联 {@link IotThingModelDO#getIdentifier()} | |
| 148 | - */ | |
| 149 | - private String identifier; | |
| 150 | - | |
| 151 | - /** | |
| 152 | - * 操作符 | |
| 153 | - * | |
| 154 | - * 枚举 {@link IotRuleSceneTriggerConditionParameterOperatorEnum} | |
| 155 | - */ | |
| 156 | - private String operator; | |
| 157 | - | |
| 158 | - /** | |
| 159 | - * 比较值 | |
| 160 | - * | |
| 161 | - * 如果有多个值,则使用 "," 分隔,类似 "1,2,3"。 | |
| 162 | - * 例如说,{@link IotRuleSceneTriggerConditionParameterOperatorEnum#IN}、{@link IotRuleSceneTriggerConditionParameterOperatorEnum#BETWEEN} | |
| 163 | - */ | |
| 164 | - private String value; | |
| 165 | - | |
| 166 | - } | |
| 167 | - | |
| 168 | - /** | |
| 169 | - * 执行器配置 | |
| 170 | - */ | |
| 171 | - @Data | |
| 172 | - public static class ActionConfig { | |
| 173 | - | |
| 174 | - /** | |
| 175 | - * 执行类型 | |
| 176 | - * | |
| 177 | - * 枚举 {@link IotRuleSceneActionTypeEnum} | |
| 178 | - */ | |
| 179 | - private Integer type; | |
| 180 | - | |
| 181 | - /** | |
| 182 | - * 设备控制 | |
| 183 | - * | |
| 184 | - * 必填:当 {@link #type} 为 {@link IotRuleSceneActionTypeEnum#DEVICE_CONTROL} 时 | |
| 185 | - */ | |
| 186 | - private ActionDeviceControl deviceControl; | |
| 187 | - | |
| 188 | - /** | |
| 189 | - * 数据桥接编号 | |
| 190 | - * | |
| 191 | - * 必填:当 {@link #type} 为 {@link IotRuleSceneActionTypeEnum#DATA_BRIDGE} 时 | |
| 192 | - * 关联:{@link IotDataBridgeDO#getId()} | |
| 193 | - */ | |
| 194 | - private Long dataBridgeId; | |
| 195 | - | |
| 196 | - } | |
| 197 | - | |
| 198 | - /** | |
| 199 | - * 执行设备控制 | |
| 200 | - */ | |
| 201 | - @Data | |
| 202 | - public static class ActionDeviceControl { | |
| 203 | - | |
| 204 | - /** | |
| 205 | - * 产品标识 | |
| 206 | - * | |
| 207 | - * 关联 {@link IotProductDO#getProductKey()} | |
| 208 | - */ | |
| 209 | - private String productKey; | |
| 210 | - /** | |
| 211 | - * 设备名称数组 | |
| 212 | - * | |
| 213 | - * 关联 {@link IotDeviceDO#getDeviceName()} | |
| 214 | - */ | |
| 215 | - private List<String> deviceNames; | |
| 216 | - | |
| 217 | - /** | |
| 218 | - * 消息类型 | |
| 219 | - * | |
| 220 | - * 枚举 {@link IotDeviceMessageTypeEnum#PROPERTY}、{@link IotDeviceMessageTypeEnum#SERVICE} | |
| 221 | - */ | |
| 222 | - private String type; | |
| 223 | - /** | |
| 224 | - * 消息标识符 | |
| 225 | - * | |
| 226 | - * 枚举 {@link IotDeviceMessageIdentifierEnum} | |
| 227 | - * | |
| 228 | - * 1. 属性设置:对应 {@link IotDeviceMessageIdentifierEnum#PROPERTY_SET} | |
| 229 | - * 2. 服务调用:对应 {@link IotDeviceMessageIdentifierEnum#SERVICE_INVOKE} | |
| 230 | - */ | |
| 231 | - private String identifier; | |
| 232 | - | |
| 233 | - /** | |
| 234 | - * 具体数据 | |
| 235 | - * | |
| 236 | - * 1. 属性设置:在 {@link #type} 是 {@link IotDeviceMessageTypeEnum#PROPERTY} 时,对应 properties | |
| 237 | - * 2. 服务调用:在 {@link #type} 是 {@link IotDeviceMessageTypeEnum#SERVICE} 时,对应 params | |
| 238 | - */ | |
| 239 | - private Map<String, Object> data; | |
| 240 | - | |
| 241 | - } | |
| 61 | + private List<IotRuleSceneActionConfig> actions; | |
| 242 | 62 | |
| 243 | 63 | } | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/IotRuleSceneServiceImpl.java
| ... | ... | @@ -17,6 +17,7 @@ import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore; |
| 17 | 17 | import cn.iocoder.yudao.framework.tenant.core.util.TenantUtils; |
| 18 | 18 | import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.scene.IotRuleScenePageReqVO; |
| 19 | 19 | import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.scene.IotRuleSceneSaveReqVO; |
| 20 | +import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.scene.config.*; | |
| 20 | 21 | import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotRuleSceneDO; |
| 21 | 22 | import cn.iocoder.yudao.module.iot.dal.mysql.rule.IotRuleSceneMapper; |
| 22 | 23 | import cn.iocoder.yudao.module.iot.enums.device.IotDeviceMessageIdentifierEnum; |
| ... | ... | @@ -117,82 +118,82 @@ public class IotRuleSceneServiceImpl implements IotRuleSceneService { |
| 117 | 118 | if (true) { |
| 118 | 119 | IotRuleSceneDO ruleScene01 = new IotRuleSceneDO(); |
| 119 | 120 | ruleScene01.setTriggers(CollUtil.newArrayList()); |
| 120 | - IotRuleSceneDO.TriggerConfig trigger01 = new IotRuleSceneDO.TriggerConfig(); | |
| 121 | + IotRuleSceneTriggerConfig trigger01 = new IotRuleSceneTriggerConfig(); | |
| 121 | 122 | trigger01.setType(IotRuleSceneTriggerTypeEnum.DEVICE.getType()); |
| 122 | 123 | trigger01.setConditions(CollUtil.newArrayList()); |
| 123 | 124 | // 属性 |
| 124 | - IotRuleSceneDO.TriggerCondition condition01 = new IotRuleSceneDO.TriggerCondition(); | |
| 125 | + IotRuleSceneTriggerCondition condition01 = new IotRuleSceneTriggerCondition(); | |
| 125 | 126 | condition01.setType(IotDeviceMessageTypeEnum.PROPERTY.getType()); |
| 126 | 127 | condition01.setIdentifier(IotDeviceMessageIdentifierEnum.PROPERTY_REPORT.getIdentifier()); |
| 127 | 128 | condition01.setParameters(CollUtil.newArrayList()); |
| 128 | -// IotRuleSceneDO.TriggerConditionParameter parameter010 = new IotRuleSceneDO.TriggerConditionParameter(); | |
| 129 | +// IotRuleSceneTriggerConditionParameter parameter010 = new IotRuleSceneTriggerConditionParameter(); | |
| 129 | 130 | // parameter010.setIdentifier("width"); |
| 130 | 131 | // parameter010.setOperator(IotRuleSceneTriggerConditionParameterOperatorEnum.EQUALS.getOperator()); |
| 131 | 132 | // parameter010.setValue("abc"); |
| 132 | 133 | // condition01.getParameters().add(parameter010); |
| 133 | - IotRuleSceneDO.TriggerConditionParameter parameter011 = new IotRuleSceneDO.TriggerConditionParameter(); | |
| 134 | + IotRuleSceneTriggerConditionParameter parameter011 = new IotRuleSceneTriggerConditionParameter(); | |
| 134 | 135 | parameter011.setIdentifier("width"); |
| 135 | 136 | parameter011.setOperator(IotRuleSceneTriggerConditionParameterOperatorEnum.EQUALS.getOperator()); |
| 136 | 137 | parameter011.setValue("1"); |
| 137 | 138 | condition01.getParameters().add(parameter011); |
| 138 | - IotRuleSceneDO.TriggerConditionParameter parameter012 = new IotRuleSceneDO.TriggerConditionParameter(); | |
| 139 | + IotRuleSceneTriggerConditionParameter parameter012 = new IotRuleSceneTriggerConditionParameter(); | |
| 139 | 140 | parameter012.setIdentifier("width"); |
| 140 | 141 | parameter012.setOperator(IotRuleSceneTriggerConditionParameterOperatorEnum.NOT_EQUALS.getOperator()); |
| 141 | 142 | parameter012.setValue("2"); |
| 142 | 143 | condition01.getParameters().add(parameter012); |
| 143 | - IotRuleSceneDO.TriggerConditionParameter parameter013 = new IotRuleSceneDO.TriggerConditionParameter(); | |
| 144 | + IotRuleSceneTriggerConditionParameter parameter013 = new IotRuleSceneTriggerConditionParameter(); | |
| 144 | 145 | parameter013.setIdentifier("width"); |
| 145 | 146 | parameter013.setOperator(IotRuleSceneTriggerConditionParameterOperatorEnum.GREATER_THAN.getOperator()); |
| 146 | 147 | parameter013.setValue("0"); |
| 147 | 148 | condition01.getParameters().add(parameter013); |
| 148 | - IotRuleSceneDO.TriggerConditionParameter parameter014 = new IotRuleSceneDO.TriggerConditionParameter(); | |
| 149 | + IotRuleSceneTriggerConditionParameter parameter014 = new IotRuleSceneTriggerConditionParameter(); | |
| 149 | 150 | parameter014.setIdentifier("width"); |
| 150 | 151 | parameter014.setOperator(IotRuleSceneTriggerConditionParameterOperatorEnum.GREATER_THAN_OR_EQUALS.getOperator()); |
| 151 | 152 | parameter014.setValue("0"); |
| 152 | 153 | condition01.getParameters().add(parameter014); |
| 153 | - IotRuleSceneDO.TriggerConditionParameter parameter015 = new IotRuleSceneDO.TriggerConditionParameter(); | |
| 154 | + IotRuleSceneTriggerConditionParameter parameter015 = new IotRuleSceneTriggerConditionParameter(); | |
| 154 | 155 | parameter015.setIdentifier("width"); |
| 155 | 156 | parameter015.setOperator(IotRuleSceneTriggerConditionParameterOperatorEnum.LESS_THAN.getOperator()); |
| 156 | 157 | parameter015.setValue("2"); |
| 157 | 158 | condition01.getParameters().add(parameter015); |
| 158 | - IotRuleSceneDO.TriggerConditionParameter parameter016 = new IotRuleSceneDO.TriggerConditionParameter(); | |
| 159 | + IotRuleSceneTriggerConditionParameter parameter016 = new IotRuleSceneTriggerConditionParameter(); | |
| 159 | 160 | parameter016.setIdentifier("width"); |
| 160 | 161 | parameter016.setOperator(IotRuleSceneTriggerConditionParameterOperatorEnum.LESS_THAN_OR_EQUALS.getOperator()); |
| 161 | 162 | parameter016.setValue("2"); |
| 162 | 163 | condition01.getParameters().add(parameter016); |
| 163 | - IotRuleSceneDO.TriggerConditionParameter parameter017 = new IotRuleSceneDO.TriggerConditionParameter(); | |
| 164 | + IotRuleSceneTriggerConditionParameter parameter017 = new IotRuleSceneTriggerConditionParameter(); | |
| 164 | 165 | parameter017.setIdentifier("width"); |
| 165 | 166 | parameter017.setOperator(IotRuleSceneTriggerConditionParameterOperatorEnum.IN.getOperator()); |
| 166 | 167 | parameter017.setValue("1,2,3"); |
| 167 | 168 | condition01.getParameters().add(parameter017); |
| 168 | - IotRuleSceneDO.TriggerConditionParameter parameter018 = new IotRuleSceneDO.TriggerConditionParameter(); | |
| 169 | + IotRuleSceneTriggerConditionParameter parameter018 = new IotRuleSceneTriggerConditionParameter(); | |
| 169 | 170 | parameter018.setIdentifier("width"); |
| 170 | 171 | parameter018.setOperator(IotRuleSceneTriggerConditionParameterOperatorEnum.NOT_IN.getOperator()); |
| 171 | 172 | parameter018.setValue("0,2,3"); |
| 172 | 173 | condition01.getParameters().add(parameter018); |
| 173 | - IotRuleSceneDO.TriggerConditionParameter parameter019 = new IotRuleSceneDO.TriggerConditionParameter(); | |
| 174 | + IotRuleSceneTriggerConditionParameter parameter019 = new IotRuleSceneTriggerConditionParameter(); | |
| 174 | 175 | parameter019.setIdentifier("width"); |
| 175 | 176 | parameter019.setOperator(IotRuleSceneTriggerConditionParameterOperatorEnum.BETWEEN.getOperator()); |
| 176 | 177 | parameter019.setValue("1,3"); |
| 177 | 178 | condition01.getParameters().add(parameter019); |
| 178 | - IotRuleSceneDO.TriggerConditionParameter parameter020 = new IotRuleSceneDO.TriggerConditionParameter(); | |
| 179 | + IotRuleSceneTriggerConditionParameter parameter020 = new IotRuleSceneTriggerConditionParameter(); | |
| 179 | 180 | parameter020.setIdentifier("width"); |
| 180 | 181 | parameter020.setOperator(IotRuleSceneTriggerConditionParameterOperatorEnum.NOT_BETWEEN.getOperator()); |
| 181 | 182 | parameter020.setValue("2,3"); |
| 182 | 183 | condition01.getParameters().add(parameter020); |
| 183 | 184 | trigger01.getConditions().add(condition01); |
| 184 | 185 | // 状态 |
| 185 | - IotRuleSceneDO.TriggerCondition condition02 = new IotRuleSceneDO.TriggerCondition(); | |
| 186 | + IotRuleSceneTriggerCondition condition02 = new IotRuleSceneTriggerCondition(); | |
| 186 | 187 | condition02.setType(IotDeviceMessageTypeEnum.STATE.getType()); |
| 187 | 188 | condition02.setIdentifier(IotDeviceMessageIdentifierEnum.STATE_ONLINE.getIdentifier()); |
| 188 | 189 | condition02.setParameters(CollUtil.newArrayList()); |
| 189 | 190 | trigger01.getConditions().add(condition02); |
| 190 | 191 | // 事件 |
| 191 | - IotRuleSceneDO.TriggerCondition condition03 = new IotRuleSceneDO.TriggerCondition(); | |
| 192 | + IotRuleSceneTriggerCondition condition03 = new IotRuleSceneTriggerCondition(); | |
| 192 | 193 | condition03.setType(IotDeviceMessageTypeEnum.EVENT.getType()); |
| 193 | 194 | condition03.setIdentifier("xxx"); |
| 194 | 195 | condition03.setParameters(CollUtil.newArrayList()); |
| 195 | - IotRuleSceneDO.TriggerConditionParameter parameter030 = new IotRuleSceneDO.TriggerConditionParameter(); | |
| 196 | + IotRuleSceneTriggerConditionParameter parameter030 = new IotRuleSceneTriggerConditionParameter(); | |
| 196 | 197 | parameter030.setIdentifier("width"); |
| 197 | 198 | parameter030.setOperator(IotRuleSceneTriggerConditionParameterOperatorEnum.EQUALS.getOperator()); |
| 198 | 199 | parameter030.setValue("1"); |
| ... | ... | @@ -201,21 +202,21 @@ public class IotRuleSceneServiceImpl implements IotRuleSceneService { |
| 201 | 202 | // 动作 |
| 202 | 203 | ruleScene01.setActions(CollUtil.newArrayList()); |
| 203 | 204 | // 设备控制 |
| 204 | - IotRuleSceneDO.ActionConfig action01 = new IotRuleSceneDO.ActionConfig(); | |
| 205 | + IotRuleSceneActionConfig action01 = new IotRuleSceneActionConfig(); | |
| 205 | 206 | action01.setType(IotRuleSceneActionTypeEnum.DEVICE_CONTROL.getType()); |
| 206 | - IotRuleSceneDO.ActionDeviceControl actionDeviceControl01 = new IotRuleSceneDO.ActionDeviceControl(); | |
| 207 | - actionDeviceControl01.setProductKey("4aymZgOTOOCrDKRT"); | |
| 208 | - actionDeviceControl01.setDeviceNames(ListUtil.of("small")); | |
| 209 | - actionDeviceControl01.setType(IotDeviceMessageTypeEnum.PROPERTY.getType()); | |
| 210 | - actionDeviceControl01.setIdentifier(IotDeviceMessageIdentifierEnum.PROPERTY_SET.getIdentifier()); | |
| 211 | - actionDeviceControl01.setData(MapUtil.<String, Object>builder() | |
| 207 | + IotRuleSceneActionDeviceControl iotRuleSceneActionDeviceControl01 = new IotRuleSceneActionDeviceControl(); | |
| 208 | + iotRuleSceneActionDeviceControl01.setProductKey("4aymZgOTOOCrDKRT"); | |
| 209 | + iotRuleSceneActionDeviceControl01.setDeviceNames(ListUtil.of("small")); | |
| 210 | + iotRuleSceneActionDeviceControl01.setType(IotDeviceMessageTypeEnum.PROPERTY.getType()); | |
| 211 | + iotRuleSceneActionDeviceControl01.setIdentifier(IotDeviceMessageIdentifierEnum.PROPERTY_SET.getIdentifier()); | |
| 212 | + iotRuleSceneActionDeviceControl01.setData(MapUtil.<String, Object>builder() | |
| 212 | 213 | .put("power", 1) |
| 213 | 214 | .put("color", "red") |
| 214 | 215 | .build()); |
| 215 | - action01.setDeviceControl(actionDeviceControl01); | |
| 216 | + action01.setDeviceControl(iotRuleSceneActionDeviceControl01); | |
| 216 | 217 | // ruleScene01.getActions().add(action01); // TODO 芋艿:先不测试了 |
| 217 | 218 | // 数据桥接(http) |
| 218 | - IotRuleSceneDO.ActionConfig action02 = new IotRuleSceneDO.ActionConfig(); | |
| 219 | + IotRuleSceneActionConfig action02 = new IotRuleSceneActionConfig(); | |
| 219 | 220 | action02.setType(IotRuleSceneActionTypeEnum.DATA_BRIDGE.getType()); |
| 220 | 221 | action02.setDataBridgeId(1L); |
| 221 | 222 | ruleScene01.getActions().add(action02); |
| ... | ... | @@ -225,7 +226,7 @@ public class IotRuleSceneServiceImpl implements IotRuleSceneService { |
| 225 | 226 | List<IotRuleSceneDO> list = ruleSceneMapper.selectList(); |
| 226 | 227 | // TODO @芋艿:需要考虑开启状态 |
| 227 | 228 | return filterList(list, ruleScene -> { |
| 228 | - for (IotRuleSceneDO.TriggerConfig trigger : ruleScene.getTriggers()) { | |
| 229 | + for (IotRuleSceneTriggerConfig trigger : ruleScene.getTriggers()) { | |
| 229 | 230 | if (ObjUtil.notEqual(trigger.getProductKey(), productKey)) { |
| 230 | 231 | continue; |
| 231 | 232 | } |
| ... | ... | @@ -260,22 +261,22 @@ public class IotRuleSceneServiceImpl implements IotRuleSceneService { |
| 260 | 261 | IotRuleSceneDO scene = new IotRuleSceneDO().setStatus(CommonStatusEnum.ENABLE.getStatus()); |
| 261 | 262 | if (true) { |
| 262 | 263 | scene.setTenantId(1L); |
| 263 | - IotRuleSceneDO.TriggerConfig triggerConfig = new IotRuleSceneDO.TriggerConfig(); | |
| 264 | - triggerConfig.setType(IotRuleSceneTriggerTypeEnum.TIMER.getType()); | |
| 265 | - scene.setTriggers(ListUtil.toList(triggerConfig)); | |
| 264 | + IotRuleSceneTriggerConfig iotRuleSceneTriggerConfig = new IotRuleSceneTriggerConfig(); | |
| 265 | + iotRuleSceneTriggerConfig.setType(IotRuleSceneTriggerTypeEnum.TIMER.getType()); | |
| 266 | + scene.setTriggers(ListUtil.toList(iotRuleSceneTriggerConfig)); | |
| 266 | 267 | // 动作 |
| 267 | - IotRuleSceneDO.ActionConfig action01 = new IotRuleSceneDO.ActionConfig(); | |
| 268 | + IotRuleSceneActionConfig action01 = new IotRuleSceneActionConfig(); | |
| 268 | 269 | action01.setType(IotRuleSceneActionTypeEnum.DEVICE_CONTROL.getType()); |
| 269 | - IotRuleSceneDO.ActionDeviceControl actionDeviceControl01 = new IotRuleSceneDO.ActionDeviceControl(); | |
| 270 | - actionDeviceControl01.setProductKey("4aymZgOTOOCrDKRT"); | |
| 271 | - actionDeviceControl01.setDeviceNames(ListUtil.of("small")); | |
| 272 | - actionDeviceControl01.setType(IotDeviceMessageTypeEnum.PROPERTY.getType()); | |
| 273 | - actionDeviceControl01.setIdentifier(IotDeviceMessageIdentifierEnum.PROPERTY_SET.getIdentifier()); | |
| 274 | - actionDeviceControl01.setData(MapUtil.<String, Object>builder() | |
| 270 | + IotRuleSceneActionDeviceControl iotRuleSceneActionDeviceControl01 = new IotRuleSceneActionDeviceControl(); | |
| 271 | + iotRuleSceneActionDeviceControl01.setProductKey("4aymZgOTOOCrDKRT"); | |
| 272 | + iotRuleSceneActionDeviceControl01.setDeviceNames(ListUtil.of("small")); | |
| 273 | + iotRuleSceneActionDeviceControl01.setType(IotDeviceMessageTypeEnum.PROPERTY.getType()); | |
| 274 | + iotRuleSceneActionDeviceControl01.setIdentifier(IotDeviceMessageIdentifierEnum.PROPERTY_SET.getIdentifier()); | |
| 275 | + iotRuleSceneActionDeviceControl01.setData(MapUtil.<String, Object>builder() | |
| 275 | 276 | .put("power", 1) |
| 276 | 277 | .put("color", "red") |
| 277 | 278 | .build()); |
| 278 | - action01.setDeviceControl(actionDeviceControl01); | |
| 279 | + action01.setDeviceControl(iotRuleSceneActionDeviceControl01); | |
| 279 | 280 | scene.setActions(ListUtil.toList(action01)); |
| 280 | 281 | } |
| 281 | 282 | if (scene == null) { |
| ... | ... | @@ -287,7 +288,7 @@ public class IotRuleSceneServiceImpl implements IotRuleSceneService { |
| 287 | 288 | return; |
| 288 | 289 | } |
| 289 | 290 | // 1.2 判断是否有定时触发器,避免脏数据 |
| 290 | - IotRuleSceneDO.TriggerConfig config = CollUtil.findOne(scene.getTriggers(), | |
| 291 | + IotRuleSceneTriggerConfig config = CollUtil.findOne(scene.getTriggers(), | |
| 291 | 292 | trigger -> ObjUtil.equals(trigger.getType(), IotRuleSceneTriggerTypeEnum.TIMER.getType())); |
| 292 | 293 | if (config == null) { |
| 293 | 294 | log.error("[executeRuleSceneByTimer][规则场景({}) 不存在定时触发器]", scene); |
| ... | ... | @@ -316,7 +317,7 @@ public class IotRuleSceneServiceImpl implements IotRuleSceneService { |
| 316 | 317 | |
| 317 | 318 | // 2. 匹配 trigger 触发器的条件 |
| 318 | 319 | return filterList(ruleScenes, ruleScene -> { |
| 319 | - for (IotRuleSceneDO.TriggerConfig trigger : ruleScene.getTriggers()) { | |
| 320 | + for (IotRuleSceneTriggerConfig trigger : ruleScene.getTriggers()) { | |
| 320 | 321 | // 2.1 非设备触发,不匹配 |
| 321 | 322 | if (ObjUtil.notEqual(trigger.getType(), IotRuleSceneTriggerTypeEnum.DEVICE.getType())) { |
| 322 | 323 | return false; |
| ... | ... | @@ -327,13 +328,13 @@ public class IotRuleSceneServiceImpl implements IotRuleSceneService { |
| 327 | 328 | return false; |
| 328 | 329 | } |
| 329 | 330 | // 2.3 多个条件,只需要满足一个即可 |
| 330 | - IotRuleSceneDO.TriggerCondition matchedCondition = CollUtil.findOne(trigger.getConditions(), condition -> { | |
| 331 | + IotRuleSceneTriggerCondition matchedCondition = CollUtil.findOne(trigger.getConditions(), condition -> { | |
| 331 | 332 | if (ObjUtil.notEqual(message.getType(), condition.getType()) |
| 332 | 333 | || ObjUtil.notEqual(message.getIdentifier(), condition.getIdentifier())) { |
| 333 | 334 | return false; |
| 334 | 335 | } |
| 335 | 336 | // 多个条件参数,必须全部满足。所以,下面的逻辑就是找到一个不满足的条件参数 |
| 336 | - IotRuleSceneDO.TriggerConditionParameter notMatchedParameter = CollUtil.findOne(condition.getParameters(), | |
| 337 | + IotRuleSceneTriggerConditionParameter notMatchedParameter = CollUtil.findOne(condition.getParameters(), | |
| 337 | 338 | parameter -> !isTriggerConditionParameterMatched(message, parameter, ruleScene, trigger)); |
| 338 | 339 | return notMatchedParameter == null; |
| 339 | 340 | }); |
| ... | ... | @@ -348,6 +349,7 @@ public class IotRuleSceneServiceImpl implements IotRuleSceneService { |
| 348 | 349 | } |
| 349 | 350 | |
| 350 | 351 | // TODO @芋艿:【可优化】可以考虑增加下单测,边界太多了。 |
| 352 | + | |
| 351 | 353 | /** |
| 352 | 354 | * 判断触发器的条件参数是否匹配 |
| 353 | 355 | * |
| ... | ... | @@ -358,8 +360,8 @@ public class IotRuleSceneServiceImpl implements IotRuleSceneService { |
| 358 | 360 | * @return 是否匹配 |
| 359 | 361 | */ |
| 360 | 362 | @SuppressWarnings({"unchecked", "DataFlowIssue"}) |
| 361 | - private boolean isTriggerConditionParameterMatched(IotDeviceMessage message, IotRuleSceneDO.TriggerConditionParameter parameter, | |
| 362 | - IotRuleSceneDO ruleScene, IotRuleSceneDO.TriggerConfig trigger) { | |
| 363 | + private boolean isTriggerConditionParameterMatched(IotDeviceMessage message, IotRuleSceneTriggerConditionParameter parameter, | |
| 364 | + IotRuleSceneDO ruleScene, IotRuleSceneTriggerConfig trigger) { | |
| 363 | 365 | // 1.1 校验操作符是否合法 |
| 364 | 366 | IotRuleSceneTriggerConditionParameterOperatorEnum operator = |
| 365 | 367 | IotRuleSceneTriggerConditionParameterOperatorEnum.operatorOf(parameter.getOperator()); |
| ... | ... | @@ -459,7 +461,7 @@ public class IotRuleSceneServiceImpl implements IotRuleSceneService { |
| 459 | 461 | schedulerManager.addOrUpdateJob(IotRuleSceneJob.class, |
| 460 | 462 | IotRuleSceneJob.buildJobName(id), |
| 461 | 463 | "0/10 * * * * ?", |
| 462 | - jobDataMap); | |
| 464 | + jobDataMap); | |
| 463 | 465 | } |
| 464 | 466 | if (false) { |
| 465 | 467 | Long id = 1L; | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/action/IotRuleSceneAction.java
| 1 | 1 | package cn.iocoder.yudao.module.iot.service.rule.action; |
| 2 | 2 | |
| 3 | -import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotRuleSceneDO; | |
| 3 | +import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.scene.config.IotRuleSceneActionConfig; | |
| 4 | 4 | import cn.iocoder.yudao.module.iot.enums.rule.IotRuleSceneActionTypeEnum; |
| 5 | 5 | import cn.iocoder.yudao.module.iot.mq.message.IotDeviceMessage; |
| 6 | 6 | |
| ... | ... | @@ -14,15 +14,16 @@ import javax.annotation.Nullable; |
| 14 | 14 | public interface IotRuleSceneAction { |
| 15 | 15 | |
| 16 | 16 | // TODO @芋艿:groovy 或者 javascript 实现数据的转换;可以考虑基于 hutool 的 ScriptUtil 做 |
| 17 | + | |
| 17 | 18 | /** |
| 18 | 19 | * 执行场景 |
| 19 | 20 | * |
| 20 | 21 | * @param message 消息,允许空 |
| 21 | 22 | * 1. 空的情况:定时触发 |
| 22 | 23 | * 2. 非空的情况:设备触发 |
| 23 | - * @param config 配置 | |
| 24 | + * @param config 配置 | |
| 24 | 25 | */ |
| 25 | - void execute(@Nullable IotDeviceMessage message, IotRuleSceneDO.ActionConfig config) throws Exception; | |
| 26 | + void execute(@Nullable IotDeviceMessage message, IotRuleSceneActionConfig config) throws Exception; | |
| 26 | 27 | |
| 27 | 28 | /** |
| 28 | 29 | * 获得类型 | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/action/IotRuleSceneAlertAction.java
| 1 | 1 | package cn.iocoder.yudao.module.iot.service.rule.action; |
| 2 | 2 | |
| 3 | -import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotRuleSceneDO; | |
| 3 | +import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.scene.config.IotRuleSceneActionConfig; | |
| 4 | 4 | import cn.iocoder.yudao.module.iot.enums.rule.IotRuleSceneActionTypeEnum; |
| 5 | 5 | import cn.iocoder.yudao.module.iot.mq.message.IotDeviceMessage; |
| 6 | 6 | import org.springframework.stereotype.Component; |
| ... | ... | @@ -16,7 +16,7 @@ import javax.annotation.Nullable; |
| 16 | 16 | public class IotRuleSceneAlertAction implements IotRuleSceneAction { |
| 17 | 17 | |
| 18 | 18 | @Override |
| 19 | - public void execute(@Nullable IotDeviceMessage message, IotRuleSceneDO.ActionConfig config) { | |
| 19 | + public void execute(@Nullable IotDeviceMessage message, IotRuleSceneActionConfig config) { | |
| 20 | 20 | // TODO @芋艿:待实现 |
| 21 | 21 | } |
| 22 | 22 | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/action/IotRuleSceneDataBridgeAction.java
| ... | ... | @@ -2,8 +2,8 @@ package cn.iocoder.yudao.module.iot.service.rule.action; |
| 2 | 2 | |
| 3 | 3 | import cn.hutool.core.lang.Assert; |
| 4 | 4 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 5 | +import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.scene.config.IotRuleSceneActionConfig; | |
| 5 | 6 | import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotDataBridgeDO; |
| 6 | -import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotRuleSceneDO; | |
| 7 | 7 | import cn.iocoder.yudao.module.iot.enums.rule.IotRuleSceneActionTypeEnum; |
| 8 | 8 | import cn.iocoder.yudao.module.iot.mq.message.IotDeviceMessage; |
| 9 | 9 | import cn.iocoder.yudao.module.iot.service.rule.IotDataBridgeService; |
| ... | ... | @@ -29,7 +29,7 @@ public class IotRuleSceneDataBridgeAction implements IotRuleSceneAction { |
| 29 | 29 | private List<IotDataBridgeExecute<?>> dataBridgeExecutes; |
| 30 | 30 | |
| 31 | 31 | @Override |
| 32 | - public void execute(IotDeviceMessage message, IotRuleSceneDO.ActionConfig config) throws Exception { | |
| 32 | + public void execute(IotDeviceMessage message, IotRuleSceneActionConfig config) throws Exception { | |
| 33 | 33 | // 1.1 如果消息为空,直接返回 |
| 34 | 34 | if (message == null) { |
| 35 | 35 | return; | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/action/IotRuleSceneDeviceControlAction.java
| ... | ... | @@ -2,8 +2,9 @@ package cn.iocoder.yudao.module.iot.service.rule.action; |
| 2 | 2 | |
| 3 | 3 | import cn.hutool.core.lang.Assert; |
| 4 | 4 | import cn.iocoder.yudao.module.iot.controller.admin.device.vo.control.IotDeviceDownstreamReqVO; |
| 5 | +import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.scene.config.IotRuleSceneActionConfig; | |
| 6 | +import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.scene.config.IotRuleSceneActionDeviceControl; | |
| 5 | 7 | import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO; |
| 6 | -import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotRuleSceneDO; | |
| 7 | 8 | import cn.iocoder.yudao.module.iot.enums.rule.IotRuleSceneActionTypeEnum; |
| 8 | 9 | import cn.iocoder.yudao.module.iot.mq.message.IotDeviceMessage; |
| 9 | 10 | import cn.iocoder.yudao.module.iot.service.device.IotDeviceService; |
| ... | ... | @@ -27,8 +28,8 @@ public class IotRuleSceneDeviceControlAction implements IotRuleSceneAction { |
| 27 | 28 | private IotDeviceService deviceService; |
| 28 | 29 | |
| 29 | 30 | @Override |
| 30 | - public void execute(IotDeviceMessage message, IotRuleSceneDO.ActionConfig config) { | |
| 31 | - IotRuleSceneDO.ActionDeviceControl control = config.getDeviceControl(); | |
| 31 | + public void execute(IotDeviceMessage message, IotRuleSceneActionConfig config) { | |
| 32 | + IotRuleSceneActionDeviceControl control = config.getDeviceControl(); | |
| 32 | 33 | Assert.notNull(control, "设备控制配置不能为空"); |
| 33 | 34 | // 遍历每个设备,下发消息 |
| 34 | 35 | control.getDeviceNames().forEach(deviceName -> { | ... | ... |