From 18a12df8bbad1b226e2a325110a2c6d9e8e5efae Mon Sep 17 00:00:00 2001 From: lulz1 Date: Fri, 28 Jun 2024 20:52:04 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=BF=AE=E5=A4=8D=E5=8F=AF=E8=83=BD?= =?UTF-8?q?=E5=AF=BC=E5=87=BA=E9=83=A8=E5=88=86=E4=B8=B4=E6=97=B6=E8=A1=8C?= =?UTF-8?q?=E7=A8=8B=E8=A7=84=E5=88=92=E5=8D=95=E9=81=97=E6=BC=8F=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../aggregates/system/SystemOrganization.java | 13 ++- .../SystemOrganizationRepository.java | 7 ++ .../service/leg_event/LegEventHandler.java | 93 +++++-------------- .../SystemOrganizationRepositoryImpl.java | 23 ++++- .../JdbcSystemOrganizationRepository.java | 3 + 5 files changed, 62 insertions(+), 77 deletions(-) diff --git a/src/main/java/com/chint/domain/aggregates/system/SystemOrganization.java b/src/main/java/com/chint/domain/aggregates/system/SystemOrganization.java index ed833cd9..89bd504c 100644 --- a/src/main/java/com/chint/domain/aggregates/system/SystemOrganization.java +++ b/src/main/java/com/chint/domain/aggregates/system/SystemOrganization.java @@ -38,6 +38,7 @@ public class SystemOrganization implements Serializable { private String costCenter; private String orgLevel; private String lastModifiedDateTime; + private String topOrgCode; @MappedCollection(idColumn = "system_organization_id", keyColumn = "system_organization_key") private List systemOrganizationExtensionList; @Transient @@ -94,10 +95,18 @@ public class SystemOrganization implements Serializable { } public String getApprovalPlatformMark() { + return getExtensionValue("ApprovalPlatformMark"); + } + + public String getApprovalType() { + return getExtensionValue("ApprovalType"); + } + + private String getExtensionValue(String fieldName) { if (systemOrganizationExtensionList == null || systemOrganizationExtensionList.isEmpty()) { - return null; + return ""; } - return this.systemOrganizationExtensionList.stream().filter(it -> it.getFieldName().equals("ApprovalPlatformMark")) + return this.systemOrganizationExtensionList.stream().filter(it -> it.getFieldName().equals(fieldName)) .map(SystemOrganizationExtension::getFieldValue) .findFirst() .orElse(""); diff --git a/src/main/java/com/chint/domain/repository/SystemOrganizationRepository.java b/src/main/java/com/chint/domain/repository/SystemOrganizationRepository.java index 5047f8c1..31f2198e 100644 --- a/src/main/java/com/chint/domain/repository/SystemOrganizationRepository.java +++ b/src/main/java/com/chint/domain/repository/SystemOrganizationRepository.java @@ -3,8 +3,10 @@ package com.chint.domain.repository; import com.chint.domain.aggregates.system.SystemOrganization; +import java.util.Collection; import java.util.List; import java.util.Optional; +import java.util.Set; public interface SystemOrganizationRepository { void saveAll(List systemOrganizationList); @@ -18,6 +20,7 @@ public interface SystemOrganizationRepository { List findByOrgLevelIsNull(); Optional findByOrgCodeContaining(String orgCode); + Optional findByOrgShortCode(String orgShortCode); List findByOrgCodeList(List orgCode); @@ -29,5 +32,9 @@ public interface SystemOrganizationRepository { Optional findByOrgCodeContainingOrOrgNameContaining(String orgCode, String orgName); + Optional findByOrgCode(String orgCode); + List queryOrgCodeListByUserId(Long userId); + + List findByOrgCodeIn(Set accountCompanyCodes); } 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 43c67155..580f2628 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 @@ -124,11 +124,9 @@ public class LegEventHandler implements LegEventService { String fakeOrderNo = data.getFakeOrderNo(); String sysCode = data.getSysCode(); //先查看是否已保存到数据库,再从redis获取,如果没有的话再从数据库获取 - RouteOrder routeOrder = routeRepository. - findByFakeOrderNoAndSysCode(data.getActualOrderNo(), sysCode); + RouteOrder routeOrder = routeRepository.findByFakeOrderNoAndSysCode(data.getActualOrderNo(), sysCode); if (routeOrder == null) { - routeOrder = routeRepository - .findByFakeOrderNoAndSysCode(fakeOrderNo, sysCode); + routeOrder = routeRepository.findByFakeOrderNoAndSysCode(fakeOrderNo, sysCode); } if (routeOrder == null) { routeOrder = routeRepository.findTempRouteOrderBySysCodeAndBillCode(sysCode, fakeOrderNo); @@ -145,14 +143,11 @@ public class LegEventHandler implements LegEventService { } //保存提交审批所提供的资料 - routeOrder.updateApprovalData(data); updateApprovalData(data, routeOrder); //这里order所有的leg触发approve事件 - routeOrder.getLegItems().forEach(leg -> leg.getEventList().add( - legEventFactory.creatLegEvent(command.getLegEventType()) - )); + routeOrder.getLegItems().forEach(leg -> leg.getEventList().add(legEventFactory.creatLegEvent(command.getLegEventType()))); //这里也为行程规划单触发审批中事件 ApprovalEvent approvalEvent = routeOrderFactory.createApprovalEvent(RouteConstant.APPROVAL_EVENT_ING); @@ -176,32 +171,17 @@ public class LegEventHandler implements LegEventService { Command.of(RouteAutoSyncCommand.class).route(save).async().sendToQueue(); } - public void updateApprovalData(ApproveRouteData data,RouteOrder routeOrder) { + 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(org.getOrgShortCode()); - break; - } else { - currentParentId = organization.getParentId(); - } - } else { - break; // Parent organization not found - } - } - }); + if (routerOrderExtensionField == null || routerOrderExtensionField.getBelongDeptCode() == null) { + return; } + String belongDeptCode = routerOrderExtensionField.getBelongDeptCode(); + systemOrganizationRepository + .findByOrgShortCode(belongDeptCode) + .ifPresent(org -> routerOrderExtensionField.setCompanyCode(org.getTopOrgCode())); } @Transactional @@ -231,18 +211,11 @@ public class LegEventHandler implements LegEventService { } //这里order所有的leg触发sync事件 - legItems.forEach(leg -> leg.getEventList().add( - legEventFactory.creatLegEvent(command.getLegEventType()) - )); + legItems.forEach(leg -> leg.getEventList().add(legEventFactory.creatLegEvent(command.getLegEventType()))); //保存routeOrder的状态 routeRepository.save(routeOrder).reloadStatus(); - routeOrder.setLegItems( - legItems - .stream() - .filter(leg -> !leg.getLegType().equals(LegConstant.LEG_TYPE_OTHER)) - .toList() - ); + routeOrder.setLegItems(legItems.stream().filter(leg -> !leg.getLegType().equals(LegConstant.LEG_TYPE_OTHER)).toList()); if (!syncAdapter.of(supplierName).syncSupplierOrder(routeOrder)) { throw new CommandException("订单提交失败"); } @@ -270,26 +243,17 @@ public class LegEventHandler implements LegEventService { BaseContext.setCurrentUser(byUserEmployeeNo); OrderDetail orderDetail; //首先查询到行程规划订单 , 从routOrder当中查询是否以及存在该订单 - Optional byOrderNo = routeOrder.getOrderDetails() - .stream() - .filter(it -> it.getOrderNo().equals(data.getOutOrderNo())) - .findFirst(); + Optional byOrderNo = routeOrder.getOrderDetails().stream().filter(it -> it.getOrderNo().equals(data.getOutOrderNo())).findFirst(); if (byOrderNo.isEmpty()) { //否则创建新的订单添加到routeOrder - orderDetail = orderDetailFactory.create(data) - .employeeNo(routeOrder.getUserId()); + orderDetail = orderDetailFactory.create(data).employeeNo(routeOrder.getUserId()); //结果多次测试, 这里自主赋值routeId orderDetail.setRouteId(routeOrder.getRouteId()); routeOrder.addOrderDetail(orderDetail); String detailOrderNo = orderDetail.getOrderNo(); routeOrder = routeRepository.save(routeOrder); - Optional first = routeOrder.getOrderDetails() - .stream() - .filter(it -> it.getOrderNo().equals(detailOrderNo) && it.getRouteId() != null) - .findFirst(); - if ( - first.isPresent() - ) { + Optional first = routeOrder.getOrderDetails().stream().filter(it -> it.getOrderNo().equals(detailOrderNo) && it.getRouteId() != null).findFirst(); + if (first.isPresent()) { orderDetail = first.get(); orderDetail = routeOrder.matchOrderWithLeg(orderDetail, legDomainService); } @@ -309,18 +273,12 @@ public class LegEventHandler implements LegEventService { String orderStatus = orderDetail.getOrderStatus(); //只有在以下状态 ,才是下单状态 - if (orderStatus.equals(ORDER_EVENT_ORDERED_NAME) || - orderStatus.equals(ORDER_EVENT_PAYED_NAME) || - orderStatus.equals(ORDER_EVENT_CHANGE_NAME) || - orderStatus.equals(ORDER_EVENT_FINISH_NAME)) { - LegEvent legEvent = legEventFactory - .creatLegEvent(command.getLegEventType()); + if (orderStatus.equals(ORDER_EVENT_ORDERED_NAME) || orderStatus.equals(ORDER_EVENT_PAYED_NAME) || orderStatus.equals(ORDER_EVENT_CHANGE_NAME) || orderStatus.equals(ORDER_EVENT_FINISH_NAME)) { + LegEvent legEvent = legEventFactory.creatLegEvent(command.getLegEventType()); leg.addEvent(legEvent); - } else if (orderStatus.equals(ORDER_EVENT_REFUND_NAME) || - orderStatus.equals(ORDER_EVENT_CANCEL_NAME)) { + } else if (orderStatus.equals(ORDER_EVENT_REFUND_NAME) || orderStatus.equals(ORDER_EVENT_CANCEL_NAME)) { //如果是退款状态,那么就创建加入未下单事件 - LegEvent legEvent = legEventFactory - .creatLegEvent(LEG_EVENT_NOT_ORDERED); + LegEvent legEvent = legEventFactory.creatLegEvent(LEG_EVENT_NOT_ORDERED); leg.addEvent(legEvent); } @@ -357,21 +315,14 @@ public class LegEventHandler implements LegEventService { if (routeOrder.getOrderStatus() >= RouteConstant.ORDER_STATUS_NOT_ORDERED) { //这里查看routeOrder的状态 , 如果是已经同步过的订单, 需要取消同步到供应商的订单 - List list = routeOrder - .getLegItems() - .stream() - .filter(it -> !it.getLegType().equals(LEG_TYPE_OTHER)) - .toList(); + List list = routeOrder.getLegItems().stream().filter(it -> !it.getLegType().equals(LEG_TYPE_OTHER)).toList(); List routeRequestList = routeOrder.getRouteRequestList(); if (routeRequestList != null && !routeRequestList.isEmpty()) { routeRequestList.forEach(it -> { List legIds = it.getRouteRequestLegList().stream().map(RouteRequestLeg::getLegId).toList(); - it.reloadGenerateRequestLegs(routeOrder.getLegItems() - .stream() - .filter(leg -> legIds.contains(leg.getLegId())) - .toList()); + it.reloadGenerateRequestLegs(routeOrder.getLegItems().stream().filter(leg -> legIds.contains(leg.getLegId())).toList()); syncAdapter.of(it.getSupplier()).cancelRouteRequest(it); }); } else { diff --git a/src/main/java/com/chint/infrastructure/repository/SystemOrganizationRepositoryImpl.java b/src/main/java/com/chint/infrastructure/repository/SystemOrganizationRepositoryImpl.java index f6a701ce..6b1e4b00 100644 --- a/src/main/java/com/chint/infrastructure/repository/SystemOrganizationRepositoryImpl.java +++ b/src/main/java/com/chint/infrastructure/repository/SystemOrganizationRepositoryImpl.java @@ -5,12 +5,10 @@ import com.chint.domain.repository.SystemOrganizationRepository; import com.chint.infrastructure.repository.cache.CacheSystemOrganizationRepository; import com.chint.infrastructure.repository.jdbc.JdbcSystemOrganizationRepository; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cache.annotation.Cacheable; import org.springframework.stereotype.Repository; -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; -import java.util.Optional; +import java.util.*; import java.util.stream.Stream; @Repository @@ -80,6 +78,11 @@ public class SystemOrganizationRepositoryImpl implements SystemOrganizationRepos .findFirst(); } + @Override + public Optional findByOrgShortCode(String orgShortCode) { + return jdbcSystemOrganizationRepository.findByOrgShortCode(orgShortCode).stream().findFirst(); + } + @Override public List findByOrgCodeList(List orgCode) { return jdbcSystemOrganizationRepository.findByOrgShortCodeIn(orgCode).stream() @@ -139,11 +142,23 @@ public class SystemOrganizationRepositoryImpl implements SystemOrganizationRepos .findFirst(); } + + @Override + public Optional findByOrgCode(String orgCode) { + return jdbcSystemOrganizationRepository.findByOrgCode(orgCode).stream().findFirst(); + } + @Override public List queryOrgCodeListByUserId(Long userId) { return jdbcSystemOrganizationRepository.queryOrgCodeListByUserId(userId); } + + @Override + public List findByOrgCodeIn(Set accountCompanyCodes) { + return jdbcSystemOrganizationRepository.findByOrgCodeIn(accountCompanyCodes.stream().filter(Objects::nonNull).toList()); + } + private void expandOrganizationRecursively(SystemOrganization org, List allOrganizations) { if (org == null) { diff --git a/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcSystemOrganizationRepository.java b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcSystemOrganizationRepository.java index b899ff8d..dae3c918 100644 --- a/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcSystemOrganizationRepository.java +++ b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcSystemOrganizationRepository.java @@ -12,6 +12,7 @@ import java.util.List; public interface JdbcSystemOrganizationRepository extends CrudRepository { List findByOrgCodeContaining(String orgCode); List findByOrgCode(String orgCode); + List findByOrgShortCode(String orgShortCode); List findByParentId(Long parentId); List findByOrgLevelIsNullOrOrgLevel(String orgLevel); List findByOrgShortCodeIn(Collection orgCode); @@ -23,4 +24,6 @@ public interface JdbcSystemOrganizationRepository extends CrudRepository queryOrgCodeListByUserId(Long userId); List findByOrgName(String orgName); + + List findByOrgCodeIn(Collection orgCode); }