puzhibing
2023-05-18 53562814add61acfdc02d6b25dae6324f6fd5f92
ManagementIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/general/TOpenCityController.java
@@ -10,11 +10,15 @@
import com.stylefeng.guns.core.shiro.ShiroKit;
import com.stylefeng.guns.core.util.DateUtil;
import com.stylefeng.guns.core.util.SinataUtil;
import com.stylefeng.guns.modular.system.model.City;
import com.stylefeng.guns.modular.system.model.TOpenCityBusiness;
import com.stylefeng.guns.modular.system.model.TRegion;
import com.stylefeng.guns.modular.system.service.ICityService;
import com.stylefeng.guns.modular.system.service.ITOpenCityBusinessService;
import com.stylefeng.guns.modular.system.service.ITRegionService;
import com.stylefeng.guns.modular.system.util.GaoDeMapUtil;
import com.stylefeng.guns.modular.system.util.GoogleMap.FindPlaceFromTextVo;
import com.stylefeng.guns.modular.system.util.GoogleMap.GoogleMapUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@@ -52,6 +56,12 @@
    @Autowired
    private ITOpenCityBusinessService tOpenCityBusinessService;
    @Autowired
    private ICityService cityService;
    /**
     * 跳转到城市管理首页
     */
@@ -65,8 +75,8 @@
     */
    @RequestMapping("/tOpenCity_add")
    public String tOpenCityAdd(Model model) {
        List<TRegion> provinceList = tRegionService.selectList(new EntityWrapper<TRegion>().eq("parent_id", 0));
        model.addAttribute("provinceList",provinceList);
        List<City> city = cityService.selectList(new EntityWrapper<City>().orderBy("id"));
        model.addAttribute("city", city);
        return PREFIX + "tOpenCity_add.html";
    }
@@ -79,15 +89,8 @@
        model.addAttribute("item",tOpenCity);
        LogObjectHolder.me().set(tOpenCity);
        //省
        List<TRegion> provinceList = tRegionService.selectList(new EntityWrapper<TRegion>().eq("parent_id", 0));
        model.addAttribute("provinceList",provinceList);
        //市
        List<TRegion> cityList = tRegionService.selectList(new EntityWrapper<TRegion>().eq("parent_id", tOpenCity.getAreaId()));
        model.addAttribute("cityList",cityList);
        //区
        List<TRegion> areaList = tRegionService.selectList(new EntityWrapper<TRegion>().eq("parent_id", tOpenCity.getCityId()));
        model.addAttribute("areaList",areaList);
        List<City> city = cityService.selectList(new EntityWrapper<City>().orderBy("id"));
        model.addAttribute("city", city);
        //经营业务
        List<Map<String,Object>> businessList = tOpenCityService.getBusinessByCityId(tOpenCityId);
        model.addAttribute("businessList",businessList);
