From 192a39681fd5256035f36b23b2b9b4ccaef48ee4 Mon Sep 17 00:00:00 2001 From: jkcdev Date: Fri, 23 May 2025 12:56:38 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=9C=B0=E7=90=86=E7=BC=96?= =?UTF-8?q?=E7=A0=81=E6=9C=8D=E5=8A=A1=EF=BC=8C=E5=90=8C=E4=B8=80=E5=9C=A8?= =?UTF-8?q?=E8=BF=90=E7=BB=B4=E6=A8=A1=E5=9D=97=E5=AE=9E=E7=8E=B0=EF=BC=8C?= =?UTF-8?q?=E9=80=9A=E8=BF=87Feign=E8=B0=83=E7=94=A8=EF=BC=8C=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E8=8E=B7=E5=8F=96=E8=AF=A6=E7=BB=86=E5=9C=B0=E5=9D=80?= =?UTF-8?q?=E7=9A=84=E6=96=B9=E6=B3=95=EF=BC=8C=E8=BF=94=E5=9B=9E=E5=86=85?= =?UTF-8?q?=E5=AE=B9=E4=B8=BAjson=EF=BC=8C=E5=8F=AF=E4=BB=A5=E6=A0=B9?= =?UTF-8?q?=E6=8D=AE=E5=AE=9E=E9=99=85=E9=9C=80=E8=A6=81=E5=A2=9E=E5=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../feign/clients/MaintenanceFeignClient.java | 10 ++ .../feign/model/res}/ReqLocationDto.java | 6 +- .../controller/EbikeSystemController.java | 39 ++++-- .../impl/EbikeBikeInfoServiceImpl.java | 4 +- .../ebikemaintenance/utils/GeoCodingUtil.java | 41 +++++- .../cdzy/payment/config/GeoCodingConfig.java | 22 ---- .../controller/EbikeWxPaymentController.java | 3 +- .../service/impl/EbikeRefundServiceImpl.java | 3 +- .../service/impl/WxPayServiceImpl.java | 39 +++--- .../com/cdzy/payment/utils/GeoCodingUtil.java | 121 ------------------ 10 files changed, 110 insertions(+), 178 deletions(-) rename {ebike-maintenance/src/main/java/com/cdzy/ebikemaintenance/model/dto/request => ebike-feign/src/main/java/com/ebike/feign/model/res}/ReqLocationDto.java (81%) delete mode 100644 ebike-payment/src/main/java/com/cdzy/payment/config/GeoCodingConfig.java delete mode 100644 ebike-payment/src/main/java/com/cdzy/payment/utils/GeoCodingUtil.java diff --git a/ebike-feign/src/main/java/com/ebike/feign/clients/MaintenanceFeignClient.java b/ebike-feign/src/main/java/com/ebike/feign/clients/MaintenanceFeignClient.java index 5a7c41e5..ceb5deae 100644 --- a/ebike-feign/src/main/java/com/ebike/feign/clients/MaintenanceFeignClient.java +++ b/ebike-feign/src/main/java/com/ebike/feign/clients/MaintenanceFeignClient.java @@ -2,6 +2,7 @@ package com.ebike.feign.clients; import com.cdzy.common.model.JsonResult; import com.ebike.feign.model.res.ReqEcuSnDto; +import com.ebike.feign.model.res.ReqLocationDto; import com.ebike.feign.model.res.ReqVehicleStatusUpdateDto; import com.ebike.feign.model.rsp.FeignEbikeBikeInfoDto; import com.ebike.feign.model.rsp.RspBikeInfo; @@ -113,4 +114,13 @@ public interface MaintenanceFeignClient { */ @GetMapping("ebikeBikeInfo/getVehicleDetailsByRegionId") JsonResult> getVehicleDetailsByRegionId(@RequestParam(name = "regionId") String regionId); + + /** + * 根据经纬度获取地址 (详细地址) + * + * @param location 经纬度(GCJ02坐标系) + * @return 地址JSON对象 + */ + @PostMapping("system/location2Address2") + JsonResult location2AddressDetails(@RequestBody ReqLocationDto location); } diff --git a/ebike-maintenance/src/main/java/com/cdzy/ebikemaintenance/model/dto/request/ReqLocationDto.java b/ebike-feign/src/main/java/com/ebike/feign/model/res/ReqLocationDto.java similarity index 81% rename from ebike-maintenance/src/main/java/com/cdzy/ebikemaintenance/model/dto/request/ReqLocationDto.java rename to ebike-feign/src/main/java/com/ebike/feign/model/res/ReqLocationDto.java index ec2900fc..c8100f37 100644 --- a/ebike-maintenance/src/main/java/com/cdzy/ebikemaintenance/model/dto/request/ReqLocationDto.java +++ b/ebike-feign/src/main/java/com/ebike/feign/model/res/ReqLocationDto.java @@ -1,4 +1,4 @@ -package com.cdzy.ebikemaintenance.model.dto.request; +package com.ebike.feign.model.res; import lombok.AllArgsConstructor; import lombok.Data; @@ -18,11 +18,11 @@ import java.io.Serializable; @AllArgsConstructor public class ReqLocationDto implements Serializable { /** - * 经度(WGS84) + * 经度(GCJ02) */ private Double longitude; /** - * 纬度(WGS84) + * 纬度(GCJ02) */ private Double latitude; diff --git a/ebike-maintenance/src/main/java/com/cdzy/ebikemaintenance/controller/EbikeSystemController.java b/ebike-maintenance/src/main/java/com/cdzy/ebikemaintenance/controller/EbikeSystemController.java index 97024110..97587e89 100644 --- a/ebike-maintenance/src/main/java/com/cdzy/ebikemaintenance/controller/EbikeSystemController.java +++ b/ebike-maintenance/src/main/java/com/cdzy/ebikemaintenance/controller/EbikeSystemController.java @@ -2,8 +2,7 @@ package com.cdzy.ebikemaintenance.controller; import com.alibaba.fastjson2.JSONObject; import com.cdzy.common.model.JsonResult; -import com.cdzy.common.utils.CoordinateUtil; -import com.cdzy.ebikemaintenance.model.dto.request.ReqLocationDto; +import com.ebike.feign.model.res.ReqLocationDto; import com.cdzy.ebikemaintenance.model.dto.response.ResLocationDto; import com.cdzy.ebikemaintenance.service.EbikeSystemInfoService; import com.cdzy.ebikemaintenance.utils.GeoCodingUtil; @@ -69,7 +68,7 @@ public class EbikeSystemController { /** * 位置地址解析 * - * @param location 经纬度(WGS84坐标系) + * @param location 经纬度(GCJ02坐标系) * @return */ @PostMapping("location2Address") @@ -77,13 +76,37 @@ public class EbikeSystemController { if((location.getLatitude()==null||location.getLongitude()==null)){ return JsonResult.failed("经纬度、GCJ02经纬度不能都为空"); } - // 经纬度转GCJ-02坐标系 - double[] gcj02 = CoordinateUtil.WGS84ToGCJ02(location.getLongitude(), location.getLatitude()); + //// 经纬度转GCJ-02坐标系 + //double[] gcj02 = CoordinateUtil.WGS84ToGCJ02(location.getLongitude(), location.getLatitude()); JSONObject jsonObject = new JSONObject(); - jsonObject.put("lat", gcj02[1]); - jsonObject.put("lng", gcj02[0]); - String address = geoCodingUtil.getLocationToaddress(jsonObject); + jsonObject.put("lat", location.getLatitude()); + jsonObject.put("lng", location.getLongitude()); + String address = geoCodingUtil.getLocationToAddress(jsonObject); + if(address!=null){ + return JsonResult.success("转换成功", address); + } + return JsonResult.failed("转换失败"); + } + + /** + * 位置地址解析 (详细地址) + * + * @param location 经纬度(GCJ02坐标系) + * @return + */ + @PostMapping("location2Address2") + public JsonResult location2AddressDetails(@RequestBody ReqLocationDto location) { + if((location.getLatitude()==null||location.getLongitude()==null)){ + return JsonResult.failed("经纬度、GCJ02经纬度不能都为空"); + } + //// 经纬度转GCJ-02坐标系 + //double[] gcj02 = CoordinateUtil.WGS84ToGCJ02(location.getLongitude(), location.getLatitude()); + + JSONObject jsonObject = new JSONObject(); + jsonObject.put("lat", location.getLatitude()); + jsonObject.put("lng", location.getLongitude()); + JSONObject address = geoCodingUtil.getLocationToAddressDetails(jsonObject); if(address!=null){ return JsonResult.success("转换成功", address); } diff --git a/ebike-maintenance/src/main/java/com/cdzy/ebikemaintenance/service/impl/EbikeBikeInfoServiceImpl.java b/ebike-maintenance/src/main/java/com/cdzy/ebikemaintenance/service/impl/EbikeBikeInfoServiceImpl.java index 1586cc50..3a259edc 100644 --- a/ebike-maintenance/src/main/java/com/cdzy/ebikemaintenance/service/impl/EbikeBikeInfoServiceImpl.java +++ b/ebike-maintenance/src/main/java/com/cdzy/ebikemaintenance/service/impl/EbikeBikeInfoServiceImpl.java @@ -252,7 +252,7 @@ public class EbikeBikeInfoServiceImpl extends ServiceImpl userIds = new ArrayList<>(); diff --git a/ebike-maintenance/src/main/java/com/cdzy/ebikemaintenance/utils/GeoCodingUtil.java b/ebike-maintenance/src/main/java/com/cdzy/ebikemaintenance/utils/GeoCodingUtil.java index b1279099..a3c2a044 100644 --- a/ebike-maintenance/src/main/java/com/cdzy/ebikemaintenance/utils/GeoCodingUtil.java +++ b/ebike-maintenance/src/main/java/com/cdzy/ebikemaintenance/utils/GeoCodingUtil.java @@ -7,7 +7,6 @@ import okhttp3.Request; import okhttp3.Response; import org.springframework.stereotype.Service; -import java.io.IOException; import java.util.Arrays; /** @@ -46,7 +45,7 @@ public class GeoCodingUtil { * @param location 经纬度 * @return 地址 */ - public String getLocationToaddress(JSONObject location) { + public String getLocationToAddress(JSONObject location) { Request request = new Request.Builder() .url(url + "/?"+LOCATION_TO_ADDRESS+"=" + String.format("%f,%f", location.getDouble("lat"), location.getDouble("lng")) + "&key=" + accessKey) .build(); @@ -72,6 +71,44 @@ public class GeoCodingUtil { } } + /** + * 输入经纬度,返回地址明细(含区域ID、县区名)。 + * + * @param location 经纬度 + * @return 地址 + */ + public JSONObject getLocationToAddressDetails(JSONObject location) { + Request request = new Request.Builder() + .url(url + "/?"+LOCATION_TO_ADDRESS+"=" + String.format("%f,%f", location.getDouble("lat"), location.getDouble("lng")) + "&key=" + accessKey) + .build(); + try(Response response = client.newCall(request).execute()) { + if(response.isSuccessful()) { + if (response.body()!= null) { + String result = response.body().string(); + JSONObject jsonObject = JSONObject.parseObject(result); + if (jsonObject.getInteger("status") == 0) { + JSONObject address = new JSONObject(); + String detail = jsonObject.getJSONObject("result").getJSONObject("formatted_addresses").getString("standard_address"); + address.put("detail", detail); + String district = jsonObject.getJSONObject("result").getJSONObject("ad_info").getString("district"); + address.put("district", district); + String adcode = jsonObject.getJSONObject("result").getJSONObject("ad_info").getString("adcode"); + address.put("adcode", adcode); + return address; + } + logError("地址解析失败==>{}", jsonObject.getString("message")); + return null; + } + logError("地址解析失败==>{}", response.message()); + return null; + } + logError("地址解析失败==>{}", response.message()); + return null; + } catch (Exception e) { + logError("地址解析失败==>{}", e.getMessage() + Arrays.toString(e.getStackTrace())); + return null; + } + } /** * 输入地址,返回经纬度(GCJ02)。 diff --git a/ebike-payment/src/main/java/com/cdzy/payment/config/GeoCodingConfig.java b/ebike-payment/src/main/java/com/cdzy/payment/config/GeoCodingConfig.java deleted file mode 100644 index f4f272fd..00000000 --- a/ebike-payment/src/main/java/com/cdzy/payment/config/GeoCodingConfig.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.cdzy.payment.config; - -import com.cdzy.payment.utils.GeoCodingUtil; -import lombok.Getter; -import lombok.Setter; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -@Setter -@Getter -@Configuration -@ConfigurationProperties(prefix = "geo-coding") -public class GeoCodingConfig { - private String apiUrl; - private String accessKey; - - @Bean - public GeoCodingUtil geoCodingUtil() { - return new GeoCodingUtil(apiUrl, accessKey); - } -} diff --git a/ebike-payment/src/main/java/com/cdzy/payment/controller/EbikeWxPaymentController.java b/ebike-payment/src/main/java/com/cdzy/payment/controller/EbikeWxPaymentController.java index 0b304b6f..bd4a967a 100644 --- a/ebike-payment/src/main/java/com/cdzy/payment/controller/EbikeWxPaymentController.java +++ b/ebike-payment/src/main/java/com/cdzy/payment/controller/EbikeWxPaymentController.java @@ -231,6 +231,7 @@ public class EbikeWxPaymentController { */ @PostMapping("/refundOrderRecords") public JsonResult refundOrderRecords(@RequestBody ReqUserQueryDto reqRefundRecordDto) { - + Page list = ebikeRefundService.getRefundOrderRecords(reqRefundRecordDto); + return JsonResult.success(list); } } diff --git a/ebike-payment/src/main/java/com/cdzy/payment/service/impl/EbikeRefundServiceImpl.java b/ebike-payment/src/main/java/com/cdzy/payment/service/impl/EbikeRefundServiceImpl.java index 736a60c5..407acb48 100644 --- a/ebike-payment/src/main/java/com/cdzy/payment/service/impl/EbikeRefundServiceImpl.java +++ b/ebike-payment/src/main/java/com/cdzy/payment/service/impl/EbikeRefundServiceImpl.java @@ -335,6 +335,7 @@ public class EbikeRefundServiceImpl extends ServiceImpl getRefundOrderRecords(ReqUserQueryDto reqRefundRecordDto) { - return null; + + } } diff --git a/ebike-payment/src/main/java/com/cdzy/payment/service/impl/WxPayServiceImpl.java b/ebike-payment/src/main/java/com/cdzy/payment/service/impl/WxPayServiceImpl.java index be9ce625..ca7c5f09 100644 --- a/ebike-payment/src/main/java/com/cdzy/payment/service/impl/WxPayServiceImpl.java +++ b/ebike-payment/src/main/java/com/cdzy/payment/service/impl/WxPayServiceImpl.java @@ -18,7 +18,6 @@ import com.cdzy.payment.model.enums.RefundProcessState; import com.cdzy.payment.service.EbikePaymentService; import com.cdzy.payment.service.EbikeRefundService; import com.cdzy.payment.service.WxPayService; -import com.cdzy.payment.utils.GeoCodingUtil; import com.cdzy.payment.utils.HttpServletUtils; import com.cdzy.payment.utils.MapUtils; import com.cdzy.payment.utils.StringUtils; @@ -26,6 +25,7 @@ import com.ebike.feign.clients.MaintenanceFeignClient; import com.ebike.feign.clients.OperateFeignClient; import com.ebike.feign.clients.OrdersFeignClient; import com.ebike.feign.model.res.ReqEbikeSiteQuery; +import com.ebike.feign.model.res.ReqLocationDto; import com.ebike.feign.model.rsp.*; import com.mybatisflex.core.paginate.Page; import com.wechat.pay.java.core.Config; @@ -90,9 +90,6 @@ public class WxPayServiceImpl implements WxPayService { private MaintenanceFeignClient maintenanceFeignClient; @Resource private OperateFeignClient operateFeignClient; - @Resource - private GeoCodingUtil geoCodingUtil; - @Override public boolean closeOrder(String outTradeNo) { @@ -674,13 +671,16 @@ public class WxPayServiceImpl implements WxPayService { } // 借车地址 if(borrowLocation != null){ - JSONObject location = new JSONObject(); - location.put("lng", borrowLocation[0]); - location.put("lat", borrowLocation[1]); - JSONObject address = geoCodingUtil.getLocationToAddress(location); - if(address!= null){ - borrowingInfo.setBorrowAddress(address.getString("detail")); - order.setStartRegion(address.getString("district")); + ReqLocationDto location = new ReqLocationDto(); + location.setLongitude(borrowLocation[0]); + location.setLatitude(borrowLocation[1]); + JsonResult getAdd = maintenanceFeignClient.location2AddressDetails(location); + if (getAdd.getCode() == Code.SUCCESS) { + JSONObject address = JSON.parseObject(JSONObject.toJSONString(getAdd.getData()), JSONObject.class); + if(address!= null){ + borrowingInfo.setBorrowAddress(address.getString("detail")); + order.setStartRegion(address.getString("district")); + } } } orderInfo.setBorrowingInfo(borrowingInfo); @@ -705,13 +705,16 @@ public class WxPayServiceImpl implements WxPayService { } // 还车地址 if(returnLocation != null){ - JSONObject location = new JSONObject(); - location.put("lng", returnLocation[0]); - location.put("lat", returnLocation[1]); - JSONObject address = geoCodingUtil.getLocationToAddress(location); - if(address!= null){ - returnInfo.setReturnAddress(address.getString("detail")); - order.setEndRegion(address.getString("district")); + ReqLocationDto location = new ReqLocationDto(); + location.setLongitude(returnLocation[0]); + location.setLatitude(returnLocation[1]); + JsonResult getAdd = maintenanceFeignClient.location2AddressDetails(location); + if (getAdd.getCode() == Code.SUCCESS) { + JSONObject address = JSON.parseObject(JSONObject.toJSONString(getAdd.getData()), JSONObject.class); + if(address!= null){ + returnInfo.setReturnAddress(address.getString("detail")); + order.setEndRegion(address.getString("district")); + } } } // 骑行时长 diff --git a/ebike-payment/src/main/java/com/cdzy/payment/utils/GeoCodingUtil.java b/ebike-payment/src/main/java/com/cdzy/payment/utils/GeoCodingUtil.java deleted file mode 100644 index 4bfdf140..00000000 --- a/ebike-payment/src/main/java/com/cdzy/payment/utils/GeoCodingUtil.java +++ /dev/null @@ -1,121 +0,0 @@ -package com.cdzy.payment.utils; - -import com.alibaba.fastjson2.JSONObject; -import lombok.extern.slf4j.Slf4j; -import okhttp3.OkHttpClient; -import okhttp3.Request; -import okhttp3.Response; -import org.springframework.stereotype.Service; - -import java.util.Arrays; - -/** - * 地址解析、反解析工具类。 - * - * @author dingchao - * @date 2025/4/3 - * @modified by: - */ -@Slf4j -@Service -public class GeoCodingUtil { - private final static String LOCATION_TO_ADDRESS = "location"; - private final static String ADDRESS_TO_LOCATION = "address"; - - private final String url; - private final String accessKey; - private final OkHttpClient client; - - /** - * 地理编码工具类构造函数。 - * 目前实现的腾讯地图webservice - * - * @param apiUrl - * @param accessKey - */ - public GeoCodingUtil(String apiUrl, String accessKey) { - this.url = apiUrl; - this.accessKey = accessKey; - this.client = new OkHttpClient(); - } - - /** - * 输入经纬度,返回地址。 - * - * @param location 经纬度 - * @return 地址 - */ - public JSONObject getLocationToAddress(JSONObject location) { - Request request = new Request.Builder() - .url(url + "/?"+LOCATION_TO_ADDRESS+"=" + String.format("%f,%f", location.getDouble("lat"), location.getDouble("lng")) + "&key=" + accessKey) - .build(); - try(Response response = client.newCall(request).execute()) { - if(response.isSuccessful()) { - if (response.body()!= null) { - String result = response.body().string(); - JSONObject jsonObject = JSONObject.parseObject(result); - if (jsonObject.getInteger("status") == 0) { - JSONObject address = new JSONObject(); - String detail = jsonObject.getJSONObject("result").getJSONObject("formatted_addresses").getString("standard_address"); - address.put("detail", detail); - String district = jsonObject.getJSONObject("result").getJSONObject("ad_info").getString("district"); - address.put("district", district); - String adcode = jsonObject.getJSONObject("result").getJSONObject("ad_info").getString("adcode"); - address.put("adcode", adcode); - return address; - } - logError("地址解析失败==>{}", jsonObject.getString("message")); - return null; - } - logError("地址解析失败==>{}", response.message()); - return null; - } - logError("地址解析失败==>{}", response.message()); - return null; - } catch (Exception e) { - logError("地址解析失败==>{}", e.getMessage() + Arrays.toString(e.getStackTrace())); - return null; - } - } - - - /** - * 输入地址,返回经纬度(GCJ02)。 - * - * @param address 地址 - * @return 经纬度 - */ - public JSONObject getAddressToLocation(String address) { - Request request = new Request.Builder() - .url(url + "/?"+ADDRESS_TO_LOCATION+"=" + address + "&key=" + accessKey) - .build(); - try(Response response = client.newCall(request).execute()) { - if(response.isSuccessful()) { - if (response.body() != null) { - String result = response.body().string(); - JSONObject jsonObject = JSONObject.parseObject(result); - if (jsonObject.getInteger("status") == 0) { - return jsonObject.getJSONObject("result").getJSONObject("location"); - }else{ - logError("位置解析失败==>{}", jsonObject.getString("message")); - return null; - } - }else{ - logError("位置解析失败==>{}", response.message()); - return null; - } - }else{ - logError("位置解析失败==>{}", response.message()); - return null; - } - } catch (Exception e) { - logError("位置解析失败==>{}", e.getMessage() + Arrays.toString(e.getStackTrace())); - return null; - } - } - - - private void logError(String errDesc, String errorMessage) { - log.error(errDesc, errorMessage); - } -}