Browse Source

add null judge

sanqi73 4 weeks ago
parent
commit
d878b25bcb

+ 4 - 5
src/main/java/com/zhiyun/project/item/domain/entity/Device.java

@@ -3,7 +3,6 @@ package com.zhiyun.project.item.domain.entity;
 import lombok.Data;
 
 import java.time.LocalDateTime;
-import java.util.Date;
 
 @Data
 public class Device {
@@ -16,13 +15,13 @@ public class Device {
 
     private Double lon;       // 经度
 
-    private double x;         // x坐标
+    private Double x;         // x坐标
 
-    private double y;         // y坐标
+    private Double y;         // y坐标
 
-    private double z;         // z坐标
+    private Double z;         // z坐标
 
-    private int  f;           // 解算状态
+    private Integer  f;           // 解算状态
 
     private LocalDateTime latestTime;  //最新时间
 

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

@@ -75,27 +75,12 @@ public class DeviceService extends ServiceImpl<DeviceMapper, Device> {
 
         device.setDeviceid(jsonObject.getString("deviceid"));
 
-        if(jsonObject.getDouble("lat")!=null)
-        {device.setLat(jsonObject.getDouble("lat"));
-            System.out.println("dsadasd");}
-
-        else
-            System.out.println("asdadas");
-
-        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"));
+        device.setLat(jsonObject.containsKey("lat") ? jsonObject.getDouble("lat") : null);
+        device.setLon(jsonObject.containsKey("lon") ? jsonObject.getDouble("lon") : null);
+        device.setX(jsonObject.containsKey("x") ? jsonObject.getDouble("x") : null);
+        device.setY(jsonObject.containsKey("y") ? jsonObject.getDouble("y") : null);
+        device.setZ(jsonObject.containsKey("z") ? jsonObject.getDouble("z") : null);
+        device.setF(jsonObject.containsKey("f") ? jsonObject.getInteger("f") : null);
 
 
         // 获取原始经纬度