package com.dsh.guns.modular.system.controller.general; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.dsh.course.entity.City; import com.dsh.course.mapper.CityMapper; import com.dsh.course.util.GoogleMap.GoogleMapUtil; import com.dsh.course.util.GoogleMap.ReverseGeocodeVo; import com.dsh.guns.config.UserExt; import com.dsh.guns.core.base.controller.BaseController; import com.dsh.guns.core.log.LogObjectHolder; import com.dsh.guns.core.util.SinataUtil; import com.dsh.guns.modular.system.model.TbHotAddress; import com.dsh.guns.modular.system.service.ITbHotAddressService; import com.dsh.guns.modular.system.util.ResultUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.*; import java.util.ArrayList; import java.util.Date; import java.util.List; /** * 控制器 * * @author fengshuonan * @Date 2022-06-17 14:43:39 */ @Controller @RequestMapping("/THotAddress") public class THotAddressController extends BaseController { private String PREFIX = "/system/tHotAddress/"; @Autowired private ITbHotAddressService tbHotAddressService; @Autowired private CityMapper cityMapper; @Autowired private GoogleMapUtil googleMapUtil; @RequestMapping(value = "/change") @ResponseBody public Object change(@RequestParam Integer id) { List list = new ArrayList<>(); if (SinataUtil.isNotEmpty(id)){ list = cityMapper.selectList(new QueryWrapper().eq("pid", id)); } if(UserExt.getLanguage()==2){ for (City city : list) { city.setChineseName(city.getEnglishName()); } } if(UserExt.getLanguage()==3){ for (City city : list) { city.setChineseName(city.getIndonesianName()); } } return list; } /** * 跳转到首页 */ @RequestMapping("") public String index(Model model) { model.addAttribute("language", UserExt.getLanguage()); return PREFIX + "tbHotAddress.html"; } /** * 跳转到添加 */ @RequestMapping("/tbHotAddress_add") public String tbHotAddressAdd(Model model) { List pid = cityMapper.selectList(new QueryWrapper().eq("pid", 0)); if(UserExt.getLanguage()==2){ for (City city : pid) { city.setChineseName(city.getEnglishName()); } }else if(UserExt.getLanguage()==3){ for (City city : pid) { city.setChineseName(city.getIndonesianName()); } } model.addAttribute("item",pid); model.addAttribute("language",UserExt.getLanguage()); return PREFIX + "tbHotAddress_add.html"; } /** * 跳转到修改 */ @RequestMapping("/tbHotAddress_update/{tbHotAddressId}") public String tbHotAddressUpdate(@PathVariable Integer tbHotAddressId, Model model) { TbHotAddress tbHotAddress = tbHotAddressService.getById(tbHotAddressId); model.addAttribute("item",tbHotAddress); List pid = cityMapper.selectList(new QueryWrapper().eq("pid", 0)); if(UserExt.getLanguage()==2){ for (City city : pid) { city.setChineseName(city.getEnglishName()); } }else if(UserExt.getLanguage()==3){ for (City city : pid) { city.setChineseName(city.getIndonesianName()); } } List pid1 = cityMapper.selectList(new QueryWrapper().eq("pid", tbHotAddress.getAreaId())); if(UserExt.getLanguage()==2){ for (City city : pid1) { city.setChineseName(city.getEnglishName()); } } if(UserExt.getLanguage()==3){ for (City city : pid1) { city.setChineseName(city.getIndonesianName()); } } model.addAttribute("cityList",pid1); model.addAttribute("item1",pid); model.addAttribute("language",UserExt.getLanguage()); LogObjectHolder.me().set(tbHotAddress); return PREFIX + "tbHotAddress_edit.html"; } /** * 获取列表 */ @RequestMapping(value = "/list") @ResponseBody public Object list(String time,String name) { List list = tbHotAddressService.getList(time,name); return list; } /** * 新增 */ @RequestMapping(value = "/add") @ResponseBody public Object add(Integer cityId,String address,Double lon,Double lat,String name,Integer sort,Integer cityId1) { TbHotAddress tbHotAddress = new TbHotAddress(); tbHotAddress.setAddress(address); tbHotAddress.setHide(0); tbHotAddress.setCityId(cityId1); tbHotAddress.setCreateTime(new Date()); tbHotAddress.setLat(lat); tbHotAddress.setAreaId(cityId); tbHotAddress.setLon(lon); tbHotAddress.setName(name); tbHotAddress.setSort(sort); tbHotAddressService.save(tbHotAddress); return SUCCESS_TIP; } /** * 删除 */ @RequestMapping(value = "/delete") @ResponseBody public Object delete(@RequestParam Integer THotAddressId) { TbHotAddress byId = tbHotAddressService.getById(THotAddressId); byId.setHide(1); tbHotAddressService.updateById(byId); return SUCCESS_TIP; } /** * 修改 */ @RequestMapping(value = "/update") @ResponseBody public Object update(TbHotAddress tbHotAddress,Integer cityId1) { tbHotAddress.setAreaId(tbHotAddress.getCityId()); tbHotAddress.setCityId(cityId1); tbHotAddressService.updateById(tbHotAddress); return SUCCESS_TIP; } /** * 详情 */ @RequestMapping(value = "/detail/{tbHotAddressId}") @ResponseBody public Object detail(@PathVariable("tbHotAddressId") Integer tbHotAddressId) { return tbHotAddressService.getById(tbHotAddressId); } @ResponseBody @RequestMapping(value = "/queryPlaceInfo", produces = "application/json;charset=utf-8") public ResultUtil queryPlaceInfo(Double lat, Double lng){ try { ReverseGeocodeVo reverseGeocode = googleMapUtil.getReverseGeocode(lat, lng); if(null != reverseGeocode){ return ResultUtil.success(reverseGeocode.getAddress()); } return ResultUtil.error("定位失败"); }catch (Exception e){ e.printStackTrace(); return ResultUtil.runErr(); } } }