소스 검색

Update DeviceService.java

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){