Преглед изворни кода

新增地区经纬度字段

woody пре 1 година
родитељ
комит
fa737d02a9

+ 10 - 0
framework-location/src/main/java/com/chelvc/framework/location/Address.java

@@ -30,6 +30,16 @@ public class Address implements Serializable {
      */
     private String name;
 
+    /**
+     * 经度
+     */
+    private Double longitude;
+
+    /**
+     * 维度
+     */
+    private Double latitude;
+
     /**
      * 省
      */

+ 2 - 2
framework-location/src/main/java/com/chelvc/framework/location/support/JuheLocationResponse.java

@@ -34,7 +34,7 @@ public class JuheLocationResponse implements Serializable {
     /**
      * 地址信息
      */
-    private Location result;
+    private Position result;
 
     /**
      * 位置信息
@@ -43,7 +43,7 @@ public class JuheLocationResponse implements Serializable {
     @SuperBuilder
     @NoArgsConstructor
     @AllArgsConstructor
-    public static class Location implements Serializable {
+    public static class Position implements Serializable {
         /**
          * 省
          */

+ 2 - 2
framework-location/src/main/java/com/chelvc/framework/location/support/JuheMobileHandler.java

@@ -66,8 +66,8 @@ public class JuheMobileHandler implements MobileHandler {
             log.warn("Juhe locate failed: {}", response);
             return null;
         }
-        String province = ObjectUtils.ifNull(response.getResult(), JuheLocationResponse.Location::getProvince);
-        String city = ObjectUtils.ifNull(response.getResult(), JuheLocationResponse.Location::getCity);
+        String province = ObjectUtils.ifNull(response.getResult(), JuheLocationResponse.Position::getProvince);
+        String city = ObjectUtils.ifNull(response.getResult(), JuheLocationResponse.Position::getCity);
         String address = Stream.of(province, city).filter(StringUtils::nonEmpty).collect(Collectors.joining());
         return StringUtils.ifEmpty(address, (String) null);
     }

+ 15 - 14
framework-location/src/main/java/com/chelvc/framework/location/support/TencentLocationHandler.java

@@ -5,6 +5,7 @@ import java.util.stream.Collectors;
 import java.util.stream.Stream;
 
 import com.chelvc.framework.base.model.Region;
+import com.chelvc.framework.base.util.ObjectUtils;
 import com.chelvc.framework.base.util.StringUtils;
 import com.chelvc.framework.location.Address;
 import com.chelvc.framework.location.Area;
@@ -70,28 +71,28 @@ public class TencentLocationHandler implements LocationHandler {
             log.warn("Tencent locate failed: {}", response);
             return null;
         }
-        TencentLocationResponse.Location location = response.getResult().getLocation();
-        if (!Region.isRegion(location.getAdcode())) {
-            log.warn("Tencent locate adcode invalid: {}", location.getAdcode());
+        TencentLocationResponse.Position position = response.getResult().getPosition();
+        if (!Region.isRegion(position.getAdcode())) {
+            log.warn("Tencent locate adcode invalid: {}", position.getAdcode());
             return null;
         }
 
         // 构建地址信息
-        Region region = Objects.requireNonNull(Region.of(location.getAdcode()));
-        Address address = Address.builder().id(region.getCode()).build();
-        address.setName(
-                Stream.of(location.getProvince(), location.getCity(), location.getDistrict())
-                        .filter(name -> !StringUtils.isEmpty(name)).collect(Collectors.joining("·"))
-        );
-        address.setProvince(
-                Area.builder().id(region.getProvince().getCode()).name(location.getProvince()).build()
-        );
+        Region region = Objects.requireNonNull(Region.of(position.getAdcode()));
+        TencentLocationResponse.Location location = response.getResult().getLocation();
+        Double longitude = ObjectUtils.ifNull(location, TencentLocationResponse.Location::getLongitude);
+        Double latitude = ObjectUtils.ifNull(location, TencentLocationResponse.Location::getLatitude);
+        Address address = Address.builder().id(region.getCode()).longitude(longitude).latitude(latitude).build();
+        address.setName(Stream.of(position.getProvince(), position.getCity(), position.getDistrict()).filter(
+                name -> !StringUtils.isEmpty(name)).collect(Collectors.joining("·")
+        ));
+        address.setProvince(Area.builder().id(region.getProvince().getCode()).name(position.getProvince()).build());
         Region city = region.getCity();
         if (city != null) {
-            address.setCity(Area.builder().id(city.getCode()).name(location.getCity()).build());
+            address.setCity(Area.builder().id(city.getCode()).name(position.getCity()).build());
         }
         if (region.getType() == Region.Type.DISTRICT) {
-            address.setDistrict(Area.builder().id(region.getCode()).name(location.getDistrict()).build());
+            address.setDistrict(Area.builder().id(region.getCode()).name(position.getDistrict()).build());
         }
         return address;
     }

+ 28 - 2
framework-location/src/main/java/com/chelvc/framework/location/support/TencentLocationResponse.java

@@ -42,21 +42,47 @@ public class TencentLocationResponse implements Serializable {
     @NoArgsConstructor
     @AllArgsConstructor
     public static class Result implements Serializable {
+        /**
+         * 定位信息
+         */
+        private Location location;
+
         /**
          * 位置信息
          */
         @JsonProperty("ad_info")
-        private Location location;
+        private Position position;
     }
 
     /**
-     * 位信息
+     * 位信息
      */
     @Data
     @SuperBuilder
     @NoArgsConstructor
     @AllArgsConstructor
     public static class Location implements Serializable {
+        /**
+         * 经度
+         */
+        @JsonProperty("lng")
+        private Double longitude;
+
+        /**
+         * 维度
+         */
+        @JsonProperty("lat")
+        private Double latitude;
+    }
+
+    /**
+     * 位置信息
+     */
+    @Data
+    @SuperBuilder
+    @NoArgsConstructor
+    @AllArgsConstructor
+    public static class Position implements Serializable {
         /**
          * 地区编号
          */