调整地理编码服务,同一在运维模块实现,通过Feign调用,增加获取详细地址的方法,返回内容为json,可以根据实际需要增减
This commit is contained in:
parent
4cd708039a
commit
192a39681f
@ -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<List<RspBikeInfo>> getVehicleDetailsByRegionId(@RequestParam(name = "regionId") String regionId);
|
||||
|
||||
/**
|
||||
* 根据经纬度获取地址 (详细地址)
|
||||
*
|
||||
* @param location 经纬度(GCJ02坐标系)
|
||||
* @return 地址JSON对象
|
||||
*/
|
||||
@PostMapping("system/location2Address2")
|
||||
JsonResult<?> location2AddressDetails(@RequestBody ReqLocationDto location);
|
||||
}
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -252,7 +252,7 @@ public class EbikeBikeInfoServiceImpl extends ServiceImpl<EbikeBikeInfoMapper, E
|
||||
jsonObject.put("lng", gcj02[0]);
|
||||
resGPSDto.setLatitude(gcj02[1]);
|
||||
resGPSDto.setLongitude(gcj02[0]);
|
||||
String address = geoCodingUtil.getLocationToaddress(jsonObject);
|
||||
String address = geoCodingUtil.getLocationToAddress(jsonObject);
|
||||
if (address != null) {
|
||||
resGPSDto.setChineseLocation(address);
|
||||
}
|
||||
@ -1091,7 +1091,7 @@ public class EbikeBikeInfoServiceImpl extends ServiceImpl<EbikeBikeInfoMapper, E
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("lat", ebikeBikeFaultReport.getLatitude());
|
||||
jsonObject.put("lng", ebikeBikeFaultReport.getLongitude());
|
||||
String address = geoCodingUtil.getLocationToaddress(jsonObject);
|
||||
String address = geoCodingUtil.getLocationToAddress(jsonObject);
|
||||
|
||||
StaffIds staffIds = new StaffIds();
|
||||
List<String> userIds = new ArrayList<>();
|
||||
|
||||
@ -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)。
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
@ -231,6 +231,7 @@ public class EbikeWxPaymentController {
|
||||
*/
|
||||
@PostMapping("/refundOrderRecords")
|
||||
public JsonResult<?> refundOrderRecords(@RequestBody ReqUserQueryDto reqRefundRecordDto) {
|
||||
|
||||
Page<OrderRecord> list = ebikeRefundService.getRefundOrderRecords(reqRefundRecordDto);
|
||||
return JsonResult.success(list);
|
||||
}
|
||||
}
|
||||
|
||||
@ -335,6 +335,7 @@ public class EbikeRefundServiceImpl extends ServiceImpl<EbikeRefundMapper, Ebike
|
||||
|
||||
@Override
|
||||
public Page<OrderRecord> getRefundOrderRecords(ReqUserQueryDto reqRefundRecordDto) {
|
||||
return null;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -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"));
|
||||
}
|
||||
}
|
||||
}
|
||||
// 骑行时长
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user