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 costCenter;
private String orgLevel; private String orgLevel;
private String lastModifiedDateTime; private String lastModifiedDateTime;
private String topOrgCode;
@MappedCollection(idColumn = "system_organization_id", keyColumn = "system_organization_key") @MappedCollection(idColumn = "system_organization_id", keyColumn = "system_organization_key")
private List<SystemOrganizationExtension> systemOrganizationExtensionList; private List<SystemOrganizationExtension> systemOrganizationExtensionList;
@Transient @Transient
@ -94,10 +95,18 @@ public class SystemOrganization implements Serializable {
} }
public String getApprovalPlatformMark() { public String getApprovalPlatformMark() {
return getExtensionValue("ApprovalPlatformMark");
}
public String getApprovalType() {
return getExtensionValue("ApprovalType");
}
private String getExtensionValue(String fieldName) {
if (systemOrganizationExtensionList == null || systemOrganizationExtensionList.isEmpty()) { 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) .map(SystemOrganizationExtension::getFieldValue)
.findFirst() .findFirst()
.orElse(""); .orElse("");

View File

@ -3,8 +3,10 @@ package com.chint.domain.repository;
import com.chint.domain.aggregates.system.SystemOrganization; import com.chint.domain.aggregates.system.SystemOrganization;
import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.Set;
public interface SystemOrganizationRepository { public interface SystemOrganizationRepository {
void saveAll(List<SystemOrganization> systemOrganizationList); void saveAll(List<SystemOrganization> systemOrganizationList);
@ -18,6 +20,7 @@ public interface SystemOrganizationRepository {
List<SystemOrganization> findByOrgLevelIsNull(); List<SystemOrganization> findByOrgLevelIsNull();
Optional<SystemOrganization> findByOrgCodeContaining(String orgCode); Optional<SystemOrganization> findByOrgCodeContaining(String orgCode);
Optional<SystemOrganization> findByOrgShortCode(String orgShortCode);
List<SystemOrganization> findByOrgCodeList(List<String> orgCode); List<SystemOrganization> findByOrgCodeList(List<String> orgCode);
@ -29,5 +32,9 @@ public interface SystemOrganizationRepository {
Optional<SystemOrganization> findByOrgCodeContainingOrOrgNameContaining(String orgCode, String orgName); Optional<SystemOrganization> findByOrgCodeContainingOrOrgNameContaining(String orgCode, String orgName);
Optional<SystemOrganization> findByOrgCode(String orgCode);
List<String> queryOrgCodeListByUserId(Long userId); 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 fakeOrderNo = data.getFakeOrderNo();
String sysCode = data.getSysCode(); String sysCode = data.getSysCode();
//先查看是否已保存到数据库再从redis获取如果没有的话再从数据库获取 //先查看是否已保存到数据库再从redis获取如果没有的话再从数据库获取
RouteOrder routeOrder = routeRepository. RouteOrder routeOrder = routeRepository.findByFakeOrderNoAndSysCode(data.getActualOrderNo(), sysCode);
findByFakeOrderNoAndSysCode(data.getActualOrderNo(), sysCode);
if (routeOrder == null) { if (routeOrder == null) {
routeOrder = routeRepository routeOrder = routeRepository.findByFakeOrderNoAndSysCode(fakeOrderNo, sysCode);
.findByFakeOrderNoAndSysCode(fakeOrderNo, sysCode);
} }
if (routeOrder == null) { if (routeOrder == null) {
routeOrder = routeRepository.findTempRouteOrderBySysCodeAndBillCode(sysCode, fakeOrderNo); routeOrder = routeRepository.findTempRouteOrderBySysCodeAndBillCode(sysCode, fakeOrderNo);
@ -145,14 +143,11 @@ public class LegEventHandler implements LegEventService {
} }
//保存提交审批所提供的资料 //保存提交审批所提供的资料
routeOrder.updateApprovalData(data);
updateApprovalData(data, routeOrder); updateApprovalData(data, routeOrder);
//这里order所有的leg触发approve事件 //这里order所有的leg触发approve事件
routeOrder.getLegItems().forEach(leg -> leg.getEventList().add( routeOrder.getLegItems().forEach(leg -> leg.getEventList().add(legEventFactory.creatLegEvent(command.getLegEventType())));
legEventFactory.creatLegEvent(command.getLegEventType())
));
//这里也为行程规划单触发审批中事件 //这里也为行程规划单触发审批中事件
ApprovalEvent approvalEvent = routeOrderFactory.createApprovalEvent(RouteConstant.APPROVAL_EVENT_ING); 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(); 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); routeOrder.updateApprovalData(data);
RouterOrderExtensionField routerOrderExtensionField = routeOrder.getRouterOrderExtensionField(); RouterOrderExtensionField routerOrderExtensionField = routeOrder.getRouterOrderExtensionField();
if (routerOrderExtensionField != null && routerOrderExtensionField.getBelongDeptCode() != null) { if (routerOrderExtensionField == null || routerOrderExtensionField.getBelongDeptCode() == null) {
String belongDeptCode = routerOrderExtensionField.getBelongDeptCode(); return;
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
}
}
});
} }
String belongDeptCode = routerOrderExtensionField.getBelongDeptCode();
systemOrganizationRepository
.findByOrgShortCode(belongDeptCode)
.ifPresent(org -> routerOrderExtensionField.setCompanyCode(org.getTopOrgCode()));
} }
@Transactional @Transactional
@ -231,18 +211,11 @@ public class LegEventHandler implements LegEventService {
} }
//这里order所有的leg触发sync事件 //这里order所有的leg触发sync事件
legItems.forEach(leg -> leg.getEventList().add( legItems.forEach(leg -> leg.getEventList().add(legEventFactory.creatLegEvent(command.getLegEventType())));
legEventFactory.creatLegEvent(command.getLegEventType())
));
//保存routeOrder的状态 //保存routeOrder的状态
routeRepository.save(routeOrder).reloadStatus(); routeRepository.save(routeOrder).reloadStatus();
routeOrder.setLegItems( routeOrder.setLegItems(legItems.stream().filter(leg -> !leg.getLegType().equals(LegConstant.LEG_TYPE_OTHER)).toList());
legItems
.stream()
.filter(leg -> !leg.getLegType().equals(LegConstant.LEG_TYPE_OTHER))
.toList()
);
if (!syncAdapter.of(supplierName).syncSupplierOrder(routeOrder)) { if (!syncAdapter.of(supplierName).syncSupplierOrder(routeOrder)) {
throw new CommandException("订单提交失败"); throw new CommandException("订单提交失败");
} }
@ -270,26 +243,17 @@ public class LegEventHandler implements LegEventService {
BaseContext.setCurrentUser(byUserEmployeeNo); BaseContext.setCurrentUser(byUserEmployeeNo);
OrderDetail orderDetail; OrderDetail orderDetail;
//首先查询到行程规划订单 从routOrder当中查询是否以及存在该订单 //首先查询到行程规划订单 从routOrder当中查询是否以及存在该订单
Optional<OrderDetail> byOrderNo = routeOrder.getOrderDetails() Optional<OrderDetail> byOrderNo = routeOrder.getOrderDetails().stream().filter(it -> it.getOrderNo().equals(data.getOutOrderNo())).findFirst();
.stream()
.filter(it -> it.getOrderNo().equals(data.getOutOrderNo()))
.findFirst();
if (byOrderNo.isEmpty()) { if (byOrderNo.isEmpty()) {
//否则创建新的订单添加到routeOrder //否则创建新的订单添加到routeOrder
orderDetail = orderDetailFactory.create(data) orderDetail = orderDetailFactory.create(data).employeeNo(routeOrder.getUserId());
.employeeNo(routeOrder.getUserId());
//结果多次测试 这里自主赋值routeId //结果多次测试 这里自主赋值routeId
orderDetail.setRouteId(routeOrder.getRouteId()); orderDetail.setRouteId(routeOrder.getRouteId());
routeOrder.addOrderDetail(orderDetail); routeOrder.addOrderDetail(orderDetail);
String detailOrderNo = orderDetail.getOrderNo(); String detailOrderNo = orderDetail.getOrderNo();
routeOrder = routeRepository.save(routeOrder); routeOrder = routeRepository.save(routeOrder);
Optional<OrderDetail> first = routeOrder.getOrderDetails() Optional<OrderDetail> first = routeOrder.getOrderDetails().stream().filter(it -> it.getOrderNo().equals(detailOrderNo) && it.getRouteId() != null).findFirst();
.stream() if (first.isPresent()) {
.filter(it -> it.getOrderNo().equals(detailOrderNo) && it.getRouteId() != null)
.findFirst();
if (
first.isPresent()
) {
orderDetail = first.get(); orderDetail = first.get();
orderDetail = routeOrder.matchOrderWithLeg(orderDetail, legDomainService); orderDetail = routeOrder.matchOrderWithLeg(orderDetail, legDomainService);
} }
@ -309,18 +273,12 @@ public class LegEventHandler implements LegEventService {
String orderStatus = orderDetail.getOrderStatus(); String orderStatus = orderDetail.getOrderStatus();
//只有在以下状态 才是下单状态 //只有在以下状态 才是下单状态
if (orderStatus.equals(ORDER_EVENT_ORDERED_NAME) || 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)) {
orderStatus.equals(ORDER_EVENT_PAYED_NAME) || LegEvent legEvent = legEventFactory.creatLegEvent(command.getLegEventType());
orderStatus.equals(ORDER_EVENT_CHANGE_NAME) ||
orderStatus.equals(ORDER_EVENT_FINISH_NAME)) {
LegEvent legEvent = legEventFactory
.creatLegEvent(command.getLegEventType());
leg.addEvent(legEvent); leg.addEvent(legEvent);
} else if (orderStatus.equals(ORDER_EVENT_REFUND_NAME) || } else if (orderStatus.equals(ORDER_EVENT_REFUND_NAME) || orderStatus.equals(ORDER_EVENT_CANCEL_NAME)) {
orderStatus.equals(ORDER_EVENT_CANCEL_NAME)) {
//如果是退款状态那么就创建加入未下单事件 //如果是退款状态那么就创建加入未下单事件
LegEvent legEvent = legEventFactory LegEvent legEvent = legEventFactory.creatLegEvent(LEG_EVENT_NOT_ORDERED);
.creatLegEvent(LEG_EVENT_NOT_ORDERED);
leg.addEvent(legEvent); leg.addEvent(legEvent);
} }
@ -357,21 +315,14 @@ public class LegEventHandler implements LegEventService {
if (routeOrder.getOrderStatus() >= RouteConstant.ORDER_STATUS_NOT_ORDERED) { if (routeOrder.getOrderStatus() >= RouteConstant.ORDER_STATUS_NOT_ORDERED) {
//这里查看routeOrder的状态 如果是已经同步过的订单 需要取消同步到供应商的订单 //这里查看routeOrder的状态 如果是已经同步过的订单 需要取消同步到供应商的订单
List<Leg> list = routeOrder List<Leg> list = routeOrder.getLegItems().stream().filter(it -> !it.getLegType().equals(LEG_TYPE_OTHER)).toList();
.getLegItems()
.stream()
.filter(it -> !it.getLegType().equals(LEG_TYPE_OTHER))
.toList();
List<RouteRequest> routeRequestList = routeOrder.getRouteRequestList(); List<RouteRequest> routeRequestList = routeOrder.getRouteRequestList();
if (routeRequestList != null && !routeRequestList.isEmpty()) { if (routeRequestList != null && !routeRequestList.isEmpty()) {
routeRequestList.forEach(it -> { routeRequestList.forEach(it -> {
List<Long> legIds = it.getRouteRequestLegList().stream().map(RouteRequestLeg::getLegId).toList(); List<Long> legIds = it.getRouteRequestLegList().stream().map(RouteRequestLeg::getLegId).toList();
it.reloadGenerateRequestLegs(routeOrder.getLegItems() it.reloadGenerateRequestLegs(routeOrder.getLegItems().stream().filter(leg -> legIds.contains(leg.getLegId())).toList());
.stream()
.filter(leg -> legIds.contains(leg.getLegId()))
.toList());
syncAdapter.of(it.getSupplier()).cancelRouteRequest(it); syncAdapter.of(it.getSupplier()).cancelRouteRequest(it);
}); });
} else { } 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.cache.CacheSystemOrganizationRepository;
import com.chint.infrastructure.repository.jdbc.JdbcSystemOrganizationRepository; import com.chint.infrastructure.repository.jdbc.JdbcSystemOrganizationRepository;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.util.ArrayList; import java.util.*;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Stream; import java.util.stream.Stream;
@Repository @Repository
@ -80,6 +78,11 @@ public class SystemOrganizationRepositoryImpl implements SystemOrganizationRepos
.findFirst(); .findFirst();
} }
@Override
public Optional<SystemOrganization> findByOrgShortCode(String orgShortCode) {
return jdbcSystemOrganizationRepository.findByOrgShortCode(orgShortCode).stream().findFirst();
}
@Override @Override
public List<SystemOrganization> findByOrgCodeList(List<String> orgCode) { public List<SystemOrganization> findByOrgCodeList(List<String> orgCode) {
return jdbcSystemOrganizationRepository.findByOrgShortCodeIn(orgCode).stream() return jdbcSystemOrganizationRepository.findByOrgShortCodeIn(orgCode).stream()
@ -139,11 +142,23 @@ public class SystemOrganizationRepositoryImpl implements SystemOrganizationRepos
.findFirst(); .findFirst();
} }
@Override
public Optional<SystemOrganization> findByOrgCode(String orgCode) {
return jdbcSystemOrganizationRepository.findByOrgCode(orgCode).stream().findFirst();
}
@Override @Override
public List<String> queryOrgCodeListByUserId(Long userId) { public List<String> queryOrgCodeListByUserId(Long userId) {
return jdbcSystemOrganizationRepository.queryOrgCodeListByUserId(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, private void expandOrganizationRecursively(SystemOrganization org,
List<SystemOrganization> allOrganizations) { List<SystemOrganization> allOrganizations) {
if (org == null) { if (org == null) {

View File

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