延时任务获取最新状态,

master
lld 2026-02-01 13:13:58 +08:00
parent f746cdac5c
commit 4aa7aeb8b4
1 changed files with 13 additions and 2 deletions

View File

@ -237,9 +237,10 @@ public class MqttAutoOffManager {
// 设备每10秒上报的状态包{"jm1k":0/1,...} 顶层字段直接取 // 设备每10秒上报的状态包{"jm1k":0/1,...} 顶层字段直接取
Integer current = null; Integer current = null;
String key = getKey(funcType);
try { try {
if (latestObj.containsKey(funcType)) { if (latestObj.containsKey(key)) {
current = latestObj.getIntValue(funcType); current = latestObj.getIntValue(key);
} }
} catch (Exception ignore) { } catch (Exception ignore) {
skipReason = "【自动关任务】最新状态功能码获取失败"; skipReason = "【自动关任务】最新状态功能码获取失败";
@ -353,4 +354,14 @@ public class MqttAutoOffManager {
return json; return json;
} }
public String getKey(String funcType) {
// 边界判断:避免空指针异常和字符串长度不足的异常
if (funcType == null || funcType.length() <= 1) {
return funcType == null ? null : "";
}
// 截取从索引0开始到倒数第二位结束substring的结束索引是开区间不包含自身
return funcType.substring(0, funcType.length() - 1);
}
} }