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;
|
}
|
}
|