diff --git a/src/main/java/com/chint/domain/service/leg_event/LegEventHandler.java b/src/main/java/com/chint/domain/service/leg_event/LegEventHandler.java index d05a9a47..317f6b54 100644 --- a/src/main/java/com/chint/domain/service/leg_event/LegEventHandler.java +++ b/src/main/java/com/chint/domain/service/leg_event/LegEventHandler.java @@ -3,6 +3,7 @@ package com.chint.domain.service.leg_event; import com.chint.application.commands.*; import com.chint.domain.aggregates.order.*; import com.chint.domain.aggregates.system.SystemCode; +import com.chint.domain.aggregates.system.SystemOrganization; import com.chint.domain.aggregates.user.User; import com.chint.domain.exceptions.CommandException; import com.chint.domain.exceptions.LegEventException; @@ -135,7 +136,7 @@ public class LegEventHandler implements LegEventService { routeOrder.reloadStatus(); //如果是已经提交审批了,就直接退出 - if(routeOrder.getApproveOrderNo().getActualOrderNo() != null){ + if (routeOrder.getApproveOrderNo().getActualOrderNo() != null) { return; } @@ -145,6 +146,8 @@ public class LegEventHandler implements LegEventService { //保存提交审批所提供的资料 routeOrder.updateApprovalData(data); + updateApprovalData(data, routeOrder); + //这里order所有的leg触发approve事件 routeOrder.getLegItems().forEach(leg -> leg.getEventList().add( @@ -173,6 +176,34 @@ public class LegEventHandler implements LegEventService { Command.of(RouteAutoSyncCommand.class).route(save).async().sendToQueue(); } + public void updateApprovalData(ApproveRouteData data,RouteOrder routeOrder) { + // 保存提交审批所提供的资料 + routeOrder.updateApprovalData(data); + RouterOrderExtensionField routerOrderExtensionField = routeOrder.getRouterOrderExtensionField(); + if (routerOrderExtensionField != null && routerOrderExtensionField.getBelongDeptCode() != null) { + String belongDeptCode = routerOrderExtensionField.getBelongDeptCode(); + systemOrganizationRepository.findByOrgCodeContaining(belongDeptCode) + .ifPresent(org -> { + Long currentParentId = org.getParentId(); + List parentOrganizations; + while (currentParentId != null) { + parentOrganizations = systemOrganizationRepository.findByIdIn(List.of(currentParentId)); + if (!parentOrganizations.isEmpty()) { + SystemOrganization organization = parentOrganizations.get(0); + if (organization.getOrgLevel() == null || organization.getOrgLevel().isEmpty()) { + routerOrderExtensionField.setCompanyCode(organization.getOrgShortCode()); + break; + } else { + currentParentId = organization.getParentId(); + } + } else { + break; // Parent organization not found + } + } + }); + } + } + @Transactional @Override public void syncLeg(LegSyncCommand command) {