From 54a05f34be0da5cf5e3c28d1e3ab44fc1ca096bb Mon Sep 17 00:00:00 2001 From: gx_ma <1773945958@qq.com> Date: Mon, 10 Aug 2026 14:02:50 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E8=A7=84=E5=88=99=E5=BC=95=E6=93=8E):?= =?UTF-8?q?=20topic=E8=BD=AC=E6=8D=A2=E5=A4=B1=E8=B4=A5=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fastbee/common/utils/gateway/mq/TopicsUtils.java | 6 +++++- .../src/main/java/com/fastbee/mqtt/handler/MqttPublish.java | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/springboot/fastbee-common/src/main/java/com/fastbee/common/utils/gateway/mq/TopicsUtils.java b/springboot/fastbee-common/src/main/java/com/fastbee/common/utils/gateway/mq/TopicsUtils.java index 87895c4d..1e63c799 100644 --- a/springboot/fastbee-common/src/main/java/com/fastbee/common/utils/gateway/mq/TopicsUtils.java +++ b/springboot/fastbee-common/src/main/java/com/fastbee/common/utils/gateway/mq/TopicsUtils.java @@ -149,7 +149,11 @@ public class TopicsUtils { @SneakyThrows public String parseSerialNumber(String topic) { 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]); } /** diff --git a/springboot/fastbee-server/mqtt-broker/src/main/java/com/fastbee/mqtt/handler/MqttPublish.java b/springboot/fastbee-server/mqtt-broker/src/main/java/com/fastbee/mqtt/handler/MqttPublish.java index 359a6e6c..915b8bee 100644 --- a/springboot/fastbee-server/mqtt-broker/src/main/java/com/fastbee/mqtt/handler/MqttPublish.java +++ b/springboot/fastbee-server/mqtt-broker/src/main/java/com/fastbee/mqtt/handler/MqttPublish.java @@ -118,7 +118,7 @@ public class MqttPublish implements MqttHandler { reportBo.setTopicName(context.getTopic()); reportBo.setData(context.getPayload().getBytes(StandardCharsets.UTF_8)); } - if (topicName.contains("property")) { + if (reportBo.getTopicName().contains("property")) { deviceReportMessageService.parseReportMsg(reportBo); }