Commit e42fd409 by yuanchao

20240314

parent a0685375
......@@ -115,10 +115,11 @@
</dependency>
<!--微信支付-->
<!-- 微信支付V3 目前新版本-->
<dependency>
<groupId>com.github.wechatpay-apiv3</groupId>
<artifactId>wechatpay-java</artifactId>
<version>0.2.12</version>
<artifactId>wechatpay-apache-httpclient</artifactId>
<version>0.4.9</version>
</dependency>
<dependency>
......
......@@ -59,6 +59,8 @@ public class WaterGoodsCart {
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime;
private String openId;
/** 封面图集合 */
private List<WaterGoodsImg> coverImgs;
......
......@@ -252,7 +252,15 @@ public class WaterStationServiceImpl implements IWaterStationService
@Override
public WaterStationVo getRecentlyStation1(String address,String address1) {
double[] doubles = AMapUtils.addressToGPS(address);
double[] doubles;
if(address1.contains(address)){
doubles = AMapUtils.addressToGPS(address);
}else {
doubles = AMapUtils.addressToGPS(address+address1);
}
double lon = doubles[0];
double lat = doubles[1];
//查询所有站点信息
......@@ -260,11 +268,9 @@ public class WaterStationServiceImpl implements IWaterStationService
List<WaterStationVo> waterStationVoList = new ArrayList<>();
//循环站点,计算符合距离的站点
for (WaterStation waterStation : waterStations) {
//判断用户和站点之前的距离是否在站点管辖范围之内
boolean inCircle = PositionUtil.isInCircle(lon, lat, waterStation.getStationLonTen(), waterStation.getStationLatTen(), "5000");
//计算距离
double distance = PositionUtil.getDistance(lon, lat, waterStation.getStationLonTen(), waterStation.getStationLatTen(), Ellipsoid.WGS84);
if (inCircle){
double distance = PositionUtil.getDistance1(lon, lat, waterStation.getStationLonTen(), waterStation.getStationLatTen());
if(distance<5000){
WaterStationVo waterStationVo = new WaterStationVo();
BeanUtils.copyProperties(waterStation,waterStationVo);
waterStationVo.setDistance(distance);
......@@ -273,7 +279,13 @@ public class WaterStationServiceImpl implements IWaterStationService
}
//根据距离排序,选出最近的站点
List<WaterStationVo> collect = waterStationVoList.stream().sorted(Comparator.comparing(WaterStationVo::getDistance)).collect(Collectors.toList());
return collect.get(0);
WaterStationVo stationVo = new WaterStationVo();
if(collect.size()>0){
stationVo = collect.get(0);
}
return stationVo;
}
/**
......
......@@ -62,11 +62,11 @@ public class AMapUtils {
return null;
}
public static void main(String[] args) {
/*public static void main(String[] args) {
String address = "广州市总统大酒店";
double[] doubles = addressToGPS(address);
System.out.println(address+"、经度: "+doubles[0]);
System.out.println(address+"、纬度: "+doubles[1]);
}
}*/
}
\ No newline at end of file
......@@ -13,6 +13,39 @@ import org.springframework.stereotype.Component;
@Component
public class PositionUtil {
/**
* 赤道半径
*/
private static final double EQUATOR_RADIUS = 6378137;
/**
* 方法一:(反余弦计算方式)
*
* @param longitude1 第一个点的经度
* @param latitude1 第一个点的纬度
* @param longitude2 第二个点的经度
* @param latitude2 第二个点的纬度
* @return 返回距离,单位m
*/
public static double getDistance1(double longitude1, double latitude1, double longitude2, double latitude2) {
// 纬度
double lat1 = Math.toRadians(latitude1);
double lat2 = Math.toRadians(latitude2);
// 经度
double lon1 = Math.toRadians(longitude1);
double lon2 = Math.toRadians(longitude2);
// 纬度之差
double a = lat1 - lat2;
// 经度之差
double b = lon1 - lon2;
// 计算两点距离的公式
double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(lat1) * Math.cos(lat2) * Math.pow(Math.sin(b / 2), 2)));
// 弧长乘赤道半径, 返回单位: 米
s = s * EQUATOR_RADIUS;
return s;
}
/**
* 方法四:(利用第三方jar包计算)
* 计算两个经纬度之间的距离
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment