fix:增加行程无需审批的配置类

This commit is contained in:
lulz1 2024-07-12 13:18:55 +08:00
parent ac5a8ed996
commit 3a2974804b
2 changed files with 23 additions and 57 deletions

View File

@ -35,8 +35,7 @@ import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.Set; import java.util.Set;
import static com.chint.domain.value_object.enums.RoutePermission.LEG_NEED_APPROVAL; import static com.chint.domain.value_object.enums.RoutePermission.*;
import static com.chint.domain.value_object.enums.RoutePermission.LEG_NEED_NOTIFY;
import static com.chint.infrastructure.constant.CommonMessageConstant.LEG_TIME_ERROR; import static com.chint.infrastructure.constant.CommonMessageConstant.LEG_TIME_ERROR;
import static com.chint.infrastructure.constant.CommonMessageConstant.NOT_FOUND; import static com.chint.infrastructure.constant.CommonMessageConstant.NOT_FOUND;
import static com.chint.infrastructure.constant.RouteConstant.ORDER_STATUS_APPROVAL; import static com.chint.infrastructure.constant.RouteConstant.ORDER_STATUS_APPROVAL;
@ -93,19 +92,15 @@ public class OrderApplicationService {
@Transactional @Transactional
public void addLegToOrder(AddLegData addLegData) { public void addLegToOrder(AddLegData addLegData) {
// First, attempt to retrieve the RouteOrder from the database // First, attempt to retrieve the RouteOrder from the database
RouteOrder routeOrder = Optional.ofNullable(routeRepository RouteOrder routeOrder = Optional.ofNullable(routeRepository.findByFakeOrderNoAndSysCode(addLegData.getFakeOrderNo(), addLegData.getSysCode())).orElseGet(() -> {
.findByFakeOrderNoAndSysCode(addLegData.getFakeOrderNo(), addLegData.getSysCode())) // If not found in the database, attempt to retrieve from Redis
.orElseGet(() -> { RouteOrder tempRouteOrder = routeRepository.findTempRouteOrderBySysCodeAndBillCode(addLegData.getSysCode(), addLegData.getFakeOrderNo());
// If not found in the database, attempt to retrieve from Redis // If not found in Redis, retrieve by ID from the database
RouteOrder tempRouteOrder = routeRepository if (tempRouteOrder == null) {
.findTempRouteOrderBySysCodeAndBillCode(addLegData.getSysCode(), addLegData.getFakeOrderNo()); return Optional.ofNullable(routeRepository.queryById(addLegData.getRouteId())).orElseThrow(() -> new NotFoundException(NOT_FOUND));
// If not found in Redis, retrieve by ID from the database }
if (tempRouteOrder == null) { return tempRouteOrder;
return Optional.ofNullable(routeRepository.queryById(addLegData.getRouteId())) });
.orElseThrow(() -> new NotFoundException(NOT_FOUND));
}
return tempRouteOrder;
});
checkLegDataTime(addLegData, routeOrder); checkLegDataTime(addLegData, routeOrder);
LegData legData = addLegData.getLegData(); LegData legData = addLegData.getLegData();
@ -124,8 +119,7 @@ public class OrderApplicationService {
public void changeLeg(AddLegData addLegData) { public void changeLeg(AddLegData addLegData) {
LegData legData = addLegData.getLegData(); LegData legData = addLegData.getLegData();
// 查找 Leg 并确保 RouteOrder 存在 // 查找 Leg 并确保 RouteOrder 存在
Leg leg = Optional.ofNullable(legRepository.findByLegId(Long.valueOf(legData.getLegId()))) Leg leg = Optional.ofNullable(legRepository.findByLegId(Long.valueOf(legData.getLegId()))).orElseThrow(() -> new NotFoundException(NOT_FOUND));
.orElseThrow(() -> new NotFoundException(NOT_FOUND));
RouteOrder routeOrder = routeRepository.queryById(leg.getRouteId()); RouteOrder routeOrder = routeRepository.queryById(leg.getRouteId());
if (routeOrder == null) { if (routeOrder == null) {
throw new NotFoundException(NOT_FOUND); throw new NotFoundException(NOT_FOUND);
@ -134,11 +128,7 @@ public class OrderApplicationService {
// 创建一个临时变量来避免 Lambda 表达式中的变量修改问题 // 创建一个临时变量来避免 Lambda 表达式中的变量修改问题
final Long legId = leg.getLegId(); final Long legId = leg.getLegId();
// 找到 LegItem // 找到 LegItem
leg = routeOrder.getLegItems().stream() leg = routeOrder.getLegItems().stream().filter(legItem -> legItem.getLegId().equals(legId)).findFirst().orElseThrow(() -> new NotFoundException(NOT_FOUND)).reloadStatus();
.filter(legItem -> legItem.getLegId().equals(legId))
.findFirst()
.orElseThrow(() -> new NotFoundException(NOT_FOUND))
.reloadStatus();
Leg oldLeg = leg.deepClone(); Leg oldLeg = leg.deepClone();
// leg 进行更新 // leg 进行更新
@ -157,10 +147,7 @@ public class OrderApplicationService {
} }
} }
if (!routeOrder.getOrderStatus().equals(ORDER_STATUS_PREPARE) && !approveOrderNo.getSysCode().equals("ANFSSC")) { if (!routeOrder.getOrderStatus().equals(ORDER_STATUS_PREPARE) && !approveOrderNo.getSysCode().equals("ANFSSC")) {
sendLegChangeCommand(oldLeg, leg, sendLegChangeCommand(oldLeg, leg, routeOrder, addLegData.getLegData().getChangeReason(), 1);
routeOrder,
addLegData.getLegData().getChangeReason(),
1);
} }
// 保存 routeOrder 并重新加载状态 // 保存 routeOrder 并重新加载状态
@ -174,7 +161,7 @@ public class OrderApplicationService {
if (routePermissionSet == null) { if (routePermissionSet == null) {
routeApprovalDomainService.checkApprovalPermissions(routeOrder); routeApprovalDomainService.checkApprovalPermissions(routeOrder);
} }
if (routePermissionSet == null) { if (routePermissionSet == null || routePermissionSet.isEmpty() || routePermissionSet.contains(LEG_NO_APPROVAL)) {
return false; return false;
} }
return routePermissionSet.contains(LEG_NEED_APPROVAL) || routePermissionSet.contains(LEG_NEED_NOTIFY); return routePermissionSet.contains(LEG_NEED_APPROVAL) || routePermissionSet.contains(LEG_NEED_NOTIFY);
@ -203,8 +190,7 @@ public class OrderApplicationService {
leg.setRouteId(routeOrder.getRouteId()); leg.setRouteId(routeOrder.getRouteId());
ApproveOrderNo approveOrderNo = routeOrder.getApproveOrderNo(); ApproveOrderNo approveOrderNo = routeOrder.getApproveOrderNo();
if (!routeOrder.getOrderStatus().equals(ORDER_STATUS_PREPARE) && addLegData.getIfApprove() == 1 if (!routeOrder.getOrderStatus().equals(ORDER_STATUS_PREPARE) && addLegData.getIfApprove() == 1) {
) {
//这里加入一个待审批事件 //这里加入一个待审批事件
if (checkIfNeedApprove(routeOrder)) { if (checkIfNeedApprove(routeOrder)) {
leg.addEvent(LegApprovalEvent.prepare()); leg.addEvent(LegApprovalEvent.prepare());
@ -220,22 +206,11 @@ public class OrderApplicationService {
} }
private boolean isOrderInApprovalState(RouteOrder routeOrder) { private boolean isOrderInApprovalState(RouteOrder routeOrder) {
return routeOrder.getApproveOrderNo().getActualOrderNo() != null return routeOrder.getApproveOrderNo().getActualOrderNo() != null || routeOrder.getOrderStatus() >= ORDER_STATUS_APPROVAL;
|| routeOrder.getOrderStatus() >= ORDER_STATUS_APPROVAL;
} }
private void sendLegChangeCommand(Leg oldLeg, Leg leg, private void sendLegChangeCommand(Leg oldLeg, Leg leg, RouteOrder routeOrder, String changeReason, int changeType) {
RouteOrder routeOrder, Command.of(BPMLegChangeCommand.class).routeId(routeOrder.getRouteId()).reason(changeReason).oldLeg(oldLeg).routeOrder(routeOrder).newleg(leg.reloadStatus()).changeType(changeType).sendToQueue();
String changeReason,
int changeType) {
Command.of(BPMLegChangeCommand.class)
.routeId(routeOrder.getRouteId())
.reason(changeReason)
.oldLeg(oldLeg)
.routeOrder(routeOrder)
.newleg(leg.reloadStatus())
.changeType(changeType)
.sendToQueue();
} }
private List<Leg> processLegData(LegData legData, RouteOrder order) { private List<Leg> processLegData(LegData legData, RouteOrder order) {
@ -259,8 +234,7 @@ public class OrderApplicationService {
routeOrder.deleteLeg(split[0]); routeOrder.deleteLeg(split[0]);
} }
if (routeOrder == null) { if (routeOrder == null) {
routeOrder = Optional.ofNullable(routeRepository.queryById(deleteLegData.getRouteId())) routeOrder = Optional.ofNullable(routeRepository.queryById(deleteLegData.getRouteId())).orElseThrow(() -> new NotFoundException(NOT_FOUND)).reloadStatus();
.orElseThrow(() -> new NotFoundException(NOT_FOUND)).reloadStatus();
} }
if (routeOrder != null) { if (routeOrder != null) {
routeOrder.reloadStatus(); routeOrder.reloadStatus();
@ -299,10 +273,7 @@ public class OrderApplicationService {
@Transactional @Transactional
public void orderedToLeg(UpdateLegData updateLegData) { public void orderedToLeg(UpdateLegData updateLegData) {
Command.of(LegOrderedCommand.class) Command.of(LegOrderedCommand.class).legId(updateLegData.getLegId()).orderDetailId(updateLegData.getOrderDetailId()).sendToQueue();
.legId(updateLegData.getLegId())
.orderDetailId(updateLegData.getOrderDetailId())
.sendToQueue();
} }
@Transactional @Transactional
@ -353,16 +324,11 @@ public class OrderApplicationService {
LocalDateTime endTime = order.getEndTime(); LocalDateTime endTime = order.getEndTime();
LegData legData = addLegData.getLegData(); LegData legData = addLegData.getLegData();
if (!order.getOrderStatus().equals(ORDER_STATUS_PREPARE) && if (!order.getOrderStatus().equals(ORDER_STATUS_PREPARE) && legData.getStartTime() != null && LocalDate.parse(legData.getStartTime(), formatter).atStartOfDay().isBefore(startTime)) {
legData.getStartTime() != null &&
LocalDate.parse(legData.getStartTime(), formatter).atStartOfDay().isBefore(startTime)) {
throw new OrderException(LEG_TIME_ERROR); throw new OrderException(LEG_TIME_ERROR);
} }
if (!order.getOrderStatus().equals(ORDER_STATUS_PREPARE) && if (!order.getOrderStatus().equals(ORDER_STATUS_PREPARE) && legData.getEndTime() != null && LocalDate.parse(legData.getEndTime(), formatter).atStartOfDay().plusHours(23).plusMinutes(59).plusSeconds(59).isAfter(endTime.plusHours(23).plusMinutes(59).plusSeconds(59))) {
legData.getEndTime() != null &&
LocalDate.parse(legData.getEndTime(), formatter).atStartOfDay()
.plusHours(23).plusMinutes(59).plusSeconds(59).isAfter(endTime.plusHours(23).plusMinutes(59).plusSeconds(59))) {
throw new OrderException(LEG_TIME_ERROR); throw new OrderException(LEG_TIME_ERROR);
} }
} }

View File

@ -1,5 +1,5 @@
package com.chint.domain.value_object.enums; package com.chint.domain.value_object.enums;
public enum RoutePermission { public enum RoutePermission {
APPROVAL_BUTTON, LEG_NEED_APPROVAL, LEG_NEED_NOTIFY APPROVAL_BUTTON, LEG_NEED_APPROVAL, LEG_NEED_NOTIFY, LEG_NO_APPROVAL
} }