perf:【IoT 物联网】场景规则匹配优化
This commit is contained in:
@@ -18,9 +18,6 @@ import java.util.Arrays;
|
|||||||
@Getter
|
@Getter
|
||||||
public enum IotSceneRuleTriggerTypeEnum implements ArrayValuable<Integer> {
|
public enum IotSceneRuleTriggerTypeEnum implements ArrayValuable<Integer> {
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
DEVICE(1), // 设备触发 // TODO @puhui999:@芋艿:这个可以作废
|
|
||||||
|
|
||||||
// TODO @芋艿:后续“对应”部分,要 @下,等包结构梳理完;
|
// TODO @芋艿:后续“对应”部分,要 @下,等包结构梳理完;
|
||||||
/**
|
/**
|
||||||
* 设备上下线变更
|
* 设备上下线变更
|
||||||
|
|||||||
@@ -83,15 +83,19 @@ public interface IotSceneRuleService {
|
|||||||
/**
|
/**
|
||||||
* 【缓存】获得指定设备的场景列表
|
* 【缓存】获得指定设备的场景列表
|
||||||
*
|
*
|
||||||
* @param productKey 产品 Key
|
* @param productId 产品 ID
|
||||||
* @param deviceName 设备名称
|
* @param deviceId 设备 ID
|
||||||
* @return 场景列表
|
* @return 场景列表
|
||||||
*/
|
*/
|
||||||
List<IotSceneRuleDO> getSceneRuleListByProductKeyAndDeviceNameFromCache(String productKey, String deviceName);
|
List<IotSceneRuleDO> getSceneRuleListByProductIdAndDeviceIdFromCache(Long productId, Long deviceId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 基于 {@link IotSceneRuleTriggerTypeEnum#DEVICE} 场景,执行规则场景
|
* 基于 {@link IotSceneRuleTriggerTypeEnum} 场景,执行规则场景
|
||||||
*
|
* 1. {@link IotSceneRuleTriggerTypeEnum#DEVICE_STATE_UPDATE}
|
||||||
|
* 2. {@link IotSceneRuleTriggerTypeEnum#DEVICE_PROPERTY_POST}
|
||||||
|
* {@link IotSceneRuleTriggerTypeEnum#DEVICE_EVENT_POST}
|
||||||
|
* 3. {@link IotSceneRuleTriggerTypeEnum#DEVICE_EVENT_POST}
|
||||||
|
* {@link IotSceneRuleTriggerTypeEnum#DEVICE_SERVICE_INVOKE}
|
||||||
* @param message 消息
|
* @param message 消息
|
||||||
*/
|
*/
|
||||||
void executeSceneRuleByDevice(IotDeviceMessage message);
|
void executeSceneRuleByDevice(IotDeviceMessage message);
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import cn.hutool.core.text.CharPool;
|
|||||||
import cn.hutool.core.util.NumberUtil;
|
import cn.hutool.core.util.NumberUtil;
|
||||||
import cn.hutool.core.util.ObjUtil;
|
import cn.hutool.core.util.ObjUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import cn.hutool.extra.spring.SpringUtil;
|
||||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
import cn.iocoder.yudao.framework.common.util.number.NumberUtils;
|
import cn.iocoder.yudao.framework.common.util.number.NumberUtils;
|
||||||
@@ -30,6 +31,7 @@ import cn.iocoder.yudao.module.iot.framework.job.core.IotSchedulerManager;
|
|||||||
import cn.iocoder.yudao.module.iot.service.device.IotDeviceService;
|
import cn.iocoder.yudao.module.iot.service.device.IotDeviceService;
|
||||||
import cn.iocoder.yudao.module.iot.service.product.IotProductService;
|
import cn.iocoder.yudao.module.iot.service.product.IotProductService;
|
||||||
import cn.iocoder.yudao.module.iot.service.rule.scene.action.IotSceneRuleAction;
|
import cn.iocoder.yudao.module.iot.service.rule.scene.action.IotSceneRuleAction;
|
||||||
|
import cn.iocoder.yudao.module.iot.service.rule.scene.matcher.IotSceneRuleTriggerMatcherManager;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -58,17 +60,16 @@ public class IotSceneRuleServiceImpl implements IotSceneRuleService {
|
|||||||
@Resource
|
@Resource
|
||||||
private IotSceneRuleMapper sceneRuleMapper;
|
private IotSceneRuleMapper sceneRuleMapper;
|
||||||
|
|
||||||
@Resource
|
|
||||||
private List<IotSceneRuleAction> sceneRuleActions;
|
|
||||||
|
|
||||||
@Resource(name = "iotSchedulerManager")
|
@Resource(name = "iotSchedulerManager")
|
||||||
private IotSchedulerManager schedulerManager;
|
private IotSchedulerManager schedulerManager;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private IotProductService productService;
|
private IotProductService productService;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private IotDeviceService deviceService;
|
private IotDeviceService deviceService;
|
||||||
|
@Resource
|
||||||
|
private IotSceneRuleTriggerMatcherManager triggerMatcherManager;
|
||||||
|
@Resource
|
||||||
|
private List<IotSceneRuleAction> sceneRuleActions;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Long createSceneRule(IotSceneRuleSaveReqVO createReqVO) {
|
public Long createSceneRule(IotSceneRuleSaveReqVO createReqVO) {
|
||||||
@@ -139,14 +140,11 @@ public class IotSceneRuleServiceImpl implements IotSceneRuleService {
|
|||||||
// TODO 芋艿,缓存待实现
|
// TODO 芋艿,缓存待实现
|
||||||
@Override
|
@Override
|
||||||
@TenantIgnore // 忽略租户隔离:因为 IotSceneRuleMessageHandler 调用时,一般未传递租户,所以需要忽略
|
@TenantIgnore // 忽略租户隔离:因为 IotSceneRuleMessageHandler 调用时,一般未传递租户,所以需要忽略
|
||||||
public List<IotSceneRuleDO> getSceneRuleListByProductKeyAndDeviceNameFromCache(String productKey, String deviceName) {
|
public List<IotSceneRuleDO> getSceneRuleListByProductIdAndDeviceIdFromCache(Long productId, Long deviceId) {
|
||||||
// TODO @puhui999:一些注释,看看要不要优化下;
|
|
||||||
// 注意:旧的测试代码已删除,因为使用了废弃的数据结构
|
|
||||||
// 如需测试,请使用上面的新结构测试代码示例
|
|
||||||
List<IotSceneRuleDO> list = sceneRuleMapper.selectList();
|
List<IotSceneRuleDO> list = sceneRuleMapper.selectList();
|
||||||
// 只返回启用状态的规则场景
|
// 只返回启用状态的规则场景
|
||||||
List<IotSceneRuleDO> enabledList = filterList(list,
|
List<IotSceneRuleDO> enabledList = filterList(list,
|
||||||
sceneRule -> CommonStatusEnum.ENABLE.getStatus().equals(sceneRule.getStatus()));
|
sceneRule -> CommonStatusEnum.isEnable(sceneRule.getStatus()));
|
||||||
|
|
||||||
// 根据 productKey 和 deviceName 进行匹配
|
// 根据 productKey 和 deviceName 进行匹配
|
||||||
return filterList(enabledList, sceneRule -> {
|
return filterList(enabledList, sceneRule -> {
|
||||||
@@ -156,59 +154,29 @@ public class IotSceneRuleServiceImpl implements IotSceneRuleService {
|
|||||||
|
|
||||||
for (IotSceneRuleDO.Trigger trigger : sceneRule.getTriggers()) {
|
for (IotSceneRuleDO.Trigger trigger : sceneRule.getTriggers()) {
|
||||||
// 检查触发器是否匹配指定的产品和设备
|
// 检查触发器是否匹配指定的产品和设备
|
||||||
if (isMatchProductAndDevice(trigger, productKey, deviceName)) {
|
try {
|
||||||
return true;
|
// 1. 检查产品是否匹配
|
||||||
|
if (trigger.getProductId() == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (trigger.getDeviceId() == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// 检查是否是全部设备的特殊标识
|
||||||
|
if (IotDeviceDO.DEVICE_ID_ALL.equals(trigger.getDeviceId())) {
|
||||||
|
return true; // 匹配所有设备
|
||||||
|
}
|
||||||
|
// 检查具体设备 ID 是否匹配
|
||||||
|
return ObjUtil.equal(productId, trigger.getProductId()) && ObjUtil.equal(deviceId, trigger.getDeviceId());
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.warn("[isMatchProductAndDevice][产品({}) 设备({}) 匹配触发器异常]", productId, deviceId, e);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 检查触发器是否匹配指定的产品和设备
|
|
||||||
*
|
|
||||||
* @param trigger 触发器
|
|
||||||
* @param productKey 产品标识
|
|
||||||
* @param deviceName 设备名称
|
|
||||||
* @return 是否匹配
|
|
||||||
*/
|
|
||||||
private boolean isMatchProductAndDevice(IotSceneRuleDO.Trigger trigger, String productKey, String deviceName) {
|
|
||||||
try {
|
|
||||||
// 1. 检查产品是否匹配
|
|
||||||
if (trigger.getProductId() != null) {
|
|
||||||
// 通过 productKey 获取产品信息
|
|
||||||
IotProductDO product = productService.getProductByProductKey(productKey);
|
|
||||||
if (product == null || !trigger.getProductId().equals(product.getId())) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 2. 检查设备是否匹配
|
|
||||||
if (trigger.getDeviceId() != null) {
|
|
||||||
// 通过 productKey 和 deviceName 获取设备信息
|
|
||||||
IotDeviceDO device = deviceService.getDeviceFromCache(productKey, deviceName);
|
|
||||||
if (device == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 检查是否是全部设备的特殊标识
|
|
||||||
if (IotDeviceDO.DEVICE_ID_ALL.equals(trigger.getDeviceId())) {
|
|
||||||
return true; // 匹配所有设备
|
|
||||||
}
|
|
||||||
|
|
||||||
// 检查具体设备ID是否匹配
|
|
||||||
if (!trigger.getDeviceId().equals(device.getId())) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.warn("[isMatchProductAndDevice][产品({}) 设备({}) 匹配触发器异常]", productKey, deviceName, e);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void executeSceneRuleByDevice(IotDeviceMessage message) {
|
public void executeSceneRuleByDevice(IotDeviceMessage message) {
|
||||||
// TODO @芋艿:这里的 tenantId,通过设备获取;
|
// TODO @芋艿:这里的 tenantId,通过设备获取;
|
||||||
@@ -273,55 +241,95 @@ public class IotSceneRuleServiceImpl implements IotSceneRuleService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 1.3 获取匹配的规则场景
|
// 1.3 获取匹配的规则场景
|
||||||
List<IotSceneRuleDO> sceneRules = getSceneRuleListByProductKeyAndDeviceNameFromCache(
|
List<IotSceneRuleDO> sceneRules = getSceneRuleListByProductIdAndDeviceIdFromCache(
|
||||||
product.getProductKey(), device.getDeviceName());
|
product.getId(), device.getId());
|
||||||
if (CollUtil.isEmpty(sceneRules)) {
|
if (CollUtil.isEmpty(sceneRules)) {
|
||||||
return sceneRules;
|
return sceneRules;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. 匹配 trigger 触发器的条件
|
// 2. 使用重构后的触发器匹配逻辑
|
||||||
return filterList(sceneRules, sceneRule -> {
|
return filterList(sceneRules, sceneRule -> matchSceneRuleTriggers(message, sceneRule));
|
||||||
for (IotSceneRuleDO.Trigger trigger : sceneRule.getTriggers()) {
|
}
|
||||||
// 2.1 检查触发器类型,根据新的枚举值进行匹配
|
|
||||||
// TODO @芋艿:需要根据新的触发器类型枚举进行适配
|
|
||||||
// 原来使用 IotSceneRuleTriggerTypeEnum.DEVICE,新结构可能有不同的类型
|
|
||||||
|
|
||||||
// 2.2 条件分组为空,说明没有匹配的条件,因此不匹配
|
/**
|
||||||
if (CollUtil.isEmpty(trigger.getConditionGroups())) {
|
* 匹配场景规则的所有触发器
|
||||||
return false;
|
*
|
||||||
}
|
* @param message 设备消息
|
||||||
|
* @param sceneRule 场景规则
|
||||||
|
* @return 是否匹配
|
||||||
|
*/
|
||||||
|
private boolean matchSceneRuleTriggers(IotDeviceMessage message, IotSceneRuleDO sceneRule) {
|
||||||
|
if (CollUtil.isEmpty(sceneRule.getTriggers())) {
|
||||||
|
log.debug("[matchSceneRuleTriggers][规则场景({}) 没有配置触发器]", sceneRule.getId());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// 2.3 检查条件分组:分组与分组之间是"或"的关系,条件与条件之间是"且"的关系
|
for (IotSceneRuleDO.Trigger trigger : sceneRule.getTriggers()) {
|
||||||
boolean anyGroupMatched = false;
|
if (matchSingleTrigger(message, trigger, sceneRule)) {
|
||||||
for (List<IotSceneRuleDO.TriggerCondition> conditionGroup : trigger.getConditionGroups()) {
|
log.info("[matchSceneRuleTriggers][消息({}) 匹配到规则场景编号({}) 的触发器({})]",
|
||||||
if (CollUtil.isEmpty(conditionGroup)) {
|
message.getRequestId(), sceneRule.getId(), trigger.getType());
|
||||||
continue;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// 检查当前分组中的所有条件是否都匹配(且关系)
|
/**
|
||||||
boolean allConditionsMatched = true;
|
* 匹配单个触发器
|
||||||
for (IotSceneRuleDO.TriggerCondition condition : conditionGroup) {
|
*
|
||||||
// TODO @芋艿:这里需要实现具体的条件匹配逻辑
|
* @param message 设备消息
|
||||||
// 根据新的 TriggerCondition 结构进行匹配
|
* @param trigger 触发器
|
||||||
if (!isTriggerConditionMatched(message, condition, sceneRule, trigger)) {
|
* @param sceneRule 场景规则(用于日志)
|
||||||
allConditionsMatched = false;
|
* @return 是否匹配
|
||||||
break;
|
*/
|
||||||
}
|
private boolean matchSingleTrigger(IotDeviceMessage message, IotSceneRuleDO.Trigger trigger, IotSceneRuleDO sceneRule) {
|
||||||
}
|
try {
|
||||||
|
// 2. 检查触发器的条件分组
|
||||||
|
return triggerMatcherManager.isMatched(message, trigger) && isTriggerConditionGroupsMatched(message, trigger, sceneRule);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("[matchSingleTrigger][触发器匹配异常] sceneRuleId: {}, triggerType: {}, message: {}",
|
||||||
|
sceneRule.getId(), trigger.getType(), message, e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (allConditionsMatched) {
|
/**
|
||||||
anyGroupMatched = true;
|
* 检查触发器的条件分组是否匹配
|
||||||
break; // 有一个分组匹配即可
|
*
|
||||||
}
|
* @param message 设备消息
|
||||||
}
|
* @param trigger 触发器
|
||||||
|
* @param sceneRule 场景规则(用于日志)
|
||||||
|
* @return 是否匹配
|
||||||
|
*/
|
||||||
|
private boolean isTriggerConditionGroupsMatched(IotDeviceMessage message, IotSceneRuleDO.Trigger trigger, IotSceneRuleDO sceneRule) {
|
||||||
|
// 如果没有条件分组,则认为匹配成功(只依赖基础触发器匹配)
|
||||||
|
if (CollUtil.isEmpty(trigger.getConditionGroups())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if (anyGroupMatched) {
|
// 检查条件分组:分组与分组之间是"或"的关系,条件与条件之间是"且"的关系
|
||||||
log.info("[getMatchedSceneRuleList][消息({}) 匹配到规则场景编号({}) 的触发器({})]", message, sceneRule.getId(), trigger);
|
for (List<IotSceneRuleDO.TriggerCondition> conditionGroup : trigger.getConditionGroups()) {
|
||||||
return true;
|
if (CollUtil.isEmpty(conditionGroup)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查当前分组中的所有条件是否都匹配(且关系)
|
||||||
|
boolean allConditionsMatched = true;
|
||||||
|
for (IotSceneRuleDO.TriggerCondition condition : conditionGroup) {
|
||||||
|
if (!isTriggerConditionMatched(message, condition, sceneRule, trigger)) {
|
||||||
|
allConditionsMatched = false;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
});
|
// 如果当前分组的所有条件都匹配,则整个触发器匹配成功
|
||||||
|
if (allConditionsMatched) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 所有分组都不匹配
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -549,4 +557,8 @@ public class IotSceneRuleServiceImpl implements IotSceneRuleService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private IotSceneRuleServiceImpl getSelf() {
|
||||||
|
return SpringUtil.getBean(IotSceneRuleServiceImpl.class);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -119,4 +119,5 @@ public abstract class AbstractIotSceneRuleTriggerMatcher implements IotSceneRule
|
|||||||
protected void logMatchFailure(IotDeviceMessage message, IotSceneRuleDO.Trigger trigger, String reason) {
|
protected void logMatchFailure(IotDeviceMessage message, IotSceneRuleDO.Trigger trigger, String reason) {
|
||||||
log.debug("[{}][消息({}) 匹配触发器({}) 失败: {}]", getMatcherName(), message.getRequestId(), trigger.getType(), reason);
|
log.debug("[{}][消息({}) 匹配触发器({}) 失败: {}]", getMatcherName(), message.getRequestId(), trigger.getType(), reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package cn.iocoder.yudao.module.iot.service.rule.scene.matcher;
|
package cn.iocoder.yudao.module.iot.service.rule.scene.matcher;
|
||||||
|
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
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.mq.message.IotDeviceMessage;
|
||||||
import cn.iocoder.yudao.module.iot.core.util.IotDeviceMessageUtils;
|
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.dal.dataobject.rule.IotSceneRuleDO;
|
||||||
@@ -20,7 +21,7 @@ public class DeviceEventPostTriggerMatcher extends AbstractIotSceneRuleTriggerMa
|
|||||||
/**
|
/**
|
||||||
* 设备事件上报消息方法
|
* 设备事件上报消息方法
|
||||||
*/
|
*/
|
||||||
private static final String DEVICE_EVENT_POST_METHOD = "thing.event.post";
|
private static final String DEVICE_EVENT_POST_METHOD = IotDeviceMessageMethodEnum.EVENT_POST.getMethod();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IotSceneRuleTriggerTypeEnum getSupportedTriggerType() {
|
public IotSceneRuleTriggerTypeEnum getSupportedTriggerType() {
|
||||||
@@ -72,4 +73,5 @@ public class DeviceEventPostTriggerMatcher extends AbstractIotSceneRuleTriggerMa
|
|||||||
public int getPriority() {
|
public int getPriority() {
|
||||||
return 30; // 中等优先级
|
return 30; // 中等优先级
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package cn.iocoder.yudao.module.iot.service.rule.scene.matcher;
|
package cn.iocoder.yudao.module.iot.service.rule.scene.matcher;
|
||||||
|
|
||||||
|
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.mq.message.IotDeviceMessage;
|
||||||
import cn.iocoder.yudao.module.iot.core.util.IotDeviceMessageUtils;
|
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.dal.dataobject.rule.IotSceneRuleDO;
|
||||||
@@ -19,7 +20,7 @@ public class DevicePropertyPostTriggerMatcher extends AbstractIotSceneRuleTrigge
|
|||||||
/**
|
/**
|
||||||
* 设备属性上报消息方法
|
* 设备属性上报消息方法
|
||||||
*/
|
*/
|
||||||
private static final String DEVICE_PROPERTY_POST_METHOD = "thing.property.post";
|
private static final String DEVICE_PROPERTY_POST_METHOD = IotDeviceMessageMethodEnum.PROPERTY_POST.getMethod();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IotSceneRuleTriggerTypeEnum getSupportedTriggerType() {
|
public IotSceneRuleTriggerTypeEnum getSupportedTriggerType() {
|
||||||
@@ -76,4 +77,5 @@ public class DevicePropertyPostTriggerMatcher extends AbstractIotSceneRuleTrigge
|
|||||||
public int getPriority() {
|
public int getPriority() {
|
||||||
return 20; // 中等优先级
|
return 20; // 中等优先级
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package cn.iocoder.yudao.module.iot.service.rule.scene.matcher;
|
package cn.iocoder.yudao.module.iot.service.rule.scene.matcher;
|
||||||
|
|
||||||
|
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.mq.message.IotDeviceMessage;
|
||||||
import cn.iocoder.yudao.module.iot.core.util.IotDeviceMessageUtils;
|
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.dal.dataobject.rule.IotSceneRuleDO;
|
||||||
@@ -19,7 +20,7 @@ public class DeviceServiceInvokeTriggerMatcher extends AbstractIotSceneRuleTrigg
|
|||||||
/**
|
/**
|
||||||
* 设备服务调用消息方法
|
* 设备服务调用消息方法
|
||||||
*/
|
*/
|
||||||
private static final String DEVICE_SERVICE_INVOKE_METHOD = "thing.service.invoke";
|
private static final String DEVICE_SERVICE_INVOKE_METHOD = IotDeviceMessageMethodEnum.SERVICE_INVOKE.getMethod();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IotSceneRuleTriggerTypeEnum getSupportedTriggerType() {
|
public IotSceneRuleTriggerTypeEnum getSupportedTriggerType() {
|
||||||
@@ -58,4 +59,5 @@ public class DeviceServiceInvokeTriggerMatcher extends AbstractIotSceneRuleTrigg
|
|||||||
public int getPriority() {
|
public int getPriority() {
|
||||||
return 40; // 较低优先级
|
return 40; // 较低优先级
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package cn.iocoder.yudao.module.iot.service.rule.scene.matcher;
|
package cn.iocoder.yudao.module.iot.service.rule.scene.matcher;
|
||||||
|
|
||||||
|
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.mq.message.IotDeviceMessage;
|
||||||
import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotSceneRuleDO;
|
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.enums.rule.IotSceneRuleTriggerTypeEnum;
|
||||||
@@ -18,7 +19,7 @@ public class DeviceStateUpdateTriggerMatcher extends AbstractIotSceneRuleTrigger
|
|||||||
/**
|
/**
|
||||||
* 设备状态更新消息方法
|
* 设备状态更新消息方法
|
||||||
*/
|
*/
|
||||||
private static final String DEVICE_STATE_UPDATE_METHOD = "thing.state.update";
|
private static final String DEVICE_STATE_UPDATE_METHOD = IotDeviceMessageMethodEnum.STATE_UPDATE.getMethod();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IotSceneRuleTriggerTypeEnum getSupportedTriggerType() {
|
public IotSceneRuleTriggerTypeEnum getSupportedTriggerType() {
|
||||||
@@ -68,4 +69,5 @@ public class DeviceStateUpdateTriggerMatcher extends AbstractIotSceneRuleTrigger
|
|||||||
public int getPriority() {
|
public int getPriority() {
|
||||||
return 10; // 高优先级
|
return 10; // 高优先级
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,4 +59,5 @@ public interface IotSceneRuleTriggerMatcher {
|
|||||||
default boolean isEnabled() {
|
default boolean isEnabled() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -147,4 +147,5 @@ public class IotSceneRuleTriggerMatcherManager {
|
|||||||
|
|
||||||
return statistics;
|
return statistics;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,4 +76,5 @@ public class TimerTriggerMatcher extends AbstractIotSceneRuleTriggerMatcher {
|
|||||||
// 定时触发器可以根据配置动态启用/禁用
|
// 定时触发器可以根据配置动态启用/禁用
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user