fix:分页排序将已结束的订单放到最后,修复未提交审批的订单查询问题

This commit is contained in:
lulz1 2024-04-20 20:38:52 +08:00
parent 934ef23eaf
commit ab4dfe60be
9 changed files with 38 additions and 45 deletions

View File

@ -152,7 +152,7 @@ public class OrderQuery {
.skip((long) (pageNum - 1) * pageSize) .skip((long) (pageNum - 1) * pageSize)
.limit(pageSize) .limit(pageSize)
.map(routeOrder -> { .map(routeOrder -> {
orderDomainService.queryLocation(routeOrder.getLegItems()); legDomainService.queryLocation(routeOrder.getLegItems());
User user = userRepository.findByUserEmployeeNo(routeOrder.getUserId()); User user = userRepository.findByUserEmployeeNo(routeOrder.getUserId());
return getRouteOrderPageRes(routeOrder, user); return getRouteOrderPageRes(routeOrder, user);
}) })
@ -318,7 +318,7 @@ public class OrderQuery {
public RouteOrder queryById(Long routeId) { public RouteOrder queryById(Long routeId) {
RouteOrder routeOrder = routeRepository.queryById(routeId); RouteOrder routeOrder = routeRepository.queryById(routeId);
if (routeOrder.getLegItems() != null && routeOrder.getLegItems().isEmpty()) { if (routeOrder.getLegItems() != null && routeOrder.getLegItems().isEmpty()) {
orderDomainService.queryLocation(routeOrder.getLegItems()); legDomainService.queryLocation(routeOrder.getLegItems());
} }
return routeOrder; return routeOrder;
} }
@ -356,7 +356,7 @@ public class OrderQuery {
userRepository.findByUserEmployeeNo(routeOrder.getUserId()) userRepository.findByUserEmployeeNo(routeOrder.getUserId())
); );
List<Leg> legItems = List<Leg> legItems =
orderDomainService.queryLocation(routeOrder.getLegItems()); legDomainService.queryLocation(routeOrder.getLegItems());
legItems.forEach(leg -> { legItems.forEach(leg -> {
@ -523,7 +523,7 @@ public class OrderQuery {
if (legItems != null && !legItems.isEmpty()) { if (legItems != null && !legItems.isEmpty()) {
//这里使用领域事件进行检查leg的订单状态 用户每次想要查看行程都会进行一次检查 //这里使用领域事件进行检查leg的订单状态 用户每次想要查看行程都会进行一次检查
legItems.forEach(leg -> legDomainService.legCheckOrder(leg)); legItems.forEach(leg -> legDomainService.legCheckOrder(leg));
orderDomainService.queryLocation(legItems); legDomainService.queryLocation(legItems);
List<LegRes> list = legItems.stream().map(LegRes::copyFrom).toList(); List<LegRes> list = legItems.stream().map(LegRes::copyFrom).toList();
routeOrderRes.setLegResList(list); routeOrderRes.setLegResList(list);
List<OrderDetailRes> orderDetailResList = routeOrder List<OrderDetailRes> orderDetailResList = routeOrder
@ -548,7 +548,7 @@ public class OrderQuery {
List<RouteOrder> routeOrders = routeRepository.findAllByEmployeeNo(currentUser.getEmployeeNo()); List<RouteOrder> routeOrders = routeRepository.findAllByEmployeeNo(currentUser.getEmployeeNo());
routeOrders = routeOrders.stream().filter(it -> it.getUserId().equals(currentUser.getEmployeeNo())).toList(); routeOrders = routeOrders.stream().filter(it -> it.getUserId().equals(currentUser.getEmployeeNo())).toList();
routeOrders.forEach(route -> { routeOrders.forEach(route -> {
orderDomainService.queryLocation(route.getLegItems()); legDomainService.queryLocation(route.getLegItems());
orderDomainService.checkRouteOrderStatus(route); orderDomainService.checkRouteOrderStatus(route);
}); });
Stream<RouteOrder> stream = routeOrders.stream(); Stream<RouteOrder> stream = routeOrders.stream();

View File

@ -93,7 +93,7 @@ public class OrderApplicationService {
checkLegDataTime(addLegData, order); checkLegDataTime(addLegData, order);
LegData legData = addLegData.getLegData(); LegData legData = addLegData.getLegData();
List<Leg> legs = processLegData(legData, order); List<Leg> legs = processLegData(legData, order);
orderDomainService.queryLocation(legs); legDomainService.queryLocation(legs);
RouteOrder routeOrder = orderDomainService.saveOrder(order); RouteOrder routeOrder = orderDomainService.saveOrder(order);
legs.forEach(leg -> { legs.forEach(leg -> {
leg.reloadStatus(); leg.reloadStatus();
@ -166,7 +166,7 @@ public class OrderApplicationService {
} }
} }
orderDomainService.queryLocation(List.of(oldLeg, leg)); legDomainService.queryLocation(List.of(oldLeg, leg));
//保存变更事件理由 //保存变更事件理由
leg = legDomainService.addChangeEvent(leg, legData.getChangeReason()); leg = legDomainService.addChangeEvent(leg, legData.getChangeReason());

View File

@ -3,6 +3,7 @@ package com.chint.domain.aggregates.order;
import com.chint.application.commands.LegOrderedCommand; import com.chint.application.commands.LegOrderedCommand;
import com.chint.domain.factoriy.leg.LegFactory; import com.chint.domain.factoriy.leg.LegFactory;
import com.chint.domain.service.LegDomainService;
import com.chint.domain.service.OrderDomainService; import com.chint.domain.service.OrderDomainService;
import com.chint.domain.service.amount_estimate.EstimateAdapter; import com.chint.domain.service.amount_estimate.EstimateAdapter;
import com.chint.domain.service.supplier.SupplierConstantUtil; import com.chint.domain.service.supplier.SupplierConstantUtil;
@ -456,12 +457,12 @@ public class RouteOrder implements Serializable {
return this; return this;
} }
public OrderDetail matchOrderWithLeg(OrderDetail orderDetail, OrderDomainService orderDomainService) { public OrderDetail matchOrderWithLeg(OrderDetail orderDetail, LegDomainService legDomainService) {
if (this.legItems.isEmpty()) { if (this.legItems.isEmpty()) {
return orderDetail; return orderDetail;
} }
orderDomainService.queryLocation(this.legItems); legDomainService.queryLocation(this.legItems);
// 定义时间容差例如1天 // 定义时间容差例如1天
long tolerance = Duration.ofDays(2).toMillis(); long tolerance = Duration.ofDays(2).toMillis();

View File

@ -8,8 +8,7 @@ import com.chint.domain.repository.*;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.ArrayList; import java.util.*;
import java.util.List;
import static com.chint.infrastructure.constant.CommonMessageConstant.LEG_CHANGE_MAX_ERROR; import static com.chint.infrastructure.constant.CommonMessageConstant.LEG_CHANGE_MAX_ERROR;
import static com.chint.infrastructure.constant.LegConstant.*; import static com.chint.infrastructure.constant.LegConstant.*;
@ -129,21 +128,24 @@ public class LegDomainService {
public List<Leg> queryLocation(List<Leg> list) { public List<Leg> queryLocation(List<Leg> list) {
list.forEach(leg -> { list.forEach(leg -> {
LegExtensionField legExtensionField = leg.getLegExtensionField(); LegExtensionField legExtensionField = leg.getLegExtensionField();
if (legExtensionField != null && legExtensionField.getLocationIds() != null) { if (legExtensionField != null && legExtensionField.getLocationIds() != null ) {
List<Long> locationIdsAsLong; List<Long> locationIdsAsLong;
if (legExtensionField.getLocationIds().startsWith("[")) { if (legExtensionField.getLocationIds().startsWith("[")) {
locationIdsAsLong = legExtensionField.getLocationIdsAsLongFromArray(); locationIdsAsLong = legExtensionField.getLocationIdsAsLongFromArray();
} else { } else {
locationIdsAsLong = legExtensionField.getLocationIdsAsLong(); locationIdsAsLong = legExtensionField.getLocationIdsAsLong();
} }
List<Location> byNameList = locationRepository.findByNameList(locationIdsAsLong); List<Location> locationList = legExtensionField.getLocationList();
legExtensionField.setLocationList(byNameList); if (locationList == null || locationList.size() != locationIdsAsLong.size()) {
List<Location> byNameList = locationRepository.findByNameList(locationIdsAsLong);
legExtensionField.setLocationList(byNameList);
}
} }
if (leg.getOriginId() != null) { if (leg.getOriginId() != null && leg.getOriginLocation() == null) {
leg.setOriginLocation(locationRepository.findByLocationId(leg.getOriginId())); leg.setOriginLocation(locationRepository.findByLocationId(leg.getOriginId()));
} }
if (leg.getDestinationId() != null) { if (leg.getDestinationId() != null && leg.getDestinationLocation() == null) {
leg.setDestinationLocation(locationRepository.findByLocationId(leg.getDestinationId())); leg.setDestinationLocation(locationRepository.findByLocationId(leg.getDestinationId()));
} }
}); });

View File

@ -129,31 +129,6 @@ public class OrderDomainService {
} }
} }
public List<Leg> queryLocation(List<Leg> list) {
list.forEach(leg -> {
LegExtensionField legExtensionField = leg.getLegExtensionField();
if (legExtensionField != null && legExtensionField.getLocationIds() != null) {
List<Long> locationIdsAsLong;
if (legExtensionField.getLocationIds().startsWith("[")) {
locationIdsAsLong = legExtensionField.getLocationIdsAsLongFromArray();
} else {
locationIdsAsLong = legExtensionField.getLocationIdsAsLong();
}
List<Location> byNameList = locationRepository.findByNameList(locationIdsAsLong);
legExtensionField.setLocationList(byNameList);
}
if (leg.getOriginId() != null) {
leg.setOriginLocation(locationRepository.findByLocationId(leg.getOriginId()));
}
if (leg.getDestinationId() != null) {
leg.setDestinationLocation(locationRepository.findByLocationId(leg.getDestinationId()));
}
});
return list;
}
@ListenTo(command = "OrderCreateCommand", order = 0) @ListenTo(command = "OrderCreateCommand", order = 0)
public RouteOrder createOrder(OrderCreateCommand command) { public RouteOrder createOrder(OrderCreateCommand command) {
User user = command.getUser(); User user = command.getUser();

View File

@ -3,6 +3,7 @@ package com.chint.domain.service.amount_estimate;
import com.chint.application.queryies.estimate.EstimatePrice; import com.chint.application.queryies.estimate.EstimatePrice;
import com.chint.domain.aggregates.order.Leg; import com.chint.domain.aggregates.order.Leg;
import com.chint.domain.aggregates.order.RouteOrder; import com.chint.domain.aggregates.order.RouteOrder;
import com.chint.domain.service.LegDomainService;
import com.chint.domain.service.OrderDomainService; import com.chint.domain.service.OrderDomainService;
import com.chint.domain.value_object.FlightPriceData; import com.chint.domain.value_object.FlightPriceData;
import com.chint.domain.value_object.HotelPriceData; import com.chint.domain.value_object.HotelPriceData;
@ -29,6 +30,9 @@ public class CTripEstimate implements AmountEstimate {
@Autowired @Autowired
private OrderDomainService orderDomainService; private OrderDomainService orderDomainService;
@Autowired
private LegDomainService legDomainService;
@Override @Override
public String amountEstimate(Leg leg) { public String amountEstimate(Leg leg) {
@ -69,7 +73,7 @@ public class CTripEstimate implements AmountEstimate {
private PriceQueryData getQueryData(Leg leg) { private PriceQueryData getQueryData(Leg leg) {
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
PriceQueryData priceQueryData = new PriceQueryData(); PriceQueryData priceQueryData = new PriceQueryData();
leg = orderDomainService.queryLocation(List.of(leg)).get(0); leg = legDomainService.queryLocation(List.of(leg)).get(0);
priceQueryData.setArriveCity(leg.getDestinationLocation().getLocationId()); priceQueryData.setArriveCity(leg.getDestinationLocation().getLocationId());
priceQueryData.setDepartCity(leg.getOriginLocation().getLocationId()); priceQueryData.setDepartCity(leg.getOriginLocation().getLocationId());
priceQueryData.setDepartDate(dateTimeFormatter.format(leg.getStartTime())); priceQueryData.setDepartDate(dateTimeFormatter.format(leg.getStartTime()));

View File

@ -12,6 +12,7 @@ import com.chint.domain.factoriy.leg_event.LegEventFactory;
import com.chint.domain.factoriy.order.RouteOrderFactory; import com.chint.domain.factoriy.order.RouteOrderFactory;
import com.chint.domain.factoriy.order_detail.OrderDetailFactory; import com.chint.domain.factoriy.order_detail.OrderDetailFactory;
import com.chint.domain.repository.*; import com.chint.domain.repository.*;
import com.chint.domain.service.LegDomainService;
import com.chint.domain.service.OrderDomainService; import com.chint.domain.service.OrderDomainService;
import com.chint.domain.service.RouteRequestDomainService; import com.chint.domain.service.RouteRequestDomainService;
import com.chint.domain.service.order_sync.SyncAdapter; import com.chint.domain.service.order_sync.SyncAdapter;
@ -91,6 +92,9 @@ public class LegEventHandler implements LegEventService {
@Autowired @Autowired
private RouteRequestDomainService routeRequestDomainService; private RouteRequestDomainService routeRequestDomainService;
@Autowired
private LegDomainService legDomainService;
@Value("${chint.envMark}") @Value("${chint.envMark}")
private String envMark; private String envMark;
@ -229,7 +233,7 @@ public class LegEventHandler implements LegEventService {
first.isPresent() first.isPresent()
) { ) {
orderDetail = first.get(); orderDetail = first.get();
orderDetail = routeOrder.matchOrderWithLeg(orderDetail, orderDomainService); orderDetail = routeOrder.matchOrderWithLeg(orderDetail, legDomainService);
} }
} else { } else {
orderDetail = byOrderNo.get(); orderDetail = byOrderNo.get();

View File

@ -5,6 +5,7 @@ import com.chint.domain.aggregates.location.basedata.DistrictPOIInfoEntity;
import com.chint.domain.aggregates.location.basedata.PrefectureLevelCityInfoEntity; import com.chint.domain.aggregates.location.basedata.PrefectureLevelCityInfoEntity;
import com.chint.domain.aggregates.order.*; import com.chint.domain.aggregates.order.*;
import com.chint.domain.repository.*; import com.chint.domain.repository.*;
import com.chint.domain.service.LegDomainService;
import com.chint.domain.service.LocationDomainService; import com.chint.domain.service.LocationDomainService;
import com.chint.domain.service.OrderDomainService; import com.chint.domain.service.OrderDomainService;
import com.chint.interfaces.rest.ctrip.CTripApprovalRequest; import com.chint.interfaces.rest.ctrip.CTripApprovalRequest;
@ -63,6 +64,9 @@ public class CTripOrderSyncAdapter implements SupplierOrderSync {
@Autowired @Autowired
private DistrictInfoRepository districtInfoRepository; private DistrictInfoRepository districtInfoRepository;
@Autowired
private LegDomainService legDomainService;
@Override @Override
public boolean syncSupplierOrder(RouteOrder order) { public boolean syncSupplierOrder(RouteOrder order) {
log.info("开始同步携程订单"); log.info("开始同步携程订单");
@ -113,7 +117,7 @@ public class CTripOrderSyncAdapter implements SupplierOrderSync {
} }
private ApprovalRequest generateApprovalRequestLegInfo(List<Leg> legList, String employeeNo, ApprovalRequest approvalRequestParam) { private ApprovalRequest generateApprovalRequestLegInfo(List<Leg> legList, String employeeNo, ApprovalRequest approvalRequestParam) {
Map<Integer, List<Leg>> collect = orderDomainService.queryLocation( Map<Integer, List<Leg>> collect = legDomainService.queryLocation(
legList.stream() legList.stream()
.filter(leg -> leg.getLegType().equals(LEG_TYPE_HOTEL) || .filter(leg -> leg.getLegType().equals(LEG_TYPE_HOTEL) ||
leg.getLegType().equals(LEG_TYPE_AIRPLANE) || leg.getLegType().equals(LEG_TYPE_AIRPLANE) ||

View File

@ -5,6 +5,7 @@ import com.chint.domain.aggregates.user.User;
import com.chint.domain.exceptions.NotFoundException; import com.chint.domain.exceptions.NotFoundException;
import com.chint.domain.repository.LocationRepository; import com.chint.domain.repository.LocationRepository;
import com.chint.domain.repository.UserRepository; import com.chint.domain.repository.UserRepository;
import com.chint.domain.service.LegDomainService;
import com.chint.domain.service.OrderDomainService; import com.chint.domain.service.OrderDomainService;
import com.chint.interfaces.rest.ly.LYPostRequest; import com.chint.interfaces.rest.ly.LYPostRequest;
import com.chint.interfaces.rest.ly.dto.applyordersync.*; import com.chint.interfaces.rest.ly.dto.applyordersync.*;
@ -42,6 +43,8 @@ public class LYOrderSyncAdapter implements SupplierOrderSync {
@Value("${ly.baseUrl}") @Value("${ly.baseUrl}")
private String lyBaseUrl; private String lyBaseUrl;
@Autowired
private LegDomainService legDomainService;
@Override @Override
public boolean syncSupplierOrder(RouteOrder order) { public boolean syncSupplierOrder(RouteOrder order) {
@ -288,7 +291,7 @@ public class LYOrderSyncAdapter implements SupplierOrderSync {
LocalDateTime endDate = LocalDateTime.MIN; LocalDateTime endDate = LocalDateTime.MIN;
StringBuilder departCityStr = new StringBuilder(); StringBuilder departCityStr = new StringBuilder();
StringBuilder arriveCityStr = new StringBuilder(); StringBuilder arriveCityStr = new StringBuilder();
orderDomainService.queryLocation(legItems); legDomainService.queryLocation(legItems);
for (Leg leg : legItems) { for (Leg leg : legItems) {
//开始时间 //开始时间
LocalDateTime startTime = leg.getStartTime(); LocalDateTime startTime = leg.getStartTime();