|
@@ -57,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,String userLongitude,String userLatitude,String place,String searchKeyWord,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,String myFlag,String searchKeyWord,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);
|
|
@@ -125,70 +125,72 @@ 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);
|
|
|
+ if (!"1".equals(myFlag)) {
|
|
|
+ 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();
|
|
|
}
|
|
|
- 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);
|
|
|
+ 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));
|
|
|
}
|
|
|
- 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));
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+ //按权重降序 距离升序排序
|
|
|
+ list.sort(Comparator.comparing(ProductManagement::getWeightSort).reversed().thenComparing(ProductManagement::getDistance));
|
|
|
}
|
|
|
- //按权重降序 距离升序排序
|
|
|
- list.sort(Comparator.comparing(ProductManagement::getWeightSort).reversed().thenComparing(ProductManagement::getDistance));
|
|
|
}
|
|
|
Integer count = productManagementMapper.selectCount(wrapper);
|
|
|
return new Page<ProductManagement>(list, page, limit, count);
|