@@ -129,34 +132,19 @@
    @ResponseBody
    public Object add(TOpenCity tOpenCity,@RequestParam String businessTypeStr,Integer areaId,Integer cityId,Integer provinceId) {
        //获取code
        if (SinataUtil.isNotEmpty(areaId)){
            TRegion area = tRegionService.selectById(areaId);
            tOpenCity.setCode(area.getCode());
        }
        if (SinataUtil.isNotEmpty(cityId)){
            TRegion city = tRegionService.selectById(cityId);
            tOpenCity.setCode(city.getCode());
        }
        if (SinataUtil.isNotEmpty(provinceId)){
            TRegion province = tRegionService.selectById(provinceId);
            tOpenCity.setCode(province.getCode());
        }
        tOpenCity.setAreaId(areaId);
        tOpenCity.setCityId(cityId);
        tOpenCity.setProvinceId(provinceId);
        //获取经纬度
        String address = tOpenCity.getAreaName();
        if (SinataUtil.isNotEmpty(tOpenCity.getCityName())){
            address+=tOpenCity.getCityName();
        City city = cityService.selectById(cityId);
        FindPlaceFromTextVo textsearch = null;
        try {
            textsearch = GoogleMapUtil.textsearch(city.getEnglishName());
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (SinataUtil.isNotEmpty(tOpenCity.getProvinceName())){
            address+=tOpenCity.getProvinceName();
        if(null == textsearch){
            return "查询地图异常";
        }
        JSONObject positionObj = GaoDeMapUtil.getLngAndLat(address);
        String longitude = positionObj.getString("longitude");
        String latitude = positionObj.getString("latitude");
        tOpenCity.setLon(Double.valueOf(longitude));
        tOpenCity.setLat(Double.valueOf(latitude));
        tOpenCity.setLat(textsearch.getLat());
        tOpenCity.setLon(textsearch.getLng());
        tOpenCity.setInsertTime(new Date());
        tOpenCity.setInsertUser(ShiroKit.getUser().getId());
        tOpenCityService.insert(tOpenCity);
@@ -186,16 +174,8 @@
            Integer businessType = 0;
            if ("专车".equals(type)){
                businessType = 1;
            }else if ("出租车".equals(type)){
                businessType = 2;
            }else if ("跨城出行".equals(type)){
                businessType = 3;
            }else if ("跨城小件物流".equals(type)){
            }else if ("市内小件物流".equals(type)){
                businessType = 4;
            }else if ("同城小件物流".equals(type)){
                businessType = 5;
            }else if ("包车".equals(type)){
                businessType = 6;
            }
            business.setBusinessType(businessType);
            business.setSort(jsonObject.getInteger("sort"));
@@ -225,50 +205,20 @@
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(TOpenCity tOpenCity,@RequestParam String businessTypeStr,Integer areaId,Integer cityId,Integer provinceId) {
        if (SinataUtil.isNotEmpty(areaId)){
            TRegion area = tRegionService.selectById(areaId);
            tOpenCity.setCode(area.getCode());
        //获取code
        tOpenCity.setCityId(cityId);
        City city = cityService.selectById(cityId);
        FindPlaceFromTextVo textsearch = null;
        try {
            textsearch = GoogleMapUtil.textsearch(city.getEnglishName());
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (SinataUtil.isNotEmpty(cityId)){
            TRegion city = tRegionService.selectById(cityId);
            tOpenCity.setCode(city.getCode());
        if(null == textsearch){
            return "查询地图异常";
        }
        if (SinataUtil.isNotEmpty(provinceId)){
            TRegion province = tRegionService.selectById(provinceId);
            tOpenCity.setCode(province.getCode());
        }
        if (SinataUtil.isEmpty(areaId)){
            tOpenCity.setAreaId(0);
            tOpenCity.setAreaName("");
        }else{
            tOpenCity.setAreaId(areaId);
        }
        if (SinataUtil.isEmpty(cityId)){
            tOpenCity.setCityId(0);
            tOpenCity.setCityName("");
        }else{
            tOpenCity.setCityId(cityId);
        }
        if (SinataUtil.isEmpty(provinceId)){
            tOpenCity.setProvinceId(0);
            tOpenCity.setProvinceName("");
        }else{
            tOpenCity.setProvinceId(provinceId);
        }
        //获取经纬度
        String address = tOpenCity.getAreaName();
        if (SinataUtil.isNotEmpty(tOpenCity.getCityName())){
            address+=tOpenCity.getCityName();
        }
        if (SinataUtil.isNotEmpty(tOpenCity.getProvinceName())){
            address+=tOpenCity.getProvinceName();
        }
        JSONObject positionObj = GaoDeMapUtil.getLngAndLat(address);
        String longitude = positionObj.getString("longitude");
        String latitude = positionObj.getString("latitude");
        tOpenCity.setLon(Double.valueOf(longitude));
        tOpenCity.setLat(Double.valueOf(latitude));
        tOpenCity.setLat(textsearch.getLat());
        tOpenCity.setLon(textsearch.getLng());
        tOpenCity.setUpdateTime(new Date());
        tOpenCity.setUpdateUser(ShiroKit.getUser().getId());
        tOpenCityService.updateById(tOpenCity);