Commit 91c29e23faa969304abbdbad07799f3f3d9f61ac

Authored by 张志伟
1 parent c232dfda

:fire: 新增接车时作废档案后结束跟进任务等数据的逻辑

fw-valhalla-server/src/main/java/cn/fw/valhalla/controller/api/CustomerApiServiceImpl.java
... ... @@ -73,7 +73,7 @@ public class CustomerApiServiceImpl implements CustomerApiService {
73 73 final String msg = "查询保有客档案[queryById]";
74 74 log.info("{}: param[{}]", msg, customerId);
75 75 try {
76   - CustomerDetailDto detailDto = customerBiz.queryById(customerId, Boolean.FALSE);
  76 + CustomerDetailDto detailDto = customerBiz.queryById(customerId);
77 77 if (Objects.isNull(detailDto)) {
78 78 log.info("{} 成功: 查无此档案", msg);
79 79 return success();
... ...
fw-valhalla-service/src/main/java/cn/fw/valhalla/service/bus/CustomEventListener.java
... ... @@ -79,7 +79,12 @@ public class CustomEventListener {
79 79 @EventListener(PublicPoolEvent.class)
80 80 public void stopTaskAndAddPublic(final PublicPoolEvent event) {
81 81 Long getCustomerId = event.getCustomerId();
82   - followBizService.stopTask(getCustomerId, event.getGroupId());
  82 + Boolean forbidden = event.getForbidden();
  83 + if (Boolean.TRUE.equals(forbidden)) {
  84 + followBizService.onForbidden(getCustomerId, event.getGroupId());
  85 + } else {
  86 + followBizService.stopTask(getCustomerId, event.getGroupId());
  87 + }
83 88 }
84 89  
85 90 /**
... ... @@ -95,6 +100,7 @@ public class CustomEventListener {
95 100  
96 101 /**
97 102 * 取消审批
  103 + *
98 104 * @param event
99 105 */
100 106 @EventListener(CancelApproveEvent.class)
... ... @@ -107,7 +113,7 @@ public class CustomEventListener {
107 113 .eq(ApproveRecord::getState, ApproveStateEnum.WAIT)
108 114 .last("limit 1")
109 115 );
110   - if (Objects.isNull(approveRecord)) {
  116 + if (Objects.isNull(approveRecord)) {
111 117 return;
112 118 }
113 119 //FIXME 优化项 处理审批取消失败的场景
... ... @@ -118,6 +124,7 @@ public class CustomEventListener {
118 124  
119 125 /**
120 126 * 档案专属顾问发生改变后
  127 + *
121 128 * @param event
122 129 */
123 130 @EventListener(CustomerDefeatedEvent.class)
... ...
fw-valhalla-service/src/main/java/cn/fw/valhalla/service/bus/cust/CustomerBizService.java
... ... @@ -96,7 +96,7 @@ public class CustomerBizService extends AbstractCustomerService {
96 96 * @return
97 97 */
98 98 public CustomerDetailVO getDetailById(final Long cusId) {
99   - CustomerDetailDto detailDto = queryById(cusId, Boolean.FALSE);
  99 + CustomerDetailDto detailDto = queryById(cusId);
100 100 BV.notNull(detailDto, () -> "查无此档案");
101 101 BV.isTrue(detailDto.getYn(), () -> "此档案已经作废,无法再继续查看");
102 102 CustomerDetailVO vo = new CustomerDetailVO();
... ... @@ -297,13 +297,8 @@ public class CustomerBizService extends AbstractCustomerService {
297 297 * @param cusId
298 298 * @return
299 299 */
300   - public CustomerDetailDto queryById(final Long cusId, final Boolean needInvalid) {
301   - Customer customer;
302   - if (Boolean.TRUE.equals(needInvalid)) {
303   - customer = customerService.queryByIdWithInvalid(cusId);
304   - } else {
305   - customer = customerService.queryById(cusId);
306   - }
  300 + public CustomerDetailDto queryById(final Long cusId) {
  301 + Customer customer = customerService.queryById(cusId);
307 302 if (Objects.isNull(customer)) {
308 303 return null;
309 304 }
... ... @@ -341,7 +336,7 @@ public class CustomerBizService extends AbstractCustomerService {
341 336 */
342 337 @Transactional(rollbackFor = Exception.class)
343 338 public void abandon(final Long customerId, final String reason) {
344   - CustomerDetailDto detailDto = queryById(customerId, Boolean.FALSE);
  339 + CustomerDetailDto detailDto = queryById(customerId);
345 340 BV.notNull(detailDto, () -> "档案不存在");
346 341 if (publicPoolService.queryByPlate(detailDto.getPlateNo(), detailDto.getGroupId()).isPresent()) {
347 342 return;
... ... @@ -359,7 +354,7 @@ public class CustomerBizService extends AbstractCustomerService {
359 354 affiliationRecordService.save(entity);
360 355 publicPoolService.save(publicPool);
361 356 stammkundePoolService.reject(customerId, detailDto.getGroupId(), DefeatReasonEnum.GU);
362   - PublicPoolEvent poolEvent = new PublicPoolEvent(customerId, detailDto.getGroupId());
  357 + PublicPoolEvent poolEvent = new PublicPoolEvent(customerId, detailDto.getGroupId(), false);
363 358 eventPublisher.publishEvent(poolEvent);
364 359 }
365 360  
... ... @@ -370,7 +365,7 @@ public class CustomerBizService extends AbstractCustomerService {
370 365 */
371 366 @Transactional(rollbackFor = Exception.class)
372 367 public void abandon(final FollowTask task, boolean flow) {
373   - CustomerDetailDto detailDto = queryById(task.getCustomerId(), Boolean.FALSE);
  368 + CustomerDetailDto detailDto = queryById(task.getCustomerId());
374 369 if (Objects.isNull(detailDto)) {
375 370 return;
376 371 }
... ... @@ -409,7 +404,7 @@ public class CustomerBizService extends AbstractCustomerService {
409 404 publicPoolService.save(publicPool);
410 405 stammkundePoolService.reject(task.getCustomerId(), task.getGroupId(), reasonEnum);
411 406  
412   - PublicPoolEvent poolEvent = new PublicPoolEvent(task.getCustomerId(), task.getGroupId());
  407 + PublicPoolEvent poolEvent = new PublicPoolEvent(task.getCustomerId(), task.getGroupId(), false);
413 408 eventPublisher.publishEvent(poolEvent);
414 409 }
415 410  
... ...
fw-valhalla-service/src/main/java/cn/fw/valhalla/service/bus/cust/CustomerChangeBizService.java
... ... @@ -40,6 +40,7 @@ import cn.fw.valhalla.sdk.enums.ReasonEnum;
40 40 import cn.fw.valhalla.sdk.param.ChangeAdviserReq;
41 41 import cn.fw.valhalla.service.data.*;
42 42 import cn.fw.valhalla.service.event.CustomerDefeatedEvent;
  43 +import cn.fw.valhalla.service.event.PublicPoolEvent;
43 44 import com.alibaba.fastjson.JSON;
44 45 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
45 46 import lombok.RequiredArgsConstructor;
... ... @@ -205,6 +206,8 @@ public class CustomerChangeBizService extends AbstractCustomerService {
205 206 if (!bool) {
206 207 stammkundePoolService.reject(saveDto.getId(), saveDto.getGroupId(), DefeatReasonEnum.CI);
207 208 customerService.forbidden(saveDto.getMotoId());
  209 + PublicPoolEvent poolEvent = new PublicPoolEvent(saveDto.getMotoId(), saveDto.getGroupId(), true);
  210 + eventPublisher.publishEvent(poolEvent);
208 211 }
209 212 Customer customer = customerService.queryById(saveDto.getId());
210 213 BV.notNull(customer, "档案信息异常");
... ... @@ -218,6 +221,8 @@ public class CustomerChangeBizService extends AbstractCustomerService {
218 221 } else {
219 222 stammkundePoolService.reject(saveDto.getId(), saveDto.getGroupId(), DefeatReasonEnum.CI);
220 223 customerService.forbidden(saveDto.getMotoId());
  224 + PublicPoolEvent poolEvent = new PublicPoolEvent(saveDto.getMotoId(), saveDto.getGroupId(), true);
  225 + eventPublisher.publishEvent(poolEvent);
221 226 Customer customer = new Customer();
222 227 BeanUtils.copyProperties(saveDto, customer);
223 228 customer.setUseType(CarUseTypeEnum.ofValue(saveDto.getUseType()));
... ... @@ -229,6 +234,8 @@ public class CustomerChangeBizService extends AbstractCustomerService {
229 234 if (Objects.nonNull(saveDto.getId())) {
230 235 stammkundePoolService.reject(saveDto.getId(), saveDto.getGroupId(), DefeatReasonEnum.CI);
231 236 customerService.forbidden(saveDto.getId());
  237 + PublicPoolEvent poolEvent = new PublicPoolEvent(saveDto.getMotoId(), saveDto.getGroupId(), true);
  238 + eventPublisher.publishEvent(poolEvent);
232 239 saveDto.setId(null);
233 240 }
234 241 Customer customer = new Customer();
... ...
fw-valhalla-service/src/main/java/cn/fw/valhalla/service/bus/follow/FollowBizService.java
... ... @@ -400,23 +400,62 @@ public class FollowBizService {
400 400 @Transactional(rollbackFor = Exception.class)
401 401 public void stopTask(Long customerId, Long groupId) {
402 402 List<FollowTypeEnum> typeList = Arrays.asList(FollowTypeEnum.FM, FollowTypeEnum.RM);
403   - List<ClueStatusEnum> statusList = Arrays.asList(ClueStatusEnum.WAITING, ClueStatusEnum.ONGOING);
404 403 List<CustomerCluePool> cluePoolList = customerCluePoolService.list(Wrappers.<CustomerCluePool>lambdaQuery()
405   - .in(CustomerCluePool::getClueStatus, statusList)
  404 + .eq(CustomerCluePool::getClueStatus, ClueStatusEnum.ONGOING)
406 405 .in(CustomerCluePool::getClueType, typeList)
407 406 .eq(CustomerCluePool::getRefererId, customerId)
408 407 .eq(CustomerCluePool::getGroupId, groupId)
409 408 );
410   - if (CollectionUtils.isEmpty(cluePoolList)) {
  409 + if (!CollectionUtils.isEmpty(cluePoolList)) {
  410 + for (CustomerCluePool clue : cluePoolList) {
  411 + FollowStrategy strategy = followMap.get(clue.getClueType());
  412 + if (Objects.nonNull(strategy)) {
  413 + strategy.forceStopClue(clue);
  414 + }
  415 + }
  416 + customerCluePoolService.updateBatchById(cluePoolList);
  417 + }
  418 + List<CustomerCluePool> cluePoolWaitList = customerCluePoolService.list(Wrappers.<CustomerCluePool>lambdaQuery()
  419 + .eq(CustomerCluePool::getClueStatus, ClueStatusEnum.WAITING)
  420 + .in(CustomerCluePool::getClueType, typeList)
  421 + .eq(CustomerCluePool::getRefererId, customerId)
  422 + .eq(CustomerCluePool::getGroupId, groupId)
  423 + );
  424 +
  425 + if (CollectionUtils.isEmpty(cluePoolWaitList)) {
411 426 return;
412 427 }
413   - for (CustomerCluePool clue : cluePoolList) {
414   - FollowStrategy strategy = followMap.get(clue.getClueType());
415   - if (Objects.nonNull(strategy)) {
416   - strategy.forceStopClue(clue);
  428 + customerCluePoolService.removeByIds(cluePoolWaitList);
  429 + }
  430 +
  431 + @Transactional(rollbackFor = Exception.class)
  432 + public void onForbidden(Long customerId, Long groupId) {
  433 + List<FollowTypeEnum> typeList = Arrays.asList(FollowTypeEnum.FM, FollowTypeEnum.RM, FollowTypeEnum.IR);
  434 + List<CustomerCluePool> cluePoolList = customerCluePoolService.list(Wrappers.<CustomerCluePool>lambdaQuery()
  435 + .eq(CustomerCluePool::getClueStatus, ClueStatusEnum.ONGOING)
  436 + .in(CustomerCluePool::getClueType, typeList)
  437 + .eq(CustomerCluePool::getRefererId, customerId)
  438 + .eq(CustomerCluePool::getGroupId, groupId)
  439 + );
  440 + if (!CollectionUtils.isEmpty(cluePoolList)) {
  441 + for (CustomerCluePool clue : cluePoolList) {
  442 + FollowStrategy strategy = followMap.get(clue.getClueType());
  443 + if (Objects.nonNull(strategy)) {
  444 + strategy.onForbiddenStopClue(clue);
  445 + }
417 446 }
418 447 }
419 448 customerCluePoolService.updateBatchById(cluePoolList);
  449 + List<CustomerCluePool> cluePoolWaitList = customerCluePoolService.list(Wrappers.<CustomerCluePool>lambdaQuery()
  450 + .eq(CustomerCluePool::getClueStatus, ClueStatusEnum.WAITING)
  451 + .in(CustomerCluePool::getClueType, typeList)
  452 + .eq(CustomerCluePool::getRefererId, customerId)
  453 + .eq(CustomerCluePool::getGroupId, groupId)
  454 + );
  455 +
  456 + if (!CollectionUtils.isEmpty(cluePoolWaitList)) {
  457 + customerCluePoolService.removeByIds(cluePoolWaitList);
  458 + }
420 459 }
421 460  
422 461 /**
... ...
fw-valhalla-service/src/main/java/cn/fw/valhalla/service/bus/follow/strategy/AbstractFollowStrategy.java
... ... @@ -635,32 +635,13 @@ public abstract class AbstractFollowStrategy implements FollowStrategy {
635 635 @Override
636 636 @Transactional(rollbackFor = Exception.class)
637 637 public void forceStopClue(CustomerCluePool clue) {
638   - clue.setClueStatus(ClueStatusEnum.FAILURE);
639   - clue.setCloseTime(new Date());
640   - FollowTask task = followTaskService.queryOngoingTaskByClueId(clue.getId());
641   - if (Objects.isNull(task)) {
642   - return;
643   - }
644   - task.setState(TaskStateEnum.DEFEAT);
645   - task.setCloseTime(new Date());
646   - task.setReason(TaskDefeatTypeEnum.A);
647   - followTaskService.updateById(task);
  638 + onStopClue(clue, TaskDefeatTypeEnum.A);
  639 + }
648 640  
649   - List<FollowRecord> recordList = followRecordService.list(Wrappers.<FollowRecord>lambdaQuery()
650   - .eq(FollowRecord::getTaskId, task.getId())
651   - .eq(FollowRecord::getCustomerId, clue.getRefererId())
652   - .eq(FollowRecord::getOutTime, Boolean.FALSE)
653   - .isNull(FollowRecord::getFollowTime)
654   - );
655   - if (!CollectionUtils.isEmpty(recordList)) {
656   - for (FollowRecord record : recordList) {
657   - if (Boolean.TRUE.equals(record.getAddTodo())) {
658   - completeRecordAndEnd(record);
659   - } else {
660   - followRecordService.removeById(record.getId());
661   - }
662   - }
663   - }
  641 + @Override
  642 + @Transactional(rollbackFor = Exception.class)
  643 + public void onForbiddenStopClue(CustomerCluePool clue) {
  644 + onStopClue(clue, TaskDefeatTypeEnum.E);
664 645 }
665 646  
666 647 @Transactional(rollbackFor = Exception.class)
... ... @@ -806,6 +787,35 @@ public abstract class AbstractFollowStrategy implements FollowStrategy {
806 787 followTaskService.updateById(task);
807 788 }
808 789  
  790 + private void onStopClue(CustomerCluePool clue, TaskDefeatTypeEnum defeatTypeEnum) {
  791 + clue.setClueStatus(ClueStatusEnum.FAILURE);
  792 + clue.setCloseTime(new Date());
  793 + FollowTask task = followTaskService.queryOngoingTaskByClueId(clue.getId());
  794 + if (Objects.isNull(task)) {
  795 + return;
  796 + }
  797 + task.setState(TaskStateEnum.DEFEAT);
  798 + task.setCloseTime(new Date());
  799 + task.setReason(defeatTypeEnum);
  800 + followTaskService.updateById(task);
  801 +
  802 + List<FollowRecord> recordList = followRecordService.list(Wrappers.<FollowRecord>lambdaQuery()
  803 + .eq(FollowRecord::getTaskId, task.getId())
  804 + .eq(FollowRecord::getCustomerId, clue.getRefererId())
  805 + .eq(FollowRecord::getOutTime, Boolean.FALSE)
  806 + .isNull(FollowRecord::getFollowTime)
  807 + );
  808 + if (!CollectionUtils.isEmpty(recordList)) {
  809 + for (FollowRecord record : recordList) {
  810 + if (Boolean.TRUE.equals(record.getAddTodo())) {
  811 + completeRecordAndEnd(record);
  812 + } else {
  813 + followRecordService.removeById(record.getId());
  814 + }
  815 + }
  816 + }
  817 + }
  818 +
809 819 /**
810 820 * 生成新的跟进
811 821 *
... ...
fw-valhalla-service/src/main/java/cn/fw/valhalla/service/bus/follow/strategy/FollowStrategy.java
... ... @@ -137,6 +137,13 @@ public interface FollowStrategy {
137 137 void forceStopClue(CustomerCluePool clue);
138 138  
139 139 /**
  140 + * 当档案作废是强制结束任务
  141 + *
  142 + * @param clue
  143 + */
  144 + void onForbiddenStopClue(CustomerCluePool clue);
  145 +
  146 + /**
140 147 * 更新跟进任务
141 148 *
142 149 * @param customerId
... ...
fw-valhalla-service/src/main/java/cn/fw/valhalla/service/bus/follow/strategy/impl/ACFollowStrategy.java
... ... @@ -303,7 +303,7 @@ public class ACFollowStrategy extends AbstractFollowStrategy {
303 303 vo.setPlateNo(accidentPool.getPlateNo());
304 304 vo.setCarModel(getStrWithDefault(accidentPool.getBrandName(), "") + " " + getStrWithDefault(accidentPool.getSeriesName(), ""));
305 305 if (Objects.nonNull(customer)) {
306   - CustomerDetailDto customerDetailDto = customerBizService.queryById(customer.getId(), Boolean.TRUE);
  306 + CustomerDetailDto customerDetailDto = customerBizService.queryById(customer.getId());
307 307 vo.setCustomerId(customer.getId());
308 308 vo.setAdviserId(customerDetailDto.getAdviserId());
309 309 vo.setAdviserName(customerDetailDto.getAdviserName());
... ...
fw-valhalla-service/src/main/java/cn/fw/valhalla/service/bus/follow/strategy/impl/FMFollowStrategy.java
... ... @@ -52,7 +52,7 @@ public class FMFollowStrategy extends AbstractFollowStrategy {
52 52 vo.setTaskId(followRecord.getTaskId());
53 53 vo.setCustomerId(followRecord.getCustomerId());
54 54 vo.setDeadline(followRecord.getDeadline());
55   - CustomerDetailDto customerDetailDto = customerBizService.queryById(followRecord.getCustomerId(), Boolean.FALSE);
  55 + CustomerDetailDto customerDetailDto = customerBizService.queryById(followRecord.getCustomerId());
56 56 if (Objects.nonNull(customerDetailDto)) {
57 57 vo.setName(customerDetailDto.getName());
58 58 vo.setPlateNo(customerDetailDto.getPlateNo());
... ... @@ -174,7 +174,7 @@ public class FMFollowStrategy extends AbstractFollowStrategy {
174 174  
175 175 @Override
176 176 public FMDetailVO assemble(Long customerId) {
177   - CustomerDetailDto customerDetailDto = customerBizService.queryById(customerId, Boolean.TRUE);
  177 + CustomerDetailDto customerDetailDto = customerBizService.queryById(customerId);
178 178 FMDetailVO vo = new FMDetailVO();
179 179 vo.setVin(customerDetailDto.getFrameNo());
180 180 vo.setCustomerId(customerId);
... ...
fw-valhalla-service/src/main/java/cn/fw/valhalla/service/bus/follow/strategy/impl/IRFollowStrategy.java
... ... @@ -62,7 +62,7 @@ public class IRFollowStrategy extends AbstractFollowStrategy {
62 62 vo.setTaskId(followRecord.getTaskId());
63 63 vo.setCustomerId(followRecord.getCustomerId());
64 64 vo.setDeadline(followRecord.getDeadline());
65   - CustomerDetailDto customerDetailDto = customerBizService.queryById(followRecord.getCustomerId(), Boolean.TRUE);
  65 + CustomerDetailDto customerDetailDto = customerBizService.queryById(followRecord.getCustomerId());
66 66 vo.setName(customerDetailDto.getName());
67 67 vo.setCarImage(customerDetailDto.getCarImage());
68 68 vo.setPlateNo(customerDetailDto.getPlateNo());
... ... @@ -407,7 +407,7 @@ public class IRFollowStrategy extends AbstractFollowStrategy {
407 407  
408 408 @Override
409 409 public IRDetailVO assemble(Long customerId) {
410   - CustomerDetailDto detailDto = customerBizService.queryById(customerId, Boolean.TRUE);
  410 + CustomerDetailDto detailDto = customerBizService.queryById(customerId);
411 411 IRDetailVO vo = new IRDetailVO();
412 412 vo.setCustomerId(customerId);
413 413 vo.setAdviserId(detailDto.getAdviserId());
... ...
fw-valhalla-service/src/main/java/cn/fw/valhalla/service/bus/follow/strategy/impl/RMFollowStrategy.java
... ... @@ -73,7 +73,7 @@ public class RMFollowStrategy extends AbstractFollowStrategy {
73 73 vo.setTaskId(followRecord.getTaskId());
74 74 vo.setCustomerId(followRecord.getCustomerId());
75 75 vo.setDeadline(followRecord.getDeadline());
76   - CustomerDetailDto customerDetailDto = customerBizService.queryById(followRecord.getCustomerId(), Boolean.TRUE);
  76 + CustomerDetailDto customerDetailDto = customerBizService.queryById(followRecord.getCustomerId());
77 77 vo.setName(customerDetailDto.getName());
78 78 vo.setCarImage(customerDetailDto.getCarImage());
79 79 vo.setPlateNo(customerDetailDto.getPlateNo());
... ... @@ -237,7 +237,7 @@ public class RMFollowStrategy extends AbstractFollowStrategy {
237 237  
238 238 @Override
239 239 public RMDetailVO assemble(Long customerId) {
240   - CustomerDetailDto customerDetailDto = customerBizService.queryById(customerId, Boolean.TRUE);
  240 + CustomerDetailDto customerDetailDto = customerBizService.queryById(customerId);
241 241 RMDetailVO vo = new RMDetailVO();
242 242 vo.setCustomerId(customerId);
243 243 vo.setName(customerDetailDto.getName());
... ...
fw-valhalla-service/src/main/java/cn/fw/valhalla/service/event/PublicPoolEvent.java
... ... @@ -14,4 +14,5 @@ import lombok.Data;
14 14 public class PublicPoolEvent {
15 15 private Long customerId;
16 16 private Long groupId;
  17 + private Boolean forbidden;
17 18 }
... ...