PoolBizService.java
13.8 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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
package cn.fw.valhalla.service.bus.follow;
import cn.fw.common.page.AppPage;
import cn.fw.common.web.auth.LoginAuthBean;
import cn.fw.valhalla.common.utils.DateUtil;
import cn.fw.valhalla.common.utils.StringUtils;
import cn.fw.valhalla.domain.db.customer.AffiliationRecord;
import cn.fw.valhalla.domain.dto.*;
import cn.fw.valhalla.domain.enums.*;
import cn.fw.valhalla.domain.query.*;
import cn.fw.valhalla.domain.vo.AppPageVO;
import cn.fw.valhalla.domain.vo.pool.*;
import cn.fw.valhalla.rpc.ehr.EhrRpcService;
import cn.fw.valhalla.rpc.erp.dto.UserInfoDTO;
import cn.fw.valhalla.rpc.oop.OopService;
import cn.fw.valhalla.rpc.oop.dto.ShopDTO;
import cn.fw.valhalla.rpc.order.OrderRpcService;
import cn.fw.valhalla.rpc.order.dto.NewCarOrderInfo;
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 java.time.LocalDate;
import java.util.*;
import java.util.stream.Collectors;
import static cn.fw.common.businessvalidator.Validator.BV;
/**
* @author : kurisu
* @className : FollowPoolBizService
* @description : 跟进池服务
* @date: 2020-09-23 15:30
*/
@Slf4j
@Service
@RequiredArgsConstructor
public class PoolBizService {
private final PublicPoolService publicPoolService;
private final StammkundePoolService stammkundePoolService;
private final PublicCluePoolService publicCluePoolService;
private final OopService oopService;
private final EhrRpcService ehrRpcService;
private final AffiliationRecordService affiliationRecordService;
private final OrderRpcService orderRpcService;
private final ClueTaskService clueTaskService;
private final PubCluePoolService pubCluePoolService;
private final FollowClueService followClueService;
/**
* 跟进池
*
* @param queryVO
* @return
*/
public AppPage<FollowPoolListVO> followList(LoginAuthBean user, FollowPoolQueryVO queryVO) {
prepareParams(user, queryVO);
AppPageVO<FollowPoolListVO> page = AppPageVO.init(queryVO);
List<FollowPoolDTO> list;
if (FollowTypeEnum.PL.getValue().equals(queryVO.getType())) {
final long total = pubCluePoolService.followListCount(queryVO);
if (total <= 0) {
return page;
}
page.setTotal(total);
list = pubCluePoolService.followList(queryVO);
} else {
final long total = clueTaskService.followListCount(queryVO);
if (total <= 0) {
return page;
}
page.setTotal(total);
list = clueTaskService.followList(queryVO);
}
List<FollowPoolListVO> followList = new ArrayList<>();
for (FollowPoolDTO followPoolDTO : list) {
FollowPoolListVO vo = trans2FollowPool(followPoolDTO);
followList.add(vo);
}
page.setData(followList);
return page;
}
/**
* 公共池
*
* @param queryVO
* @return
*/
public AppPage<PublicPoolVO> publicList(LoginAuthBean currentUser, PublicPoolQueryVO queryVO) {
if (!Boolean.TRUE.equals(queryVO.getFromReport())) {
List<AffiliationRecord> affiliationRecordList = Optional.ofNullable(affiliationRecordService.list(Wrappers.<AffiliationRecord>lambdaQuery()
.eq(AffiliationRecord::getType, CustomerChangeTypeEnum.DEFEAT)
.eq(AffiliationRecord::getOriginUserId, currentUser.getUserId())
.ge(AffiliationRecord::getDefeatTime, DateUtil.getNowExpiredMonth(-6))
)).orElse(new ArrayList<>());
List<Long> custIds = affiliationRecordList.stream().map(AffiliationRecord::getCustomerId).distinct().collect(Collectors.toList());
if (custIds.size() > 0) {
queryVO.setIgnoreCustIds(custIds);
}
}
AppPageVO<PublicPoolVO> page = AppPageVO.init(queryVO);
Long count = publicPoolService.publicListCount(queryVO);
if (count <= 0) {
return page;
}
List<PublicPoolVO> appList = new ArrayList<>();
List<PublicPoolDTO> list = publicPoolService.publicList(queryVO);
for (PublicPoolDTO dto : list) {
PublicPoolVO vo = new PublicPoolVO();
BeanUtils.copyProperties(dto, vo);
PublicPoolTypeEnum typeEnum = PublicPoolTypeEnum.ofValue(dto.getType());
if (Objects.nonNull(typeEnum)) {
vo.setTypeDesc(typeEnum.getName());
}
if (StringUtils.isEmpty(dto.getTags())) {
vo.setMaintainCard(Boolean.FALSE);
vo.setWarrantyCard(Boolean.FALSE);
} else {
vo.setMaintainCard(dto.getTags().contains(CusTagEnum.MAINTAIN_CARD.getValue()));
vo.setWarrantyCard(dto.getTags().contains(CusTagEnum.QUA_ASS_CARD.getValue()));
}
appList.add(vo);
}
page.setData(appList);
return page;
}
/**
* 保有客池
*
* @param user
* @param queryVO
* @return
*/
public AppPage<StammkundePoolVO> stammkundeList(LoginAuthBean user, StammkundePoolQueryVO queryVO) {
prepareParams(user, queryVO);
AppPageVO<StammkundePoolVO> page = AppPageVO.init(queryVO);
long total = stammkundePoolService.stammkundeListCount(queryVO);
if (total <= 0) {
return page;
}
page.setTotal(total);
List<StammkundePoolDTO> list = stammkundePoolService.stammkundeList(queryVO);
List<StammkundePoolVO> appList = new ArrayList<>();
for (StammkundePoolDTO dto : list) {
StammkundePoolVO vo = trans2StaPool(dto);
appList.add(vo);
}
page.setData(appList);
return page;
}
/**
* 客户线索池
*
* @param queryVO
* @return
*/
public AppPage<CustomerCluePoolVO> clueList(CustomerCluePoolQueryVO queryVO) {
prepareParams(null, queryVO);
BV.isNotEmpty(queryVO.getScope(), () -> "人员权限范围不正确,请确认是否有管理权限");
if (ClueStatusEnum.ONGOING.getValue().equals(queryVO.getStatus())) {
queryVO.setCloseTime(null);
}
AppPageVO<CustomerCluePoolVO> page = AppPageVO.init(queryVO);
long total = followClueService.clueListCount(queryVO);
if (total <= 0) {
return page;
}
page.setTotal(total);
final HashSet<Long> scope = new HashSet<>(queryVO.getScope());
List<FollowClueDTO> list = followClueService.clueList(queryVO);
List<CustomerCluePoolVO> appList = new ArrayList<>();
for (FollowClueDTO dto : list) {
CustomerCluePoolVO vo = trans2CluePool(dto, scope);
appList.add(vo);
}
page.setData(appList);
return page;
}
/**
* 线索池概况
*
* @param queryVO
* @return
*/
public CustomerClueSummaryVO summary(CustomerCluePoolQueryVO queryVO) {
prepareParams(null, queryVO);
BV.isNotEmpty(queryVO.getScope(), () -> "人员权限范围不正确,请确认是否有管理权限");
CustomerClueSummaryVO vo = new CustomerClueSummaryVO();
vo.setCompleteNum(followClueService.completeNum(queryVO));
vo.setDefeatNum(followClueService.defeatNum(queryVO));
vo.setOnGoingNum(followClueService.onGoingNum(queryVO));
vo.setClosedNum(vo.getCompleteNum() + vo.getDefeatNum());
return vo;
}
/**
* 公共客户线索池
*
* @param queryVO
* @return
*/
public AppPage<PublicCluePoolVO> publicClueList(PublicCluePoolQueryVO queryVO, LoginAuthBean user) {
prepareParams(user, queryVO);
AppPageVO<PublicCluePoolVO> page = AppPageVO.init(queryVO);
long total = publicCluePoolService.publicCluePoolListCount(queryVO);
if (total <= 0) {
return page;
}
page.setTotal(total);
List<PublicCluePoolDTO> list = publicCluePoolService.publicCluePoolList(queryVO);
List<PublicCluePoolVO> appList = new ArrayList<>();
for (PublicCluePoolDTO dto : list) {
PublicCluePoolVO vo = new PublicCluePoolVO();
BeanUtils.copyProperties(dto, vo);
if (StringUtils.isEmpty(dto.getTags())) {
vo.setMaintainCard(Boolean.FALSE);
vo.setWarrantyCard(Boolean.FALSE);
} else {
vo.setMaintainCard(dto.getTags().contains(CusTagEnum.MAINTAIN_CARD.getValue()));
vo.setWarrantyCard(dto.getTags().contains(CusTagEnum.QUA_ASS_CARD.getValue()));
}
if (Objects.nonNull(dto.getBuyDate())) {
LocalDate buyDate = DateUtil.date2LocalDate(dto.getBuyDate());
long days = LocalDate.now().toEpochDay() - buyDate.toEpochDay();
double years = Math.ceil(days / 365.0);
vo.setAgeLimit(Math.round(years));
}
appList.add(vo);
}
page.setData(appList);
return page;
}
/**
* 跟进池数据转换
*
* @param poolDTO
* @return
*/
private FollowPoolListVO trans2FollowPool(FollowPoolDTO poolDTO) {
FollowPoolListVO vo = new FollowPoolListVO();
BeanUtils.copyProperties(poolDTO, vo);
vo.setFollower(poolDTO.getFollowUserName());
if (StringUtils.isEmpty(poolDTO.getFollowUserName()) && Objects.nonNull(poolDTO.getUserId())) {
UserInfoDTO user = ehrRpcService.user(poolDTO.getUserId());
if (Objects.nonNull(user)) {
vo.setFollower(user.getUserName());
}
}
if (Objects.nonNull(poolDTO.getShopId())) {
ShopDTO shop = oopService.shop(poolDTO.getShopId());
if (Objects.nonNull(shop)) {
vo.setShopName(shop.getShortName());
}
}
if (Objects.nonNull(poolDTO.getFinishShop())) {
ShopDTO fshop = oopService.shop(poolDTO.getFinishShop());
if (Objects.nonNull(fshop)) {
vo.setFinishShopName(fshop.getShortName());
}
}
if (Objects.nonNull(poolDTO.getLoanExpires())) {
vo.setLoanCustomer(DateUtil.date2LocalDate(poolDTO.getLoanExpires()).isAfter(LocalDate.now()));
vo.setLoanDate(poolDTO.getLoanExpires());
}
TaskDefeatTypeEnum defeatTypeEnum = TaskDefeatTypeEnum.ofValue(poolDTO.getInitiative());
if (Objects.nonNull(defeatTypeEnum)) {
vo.setDefeatType(defeatTypeEnum.getName());
}
return vo;
}
private StammkundePoolVO trans2StaPool(StammkundePoolDTO dto) {
StammkundePoolVO vo = new StammkundePoolVO();
BeanUtils.copyProperties(dto, vo);
ShopDTO shop = oopService.shop(dto.getShopId());
if (Objects.nonNull(shop)) {
vo.setShopName(shop.getShortName());
}
if (Objects.nonNull(dto.getLoanExpires())) {
vo.setLoanCustomer(DateUtil.date2LocalDate(dto.getLoanExpires()).isAfter(LocalDate.now()));
}
String tags = dto.getTags();
if (StringUtils.isEmpty(tags)) {
vo.setMaintainCard(Boolean.FALSE);
vo.setWarrantyCard(Boolean.FALSE);
} else {
vo.setMaintainCard(tags.contains(CusTagEnum.MAINTAIN_CARD.getValue()));
vo.setWarrantyCard(tags.contains(CusTagEnum.QUA_ASS_CARD.getValue()));
}
if (Objects.nonNull(dto.getReason())) {
DefeatReasonEnum reasonEnum = DefeatReasonEnum.ofValue(dto.getReason());
vo.setReason(Objects.nonNull(reasonEnum) ? reasonEnum.getName() : null);
}
if (Objects.nonNull(dto.getBuyDate())) {
LocalDate buyDate = DateUtil.date2LocalDate(dto.getBuyDate());
long days = LocalDate.now().toEpochDay() - buyDate.toEpochDay();
double years = Math.ceil(days / 365.0);
vo.setAgeLimit(Math.round(years));
}
return vo;
}
private CustomerCluePoolVO trans2CluePool(FollowClueDTO poolDTO, Set<Long> scope) {
CustomerCluePoolVO vo = new CustomerCluePoolVO();
BeanUtils.copyProperties(poolDTO, vo);
vo.setStatus(poolDTO.getClueStatus());
if (Objects.nonNull(poolDTO.getLoanExpires())) {
vo.setLoanCustomer(DateUtil.date2LocalDate(poolDTO.getLoanExpires()).isAfter(LocalDate.now()));
}
if (ClueStatusEnum.COMPLETE.getValue().equals(poolDTO.getClueStatus())) {
vo.setStatus(ClueStatusEnum.COMPLETE.getValue());
}
if (ClueStatusEnum.FAILURE.getValue().equals(poolDTO.getClueStatus())) {
vo.setStatus(ClueStatusEnum.FAILURE.getValue());
}
//首保
if (FollowTypeEnum.FM.getValue().equals(poolDTO.getType())) {
NewCarOrderInfo orderInfo = orderRpcService.getOrderInfo(poolDTO.getFrameNo());
if (Objects.nonNull(orderInfo)) {
ShopDTO shop = oopService.shop(orderInfo.getShopId());
vo.setSaleShop(Objects.nonNull(shop) ? shop.getShortName() : "-");
}
}
return vo;
}
private void prepareParams(LoginAuthBean user, PoolQuery queryVO) {
if (Objects.nonNull(user)) {
queryVO.setUserId(user.getUserId());
queryVO.setGroupId(user.getGroupId());
}
if (Objects.nonNull(queryVO.getOrder()) && StringUtils.isValid(queryVO.getOrderAtt())) {
StringBuilder sb = new StringBuilder(" order by ");
sb.append(StringUtils.toColumnName(queryVO.getOrderAtt()).toLowerCase());
if (queryVO.getOrder() == 1) {
sb.append(" asc ");
} else {
sb.append(" desc ");
}
queryVO.setOrderString(sb.toString());
}
}
}