Pu Zhibing
2025-04-03 33ac3b8bf6683024784d9e3152732bc0d50472c3
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
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
public class CompanyCityServiceImpl extends ServiceImpl<CompanyCityMapper, CompanyCity> implements ICompanyCityService {
 
    @Resource
    private CompanyMapper companyMapper;
 
    @Autowired
    private ICityService cityService;
    
    @Resource
    private RedisUtil redisUtil;
 
 
 
 
    @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.query(citys);
        return query;
    }
 
 
 
 
    @Override
    public Company query(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.indexOf(chineseName) != -1){
                    collect.add(city1.getId());
                    break;
                }
                if(s.indexOf(englishName) != -1){
                    collect.add(city1.getId());
                    break;
                }
                if(s.indexOf(frenchName) != -1){
                    collect.add(city1.getId());
                    break;
                }
            }
        }
        if(collect.size() == 0){
            return null;
        }
        return companyMapper.query(collect);
    }
    
    
    @Override
    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.indexOf(chineseName) != -1){
                    collect.add(city1.getId());
                    break;
                }
                if(s.indexOf(englishName) != -1){
                    collect.add(city1.getId());
                    break;
                }
                if(s.indexOf(frenchName) != -1){
                    collect.add(city1.getId());
                    break;
                }
            }
        }
        List<Company> query = companyMapper.queryList1(collect, 3);
        if(query.size() == 0){
            query = companyMapper.queryList1(collect, 2);
        }
        if(query.size() == 0){
            query = companyMapper.queryList1(collect, 1);
        }
        if(query.size() > 0){
            return query.get(0);
        }
        return null;
    }
    
    
    
    @Override
    public List<Company> query2(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.indexOf(chineseName) != -1){
                    collect.add(city1.getId());
                    break;
                }
                if(s.indexOf(englishName) != -1){
                    collect.add(city1.getId());
                    break;
                }
                if(s.indexOf(frenchName) != -1){
                    collect.add(city1.getId());
                    break;
                }
            }
        }
        List<Company> query = companyMapper.queryList1(collect, 3);
        if(query.size() == 0){
            query = companyMapper.queryList1(collect, 2);
        }
        if(query.size() == 0){
            query = companyMapper.queryList1(collect, 1);
        }
        return query;
    }
}