forked from dyf/fys-Multi-tenant
设备mqtt收发数据
This commit is contained in:
@ -9,7 +9,7 @@ public interface MqttMessageRule {
|
||||
* 获取命令类型
|
||||
* @return 命令类型
|
||||
*/
|
||||
Integer getCommandType();
|
||||
String getCommandType();
|
||||
/**
|
||||
* 执行处理
|
||||
* @param context 处理上下文
|
||||
|
||||
@ -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;
|
||||
|
||||
Reference in New Issue
Block a user