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

View File

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