From 79bbee5adf0071808a33c09d5f87c5573d83cb3b Mon Sep 17 00:00:00 2001 From: nickchange <126672920+nickchange@users.noreply.github.com> Date: 星期二, 21 十一月 2023 19:44:15 +0800 Subject: [PATCH] 11.21。1 --- cloud-server-other/src/main/java/com/dsh/other/controller/StoreController.java | 104 ++++++++++++++++++++++++++++++++++++++------------- 1 files changed, 77 insertions(+), 27 deletions(-) diff --git a/cloud-server-other/src/main/java/com/dsh/other/controller/StoreController.java b/cloud-server-other/src/main/java/com/dsh/other/controller/StoreController.java index 2170111..117e660 100644 --- a/cloud-server-other/src/main/java/com/dsh/other/controller/StoreController.java +++ b/cloud-server-other/src/main/java/com/dsh/other/controller/StoreController.java @@ -6,8 +6,10 @@ import com.dsh.other.entity.*; import com.dsh.other.feignclient.model.*; import com.dsh.other.model.*; +import com.dsh.other.model.dto.siteDto.StoreInfoDto; import com.dsh.other.service.*; import com.dsh.other.util.GDMapGeocodingUtil; +import com.dsh.other.util.GeodesyUtil; import com.dsh.other.util.ResultUtil; import com.dsh.other.util.ToolUtil; import io.swagger.annotations.ApiImplicitParam; @@ -16,6 +18,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; +import java.math.BigDecimal; +import java.math.RoundingMode; import java.util.*; import java.util.stream.Collectors; @@ -36,7 +40,14 @@ @Autowired private TBackRecordService backRecordService; + /** + * 获取根据门店id 获取店长信息 + */ + @RequestMapping(value = "/getStoreInfo") + public StoreInfoDto getStoreInfo(@RequestBody Integer id){ + return storeService.getStoreInfo(id); + } /** * 根据城市管理员id获取门店 */ @@ -114,28 +125,41 @@ String result = storeLon+","+storeLat; String distanceTOKilometer = gdMapGeocodingUtil.getDistanceTOKilometer(current, result); long l = 0; - try { - l = Long.parseLong(distanceTOKilometer); - }catch (Exception e){ - l = 0; - } +// try { +// l = Long.parseLong(distanceTOKilometer); +// }catch (Exception e){ +// l = 0; +// } StoreInfo info = new StoreInfo(); info.setStoreId(store.getId()); info.setStoreName(store.getName()); info.setStoreImg(store.getCoverDrawing()); - info.setDistance(l); - info.setStoreAddr(store.getAddress()); + info.setDistance((long) Double.parseDouble(distanceTOKilometer)); + + + String str = store.getAddress(); + str = str.substring(str.indexOf("省") + 1); + + // 去掉第一个“市”及之前的字符串 + str = str.substring(str.indexOf("市") + 1); + + // 去掉第一个“区”及之前的字符串 + str = str.substring(str.indexOf("区") + 1); + + info.setStoreAddr(str); info.setLatitude(storeLat); info.setLongitude(storeLon); + storeInfos.add(info); } - Comparator<StoreInfo> distanceComparator = new Comparator<StoreInfo>() { - @Override - public int compare(StoreInfo store1, StoreInfo store2) { - return Long.compare(store1.getDistance(), store2.getDistance()); - } - }; - Collections.sort(storeInfos, distanceComparator); +// Comparator<StoreInfo> distanceComparator = new Comparator<StoreInfo>() { +// @Override +// public int compare(StoreInfo store1, StoreInfo store2) { +// return Long.compare(store1.getDistance(), store2.getDistance()); +// } +// }; +// Collections.sort(storeInfos, distanceComparator); + storeInfos = storeInfos.stream().sorted(Comparator.comparing(StoreInfo::getDistance)).collect(Collectors.toList()); } return storeInfos; } @@ -150,38 +174,57 @@ String current = distanceVo.getLongitude()+","+distanceVo.getLatitude(); Store store = storeService.getById(distanceVo.getStoreId()); String result = store.getLon()+","+store.getLat(); - return gdMapGeocodingUtil.getDistanceTOKilometer(current, result); + + + if(ToolUtil.isNotEmpty(distanceVo.getLongitude()) && ToolUtil.isNotEmpty(distanceVo.getLatitude())){ + Map<String, Double> distance = GeodesyUtil.getDistance(distanceVo.getLongitude() + "," + distanceVo.getLatitude(), store.getLon() + "," + store.getLat()); + double wgs84 = new BigDecimal(distance.get("WGS84")).divide(new BigDecimal(1000)).setScale(2, RoundingMode.HALF_EVEN).doubleValue(); +// packageResponse.setDistance(wgs84); + return wgs84+""; + } + return ""; + +// return gdMapGeocodingUtil.getDistanceTOKilometer(current, result); } @PostMapping("/base/protocol/storeDetail/citycodeLoLa") - public List<StoreDetailList> getQueryStoreList(@RequestBody StoreOfCitycodeResp citycodeResp){ + public List<StoreDetailList> getQueryStoreList(@RequestBody StoreOfCitycodeResp citycodeResp) throws Exception { List<StoreDetailList> detailLists = new ArrayList<>(); + + if (citycodeResp.getCityCode()==null){ + Map<String, String> geocode = gdMapGeocodingUtil.geocode(citycodeResp.getLongitude(), citycodeResp.getLatitude()); + String provinceCode = geocode.get("provinceCode"); + String cityCode = geocode.get("cityCode"); + citycodeResp.setCityCode(cityCode); + } + List<Store> list = storeService.list(new QueryWrapper<Store>() .eq("state",1 ) .eq("cityCode",citycodeResp.getCityCode())); if (list.size() > 0 ){ - if (ToolUtil.isEmpty(citycodeResp.getLongitude()) && ToolUtil.isEmpty(citycodeResp.getLatitude())){ - return detailLists; - } +// if (ToolUtil.isEmpty(citycodeResp.getLongitude()) && ToolUtil.isEmpty(citycodeResp.getLatitude())){ +// return detailLists; +// } for (Store store : list) { String current = citycodeResp.getLongitude() +","+citycodeResp.getLatitude(); String result = store.getLon()+","+store.getLat(); String distanceTOKilometer = gdMapGeocodingUtil.getDistanceTOKilometer(current, result); - long l = Long.parseLong(distanceTOKilometer); -// 取5公里范围内的门店 - if ( l > 5){ - continue; - } +// long l = Long.parseLong(distanceTOKilometer); +//// 取5公里范围内的门店 +// if ( l > 5){ +// continue; +// } StoreDetailList detailList = new StoreDetailList(); detailList.setStoreId(store.getId()); detailList.setStoreImg(store.getCoverDrawing()); detailList.setStoreName(store.getName()); detailList.setStoreAddress(store.getAddress()); detailList.setStorePhone(store.getPhone()); - detailList.setStoreDistance(l); +// detailList.setStoreDistance(l); detailList.setStoreTime(store.getStartTime() + "-" + store.getEndTime()); detailList.setStoreInfo(store.getIntroduce()); + detailList.setStoreDistance(Long.valueOf(distanceTOKilometer.lastIndexOf("."))); detailLists.add(detailList); } } @@ -380,6 +423,13 @@ if(list.size()>0){ tStoreOtherConfigTrues= tStoreOtherConfigTrueService.list(new LambdaQueryWrapper<TStoreOtherConfigTrue>().in(TStoreOtherConfigTrue::getPid, list.stream().map(TStoreOther::getId).collect(Collectors.toList())).eq(TStoreOtherConfigTrue::getState,1)); } + for (TStoreOtherConfigTrue tStoreOtherConfigTrue : tStoreOtherConfigTrues) { + for (TStoreOther tStoreOther : list) { + if (tStoreOtherConfigTrue.getPid()==tStoreOther.getId()){ + tStoreOtherConfigTrue.setSort(tStoreOther.getSort()); + } + } + } return ResultUtil.success(tStoreOtherConfigTrues); }catch (Exception e){ e.printStackTrace(); @@ -433,9 +483,9 @@ @ApiImplicitParams({ @ApiImplicitParam(value = "城市code", name = "cityCode", dataType = "string", required = true), }) - public ResultUtil<List<BaseVo>> queryStoreByCityCode(String cityCode){ + public ResultUtil<List<BaseVo>> queryStoreByCityCode(String provinceCode,String cityCode){ try { - List<BaseVo> list = storeService.queryStoreByCityCode(cityCode); + List<BaseVo> list = storeService.queryStoreByCityCode(provinceCode,cityCode); return ResultUtil.success(list); }catch (Exception e){ e.printStackTrace(); -- Gitblit v1.7.1