Ver código fonte

Merge branch 'master' of http://git.zthymaoyi.com/zyw/tourism

高敬炎 2 anos atrás
pai
commit
924d37b5ec

+ 3 - 0
unimall-admin-api/src/main/java/com/iotechn/unimall/admin/api/tourism/IProductManagementService.java

@@ -43,6 +43,9 @@ public interface IProductManagementService{
 							@HttpParam(name = "personImageBack", type = HttpParamType.COMMON, description = "身份证背面") String personImageBack,
 							@HttpParam(name = "businessLicense", type = HttpParamType.COMMON, description = "营业执照") String businessLicense,
 							@HttpParam(name = "status", type = HttpParamType.COMMON, description = "状态") String status,
+							@HttpParam(name = "userLongitude", type = HttpParamType.COMMON, description = "用户经度") String userLongitude,
+							@HttpParam(name = "userLatitude", type = HttpParamType.COMMON, description = "用户纬度") String userLatitude,
+							@HttpParam(name = "place", type = HttpParamType.COMMON, description = "用户定位的地址") String place,
 							@HttpParam(name = "gmtCreate", type = HttpParamType.COMMON, description = "") Date gmtCreate,
 							@HttpParam(name = "gmtUpdate", type = HttpParamType.COMMON, description = "") Date gmtUpdate,
 							@HttpParam(name = "deleteFlag", type = HttpParamType.COMMON, description = "删除标识") Long deleteFlag,

+ 12 - 9
unimall-admin-api/src/main/java/com/iotechn/unimall/admin/api/tourism/impl/FoodInfoServiceImpl.java

@@ -52,7 +52,7 @@ public class FoodInfoServiceImpl implements IFoodInfoService {
 	 * 地球半径,单位 km
 	 */
 	private static final double EARTH_RADIUS = 6378.137;
-	private static final String KEY = "OKDBZ-G3GC3-3C53F-3FWLN-HOGIV-FWBZM";
+	private static final String KEY = "0356df5341cf34f039b458e97895c082";
 
 	@Override
 	public Boolean add(FoodInfo foodInfo) throws ServiceException {
@@ -207,11 +207,14 @@ public class FoodInfoServiceImpl implements IFoodInfoService {
 				if (!CollectionUtils.isEmpty(foodDishesInfoList)){
 					foodInfo.setFoodDishesInfoList(foodDishesInfoList);
 				}
+				String[] parts=foodInfo.getLocation().split(",");
+				String latitude=parts[0];
+				String longitude=parts[1];
 
 				//根据用户经纬度求距离
 				if (!StringUtils.isEmpty(userLatitude) && !StringUtils.isEmpty(userLongitude)) {
-					 // 参数解释:lng:经度,lat:维度。KEY:腾讯地图key
-					String urlString = "https://apis.map.qq.com/ws/direction/v1/driving/?from=" + userLatitude + "," + userLongitude+ "&to=" + foodInfo.getLocation()  + "&key=" + KEY ;
+					// 参数解释: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 {
@@ -228,8 +231,8 @@ public class FoodInfoServiceImpl implements IFoodInfoService {
 					}
 					String result = sb.toString();
 					JSONObject jsonObj = JSONObject.parseObject(result);
-					JSONObject obj = jsonObj.getJSONObject("result");
-					JSONArray jsonArray = obj.getJSONArray("routes");
+					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");
 						foodInfo.setDistance(Double.valueOf(distance));
@@ -239,8 +242,8 @@ public class FoodInfoServiceImpl implements IFoodInfoService {
 				else if (!StringUtils.isEmpty(place)) {
 					//根据装货城市获取经纬度
 					String str = EntCoordUtil.getCoordinate(place);
-					// 参数解释:lng:经度,lat:维度。KEY:腾讯地图key
-					String urlString = "https://apis.map.qq.com/ws/direction/v1/driving/?from=" + str+ "&to=" + foodInfo.getLocation()  + "&key=" + KEY ;
+					// 参数解释: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 {
@@ -257,8 +260,8 @@ public class FoodInfoServiceImpl implements IFoodInfoService {
 					}
 					String result = sb.toString();
 					JSONObject jsonObj = JSONObject.parseObject(result);
-					JSONObject obj = jsonObj.getJSONObject("result");
-					JSONArray jsonArray = obj.getJSONArray("routes");
+					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");
 						foodInfo.setDistance(Double.valueOf(distance));

+ 72 - 2
unimall-admin-api/src/main/java/com/iotechn/unimall/admin/api/tourism/impl/ProductManagementServiceImpl.java

@@ -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);
 	}

+ 21 - 0
unimall-data/src/main/java/com/iotechn/unimall/data/domain/ProductManagement.java

@@ -134,6 +134,27 @@ public class ProductManagement extends SuperDO{
     /** 语音 */
     @TableField(exist = false)
     private String voiceMessage;
+    /**
+     * 用户经度
+     */
+    @TableField(exist = false)
+    private String userLongitude;
+
+    /**
+     * 用户纬度
+     */
+    @TableField(exist = false)
+    private String userLatitude;
+    /**
+     * 距离
+     */
+    @TableField(exist = false)
+    private Double distance;
+    /**
+     * 用户定位的地址
+     */
+    @TableField(exist = false)
+    private String place;
 
     @Override
     public String toString() {