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); }