Commit cfb5230c2a218f8f23551a1a404f0aeb7ce6b56b
1 parent
49bf744b
perf:【IoT 物联网】场景规则匹配优化
Showing
11 changed files
with
132 additions
and
107 deletions
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/enums/rule/IotSceneRuleTriggerTypeEnum.java
| @@ -18,9 +18,6 @@ import java.util.Arrays; | @@ -18,9 +18,6 @@ import java.util.Arrays; | ||
| 18 | @Getter | 18 | @Getter |
| 19 | public enum IotSceneRuleTriggerTypeEnum implements ArrayValuable<Integer> { | 19 | public enum IotSceneRuleTriggerTypeEnum implements ArrayValuable<Integer> { |
| 20 | 20 | ||
| 21 | - @Deprecated | ||
| 22 | - DEVICE(1), // 设备触发 // TODO @puhui999:@芋艿:这个可以作废 | ||
| 23 | - | ||
| 24 | // TODO @芋艿:后续“对应”部分,要 @下,等包结构梳理完; | 21 | // TODO @芋艿:后续“对应”部分,要 @下,等包结构梳理完; |
| 25 | /** | 22 | /** |
| 26 | * 设备上下线变更 | 23 | * 设备上下线变更 |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/scene/IotSceneRuleService.java
| @@ -83,15 +83,19 @@ public interface IotSceneRuleService { | @@ -83,15 +83,19 @@ public interface IotSceneRuleService { | ||
| 83 | /** | 83 | /** |
| 84 | * 【缓存】获得指定设备的场景列表 | 84 | * 【缓存】获得指定设备的场景列表 |
| 85 | * | 85 | * |
| 86 | - * @param productKey 产品 Key | ||
| 87 | - * @param deviceName 设备名称 | 86 | + * @param productId 产品 ID |
| 87 | + * @param deviceId 设备 ID | ||
| 88 | * @return 场景列表 | 88 | * @return 场景列表 |
| 89 | */ | 89 | */ |
| 90 | - List<IotSceneRuleDO> getSceneRuleListByProductKeyAndDeviceNameFromCache(String productKey, String deviceName); | 90 | + List<IotSceneRuleDO> getSceneRuleListByProductIdAndDeviceIdFromCache(Long productId, Long deviceId); |
| 91 | 91 | ||
| 92 | /** | 92 | /** |
| 93 | - * 基于 {@link IotSceneRuleTriggerTypeEnum#DEVICE} 场景,执行规则场景 | ||
| 94 | - * | 93 | + * 基于 {@link IotSceneRuleTriggerTypeEnum} 场景,执行规则场景 |
| 94 | + * 1. {@link IotSceneRuleTriggerTypeEnum#DEVICE_STATE_UPDATE} | ||
| 95 | + * 2. {@link IotSceneRuleTriggerTypeEnum#DEVICE_PROPERTY_POST} | ||
| 96 | + * {@link IotSceneRuleTriggerTypeEnum#DEVICE_EVENT_POST} | ||
| 97 | + * 3. {@link IotSceneRuleTriggerTypeEnum#DEVICE_EVENT_POST} | ||
| 98 | + * {@link IotSceneRuleTriggerTypeEnum#DEVICE_SERVICE_INVOKE} | ||
| 95 | * @param message 消息 | 99 | * @param message 消息 |
| 96 | */ | 100 | */ |
| 97 | void executeSceneRuleByDevice(IotDeviceMessage message); | 101 | void executeSceneRuleByDevice(IotDeviceMessage message); |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/scene/IotSceneRuleServiceImpl.java
| @@ -7,6 +7,7 @@ import cn.hutool.core.text.CharPool; | @@ -7,6 +7,7 @@ import cn.hutool.core.text.CharPool; | ||
| 7 | import cn.hutool.core.util.NumberUtil; | 7 | import cn.hutool.core.util.NumberUtil; |
| 8 | import cn.hutool.core.util.ObjUtil; | 8 | import cn.hutool.core.util.ObjUtil; |
| 9 | import cn.hutool.core.util.StrUtil; | 9 | import cn.hutool.core.util.StrUtil; |
| 10 | +import cn.hutool.extra.spring.SpringUtil; | ||
| 10 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | 11 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 11 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 12 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 12 | import cn.iocoder.yudao.framework.common.util.number.NumberUtils; | 13 | import cn.iocoder.yudao.framework.common.util.number.NumberUtils; |
| @@ -30,6 +31,7 @@ import cn.iocoder.yudao.module.iot.framework.job.core.IotSchedulerManager; | @@ -30,6 +31,7 @@ import cn.iocoder.yudao.module.iot.framework.job.core.IotSchedulerManager; | ||
| 30 | import cn.iocoder.yudao.module.iot.service.device.IotDeviceService; | 31 | import cn.iocoder.yudao.module.iot.service.device.IotDeviceService; |
| 31 | import cn.iocoder.yudao.module.iot.service.product.IotProductService; | 32 | import cn.iocoder.yudao.module.iot.service.product.IotProductService; |
| 32 | import cn.iocoder.yudao.module.iot.service.rule.scene.action.IotSceneRuleAction; | 33 | import cn.iocoder.yudao.module.iot.service.rule.scene.action.IotSceneRuleAction; |
| 34 | +import cn.iocoder.yudao.module.iot.service.rule.scene.matcher.IotSceneRuleTriggerMatcherManager; | ||
| 33 | import jakarta.annotation.Resource; | 35 | import jakarta.annotation.Resource; |
| 34 | import lombok.extern.slf4j.Slf4j; | 36 | import lombok.extern.slf4j.Slf4j; |
| 35 | import org.springframework.stereotype.Service; | 37 | import org.springframework.stereotype.Service; |
| @@ -58,17 +60,16 @@ public class IotSceneRuleServiceImpl implements IotSceneRuleService { | @@ -58,17 +60,16 @@ public class IotSceneRuleServiceImpl implements IotSceneRuleService { | ||
| 58 | @Resource | 60 | @Resource |
| 59 | private IotSceneRuleMapper sceneRuleMapper; | 61 | private IotSceneRuleMapper sceneRuleMapper; |
| 60 | 62 | ||
| 61 | - @Resource | ||
| 62 | - private List<IotSceneRuleAction> sceneRuleActions; | ||
| 63 | - | ||
| 64 | @Resource(name = "iotSchedulerManager") | 63 | @Resource(name = "iotSchedulerManager") |
| 65 | private IotSchedulerManager schedulerManager; | 64 | private IotSchedulerManager schedulerManager; |
| 66 | - | ||
| 67 | @Resource | 65 | @Resource |
| 68 | private IotProductService productService; | 66 | private IotProductService productService; |
| 69 | - | ||
| 70 | @Resource | 67 | @Resource |
| 71 | private IotDeviceService deviceService; | 68 | private IotDeviceService deviceService; |
| 69 | + @Resource | ||
| 70 | + private IotSceneRuleTriggerMatcherManager triggerMatcherManager; | ||
| 71 | + @Resource | ||
| 72 | + private List<IotSceneRuleAction> sceneRuleActions; | ||
| 72 | 73 | ||
| 73 | @Override | 74 | @Override |
| 74 | public Long createSceneRule(IotSceneRuleSaveReqVO createReqVO) { | 75 | public Long createSceneRule(IotSceneRuleSaveReqVO createReqVO) { |
| @@ -139,14 +140,11 @@ public class IotSceneRuleServiceImpl implements IotSceneRuleService { | @@ -139,14 +140,11 @@ public class IotSceneRuleServiceImpl implements IotSceneRuleService { | ||
| 139 | // TODO 芋艿,缓存待实现 | 140 | // TODO 芋艿,缓存待实现 |
| 140 | @Override | 141 | @Override |
| 141 | @TenantIgnore // 忽略租户隔离:因为 IotSceneRuleMessageHandler 调用时,一般未传递租户,所以需要忽略 | 142 | @TenantIgnore // 忽略租户隔离:因为 IotSceneRuleMessageHandler 调用时,一般未传递租户,所以需要忽略 |
| 142 | - public List<IotSceneRuleDO> getSceneRuleListByProductKeyAndDeviceNameFromCache(String productKey, String deviceName) { | ||
| 143 | - // TODO @puhui999:一些注释,看看要不要优化下; | ||
| 144 | - // 注意:旧的测试代码已删除,因为使用了废弃的数据结构 | ||
| 145 | - // 如需测试,请使用上面的新结构测试代码示例 | 143 | + public List<IotSceneRuleDO> getSceneRuleListByProductIdAndDeviceIdFromCache(Long productId, Long deviceId) { |
| 146 | List<IotSceneRuleDO> list = sceneRuleMapper.selectList(); | 144 | List<IotSceneRuleDO> list = sceneRuleMapper.selectList(); |
| 147 | // 只返回启用状态的规则场景 | 145 | // 只返回启用状态的规则场景 |
| 148 | List<IotSceneRuleDO> enabledList = filterList(list, | 146 | List<IotSceneRuleDO> enabledList = filterList(list, |
| 149 | - sceneRule -> CommonStatusEnum.ENABLE.getStatus().equals(sceneRule.getStatus())); | 147 | + sceneRule -> CommonStatusEnum.isEnable(sceneRule.getStatus())); |
| 150 | 148 | ||
| 151 | // 根据 productKey 和 deviceName 进行匹配 | 149 | // 根据 productKey 和 deviceName 进行匹配 |
| 152 | return filterList(enabledList, sceneRule -> { | 150 | return filterList(enabledList, sceneRule -> { |
| @@ -156,57 +154,27 @@ public class IotSceneRuleServiceImpl implements IotSceneRuleService { | @@ -156,57 +154,27 @@ public class IotSceneRuleServiceImpl implements IotSceneRuleService { | ||
| 156 | 154 | ||
| 157 | for (IotSceneRuleDO.Trigger trigger : sceneRule.getTriggers()) { | 155 | for (IotSceneRuleDO.Trigger trigger : sceneRule.getTriggers()) { |
| 158 | // 检查触发器是否匹配指定的产品和设备 | 156 | // 检查触发器是否匹配指定的产品和设备 |
| 159 | - if (isMatchProductAndDevice(trigger, productKey, deviceName)) { | ||
| 160 | - return true; | ||
| 161 | - } | ||
| 162 | - } | ||
| 163 | - return false; | ||
| 164 | - }); | ||
| 165 | - } | ||
| 166 | - | ||
| 167 | - /** | ||
| 168 | - * 检查触发器是否匹配指定的产品和设备 | ||
| 169 | - * | ||
| 170 | - * @param trigger 触发器 | ||
| 171 | - * @param productKey 产品标识 | ||
| 172 | - * @param deviceName 设备名称 | ||
| 173 | - * @return 是否匹配 | ||
| 174 | - */ | ||
| 175 | - private boolean isMatchProductAndDevice(IotSceneRuleDO.Trigger trigger, String productKey, String deviceName) { | ||
| 176 | - try { | ||
| 177 | - // 1. 检查产品是否匹配 | ||
| 178 | - if (trigger.getProductId() != null) { | ||
| 179 | - // 通过 productKey 获取产品信息 | ||
| 180 | - IotProductDO product = productService.getProductByProductKey(productKey); | ||
| 181 | - if (product == null || !trigger.getProductId().equals(product.getId())) { | ||
| 182 | - return false; | ||
| 183 | - } | ||
| 184 | - } | ||
| 185 | - | ||
| 186 | - // 2. 检查设备是否匹配 | ||
| 187 | - if (trigger.getDeviceId() != null) { | ||
| 188 | - // 通过 productKey 和 deviceName 获取设备信息 | ||
| 189 | - IotDeviceDO device = deviceService.getDeviceFromCache(productKey, deviceName); | ||
| 190 | - if (device == null) { | ||
| 191 | - return false; | ||
| 192 | - } | ||
| 193 | - | ||
| 194 | - // 检查是否是全部设备的特殊标识 | ||
| 195 | - if (IotDeviceDO.DEVICE_ID_ALL.equals(trigger.getDeviceId())) { | ||
| 196 | - return true; // 匹配所有设备 | ||
| 197 | - } | ||
| 198 | - | ||
| 199 | - // 检查具体设备ID是否匹配 | ||
| 200 | - if (!trigger.getDeviceId().equals(device.getId())) { | 157 | + try { |
| 158 | + // 1. 检查产品是否匹配 | ||
| 159 | + if (trigger.getProductId() == null) { | ||
| 160 | + return false; | ||
| 161 | + } | ||
| 162 | + if (trigger.getDeviceId() == null) { | ||
| 163 | + return false; | ||
| 164 | + } | ||
| 165 | + // 检查是否是全部设备的特殊标识 | ||
| 166 | + if (IotDeviceDO.DEVICE_ID_ALL.equals(trigger.getDeviceId())) { | ||
| 167 | + return true; // 匹配所有设备 | ||
| 168 | + } | ||
| 169 | + // 检查具体设备 ID 是否匹配 | ||
| 170 | + return ObjUtil.equal(productId, trigger.getProductId()) && ObjUtil.equal(deviceId, trigger.getDeviceId()); | ||
| 171 | + } catch (Exception e) { | ||
| 172 | + log.warn("[isMatchProductAndDevice][产品({}) 设备({}) 匹配触发器异常]", productId, deviceId, e); | ||
| 201 | return false; | 173 | return false; |
| 202 | } | 174 | } |
| 203 | } | 175 | } |
| 204 | - | ||
| 205 | - return true; | ||
| 206 | - } catch (Exception e) { | ||
| 207 | - log.warn("[isMatchProductAndDevice][产品({}) 设备({}) 匹配触发器异常]", productKey, deviceName, e); | ||
| 208 | return false; | 176 | return false; |
| 209 | - } | 177 | + }); |
| 210 | } | 178 | } |
| 211 | 179 | ||
| 212 | @Override | 180 | @Override |
| @@ -273,55 +241,95 @@ public class IotSceneRuleServiceImpl implements IotSceneRuleService { | @@ -273,55 +241,95 @@ public class IotSceneRuleServiceImpl implements IotSceneRuleService { | ||
| 273 | } | 241 | } |
| 274 | 242 | ||
| 275 | // 1.3 获取匹配的规则场景 | 243 | // 1.3 获取匹配的规则场景 |
| 276 | - List<IotSceneRuleDO> sceneRules = getSceneRuleListByProductKeyAndDeviceNameFromCache( | ||
| 277 | - product.getProductKey(), device.getDeviceName()); | 244 | + List<IotSceneRuleDO> sceneRules = getSceneRuleListByProductIdAndDeviceIdFromCache( |
| 245 | + product.getId(), device.getId()); | ||
| 278 | if (CollUtil.isEmpty(sceneRules)) { | 246 | if (CollUtil.isEmpty(sceneRules)) { |
| 279 | return sceneRules; | 247 | return sceneRules; |
| 280 | } | 248 | } |
| 281 | 249 | ||
| 282 | - // 2. 匹配 trigger 触发器的条件 | ||
| 283 | - return filterList(sceneRules, sceneRule -> { | ||
| 284 | - for (IotSceneRuleDO.Trigger trigger : sceneRule.getTriggers()) { | ||
| 285 | - // 2.1 检查触发器类型,根据新的枚举值进行匹配 | ||
| 286 | - // TODO @芋艿:需要根据新的触发器类型枚举进行适配 | ||
| 287 | - // 原来使用 IotSceneRuleTriggerTypeEnum.DEVICE,新结构可能有不同的类型 | 250 | + // 2. 使用重构后的触发器匹配逻辑 |
| 251 | + return filterList(sceneRules, sceneRule -> matchSceneRuleTriggers(message, sceneRule)); | ||
| 252 | + } | ||
| 288 | 253 | ||
| 289 | - // 2.2 条件分组为空,说明没有匹配的条件,因此不匹配 | ||
| 290 | - if (CollUtil.isEmpty(trigger.getConditionGroups())) { | ||
| 291 | - return false; | ||
| 292 | - } | 254 | + /** |
| 255 | + * 匹配场景规则的所有触发器 | ||
| 256 | + * | ||
| 257 | + * @param message 设备消息 | ||
| 258 | + * @param sceneRule 场景规则 | ||
| 259 | + * @return 是否匹配 | ||
| 260 | + */ | ||
| 261 | + private boolean matchSceneRuleTriggers(IotDeviceMessage message, IotSceneRuleDO sceneRule) { | ||
| 262 | + if (CollUtil.isEmpty(sceneRule.getTriggers())) { | ||
| 263 | + log.debug("[matchSceneRuleTriggers][规则场景({}) 没有配置触发器]", sceneRule.getId()); | ||
| 264 | + return false; | ||
| 265 | + } | ||
| 293 | 266 | ||
| 294 | - // 2.3 检查条件分组:分组与分组之间是"或"的关系,条件与条件之间是"且"的关系 | ||
| 295 | - boolean anyGroupMatched = false; | ||
| 296 | - for (List<IotSceneRuleDO.TriggerCondition> conditionGroup : trigger.getConditionGroups()) { | ||
| 297 | - if (CollUtil.isEmpty(conditionGroup)) { | ||
| 298 | - continue; | ||
| 299 | - } | 267 | + for (IotSceneRuleDO.Trigger trigger : sceneRule.getTriggers()) { |
| 268 | + if (matchSingleTrigger(message, trigger, sceneRule)) { | ||
| 269 | + log.info("[matchSceneRuleTriggers][消息({}) 匹配到规则场景编号({}) 的触发器({})]", | ||
| 270 | + message.getRequestId(), sceneRule.getId(), trigger.getType()); | ||
| 271 | + return true; | ||
| 272 | + } | ||
| 273 | + } | ||
| 274 | + return false; | ||
| 275 | + } | ||
| 300 | 276 | ||
| 301 | - // 检查当前分组中的所有条件是否都匹配(且关系) | ||
| 302 | - boolean allConditionsMatched = true; | ||
| 303 | - for (IotSceneRuleDO.TriggerCondition condition : conditionGroup) { | ||
| 304 | - // TODO @芋艿:这里需要实现具体的条件匹配逻辑 | ||
| 305 | - // 根据新的 TriggerCondition 结构进行匹配 | ||
| 306 | - if (!isTriggerConditionMatched(message, condition, sceneRule, trigger)) { | ||
| 307 | - allConditionsMatched = false; | ||
| 308 | - break; | ||
| 309 | - } | ||
| 310 | - } | 277 | + /** |
| 278 | + * 匹配单个触发器 | ||
| 279 | + * | ||
| 280 | + * @param message 设备消息 | ||
| 281 | + * @param trigger 触发器 | ||
| 282 | + * @param sceneRule 场景规则(用于日志) | ||
| 283 | + * @return 是否匹配 | ||
| 284 | + */ | ||
| 285 | + private boolean matchSingleTrigger(IotDeviceMessage message, IotSceneRuleDO.Trigger trigger, IotSceneRuleDO sceneRule) { | ||
| 286 | + try { | ||
| 287 | + // 2. 检查触发器的条件分组 | ||
| 288 | + return triggerMatcherManager.isMatched(message, trigger) && isTriggerConditionGroupsMatched(message, trigger, sceneRule); | ||
| 289 | + } catch (Exception e) { | ||
| 290 | + log.error("[matchSingleTrigger][触发器匹配异常] sceneRuleId: {}, triggerType: {}, message: {}", | ||
| 291 | + sceneRule.getId(), trigger.getType(), message, e); | ||
| 292 | + return false; | ||
| 293 | + } | ||
| 294 | + } | ||
| 311 | 295 | ||
| 312 | - if (allConditionsMatched) { | ||
| 313 | - anyGroupMatched = true; | ||
| 314 | - break; // 有一个分组匹配即可 | ||
| 315 | - } | ||
| 316 | - } | 296 | + /** |
| 297 | + * 检查触发器的条件分组是否匹配 | ||
| 298 | + * | ||
| 299 | + * @param message 设备消息 | ||
| 300 | + * @param trigger 触发器 | ||
| 301 | + * @param sceneRule 场景规则(用于日志) | ||
| 302 | + * @return 是否匹配 | ||
| 303 | + */ | ||
| 304 | + private boolean isTriggerConditionGroupsMatched(IotDeviceMessage message, IotSceneRuleDO.Trigger trigger, IotSceneRuleDO sceneRule) { | ||
| 305 | + // 如果没有条件分组,则认为匹配成功(只依赖基础触发器匹配) | ||
| 306 | + if (CollUtil.isEmpty(trigger.getConditionGroups())) { | ||
| 307 | + return true; | ||
| 308 | + } | ||
| 309 | + | ||
| 310 | + // 检查条件分组:分组与分组之间是"或"的关系,条件与条件之间是"且"的关系 | ||
| 311 | + for (List<IotSceneRuleDO.TriggerCondition> conditionGroup : trigger.getConditionGroups()) { | ||
| 312 | + if (CollUtil.isEmpty(conditionGroup)) { | ||
| 313 | + continue; | ||
| 314 | + } | ||
| 317 | 315 | ||
| 318 | - if (anyGroupMatched) { | ||
| 319 | - log.info("[getMatchedSceneRuleList][消息({}) 匹配到规则场景编号({}) 的触发器({})]", message, sceneRule.getId(), trigger); | ||
| 320 | - return true; | 316 | + // 检查当前分组中的所有条件是否都匹配(且关系) |
| 317 | + boolean allConditionsMatched = true; | ||
| 318 | + for (IotSceneRuleDO.TriggerCondition condition : conditionGroup) { | ||
| 319 | + if (!isTriggerConditionMatched(message, condition, sceneRule, trigger)) { | ||
| 320 | + allConditionsMatched = false; | ||
| 321 | + break; | ||
| 321 | } | 322 | } |
| 322 | } | 323 | } |
| 323 | - return false; | ||
| 324 | - }); | 324 | + |
| 325 | + // 如果当前分组的所有条件都匹配,则整个触发器匹配成功 | ||
| 326 | + if (allConditionsMatched) { | ||
| 327 | + return true; | ||
| 328 | + } | ||
| 329 | + } | ||
| 330 | + | ||
| 331 | + // 所有分组都不匹配 | ||
| 332 | + return false; | ||
| 325 | } | 333 | } |
| 326 | 334 | ||
| 327 | /** | 335 | /** |
| @@ -549,4 +557,8 @@ public class IotSceneRuleServiceImpl implements IotSceneRuleService { | @@ -549,4 +557,8 @@ public class IotSceneRuleServiceImpl implements IotSceneRuleService { | ||
| 549 | }); | 557 | }); |
| 550 | } | 558 | } |
| 551 | 559 | ||
| 560 | + private IotSceneRuleServiceImpl getSelf() { | ||
| 561 | + return SpringUtil.getBean(IotSceneRuleServiceImpl.class); | ||
| 562 | + } | ||
| 563 | + | ||
| 552 | } | 564 | } |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/scene/matcher/AbstractIotSceneRuleTriggerMatcher.java
| @@ -119,4 +119,5 @@ public abstract class AbstractIotSceneRuleTriggerMatcher implements IotSceneRule | @@ -119,4 +119,5 @@ public abstract class AbstractIotSceneRuleTriggerMatcher implements IotSceneRule | ||
| 119 | protected void logMatchFailure(IotDeviceMessage message, IotSceneRuleDO.Trigger trigger, String reason) { | 119 | protected void logMatchFailure(IotDeviceMessage message, IotSceneRuleDO.Trigger trigger, String reason) { |
| 120 | log.debug("[{}][消息({}) 匹配触发器({}) 失败: {}]", getMatcherName(), message.getRequestId(), trigger.getType(), reason); | 120 | log.debug("[{}][消息({}) 匹配触发器({}) 失败: {}]", getMatcherName(), message.getRequestId(), trigger.getType(), reason); |
| 121 | } | 121 | } |
| 122 | + | ||
| 122 | } | 123 | } |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/scene/matcher/DeviceEventPostTriggerMatcher.java
| 1 | package cn.iocoder.yudao.module.iot.service.rule.scene.matcher; | 1 | package cn.iocoder.yudao.module.iot.service.rule.scene.matcher; |
| 2 | 2 | ||
| 3 | import cn.hutool.core.util.StrUtil; | 3 | import cn.hutool.core.util.StrUtil; |
| 4 | +import cn.iocoder.yudao.module.iot.core.enums.IotDeviceMessageMethodEnum; | ||
| 4 | import cn.iocoder.yudao.module.iot.core.mq.message.IotDeviceMessage; | 5 | import cn.iocoder.yudao.module.iot.core.mq.message.IotDeviceMessage; |
| 5 | import cn.iocoder.yudao.module.iot.core.util.IotDeviceMessageUtils; | 6 | import cn.iocoder.yudao.module.iot.core.util.IotDeviceMessageUtils; |
| 6 | import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotSceneRuleDO; | 7 | import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotSceneRuleDO; |
| @@ -20,7 +21,7 @@ public class DeviceEventPostTriggerMatcher extends AbstractIotSceneRuleTriggerMa | @@ -20,7 +21,7 @@ public class DeviceEventPostTriggerMatcher extends AbstractIotSceneRuleTriggerMa | ||
| 20 | /** | 21 | /** |
| 21 | * 设备事件上报消息方法 | 22 | * 设备事件上报消息方法 |
| 22 | */ | 23 | */ |
| 23 | - private static final String DEVICE_EVENT_POST_METHOD = "thing.event.post"; | 24 | + private static final String DEVICE_EVENT_POST_METHOD = IotDeviceMessageMethodEnum.EVENT_POST.getMethod(); |
| 24 | 25 | ||
| 25 | @Override | 26 | @Override |
| 26 | public IotSceneRuleTriggerTypeEnum getSupportedTriggerType() { | 27 | public IotSceneRuleTriggerTypeEnum getSupportedTriggerType() { |
| @@ -72,4 +73,5 @@ public class DeviceEventPostTriggerMatcher extends AbstractIotSceneRuleTriggerMa | @@ -72,4 +73,5 @@ public class DeviceEventPostTriggerMatcher extends AbstractIotSceneRuleTriggerMa | ||
| 72 | public int getPriority() { | 73 | public int getPriority() { |
| 73 | return 30; // 中等优先级 | 74 | return 30; // 中等优先级 |
| 74 | } | 75 | } |
| 76 | + | ||
| 75 | } | 77 | } |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/scene/matcher/DevicePropertyPostTriggerMatcher.java
| 1 | package cn.iocoder.yudao.module.iot.service.rule.scene.matcher; | 1 | package cn.iocoder.yudao.module.iot.service.rule.scene.matcher; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.module.iot.core.enums.IotDeviceMessageMethodEnum; | ||
| 3 | import cn.iocoder.yudao.module.iot.core.mq.message.IotDeviceMessage; | 4 | import cn.iocoder.yudao.module.iot.core.mq.message.IotDeviceMessage; |
| 4 | import cn.iocoder.yudao.module.iot.core.util.IotDeviceMessageUtils; | 5 | import cn.iocoder.yudao.module.iot.core.util.IotDeviceMessageUtils; |
| 5 | import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotSceneRuleDO; | 6 | import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotSceneRuleDO; |
| @@ -19,7 +20,7 @@ public class DevicePropertyPostTriggerMatcher extends AbstractIotSceneRuleTrigge | @@ -19,7 +20,7 @@ public class DevicePropertyPostTriggerMatcher extends AbstractIotSceneRuleTrigge | ||
| 19 | /** | 20 | /** |
| 20 | * 设备属性上报消息方法 | 21 | * 设备属性上报消息方法 |
| 21 | */ | 22 | */ |
| 22 | - private static final String DEVICE_PROPERTY_POST_METHOD = "thing.property.post"; | 23 | + private static final String DEVICE_PROPERTY_POST_METHOD = IotDeviceMessageMethodEnum.PROPERTY_POST.getMethod(); |
| 23 | 24 | ||
| 24 | @Override | 25 | @Override |
| 25 | public IotSceneRuleTriggerTypeEnum getSupportedTriggerType() { | 26 | public IotSceneRuleTriggerTypeEnum getSupportedTriggerType() { |
| @@ -76,4 +77,5 @@ public class DevicePropertyPostTriggerMatcher extends AbstractIotSceneRuleTrigge | @@ -76,4 +77,5 @@ public class DevicePropertyPostTriggerMatcher extends AbstractIotSceneRuleTrigge | ||
| 76 | public int getPriority() { | 77 | public int getPriority() { |
| 77 | return 20; // 中等优先级 | 78 | return 20; // 中等优先级 |
| 78 | } | 79 | } |
| 80 | + | ||
| 79 | } | 81 | } |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/scene/matcher/DeviceServiceInvokeTriggerMatcher.java
| 1 | package cn.iocoder.yudao.module.iot.service.rule.scene.matcher; | 1 | package cn.iocoder.yudao.module.iot.service.rule.scene.matcher; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.module.iot.core.enums.IotDeviceMessageMethodEnum; | ||
| 3 | import cn.iocoder.yudao.module.iot.core.mq.message.IotDeviceMessage; | 4 | import cn.iocoder.yudao.module.iot.core.mq.message.IotDeviceMessage; |
| 4 | import cn.iocoder.yudao.module.iot.core.util.IotDeviceMessageUtils; | 5 | import cn.iocoder.yudao.module.iot.core.util.IotDeviceMessageUtils; |
| 5 | import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotSceneRuleDO; | 6 | import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotSceneRuleDO; |
| @@ -19,7 +20,7 @@ public class DeviceServiceInvokeTriggerMatcher extends AbstractIotSceneRuleTrigg | @@ -19,7 +20,7 @@ public class DeviceServiceInvokeTriggerMatcher extends AbstractIotSceneRuleTrigg | ||
| 19 | /** | 20 | /** |
| 20 | * 设备服务调用消息方法 | 21 | * 设备服务调用消息方法 |
| 21 | */ | 22 | */ |
| 22 | - private static final String DEVICE_SERVICE_INVOKE_METHOD = "thing.service.invoke"; | 23 | + private static final String DEVICE_SERVICE_INVOKE_METHOD = IotDeviceMessageMethodEnum.SERVICE_INVOKE.getMethod(); |
| 23 | 24 | ||
| 24 | @Override | 25 | @Override |
| 25 | public IotSceneRuleTriggerTypeEnum getSupportedTriggerType() { | 26 | public IotSceneRuleTriggerTypeEnum getSupportedTriggerType() { |
| @@ -58,4 +59,5 @@ public class DeviceServiceInvokeTriggerMatcher extends AbstractIotSceneRuleTrigg | @@ -58,4 +59,5 @@ public class DeviceServiceInvokeTriggerMatcher extends AbstractIotSceneRuleTrigg | ||
| 58 | public int getPriority() { | 59 | public int getPriority() { |
| 59 | return 40; // 较低优先级 | 60 | return 40; // 较低优先级 |
| 60 | } | 61 | } |
| 62 | + | ||
| 61 | } | 63 | } |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/scene/matcher/DeviceStateUpdateTriggerMatcher.java
| 1 | package cn.iocoder.yudao.module.iot.service.rule.scene.matcher; | 1 | package cn.iocoder.yudao.module.iot.service.rule.scene.matcher; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.module.iot.core.enums.IotDeviceMessageMethodEnum; | ||
| 3 | import cn.iocoder.yudao.module.iot.core.mq.message.IotDeviceMessage; | 4 | import cn.iocoder.yudao.module.iot.core.mq.message.IotDeviceMessage; |
| 4 | import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotSceneRuleDO; | 5 | import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotSceneRuleDO; |
| 5 | import cn.iocoder.yudao.module.iot.enums.rule.IotSceneRuleTriggerTypeEnum; | 6 | import cn.iocoder.yudao.module.iot.enums.rule.IotSceneRuleTriggerTypeEnum; |
| @@ -18,7 +19,7 @@ public class DeviceStateUpdateTriggerMatcher extends AbstractIotSceneRuleTrigger | @@ -18,7 +19,7 @@ public class DeviceStateUpdateTriggerMatcher extends AbstractIotSceneRuleTrigger | ||
| 18 | /** | 19 | /** |
| 19 | * 设备状态更新消息方法 | 20 | * 设备状态更新消息方法 |
| 20 | */ | 21 | */ |
| 21 | - private static final String DEVICE_STATE_UPDATE_METHOD = "thing.state.update"; | 22 | + private static final String DEVICE_STATE_UPDATE_METHOD = IotDeviceMessageMethodEnum.STATE_UPDATE.getMethod(); |
| 22 | 23 | ||
| 23 | @Override | 24 | @Override |
| 24 | public IotSceneRuleTriggerTypeEnum getSupportedTriggerType() { | 25 | public IotSceneRuleTriggerTypeEnum getSupportedTriggerType() { |
| @@ -68,4 +69,5 @@ public class DeviceStateUpdateTriggerMatcher extends AbstractIotSceneRuleTrigger | @@ -68,4 +69,5 @@ public class DeviceStateUpdateTriggerMatcher extends AbstractIotSceneRuleTrigger | ||
| 68 | public int getPriority() { | 69 | public int getPriority() { |
| 69 | return 10; // 高优先级 | 70 | return 10; // 高优先级 |
| 70 | } | 71 | } |
| 72 | + | ||
| 71 | } | 73 | } |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/scene/matcher/IotSceneRuleTriggerMatcher.java
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/scene/matcher/IotSceneRuleTriggerMatcherManager.java
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/scene/matcher/TimerTriggerMatcher.java