CommonService.java
8.88 KB
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
package cn.fw.valhalla.service.bus;
import cn.fw.common.util.ValidationUtils;
import cn.fw.valhalla.common.constant.RoleCode;
import cn.fw.valhalla.common.utils.DateUtil;
import cn.fw.valhalla.domain.db.customer.AccidentPool;
import cn.fw.valhalla.domain.db.customer.Customer;
import cn.fw.valhalla.domain.db.customer.CustomerBaseInfo;
import cn.fw.valhalla.domain.db.pool.CustomerCluePool;
import cn.fw.valhalla.domain.db.pool.StammkundePool;
import cn.fw.valhalla.domain.enums.ClueStatusEnum;
import cn.fw.valhalla.domain.enums.FollowTypeEnum;
import cn.fw.valhalla.domain.enums.StammkundeStatusEnum;
import cn.fw.valhalla.domain.vo.PostUserVO;
import cn.fw.valhalla.rpc.ehr.EhrRpcService;
import cn.fw.valhalla.rpc.ehr.dto.StaffInfoDTO;
import cn.fw.valhalla.rpc.erp.UserService;
import cn.fw.valhalla.rpc.erp.dto.PostUserDTO;
import cn.fw.valhalla.rpc.pstn.PstnService;
import cn.fw.valhalla.service.bus.cust.CustomerChangeBizService;
import cn.fw.valhalla.service.data.*;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import static cn.fw.common.businessvalidator.Validator.BV;
/**
* @author : kurisu
* @className : CommonService
* @description : 公共服务
* @date: 2020-10-22 11:07
*/
@Service
@Slf4j
@RequiredArgsConstructor
public class CommonService {
private final UserService userService;
private final CustomerService customerService;
private final CustomerBaseInfoService customerBaseInfoService;
private final StammkundePoolService stammkundePoolService;
private final PstnService pstnService;
private final EhrRpcService ehrRpcService;
private final AccidentPoolService accidentPoolService;
private final CustomerChangeBizService customerChangeBizService;
private final CustomerCluePoolService customerCluePoolService;
public List<PostUserVO> getUsers(final Long shopId) {
List<PostUserVO> list = new ArrayList<>();
List<PostUserDTO> userByRole = userService.getUserByRole(shopId, RoleCode.FWGW);
if (CollectionUtils.isEmpty(userByRole)) {
return list;
}
for (PostUserDTO userDTO : userByRole) {
PostUserVO vo = new PostUserVO(userDTO.getUserId(), userDTO.getUserName(), 0);
int count = stammkundePoolService.count(Wrappers.<StammkundePool>lambdaQuery()
.eq(StammkundePool::getAdviserId, userDTO.getUserId())
.eq(StammkundePool::getShopId, shopId)
.eq(StammkundePool::getPoolStatus, StammkundeStatusEnum.KUNDE)
.eq(StammkundePool::getAktiv, Boolean.TRUE)
.isNull(StammkundePool::getRejectTime)
);
vo.setCurQuantity(count);
list.add(vo);
}
return list;
}
public void rollBack(String vin, Long groupId) {
rollBack(vin);
customerChangeBizService.rollBack(vin, groupId);
}
public void rollBack(String vin) {
//todo 去订单系统校验vin是否是退换车
}
/**
* 通过智能通话系统获取所拨打的电话号码
*
* @param userId
* @param cusId
* @param accidentCar
* @return
*/
public String call(Long userId, Long cusId, Boolean accidentCar) {
StaffInfoDTO staffInfo = ehrRpcService.queryStaffInfo(userId);
BV.notNull(staffInfo, () -> "用户身份验证异常,请重试");
String becallNo;
if (Boolean.TRUE.equals(accidentCar)) {
AccidentPool accidentPool = accidentPoolService.getById(cusId);
BV.notNull(accidentPool, () -> "用户不存在");
becallNo = accidentPool.getReportMobile();
if (!ValidationUtils.checkMobile(becallNo)) {
return becallNo;
}
} else {
Customer customer = customerService.queryByIdWithInvalid(cusId);
BV.notNull(customer, () -> "用户不存在");
BV.isTrue(customer.getYn(), () -> "此档案已经作废,请主动放弃本次跟进");
CustomerBaseInfo baseInfo = customerBaseInfoService.getById(customer.getBaseId());
BV.notNull(baseInfo, () -> "用户不存在");
becallNo = baseInfo.getMobile();
}
BV.isNotBlank(becallNo, () -> "客户电话号码不正确,无法拨打");
assert staffInfo != null;
BV.isNotBlank(staffInfo.getMobile(), () -> "用户电话号码不正确,无法拨打");
String virtualNumber = pstnService.virtualNumber(staffInfo.getMobile(), becallNo, staffInfo.getGroupId());
BV.isNotBlank(virtualNumber, () -> "号码不正确,无法拨号");
return virtualNumber;
}
@Transactional(rollbackFor = Exception.class)
public int createClue() {
List<CustomerCluePool> list = customerCluePoolService.list(Wrappers.<CustomerCluePool>lambdaQuery()
.eq(CustomerCluePool::getClueType, FollowTypeEnum.IR)
.in(CustomerCluePool::getClueStatus, ClueStatusEnum.FAILURE, ClueStatusEnum.COMPLETE)
.lt(CustomerCluePool::getUpdateTime, DateUtil.localDate2Date(LocalDate.now()))
.ne(CustomerCluePool::getGroupId, 1L)
.last(" limit 2000")
);
if (CollectionUtils.isEmpty(list)) {
return 0;
}
Long[] shopArr = new Long[]{65L, 66L, 67L};
String[] shopNameArr = new String[]{"宁夏瑞静售后店", "宁夏翔之星售后店", "贺兰捷联售后店"};
for (int i = 0; i < list.size(); i++) {
CustomerCluePool pool = list.get(i);
Long customerId = pool.getRefererId();
int count = customerCluePoolService.count(Wrappers.<CustomerCluePool>lambdaQuery()
.eq(CustomerCluePool::getClueType, FollowTypeEnum.IR)
.eq(CustomerCluePool::getRefererId, customerId)
.in(CustomerCluePool::getClueStatus, ClueStatusEnum.WAITING, ClueStatusEnum.ONGOING));
if (count > 0) {
continue;
}
Customer customer = customerService.queryById(customerId);
if (Objects.isNull(customer)) {
continue;
}
Long shopId = pool.getOriginalShopId();
String shopName = pool.getOriginalShopName();
if (Long.valueOf(146L).equals(shopId)) {
shopId = shopArr[i % 3];
shopName = shopNameArr[i % 3];
}
CustomerCluePool customerCluePool = new CustomerCluePool();
List<PostUserDTO> dtoList = userService.getUserByRole(shopId, RoleCode.XBGJ);
BV.isNotEmpty(dtoList, "门店[" + shopId + "]没有续保跟进人员");
Collections.shuffle(dtoList);
PostUserDTO userDTO = dtoList.get(0);
BeanUtils.copyProperties(pool, customerCluePool);
customerCluePool.setId(null);
customerCluePool.setOriginalUserId(userDTO.getUserId());
customerCluePool.setOriginalUserName(userDTO.getUserName());
customerCluePool.setOriginalShopId(shopId);
customerCluePool.setOriginalShopName(shopName);
customerCluePool.setClueStatus(ClueStatusEnum.WAITING);
customerCluePool.setRedistribution(Boolean.FALSE);
customerCluePool.setClueType(FollowTypeEnum.IR);
customerCluePool.setFinishShopId(null);
customerCluePool.setFinishShopName(null);
customerCluePool.setFinishUserId(null);
customerCluePool.setFinishUserName(null);
customerCluePool.setCreateTime(null);
customerCluePool.setUpdateTime(null);
LocalDate addTime = DateUtil.date2LocalDate(pool.getAddTime());
while (!addTime.minusDays(40L).isAfter(LocalDate.now())) {
addTime = addTime.plusYears(1L);
}
customerCluePool.setStartTime(DateUtil.localDate2Date(addTime.minusDays(40L)));
customerCluePool.setAddTime(DateUtil.localDate2Date(addTime));
customerCluePool.setDeadline(DateUtil.localDate2Date(addTime));
customerCluePool.setCloseTime(null);
customerCluePoolService.save(customerCluePool);
}
customerCluePoolService.updateBatchById(list);
return list.size();
}
private String getRoleCode(FollowTypeEnum followTypeEnum) {
switch (followTypeEnum) {
case AC:
return RoleCode.SGCGJ;
case IR:
return RoleCode.XBGJ;
case FM:
case RM:
default:
return RoleCode.FWGW;
}
}
}