Commit bf85c222641347f3657537585ff30aa5119a9f7b
1 parent
499f5f26
事故车录入逻辑优化
Showing
3 changed files
with
42 additions
and
11 deletions
fw-valhalla-domain/src/main/java/cn/fw/valhalla/domain/dto/AccidentPoolDTO.java
fw-valhalla-server/src/main/java/cn/fw/valhalla/controller/app/AccidentCarController.java
... | ... | @@ -42,9 +42,8 @@ public class AccidentCarController { |
42 | 42 | |
43 | 43 | @PostMapping("/pool/save") |
44 | 44 | @ControllerMethod("新增事故车线索") |
45 | - public Message<Void> save(@CurrentUser LoginAuthBean currentUser, | |
45 | + public Message<Long> save(@CurrentUser LoginAuthBean currentUser, | |
46 | 46 | @RequestBody @Valid final AccidentPoolDTO accidentPoolDTO) { |
47 | - accidentPoolBizService.add2Pool(currentUser, accidentPoolDTO); | |
48 | - return success(); | |
47 | + return success(accidentPoolBizService.add2Pool(currentUser, accidentPoolDTO)); | |
49 | 48 | } |
50 | 49 | } | ... | ... |
fw-valhalla-service/src/main/java/cn/fw/valhalla/service/bus/cust/AccidentPoolBizService.java
1 | 1 | package cn.fw.valhalla.service.bus.cust; |
2 | 2 | |
3 | +import cn.fw.common.util.ValidationUtils; | |
3 | 4 | import cn.fw.common.web.annotation.DisLock; |
4 | 5 | import cn.fw.common.web.auth.LoginAuthBean; |
5 | 6 | import cn.fw.valhalla.common.constant.RoleCode; |
... | ... | @@ -31,11 +32,11 @@ import org.springframework.transaction.annotation.Transactional; |
31 | 32 | import org.springframework.util.CollectionUtils; |
32 | 33 | |
33 | 34 | import java.sql.Timestamp; |
35 | +import java.time.LocalDate; | |
34 | 36 | import java.time.LocalDateTime; |
35 | 37 | import java.util.*; |
36 | 38 | |
37 | 39 | import static cn.fw.common.businessvalidator.Validator.BV; |
38 | -import static cn.fw.valhalla.common.utils.DateUtil.getNowExpiredDay; | |
39 | 40 | import static cn.fw.valhalla.service.bus.follow.strategy.AbstractFollowStrategy.getCalendarType; |
40 | 41 | |
41 | 42 | /** |
... | ... | @@ -70,9 +71,16 @@ public class AccidentPoolBizService { |
70 | 71 | |
71 | 72 | @Transactional(rollbackFor = Exception.class) |
72 | 73 | @DisLock(prefix = "#this.getKeyPrefix()", key = "#currentUser.groupId + ':' + #poolDTO.plateNo", message = "请勿重复提交") |
73 | - public void add2Pool(LoginAuthBean currentUser, AccidentPoolDTO poolDTO) { | |
74 | - boolean repetition = isRepetition(currentUser.getGroupId(), poolDTO.getPlateNo()); | |
75 | - BV.isFalse(repetition, () -> "该记录已存在,请勿重复添加"); | |
74 | + public Long add2Pool(LoginAuthBean currentUser, AccidentPoolDTO poolDTO) { | |
75 | + boolean isPlateNo = ValidationUtils.checkCarPlate(poolDTO.getPlateNo()); | |
76 | + BV.isTrue(isPlateNo, () -> "车牌号不正确,请检查是否包含I、O或特殊字符"); | |
77 | + if (!Boolean.TRUE.equals(poolDTO.getForce())) { | |
78 | + AccidentPool repetition = isRepetition(currentUser.getGroupId(), poolDTO.getPlateNo()); | |
79 | + if (Objects.nonNull(repetition)) { | |
80 | + return repetition.getCreateTime().getTime(); | |
81 | + } | |
82 | + } | |
83 | + | |
76 | 84 | if (StringUtils.isEmpty(poolDTO.getMobile())) { |
77 | 85 | poolDTO.setMobile(poolDTO.getReportMobile()); |
78 | 86 | } |
... | ... | @@ -82,6 +90,7 @@ public class AccidentPoolBizService { |
82 | 90 | BV.notNull(pool.getShopId(), () -> "服务站信息不正确,请确认"); |
83 | 91 | accidentPoolService.save(pool); |
84 | 92 | afterAddPool(pool); |
93 | + return 0L; | |
85 | 94 | } |
86 | 95 | |
87 | 96 | private void afterAddPool(final AccidentPool pool) { |
... | ... | @@ -108,13 +117,32 @@ public class AccidentPoolBizService { |
108 | 117 | return pool; |
109 | 118 | } |
110 | 119 | |
111 | - private boolean isRepetition(Long groupId, String plateNo) { | |
112 | - int count = accidentPoolService.count(Wrappers.<AccidentPool>lambdaQuery() | |
120 | + private AccidentPool isRepetition(Long groupId, String plateNo) { | |
121 | + AccidentPool lastOne = accidentPoolService.getOne(Wrappers.<AccidentPool>lambdaQuery() | |
113 | 122 | .eq(AccidentPool::getPlateNo, plateNo) |
114 | 123 | .eq(AccidentPool::getGroupId, groupId) |
115 | - .ge(AccidentPool::getCreateTime, DateUtil.startDate(getNowExpiredDay(-1))) | |
124 | + .orderByDesc(AccidentPool::getCreateTime) | |
125 | + .last(" limit 1 ") | |
116 | 126 | ); |
117 | - return count > 0; | |
127 | + | |
128 | + if (Objects.isNull(lastOne)) { | |
129 | + return null; | |
130 | + } | |
131 | + | |
132 | + if (LocalDate.now().minusDays(7L).isBefore(DateUtil.date2LocalDate(lastOne.getCreateTime()))) { | |
133 | + FollowTask lastOngoingTask = followTaskService.getOne(Wrappers.<FollowTask>lambdaQuery() | |
134 | + .eq(FollowTask::getCustomerId, lastOne.getId()) | |
135 | + .eq(FollowTask::getType, FollowTypeEnum.AC) | |
136 | + .eq(FollowTask::getState, TaskStateEnum.ONGOING) | |
137 | + .last(" limit 1 ") | |
138 | + ); | |
139 | + | |
140 | + if (Objects.nonNull(lastOngoingTask)) { | |
141 | + return lastOne; | |
142 | + } | |
143 | + } | |
144 | + | |
145 | + return null; | |
118 | 146 | } |
119 | 147 | |
120 | 148 | /** | ... | ... |