package com.stylefeng.guns.modular.system.service.impl;
|
|
import com.stylefeng.guns.modular.system.dao.TCompanyMapper;
|
import com.stylefeng.guns.modular.system.model.TCompany;
|
import com.stylefeng.guns.modular.system.model.TCompanyCity;
|
import com.stylefeng.guns.modular.system.dao.TCompanyCityMapper;
|
import com.stylefeng.guns.modular.system.service.ITCompanyCityService;
|
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
|
import com.stylefeng.guns.modular.system.util.GDMapGeocodingUtil;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import javax.annotation.Resource;
|
import java.util.List;
|
import java.util.Map;
|
|
/**
|
* <p>
|
* 公司经营地区 服务实现类
|
* </p>
|
*
|
* @author 吕雪
|
* @since 2020-06-06
|
*/
|
@Service
|
public class TCompanyCityServiceImpl extends ServiceImpl<TCompanyCityMapper, TCompanyCity> implements ITCompanyCityService {
|
|
@Autowired
|
private GDMapGeocodingUtil gdMapGeocodingUtil;
|
|
@Resource
|
private TCompanyMapper companyMapper;
|
|
@Override
|
public TCompany query(String lon, String lat) throws Exception {
|
Map<String, String> geocode = gdMapGeocodingUtil.geocode(String.valueOf(lon), String.valueOf(lat));
|
String districtCode = geocode.get("districtCode");
|
TCompany query = this.query(districtCode);
|
return query;
|
}
|
|
|
public TCompany query(String code) throws Exception {
|
String province = code.substring(0, 2) + "0000";
|
String city = code.substring(0, 4) + "00";
|
List<TCompany> 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(TCompany company : query){
|
if(company.getType() == i){
|
return company;
|
}
|
}
|
}
|
return null;
|
}
|
}
|