CustomerBizService.java
26 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
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
package cn.fw.valhalla.service.bus.cust;
import cn.fw.common.exception.BusinessException;
import cn.fw.common.page.AppPage;
import cn.fw.common.web.auth.LoginAuthBean;
import cn.fw.valhalla.common.constant.RoleCode;
import cn.fw.valhalla.common.utils.DateUtil;
import cn.fw.valhalla.domain.db.CompanyWechatJoin;
import cn.fw.valhalla.domain.db.WechatSubscribe;
import cn.fw.valhalla.domain.db.customer.*;
import cn.fw.valhalla.domain.db.follow.FollowTask;
import cn.fw.valhalla.domain.db.pool.PublicPool;
import cn.fw.valhalla.domain.db.pool.StammkundePool;
import cn.fw.valhalla.domain.dto.CustomerDetailDto;
import cn.fw.valhalla.domain.enums.*;
import cn.fw.valhalla.domain.query.CustomerQueryVO;
import cn.fw.valhalla.domain.vo.customer.*;
import cn.fw.valhalla.rpc.angel.dto.InsuranceDTO;
import cn.fw.valhalla.rpc.cas.CasRpcService;
import cn.fw.valhalla.rpc.cas.dto.SubstituteDTO;
import cn.fw.valhalla.rpc.erp.dto.UserInfoDTO;
import cn.fw.valhalla.rpc.erp.dto.UserRoleDataRangeDTO;
import cn.fw.valhalla.rpc.member.MemberRpcService;
import cn.fw.valhalla.rpc.member.dto.MemberUserDTO;
import cn.fw.valhalla.rpc.oop.dto.ShopDTO;
import cn.fw.valhalla.rpc.oop.dto.SpecDTO;
import cn.fw.valhalla.sdk.param.CustomerParams;
import cn.fw.valhalla.sdk.result.CustomerInfoDto;
import cn.fw.valhalla.sdk.result.ReceptionResultDto;
import cn.fw.valhalla.service.data.*;
import cn.fw.valhalla.service.event.PublicPoolEvent;
import cn.fw.valhalla.service.event.StopTaskEvent;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;
import static cn.fw.common.businessvalidator.Validator.BV;
/**
* @author : kurisu
* @className : CustomerBizService
* @description : 档案
* @date: 2020-08-12 13:57
*/
@Service
@Slf4j
@RequiredArgsConstructor
public class CustomerBizService extends AbstractCustomerService {
/**
* 关注公众号服务
*/
private final WechatSubscribeService wechatSubscribeService;
/**
* 加入企业微信服务
*/
private final CompanyWechatJoinService companyWechatJoinService;
private final MemberRpcService memberRpcService;
private final AffiliationRecordService affiliationRecordService;
private final PublicPoolService publicPoolService;
private final ApplicationEventPublisher eventPublisher;
private final CasRpcService casRpcService;
private final CustomerReachLogService customerReachLogService;
/**
* app分页查询档案
*
* @param userInfo
* @param queryVO
* @return
*/
public AppPage<CustomerListVO> getList(LoginAuthBean userInfo, CustomerQueryVO queryVO) {
queryVO.setGroupId(userInfo.getGroupId());
queryVO.setCurrent(queryVO.getCurrent() > 0 ? queryVO.getCurrent() : 1);
Integer startIndex = (queryVO.getCurrent() - 1) * queryVO.getPageSize();
List<CustomerListVO> appPageList = customerService.getAppPageList(startIndex, queryVO.getPageSize(), queryVO);
AppPage<CustomerListVO> page = AppPage.empty(queryVO);
page.setData(appPageList);
return page;
}
/**
* 根据档案id查询详情
*
* @param cusId
* @return
*/
public CustomerDetailVO getDetailById(final Long cusId) {
CustomerDetailDto detailDto = queryById(cusId);
BV.notNull(detailDto, () -> "查无此档案");
BV.isTrue(detailDto.getYn(), () -> "此档案已经作废,无法再继续查看");
CustomerDetailVO vo = new CustomerDetailVO();
BeanUtils.copyProperties(detailDto, vo);
vo.setRealMobile(detailDto.getMobile());
vo.setOrgCode(detailDto.getIdCode());
return vo;
}
/**
* 根据ID查询档案基本信息
*
* @param id
* @return
*/
public VehicleRecordVO getCarInfoById(Long id) {
final VehicleRecordVO vo = new VehicleRecordVO();
Customer customer = customerService.queryById(id);
BV.notNull(customer, () -> "查无此档案");
CustomerDetailDto detailDto = renderDto(customer);
BeanUtils.copyProperties(detailDto, vo);
Optional<InsuranceDTO> dtoOptional = queryInsuInfo(customer.getId());
dtoOptional.ifPresent(t -> {
vo.setInsurCompanyId(t.getInsurerId());
vo.setInsurCompanyName(t.getInsurerName());
vo.setInsurExpireDate(t.getExpiryDate());
});
return vo;
}
/**
* 根据id查询车辆所有人信息
*
* @param id
* @return
*/
public OwnerVO getOwnerInfo(Long id) {
OwnerVO vo = new OwnerVO();
Customer customer = customerService.queryById(id);
BV.notNull(customer, "查无此档案");
CustomerDetailDto detailDto = renderDto(customer);
BeanUtils.copyProperties(detailDto, vo);
vo.setIdNum(detailDto.getIdCode());
vo.setId(id);
// 是否关注微信公众号
vo.setSubscribed(wechatSubscribeService.count(Wrappers.<WechatSubscribe>lambdaQuery()
.eq(WechatSubscribe::getSubscribed, Boolean.TRUE)
.eq(WechatSubscribe::getMemberId, detailDto.getMemberId())) > 0);
vo.setJoined(companyWechatJoinService.count(Wrappers.<CompanyWechatJoin>lambdaQuery()
.eq(CompanyWechatJoin::getJoined, Boolean.TRUE)
.eq(CompanyWechatJoin::getMemberId, detailDto.getMemberId())) > 0);
return vo;
}
/**
* 根据memberId查询该客户的更多车辆
*
* @param id
* @param groupId
* @return
*/
public List<MoreVehicleVO> getMoreArchive(Long id, Long groupId) {
Customer customer = customerService.queryById(id);
if (Objects.isNull(customer)) {
return new ArrayList<>();
}
List<MoreVehicleVO> list = new ArrayList<>();
List<Customer> customerList = customerService.getBaseMapper().selectList(Wrappers.<Customer>lambdaQuery()
.eq(Customer::getBaseId, customer.getBaseId())
.ne(Customer::getId, customer.getId())
.eq(Customer::getGroupId, groupId)
.eq(Customer::getYn, Boolean.TRUE)
);
if (!CollectionUtils.isEmpty(customerList)) {
for (Customer cust : customerList) {
MoreVehicleVO vo = new MoreVehicleVO();
BeanUtils.copyProperties(cust, vo);
vo.setId(cust.getId());
list.add(vo);
}
}
return list;
}
/**
* 批量查询保有客档案
*
* @param customerIds 保有客档案id集合
* @return 保有客档案
*/
public List<CustomerInfoDto> queryBatch(final Long[] customerIds) {
final List<Customer> customers = customerService.list(Wrappers.<Customer>lambdaQuery()
.in(Customer::getId, Arrays.asList(customerIds)));
if (CollectionUtils.isEmpty(customers)) {
return Collections.emptyList();
}
return customers.stream().map(customer -> {
CustomerInfoDto customerInfoDto = new CustomerInfoDto();
BeanUtils.copyProperties(customer, customerInfoDto);
customerInfoDto.setCreateTime(customer.getCreateTime());
customerInfoDto.setConsultantId(customer.getAdviserId());
return customerInfoDto;
}).collect(Collectors.toList());
}
/**
* 查询会员对应保有客的商家id
*
* @param memberId 会员id
* @param groupId 集团id
* @return 商家id集合
*/
public List<Long> getCustomerDealerId(Long groupId, Long memberId) {
CustomerBaseInfo baseInfo = customerBaseInfoService.getOne(Wrappers.<CustomerBaseInfo>lambdaQuery()
.eq(CustomerBaseInfo::getGroupId, groupId)
.eq(CustomerBaseInfo::getMemberId, memberId)
.eq(CustomerBaseInfo::getYn, Boolean.TRUE)
.last("limit 1")
);
if (Objects.isNull(baseInfo)) {
return Collections.emptyList();
}
final List<Customer> customers = customerService.list(Wrappers.<Customer>lambdaQuery()
.eq(Customer::getGroupId, groupId)
.eq(Customer::getBaseId, baseInfo.getId())
.eq(Customer::getYn, Boolean.TRUE)
);
if (CollectionUtils.isEmpty(customers)) {
return Collections.emptyList();
}
return customers.stream().map(Customer::getShopId).distinct().collect(Collectors.toList());
}
/**
* 修改车型代码
*
* @param customerId
* @param specCode
* @return
*/
public boolean modifySpecCode(Long customerId, String specCode) {
Customer customer = customerService.queryById(customerId);
BV.notNull(customer, () -> "档案不存在");
customer.setSpecCode(specCode);
return customerService.updateById(customer);
}
/**
* 查询能否接车
*
* @param userId
* @param plateNo
* @return
*/
public ReceptionResultDto queryReceivable(Long userId, String plateNo) {
UserInfoDTO userInfo = userService.user(userId);
if (Objects.isNull(userInfo)) {
return new ReceptionResultDto(false, "非服务顾问无法接待");
}
List<UserRoleDataRangeDTO> dataRange = userService.getUserRoleDataRange(userId, RoleCode.FWGW);
if (CollectionUtils.isEmpty(dataRange)) {
return new ReceptionResultDto(false, "非服务顾问无法接待");
}
Customer customer = customerService.queryByPlateNo(plateNo, userInfo.getGroupId());
if (Objects.isNull(customer)) {
return new ReceptionResultDto(true, "");
}
ShopDTO shop = oopService.shop(dataRange.get(0).getRangeValue());
if (Objects.isNull(shop)) {
return new ReceptionResultDto(false, "服务顾问服务站信息不正确");
}
if (Objects.nonNull(customer.getAdviserId())) {
if (customer.getShopId().equals(shop.getId())) {
boolean canReception = userId.equals(customer.getAdviserId());
SubstituteDTO substitute = casRpcService.getSubstitute(customer.getShopId(), customer.getAdviserId());
if (Objects.nonNull(substitute)) {
canReception = canReception || userId.equals(substitute.getSubstituteId());
}
return new ReceptionResultDto(canReception, canReception ? "" : "无法接待其他人的客户");
}
}
boolean bool = affiliationRecordService.count(Wrappers.<AffiliationRecord>lambdaQuery()
.eq(AffiliationRecord::getType, CustomerChangeTypeEnum.DEFEAT)
.eq(AffiliationRecord::getOriginUserId, userId)
.eq(AffiliationRecord::getCustomerId, customer.getId())
.ge(AffiliationRecord::getDefeatTime, DateUtil.getNowExpiredMonth(-12))
) > 0;
if (bool) {
return new ReceptionResultDto(false, "无法接待由你战败的客户");
}
return new ReceptionResultDto(true, "");
}
/**
* 根据档案id查询详情
*
* @param cusId
* @return
*/
public CustomerDetailDto queryById(final Long cusId) {
Customer customer = customerService.queryById(cusId);
if (Objects.isNull(customer)) {
return null;
}
return renderDto(customer);
}
/**
* 根据手机号查询所有档案
*
* @param mobile
* @param groupId
* @return
*/
public List<CustomerDetailDto> queryByMobile(final String mobile, final Long groupId) {
CustomerBaseInfo baseInfo = customerBaseInfoService.queryByMobile(mobile, groupId);
if (Objects.isNull(baseInfo)) {
return new ArrayList<>();
}
List<Customer> customerList = customerService.queryByBaseId(baseInfo.getId());
if (CollectionUtils.isEmpty(customerList)) {
return new ArrayList<>();
}
List<CustomerDetailDto> list = new ArrayList<>();
for (Customer customer : customerList) {
list.add(renderDto(customer, baseInfo));
}
return list;
}
/**
* 放弃客户
*
* @param customerId
* @param reason
*/
@Transactional(rollbackFor = Exception.class)
public void abandon(final Long customerId, final String reason) {
CustomerDetailDto detailDto = queryById(customerId);
BV.notNull(detailDto, () -> "档案不存在");
if (publicPoolService.queryByPlate(detailDto.getPlateNo(), detailDto.getGroupId()).isPresent()) {
return;
}
PublicPool publicPool = createPublicPool(detailDto, PublicPoolTypeEnum.AD, reason);
boolean updated = customerService.update(Wrappers.<Customer>lambdaUpdate()
.set(Customer::getAdviserId, null)
.set(Customer::getShopId, null)
.eq(Customer::getId, customerId));
if (!updated) {
return;
}
AffiliationRecord entity = createEntity(detailDto);
entity.setReason(DefeatReasonEnum.GU.getName());
affiliationRecordService.save(entity);
publicPoolService.save(publicPool);
stammkundePoolService.reject(customerId, detailDto.getGroupId(), DefeatReasonEnum.GU);
PublicPoolEvent poolEvent = new PublicPoolEvent(customerId, detailDto.getGroupId(), false);
eventPublisher.publishEvent(poolEvent);
}
/**
* 放弃客户
*
* @param task
*/
@Transactional(rollbackFor = Exception.class)
public void abandon(final FollowTask task, boolean flow) {
CustomerDetailDto detailDto = queryById(task.getCustomerId());
if (Objects.isNull(detailDto)) {
return;
}
if (publicPoolService.queryByPlate(detailDto.getPlateNo(), detailDto.getGroupId()).isPresent()) {
return;
}
List<FollowTypeEnum> typeList = Arrays.asList(FollowTypeEnum.AC, FollowTypeEnum.IR);
HashSet<FollowTypeEnum> set = new HashSet<>(typeList);
if (set.contains(task.getType())) {
StopTaskEvent stopTaskEvent = new StopTaskEvent(task);
eventPublisher.publishEvent(stopTaskEvent);
return;
}
PublicPoolTypeEnum type = PublicPoolTypeEnum.FM;
if (FollowTypeEnum.RM.equals(task.getType())) {
type = PublicPoolTypeEnum.RM;
}
PublicPool publicPool = createPublicPool(detailDto, type, "系统判定");
boolean updated = customerService.update(Wrappers.<Customer>lambdaUpdate()
.set(Customer::getAdviserId, null)
.set(Customer::getShopId, null)
.eq(Customer::getId, task.getCustomerId()));
if (!updated) {
return;
}
DefeatReasonEnum reasonEnum = DefeatReasonEnum.OT;
if (FollowTypeEnum.FM.equals(task.getType())) {
reasonEnum = flow ? DefeatReasonEnum.GU : DefeatReasonEnum.FM;
}
if (FollowTypeEnum.RM.equals(task.getType())) {
reasonEnum = flow ? DefeatReasonEnum.GU : DefeatReasonEnum.RM;
}
AffiliationRecord entity = createEntity(detailDto);
entity.setReason(reasonEnum.getName());
affiliationRecordService.save(entity);
publicPoolService.save(publicPool);
stammkundePoolService.reject(task.getCustomerId(), task.getGroupId(), reasonEnum);
PublicPoolEvent poolEvent = new PublicPoolEvent(task.getCustomerId(), task.getGroupId(), false);
eventPublisher.publishEvent(poolEvent);
}
/**
* 继续跟进
*
* @param currentUser
* @param customerId
*/
@Transactional(rollbackFor = Exception.class)
public void continueFollow(LoginAuthBean currentUser, final Long customerId) {
List<UserRoleDataRangeDTO> dataRange = userService.getUserRoleDataRange(currentUser.getUserId(), RoleCode.FWGW);
BV.isFalse(CollectionUtils.isEmpty(dataRange), () -> "非服务顾问无法进行操作");
Customer customer = customerService.queryById(customerId);
if (Objects.isNull(customer)) {
publicPoolService.removeByCustomerId(customerId, currentUser.getGroupId());
throw new BusinessException("档案信息有误,请刷新后重试");
}
boolean bool = affiliationRecordService.count(Wrappers.<AffiliationRecord>lambdaQuery()
.eq(AffiliationRecord::getType, CustomerChangeTypeEnum.DEFEAT)
.eq(AffiliationRecord::getOriginUserId, currentUser.getUserId())
.eq(AffiliationRecord::getCustomerId, customerId)
) > 0;
BV.isFalse(bool, () -> "无法继续跟进由你战败的客户");
if (Objects.isNull(customer.getAdviserId()) && Objects.isNull(customer.getShopId())) {
customer.setAdviserId(currentUser.getUserId());
customer.setShopId(dataRange.get(0).getRangeValue());
customerService.updateById(customer);
StammkundePool stammkundePool = createSimpleInfo(customer);
stammkundePool.setAdviserId(currentUser.getUserId());
stammkundePool.setAdviserName(currentUser.getUserName());
stammkundePool.setSources(StammkundeSourcesEnum.PUBLIC_POOL);
stammkundePool.setPoolStatus(StammkundeStatusEnum.PUBLIC);
stammkundePoolService.save(stammkundePool);
}
publicPoolService.removeByCustomerId(customerId, currentUser.getGroupId());
}
/**
* 根据车牌号查询所有档案
*
* @param plateNo
* @param groupId
* @return
*/
public CustomerDetailDto queryByPlateNo(final String plateNo, final Long groupId) {
Customer customer = customerService.queryByPlateNo(plateNo, groupId);
if (Objects.isNull(customer)) {
return null;
}
return renderDto(customer);
}
/**
* 根据车架号号查询所有档案
*
* @param frameNo
* @param groupId
* @return
*/
public CustomerDetailDto queryByFrameNo(final String frameNo, final Long groupId) {
Customer customer = customerService.queryByFrameNo(frameNo, groupId);
if (Objects.isNull(customer)) {
return null;
}
return renderDto(customer);
}
/**
* 是否关联了档案
*
* @param customerParams
* @return
*/
@Transactional(rollbackFor = Exception.class)
public Boolean save4api(final CustomerParams customerParams) {
String plateNo = customerParams.getPlateNo();
Long groupId = customerParams.getGroupId();
Customer customer = customerService.queryByPlateNo(plateNo, groupId);
BV.isNull(customer, "该车牌号对应的档案已存在");
CustomerBaseInfo baseInfo = new CustomerBaseInfo();
BeanUtils.copyProperties(customerParams, baseInfo);
baseInfo.setContact(customerParams.getName());
baseInfo.setYn(Boolean.TRUE);
baseInfo.setCreateTime(new Date());
baseInfo.setUpdateTime(new Date());
customer = new Customer();
BeanUtils.copyProperties(customerParams, customer);
customer.setSpecCode((org.apache.commons.lang.StringUtils.isNotBlank(customerParams.getSpecCode()) && customerParams.getSpecCode().contains(".")) ?
customerParams.getSpecCode().substring(0, customerParams.getSpecCode().lastIndexOf(".")) : customerParams.getSpecCode());
customer.setCreateTime(new Date());
customer.setUpdateTime(new Date());
customer.setYn(Boolean.TRUE);
final SpecDTO spec = oopService.spec(customerParams.getSpecId());
customer.setCarImage(Optional.ofNullable(spec).orElse(new SpecDTO()).getThumbnail());
ShopDTO shop = oopService.shop(customerParams.getShopId());
BV.notNull(shop, () -> "shop信息有误,请检查");
customer.setShopId(shop.getCasShopId());
Long cid = create(customer, baseInfo);
CustomerParams.LoanInfo loanInfo = customerParams.getLoanInfo();
if (Objects.nonNull(loanInfo)) {
saveLoanInfo(customer.getGroupId(), customer.getFrameNo(), loanInfo.getPeriods(), loanInfo.getExpires());
}
if (Objects.nonNull(cid)) {
final CustomerInfoDto customerInfoDto = new CustomerInfoDto();
BeanUtils.copyProperties(customer, customerInfoDto);
customerInfoDto.setConsultantId(customer.getAdviserId());
customerInfoDto.setId(customer.getId());
this.customerChangeProducer.send(customerInfoDto);
}
return Objects.nonNull(cid);
}
/**
* 查询所有字段
*
* @param memberId
* @return
*/
public List<CarArchiveVO> defaultCustomer(final Long memberId) {
if (Objects.isNull(memberId)) {
return new ArrayList<>();
}
final MemberUserDTO user = memberRpcService.user(memberId);
if (Objects.isNull(user)) {
return new ArrayList<>();
}
List<CustomerBaseInfo> baseList = this.customerBaseInfoService.list(Wrappers.<CustomerBaseInfo>lambdaQuery()
.eq(CustomerBaseInfo::getMemberId, memberId)
.eq(CustomerBaseInfo::getYn, Boolean.TRUE)
);
List<Long> baseIds = Optional.ofNullable(baseList).map(l -> l.stream().map(CustomerBaseInfo::getId).collect(Collectors.toList())).orElse(null);
if (CollectionUtils.isEmpty(baseIds)) {
return new ArrayList<>();
}
final List<Customer> customers = this.customerService.list(Wrappers.<Customer>lambdaQuery()
.in(Customer::getBaseId, baseIds)
.eq(Customer::getYn, Boolean.TRUE)
.orderByDesc(Customer::getCreateTime));
if (CollectionUtils.isNotEmpty(customers)) {
return customers.stream()
.map(CarArchiveVO::with)
.filter(Objects::nonNull)
.peek(vo -> {
UserInfoDTO dto = userService.user(vo.getAdviserId());
if (Objects.nonNull(dto)) {
vo.setAdviserName(dto.getUserName());
}
vo.setDealerInfoVO(createDeal(vo.getShopId()));
vo.setOwner(true);
vo.setOwnerName(user.getRealName());
loanCustomer(vo);
}).collect(Collectors.toList());
}
return new ArrayList<>();
}
private AffiliationRecord createEntity(CustomerDetailDto customer) {
AffiliationRecord record = new AffiliationRecord();
record.setCustomerId(customer.getId());
record.setType(CustomerChangeTypeEnum.DEFEAT);
record.setDefeatTime(DateUtil.localDateTime2Date(LocalDateTime.now()));
record.setOriginUserId(customer.getAdviserId());
record.setOriginShopId(customer.getShopId());
record.setCreateTime(DateUtil.localDateTime2Date(LocalDateTime.now()));
return record;
}
private CarArchiveVO.DealerItem createDeal(Long shopId) {
//没有商家这个概念 这里主要是兼容之前的小程序代码
ShopDTO shop = oopService.shop(shopId);
if (Objects.isNull(shop)) {
return null;
}
CarArchiveVO.DealerItem vo = CarArchiveVO.createDealerItem();
vo.setId(shop.getId());
vo.setName(shop.getShortName());
vo.setLogo(shop.getShopLogo());
vo.setPhone(shop.getTel());
vo.setAddr(shop.getAddr());
vo.setLat(shop.getLat());
vo.setLng(shop.getLng());
vo.setDistance(0.0);
return vo;
}
private PublicPool createPublicPool(CustomerDetailDto dto, PublicPoolTypeEnum type, String reason) {
PublicPool pool = new PublicPool();
pool.setCustomerId(dto.getId());
pool.setCustomerName(dto.getName());
pool.setPlateNo(dto.getPlateNo());
pool.setAddress(dto.getAddress());
pool.setCompany(dto.getCompanyName());
pool.setType(type);
pool.setReason(reason);
pool.setShopId(dto.getShopId());
ShopDTO shop = oopService.shop(dto.getShopId());
if (Objects.nonNull(shop)) {
pool.setShopName(shop.getShortName());
}
int times = customerReachLogService.count(Wrappers.<CustomerReachLog>lambdaQuery()
.eq(CustomerReachLog::getFrameNo, dto.getFrameNo())
);
pool.setTimes(times);
pool.setGroupId(dto.getGroupId());
return pool;
}
private void saveLoanInfo(Long groupId, String vin, int periods, Date expires) {
try {
CustomerLoanInfo loanInfo = customerLoanInfoService.getOne(Wrappers.<CustomerLoanInfo>lambdaQuery()
.eq(CustomerLoanInfo::getFrameNo, vin)
.eq(CustomerLoanInfo::getGroupId, groupId)
.last(" limit 1")
);
if (Objects.nonNull(loanInfo)) {
return;
}
loanInfo = new CustomerLoanInfo();
loanInfo.setFrameNo(vin);
loanInfo.setPeriods(periods);
loanInfo.setExpires(expires);
loanInfo.setGroupId(groupId);
customerLoanInfoService.save(loanInfo);
} catch (Exception e) {
log.error("新增客户贷款信息失败:", e);
}
}
private void loanCustomer(CarArchiveVO vo) {
CustomerLoanInfo loanInfo = customerLoanInfoService.getOne(Wrappers.<CustomerLoanInfo>lambdaQuery()
.eq(CustomerLoanInfo::getGroupId, vo.getGroupId())
.eq(CustomerLoanInfo::getFrameNo, vo.getFrameNo())
.last(" limit 1 ")
);
if (Objects.nonNull(loanInfo)) {
vo.setLoanCustomer(LocalDate.now().isBefore(DateUtil.date2LocalDate(loanInfo.getExpires())));
vo.setExpires(loanInfo.getExpires());
vo.setPeriods(loanInfo.getPeriods());
}
}
}