商品列表 返回区域信息

This commit is contained in:
2024-05-16 16:41:13 +08:00
parent 63921852e9
commit 200b75e04d
7 changed files with 38 additions and 16 deletions

View File

@@ -106,6 +106,9 @@ public class TbShopInfo implements Serializable {
* 商户标签 * 商户标签
*/ */
private String tag; private String tag;
private String provinces;
private String cities;
private String districts;
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;

View File

@@ -70,6 +70,9 @@ public class ProductInfoVo {
* 距离 * 距离
*/ */
private String distances = "100"; private String distances = "100";
private String lat;
private String lng;
private String districts;
/** /**
* 地址 * 地址
*/ */

View File

@@ -78,10 +78,10 @@ public class GroupOrderInfoService {
TbShopInfo shopInfo = shopInfoMapper.selectByPrimaryKey(groupOrder.getShopId()); TbShopInfo shopInfo = shopInfoMapper.selectByPrimaryKey(groupOrder.getShopId());
result.setShopName(shopInfo.getShopName()); result.setShopName(shopInfo.getShopName());
BigDecimal distance = LocationUtils.getDistanceFrom2LngLat( String distance = LocationUtils.getDistanceString(
Double.parseDouble(lng), Double.parseDouble(lat), Double.parseDouble(lng), Double.parseDouble(lat),
Double.parseDouble(shopInfo.getLng()), Double.parseDouble(shopInfo.getLat())); Double.parseDouble(shopInfo.getLng()), Double.parseDouble(shopInfo.getLat()));
result.setDistances(distance.toString()); result.setDistances(distance);
result.setAddress(shopInfo.getAddress()); result.setAddress(shopInfo.getAddress());
result.setShopPhone(shopInfo.getPhone()); result.setShopPhone(shopInfo.getPhone());

View File

@@ -109,10 +109,10 @@ public class HomeDistrictService {
param.getAddress(), param.getLng(), param.getLat(),null);//西安市 param.getAddress(), param.getLng(), param.getLat(),null);//西安市
for (SubShopVo subShopVo : subShopVos) {//距离计算 for (SubShopVo subShopVo : subShopVos) {//距离计算
if (StringUtils.isNotBlank(subShopVo.getLat()) && StringUtils.isNotBlank(subShopVo.getLng())) { if (StringUtils.isNotBlank(subShopVo.getLat()) && StringUtils.isNotBlank(subShopVo.getLng())) {
BigDecimal distance = LocationUtils.getDistanceFrom2LngLat( String distance = LocationUtils.getDistanceString(
Double.parseDouble(param.getLng()), Double.parseDouble(param.getLat()), Double.parseDouble(param.getLng()), Double.parseDouble(param.getLat()),
Double.parseDouble(subShopVo.getLng()), Double.parseDouble(subShopVo.getLat())); Double.parseDouble(subShopVo.getLng()), Double.parseDouble(subShopVo.getLat()));
subShopVo.setDistances(distance.toString()); subShopVo.setDistances(distance);
} }
} }
return Result.success(CodeEnum.SUCCESS, new PageInfo(subShopVos)); return Result.success(CodeEnum.SUCCESS, new PageInfo(subShopVos));
@@ -133,10 +133,10 @@ public class HomeDistrictService {
for (SubShopVo subShopVo : subShopVos) {//距离计算 for (SubShopVo subShopVo : subShopVos) {//距离计算
subShopVo.setBusinessTime(subShopVo.getBusinessStartDay()+""+subShopVo.getBusinessEndDay()+" "+subShopVo.getBusinessTime()); subShopVo.setBusinessTime(subShopVo.getBusinessStartDay()+""+subShopVo.getBusinessEndDay()+" "+subShopVo.getBusinessTime());
if (StringUtils.isNotBlank(subShopVo.getLat()) && StringUtils.isNotBlank(subShopVo.getLng())) { if (StringUtils.isNotBlank(subShopVo.getLat()) && StringUtils.isNotBlank(subShopVo.getLng())) {
BigDecimal distance = LocationUtils.getDistanceFrom2LngLat( String distance = LocationUtils.getDistanceString(
Double.parseDouble(param.getLng()), Double.parseDouble(param.getLat()), Double.parseDouble(param.getLng()), Double.parseDouble(param.getLat()),
Double.parseDouble(subShopVo.getLng()), Double.parseDouble(subShopVo.getLat())); Double.parseDouble(subShopVo.getLng()), Double.parseDouble(subShopVo.getLat()));
subShopVo.setDistances(distance.toString()); subShopVo.setDistances(distance);
} }
} }
return Result.success(CodeEnum.SUCCESS, subShopVos); return Result.success(CodeEnum.SUCCESS, subShopVos);

View File

@@ -204,10 +204,10 @@ public class ProductService {
homeVO.setShopTag(JSONUtil.parseListTNewList(tbPlatformDicts, TagVo.class)); homeVO.setShopTag(JSONUtil.parseListTNewList(tbPlatformDicts, TagVo.class));
} }
if (StringUtils.isNotBlank(o.getLat()) && StringUtils.isNotBlank(o.getLng())) { if (StringUtils.isNotBlank(o.getLat()) && StringUtils.isNotBlank(o.getLng())) {
BigDecimal distance = LocationUtils.getDistanceFrom2LngLat( String distance = LocationUtils.getDistanceString(
Double.parseDouble(homeDto.getLng()), Double.parseDouble(homeDto.getLat()), Double.parseDouble(homeDto.getLng()), Double.parseDouble(homeDto.getLat()),
Double.parseDouble(o.getLng()), Double.parseDouble(o.getLat())); Double.parseDouble(o.getLng()), Double.parseDouble(o.getLat()));
homeVO.setDistances(distance.toString()); homeVO.setDistances(distance);
} }
homeVO.setProductName(o.getProName()); homeVO.setProductName(o.getProName());
homeVO.setImage(o.getProImg()); homeVO.setImage(o.getProImg());
@@ -297,12 +297,15 @@ public class ProductService {
productInfo.setShopNum(i); productInfo.setShopNum(i);
} }
productInfo.setPhone(tbShopInfo.getPhone()); productInfo.setPhone(tbShopInfo.getPhone());
productInfo.setLat(tbShopInfo.getLat());
productInfo.setLng(tbShopInfo.getLng());
productInfo.setBusinessTime(tbShopInfo.getBusinessStartDay() + "" + tbShopInfo.getBusinessEndDay() + " " + tbShopInfo.getBusinessTime()); productInfo.setBusinessTime(tbShopInfo.getBusinessStartDay() + "" + tbShopInfo.getBusinessEndDay() + " " + tbShopInfo.getBusinessTime());
BigDecimal distance = LocationUtils.getDistanceFrom2LngLat( String distance = LocationUtils.getDistanceString(
Double.parseDouble(lng), Double.parseDouble(lat), Double.parseDouble(lng), Double.parseDouble(lat),
Double.parseDouble(tbShopInfo.getLng()), Double.parseDouble(tbShopInfo.getLat())); Double.parseDouble(tbShopInfo.getLng()), Double.parseDouble(tbShopInfo.getLat()));
productInfo.setDistances(distance.toString());//距离 productInfo.setDistances(distance);//距离
productInfo.setAddress(tbShopInfo.getAddress()); productInfo.setAddress(tbShopInfo.getAddress());
productInfo.setDistricts(tbShopInfo.getDistricts());
List<ProductVo> productVos = JSONUtil.parseListTNewList(tbProduct.getGroupSnap(), ProductVo.class); List<ProductVo> productVos = JSONUtil.parseListTNewList(tbProduct.getGroupSnap(), ProductVo.class);
for (ProductVo productVo : productVos) { for (ProductVo productVo : productVos) {

View File

@@ -17,6 +17,7 @@ import static java.lang.Math.sin;
public class LocationUtils { public class LocationUtils {
/** /**
* 通过Ip获取定位信息 * 通过Ip获取定位信息
*
* @param ip * @param ip
* @return * @return
*/ */
@@ -24,7 +25,7 @@ public class LocationUtils {
Map<String, String> param = new HashMap<>(); Map<String, String> param = new HashMap<>();
//超掌柜生活-用户端 //超掌柜生活-用户端
param.put("key", "7a7f2e4790ea222660a027352ee3af39"); param.put("key", "7a7f2e4790ea222660a027352ee3af39");
if(StringUtils.isNotBlank(ip)){ if (StringUtils.isNotBlank(ip)) {
param.put("ip", ip); param.put("ip", ip);
} }
String s = HttpClientUtil.doGet("https://restapi.amap.com/v3/ip", param); String s = HttpClientUtil.doGet("https://restapi.amap.com/v3/ip", param);
@@ -36,7 +37,7 @@ public class LocationUtils {
*/ */
public static JsonNode geocode(String location) { public static JsonNode geocode(String location) {
RestTemplate restTemplate = new RestTemplate(); RestTemplate restTemplate = new RestTemplate();
String s = restTemplate.getForObject("https://restapi.amap.com/v3/geocode/regeo?key=7a7f2e4790ea222660a027352ee3af39&location="+location, String.class); String s = restTemplate.getForObject("https://restapi.amap.com/v3/geocode/regeo?key=7a7f2e4790ea222660a027352ee3af39&location=" + location, String.class);
ObjectMapper objectMapper = new ObjectMapper(); ObjectMapper objectMapper = new ObjectMapper();
// 将 JSON 字符串解析为 JsonNode 对象 // 将 JSON 字符串解析为 JsonNode 对象
try { try {
@@ -49,6 +50,7 @@ public class LocationUtils {
/** /**
* 行政区域查询 * 行政区域查询
*
* @param keywords * @param keywords
* @return * @return
*/ */
@@ -83,12 +85,21 @@ public class LocationUtils {
double a = radLat1 - radLat2; double a = radLat1 - radLat2;
double b = radLng1 - radLng2; double b = radLng1 - radLng2;
double dis= 2 * asin(sqrt(sin(a / 2) * sin(a / 2) + cos(radLat1) * cos(radLat2) * sin(b / 2) * sin(b / 2))) * 6378.137; double dis = 2 * asin(sqrt(sin(a / 2) * sin(a / 2) + cos(radLat1) * cos(radLat2) * sin(b / 2) * sin(b / 2))) * 6378.137;
BigDecimal bigDecimalValue = new BigDecimal(dis); BigDecimal bigDecimalValue = new BigDecimal(dis);
bigDecimalValue = bigDecimalValue.setScale(3, RoundingMode.DOWN); bigDecimalValue = bigDecimalValue.setScale(3, RoundingMode.DOWN);
return bigDecimalValue; return bigDecimalValue;
} }
public static String getDistanceString(double lng1, double lat1, double lng2, double lat2) {
BigDecimal distance = getDistanceFrom2LngLat(lng1, lat1, lng2, lat2);
if (distance.compareTo(BigDecimal.ONE) < 0) {
return distance.multiply(new BigDecimal(1000)) + "m";
} else {
return distance + "km";
}
}
/** /**
* @param longitude 经度 108 * @param longitude 经度 108
* @param latitude 纬度 34 * @param latitude 纬度 34
@@ -128,14 +139,13 @@ public class LocationUtils {
} }
/** /**
* 将角度转化为弧度 * 将角度转化为弧度
*/ */
public static double radians(double d) { public static double radians(double d) {
return d * Math.PI / 180.0; return d * Math.PI / 180.0;
} }
//1KM //1KM
public static void main(String[] args) { public static void main(String[] args) {
Map<String, double[]> stringMap = returnLLSquarePoint(108.975418, 34.280890, "5"); Map<String, double[]> stringMap = returnLLSquarePoint(108.975418, 34.280890, "5");

View File

@@ -48,6 +48,9 @@
<result column="updated_at" jdbcType="BIGINT" property="updatedAt"/> <result column="updated_at" jdbcType="BIGINT" property="updatedAt"/>
<result column="proxy_id" jdbcType="VARCHAR" property="proxyId"/> <result column="proxy_id" jdbcType="VARCHAR" property="proxyId"/>
<result column="is_open_yhq" jdbcType="VARCHAR" property="isOpenYhq"/> <result column="is_open_yhq" jdbcType="VARCHAR" property="isOpenYhq"/>
<result column="provinces" jdbcType="VARCHAR" property="provinces"/>
<result column="cities" jdbcType="VARCHAR" property="cities"/>
<result column="districts" jdbcType="VARCHAR" property="districts"/>
</resultMap> </resultMap>
<resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" <resultMap extends="BaseResultMap" id="ResultMapWithBLOBs"
type="com.chaozhanggui.system.cashierservice.entity.TbShopInfo"> type="com.chaozhanggui.system.cashierservice.entity.TbShopInfo">
@@ -60,7 +63,7 @@
detail, lat, lng, mch_id, register_type, is_wx_ma_independent, address, city, type, detail, lat, lng, mch_id, register_type, is_wx_ma_independent, address, city, type,
industry, industry_name, business_start_day,business_end_day,business_time, post_time, post_amount_line, on_sale, settle_type, industry, industry_name, business_start_day,business_end_day,business_time, post_time, post_amount_line, on_sale, settle_type,
settle_time, enter_at, expire_at, status, average, order_wait_pay_minute, support_device_number, settle_time, enter_at, expire_at, status, average, order_wait_pay_minute, support_device_number,
distribute_level, created_at, updated_at, proxy_id, shop_qrcode, tag,is_open_yhq distribute_level, created_at, updated_at, proxy_id, shop_qrcode, tag,is_open_yhq,provinces,cities,districts
</sql> </sql>
<sql id="Blob_Column_List"> <sql id="Blob_Column_List">
view view