diff --git a/src/main/java/com/chint/domain/aggregates/approval/ApprovalLegAddAndChangeBatch.java b/src/main/java/com/chint/domain/aggregates/approval/ApprovalLegAddAndChangeBatch.java index c4ad5d3e..73bdc215 100644 --- a/src/main/java/com/chint/domain/aggregates/approval/ApprovalLegAddAndChangeBatch.java +++ b/src/main/java/com/chint/domain/aggregates/approval/ApprovalLegAddAndChangeBatch.java @@ -65,16 +65,23 @@ public class ApprovalLegAddAndChangeBatch extends ApprovalProcess { public void handlerApprovalResultBefore(ApprovalResultData data) { String approvalRecordNo = data.getApprovalRecordNo(); RouteOrder routeOrder = data.getRouteOrder(); - - routeOrder.getLegItems().stream() + List legs = routeOrder.getLegItems().stream() .filter(leg -> isLegApprovalPending(leg, approvalRecordNo)) - .forEach(leg -> handleLegApprovalResult(data, routeOrder, leg)); + .toList(); + for (Leg leg : legs) { + handleLegApprovalResult(data, routeOrder, leg); + } } + private boolean isLegApprovalPending(Leg leg, String approvalRecordNo) { + if (leg == null) { + return false; + } BaseEvent lastEvent = leg.getLastEvent(); return lastEvent.getEventType().equals(LEG_APPROVAL_STATUS_SUBMIT) && lastEvent.getExtension().equals(approvalRecordNo); } + private void handleLegApprovalResult(ApprovalResultData data, RouteOrder routeOrder, Leg leg) { if (data.getApprovalStatus().equals(ApprovalRecord.successApprovalStatus())) { leg.addEvent(LegApprovalEvent.success()); @@ -83,6 +90,7 @@ public class ApprovalLegAddAndChangeBatch extends ApprovalProcess { rollbackLegState(routeOrder, leg); } } + private void rollbackLegState(RouteOrder routeOrder, Leg leg) { leg.getLegApprovalEventList().stream() .filter(event -> event.getEventType().equals(LEG_APPROVAL_STATUS_PREPARE)) @@ -95,6 +103,7 @@ public class ApprovalLegAddAndChangeBatch extends ApprovalProcess { } }); } + private boolean isRollbackToOriginalLeg(LegApprovalEvent lastPrepareEvent) { return lastPrepareEvent.getExtension() == null || lastPrepareEvent.getExtension().isEmpty(); } diff --git a/src/main/java/com/chint/domain/aggregates/approval/ApprovalRecord.java b/src/main/java/com/chint/domain/aggregates/approval/ApprovalRecord.java index bceaac3e..813ea91d 100644 --- a/src/main/java/com/chint/domain/aggregates/approval/ApprovalRecord.java +++ b/src/main/java/com/chint/domain/aggregates/approval/ApprovalRecord.java @@ -10,6 +10,7 @@ import org.springframework.data.relational.core.mapping.Table; import java.io.Serial; import java.io.Serializable; import java.time.LocalDateTime; +import java.util.Objects; @Data @Table("approval_record") @@ -65,4 +66,17 @@ public class ApprovalRecord implements Serializable { public static Integer rejectApprovalStatus() { return -1; } + + public String approvalStatusName() { + if (Objects.equals(this.approvalStatus, prepareApprovalStatus())) { + return "待审批"; + } + if (Objects.equals(this.approvalStatus, successApprovalStatus())) { + return "已通过"; + } + if (Objects.equals(this.approvalStatus, rejectApprovalStatus())) { + return "已驳回"; + } + return "未知状态"; + } } diff --git a/src/main/java/com/chint/domain/aggregates/approval/ApprovalSubmit.java b/src/main/java/com/chint/domain/aggregates/approval/ApprovalSubmit.java index 0f1cef93..f2dbdd94 100644 --- a/src/main/java/com/chint/domain/aggregates/approval/ApprovalSubmit.java +++ b/src/main/java/com/chint/domain/aggregates/approval/ApprovalSubmit.java @@ -2,6 +2,7 @@ package com.chint.domain.aggregates.approval; import com.chint.domain.aggregates.approval.platform.ApprovalPlatform; import com.chint.domain.aggregates.order.RouteOrder; +import com.chint.domain.exceptions.CommandException; import com.chint.domain.repository.ApprovalRecordRepository; import com.chint.domain.repository.RouteRepository; import org.jetbrains.annotations.NotNull; @@ -12,7 +13,9 @@ import org.springframework.context.ApplicationListener; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; +import java.time.LocalDateTime; import java.util.Map; +import java.util.Objects; import java.util.Optional; import java.util.stream.Collectors; @@ -75,10 +78,16 @@ public class ApprovalSubmit implements ApplicationListener it.getApprovalRecordNo().equals(approvalData.getApprovalRecordNo())) + .findFirst() + .ifPresent(it -> approvalScheduleParam.setRemark(it.getApprovalReason())); List scheduleItemList = new ArrayList<>(); for (Pair legPair : approvalData.getChangeLegList()) { Leg newLeg = legPair.getFirst(); @@ -287,6 +292,7 @@ public class ApprovalPlatformAN implements ApprovalPlatform { public String applicant; public String applicantDate; public String applyNo; + public String remark; public List scheduleList; } } diff --git a/src/main/java/com/chint/domain/service/RouteApprovalDomainService.java b/src/main/java/com/chint/domain/service/RouteApprovalDomainService.java index 8f37b4ea..7464f0e0 100644 --- a/src/main/java/com/chint/domain/service/RouteApprovalDomainService.java +++ b/src/main/java/com/chint/domain/service/RouteApprovalDomainService.java @@ -132,25 +132,28 @@ public class RouteApprovalDomainService { public RouteOrder checkApprovalPermissions(RouteOrder routeOrder) { ApproveOrderNo approveOrderNo = routeOrder.getApproveOrderNo(); - String approvalType = systemOrganizationRepository.findByOrgCodeContainingOrOrgNameContaining(approveOrderNo.getAccountCompany(), - approveOrderNo.getAccountCompany()).map(SystemOrganization::getApprovalType).orElseGet( - () -> systemCodeRepository.findBySysCode(approveOrderNo.getSysCode()).getApprovalType()); - if(approvalType != null){ - routeOrder.setRoutePermissionSet( - permissionConfigRepository.findByPermissionName(approvalType) - .map(permissionConfig -> { - List permissions = permissionConfig.permissions(); - return permissions.stream() - .distinct() - .map(permission -> Enum.valueOf(RoutePermission.class, permission)) - .collect(Collectors.toSet()); - }).orElseGet(Set::of) - ); + String approvalType = findApprovalType(approveOrderNo); + if (approvalType != null) { + Set permissions = findRoutePermissions(approvalType); + routeOrder.setRoutePermissionSet(permissions); } else { routeOrder.setRoutePermissionSet(Collections.emptySet()); } return routeOrder; } + private String findApprovalType(ApproveOrderNo approveOrderNo) { + return systemOrganizationRepository.findByOrgCodeContainingOrOrgNameContaining(approveOrderNo.getAccountCompany(), approveOrderNo.getAccountCompany()) + .map(SystemOrganization::getApprovalType) + .orElseGet(() -> systemCodeRepository.findBySysCode(approveOrderNo.getSysCode()).getApprovalType()); + } + private Set findRoutePermissions(String approvalType) { + return permissionConfigRepository.findByPermissionName(approvalType) + .map(permissionConfig -> permissionConfig.permissions().stream() + .distinct() + .map(permission -> Enum.valueOf(RoutePermission.class, permission)) + .collect(Collectors.toSet())) + .orElseGet(Collections::emptySet); + } private String getApprovalPlatformMark(RouteOrder routeOrder) { diff --git a/src/test/java/com/chint/CTripTest.java b/src/test/java/com/chint/CTripTest.java index 45ae1f68..9f33db7f 100644 --- a/src/test/java/com/chint/CTripTest.java +++ b/src/test/java/com/chint/CTripTest.java @@ -250,7 +250,7 @@ public class CTripTest { @Test void search() { BaseContext.setCurrentUser(user); - SearchOrderResponse response = orderSearchRequest.searchOrderResponseByOrderId("32219551997"); + SearchOrderResponse response = orderSearchRequest.searchOrderResponseByOrderId("32952443950"); System.out.println(response); } diff --git a/src/test/java/com/chint/RouteApplicationTests.java b/src/test/java/com/chint/RouteApplicationTests.java index 5240eeda..4a3a56e2 100644 --- a/src/test/java/com/chint/RouteApplicationTests.java +++ b/src/test/java/com/chint/RouteApplicationTests.java @@ -313,7 +313,7 @@ class RouteApplicationTests { @Test void loginSign() { - String sfno = "011207001"; + String sfno = "221108016"; String syscode = "FSSC"; String billcode = "CLSQ240620004123"; String companycode = "正泰集团股份有限公司";