fix: 开关数据状态变化,bug修复。

This commit is contained in:
tianyongbao
2026-03-22 19:27:22 +08:00
parent ada48d0d77
commit 5d9510f934
2 changed files with 11 additions and 9 deletions

View File

@@ -2,6 +2,7 @@ package com.intc.iot.handler;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONArray; import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONConfig;
import cn.hutool.json.JSONObject; import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import com.intc.iot.domain.AquMapMessageWarnCallNotice; import com.intc.iot.domain.AquMapMessageWarnCallNotice;
@@ -163,7 +164,7 @@ public class DeviceDataHandler {
*/ */
public void handlePropertyPost(String topic, String payload) { public void handlePropertyPost(String topic, String payload) {
try { try {
JSONObject data = JSONUtil.parseObj(payload); JSONObject data = new JSONObject(payload, JSONConfig.create().setIgnoreCase(false));
// 解析飞燕平台消息格式 // 解析飞燕平台消息格式
JSONObject params = data.getJSONObject("params"); JSONObject params = data.getJSONObject("params");
@@ -196,7 +197,7 @@ public class DeviceDataHandler {
if (isController) { if (isController) {
// 判断数据类型(开关数据和传感器数据不会同时出现) // 判断数据类型(开关数据和传感器数据不会同时出现)
if (hasSwitchData(params)) { if (hasSwitchData(params)) {
// 开关数据:更新MySQL的开关状态和电压电流 // 开关数据:更新开关状态和电压电流
handleSwitchData(deviceName, params); handleSwitchData(deviceName, params);
} else if (hasSensorData(params)) { } else if (hasSensorData(params)) {
// 传感器数据写入TDengine // 传感器数据写入TDengine
@@ -252,7 +253,7 @@ public class DeviceDataHandler {
*/ */
public void handleEventPost(String topic, String payload) { public void handleEventPost(String topic, String payload) {
try { try {
JSONObject data = JSONUtil.parseObj(payload); JSONObject data = new JSONObject(payload, JSONConfig.create().setIgnoreCase(false));
JSONObject params = data.getJSONObject("params"); JSONObject params = data.getJSONObject("params");

View File

@@ -1,5 +1,6 @@
package com.intc.iot.service.impl; package com.intc.iot.service.impl;
import cn.hutool.json.JSONConfig;
import cn.hutool.json.JSONObject; import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import com.intc.iot.handler.DeviceDataHandler; import com.intc.iot.handler.DeviceDataHandler;
@@ -31,7 +32,7 @@ public class AmqpMessageHandlerImpl implements AmqpMessageHandler {
@Override @Override
public void handleMessage(String message) { public void handleMessage(String message) {
try { try {
JSONObject json = JSONUtil.parseObj(message); JSONObject json = new JSONObject(message, JSONConfig.create().setIgnoreCase(false));
// 检查是否包含 items 字段(设备属性数据) // 检查是否包含 items 字段(设备属性数据)
if (json.containsKey("items")) { if (json.containsKey("items")) {
@@ -117,7 +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}
JSONObject params = new JSONObject(); JSONObject params = new JSONObject(JSONConfig.create().setIgnoreCase(false));
if (items != null) { if (items != null) {
for (String key : items.keySet()) { for (String key : items.keySet()) {
Object itemValue = items.get(key); Object itemValue = items.get(key);
@@ -140,7 +141,7 @@ public class AmqpMessageHandlerImpl implements AmqpMessageHandler {
// 构造 topic 格式:/sys/{ProductKey}/{DeviceName}/thing/event/property/post // 构造 topic 格式:/sys/{ProductKey}/{DeviceName}/thing/event/property/post
String topic = String.format("/sys/%s/%s/thing/event/property/post", productKey, deviceName); 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("method", "thing.event.property.post");
message.set("params", params); message.set("params", params);
@@ -170,8 +171,8 @@ public class AmqpMessageHandlerImpl implements AmqpMessageHandler {
case "salinitySet": case "salinitySet":
return "salinity"; return "salinity";
default: default:
// 其他字段名保持不变(转为小写) // 其他字段名保持原始大小写,不做转换
return fieldName.toLowerCase(); return fieldName;
} }
} }
@@ -209,7 +210,7 @@ public class AmqpMessageHandlerImpl implements AmqpMessageHandler {
// 构造 topic 格式:/sys/{ProductKey}/{DeviceName}/thing/event/{EventIdentifier}/post // 构造 topic 格式:/sys/{ProductKey}/{DeviceName}/thing/event/{EventIdentifier}/post
String topic = String.format("/sys/%s/%s/thing/event/%s/post", productKey, deviceName, identifier); 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("method", "thing.event." + identifier + ".post");
message.set("params", value); message.set("params", value);