| | |
| | | import com.baomidou.mybatisplus.service.impl.ServiceImpl; |
| | | import com.stylefeng.guns.core.util.ToolUtil; |
| | | import com.stylefeng.guns.modular.system.dao.OpenCityMapper; |
| | | import com.stylefeng.guns.modular.system.model.City; |
| | | import com.stylefeng.guns.modular.system.model.OpenCity; |
| | | import com.stylefeng.guns.modular.system.model.UserInfo; |
| | | import com.stylefeng.guns.modular.system.service.ICityService; |
| | | import com.stylefeng.guns.modular.system.service.IOpenCityService; |
| | | import com.stylefeng.guns.modular.system.service.IUserInfoService; |
| | | import com.stylefeng.guns.modular.system.util.GoogleMap.AddressComponentsVo; |
| | | import com.stylefeng.guns.modular.system.util.GoogleMap.GoogleMapUtil; |
| | | import com.stylefeng.guns.modular.system.util.GoogleMap.ReverseGeocodeVo; |
| | | import com.stylefeng.guns.modular.system.warpper.BaseWarpper; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | |
| | | @Resource |
| | | private OpenCityMapper openCityMapper; |
| | | |
| | | @Autowired |
| | | private ICityService cityService; |
| | | |
| | | @Autowired |
| | | private IUserInfoService userInfoService; |
| | | |
| | | |
| | | /** |
| | | * 获取开通城市列表 |
| | |
| | | * @throws Exception |
| | | */ |
| | | @Override |
| | | public List<BaseWarpper> queryOpenCity() throws Exception { |
| | | public List<BaseWarpper> queryOpenCity(Integer uid, Integer language) throws Exception { |
| | | if(null == language){ |
| | | language = 2; |
| | | } |
| | | if(null != uid){ |
| | | UserInfo userInfo = userInfoService.selectById(uid); |
| | | language = userInfo.getLanguage(); |
| | | } |
| | | List<OpenCity> openCities = openCityMapper.queryOpenCity(); |
| | | List<BaseWarpper> list = new ArrayList<>(); |
| | | for(OpenCity c : openCities){ |
| | | BaseWarpper baseWarpper = new BaseWarpper(); |
| | | baseWarpper.setId(c.getId()); |
| | | baseWarpper.setName(ToolUtil.isEmpty(c.getProvinceName()) ? |
| | | (ToolUtil.isEmpty(c.getCityName()) ? (ToolUtil.isEmpty(c.getAreaName()) ? "" : c.getAreaName()) : c.getCityName()) : c.getProvinceName()); |
| | | City city = cityService.selectById(c.getCityId()); |
| | | baseWarpper.setName(language == 1 ? city.getChineseName() : language == 2 ? city.getEnglishName() : language == 3 ? city.getFrenchName() : city.getEnglishName()); |
| | | baseWarpper.setLon(null != c.getLon() ? c.getLon() : 0); |
| | | baseWarpper.setLat(null != c.getLat() ? c.getLat() : 0); |
| | | baseWarpper.setContent(c.getCode()); |
| | | list.add(baseWarpper); |
| | | } |
| | | return list; |
| | |
| | | |
| | | /** |
| | | * 判断是否是开通城市 |
| | | * @param code |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | @Override |
| | | public boolean openCity(String code) throws Exception { |
| | | String province = code.substring(0, 2) + "0000"; |
| | | String city = code.substring(0, 4) + "00"; |
| | | List<OpenCity> openCities = openCityMapper.queryByCode(code); |
| | | if(openCities.size() == 0){ |
| | | openCities = openCityMapper.queryByCode(city); |
| | | public boolean openCity(Double lat, Double lnt) throws Exception { |
| | | ReverseGeocodeVo reverseGeocode = GoogleMapUtil.getReverseGeocode(lat, lnt); |
| | | if(null == reverseGeocode){ |
| | | return false; |
| | | } |
| | | if(openCities.size() == 0){ |
| | | openCities = openCityMapper.queryByCode(province); |
| | | AddressComponentsVo[] addressComponentsVos = reverseGeocode.getAddressComponentsVos(); |
| | | String[] city = new String[addressComponentsVos.length]; |
| | | for (int i = 0; i < addressComponentsVos.length; i++) { |
| | | city[i] = addressComponentsVos[i].getLongName(); |
| | | } |
| | | List<OpenCity> openCities = openCityMapper.queryByCode(city); |
| | | if(openCities.size() == 0){ |
| | | return false; |
| | | } |