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

This commit is contained in:
YunaiV
2025-08-19 23:49:17 +08:00
parent 7d911760b6
commit 887bf175af
5 changed files with 8 additions and 17 deletions

View File

@@ -64,17 +64,5 @@ public enum IotSceneRuleTriggerTypeEnum implements ArrayValuable<Integer> {
public static IotSceneRuleTriggerTypeEnum typeOf(Integer type) {
return ArrayUtil.firstMatch(item -> item.getType().equals(type), values());
}
/**
* 根据类型值查找触发器类型枚举
*
* @param typeValue 类型值
* @return 触发器类型枚举
*/
public static IotSceneRuleTriggerTypeEnum findTriggerTypeEnum(Integer typeValue) {
return Arrays.stream(IotSceneRuleTriggerTypeEnum.values())
.filter(type -> type.getType().equals(typeValue))
.findFirst()
.orElse(null);
}
}

View File

@@ -29,21 +29,18 @@ public class IotSceneRuleMatcherManager {
/**
* 触发器匹配器映射表
* Key: 触发器类型枚举
* Value: 对应的匹配器实例
*/
private final Map<IotSceneRuleTriggerTypeEnum, IotSceneRuleTriggerMatcher> triggerMatchers;
/**
* 条件匹配器映射表
* Key: 条件类型枚举
* Value: 对应的匹配器实例
*/
private final Map<IotSceneRuleConditionTypeEnum, IotSceneRuleConditionMatcher> conditionMatchers;
/**
* 所有匹配器列表(按优先级排序)
*/
// TODO @puhui999貌似 local variable 也可以
private final List<IotSceneRuleMatcher> allMatchers;
public IotSceneRuleMatcherManager(List<IotSceneRuleMatcher> matchers) {
@@ -152,13 +149,13 @@ public class IotSceneRuleMatcherManager {
log.warn("[isConditionMatched][conditionType({}) 未知的条件类型]", condition.getType());
return false;
}
IotSceneRuleConditionMatcher matcher = conditionMatchers.get(conditionType);
if (matcher == null) {
log.warn("[isConditionMatched][conditionType({}) 没有对应的匹配器]", conditionType);
return false;
}
// 执行匹配逻辑
try {
return matcher.isMatched(message, condition);
} catch (Exception e) {
@@ -174,12 +171,15 @@ public class IotSceneRuleMatcherManager {
* @return 条件类型枚举
*/
private IotSceneRuleConditionTypeEnum findConditionTypeEnum(Integer typeValue) {
// TODO @puhui999是不是搞到枚举类里
return Arrays.stream(IotSceneRuleConditionTypeEnum.values())
.filter(type -> type.getType().equals(typeValue))
.findFirst()
.orElse(null);
}
// TODO @puhui999下面两个方法是不是也可以删除哈
/**
* 获取所有支持的触发器类型
*

View File

@@ -123,6 +123,7 @@ public class CurrentTimeConditionMatcher implements IotSceneRuleConditionMatcher
isDateTimeOperator(operatorEnum);
}
// TODO @puhui999switch 兼容下 jdk8
/**
* 匹配日期时间(时间戳)
* 直接实现时间戳比较逻辑

View File

@@ -22,6 +22,7 @@ public class DevicePropertyConditionMatcher implements IotSceneRuleConditionMatc
return IotSceneRuleConditionTypeEnum.DEVICE_PROPERTY;
}
// TODO @puhui999matches 会不会更好?参考的 org.hamcrest.Matcher jdk 接口
@Override
public boolean isMatched(IotDeviceMessage message, IotSceneRuleDO.TriggerCondition condition) {
// 1.1 基础参数校验

View File

@@ -31,6 +31,7 @@ public class DeviceServiceInvokeTriggerMatcherTest extends BaseMockitoUnitTest {
@Test
public void testGetSupportedTriggerType() {
// when & then
// TODO @puhui999单测按照现有项目的注释风格哈类似 // 调用;// 断言
assertEquals(IotSceneRuleTriggerTypeEnum.DEVICE_SERVICE_INVOKE, matcher.getSupportedTriggerType());
}