完善逻辑

master
lld 2026-03-08 20:17:47 +08:00
parent 97da9f0abb
commit 2828c209a1
1 changed files with 8 additions and 8 deletions

View File

@ -88,7 +88,14 @@ public class DeviceStatusHandler {
*/
public void handle(String topic, String payload) {
if (!isJsonObjectLike(payload)) return;
// log.info("【设备处理】JSON解析{}",payloadObj);
// 解析设备ID主题格式为dtu/{deviceId}/up分割后第2个元素是设备ID
String deviceId = extractDeviceId(topic);
if (deviceId == null) return;
String[] segments = topic.split("/");
String action = segments[2];
if ("down".equals(action) || !isJsonObjectLike(payload)) return;
// 第一步解析JSON非有效JSON直接return
JSONObject payloadObj;
try {
@ -102,13 +109,6 @@ public class DeviceStatusHandler {
return;
}
// log.info("【设备处理】JSON解析{}",payloadObj);
// 解析设备ID主题格式为dtu/{deviceId}/up分割后第2个元素是设备ID
String deviceId = extractDeviceId(topic);
if (deviceId == null) return;
String[] segments = topic.split("/");
String action = segments[2];
// 转发消息
forwardPayload(deviceId, payload,payloadObj,action);