|
@@ -1,10 +1,16 @@
|
|
|
package com.iotechn.unimall.admin.api.tourism.impl;
|
|
|
|
|
|
+import java.io.BufferedReader;
|
|
|
+import java.io.InputStreamReader;
|
|
|
+import java.net.URL;
|
|
|
import java.util.*;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.iotechn.unimall.data.domain.FoodDishesInfo;
|
|
|
+import com.iotechn.unimall.data.domain.FoodInfo;
|
|
|
import com.iotechn.unimall.data.dto.DistinguishView;
|
|
|
+import com.iotechn.unimall.data.util.EntCoordUtil;
|
|
|
import com.iotechn.unimall.data.util.HttpUtils;
|
|
|
import org.apache.http.HttpEntity;
|
|
|
import org.apache.http.HttpResponse;
|
|
@@ -18,6 +24,7 @@ import org.apache.http.util.EntityUtils;
|
|
|
import org.apache.ibatis.session.RowBounds;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
|
@@ -40,7 +47,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
public class ProductManagementServiceImpl implements IProductManagementService{
|
|
|
@Autowired
|
|
|
private ProductManagementMapper productManagementMapper;
|
|
|
-
|
|
|
+ private static final String KEY = "0356df5341cf34f039b458e97895c082";
|
|
|
@Override
|
|
|
public Boolean add(ProductManagement productManagement) throws ServiceException {
|
|
|
Date now = new Date();
|
|
@@ -50,7 +57,7 @@ public class ProductManagementServiceImpl implements IProductManagementService{
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Page<ProductManagement> list(Long commonId,String mainBody,String shopNames,String coverImage,String province,String city,String area,String location,String detailedAddress,String serviceDescription,String nickname,String phone,String realname,String personNo,String personImageFront,String personImageBack,String businessLicense,String status,Date gmtCreate,Date gmtUpdate,Long deleteFlag, Integer page, Integer limit)throws ServiceException {
|
|
|
+ public Page<ProductManagement> list(Long commonId,String mainBody,String shopNames,String coverImage,String province,String city,String area,String location,String detailedAddress,String serviceDescription,String nickname,String phone,String realname,String personNo,String personImageFront,String personImageBack,String businessLicense,String status,String userLongitude,String userLatitude,String place,Date gmtCreate,Date gmtUpdate,Long deleteFlag, Integer page, Integer limit)throws ServiceException {
|
|
|
Wrapper<ProductManagement> wrapper = new EntityWrapper<ProductManagement>();
|
|
|
if (!StringUtils.isEmpty(commonId)) {
|
|
|
wrapper.eq("common_id", commonId);
|
|
@@ -117,6 +124,69 @@ public class ProductManagementServiceImpl implements IProductManagementService{
|
|
|
}
|
|
|
wrapper.eq("delete_flag", 0);
|
|
|
List<ProductManagement> list = productManagementMapper.selectPage(new RowBounds((page - 1) * limit, limit), wrapper);
|
|
|
+ if (!CollectionUtils.isEmpty(list)){
|
|
|
+ for (ProductManagement productManagement:list){
|
|
|
+ String[] parts=productManagement.getLocation().split(",");
|
|
|
+ String latitude=parts[0];
|
|
|
+ String longitude=parts[1];
|
|
|
+ //根据用户经纬度求距离
|
|
|
+ if (!StringUtils.isEmpty(userLatitude) && !StringUtils.isEmpty(userLongitude)) {
|
|
|
+ // 参数解释:lng:经度,lat:维度。KEY:高德地图key
|
|
|
+ String urlString = "https://restapi.amap.com/v3/direction/driving?origin=" + userLongitude + "," +userLatitude + "&destination=" + longitude + "," + latitude + "&key=" + KEY ;
|
|
|
+ //输入流的缓冲
|
|
|
+ StringBuffer sb = new StringBuffer();
|
|
|
+ try {
|
|
|
+ URL url = new URL(urlString);
|
|
|
+ BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream(), "UTF-8"));
|
|
|
+ String line;
|
|
|
+ // 获取地址解析结果
|
|
|
+ while ((line = in.readLine()) != null) {
|
|
|
+ sb.append(line);
|
|
|
+ }
|
|
|
+ in.close();
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.getMessage();
|
|
|
+ }
|
|
|
+ String result = sb.toString();
|
|
|
+ JSONObject jsonObj = JSONObject.parseObject(result);
|
|
|
+ JSONObject obj = jsonObj.getJSONObject("route");
|
|
|
+ JSONArray jsonArray = obj.getJSONArray("paths");
|
|
|
+ if(jsonArray != null&&jsonArray.size() > 0){
|
|
|
+ String distance=JSONObject.parseObject(jsonArray.get(0).toString()).getString("distance");
|
|
|
+ productManagement.setDistance(Double.valueOf(distance));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //根据用户定位的位置求距离
|
|
|
+ else if (!StringUtils.isEmpty(place)) {
|
|
|
+ //根据装货城市获取经纬度
|
|
|
+ String str = EntCoordUtil.getCoordinate(place);
|
|
|
+ // 参数解释:lng:经度,lat:维度。KEY:高德地图key
|
|
|
+ String urlString = "https://restapi.amap.com/v3/direction/driving?origin=" + str + "&destination=" + longitude + "," + latitude + "&key=" + KEY ;
|
|
|
+ //输入流的缓冲
|
|
|
+ StringBuffer sb = new StringBuffer();
|
|
|
+ try {
|
|
|
+ URL url = new URL(urlString);
|
|
|
+ BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream(), "UTF-8"));
|
|
|
+ String line;
|
|
|
+ // 获取地址解析结果
|
|
|
+ while ((line = in.readLine()) != null) {
|
|
|
+ sb.append(line);
|
|
|
+ }
|
|
|
+ in.close();
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.getMessage();
|
|
|
+ }
|
|
|
+ String result = sb.toString();
|
|
|
+ JSONObject jsonObj = JSONObject.parseObject(result);
|
|
|
+ JSONObject obj = jsonObj.getJSONObject("route");
|
|
|
+ JSONArray jsonArray = obj.getJSONArray("paths");
|
|
|
+ if(jsonArray != null&&jsonArray.size() > 0){
|
|
|
+ String distance=JSONObject.parseObject(jsonArray.get(0).toString()).getString("distance");
|
|
|
+ productManagement.setDistance(Double.valueOf(distance));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
Integer count = productManagementMapper.selectCount(wrapper);
|
|
|
return new Page<ProductManagement>(list, page, limit, count);
|
|
|
}
|