From 16bd95ea300e5b8f519d29dfd1c30832c44af8d7 Mon Sep 17 00:00:00 2001 From: tianyongbao Date: Fri, 10 Apr 2026 12:06:02 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=9B=90=E5=BA=A6=E5=8F=96=E5=80=BC?= =?UTF-8?q?=E9=94=99=E8=AF=AF=EF=BC=8C=E9=97=AE=E9=A2=98=E8=A7=A3=E5=86=B3?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/intc/iot/handler/DeviceDataHandler.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/intc-modules/intc-iot/src/main/java/com/intc/iot/handler/DeviceDataHandler.java b/intc-modules/intc-iot/src/main/java/com/intc/iot/handler/DeviceDataHandler.java index 802b3f0..ef49ed2 100644 --- a/intc-modules/intc-iot/src/main/java/com/intc/iot/handler/DeviceDataHandler.java +++ b/intc-modules/intc-iot/src/main/java/com/intc/iot/handler/DeviceDataHandler.java @@ -188,8 +188,12 @@ public class DeviceDataHandler { try { JSONObject data = new JSONObject(payload, JSONConfig.create().setIgnoreCase(false)); - // 解析飞燕平台消息格式 - JSONObject params = data.getJSONObject("params"); + // 解析飞燕平台消息格式(保持ignoreCase=false,避免子对象丢失大小写配置) + JSONObject params = null; + Object paramsObj = data.get("params"); + if (paramsObj != null) { + params = new JSONObject(paramsObj.toString(), JSONConfig.create().setIgnoreCase(false)); + } // 从Topic中解析产品Key和设备名称 // Topic格式: /sys/{ProductKey}/{DeviceName}/thing/event/property/post @@ -299,7 +303,12 @@ public class DeviceDataHandler { try { JSONObject data = new JSONObject(payload, JSONConfig.create().setIgnoreCase(false)); - JSONObject params = data.getJSONObject("params"); + // 保持ignoreCase=false,避免子对象丢失大小写配置 + JSONObject params = null; + Object paramsObj = data.get("params"); + if (paramsObj != null) { + params = new JSONObject(paramsObj.toString(), JSONConfig.create().setIgnoreCase(false)); + } // 从Topic中解析产品Key、设备名称和事件标识符 // Topic格式: /sys/{ProductKey}/{DeviceName}/thing/event/{EventIdentifier}/post @@ -2119,6 +2128,8 @@ public class DeviceDataHandler { : params.getDouble("ph"); sensorData.setPh(value); } + // 注意:忽略大小写时 containsKey("salinity") 会误匹配 salinitySet, + // 已在取 params 时设置 ignoreCase=false,精确匹配 "salinity" key,不会取到 salinitySet if (params.containsKey("salinity")) { sensorData.setSalinity(params.getDouble("salinity")); }