Commit cf3ecd3e5be57145dc81e77ac22d964930c04d95

Authored by puhui999
1 parent 00bd4293

refactor:【IoT 物联网】IotRuleSceneDO => IotSceneRuleDO

Showing 13 changed files with 84 additions and 75 deletions
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/IotRuleSceneController.java
... ... @@ -8,7 +8,7 @@ import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.scene.IotRuleScenePa
8 8 import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.scene.IotRuleSceneRespVO;
9 9 import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.scene.IotRuleSceneSaveReqVO;
10 10 import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.scene.IotRuleSceneUpdateStatusReqVO;
11   -import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotRuleSceneDO;
  11 +import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotSceneRuleDO;
12 12 import cn.iocoder.yudao.module.iot.service.rule.scene.IotRuleSceneService;
13 13 import io.swagger.v3.oas.annotations.Operation;
14 14 import io.swagger.v3.oas.annotations.Parameter;
... ... @@ -71,7 +71,7 @@ public class IotRuleSceneController {
71 71 @Parameter(name = "id", description = "编号", required = true, example = "1024")
72 72 @PreAuthorize("@ss.hasPermission('iot:rule-scene:query')")
73 73 public CommonResult<IotRuleSceneRespVO> getRuleScene(@RequestParam("id") Long id) {
74   - IotRuleSceneDO ruleScene = ruleSceneService.getRuleScene(id);
  74 + IotSceneRuleDO ruleScene = ruleSceneService.getRuleScene(id);
75 75 return success(BeanUtils.toBean(ruleScene, IotRuleSceneRespVO.class));
76 76 }
77 77  
... ... @@ -79,14 +79,14 @@ public class IotRuleSceneController {
79 79 @Operation(summary = "获得场景联动分页")
80 80 @PreAuthorize("@ss.hasPermission('iot:rule-scene:query')")
81 81 public CommonResult<PageResult<IotRuleSceneRespVO>> getRuleScenePage(@Valid IotRuleScenePageReqVO pageReqVO) {
82   - PageResult<IotRuleSceneDO> pageResult = ruleSceneService.getRuleScenePage(pageReqVO);
  82 + PageResult<IotSceneRuleDO> pageResult = ruleSceneService.getRuleScenePage(pageReqVO);
83 83 return success(BeanUtils.toBean(pageResult, IotRuleSceneRespVO.class));
84 84 }
85 85  
86 86 @GetMapping("/simple-list")
87 87 @Operation(summary = "获取场景联动的精简信息列表", description = "主要用于前端的下拉选项")
88 88 public CommonResult<List<IotRuleSceneRespVO>> getRuleSceneSimpleList() {
89   - List<IotRuleSceneDO> list = ruleSceneService.getRuleSceneListByStatus(CommonStatusEnum.ENABLE.getStatus());
  89 + List<IotSceneRuleDO> list = ruleSceneService.getRuleSceneListByStatus(CommonStatusEnum.ENABLE.getStatus());
90 90 return success(convertList(list, scene -> // 只返回 id、name 字段
91 91 new IotRuleSceneRespVO().setId(scene.getId()).setName(scene.getName())));
92 92 }
... ...
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.dal.dataobject.rule.IotRuleSceneDO;
  3 +import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotSceneRuleDO;
4 4 import io.swagger.v3.oas.annotations.media.Schema;
5 5 import lombok.Data;
6 6  
... ... @@ -24,10 +24,10 @@ public class IotRuleSceneRespVO {
24 24 private Integer status;
25 25  
26 26 @Schema(description = "触发器数组", requiredMode = Schema.RequiredMode.REQUIRED)
27   - private List<IotRuleSceneDO.Trigger> triggers;
  27 + private List<IotSceneRuleDO.Trigger> triggers;
28 28  
29 29 @Schema(description = "执行器数组", requiredMode = Schema.RequiredMode.REQUIRED)
30   - private List<IotRuleSceneDO.Action> actions;
  30 + private List<IotSceneRuleDO.Action> actions;
31 31  
32 32 @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
33 33 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,7 +2,7 @@ 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.dal.dataobject.rule.IotRuleSceneDO;
  5 +import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotSceneRuleDO;
6 6 import io.swagger.v3.oas.annotations.media.Schema;
7 7 import jakarta.validation.constraints.NotEmpty;
8 8 import jakarta.validation.constraints.NotNull;
... ... @@ -31,10 +31,10 @@ public class IotRuleSceneSaveReqVO {
31 31  
32 32 @Schema(description = "触发器数组", requiredMode = Schema.RequiredMode.REQUIRED)
33 33 @NotEmpty(message = "触发器数组不能为空")
34   - private List<IotRuleSceneDO.Trigger> triggers;
  34 + private List<IotSceneRuleDO.Trigger> triggers;
35 35  
36 36 @Schema(description = "执行器数组", requiredMode = Schema.RequiredMode.REQUIRED)
37 37 @NotEmpty(message = "执行器数组不能为空")
38   - private List<IotRuleSceneDO.Action> actions;
  38 + private List<IotSceneRuleDO.Action> actions;
39 39  
40 40 }
41 41 \ No newline at end of file
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/alert/IotAlertConfigDO.java
... ... @@ -4,7 +4,7 @@ import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
4 4 import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
5 5 import cn.iocoder.yudao.framework.mybatis.core.type.IntegerListTypeHandler;
6 6 import cn.iocoder.yudao.framework.mybatis.core.type.LongListTypeHandler;
7   -import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotRuleSceneDO;
  7 +import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotSceneRuleDO;
8 8 import cn.iocoder.yudao.module.iot.enums.DictTypeConstants;
9 9 import cn.iocoder.yudao.module.iot.enums.alert.IotAlertReceiveTypeEnum;
10 10 import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
... ... @@ -61,7 +61,7 @@ public class IotAlertConfigDO extends BaseDO {
61 61 /**
62 62 * 关联的场景联动规则编号数组
63 63 *
64   - * 关联 {@link IotRuleSceneDO#getId()}
  64 + * 关联 {@link IotSceneRuleDO#getId()}
65 65 */
66 66 @TableField(typeHandler = LongListTypeHandler.class)
67 67 private List<Long> sceneRuleIds;
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/alert/IotAlertRecordDO.java
... ... @@ -4,7 +4,7 @@ import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
4 4 import cn.iocoder.yudao.module.iot.core.mq.message.IotDeviceMessage;
5 5 import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO;
6 6 import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductDO;
7   -import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotRuleSceneDO;
  7 +import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotSceneRuleDO;
8 8 import com.baomidou.mybatisplus.annotation.KeySequence;
9 9 import com.baomidou.mybatisplus.annotation.TableField;
10 10 import com.baomidou.mybatisplus.annotation.TableId;
... ... @@ -55,7 +55,7 @@ public class IotAlertRecordDO extends BaseDO {
55 55 /**
56 56 * 场景规则编号
57 57 *
58   - * 关联 {@link IotRuleSceneDO#getId()}
  58 + * 关联 {@link IotSceneRuleDO#getId()}
59 59 */
60 60 private Long sceneRuleId;
61 61  
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/rule/IotRuleSceneDO.java renamed to yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/rule/IotSceneRuleDO.java
... ... @@ -23,19 +23,18 @@ import lombok.NoArgsConstructor;
23 23  
24 24 import java.util.List;
25 25  
26   -// TODO @puhui999:名字改成 IotSceneRuleDO
27 26 /**
28 27 * IoT 场景联动规则 DO
29 28 *
30 29 * @author 芋道源码
31 30 */
32   -@TableName(value = "iot_rule_scene", autoResultMap = true)
33   -@KeySequence("iot_rule_scene_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
  31 +@TableName(value = "iot_scene_rule", autoResultMap = true)
  32 +@KeySequence("iot_scene_rule_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
34 33 @Data
35 34 @Builder
36 35 @NoArgsConstructor
37 36 @AllArgsConstructor
38   -public class IotRuleSceneDO extends TenantBaseDO {
  37 +public class IotSceneRuleDO extends TenantBaseDO {
39 38  
40 39 /**
41 40 * 场景联动编号
... ... @@ -219,6 +218,14 @@ public class IotRuleSceneDO extends TenantBaseDO {
219 218 * 关联 {@link IotDeviceDO#getId()}
220 219 */
221 220 private Long deviceId;
  221 +
  222 + /**
  223 + * 标识符(服务)
  224 + * <p>
  225 + * 关联 {@link IotThingModelDO#getIdentifier()}
  226 + */
  227 + private String identifier;
  228 +
222 229 /**
223 230 * 请求参数
224 231 *
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/rule/IotRuleSceneMapper.java
... ... @@ -4,7 +4,7 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
4 4 import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
5 5 import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
6 6 import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.scene.IotRuleScenePageReqVO;
7   -import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotRuleSceneDO;
  7 +import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotSceneRuleDO;
8 8 import org.apache.ibatis.annotations.Mapper;
9 9  
10 10 import java.util.List;
... ... @@ -15,19 +15,19 @@ import java.util.List;
15 15 * @author HUIHUI
16 16 */
17 17 @Mapper
18   -public interface IotRuleSceneMapper extends BaseMapperX<IotRuleSceneDO> {
  18 +public interface IotRuleSceneMapper extends BaseMapperX<IotSceneRuleDO> {
19 19  
20   - default PageResult<IotRuleSceneDO> selectPage(IotRuleScenePageReqVO reqVO) {
21   - return selectPage(reqVO, new LambdaQueryWrapperX<IotRuleSceneDO>()
22   - .likeIfPresent(IotRuleSceneDO::getName, reqVO.getName())
23   - .likeIfPresent(IotRuleSceneDO::getDescription, reqVO.getDescription())
24   - .eqIfPresent(IotRuleSceneDO::getStatus, reqVO.getStatus())
25   - .betweenIfPresent(IotRuleSceneDO::getCreateTime, reqVO.getCreateTime())
26   - .orderByDesc(IotRuleSceneDO::getId));
  20 + default PageResult<IotSceneRuleDO> selectPage(IotRuleScenePageReqVO reqVO) {
  21 + return selectPage(reqVO, new LambdaQueryWrapperX<IotSceneRuleDO>()
  22 + .likeIfPresent(IotSceneRuleDO::getName, reqVO.getName())
  23 + .likeIfPresent(IotSceneRuleDO::getDescription, reqVO.getDescription())
  24 + .eqIfPresent(IotSceneRuleDO::getStatus, reqVO.getStatus())
  25 + .betweenIfPresent(IotSceneRuleDO::getCreateTime, reqVO.getCreateTime())
  26 + .orderByDesc(IotSceneRuleDO::getId));
27 27 }
28 28  
29   - default List<IotRuleSceneDO> selectListByStatus(Integer status) {
30   - return selectList(IotRuleSceneDO::getStatus, status);
  29 + default List<IotSceneRuleDO> selectListByStatus(Integer status) {
  30 + return selectList(IotSceneRuleDO::getStatus, status);
31 31 }
32 32  
33 33 }
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/scene/IotRuleSceneService.java
... ... @@ -4,7 +4,7 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
4 4 import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.scene.IotRuleScenePageReqVO;
5 5 import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.scene.IotRuleSceneSaveReqVO;
6 6 import cn.iocoder.yudao.module.iot.core.mq.message.IotDeviceMessage;
7   -import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotRuleSceneDO;
  7 +import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotSceneRuleDO;
8 8 import cn.iocoder.yudao.module.iot.enums.rule.IotRuleSceneTriggerTypeEnum;
9 9 import jakarta.validation.Valid;
10 10  
... ... @@ -54,7 +54,7 @@ public interface IotRuleSceneService {
54 54 * @param id 编号
55 55 * @return 场景联动
56 56 */
57   - IotRuleSceneDO getRuleScene(Long id);
  57 + IotSceneRuleDO getRuleScene(Long id);
58 58  
59 59 /**
60 60 * 获得场景联动分页
... ... @@ -62,7 +62,7 @@ public interface IotRuleSceneService {
62 62 * @param pageReqVO 分页查询
63 63 * @return 场景联动分页
64 64 */
65   - PageResult<IotRuleSceneDO> getRuleScenePage(IotRuleScenePageReqVO pageReqVO);
  65 + PageResult<IotSceneRuleDO> getRuleScenePage(IotRuleScenePageReqVO pageReqVO);
66 66  
67 67 /**
68 68 * 校验规则场景联动规则编号们是否存在。如下情况,视为无效:
... ... @@ -78,7 +78,7 @@ public interface IotRuleSceneService {
78 78 * @param status 状态
79 79 * @return 场景联动列表
80 80 */
81   - List<IotRuleSceneDO> getRuleSceneListByStatus(Integer status);
  81 + List<IotSceneRuleDO> getRuleSceneListByStatus(Integer status);
82 82  
83 83 /**
84 84 * 【缓存】获得指定设备的场景列表
... ... @@ -87,7 +87,7 @@ public interface IotRuleSceneService {
87 87 * @param deviceName 设备名称
88 88 * @return 场景列表
89 89 */
90   - List<IotRuleSceneDO> getRuleSceneListByProductKeyAndDeviceNameFromCache(String productKey, String deviceName);
  90 + List<IotSceneRuleDO> getRuleSceneListByProductKeyAndDeviceNameFromCache(String productKey, String deviceName);
91 91  
92 92 /**
93 93 * 基于 {@link IotRuleSceneTriggerTypeEnum#DEVICE} 场景,执行规则场景
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/scene/IotRuleSceneServiceImpl.java
... ... @@ -21,9 +21,8 @@ import cn.iocoder.yudao.module.iot.core.mq.message.IotDeviceMessage;
21 21 import cn.iocoder.yudao.module.iot.core.util.IotDeviceMessageUtils;
22 22 import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO;
23 23 import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductDO;
24   -import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotRuleSceneDO;
  24 +import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotSceneRuleDO;
25 25 import cn.iocoder.yudao.module.iot.dal.mysql.rule.IotRuleSceneMapper;
26   -import cn.iocoder.yudao.module.iot.enums.rule.IotRuleSceneActionTypeEnum;
27 26 import cn.iocoder.yudao.module.iot.enums.rule.IotRuleSceneConditionOperatorEnum;
28 27 import cn.iocoder.yudao.module.iot.enums.rule.IotRuleSceneConditionTypeEnum;
29 28 import cn.iocoder.yudao.module.iot.enums.rule.IotRuleSceneTriggerTypeEnum;
... ... @@ -43,7 +42,10 @@ import org.quartz.impl.StdSchedulerFactory;
43 42 import org.springframework.stereotype.Service;
44 43 import org.springframework.validation.annotation.Validated;
45 44  
46   -import java.util.*;
  45 +import java.util.Collection;
  46 +import java.util.HashMap;
  47 +import java.util.List;
  48 +import java.util.Map;
47 49  
48 50 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
49 51 import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
... ... @@ -77,7 +79,7 @@ public class IotRuleSceneServiceImpl implements IotRuleSceneService {
77 79  
78 80 @Override
79 81 public Long createRuleScene(IotRuleSceneSaveReqVO createReqVO) {
80   - IotRuleSceneDO ruleScene = BeanUtils.toBean(createReqVO, IotRuleSceneDO.class);
  82 + IotSceneRuleDO ruleScene = BeanUtils.toBean(createReqVO, IotSceneRuleDO.class);
81 83 ruleSceneMapper.insert(ruleScene);
82 84 return ruleScene.getId();
83 85 }
... ... @@ -87,7 +89,7 @@ public class IotRuleSceneServiceImpl implements IotRuleSceneService {
87 89 // 校验存在
88 90 validateRuleSceneExists(updateReqVO.getId());
89 91 // 更新
90   - IotRuleSceneDO updateObj = BeanUtils.toBean(updateReqVO, IotRuleSceneDO.class);
  92 + IotSceneRuleDO updateObj = BeanUtils.toBean(updateReqVO, IotSceneRuleDO.class);
91 93 ruleSceneMapper.updateById(updateObj);
92 94 }
93 95  
... ... @@ -96,7 +98,7 @@ public class IotRuleSceneServiceImpl implements IotRuleSceneService {
96 98 // 校验存在
97 99 validateRuleSceneExists(id);
98 100 // 更新状态
99   - IotRuleSceneDO updateObj = new IotRuleSceneDO().setId(id).setStatus(status);
  101 + IotSceneRuleDO updateObj = new IotSceneRuleDO().setId(id).setStatus(status);
100 102 ruleSceneMapper.updateById(updateObj);
101 103 }
102 104  
... ... @@ -115,12 +117,12 @@ public class IotRuleSceneServiceImpl implements IotRuleSceneService {
115 117 }
116 118  
117 119 @Override
118   - public IotRuleSceneDO getRuleScene(Long id) {
  120 + public IotSceneRuleDO getRuleScene(Long id) {
119 121 return ruleSceneMapper.selectById(id);
120 122 }
121 123  
122 124 @Override
123   - public PageResult<IotRuleSceneDO> getRuleScenePage(IotRuleScenePageReqVO pageReqVO) {
  125 + public PageResult<IotSceneRuleDO> getRuleScenePage(IotRuleScenePageReqVO pageReqVO) {
124 126 return ruleSceneMapper.selectPage(pageReqVO);
125 127 }
126 128  
... ... @@ -130,27 +132,27 @@ public class IotRuleSceneServiceImpl implements IotRuleSceneService {
130 132 return;
131 133 }
132 134 // 批量查询存在的规则场景
133   - List<IotRuleSceneDO> existingScenes = ruleSceneMapper.selectByIds(ids);
  135 + List<IotSceneRuleDO> existingScenes = ruleSceneMapper.selectByIds(ids);
134 136 if (existingScenes.size() != ids.size()) {
135 137 throw exception(RULE_SCENE_NOT_EXISTS);
136 138 }
137 139 }
138 140  
139 141 @Override
140   - public List<IotRuleSceneDO> getRuleSceneListByStatus(Integer status) {
  142 + public List<IotSceneRuleDO> getRuleSceneListByStatus(Integer status) {
141 143 return ruleSceneMapper.selectListByStatus(status);
142 144 }
143 145  
144 146 // TODO 芋艿,缓存待实现
145 147 @Override
146 148 @TenantIgnore // 忽略租户隔离:因为 IotRuleSceneMessageHandler 调用时,一般未传递租户,所以需要忽略
147   - public List<IotRuleSceneDO> getRuleSceneListByProductKeyAndDeviceNameFromCache(String productKey, String deviceName) {
  149 + public List<IotSceneRuleDO> getRuleSceneListByProductKeyAndDeviceNameFromCache(String productKey, String deviceName) {
148 150 // TODO @puhui999:一些注释,看看要不要优化下;
149 151 // 注意:旧的测试代码已删除,因为使用了废弃的数据结构
150 152 // 如需测试,请使用上面的新结构测试代码示例
151   - List<IotRuleSceneDO> list = ruleSceneMapper.selectList();
  153 + List<IotSceneRuleDO> list = ruleSceneMapper.selectList();
152 154 // 只返回启用状态的规则场景
153   - List<IotRuleSceneDO> enabledList = filterList(list,
  155 + List<IotSceneRuleDO> enabledList = filterList(list,
154 156 ruleScene -> CommonStatusEnum.ENABLE.getStatus().equals(ruleScene.getStatus()));
155 157  
156 158 // 根据 productKey 和 deviceName 进行匹配
... ... @@ -159,7 +161,7 @@ public class IotRuleSceneServiceImpl implements IotRuleSceneService {
159 161 return false;
160 162 }
161 163  
162   - for (IotRuleSceneDO.Trigger trigger : ruleScene.getTriggers()) {
  164 + for (IotSceneRuleDO.Trigger trigger : ruleScene.getTriggers()) {
163 165 // 检查触发器是否匹配指定的产品和设备
164 166 if (isMatchProductAndDevice(trigger, productKey, deviceName)) {
165 167 return true;
... ... @@ -177,7 +179,7 @@ public class IotRuleSceneServiceImpl implements IotRuleSceneService {
177 179 * @param deviceName 设备名称
178 180 * @return 是否匹配
179 181 */
180   - private boolean isMatchProductAndDevice(IotRuleSceneDO.Trigger trigger, String productKey, String deviceName) {
  182 + private boolean isMatchProductAndDevice(IotSceneRuleDO.Trigger trigger, String productKey, String deviceName) {
181 183 try {
182 184 // 1. 检查产品是否匹配
183 185 if (trigger.getProductId() != null) {
... ... @@ -219,7 +221,7 @@ public class IotRuleSceneServiceImpl implements IotRuleSceneService {
219 221 // TODO @芋艿:这里的 tenantId,通过设备获取;
220 222 TenantUtils.execute(message.getTenantId(), () -> {
221 223 // 1. 获得设备匹配的规则场景
222   - List<IotRuleSceneDO> ruleScenes = getMatchedRuleSceneListByMessage(message);
  224 + List<IotSceneRuleDO> ruleScenes = getMatchedRuleSceneListByMessage(message);
223 225 if (CollUtil.isEmpty(ruleScenes)) {
224 226 return;
225 227 }
... ... @@ -232,7 +234,7 @@ public class IotRuleSceneServiceImpl implements IotRuleSceneService {
232 234 @Override
233 235 public void executeRuleSceneByTimer(Long id) {
234 236 // 1.1 获得规则场景
235   - IotRuleSceneDO scene = TenantUtils.executeIgnore(() -> ruleSceneMapper.selectById(id));
  237 + IotSceneRuleDO scene = TenantUtils.executeIgnore(() -> ruleSceneMapper.selectById(id));
236 238 if (scene == null) {
237 239 log.error("[executeRuleSceneByTimer][规则场景({}) 不存在]", id);
238 240 return;
... ... @@ -242,7 +244,7 @@ public class IotRuleSceneServiceImpl implements IotRuleSceneService {
242 244 return;
243 245 }
244 246 // 1.2 判断是否有定时触发器,避免脏数据
245   - IotRuleSceneDO.Trigger config = CollUtil.findOne(scene.getTriggers(),
  247 + IotSceneRuleDO.Trigger config = CollUtil.findOne(scene.getTriggers(),
246 248 trigger -> ObjUtil.equals(trigger.getType(), IotRuleSceneTriggerTypeEnum.TIMER.getType()));
247 249 if (config == null) {
248 250 log.error("[executeRuleSceneByTimer][规则场景({}) 不存在定时触发器]", scene);
... ... @@ -260,7 +262,7 @@ public class IotRuleSceneServiceImpl implements IotRuleSceneService {
260 262 * @param message 设备消息
261 263 * @return 规则场景列表
262 264 */
263   - private List<IotRuleSceneDO> getMatchedRuleSceneListByMessage(IotDeviceMessage message) {
  265 + private List<IotSceneRuleDO> getMatchedRuleSceneListByMessage(IotDeviceMessage message) {
264 266 // 1. 匹配设备
265 267 // TODO @芋艿:可能需要 getSelf(); 缓存
266 268 // 1.1 通过 deviceId 获取设备信息
... ... @@ -278,7 +280,7 @@ public class IotRuleSceneServiceImpl implements IotRuleSceneService {
278 280 }
279 281  
280 282 // 1.3 获取匹配的规则场景
281   - List<IotRuleSceneDO> ruleScenes = getRuleSceneListByProductKeyAndDeviceNameFromCache(
  283 + List<IotSceneRuleDO> ruleScenes = getRuleSceneListByProductKeyAndDeviceNameFromCache(
282 284 product.getProductKey(), device.getDeviceName());
283 285 if (CollUtil.isEmpty(ruleScenes)) {
284 286 return ruleScenes;
... ... @@ -286,7 +288,7 @@ public class IotRuleSceneServiceImpl implements IotRuleSceneService {
286 288  
287 289 // 2. 匹配 trigger 触发器的条件
288 290 return filterList(ruleScenes, ruleScene -> {
289   - for (IotRuleSceneDO.Trigger trigger : ruleScene.getTriggers()) {
  291 + for (IotSceneRuleDO.Trigger trigger : ruleScene.getTriggers()) {
290 292 // 2.1 检查触发器类型,根据新的枚举值进行匹配
291 293 // TODO @芋艿:需要根据新的触发器类型枚举进行适配
292 294 // 原来使用 IotRuleSceneTriggerTypeEnum.DEVICE,新结构可能有不同的类型
... ... @@ -298,14 +300,14 @@ public class IotRuleSceneServiceImpl implements IotRuleSceneService {
298 300  
299 301 // 2.3 检查条件分组:分组与分组之间是"或"的关系,条件与条件之间是"且"的关系
300 302 boolean anyGroupMatched = false;
301   - for (List<IotRuleSceneDO.TriggerCondition> conditionGroup : trigger.getConditionGroups()) {
  303 + for (List<IotSceneRuleDO.TriggerCondition> conditionGroup : trigger.getConditionGroups()) {
302 304 if (CollUtil.isEmpty(conditionGroup)) {
303 305 continue;
304 306 }
305 307  
306 308 // 检查当前分组中的所有条件是否都匹配(且关系)
307 309 boolean allConditionsMatched = true;
308   - for (IotRuleSceneDO.TriggerCondition condition : conditionGroup) {
  310 + for (IotSceneRuleDO.TriggerCondition condition : conditionGroup) {
309 311 // TODO @芋艿:这里需要实现具体的条件匹配逻辑
310 312 // 根据新的 TriggerCondition 结构进行匹配
311 313 if (!isTriggerConditionMatched(message, condition, ruleScene, trigger)) {
... ... @@ -338,8 +340,8 @@ public class IotRuleSceneServiceImpl implements IotRuleSceneService {
338 340 * @param trigger 触发器(用于日志,无其它作用)
339 341 * @return 是否匹配
340 342 */
341   - private boolean isTriggerConditionMatched(IotDeviceMessage message, IotRuleSceneDO.TriggerCondition condition,
342   - IotRuleSceneDO ruleScene, IotRuleSceneDO.Trigger trigger) {
  343 + private boolean isTriggerConditionMatched(IotDeviceMessage message, IotSceneRuleDO.TriggerCondition condition,
  344 + IotSceneRuleDO ruleScene, IotSceneRuleDO.Trigger trigger) {
343 345 try {
344 346 // 1. 根据条件类型进行匹配
345 347 if (IotRuleSceneConditionTypeEnum.DEVICE_STATE.getType().equals(condition.getType())) {
... ... @@ -370,7 +372,7 @@ public class IotRuleSceneServiceImpl implements IotRuleSceneService {
370 372 * @param condition 触发条件
371 373 * @return 是否匹配
372 374 */
373   - private boolean matchDeviceStateCondition(IotDeviceMessage message, IotRuleSceneDO.TriggerCondition condition) {
  375 + private boolean matchDeviceStateCondition(IotDeviceMessage message, IotSceneRuleDO.TriggerCondition condition) {
374 376 // TODO @芋艿:需要根据设备状态进行匹配
375 377 // 这里需要检查消息中的设备状态是否符合条件中定义的状态
376 378 log.debug("[matchDeviceStateCondition][设备状态条件匹配逻辑待实现] condition: {}", condition);
... ... @@ -384,7 +386,7 @@ public class IotRuleSceneServiceImpl implements IotRuleSceneService {
384 386 * @param condition 触发条件
385 387 * @return 是否匹配
386 388 */
387   - private boolean matchDevicePropertyCondition(IotDeviceMessage message, IotRuleSceneDO.TriggerCondition condition) {
  389 + private boolean matchDevicePropertyCondition(IotDeviceMessage message, IotSceneRuleDO.TriggerCondition condition) {
388 390 // 1. 检查标识符是否匹配
389 391 String messageIdentifier = IotDeviceMessageUtils.getIdentifier(message);
390 392 if (StrUtil.isBlank(condition.getIdentifier()) || !condition.getIdentifier().equals(messageIdentifier)) {
... ... @@ -407,7 +409,7 @@ public class IotRuleSceneServiceImpl implements IotRuleSceneService {
407 409 * @param condition 触发条件
408 410 * @return 是否匹配
409 411 */
410   - private boolean matchCurrentTimeCondition(IotRuleSceneDO.TriggerCondition condition) {
  412 + private boolean matchCurrentTimeCondition(IotSceneRuleDO.TriggerCondition condition) {
411 413 // TODO @芋艿:需要根据当前时间进行匹配
412 414 // 这里需要检查当前时间是否符合条件中定义的时间范围
413 415 log.debug("[matchCurrentTimeCondition][当前时间条件匹配逻辑待实现] condition: {}", condition);
... ... @@ -474,8 +476,8 @@ public class IotRuleSceneServiceImpl implements IotRuleSceneService {
474 476 * @return 是否匹配
475 477 */
476 478 @SuppressWarnings({"unchecked", "DataFlowIssue"})
477   - private boolean isTriggerConditionParameterMatched(IotDeviceMessage message, IotRuleSceneDO.TriggerCondition condition,
478   - IotRuleSceneDO ruleScene, IotRuleSceneDO.Trigger trigger) {
  479 + private boolean isTriggerConditionParameterMatched(IotDeviceMessage message, IotSceneRuleDO.TriggerCondition condition,
  480 + IotSceneRuleDO ruleScene, IotSceneRuleDO.Trigger trigger) {
479 481 // 1.1 校验操作符是否合法
480 482 IotRuleSceneConditionOperatorEnum operator =
481 483 IotRuleSceneConditionOperatorEnum.operatorOf(condition.getOperator());
... ... @@ -528,7 +530,7 @@ public class IotRuleSceneServiceImpl implements IotRuleSceneService {
528 530 * @param message 设备消息
529 531 * @param ruleScenes 规则场景列表
530 532 */
531   - private void executeRuleSceneAction(IotDeviceMessage message, List<IotRuleSceneDO> ruleScenes) {
  533 + private void executeRuleSceneAction(IotDeviceMessage message, List<IotSceneRuleDO> ruleScenes) {
532 534 // 1. 遍历规则场景
533 535 ruleScenes.forEach(ruleScene -> {
534 536 // 2. 遍历规则场景的动作
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/scene/action/IotAlertRecoverSceneRuleAction.java
... ... @@ -4,7 +4,7 @@ import cn.hutool.core.collection.CollUtil;
4 4 import cn.hutool.core.util.StrUtil;
5 5 import cn.iocoder.yudao.module.iot.core.mq.message.IotDeviceMessage;
6 6 import cn.iocoder.yudao.module.iot.dal.dataobject.alert.IotAlertRecordDO;
7   -import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotRuleSceneDO;
  7 +import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotSceneRuleDO;
8 8 import cn.iocoder.yudao.module.iot.enums.rule.IotRuleSceneActionTypeEnum;
9 9 import cn.iocoder.yudao.module.iot.service.alert.IotAlertRecordService;
10 10 import jakarta.annotation.Resource;
... ... @@ -30,7 +30,7 @@ public class IotAlertRecoverSceneRuleAction implements IotSceneRuleAction {
30 30  
31 31 @Override
32 32 public void execute(IotDeviceMessage message,
33   - IotRuleSceneDO rule, IotRuleSceneDO.Action actionConfig) throws Exception {
  33 + IotSceneRuleDO rule, IotSceneRuleDO.Action actionConfig) throws Exception {
34 34 Long deviceId = message != null ? message.getDeviceId() : null;
35 35 List<IotAlertRecordDO> alertRecords = alertRecordService.getAlertRecordListBySceneRuleId(
36 36 rule.getId(), deviceId, false);
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/scene/action/IotAlertTriggerSceneRuleAction.java
... ... @@ -4,7 +4,7 @@ import cn.hutool.core.collection.CollUtil;
4 4 import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
5 5 import cn.iocoder.yudao.module.iot.core.mq.message.IotDeviceMessage;
6 6 import cn.iocoder.yudao.module.iot.dal.dataobject.alert.IotAlertConfigDO;
7   -import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotRuleSceneDO;
  7 +import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotSceneRuleDO;
8 8 import cn.iocoder.yudao.module.iot.enums.rule.IotRuleSceneActionTypeEnum;
9 9 import cn.iocoder.yudao.module.iot.service.alert.IotAlertConfigService;
10 10 import cn.iocoder.yudao.module.iot.service.alert.IotAlertRecordService;
... ... @@ -40,7 +40,7 @@ public class IotAlertTriggerSceneRuleAction implements IotSceneRuleAction {
40 40  
41 41 @Override
42 42 public void execute(@Nullable IotDeviceMessage message,
43   - IotRuleSceneDO rule, IotRuleSceneDO.Action actionConfig) throws Exception {
  43 + IotSceneRuleDO rule, IotSceneRuleDO.Action actionConfig) throws Exception {
44 44 List<IotAlertConfigDO> alertConfigs = alertConfigService.getAlertConfigListBySceneRuleIdAndStatus(
45 45 rule.getId(), CommonStatusEnum.ENABLE.getStatus());
46 46 if (CollUtil.isEmpty(alertConfigs)) {
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/scene/action/IotDeviceControlRuleSceneAction.java
1 1 package cn.iocoder.yudao.module.iot.service.rule.scene.action;
2 2  
3 3 import cn.iocoder.yudao.module.iot.core.mq.message.IotDeviceMessage;
4   -import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotRuleSceneDO;
  4 +import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotSceneRuleDO;
5 5 import cn.iocoder.yudao.module.iot.enums.rule.IotRuleSceneActionTypeEnum;
6 6 import cn.iocoder.yudao.module.iot.service.device.IotDeviceService;
7 7 import cn.iocoder.yudao.module.iot.service.device.message.IotDeviceMessageService;
... ... @@ -26,8 +26,8 @@ public class IotDeviceControlRuleSceneAction implements IotSceneRuleAction {
26 26 // TODO @puhui999:这里
27 27 @Override
28 28 public void execute(IotDeviceMessage message,
29   - IotRuleSceneDO rule, IotRuleSceneDO.Action actionConfig) {
30   - //IotRuleSceneDO.ActionDeviceControl control = actionConfig.getDeviceControl();
  29 + IotSceneRuleDO rule, IotSceneRuleDO.Action actionConfig) {
  30 + //IotSceneRuleDO.ActionDeviceControl control = actionConfig.getDeviceControl();
31 31 //Assert.notNull(control, "设备控制配置不能为空");
32 32 //// 遍历每个设备,下发消息
33 33 //control.getDeviceNames().forEach(deviceName -> {
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/scene/action/IotSceneRuleAction.java
1 1 package cn.iocoder.yudao.module.iot.service.rule.scene.action;
2 2  
3 3 import cn.iocoder.yudao.module.iot.core.mq.message.IotDeviceMessage;
4   -import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotRuleSceneDO;
  4 +import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotSceneRuleDO;
5 5 import cn.iocoder.yudao.module.iot.enums.rule.IotRuleSceneActionTypeEnum;
6 6  
7 7 import javax.annotation.Nullable;
... ... @@ -23,8 +23,8 @@ public interface IotSceneRuleAction {
23 23 * @param actionConfig 执行配置(实际对应规则里的哪条执行配置)
24 24 */
25 25 void execute(@Nullable IotDeviceMessage message,
26   - IotRuleSceneDO rule,
27   - IotRuleSceneDO.Action actionConfig) throws Exception;
  26 + IotSceneRuleDO rule,
  27 + IotSceneRuleDO.Action actionConfig) throws Exception;
28 28  
29 29 /**
30 30 * 获得类型
... ...