puzhibing
2023-07-06 2b4511ca363e74343e1cb678c23a9e7638800a3f
cloud-server-other/src/main/java/com/dsh/other/controller/StoreController.java
@@ -1,27 +1,43 @@
package com.dsh.other.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dsh.other.entity.Store;
import com.dsh.other.feignclient.model.GetAllNearbyStoreList;
import com.dsh.other.feignclient.model.StoreDetailOfCourse;
import com.dsh.other.feignclient.model.StoreInfo;
import com.dsh.other.feignclient.model.StoreLonLatList;
import com.dsh.other.model.BaseVo;
import com.dsh.other.service.StoreService;
import com.dsh.other.util.GDMapGeocodingUtil;
import com.dsh.other.util.ResultUtil;
import com.dsh.other.util.ToolUtil;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import java.util.*;
@RestController
@RequestMapping("/base/protocol")
@RequestMapping("")
public class StoreController {
    @Autowired
    private StoreService stoService;
    private StoreService storeService;
    @PostMapping("/storeDetail/courseOfSto")
    @Autowired
    private GDMapGeocodingUtil gdMapGeocodingUtil;
    @PostMapping("/base/protocol/storeDetail/courseOfSto")
    public StoreDetailOfCourse getCourseOfStore(@RequestBody Integer storeId){
        StoreDetailOfCourse ofCourse = new StoreDetailOfCourse();
        Store store = stoService.getById(storeId);
        Store store = storeService.getById(storeId);
        if (null != store){
            ofCourse.setStoreName(store.getName());
            ofCourse.setStoreAddr(store.getAddress());
@@ -29,4 +45,152 @@
        return ofCourse;
    }
    @PostMapping("/base/protocol/storeDetail/nearbyStore")
    public List<StoreInfo> getAllNearbyStoreList(@RequestBody GetAllNearbyStoreList list ){
        String current = list.getLongitude()+","+list.getLatitude();
        List<StoreInfo> storeInfos = new ArrayList<>();
        String cityCode = "";
        try {
            Map<String, String> geocode = gdMapGeocodingUtil.geocode(list.getLongitude(), list.getLatitude());
            cityCode = geocode.get("cityCode");
        }catch (Exception e){
            e.printStackTrace();
        }
        List<Store> storeList = storeService.list(new QueryWrapper<Store>()
                .eq("state", 1)
                .eq("cityCode",cityCode));
        if (storeList.size() > 0){
            for (Store store : storeList) {
                String storeLon = store.getLon();
                String storeLat = store.getLat();
                String result = storeLon+","+storeLat;
                String distanceTOKilometer = gdMapGeocodingUtil.getDistanceTOKilometer(current, result);
                StoreInfo info = new StoreInfo();
                info.setStoreId(store.getId());
                info.setStoreName(store.getName());
                info.setStoreImg(store.getRealPicture());
                info.setDistance(Long.parseLong(distanceTOKilometer));
                info.setStoreAddr(store.getAddress());
                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);
        }
        return storeInfos;
    }
    @PostMapping("/base/protocol/storeDetail/storeOfLonLat")
    public List<StoreLonLatList> getAllStoreLonLats(@RequestBody GetAllNearbyStoreList list ){
        List<StoreLonLatList> storeInfos = new ArrayList<>();
        try {
            Map<String, String> geocode = gdMapGeocodingUtil.geocode(list.getLongitude(), list.getLatitude());
            String cityCode = geocode.get("cityCode");
            List<Store> storeList = storeService.list(new QueryWrapper<Store>()
                    .eq("cityCode",cityCode));
            if (storeList.size() > 0){
                for (Store store : storeList) {
                    StoreLonLatList latList = new StoreLonLatList();
                    latList.setStoreId(store.getId());
                    latList.setLongitude(store.getLon());
                    latList.setLatitude(store.getLat());
                    storeInfos.add(latList);
                }
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return storeInfos;
    }
    /**
     * 获取门店列表
     * @param provinceCode
     * @param cityCode
     * @return
     */
    @ResponseBody
    @PostMapping("/store/queryStoreList")
    public List<Store> queryStoreList(@RequestBody String provinceCode, @RequestBody String cityCode){
        try {
            return storeService.queryStorsList(provinceCode, cityCode);
        }catch (Exception e){
            e.printStackTrace();
            return new ArrayList<>();
        }
    }
    @ResponseBody
    @PostMapping("/base/store/queryStoreLists")
    @ApiOperation(value = "获取门店列表", tags = {"APP-加入玩湃", "APP-课程列表"})
    @ApiImplicitParams({
            @ApiImplicitParam(value = "经纬", name = "lon", dataType = "string", required = true),
            @ApiImplicitParam(value = "纬度", name = "lat", dataType = "string", required = true),
    })
    public ResultUtil<List<BaseVo>> queryStoreLists(@RequestBody String lon, @RequestBody String lat){
        if(ToolUtil.isEmpty(lon)){
            return ResultUtil.paranErr("lon");
        }
        if(ToolUtil.isEmpty(lat)){
            return ResultUtil.paranErr("lat");
        }
        try {
            List<BaseVo> baseVos = storeService.queryStoreLists(lon, lat);
            return ResultUtil.success(baseVos);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
    /**
     * 根据门店模糊搜索店铺
     * @param name
     * @return
     */
    @ResponseBody
    @PostMapping("/store/queryStoreListByName")
    public List<Store> queryStoreListByName(@RequestBody String name){
        try {
            List<Store> stores = storeService.list(new QueryWrapper<Store>().eq("state", 1).like("name", name));
            return stores;
        }catch (Exception e){
            e.printStackTrace();
            return new ArrayList<>();
        }
    }
    /**
     * 根据门店
     * @param id
     * @return
     */
    @ResponseBody
    @PostMapping("/store/queryStoreById")
    public Store queryStoreById(@RequestBody Integer id){
        try {
            return storeService.getById(id);
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }
}