zhibing.pu
2024-08-27 8f39e870ca9519d8a8190c038d15a030149de98e
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
package com.stylefeng.guns.modular.system.service.impl;
 
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.stylefeng.guns.modular.system.dao.PhoneMapper;
import com.stylefeng.guns.modular.system.model.Phone;
import com.stylefeng.guns.modular.system.service.IPhoneService;
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.stereotype.Service;
 
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
 
@Service
public class PhoneServiceImpl extends ServiceImpl<PhoneMapper, Phone> implements IPhoneService {
 
    @Resource
    private PhoneMapper phoneMapper;
    
    @Resource
    private RedisUtil redisUtil;
    
    
    
 
    /**
     * 获取所有系统电话
     * @return
     * @throws Exception
     */
    @Override
    public List<Phone> queryPhones(Integer uid, Double lat, Double lnt) throws Exception {
        String tripId = redisUtil.getValue("trip" + uid);
        ReverseGeocodeVo reverseGeocode = GoogleMapUtil.getReverseGeocode(lat, lnt, tripId);
        if(null == reverseGeocode){
            return new ArrayList<>();
        }
        AddressComponentsVo[] addressComponentsVos = reverseGeocode.getAddressComponentsVos();
        String[] city = new String[addressComponentsVos.length];
        for (int i = 0; i < addressComponentsVos.length; i++) {
            city[i] = addressComponentsVos[i].getLongName();
        }
        List<Phone> list = phoneMapper.queryPhones(city);
        return list;
    }
 
 
    /**
     * 获取客服电话(个人中心)
     * @return
     * @throws Exception
     */
    @Override
    public Map<String, Object> queryCustomerPhone(Integer uid, Double lat, Double lnt) throws Exception {
        String tripId = redisUtil.getValue("trip" + uid);
        ReverseGeocodeVo reverseGeocode = GoogleMapUtil.getReverseGeocode(lat, lnt, tripId);
        if(null == reverseGeocode){
            return new HashMap<>();
        }
        AddressComponentsVo[] addressComponentsVos = reverseGeocode.getAddressComponentsVos();
        String[] city = new String[addressComponentsVos.length];
        for (int i = 0; i < addressComponentsVos.length; i++) {
            city[i] = addressComponentsVos[i].getLongName();
        }
        Map<String, Object> map = new HashMap<>();
        //平台电话
        Phone query = phoneMapper.query(2, 1, city);
        map.put("platform", null != query ? query.getPhone() : "");
 
        //公司
        query = phoneMapper.query(2, 2, city);
        map.put("company", null != query ? query.getPhone() : "");
        return map;
    }
}