xuhy
2023-08-11 3c1223bf3eb6df077b48637a7c93a93246a1a8ae
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package com.stylefeng.guns.modular.system.service.impl;
 
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.Company;
import com.stylefeng.guns.modular.system.model.CompanyCity;
import com.stylefeng.guns.modular.system.service.ICompanyCityService;
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;
 
 
@Service
public class CompanyCityServiceImpl extends ServiceImpl<CompanyCityMapper, CompanyCity> implements ICompanyCityService {
 
    @Resource
    private CompanyMapper companyMapper;
 
    @Autowired
    private GDMapGeocodingUtil gdMapGeocodingUtil;
 
 
    /**
     * 根据经纬度获取所属企业
     * @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;
    }
 
 
    /**
     * 根据行政编号获取所属企业
     * @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;
    }
}