refactor: 【IoT 物联网】修复设备属性条件匹配器设计问题并重构属性值提取逻辑
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package cn.iocoder.yudao.module.iot.service.rule.scene.matcher.condition;
|
||||
|
||||
|
||||
import cn.iocoder.yudao.module.iot.core.mq.message.IotDeviceMessage;
|
||||
import cn.iocoder.yudao.module.iot.core.util.IotDeviceMessageUtils;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotSceneRuleDO;
|
||||
@@ -7,6 +8,7 @@ import cn.iocoder.yudao.module.iot.enums.rule.IotSceneRuleConditionTypeEnum;
|
||||
import cn.iocoder.yudao.module.iot.service.rule.scene.matcher.IotSceneRuleMatcherHelper;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
||||
/**
|
||||
* 设备属性条件匹配器
|
||||
* <p>
|
||||
@@ -43,10 +45,10 @@ public class DevicePropertyConditionMatcher implements IotSceneRuleConditionMatc
|
||||
return false;
|
||||
}
|
||||
|
||||
// 2.1. 获取属性值
|
||||
Object propertyValue = message.getParams();
|
||||
// 2.1. 获取属性值 - 使用工具类方法正确提取属性值
|
||||
Object propertyValue = IotDeviceMessageUtils.extractPropertyValue(message, condition.getIdentifier());
|
||||
if (propertyValue == null) {
|
||||
IotSceneRuleMatcherHelper.logConditionMatchFailure(message, condition, "消息中属性值为空");
|
||||
IotSceneRuleMatcherHelper.logConditionMatchFailure(message, condition, "消息中属性值为空或未找到指定属性");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package cn.iocoder.yudao.module.iot.service.rule.scene.matcher.condition;
|
||||
|
||||
import cn.iocoder.yudao.module.iot.core.mq.message.IotDeviceMessage;
|
||||
import cn.iocoder.yudao.module.iot.core.util.IotDeviceMessageUtils;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotSceneRuleDO;
|
||||
import cn.iocoder.yudao.module.iot.enums.rule.IotSceneRuleConditionTypeEnum;
|
||||
import cn.iocoder.yudao.module.iot.service.rule.scene.matcher.IotSceneRuleMatcherHelper;
|
||||
@@ -35,8 +36,9 @@ public class DeviceStateConditionMatcher implements IotSceneRuleConditionMatcher
|
||||
return false;
|
||||
}
|
||||
|
||||
// 2.1 获取设备状态值
|
||||
Object stateValue = message.getParams();
|
||||
// 2.1 获取设备状态值 - 使用工具类方法正确提取状态值
|
||||
// 对于设备状态条件,状态值通过 getIdentifier 获取(实际是从 params.state 字段)
|
||||
String stateValue = IotDeviceMessageUtils.getIdentifier(message);
|
||||
if (stateValue == null) {
|
||||
IotSceneRuleMatcherHelper.logConditionMatchFailure(message, condition, "消息中设备状态值为空");
|
||||
return false;
|
||||
|
||||
@@ -52,10 +52,10 @@ public class DevicePropertyPostTriggerMatcher implements IotSceneRuleTriggerMatc
|
||||
return false;
|
||||
}
|
||||
|
||||
// 2.1 获取属性值
|
||||
Object propertyValue = message.getParams();
|
||||
// 2.1 获取属性值 - 使用工具类方法正确提取属性值
|
||||
Object propertyValue = IotDeviceMessageUtils.extractPropertyValue(message, trigger.getIdentifier());
|
||||
if (propertyValue == null) {
|
||||
IotSceneRuleMatcherHelper.logTriggerMatchFailure(message, trigger, "消息中属性值为空");
|
||||
IotSceneRuleMatcherHelper.logTriggerMatchFailure(message, trigger, "消息中属性值为空或未找到指定属性");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.iot.service.rule.scene.matcher.trigger;
|
||||
|
||||
import cn.iocoder.yudao.module.iot.core.enums.IotDeviceMessageMethodEnum;
|
||||
import cn.iocoder.yudao.module.iot.core.mq.message.IotDeviceMessage;
|
||||
import cn.iocoder.yudao.module.iot.core.util.IotDeviceMessageUtils;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotSceneRuleDO;
|
||||
import cn.iocoder.yudao.module.iot.enums.rule.IotSceneRuleTriggerTypeEnum;
|
||||
import cn.iocoder.yudao.module.iot.service.rule.scene.matcher.IotSceneRuleMatcherHelper;
|
||||
@@ -43,16 +44,17 @@ public class DeviceStateUpdateTriggerMatcher implements IotSceneRuleTriggerMatch
|
||||
return false;
|
||||
}
|
||||
|
||||
// 2.1 获取设备状态值
|
||||
Object stateValue = message.getParams();
|
||||
if (stateValue == null) {
|
||||
// 2.1 获取设备状态值 - 使用工具类方法正确提取状态值
|
||||
// 对于状态更新消息,状态值通过 getIdentifier 获取(实际是从 params.state 字段)
|
||||
String stateIdentifier = IotDeviceMessageUtils.getIdentifier(message);
|
||||
if (stateIdentifier == null) {
|
||||
IotSceneRuleMatcherHelper.logTriggerMatchFailure(message, trigger, "消息中设备状态值为空");
|
||||
return false;
|
||||
}
|
||||
|
||||
// 2.2 使用条件评估器进行匹配
|
||||
// TODO @puhui999: 状态匹配重新实现
|
||||
boolean matched = IotSceneRuleMatcherHelper.evaluateCondition(stateValue, trigger.getOperator(), trigger.getValue());
|
||||
// 状态值通常是字符串或数字,直接使用标识符作为状态值
|
||||
boolean matched = IotSceneRuleMatcherHelper.evaluateCondition(stateIdentifier, trigger.getOperator(), trigger.getValue());
|
||||
if (matched) {
|
||||
IotSceneRuleMatcherHelper.logTriggerMatchSuccess(message, trigger);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user