| | |
| | | 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 org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | |
| | | |
| | | @Service |
| | |
| | | private CompanyMapper companyMapper; |
| | | |
| | | @Autowired |
| | | private GDMapGeocodingUtil gdMapGeocodingUtil; |
| | | private ICityService cityService; |
| | | |
| | | |
| | | /** |
| | | * 根据经纬度获取所属企业 |
| | | * @param lon |
| | | * @param lat |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | @Override |
| | | public Company query(String lon, String lat) throws Exception { |
| | | Map<String, String> geocode = gdMapGeocodingUtil.geocode(String.valueOf(lon), String.valueOf(lat)); |
| | | String districtCode = geocode.get("districtCode"); |
| | | Company query = this.query(districtCode); |
| | | return query; |
| | | } |
| | | |
| | | |
| | | @Override |
| | |
| | | return null; |
| | | } |
| | | AddressComponentsVo[] addressComponentsVos = reverseGeocode.getAddressComponentsVos(); |
| | | String[] city = new String[addressComponentsVos.length]; |
| | | String[] citys = new String[addressComponentsVos.length]; |
| | | for (int i = 0; i < addressComponentsVos.length; i++) { |
| | | city[i] = addressComponentsVos[i].getLongName(); |
| | | citys[i] = addressComponentsVos[i].getLongName(); |
| | | } |
| | | Company query = this.query(city); |
| | | Company query = this.query(citys); |
| | | return query; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 根据行政编号获取所属企业 |
| | | * @param code |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | @Override |
| | | public Company query(String code) throws Exception { |
| | | String province = code.substring(0, 2) + "0000"; |
| | | String city = code.substring(0, 4) + "00"; |
| | | List<Company> query = companyMapper.query(province, city, code); |
| | | if(query.size() == 0){ |
| | | query = companyMapper.query(province, city, null); |
| | | } |
| | | if(query.size() == 0){ |
| | | query = companyMapper.query(province, null, null); |
| | | } |
| | | for(int i = 3; i > 0; i--){ |
| | | for(Company company : query){ |
| | | if(company.getType() == i){ |
| | | return company; |
| | | } |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public Company query(String[] city) throws Exception { |
| | | List<Company> query = companyMapper.queryList(city, 3); |
| | | if(query.size() == 0){ |
| | | query = companyMapper.queryList(city, 2); |
| | | } |
| | | if(query.size() == 0){ |
| | | query = companyMapper.queryList(city, 1); |
| | | } |
| | | if(query.size() > 0){ |
| | | return query.get(0); |
| | | } |
| | | return null; |
| | | List<City> cities = cityService.selectList(new EntityWrapper<City>().in("chineseName", Arrays.asList(city)).or() |
| | | .in("englishName", Arrays.asList(city)).or().in("frenchName", Arrays.asList(city))); |
| | | List<Integer> collect = cities.stream().map(City::getId).collect(Collectors.toList()); |
| | | return companyMapper.query(collect); |
| | | } |
| | | } |