fix:修复可能导出部分临时行程规划单遗漏的问题

This commit is contained in:
lulz1 2024-06-28 20:52:04 +08:00
parent 60e244a919
commit 18a12df8bb
5 changed files with 62 additions and 77 deletions

View File

@ -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<SystemOrganizationExtension> systemOrganizationExtensionList;
@Transient
@ -94,10 +95,18 @@ public class SystemOrganization implements Serializable {
}
public String getApprovalPlatformMark() {
if (systemOrganizationExtensionList == null || systemOrganizationExtensionList.isEmpty()) {
return null;
return getExtensionValue("ApprovalPlatformMark");
}
return this.systemOrganizationExtensionList.stream().filter(it -> it.getFieldName().equals("ApprovalPlatformMark"))
public String getApprovalType() {
return getExtensionValue("ApprovalType");
}
private String getExtensionValue(String fieldName) {
if (systemOrganizationExtensionList == null || systemOrganizationExtensionList.isEmpty()) {
return "";
}
return this.systemOrganizationExtensionList.stream().filter(it -> it.getFieldName().equals(fieldName))
.map(SystemOrganizationExtension::getFieldValue)
.findFirst()
.orElse("");

View File

@ -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<SystemOrganization> systemOrganizationList);
@ -18,6 +20,7 @@ public interface SystemOrganizationRepository {
List<SystemOrganization> findByOrgLevelIsNull();
Optional<SystemOrganization> findByOrgCodeContaining(String orgCode);
Optional<SystemOrganization> findByOrgShortCode(String orgShortCode);
List<SystemOrganization> findByOrgCodeList(List<String> orgCode);
@ -29,5 +32,9 @@ public interface SystemOrganizationRepository {
Optional<SystemOrganization> findByOrgCodeContainingOrOrgNameContaining(String orgCode, String orgName);
Optional<SystemOrganization> findByOrgCode(String orgCode);
List<String> queryOrgCodeListByUserId(Long userId);
List<SystemOrganization> findByOrgCodeIn(Set<String> accountCompanyCodes);
}

View File

@ -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);
@ -180,28 +175,13 @@ public class LegEventHandler implements LegEventService {
// 保存提交审批所提供的资料
routeOrder.updateApprovalData(data);
RouterOrderExtensionField routerOrderExtensionField = routeOrder.getRouterOrderExtensionField();
if (routerOrderExtensionField != null && routerOrderExtensionField.getBelongDeptCode() != null) {
if (routerOrderExtensionField == null || routerOrderExtensionField.getBelongDeptCode() == null) {
return;
}
String belongDeptCode = routerOrderExtensionField.getBelongDeptCode();
systemOrganizationRepository.findByOrgCodeContaining(belongDeptCode)
.ifPresent(org -> {
Long currentParentId = org.getParentId();
List<SystemOrganization> 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
}
}
});
}
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<OrderDetail> byOrderNo = routeOrder.getOrderDetails()
.stream()
.filter(it -> it.getOrderNo().equals(data.getOutOrderNo()))
.findFirst();
Optional<OrderDetail> 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<OrderDetail> first = routeOrder.getOrderDetails()
.stream()
.filter(it -> it.getOrderNo().equals(detailOrderNo) && it.getRouteId() != null)
.findFirst();
if (
first.isPresent()
) {
Optional<OrderDetail> 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<Leg> list = routeOrder
.getLegItems()
.stream()
.filter(it -> !it.getLegType().equals(LEG_TYPE_OTHER))
.toList();
List<Leg> list = routeOrder.getLegItems().stream().filter(it -> !it.getLegType().equals(LEG_TYPE_OTHER)).toList();
List<RouteRequest> routeRequestList = routeOrder.getRouteRequestList();
if (routeRequestList != null && !routeRequestList.isEmpty()) {
routeRequestList.forEach(it -> {
List<Long> 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 {

View File

@ -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<SystemOrganization> findByOrgShortCode(String orgShortCode) {
return jdbcSystemOrganizationRepository.findByOrgShortCode(orgShortCode).stream().findFirst();
}
@Override
public List<SystemOrganization> findByOrgCodeList(List<String> orgCode) {
return jdbcSystemOrganizationRepository.findByOrgShortCodeIn(orgCode).stream()
@ -139,11 +142,23 @@ public class SystemOrganizationRepositoryImpl implements SystemOrganizationRepos
.findFirst();
}
@Override
public Optional<SystemOrganization> findByOrgCode(String orgCode) {
return jdbcSystemOrganizationRepository.findByOrgCode(orgCode).stream().findFirst();
}
@Override
public List<String> queryOrgCodeListByUserId(Long userId) {
return jdbcSystemOrganizationRepository.queryOrgCodeListByUserId(userId);
}
@Override
public List<SystemOrganization> findByOrgCodeIn(Set<String> accountCompanyCodes) {
return jdbcSystemOrganizationRepository.findByOrgCodeIn(accountCompanyCodes.stream().filter(Objects::nonNull).toList());
}
private void expandOrganizationRecursively(SystemOrganization org,
List<SystemOrganization> allOrganizations) {
if (org == null) {

View File

@ -12,6 +12,7 @@ import java.util.List;
public interface JdbcSystemOrganizationRepository extends CrudRepository<SystemOrganization, Long> {
List<SystemOrganization> findByOrgCodeContaining(String orgCode);
List<SystemOrganization> findByOrgCode(String orgCode);
List<SystemOrganization> findByOrgShortCode(String orgShortCode);
List<SystemOrganization> findByParentId(Long parentId);
List<SystemOrganization> findByOrgLevelIsNullOrOrgLevel(String orgLevel);
List<SystemOrganization> findByOrgShortCodeIn(Collection<String> orgCode);
@ -23,4 +24,6 @@ public interface JdbcSystemOrganizationRepository extends CrudRepository<SystemO
"and ru.user_id = :#{#userId}")
List<String> queryOrgCodeListByUserId(Long userId);
List<SystemOrganization> findByOrgName(String orgName);
List<SystemOrganization> findByOrgCodeIn(Collection<String> orgCode);
}