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 03b3bc1..5d60727 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 @@ -2,6 +2,7 @@ package com.intc.iot.handler; import cn.hutool.core.util.StrUtil; import cn.hutool.json.JSONArray; +import cn.hutool.json.JSONConfig; import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; import com.intc.iot.domain.AquMapMessageWarnCallNotice; @@ -163,7 +164,7 @@ public class DeviceDataHandler { */ public void handlePropertyPost(String topic, String payload) { try { - JSONObject data = JSONUtil.parseObj(payload); + JSONObject data = new JSONObject(payload, JSONConfig.create().setIgnoreCase(false)); // 解析飞燕平台消息格式 JSONObject params = data.getJSONObject("params"); @@ -196,7 +197,7 @@ public class DeviceDataHandler { if (isController) { // 判断数据类型(开关数据和传感器数据不会同时出现) if (hasSwitchData(params)) { - // 开关数据:更新MySQL的开关状态和电压电流 + // 开关数据:更新开关状态和电压电流 handleSwitchData(deviceName, params); } else if (hasSensorData(params)) { // 传感器数据:写入TDengine @@ -252,7 +253,7 @@ public class DeviceDataHandler { */ public void handleEventPost(String topic, String payload) { try { - JSONObject data = JSONUtil.parseObj(payload); + JSONObject data = new JSONObject(payload, JSONConfig.create().setIgnoreCase(false)); JSONObject params = data.getJSONObject("params"); diff --git a/intc-modules/intc-iot/src/main/java/com/intc/iot/service/impl/AmqpMessageHandlerImpl.java b/intc-modules/intc-iot/src/main/java/com/intc/iot/service/impl/AmqpMessageHandlerImpl.java index fc0570e..d2c336d 100644 --- a/intc-modules/intc-iot/src/main/java/com/intc/iot/service/impl/AmqpMessageHandlerImpl.java +++ b/intc-modules/intc-iot/src/main/java/com/intc/iot/service/impl/AmqpMessageHandlerImpl.java @@ -1,5 +1,6 @@ package com.intc.iot.service.impl; +import cn.hutool.json.JSONConfig; import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; import com.intc.iot.handler.DeviceDataHandler; @@ -31,7 +32,7 @@ public class AmqpMessageHandlerImpl implements AmqpMessageHandler { @Override public void handleMessage(String message) { try { - JSONObject json = JSONUtil.parseObj(message); + JSONObject json = new JSONObject(message, JSONConfig.create().setIgnoreCase(false)); // 检查是否包含 items 字段(设备属性数据) if (json.containsKey("items")) { @@ -117,7 +118,7 @@ public class AmqpMessageHandlerImpl implements AmqpMessageHandler { // 使用 DeviceDataHandler 处理数据(包括存储和报警) try { // 转换 items 格式:{"dissolvedOxygen": {"value": 7.82, "time": xxx}} -> {"dissolvedOxygen": 7.82} - JSONObject params = new JSONObject(); + JSONObject params = new JSONObject(JSONConfig.create().setIgnoreCase(false)); if (items != null) { for (String key : items.keySet()) { Object itemValue = items.get(key); @@ -140,7 +141,7 @@ public class AmqpMessageHandlerImpl implements AmqpMessageHandler { // 构造 topic 格式:/sys/{ProductKey}/{DeviceName}/thing/event/property/post String topic = String.format("/sys/%s/%s/thing/event/property/post", productKey, deviceName); // 构造飞燕平台消息格式 - JSONObject message = new JSONObject(); + JSONObject message = new JSONObject(JSONConfig.create().setIgnoreCase(false)); message.set("method", "thing.event.property.post"); message.set("params", params); @@ -170,8 +171,8 @@ public class AmqpMessageHandlerImpl implements AmqpMessageHandler { case "salinitySet": return "salinity"; default: - // 其他字段名保持不变(转为小写) - return fieldName.toLowerCase(); + // 其他字段名保持原始大小写,不做转换 + return fieldName; } } @@ -209,7 +210,7 @@ public class AmqpMessageHandlerImpl implements AmqpMessageHandler { // 构造 topic 格式:/sys/{ProductKey}/{DeviceName}/thing/event/{EventIdentifier}/post String topic = String.format("/sys/%s/%s/thing/event/%s/post", productKey, deviceName, identifier); // 构造飞燕平台消息格式 - JSONObject message = new JSONObject(); + JSONObject message = new JSONObject(JSONConfig.create().setIgnoreCase(false)); message.set("method", "thing.event." + identifier + ".post"); message.set("params", value);