浏览代码

mqtt采集数据处理修改

丁治程 2 月之前
父节点
当前提交
bc6e9bfdee

+ 9 - 2
jeecg-module-interlock/src/main/java/org/jeecg/modules/mqtt/component/MqttPushClient.java

@@ -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;
@@ -11,6 +12,7 @@ import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
+import java.math.BigDecimal;
 import java.util.ArrayList;
 import java.util.Map;
 import java.util.UUID;
@@ -213,7 +215,7 @@ public class MqttPushClient {
             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");
@@ -221,7 +223,12 @@ public class MqttPushClient {
 
                 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);

+ 10 - 2
jeecg-module-interlock/src/main/java/org/jeecg/modules/mqtt/component/PushCallback.java

@@ -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));
         }