refactor(规则引擎): topic转换失败修复

This commit is contained in:
gx_ma
2026-08-10 14:02:50 +08:00
parent dd7fe18ec8
commit 54a05f34be
2 changed files with 6 additions and 2 deletions

View File

@@ -149,7 +149,11 @@ public class TopicsUtils {
@SneakyThrows @SneakyThrows
public String parseSerialNumber(String topic) { public String parseSerialNumber(String topic) {
String[] values = topic.split("/"); String[] values = topic.split("/");
return values[2]; // 从topic分段中按长度识别设备编号设备编号通常长度>9
return Arrays.stream(values)
.filter(s -> s.length() > 9)
.findFirst()
.orElseGet(() -> values.length > 2 ? values[2] : values[0]);
} }
/** /**

View File

@@ -118,7 +118,7 @@ public class MqttPublish implements MqttHandler {
reportBo.setTopicName(context.getTopic()); reportBo.setTopicName(context.getTopic());
reportBo.setData(context.getPayload().getBytes(StandardCharsets.UTF_8)); reportBo.setData(context.getPayload().getBytes(StandardCharsets.UTF_8));
} }
if (topicName.contains("property")) { if (reportBo.getTopicName().contains("property")) {
deviceReportMessageService.parseReportMsg(reportBo); deviceReportMessageService.parseReportMsg(reportBo);
} }