| | |
| | | package com.stylefeng.guns.modular.system.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.baomidou.mybatisplus.service.impl.ServiceImpl; |
| | | import com.stylefeng.guns.modular.system.dao.CompanyCityMapper; |
| | | import com.stylefeng.guns.modular.system.dao.CompanyMapper; |
| | | import com.stylefeng.guns.modular.system.model.City; |
| | | import com.stylefeng.guns.modular.system.model.Company; |
| | | import com.stylefeng.guns.modular.system.model.CompanyCity; |
| | | import com.stylefeng.guns.modular.system.service.ICityService; |
| | | import com.stylefeng.guns.modular.system.service.ICompanyCityService; |
| | | import com.stylefeng.guns.modular.system.util.GDMapGeocodingUtil; |
| | | 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.util.RedisUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | |
| | | |
| | | @Service |
| | |
| | | |
| | | @Autowired |
| | | private GDMapGeocodingUtil gdMapGeocodingUtil; |
| | | |
| | | @Autowired |
| | | private ICityService cityService; |
| | | |
| | | @Resource |
| | | private RedisUtil redisUtil; |
| | | |
| | | |
| | | /** |
| | |
| | | Company query = this.query(districtCode); |
| | | return query; |
| | | } |
| | | |
| | | |
| | | |
| | | @Override |
| | | public Company query1(Integer uid, String lon, String lat) throws Exception { |
| | | String tripId = redisUtil.getValue("trip" + uid); |
| | | ReverseGeocodeVo reverseGeocode = GoogleMapUtil.getReverseGeocode(Double.valueOf(lat), Double.valueOf(lon), tripId); |
| | | if(null == reverseGeocode){ |
| | | return null; |
| | | } |
| | | AddressComponentsVo[] addressComponentsVos = reverseGeocode.getAddressComponentsVos(); |
| | | String[] citys = new String[addressComponentsVos.length]; |
| | | for (int i = 0; i < addressComponentsVos.length; i++) { |
| | | citys[i] = addressComponentsVos[i].getLongName(); |
| | | } |
| | | Company query = this.query1(citys); |
| | | return query; |
| | | } |
| | | |
| | | /** |
| | | * 根据行政编号获取所属企业 |
| | | * @param code |
| | |
| | | |
| | | @Override |
| | | public Company query(String[] city) throws Exception { |
| | | List<Company> query = companyMapper.queryList(city, 3); |
| | | List<City> cities1 = cityService.selectList(null); |
| | | List<Integer> collect = new ArrayList<>(); |
| | | for (City city1 : cities1) { |
| | | String chineseName = city1.getChineseName(); |
| | | String englishName = city1.getEnglishName(); |
| | | String frenchName = city1.getFrenchName(); |
| | | for (String s : city) { |
| | | if(s.equals(chineseName)){ |
| | | collect.add(city1.getId()); |
| | | break; |
| | | } |
| | | if(s.equals(englishName)){ |
| | | collect.add(city1.getId()); |
| | | break; |
| | | } |
| | | if(s.equals(frenchName)){ |
| | | collect.add(city1.getId()); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | if(collect.size() == 0){ |
| | | for (City city1 : cities1) { |
| | | String chineseName = city1.getChineseName(); |
| | | String englishName = city1.getEnglishName(); |
| | | String frenchName = city1.getFrenchName(); |
| | | for (String s : city) { |
| | | if(s.contains(chineseName)){ |
| | | collect.add(city1.getId()); |
| | | break; |
| | | } |
| | | if(s.contains(englishName)){ |
| | | collect.add(city1.getId()); |
| | | break; |
| | | } |
| | | if(s.contains(frenchName)){ |
| | | collect.add(city1.getId()); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | if(collect.size() == 0){ |
| | | return null; |
| | | } |
| | | List<Company> query = companyMapper.queryList(collect, 3); |
| | | if(query.size() == 0){ |
| | | query = companyMapper.queryList(city, 2); |
| | | query = companyMapper.queryList(collect, 2); |
| | | } |
| | | if(query.size() == 0){ |
| | | query = companyMapper.queryList(city, 1); |
| | | query = companyMapper.queryList(collect, 1); |
| | | } |
| | | if(query.size() > 0){ |
| | | return query.get(0); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | |
| | | |
| | | public Company query1(String[] city) throws Exception { |
| | | List<City> cities1 = cityService.selectList(null); |
| | | List<Integer> collect = new ArrayList<>(); |
| | | for (City city1 : cities1) { |
| | | String chineseName = city1.getChineseName(); |
| | | String englishName = city1.getEnglishName(); |
| | | String frenchName = city1.getFrenchName(); |
| | | for (String s : city) { |
| | | if(s.equals(chineseName)){ |
| | | collect.add(city1.getId()); |
| | | break; |
| | | } |
| | | if(s.equals(englishName)){ |
| | | collect.add(city1.getId()); |
| | | break; |
| | | } |
| | | if(s.equals(frenchName)){ |
| | | collect.add(city1.getId()); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | if(collect.size() == 0){ |
| | | for (City city1 : cities1) { |
| | | String chineseName = city1.getChineseName(); |
| | | String englishName = city1.getEnglishName(); |
| | | String frenchName = city1.getFrenchName(); |
| | | for (String s : city) { |
| | | if(s.contains(chineseName)){ |
| | | collect.add(city1.getId()); |
| | | break; |
| | | } |
| | | if(s.contains(englishName)){ |
| | | collect.add(city1.getId()); |
| | | break; |
| | | } |
| | | if(s.contains(frenchName)){ |
| | | collect.add(city1.getId()); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | if(collect.size() == 0){ |
| | | return null; |
| | | } |
| | | return companyMapper.query1(collect); |
| | | } |
| | | } |