puzhibing
2023-06-13 7860e5cb6db60aeb82c640651998f8294635df5b
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
163
164
165
166
167
168
169
170
171
172
package com.dsh.course.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dsh.course.entity.Phone;
import com.dsh.course.feignClient.activity.CompanyCityClient;
import com.dsh.course.feignClient.activity.CompanyClient;
import com.dsh.course.feignClient.activity.model.CompanyCityQueryCompanyReq;
import com.dsh.course.feignClient.activity.model.CompanyInfoRes;
import com.dsh.course.feignClient.driver.DriverClient;
import com.dsh.course.feignClient.driver.model.DriverInfoRes;
import com.dsh.course.mapper.PhoneMapper;
import com.dsh.course.model.dto.GetPhoneInfoRequest;
import com.dsh.course.service.IPhoneService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
 
 
@Service
public class PhoneServiceImpl extends ServiceImpl<PhoneMapper, Phone> implements IPhoneService {
 
    @Resource
    private PhoneMapper phoneMapper;
 
    @Autowired
    private CompanyCityClient companyCityClient;
 
    @Autowired
    private DriverClient driverClient;
 
    @Autowired
    private CompanyClient companyClient;
 
 
 
    /**
     * 获取所有系统电话
     * @return
     * @throws Exception
     */
    @Override
    public List<Phone> queryPhones(String code) throws Exception {
        String province = code.substring(0, 2) + "0000";
        String city = code.substring(0, 4) + "00";
 
        List<Phone> list = phoneMapper.queryPhones(province, city, code);
        if(list.size() == 0){
            list = phoneMapper.queryPhones(province, city, null);
        }
        if(list.size() == 0){
            list = phoneMapper.queryPhones(province, null, null);
        }
        return list;
    }
 
 
    /**
     * 获取客服电话(个人中心)
     * @param code
     * @return
     * @throws Exception
     */
    @Override
    public Map<String, Object> queryCustomerPhone(String code) throws Exception {
        String province = code.substring(0, 2) + "0000";
        String city = code.substring(0, 4) + "00";
 
        Map<String, Object> map = new HashMap<>();
        //平台电话
        Phone query = phoneMapper.query(2, 1, null, null, null);
        map.put("platform", null != query ? query.getPhone() : "");
 
        //公司
        query = phoneMapper.query(2, 2, province, city, code);
        if(query == null){
            query = phoneMapper.query(2, 2, province, city, null);
        }
        if(query == null){
            query = phoneMapper.query(2, 2, province, null, null);
        }
        map.put("company", null != query ? query.getPhone() : "");
        return map;
    }
 
 
 
    /**
     * 根据定位的城市行政编号获取分公司的客服电话
     * @param code
     * @return
     * @throws Exception
     */
    @Override
    public Map<String, Object> queryPhone(String code) throws Exception {
        CompanyInfoRes query = companyCityClient.query(new CompanyCityQueryCompanyReq("", ""));
        Map<String, Object> map = new HashMap<>();
        if(null == query){
            map.put("phone", "");
        }else{
            Phone phone = phoneMapper.queryInfo(query.getId(), 2);
            map.put("phone", null != phone ? phone.getPhone() : "");
        }
        return map;
    }
 
    @Override
    public Map<String, Object> queryPhone(Integer uid) throws Exception {
        DriverInfoRes driver = driverClient.getDriver(uid);
        CompanyInfoRes company = companyClient.queryById(driver.getFranchiseeId() != null && driver.getFranchiseeId() != 0 ? driver.getFranchiseeId() : (
                driver.getCompanyId() != null && driver.getCompanyId() != 0 ? driver.getCompanyId() : 1));
        Map<String, Object> map = new HashMap<>();
        if(company.getType() == 3){//加盟商
            Phone phone = phoneMapper.queryInfo(company.getId(), 2);
            map.put("franchisee", null != phone ? phone.getPhone() : "");
            company = companyClient.queryById(company.getSuperiorId());
            if(null != company){
                phone = phoneMapper.queryInfo(company.getId(), 2);
                map.put("branch", null != phone ? phone.getPhone() : "");
            }else{
                map.put("branch", "");
            }
            company = companyClient.queryById(company.getSuperiorId());
            if(null != company){
                phone = phoneMapper.queryInfo(company.getId(), 2);
                map.put("platform", null != phone ? phone.getPhone() : "");
            }else{
                map.put("platform", "");
            }
            return map;
        }
        if(company.getType() == 2){//分公司
            map.put("franchisee", "");
            Phone phone = phoneMapper.queryInfo(company.getId(), 2);
            map.put("branch", null != phone ? phone.getPhone() : "");
            company = companyClient.queryById(company.getSuperiorId());
            if(null != company){
                phone = phoneMapper.queryInfo(company.getId(), 2);
                map.put("platform",null != phone ? phone.getPhone() : "");
            }else{
                map.put("platform", "");
            }
            return map;
        }
        if(company.getType() == 1){//平台
            map.put("franchisee", "");
            map.put("branch", "");
            Phone phone = phoneMapper.queryInfo(company.getId(), 2);
            map.put("platform", null != phone ? phone.getPhone() : "");
            return map;
        }
        return map;
    }
 
    @Override
    public String selectPhoneByCompany(GetPhoneInfoRequest request) {
        LambdaQueryWrapper<Phone> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.select(Phone::getPhone);
        queryWrapper.eq(Phone::getType,request.getType());
        queryWrapper.eq(Phone::getCompanyId,request.getCompanyId());
        Phone phone = this.baseMapper.selectOne(queryWrapper);
        if (Objects.nonNull(phone)) {
            return phone.getPhone();
        }
        return null;
    }
}