diff --git a/fw-valhalla-domain/src/main/java/cn/fw/valhalla/domain/dto/AccidentPoolDTO.java b/fw-valhalla-domain/src/main/java/cn/fw/valhalla/domain/dto/AccidentPoolDTO.java index b97b8c2..b4101e2 100644 --- a/fw-valhalla-domain/src/main/java/cn/fw/valhalla/domain/dto/AccidentPoolDTO.java +++ b/fw-valhalla-domain/src/main/java/cn/fw/valhalla/domain/dto/AccidentPoolDTO.java @@ -80,4 +80,8 @@ public class AccidentPoolDTO { * 报案地点 */ private String reportAddress; + /** + * 强制录入 + */ + private Boolean force; } diff --git a/fw-valhalla-server/src/main/java/cn/fw/valhalla/controller/app/AccidentCarController.java b/fw-valhalla-server/src/main/java/cn/fw/valhalla/controller/app/AccidentCarController.java index 6670418..9211b2b 100644 --- a/fw-valhalla-server/src/main/java/cn/fw/valhalla/controller/app/AccidentCarController.java +++ b/fw-valhalla-server/src/main/java/cn/fw/valhalla/controller/app/AccidentCarController.java @@ -42,9 +42,8 @@ public class AccidentCarController { @PostMapping("/pool/save") @ControllerMethod("新增事故车线索") - public Message save(@CurrentUser LoginAuthBean currentUser, + public Message save(@CurrentUser LoginAuthBean currentUser, @RequestBody @Valid final AccidentPoolDTO accidentPoolDTO) { - accidentPoolBizService.add2Pool(currentUser, accidentPoolDTO); - return success(); + return success(accidentPoolBizService.add2Pool(currentUser, accidentPoolDTO)); } } diff --git a/fw-valhalla-service/src/main/java/cn/fw/valhalla/service/bus/cust/AccidentPoolBizService.java b/fw-valhalla-service/src/main/java/cn/fw/valhalla/service/bus/cust/AccidentPoolBizService.java index 8aa9eaa..a38ebb1 100644 --- a/fw-valhalla-service/src/main/java/cn/fw/valhalla/service/bus/cust/AccidentPoolBizService.java +++ b/fw-valhalla-service/src/main/java/cn/fw/valhalla/service/bus/cust/AccidentPoolBizService.java @@ -1,5 +1,6 @@ package cn.fw.valhalla.service.bus.cust; +import cn.fw.common.util.ValidationUtils; import cn.fw.common.web.annotation.DisLock; import cn.fw.common.web.auth.LoginAuthBean; import cn.fw.valhalla.common.constant.RoleCode; @@ -31,11 +32,11 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; import java.sql.Timestamp; +import java.time.LocalDate; import java.time.LocalDateTime; import java.util.*; import static cn.fw.common.businessvalidator.Validator.BV; -import static cn.fw.valhalla.common.utils.DateUtil.getNowExpiredDay; import static cn.fw.valhalla.service.bus.follow.strategy.AbstractFollowStrategy.getCalendarType; /** @@ -70,9 +71,16 @@ public class AccidentPoolBizService { @Transactional(rollbackFor = Exception.class) @DisLock(prefix = "#this.getKeyPrefix()", key = "#currentUser.groupId + ':' + #poolDTO.plateNo", message = "请勿重复提交") - public void add2Pool(LoginAuthBean currentUser, AccidentPoolDTO poolDTO) { - boolean repetition = isRepetition(currentUser.getGroupId(), poolDTO.getPlateNo()); - BV.isFalse(repetition, () -> "该记录已存在,请勿重复添加"); + public Long add2Pool(LoginAuthBean currentUser, AccidentPoolDTO poolDTO) { + boolean isPlateNo = ValidationUtils.checkCarPlate(poolDTO.getPlateNo()); + BV.isTrue(isPlateNo, () -> "车牌号不正确,请检查是否包含I、O或特殊字符"); + if (!Boolean.TRUE.equals(poolDTO.getForce())) { + AccidentPool repetition = isRepetition(currentUser.getGroupId(), poolDTO.getPlateNo()); + if (Objects.nonNull(repetition)) { + return repetition.getCreateTime().getTime(); + } + } + if (StringUtils.isEmpty(poolDTO.getMobile())) { poolDTO.setMobile(poolDTO.getReportMobile()); } @@ -82,6 +90,7 @@ public class AccidentPoolBizService { BV.notNull(pool.getShopId(), () -> "服务站信息不正确,请确认"); accidentPoolService.save(pool); afterAddPool(pool); + return 0L; } private void afterAddPool(final AccidentPool pool) { @@ -108,13 +117,32 @@ public class AccidentPoolBizService { return pool; } - private boolean isRepetition(Long groupId, String plateNo) { - int count = accidentPoolService.count(Wrappers.lambdaQuery() + private AccidentPool isRepetition(Long groupId, String plateNo) { + AccidentPool lastOne = accidentPoolService.getOne(Wrappers.lambdaQuery() .eq(AccidentPool::getPlateNo, plateNo) .eq(AccidentPool::getGroupId, groupId) - .ge(AccidentPool::getCreateTime, DateUtil.startDate(getNowExpiredDay(-1))) + .orderByDesc(AccidentPool::getCreateTime) + .last(" limit 1 ") ); - return count > 0; + + if (Objects.isNull(lastOne)) { + return null; + } + + if (LocalDate.now().minusDays(7L).isBefore(DateUtil.date2LocalDate(lastOne.getCreateTime()))) { + FollowTask lastOngoingTask = followTaskService.getOne(Wrappers.lambdaQuery() + .eq(FollowTask::getCustomerId, lastOne.getId()) + .eq(FollowTask::getType, FollowTypeEnum.AC) + .eq(FollowTask::getState, TaskStateEnum.ONGOING) + .last(" limit 1 ") + ); + + if (Objects.nonNull(lastOngoingTask)) { + return lastOne; + } + } + + return null; } /**