fix: 盐度取值错误,问题彻底解决。

This commit is contained in:
tianyongbao
2026-04-10 14:03:17 +08:00
parent 93fcd79f0b
commit 0011245a32

View File

@@ -118,6 +118,7 @@ public class AmqpMessageHandlerImpl implements AmqpMessageHandler {
// 使用 DeviceDataHandler 处理数据(包括存储和报警) // 使用 DeviceDataHandler 处理数据(包括存储和报警)
try { try {
// 转换 items 格式:{"dissolvedOxygen": {"value": 7.82, "time": xxx}} -> {"dissolvedOxygen": 7.82} // 转换 items 格式:{"dissolvedOxygen": {"value": 7.82, "time": xxx}} -> {"dissolvedOxygen": 7.82}
// 保留原始字段名不做任何映射convertToSensorData 已兼容多种字段名格式
JSONObject params = new JSONObject(JSONConfig.create().setIgnoreCase(false)); JSONObject params = new JSONObject(JSONConfig.create().setIgnoreCase(false));
if (items != null) { if (items != null) {
for (String key : items.keySet()) { for (String key : items.keySet()) {
@@ -126,14 +127,11 @@ public class AmqpMessageHandlerImpl implements AmqpMessageHandler {
JSONObject itemObj = (JSONObject) itemValue; JSONObject itemObj = (JSONObject) itemValue;
// 提取 value 字段 // 提取 value 字段
if (itemObj.containsKey("value")) { if (itemObj.containsKey("value")) {
// 字段名映射currentTemperature -> temperature, dosat -> saturability params.set(key, itemObj.get("value"));
String mappedKey = mapFieldName(key);
params.set(mappedKey, itemObj.get("value"));
} }
} else { } else {
// 如果不是嵌套格式,直接使用 // 如果不是嵌套格式,直接使用
String mappedKey = mapFieldName(key); params.set(key, itemValue);
params.set(mappedKey, itemValue);
} }
} }
} }
@@ -150,31 +148,6 @@ public class AmqpMessageHandlerImpl implements AmqpMessageHandler {
log.error("使用 DeviceDataHandler 处理属性数据失败", e); log.error("使用 DeviceDataHandler 处理属性数据失败", e);
} }
} }
/**
* 字段名映射:将阿里云字段名映射为应用字段名
*/
private String mapFieldName(String fieldName) {
switch (fieldName) {
case "currentTemperature":
return "temperature";
case "dosat":
return "saturability";
case "Treference":
return "treference";
case "Tfluorescence":
return "tfluorescence";
case "Tcorrect":
return "tcorrect";
case "Tsignal":
return "tsignal";
case "salinitySet":
return "salinity";
default:
// 其他字段名保持原始大小写,不做转换
return fieldName;
}
}
/** /**
* 处理从 Topic 判断的属性消息(飞燕平台原始格式) * 处理从 Topic 判断的属性消息(飞燕平台原始格式)