zhangyuewww 2 лет назад
Родитель
Сommit
9036f959a7

+ 1 - 0
unimall-admin-api/src/main/java/com/iotechn/unimall/admin/api/tourism/IFoodInfoService.java

@@ -24,6 +24,7 @@ public interface IFoodInfoService{
 
 
 	@HttpMethod(description = "列表", permissionName = "餐饮入驻信息管理")
 	@HttpMethod(description = "列表", permissionName = "餐饮入驻信息管理")
 	public Page<FoodInfo> list(
 	public Page<FoodInfo> list(
+			@HttpParam(name = "id", type = HttpParamType.COMMON, description = "id") Long id,
 								@HttpParam(name = "commonId", type = HttpParamType.COMMON, description = "个人id") Long commonId,
 								@HttpParam(name = "commonId", type = HttpParamType.COMMON, description = "个人id") Long commonId,
 							@HttpParam(name = "mainBody", type = HttpParamType.COMMON, description = "主体(商铺/个人)") String mainBody,
 							@HttpParam(name = "mainBody", type = HttpParamType.COMMON, description = "主体(商铺/个人)") String mainBody,
 							@HttpParam(name = "shopNames", type = HttpParamType.COMMON, description = "店铺名称") String shopNames,
 							@HttpParam(name = "shopNames", type = HttpParamType.COMMON, description = "店铺名称") String shopNames,

+ 59 - 34
unimall-admin-api/src/main/java/com/iotechn/unimall/admin/api/tourism/impl/FoodInfoServiceImpl.java

@@ -1,9 +1,15 @@
 package com.iotechn.unimall.admin.api.tourism.impl;
 package com.iotechn.unimall.admin.api.tourism.impl;
 
 
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.URL;
 import java.util.ArrayList;
 import java.util.ArrayList;
 import java.util.Comparator;
 import java.util.Comparator;
 import java.util.List;
 import java.util.List;
 
 
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
 import com.iotechn.unimall.admin.api.tourism.IFoodInfoService;
 import com.iotechn.unimall.admin.api.tourism.IFoodInfoService;
 import com.iotechn.unimall.data.domain.*;
 import com.iotechn.unimall.data.domain.*;
 import com.iotechn.unimall.data.mapper.*;
 import com.iotechn.unimall.data.mapper.*;
@@ -46,6 +52,7 @@ public class FoodInfoServiceImpl implements IFoodInfoService {
 	 * 地球半径,单位 km
 	 * 地球半径,单位 km
 	 */
 	 */
 	private static final double EARTH_RADIUS = 6378.137;
 	private static final double EARTH_RADIUS = 6378.137;
+	private static final String KEY = "OKDBZ-G3GC3-3C53F-3FWLN-HOGIV-FWBZM";
 
 
 	@Override
 	@Override
 	public Boolean add(FoodInfo foodInfo) throws ServiceException {
 	public Boolean add(FoodInfo foodInfo) throws ServiceException {
@@ -58,8 +65,11 @@ public class FoodInfoServiceImpl implements IFoodInfoService {
 	}
 	}
 
 
 	@Override
 	@Override
-	public Page<FoodInfo> list(Long commonId,String mainBody,String shopNames,String coverImage,String indoorImage,String province,String city,String area,String location,String detailedAddress,String operater,String operaterPhone,String contacts,String contactsPhone,String label,String businessLicense,String operateCertificate,Date operateCertificateDate,String startDate,String endDate,Long lookFlag,String status,Date gmtCreate,Date gmtUpdate,Long deleteFlag, Integer page, Integer limit)throws ServiceException {
+	public Page<FoodInfo> list(Long id,Long commonId,String mainBody,String shopNames,String coverImage,String indoorImage,String province,String city,String area,String location,String detailedAddress,String operater,String operaterPhone,String contacts,String contactsPhone,String label,String businessLicense,String operateCertificate,Date operateCertificateDate,String startDate,String endDate,Long lookFlag,String status,Date gmtCreate,Date gmtUpdate,Long deleteFlag, Integer page, Integer limit)throws ServiceException {
 		Wrapper<FoodInfo> wrapper = new EntityWrapper<FoodInfo>();
 		Wrapper<FoodInfo> wrapper = new EntityWrapper<FoodInfo>();
+				if (!StringUtils.isEmpty(id)) {
+					wrapper.eq("id", id);
+				}
 														if (!StringUtils.isEmpty(commonId)) {
 														if (!StringUtils.isEmpty(commonId)) {
 					wrapper.eq("common_id", commonId);
 					wrapper.eq("common_id", commonId);
 				}
 				}
@@ -191,46 +201,61 @@ public class FoodInfoServiceImpl implements IFoodInfoService {
 			//查询发货地经纬度
 			//查询发货地经纬度
 			for (int i = 0; i < list.size(); i++) {
 			for (int i = 0; i < list.size(); i++) {
 				FoodInfo foodInfo = list.get(i);
 				FoodInfo foodInfo = list.get(i);
-				String [] tempArray = foodInfo.getLocation().split(",");
-				//店铺经纬度
-				double longitude = Double.parseDouble(tempArray[0]);
-				double latitude = Double.parseDouble(tempArray[1]);
 				//根据用户经纬度求距离
 				//根据用户经纬度求距离
 				if (!StringUtils.isEmpty(userLatitude) && !StringUtils.isEmpty(userLongitude)) {
 				if (!StringUtils.isEmpty(userLatitude) && !StringUtils.isEmpty(userLongitude)) {
-					double lat1 = Math.toRadians(Double.valueOf(userLatitude));
-					double lng1 = Math.toRadians(Double.valueOf(userLongitude));
-					// 纬度之差
-					double a = lat1 - latitude;
-					// 经度之差
-					double b = lng1 - longitude;
-					// 计算两点距离的公式
-					double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) +
-							Math.cos(lat1) * Math.cos(latitude) * Math.pow(Math.sin(b / 2), 2)));
-
-					// 弧长乘地球半径, 返回单位: 千米
-					s = s * EARTH_RADIUS;
-					foodInfo.setDistance(Math.floor(s));
+					 // 参数解释:lng:经度,lat:维度。KEY:腾讯地图key
+					String urlString = "https://apis.map.qq.com/ws/direction/v1/driving/?from=" + userLatitude + "," + userLongitude+ "&to=" + foodInfo.getLocation()  + "&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("result");
+					JSONArray jsonArray = obj.getJSONArray("routes");
+					if(jsonArray != null&&jsonArray.size() > 0){
+						String distance=JSONObject.parseObject(jsonArray.get(0).toString()).getString("distance");
+						foodInfo.setDistance(Double.valueOf(distance));
+					}
 				}
 				}
 				//根据用户定位的位置求距离
 				//根据用户定位的位置求距离
 				else if (!StringUtils.isEmpty(place)) {
 				else if (!StringUtils.isEmpty(place)) {
 					//根据装货城市获取经纬度
 					//根据装货城市获取经纬度
 					String str = EntCoordUtil.getCoordinate(place);
 					String str = EntCoordUtil.getCoordinate(place);
-					String str1 = str.substring(0, str.indexOf(","));//经度
-					String str2 = str.substring(str1.length() + 1, str.length());//纬度
-
-					//装货地经纬度
-					double lng1 = Math.toRadians(Double.valueOf(str1));
-					double lat1 = Math.toRadians(Double.valueOf(str2));
-					// 纬度之差
-					double a = lat1 - latitude;
-					// 经度之差
-					double b = lng1 - longitude;
-					// 计算两点距离的公式
-					double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) +
-							Math.cos(lat1) * Math.cos(latitude) * Math.pow(Math.sin(b / 2), 2)));
-					// 弧长乘地球半径, 返回单位: 千米
-					s = s * EARTH_RADIUS;
-					foodInfo.setDistance(Math.floor(s));
+					// 参数解释:lng:经度,lat:维度。KEY:腾讯地图key
+					String urlString = "https://apis.map.qq.com/ws/direction/v1/driving/?from=" + str+ "&to=" + foodInfo.getLocation()  + "&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("result");
+					JSONArray jsonArray = obj.getJSONArray("routes");
+					if(jsonArray != null&&jsonArray.size() > 0){
+						String distance=JSONObject.parseObject(jsonArray.get(0).toString()).getString("distance");
+						foodInfo.setDistance(Double.valueOf(distance));
+					}
 				}
 				}
 			}
 			}
 			//按距离排序
 			//按距离排序

+ 3 - 1
unimall-data/src/main/resources/com/iotechn/unimall/data/mapper/FoodInfoMapper.xml

@@ -39,6 +39,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
                 AND lci.delete_flag = 0
                 AND lci.delete_flag = 0
                 AND lci.interaction_flag = 1
                 AND lci.interaction_flag = 1
                 AND lci.common_id = #{commonId}
                 AND lci.common_id = #{commonId}
+        LEFT JOIN food_dishes_info fdi ON fdi.food_id=f.id and fdi.delete_flag = 0
         WHERE
         WHERE
             f.delete_flag = 0
             f.delete_flag = 0
           AND f.`status` = '显示中'
           AND f.`status` = '显示中'
@@ -47,7 +48,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         </if>
         </if>
         <if test="searchKeyWord != null and searchKeyWord != ''">
         <if test="searchKeyWord != null and searchKeyWord != ''">
             AND (lower(f.label) like lower(CONCAT('%',#{searchKeyWord},'%'))
             AND (lower(f.label) like lower(CONCAT('%',#{searchKeyWord},'%'))
-            OR lower(f.shop_names) like lower(CONCAT('%',#{searchKeyWord},'%')))
+            OR lower(f.shop_names) like lower(CONCAT('%',#{searchKeyWord},'%'))
+            OR lower(fdi.dish_name) like lower(CONCAT('%',#{searchKeyWord},'%')))
         </if>
         </if>
         <if test="searchType != null and searchType == 4">
         <if test="searchType != null and searchType == 4">
             and lci.id is not null
             and lci.id is not null