review:【iot 物联网】场景联动相关实现
This commit is contained in:
parent
7d911760b6
commit
887bf175af
@ -64,17 +64,5 @@ public enum IotSceneRuleTriggerTypeEnum implements ArrayValuable<Integer> {
|
|||||||
public static IotSceneRuleTriggerTypeEnum typeOf(Integer type) {
|
public static IotSceneRuleTriggerTypeEnum typeOf(Integer type) {
|
||||||
return ArrayUtil.firstMatch(item -> item.getType().equals(type), values());
|
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -29,21 +29,18 @@ public class IotSceneRuleMatcherManager {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 触发器匹配器映射表
|
* 触发器匹配器映射表
|
||||||
* Key: 触发器类型枚举
|
|
||||||
* Value: 对应的匹配器实例
|
|
||||||
*/
|
*/
|
||||||
private final Map<IotSceneRuleTriggerTypeEnum, IotSceneRuleTriggerMatcher> triggerMatchers;
|
private final Map<IotSceneRuleTriggerTypeEnum, IotSceneRuleTriggerMatcher> triggerMatchers;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 条件匹配器映射表
|
* 条件匹配器映射表
|
||||||
* Key: 条件类型枚举
|
|
||||||
* Value: 对应的匹配器实例
|
|
||||||
*/
|
*/
|
||||||
private final Map<IotSceneRuleConditionTypeEnum, IotSceneRuleConditionMatcher> conditionMatchers;
|
private final Map<IotSceneRuleConditionTypeEnum, IotSceneRuleConditionMatcher> conditionMatchers;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 所有匹配器列表(按优先级排序)
|
* 所有匹配器列表(按优先级排序)
|
||||||
*/
|
*/
|
||||||
|
// TODO @puhui999:貌似 local variable 也可以
|
||||||
private final List<IotSceneRuleMatcher> allMatchers;
|
private final List<IotSceneRuleMatcher> allMatchers;
|
||||||
|
|
||||||
public IotSceneRuleMatcherManager(List<IotSceneRuleMatcher> matchers) {
|
public IotSceneRuleMatcherManager(List<IotSceneRuleMatcher> matchers) {
|
||||||
@ -152,13 +149,13 @@ public class IotSceneRuleMatcherManager {
|
|||||||
log.warn("[isConditionMatched][conditionType({}) 未知的条件类型]", condition.getType());
|
log.warn("[isConditionMatched][conditionType({}) 未知的条件类型]", condition.getType());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
IotSceneRuleConditionMatcher matcher = conditionMatchers.get(conditionType);
|
IotSceneRuleConditionMatcher matcher = conditionMatchers.get(conditionType);
|
||||||
if (matcher == null) {
|
if (matcher == null) {
|
||||||
log.warn("[isConditionMatched][conditionType({}) 没有对应的匹配器]", conditionType);
|
log.warn("[isConditionMatched][conditionType({}) 没有对应的匹配器]", conditionType);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 执行匹配逻辑
|
||||||
try {
|
try {
|
||||||
return matcher.isMatched(message, condition);
|
return matcher.isMatched(message, condition);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -174,12 +171,15 @@ public class IotSceneRuleMatcherManager {
|
|||||||
* @return 条件类型枚举
|
* @return 条件类型枚举
|
||||||
*/
|
*/
|
||||||
private IotSceneRuleConditionTypeEnum findConditionTypeEnum(Integer typeValue) {
|
private IotSceneRuleConditionTypeEnum findConditionTypeEnum(Integer typeValue) {
|
||||||
|
// TODO @puhui999:是不是搞到枚举类里?
|
||||||
return Arrays.stream(IotSceneRuleConditionTypeEnum.values())
|
return Arrays.stream(IotSceneRuleConditionTypeEnum.values())
|
||||||
.filter(type -> type.getType().equals(typeValue))
|
.filter(type -> type.getType().equals(typeValue))
|
||||||
.findFirst()
|
.findFirst()
|
||||||
.orElse(null);
|
.orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO @puhui999:下面两个方法,是不是也可以删除哈?
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取所有支持的触发器类型
|
* 获取所有支持的触发器类型
|
||||||
*
|
*
|
||||||
|
|||||||
@ -123,6 +123,7 @@ public class CurrentTimeConditionMatcher implements IotSceneRuleConditionMatcher
|
|||||||
isDateTimeOperator(operatorEnum);
|
isDateTimeOperator(operatorEnum);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO @puhui999:switch 兼容下 jdk8
|
||||||
/**
|
/**
|
||||||
* 匹配日期时间(时间戳)
|
* 匹配日期时间(时间戳)
|
||||||
* 直接实现时间戳比较逻辑
|
* 直接实现时间戳比较逻辑
|
||||||
|
|||||||
@ -22,6 +22,7 @@ public class DevicePropertyConditionMatcher implements IotSceneRuleConditionMatc
|
|||||||
return IotSceneRuleConditionTypeEnum.DEVICE_PROPERTY;
|
return IotSceneRuleConditionTypeEnum.DEVICE_PROPERTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO @puhui999:matches 会不会更好?参考的 org.hamcrest.Matcher jdk 接口
|
||||||
@Override
|
@Override
|
||||||
public boolean isMatched(IotDeviceMessage message, IotSceneRuleDO.TriggerCondition condition) {
|
public boolean isMatched(IotDeviceMessage message, IotSceneRuleDO.TriggerCondition condition) {
|
||||||
// 1.1 基础参数校验
|
// 1.1 基础参数校验
|
||||||
|
|||||||
@ -31,6 +31,7 @@ public class DeviceServiceInvokeTriggerMatcherTest extends BaseMockitoUnitTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testGetSupportedTriggerType() {
|
public void testGetSupportedTriggerType() {
|
||||||
// when & then
|
// when & then
|
||||||
|
// TODO @puhui999:单测按照现有项目的注释风格哈;类似 // 调用;// 断言
|
||||||
assertEquals(IotSceneRuleTriggerTypeEnum.DEVICE_SERVICE_INVOKE, matcher.getSupportedTriggerType());
|
assertEquals(IotSceneRuleTriggerTypeEnum.DEVICE_SERVICE_INVOKE, matcher.getSupportedTriggerType());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user