From 3a2974804b2e6fe5f3f4a93d6c7489e114e014a7 Mon Sep 17 00:00:00 2001 From: lulz1 Date: Fri, 12 Jul 2024 13:18:55 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E5=A2=9E=E5=8A=A0=E8=A1=8C=E7=A8=8B?= =?UTF-8?q?=E6=97=A0=E9=9C=80=E5=AE=A1=E6=89=B9=E7=9A=84=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../services/OrderApplicationService.java | 78 ++++++------------- .../value_object/enums/RoutePermission.java | 2 +- 2 files changed, 23 insertions(+), 57 deletions(-) diff --git a/src/main/java/com/chint/application/services/OrderApplicationService.java b/src/main/java/com/chint/application/services/OrderApplicationService.java index 8c2c5361..81644ad8 100644 --- a/src/main/java/com/chint/application/services/OrderApplicationService.java +++ b/src/main/java/com/chint/application/services/OrderApplicationService.java @@ -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 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); } } diff --git a/src/main/java/com/chint/domain/value_object/enums/RoutePermission.java b/src/main/java/com/chint/domain/value_object/enums/RoutePermission.java index 5188c382..4c01b34c 100644 --- a/src/main/java/com/chint/domain/value_object/enums/RoutePermission.java +++ b/src/main/java/com/chint/domain/value_object/enums/RoutePermission.java @@ -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 }