Commit 887bf175affa1c88ebad5870f87a3ade899bd259

Authored by YunaiV
1 parent 7d911760

review:【iot 物联网】场景联动相关实现

yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/enums/rule/IotSceneRuleTriggerTypeEnum.java
... ... @@ -64,17 +64,5 @@ public enum IotSceneRuleTriggerTypeEnum implements ArrayValuable<Integer> {
64 64 public static IotSceneRuleTriggerTypeEnum typeOf(Integer type) {
65 65 return ArrayUtil.firstMatch(item -> item.getType().equals(type), values());
66 66 }
67   - /**
68   - * 根据类型值查找触发器类型枚举
69   - *
70   - * @param typeValue 类型值
71   - * @return 触发器类型枚举
72   - */
73   - public static IotSceneRuleTriggerTypeEnum findTriggerTypeEnum(Integer typeValue) {
74   - return Arrays.stream(IotSceneRuleTriggerTypeEnum.values())
75   - .filter(type -> type.getType().equals(typeValue))
76   - .findFirst()
77   - .orElse(null);
78   - }
79 67  
80 68 }
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/scene/matcher/IotSceneRuleMatcherManager.java
... ... @@ -29,21 +29,18 @@ public class IotSceneRuleMatcherManager {
29 29  
30 30 /**
31 31 * 触发器匹配器映射表
32   - * Key: 触发器类型枚举
33   - * Value: 对应的匹配器实例
34 32 */
35 33 private final Map<IotSceneRuleTriggerTypeEnum, IotSceneRuleTriggerMatcher> triggerMatchers;
36 34  
37 35 /**
38 36 * 条件匹配器映射表
39   - * Key: 条件类型枚举
40   - * Value: 对应的匹配器实例
41 37 */
42 38 private final Map<IotSceneRuleConditionTypeEnum, IotSceneRuleConditionMatcher> conditionMatchers;
43 39  
44 40 /**
45 41 * 所有匹配器列表(按优先级排序)
46 42 */
  43 + // TODO @puhui999:貌似 local variable 也可以
47 44 private final List<IotSceneRuleMatcher> allMatchers;
48 45  
49 46 public IotSceneRuleMatcherManager(List<IotSceneRuleMatcher> matchers) {
... ... @@ -152,13 +149,13 @@ public class IotSceneRuleMatcherManager {
152 149 log.warn("[isConditionMatched][conditionType({}) 未知的条件类型]", condition.getType());
153 150 return false;
154 151 }
155   -
156 152 IotSceneRuleConditionMatcher matcher = conditionMatchers.get(conditionType);
157 153 if (matcher == null) {
158 154 log.warn("[isConditionMatched][conditionType({}) 没有对应的匹配器]", conditionType);
159 155 return false;
160 156 }
161 157  
  158 + // 执行匹配逻辑
162 159 try {
163 160 return matcher.isMatched(message, condition);
164 161 } catch (Exception e) {
... ... @@ -174,12 +171,15 @@ public class IotSceneRuleMatcherManager {
174 171 * @return 条件类型枚举
175 172 */
176 173 private IotSceneRuleConditionTypeEnum findConditionTypeEnum(Integer typeValue) {
  174 + // TODO @puhui999:是不是搞到枚举类里?
177 175 return Arrays.stream(IotSceneRuleConditionTypeEnum.values())
178 176 .filter(type -> type.getType().equals(typeValue))
179 177 .findFirst()
180 178 .orElse(null);
181 179 }
182 180  
  181 + // TODO @puhui999:下面两个方法,是不是也可以删除哈?
  182 +
183 183 /**
184 184 * 获取所有支持的触发器类型
185 185 *
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/scene/matcher/condition/CurrentTimeConditionMatcher.java
... ... @@ -123,6 +123,7 @@ public class CurrentTimeConditionMatcher implements IotSceneRuleConditionMatcher
123 123 isDateTimeOperator(operatorEnum);
124 124 }
125 125  
  126 + // TODO @puhui999:switch 兼容下 jdk8
126 127 /**
127 128 * 匹配日期时间(时间戳)
128 129 * 直接实现时间戳比较逻辑
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/scene/matcher/condition/DevicePropertyConditionMatcher.java
... ... @@ -22,6 +22,7 @@ public class DevicePropertyConditionMatcher implements IotSceneRuleConditionMatc
22 22 return IotSceneRuleConditionTypeEnum.DEVICE_PROPERTY;
23 23 }
24 24  
  25 + // TODO @puhui999:matches 会不会更好?参考的 org.hamcrest.Matcher jdk 接口
25 26 @Override
26 27 public boolean isMatched(IotDeviceMessage message, IotSceneRuleDO.TriggerCondition condition) {
27 28 // 1.1 基础参数校验
... ...
yudao-module-iot/yudao-module-iot-biz/src/test/java/cn/iocoder/yudao/module/iot/service/rule/scene/matcher/trigger/DeviceServiceInvokeTriggerMatcherTest.java
... ... @@ -31,6 +31,7 @@ public class DeviceServiceInvokeTriggerMatcherTest extends BaseMockitoUnitTest {
31 31 @Test
32 32 public void testGetSupportedTriggerType() {
33 33 // when & then
  34 + // TODO @puhui999:单测按照现有项目的注释风格哈;类似 // 调用;// 断言
34 35 assertEquals(IotSceneRuleTriggerTypeEnum.DEVICE_SERVICE_INVOKE, matcher.getSupportedTriggerType());
35 36 }
36 37  
... ...