延时任务获取最新状态,
parent
f746cdac5c
commit
4aa7aeb8b4
|
|
@ -237,9 +237,10 @@ public class MqttAutoOffManager {
|
|||
|
||||
// 设备每10秒上报的状态包:{"jm1k":0/1,...} 顶层字段直接取
|
||||
Integer current = null;
|
||||
String key = getKey(funcType);
|
||||
try {
|
||||
if (latestObj.containsKey(funcType)) {
|
||||
current = latestObj.getIntValue(funcType);
|
||||
if (latestObj.containsKey(key)) {
|
||||
current = latestObj.getIntValue(key);
|
||||
}
|
||||
} catch (Exception ignore) {
|
||||
skipReason = "【自动关任务】最新状态功能码获取失败";
|
||||
|
|
@ -353,4 +354,14 @@ public class MqttAutoOffManager {
|
|||
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);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue