|
@@ -1,5 +1,6 @@
|
|
|
package org.jeecg.modules.mqtt.component;
|
|
|
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import org.eclipse.paho.client.mqttv3.*;
|
|
|
import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
|
|
@@ -13,6 +14,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
@@ -131,7 +133,7 @@ public class PushCallback implements MqttCallback {
|
|
|
for (String item : tagmap.keySet()) {
|
|
|
Map<String, Object> valuemap = (Map<String, Object>) tagmap.get(item);
|
|
|
String value1;
|
|
|
- if (valuemap.get("value") instanceof Integer) {
|
|
|
+ if (valuemap.get("value") instanceof Integer || valuemap.get("value") instanceof BigDecimal) {
|
|
|
value1 = String.valueOf(valuemap.get("value"));
|
|
|
} else {
|
|
|
value1 = (String) valuemap.get("value");
|
|
@@ -139,7 +141,12 @@ public class PushCallback implements MqttCallback {
|
|
|
|
|
|
IotedgeCollectData iotedgeCollectData = new IotedgeCollectData();
|
|
|
iotedgeCollectData.setGroupid(jsonObject.get("g_id").toString());
|
|
|
- iotedgeCollectData.setPid(jsonObject.get("p_id").toString());
|
|
|
+ if (ObjectUtil.isNotNull(jsonObject.get("prj_id"))){
|
|
|
+ iotedgeCollectData.setPid(jsonObject.get("prj_id").toString());
|
|
|
+ }
|
|
|
+ if (ObjectUtil.isNotNull(jsonObject.get("p_id"))){
|
|
|
+ iotedgeCollectData.setPid(jsonObject.get("p_id").toString());
|
|
|
+ }
|
|
|
iotedgeCollectData.setDevice(jsonObject.get("d_id").toString());
|
|
|
iotedgeCollectData.setTime(jsonObject.get("ts").toString());
|
|
|
iotedgeCollectData.setService(key);
|
|
@@ -151,6 +158,7 @@ public class PushCallback implements MqttCallback {
|
|
|
}
|
|
|
IIotedgeCollectDataService dataService = new IotedgeCollectDataServiceImpl();
|
|
|
dataService.saveBatch(list);
|
|
|
+ logger.info("数据入库成功");
|
|
|
} catch (Exception e){
|
|
|
logger.error(String.valueOf(e));
|
|
|
}
|