修改延时任务存最后一条设备信息的逻辑

feasure
xce 2026-01-18 17:52:41 +08:00
parent d6cfe99710
commit 9fc3b1d372
1 changed files with 4 additions and 5 deletions

View File

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