fix:审批功能重构-安能添加行程和变更行程-细节问题修复

This commit is contained in:
lulz1 2024-07-02 17:10:26 +08:00
parent 2ba217d23d
commit 61dbc769c8
7 changed files with 61 additions and 20 deletions

View File

@ -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<Leg> 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();
}

View File

@ -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 "未知状态";
}
}

View File

@ -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<ApplicationReadyEvent
}
private void processHandleApprovalResult(ApprovalResultData data, RouteOrder routeOrder, ApprovalRecord approvalRecord) {
if (!approvalRecord.getApprovalStatus().equals(ApprovalRecord.prepareApprovalStatus())) {
throw new CommandException("该审批单已审批完毕,结果为" + approvalRecord.approvalStatusName());
}
ApprovalProcess approvalProcess = of(ApprovalType.valueOf(approvalRecord.getApprovalType()),
approvalRecord.getApprovalPlatformMark());
approvalProcess.handlerApprovalResult(data);
approvalRecord.setApprovalStatus(data.getApprovalStatus());
approvalRecord.setApprovalStatus(Objects.equals(data.getApprovalStatus(), ApprovalRecord.successApprovalStatus()) ?
ApprovalRecord.successApprovalStatus() :
ApprovalRecord.rejectApprovalStatus());
approvalRecord.setApprovalResponseDate(LocalDateTime.now());
routeRepository.save(routeOrder);
}
}

View File

@ -112,6 +112,11 @@ public class ApprovalPlatformAN implements ApprovalPlatform {
approvalScheduleParam.setApplicant(routeOrder.getUserId());
approvalScheduleParam.setApplicantDate(DateTimeUtil.timeToStr(LocalDateTime.now()));
approvalScheduleParam.setApplyNo(approveOrderNo.getActualOrderNo());
routeOrder.getApprovalRecordList()
.stream()
.filter(it -> it.getApprovalRecordNo().equals(approvalData.getApprovalRecordNo()))
.findFirst()
.ifPresent(it -> approvalScheduleParam.setRemark(it.getApprovalReason()));
List<ScheduleItem> scheduleItemList = new ArrayList<>();
for (Pair<Leg, Leg> 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<ScheduleItem> scheduleList;
}
}

View File

@ -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());
String approvalType = findApprovalType(approveOrderNo);
if (approvalType != null) {
routeOrder.setRoutePermissionSet(
permissionConfigRepository.findByPermissionName(approvalType)
.map(permissionConfig -> {
List<String> permissions = permissionConfig.permissions();
return permissions.stream()
.distinct()
.map(permission -> Enum.valueOf(RoutePermission.class, permission))
.collect(Collectors.toSet());
}).orElseGet(Set::of)
);
Set<RoutePermission> 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<RoutePermission> 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) {

View File

@ -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);
}

View File

@ -313,7 +313,7 @@ class RouteApplicationTests {
@Test
void loginSign() {
String sfno = "011207001";
String sfno = "221108016";
String syscode = "FSSC";
String billcode = "CLSQ240620004123";
String companycode = "正泰集团股份有限公司";