sanqi73 пре 1 недеља
родитељ
комит
378c1c44cb
1 измењених фајлова са 21 додато и 6 уклоњено
  1. 21 6
      src/main/java/com/zhiyun/project/item/service/DeviceService.java

+ 21 - 6
src/main/java/com/zhiyun/project/item/service/DeviceService.java

@@ -64,17 +64,32 @@ public class DeviceService extends ServiceImpl<DeviceMapper, Device> {
     }
 
     public int insetDeviceData(JSONObject jsonObject) {
+        if (jsonObject == null || jsonObject.getString("deviceid") == null) {
+            return -1;
+        }
         // 创建 Device 实体对象
         Device device = new Device();
 
         device.setDeviceid(jsonObject.getString("deviceid"));
 
-        device.setLat(jsonObject.getDouble("lat"));
-        device.setLon(jsonObject.getDouble("lon"));
-        device.setX(jsonObject.getDouble("x"));
-        device.setY(jsonObject.getDouble("y"));
-        device.setZ(jsonObject.getDouble("z"));
-        device.setF(jsonObject.getInteger("f"));
+        if(jsonObject.getDouble("lat")!=null)
+            device.setLat(jsonObject.getDouble("lat"));
+
+        if(jsonObject.getDouble("lon")!=null)
+            device.setLon(jsonObject.getDouble("lon"));
+
+        if(jsonObject.getDouble("x")!=null)
+            device.setX(jsonObject.getDouble("x"));
+
+        if(jsonObject.getDouble("y")!=null)
+            device.setX(jsonObject.getDouble("y"));
+
+        if(jsonObject.getDouble("z")!=null)
+            device.setX(jsonObject.getDouble("z"));
+
+        if(jsonObject.getInteger("f")!=null)
+            device.setX(jsonObject.getInteger("f"));
+
 
         // 获取原始经纬度
         if(device.getLat() != null && device.getLat() != null){