diff --git a/agri-framework/src/main/java/com/agri/framework/interceptor/MqttMessageHandler.java b/agri-framework/src/main/java/com/agri/framework/interceptor/MqttMessageHandler.java index cfde2de..9b6e8c3 100644 --- a/agri-framework/src/main/java/com/agri/framework/interceptor/MqttMessageHandler.java +++ b/agri-framework/src/main/java/com/agri/framework/interceptor/MqttMessageHandler.java @@ -342,12 +342,11 @@ public class MqttMessageHandler implements SmartLifecycle { for (String validCode : VALID_FUNC_CODES) { if (!payloadObj.containsKey(validCode)) { isValidStatus = false; + log.debug("【设备状态包】结构不合法(非8个功能码),跳过Redis写入,deviceId={};payload={}", deviceId, payload); break; } } - if (!isValidStatus) { - log.debug("【设备状态包】结构不合法(非8个功能码),跳过Redis写入,deviceId={};payload={}", deviceId, payload); - } else if(hasAutoOffTask(deviceId)){ + if(hasAutoOffTask(deviceId) && isValidStatus){ // ✅ 8个功能码状态包:无条件写device:latest:{deviceId},避免自动关读不到最新状态 stringRedisTemplate.opsForValue().set( "device:latest:" + deviceId, @@ -469,7 +468,7 @@ public class MqttMessageHandler implements SmartLifecycle { String deviceTopic = "dtu/" + deviceId + "/down"; //todo - mqttMessageSender.publish(deviceTopic, down.toJSONString()); + // mqttMessageSender.publish(deviceTopic, down.toJSONString()); log.info("【自动关任务】检测仍在运行,已下发关闭:deviceId={}, funcType={}, payload={}", deviceId, funcType, down.toJSONString()); } else { log.info("【自动关任务】检测未运行或状态未知,跳过关闭:deviceId={}, funcType={}, current={}", deviceId, funcType, current); @@ -538,7 +537,7 @@ public class MqttMessageHandler implements SmartLifecycle { // 4. 转发指令到设备 String deviceTopic = "dtu/" + deviceId + "/down"; //todo - mqttMessageSender.publish(deviceTopic, payload); + // mqttMessageSender.publish(deviceTopic, payload); log.info("【指令转发】前端{} → 设备{}的{}功能", clientId, deviceId, funcType); }