Commit 378cf1e997611e9330ab33ba8244f65b2bace0a3
1 parent
93aaffdd
perf:【IoT 物联网】场景规则匹配优化
Showing
6 changed files
with
2 additions
and
128 deletions
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/enums/rule/IotSceneRuleConditionLevelEnum.java deleted
| 1 | -package cn.iocoder.yudao.module.iot.enums.rule; | ||
| 2 | - | ||
| 3 | -import lombok.AllArgsConstructor; | ||
| 4 | -import lombok.Getter; | ||
| 5 | - | ||
| 6 | -/** | ||
| 7 | - * IoT 场景规则条件层级枚举 | ||
| 8 | - * <p> | ||
| 9 | - * 用于区分主条件(触发器级别)和子条件(条件分组级别) | ||
| 10 | - * | ||
| 11 | - * @author HUIHUI | ||
| 12 | - */ | ||
| 13 | -@AllArgsConstructor | ||
| 14 | -@Getter | ||
| 15 | -public enum IotSceneRuleConditionLevelEnum { | ||
| 16 | - | ||
| 17 | - /** | ||
| 18 | - * 主条件 - 触发器级别的条件 | ||
| 19 | - * 用于判断触发器本身是否匹配(如消息类型、设备标识等) | ||
| 20 | - */ | ||
| 21 | - PRIMARY(1, "主条件"), | ||
| 22 | - | ||
| 23 | - /** | ||
| 24 | - * 子条件 - 条件分组级别的条件 | ||
| 25 | - * 用于判断具体的业务条件(如设备状态、属性值、时间条件等) | ||
| 26 | - */ | ||
| 27 | - SECONDARY(2, "子条件"); | ||
| 28 | - | ||
| 29 | - /** | ||
| 30 | - * 条件层级 | ||
| 31 | - */ | ||
| 32 | - private final Integer level; | ||
| 33 | - | ||
| 34 | - /** | ||
| 35 | - * 条件层级名称 | ||
| 36 | - */ | ||
| 37 | - private final String name; | ||
| 38 | - | ||
| 39 | - /** | ||
| 40 | - * 根据层级值获取枚举 | ||
| 41 | - * | ||
| 42 | - * @param level 层级值 | ||
| 43 | - * @return 条件层级枚举 | ||
| 44 | - */ | ||
| 45 | - public static IotSceneRuleConditionLevelEnum levelOf(Integer level) { | ||
| 46 | - if (level == null) { | ||
| 47 | - return null; | ||
| 48 | - } | ||
| 49 | - for (IotSceneRuleConditionLevelEnum levelEnum : values()) { | ||
| 50 | - if (levelEnum.getLevel().equals(level)) { | ||
| 51 | - return levelEnum; | ||
| 52 | - } | ||
| 53 | - } | ||
| 54 | - return null; | ||
| 55 | - } | ||
| 56 | - | ||
| 57 | - /** | ||
| 58 | - * 判断是否为主条件 | ||
| 59 | - * | ||
| 60 | - * @return 是否为主条件 | ||
| 61 | - */ | ||
| 62 | - public boolean isPrimary() { | ||
| 63 | - return this == PRIMARY; | ||
| 64 | - } | ||
| 65 | - | ||
| 66 | - /** | ||
| 67 | - * 判断是否为子条件 | ||
| 68 | - * | ||
| 69 | - * @return 是否为子条件 | ||
| 70 | - */ | ||
| 71 | - public boolean isSecondary() { | ||
| 72 | - return this == SECONDARY; | ||
| 73 | - } | ||
| 74 | -} |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/scene/matcher/CurrentTimeConditionMatcher.java
| @@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.iot.service.rule.scene.matcher; | @@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.iot.service.rule.scene.matcher; | ||
| 3 | import cn.hutool.core.util.StrUtil; | 3 | import cn.hutool.core.util.StrUtil; |
| 4 | import cn.iocoder.yudao.module.iot.core.mq.message.IotDeviceMessage; | 4 | import cn.iocoder.yudao.module.iot.core.mq.message.IotDeviceMessage; |
| 5 | import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotSceneRuleDO; | 5 | import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotSceneRuleDO; |
| 6 | -import cn.iocoder.yudao.module.iot.enums.rule.IotSceneRuleConditionLevelEnum; | ||
| 7 | import cn.iocoder.yudao.module.iot.enums.rule.IotSceneRuleConditionTypeEnum; | 6 | import cn.iocoder.yudao.module.iot.enums.rule.IotSceneRuleConditionTypeEnum; |
| 8 | import lombok.extern.slf4j.Slf4j; | 7 | import lombok.extern.slf4j.Slf4j; |
| 9 | import org.springframework.stereotype.Component; | 8 | import org.springframework.stereotype.Component; |
| @@ -44,11 +43,6 @@ public class CurrentTimeConditionMatcher extends AbstractIotSceneRuleMatcher { | @@ -44,11 +43,6 @@ public class CurrentTimeConditionMatcher extends AbstractIotSceneRuleMatcher { | ||
| 44 | } | 43 | } |
| 45 | 44 | ||
| 46 | @Override | 45 | @Override |
| 47 | - public IotSceneRuleConditionLevelEnum getSupportedConditionLevel() { | ||
| 48 | - return IotSceneRuleConditionLevelEnum.SECONDARY; | ||
| 49 | - } | ||
| 50 | - | ||
| 51 | - @Override | ||
| 52 | public boolean isMatched(IotDeviceMessage message, IotSceneRuleDO.TriggerCondition condition) { | 46 | public boolean isMatched(IotDeviceMessage message, IotSceneRuleDO.TriggerCondition condition) { |
| 53 | // 1. 基础参数校验 | 47 | // 1. 基础参数校验 |
| 54 | if (!isBasicConditionValid(condition)) { | 48 | if (!isBasicConditionValid(condition)) { |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/scene/matcher/DevicePropertyConditionMatcher.java
| @@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.iot.service.rule.scene.matcher; | @@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.iot.service.rule.scene.matcher; | ||
| 3 | import cn.iocoder.yudao.module.iot.core.mq.message.IotDeviceMessage; | 3 | import cn.iocoder.yudao.module.iot.core.mq.message.IotDeviceMessage; |
| 4 | import cn.iocoder.yudao.module.iot.core.util.IotDeviceMessageUtils; | 4 | import cn.iocoder.yudao.module.iot.core.util.IotDeviceMessageUtils; |
| 5 | import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotSceneRuleDO; | 5 | import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotSceneRuleDO; |
| 6 | -import cn.iocoder.yudao.module.iot.enums.rule.IotSceneRuleConditionLevelEnum; | ||
| 7 | import cn.iocoder.yudao.module.iot.enums.rule.IotSceneRuleConditionTypeEnum; | 6 | import cn.iocoder.yudao.module.iot.enums.rule.IotSceneRuleConditionTypeEnum; |
| 8 | import org.springframework.stereotype.Component; | 7 | import org.springframework.stereotype.Component; |
| 9 | 8 | ||
| @@ -28,11 +27,6 @@ public class DevicePropertyConditionMatcher extends AbstractIotSceneRuleMatcher | @@ -28,11 +27,6 @@ public class DevicePropertyConditionMatcher extends AbstractIotSceneRuleMatcher | ||
| 28 | } | 27 | } |
| 29 | 28 | ||
| 30 | @Override | 29 | @Override |
| 31 | - public IotSceneRuleConditionLevelEnum getSupportedConditionLevel() { | ||
| 32 | - return IotSceneRuleConditionLevelEnum.SECONDARY; | ||
| 33 | - } | ||
| 34 | - | ||
| 35 | - @Override | ||
| 36 | public boolean isMatched(IotDeviceMessage message, IotSceneRuleDO.TriggerCondition condition) { | 30 | public boolean isMatched(IotDeviceMessage message, IotSceneRuleDO.TriggerCondition condition) { |
| 37 | // 1. 基础参数校验 | 31 | // 1. 基础参数校验 |
| 38 | if (!isBasicConditionValid(condition)) { | 32 | if (!isBasicConditionValid(condition)) { |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/scene/matcher/DeviceStateConditionMatcher.java
| @@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.iot.service.rule.scene.matcher; | @@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.iot.service.rule.scene.matcher; | ||
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.module.iot.core.mq.message.IotDeviceMessage; | 3 | import cn.iocoder.yudao.module.iot.core.mq.message.IotDeviceMessage; |
| 4 | import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotSceneRuleDO; | 4 | import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotSceneRuleDO; |
| 5 | -import cn.iocoder.yudao.module.iot.enums.rule.IotSceneRuleConditionLevelEnum; | ||
| 6 | import cn.iocoder.yudao.module.iot.enums.rule.IotSceneRuleConditionTypeEnum; | 5 | import cn.iocoder.yudao.module.iot.enums.rule.IotSceneRuleConditionTypeEnum; |
| 7 | import org.springframework.stereotype.Component; | 6 | import org.springframework.stereotype.Component; |
| 8 | 7 | ||
| @@ -27,11 +26,6 @@ public class DeviceStateConditionMatcher extends AbstractIotSceneRuleMatcher { | @@ -27,11 +26,6 @@ public class DeviceStateConditionMatcher extends AbstractIotSceneRuleMatcher { | ||
| 27 | } | 26 | } |
| 28 | 27 | ||
| 29 | @Override | 28 | @Override |
| 30 | - public IotSceneRuleConditionLevelEnum getSupportedConditionLevel() { | ||
| 31 | - return IotSceneRuleConditionLevelEnum.SECONDARY; | ||
| 32 | - } | ||
| 33 | - | ||
| 34 | - @Override | ||
| 35 | public boolean isMatched(IotDeviceMessage message, IotSceneRuleDO.TriggerCondition condition) { | 29 | public boolean isMatched(IotDeviceMessage message, IotSceneRuleDO.TriggerCondition condition) { |
| 36 | // 1. 基础参数校验 | 30 | // 1. 基础参数校验 |
| 37 | if (!isBasicConditionValid(condition)) { | 31 | if (!isBasicConditionValid(condition)) { |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/scene/matcher/IotSceneRuleMatcher.java
| @@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.iot.service.rule.scene.matcher; | @@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.iot.service.rule.scene.matcher; | ||
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.module.iot.core.mq.message.IotDeviceMessage; | 3 | import cn.iocoder.yudao.module.iot.core.mq.message.IotDeviceMessage; |
| 4 | import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotSceneRuleDO; | 4 | import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotSceneRuleDO; |
| 5 | -import cn.iocoder.yudao.module.iot.enums.rule.IotSceneRuleConditionLevelEnum; | ||
| 6 | import cn.iocoder.yudao.module.iot.enums.rule.IotSceneRuleConditionTypeEnum; | 5 | import cn.iocoder.yudao.module.iot.enums.rule.IotSceneRuleConditionTypeEnum; |
| 7 | import cn.iocoder.yudao.module.iot.enums.rule.IotSceneRuleTriggerTypeEnum; | 6 | import cn.iocoder.yudao.module.iot.enums.rule.IotSceneRuleTriggerTypeEnum; |
| 8 | 7 | ||
| @@ -59,15 +58,6 @@ public interface IotSceneRuleMatcher { | @@ -59,15 +58,6 @@ public interface IotSceneRuleMatcher { | ||
| 59 | } | 58 | } |
| 60 | 59 | ||
| 61 | /** | 60 | /** |
| 62 | - * 获取支持的条件层级(仅条件匹配器需要实现) | ||
| 63 | - * | ||
| 64 | - * @return 条件层级枚举,触发器匹配器返回 null | ||
| 65 | - */ | ||
| 66 | - default IotSceneRuleConditionLevelEnum getSupportedConditionLevel() { | ||
| 67 | - return null; | ||
| 68 | - } | ||
| 69 | - | ||
| 70 | - /** | ||
| 71 | * 检查触发器是否匹配消息(仅触发器匹配器需要实现) | 61 | * 检查触发器是否匹配消息(仅触发器匹配器需要实现) |
| 72 | * | 62 | * |
| 73 | * @param message 设备消息 | 63 | * @param message 设备消息 |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/scene/matcher/IotSceneRuleMatcherManager.java
| @@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.iot.service.rule.scene.matcher; | @@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.iot.service.rule.scene.matcher; | ||
| 3 | import cn.hutool.core.collection.CollUtil; | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | import cn.iocoder.yudao.module.iot.core.mq.message.IotDeviceMessage; | 4 | import cn.iocoder.yudao.module.iot.core.mq.message.IotDeviceMessage; |
| 5 | import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotSceneRuleDO; | 5 | import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotSceneRuleDO; |
| 6 | -import cn.iocoder.yudao.module.iot.enums.rule.IotSceneRuleConditionLevelEnum; | ||
| 7 | import cn.iocoder.yudao.module.iot.enums.rule.IotSceneRuleConditionTypeEnum; | 6 | import cn.iocoder.yudao.module.iot.enums.rule.IotSceneRuleConditionTypeEnum; |
| 8 | import cn.iocoder.yudao.module.iot.enums.rule.IotSceneRuleTriggerTypeEnum; | 7 | import cn.iocoder.yudao.module.iot.enums.rule.IotSceneRuleTriggerTypeEnum; |
| 9 | import lombok.extern.slf4j.Slf4j; | 8 | import lombok.extern.slf4j.Slf4j; |
| @@ -107,8 +106,8 @@ public class IotSceneRuleMatcherManager { | @@ -107,8 +106,8 @@ public class IotSceneRuleMatcherManager { | ||
| 107 | 106 | ||
| 108 | // 记录条件匹配器详情 | 107 | // 记录条件匹配器详情 |
| 109 | this.conditionMatcherMap.forEach((type, matcher) -> | 108 | this.conditionMatcherMap.forEach((type, matcher) -> |
| 110 | - log.info("[IotSceneRuleMatcherManager][条件匹配器] 类型: {}, 匹配器: {}, 优先级: {}, 层级: {}", | ||
| 111 | - type, matcher.getMatcherName(), matcher.getPriority(), matcher.getSupportedConditionLevel())); | 109 | + log.info("[IotSceneRuleMatcherManager][条件匹配器] 类型: {}, 匹配器: {}, 优先级: {}", |
| 110 | + type, matcher.getMatcherName(), matcher.getPriority())); | ||
| 112 | } | 111 | } |
| 113 | 112 | ||
| 114 | /** | 113 | /** |
| @@ -233,19 +232,6 @@ public class IotSceneRuleMatcherManager { | @@ -233,19 +232,6 @@ public class IotSceneRuleMatcherManager { | ||
| 233 | } | 232 | } |
| 234 | 233 | ||
| 235 | /** | 234 | /** |
| 236 | - * 根据条件层级获取匹配器列表 | ||
| 237 | - * | ||
| 238 | - * @param level 条件层级 | ||
| 239 | - * @return 匹配器列表 | ||
| 240 | - */ | ||
| 241 | - public List<IotSceneRuleMatcher> getMatchersByLevel(IotSceneRuleConditionLevelEnum level) { | ||
| 242 | - return allMatchers.stream() | ||
| 243 | - .filter(matcher -> matcher.getMatcherType() == IotSceneRuleMatcher.MatcherType.CONDITION) | ||
| 244 | - .filter(matcher -> matcher.getSupportedConditionLevel() == level) | ||
| 245 | - .collect(Collectors.toList()); | ||
| 246 | - } | ||
| 247 | - | ||
| 248 | - /** | ||
| 249 | * 获取所有匹配器的统计信息 | 235 | * 获取所有匹配器的统计信息 |
| 250 | * | 236 | * |
| 251 | * @return 统计信息映射表 | 237 | * @return 统计信息映射表 |
| @@ -258,15 +244,6 @@ public class IotSceneRuleMatcherManager { | @@ -258,15 +244,6 @@ public class IotSceneRuleMatcherManager { | ||
| 258 | statistics.put("supportedTriggerTypes", getSupportedTriggerTypes()); | 244 | statistics.put("supportedTriggerTypes", getSupportedTriggerTypes()); |
| 259 | statistics.put("supportedConditionTypes", getSupportedConditionTypes()); | 245 | statistics.put("supportedConditionTypes", getSupportedConditionTypes()); |
| 260 | 246 | ||
| 261 | - // 按层级统计条件匹配器 | ||
| 262 | - Map<IotSceneRuleConditionLevelEnum, Long> levelStats = allMatchers.stream() | ||
| 263 | - .filter(matcher -> matcher.getMatcherType() == IotSceneRuleMatcher.MatcherType.CONDITION) | ||
| 264 | - .collect(Collectors.groupingBy( | ||
| 265 | - IotSceneRuleMatcher::getSupportedConditionLevel, | ||
| 266 | - Collectors.counting() | ||
| 267 | - )); | ||
| 268 | - statistics.put("conditionLevelStatistics", levelStats); | ||
| 269 | - | ||
| 270 | // 触发器匹配器详情 | 247 | // 触发器匹配器详情 |
| 271 | Map<String, Object> triggerMatcherDetails = new HashMap<>(); | 248 | Map<String, Object> triggerMatcherDetails = new HashMap<>(); |
| 272 | triggerMatcherMap.forEach((type, matcher) -> { | 249 | triggerMatcherMap.forEach((type, matcher) -> { |
| @@ -284,7 +261,6 @@ public class IotSceneRuleMatcherManager { | @@ -284,7 +261,6 @@ public class IotSceneRuleMatcherManager { | ||
| 284 | Map<String, Object> detail = new HashMap<>(); | 261 | Map<String, Object> detail = new HashMap<>(); |
| 285 | detail.put("matcherName", matcher.getMatcherName()); | 262 | detail.put("matcherName", matcher.getMatcherName()); |
| 286 | detail.put("priority", matcher.getPriority()); | 263 | detail.put("priority", matcher.getPriority()); |
| 287 | - detail.put("level", matcher.getSupportedConditionLevel()); | ||
| 288 | detail.put("enabled", matcher.isEnabled()); | 264 | detail.put("enabled", matcher.isEnabled()); |
| 289 | conditionMatcherDetails.put(type.name(), detail); | 265 | conditionMatcherDetails.put(type.name(), detail); |
| 290 | }); | 266 | }); |