Explorar o código

优化订阅新增设备信息mqtt消息,增加字段为空的判断

james hai 3 semanas
pai
achega
0af1c58346

+ 22 - 6
data-transfer/data-transfer-biz/src/main/java/com/usky/transfer/service/mqtt/add/Add.java

@@ -23,6 +23,7 @@ import org.springframework.stereotype.Service;
 import java.time.LocalDateTime;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Objects;
 
 @Slf4j
 @Service("add")
@@ -37,13 +38,12 @@ public class Add implements MqttStrategy {
     private DmpDeviceStatusService dmpDeviceStatusService;
 
     public String disposeMessage(MqttBaseVO mqttBaseVO){
-        String[] topics = mqttBaseVO.getTopic().toString().split(",");
+        String[] topics = mqttBaseVO.getTopic().toString().split("/");
         String topic_deviceUUID = topics[3];
         String deviceInfoStr = mqttBaseVO.getData().toString();
         JSONObject deviceInfoJson = JSONObject.parseObject(deviceInfoStr);
         String productCode = deviceInfoJson.get("productCode").toString();
         String deviceId = deviceInfoJson.get("deviceId").toString();
-        String deviceUUID = deviceInfoJson.get("deviceUUID").toString();
         Integer categoryType = Integer.valueOf(deviceInfoJson.get("categoryType").toString());
 
         //判断上报数据对应产品是否注册,如未注册则为非法
@@ -68,7 +68,15 @@ public class Add implements MqttStrategy {
             DmpDevice dmpDeviceInfo = new DmpDevice();
             ProductMapVO productMapVO = productMapList.get(productCode);
             dmpDeviceInfo.setDeviceId(deviceId);
-            dmpDeviceInfo.setDeviceName("");
+            if(Objects.nonNull(deviceInfoJson.get("deviceName"))){
+                dmpDeviceInfo.setDeviceName(deviceInfoJson.get("deviceName").toString());
+            }
+            if(Objects.nonNull(deviceInfoJson.get("simCode"))){
+                dmpDeviceInfo.setSimCode(deviceInfoJson.get("simCode").toString());
+            }
+            if(Objects.nonNull(deviceInfoJson.get("installAddress"))){
+                dmpDeviceInfo.setInstallAddress(deviceInfoJson.get("installAddress").toString());
+            }
             dmpDeviceInfo.setDeviceType(productMapVO.getDeviceType());
             dmpDeviceInfo.setProductId(productMapVO.getProductId());
             dmpDeviceInfo.setProductCode(productCode);
@@ -76,7 +84,7 @@ public class Add implements MqttStrategy {
             dmpDeviceInfo.setCreatedTime(LocalDateTime.now());
             dmpDeviceInfo.setTenantId(productMapVO.getTenantId());
             dmpDeviceInfo.setServiceStatus(1);
-            dmpDeviceInfo.setDeviceUuid(deviceUUID);
+            dmpDeviceInfo.setDeviceUuid(deviceInfoJson.get("deviceUuid").toString());
             dmpDeviceInfo.setCategoryType(categoryType);
             if(categoryType == 3){
                 dmpDeviceInfo.setGatewayUuid(topic_deviceUUID);
@@ -103,7 +111,15 @@ public class Add implements MqttStrategy {
                 DmpDevice dmpDeviceInfo = new DmpDevice();
                 ProductMapVO productMapVO = productMapList.get(productCode);
                 dmpDeviceInfo.setDeviceId(deviceId);
-                dmpDeviceInfo.setDeviceName("");
+                if(Objects.nonNull(deviceInfoJson.get("deviceName"))){
+                    dmpDeviceInfo.setDeviceName(deviceInfoJson.get("deviceName").toString());
+                }
+                if(Objects.nonNull(deviceInfoJson.get("simCode"))){
+                    dmpDeviceInfo.setSimCode(deviceInfoJson.get("simCode").toString());
+                }
+                if(Objects.nonNull(deviceInfoJson.get("installAddress"))){
+                    dmpDeviceInfo.setInstallAddress(deviceInfoJson.get("installAddress").toString());
+                }
                 dmpDeviceInfo.setDeviceType(productMapVO.getDeviceType());
                 dmpDeviceInfo.setProductId(productMapVO.getProductId());
                 dmpDeviceInfo.setProductCode(productCode);
@@ -111,7 +127,7 @@ public class Add implements MqttStrategy {
                 dmpDeviceInfo.setCreatedTime(LocalDateTime.now());
                 dmpDeviceInfo.setTenantId(productMapVO.getTenantId());
                 dmpDeviceInfo.setServiceStatus(1);
-                dmpDeviceInfo.setDeviceUuid(deviceUUID);
+                dmpDeviceInfo.setDeviceUuid(deviceInfoJson.get("deviceUuid").toString());
                 dmpDeviceInfo.setCategoryType(categoryType);
                 if(categoryType == 3){
                     dmpDeviceInfo.setGatewayUuid(topic_deviceUUID);