设备mqtt收发数据

This commit is contained in:
2025-07-30 17:13:57 +08:00
parent ac353b1078
commit a119ccc8d6
13 changed files with 238 additions and 115 deletions

View File

@ -9,7 +9,7 @@ public interface MqttMessageRule {
* 获取命令类型
* @return 命令类型
*/
Integer getCommandType();
String getCommandType();
/**
* 执行处理
* @param context 处理上下文

View File

@ -13,11 +13,12 @@ import java.util.List;
public class MqttRuleEngine {
private final LinkedHashMap<Integer, MqttMessageRule> rulesMap = new LinkedHashMap<>();
private final LinkedHashMap<String, MqttMessageRule> rulesMap = new LinkedHashMap<>();
public MqttRuleEngine(List<MqttMessageRule> rules) {
// 按优先级排序
rules.sort(Comparator.comparing(MqttMessageRule::getPriority));
rules.forEach(rule -> rulesMap.put(rule.getCommandType(), rule));
rules.forEach(rule -> rulesMap.put(rule.getCommandType(), rule)
);
}
/**
@ -27,7 +28,7 @@ public class MqttRuleEngine {
*/
public boolean executeRule(MqttRuleContext context) {
int commandType = context.getCommandType();
MqttMessageRule mqttMessageRule = rulesMap.get(commandType);
MqttMessageRule mqttMessageRule = rulesMap.get("Light_"+commandType);
if (mqttMessageRule != null) {
mqttMessageRule.execute(context);
return true;