fix: preserve native tail order facts in combined lists

This commit is contained in:
2026-10-23 01:44:07 +08:00
parent d60a35b367
commit 6cd27658f7
4 changed files with 43 additions and 26 deletions
@@ -27,6 +27,12 @@ public interface InventoryBalanceMapper extends BaseMapper<InventoryBalance> {
WHERE c.customer_id=#{customerId} AND t.inbound_order_id=#{inboundOrderId}
AND t.operating_warehouse_id=#{warehouseId} AND c.status='COUNTED'
AND (c.carton_mark=#{cartonMark} OR c.customer_carton_mark=#{cartonMark})
UNION ALL
SELECT 1 FROM ll_dropship_carton c
JOIN ll_order o ON o.id=c.order_id AND o.customer_id=c.customer_id
JOIN ll_inbound_order i ON i.customer_id=o.customer_id AND i.inbound_code=o.inbound_code
WHERE c.customer_id=#{customerId} AND i.id=#{inboundOrderId}
AND o.overseas_warehouse_id=#{warehouseId} AND c.carton_mark=#{cartonMark}
)
""")
boolean cartonBelongsToInbound(@Param("customerId") String customerId,
@@ -109,21 +109,26 @@ public class LastlegOrderService {
if (query.sailingStage() == null && relabelNo == null) return aggregateAllPage(customerId, query);
Page<LastlegOrder> page = orderMapper.selectPage(
new Page<>(query.page(), query.size()), filter(customerId, query, relabelNo).orderByDesc(LastlegOrder::getCreatedAt).orderByDesc(LastlegOrder::getId));
Map<Long, List<LastlegOrderMapper.PalletMergeRelationRow>> mergeRelations = palletMergeRelations(page.getRecords());
returnOrderReferences.populateForRead(page.getRecords());
refreshReturnVolumes(page.getRecords());
Map<String, String> containerNodes = containerNodes(page.getRecords());
Map<Long, String> dispatchStatuses = dispatchStatuses(page.getRecords());
Map<Long, LastlegOrderMapper.OrderWeightRow> weights = orderWeights(page.getRecords());
Map<Long, List<com.baiyue.lastleg.dto.RelabelSubOrder>> relabels = relabelSubOrders(page.getRecords());
Map<Long, LastlegOrderSummary.BusinessSource> businessSources = businessSources(page.getRecords());
var quantities = transferQuantities.forOrders(page.getRecords());
return new PageResult<>(page.getRecords().stream().map(order -> summary(order, mergeRelations.get(order.getId()),
return new PageResult<>(nativeSummaries(page.getRecords()),
page.getCurrent(), page.getSize(), page.getTotal(), page.getPages());
}
/** 全部及已开船列表使用同一组业务事实,避免聚合列表丢失并托、排车和换标信息。 */
private List<LastlegOrderSummary> nativeSummaries(List<LastlegOrder> orders) {
Map<Long, List<LastlegOrderMapper.PalletMergeRelationRow>> mergeRelations = palletMergeRelations(orders);
returnOrderReferences.populateForRead(orders);
refreshReturnVolumes(orders);
Map<String, String> containerNodes = containerNodes(orders);
Map<Long, String> dispatchStatuses = dispatchStatuses(orders);
Map<Long, LastlegOrderMapper.OrderWeightRow> weights = orderWeights(orders);
Map<Long, List<com.baiyue.lastleg.dto.RelabelSubOrder>> relabels = relabelSubOrders(orders);
Map<Long, LastlegOrderSummary.BusinessSource> businessSources = businessSources(orders);
var quantities = transferQuantities.forOrders(orders);
return orders.stream().map(order -> summary(order, mergeRelations.get(order.getId()),
StringUtils.hasText(order.getSourceContainerBookingId())
? containerNodes.get(order.getSourceContainerBookingId()) : null,
dispatchStatuses.getOrDefault(order.getId(), "UNSCHEDULED"), weights.get(order.getId()),
relabels.getOrDefault(order.getId(), List.of()), businessSources.get(order.getId()), quantities.get(order.getId()))).toList(),
page.getCurrent(), page.getSize(), page.getTotal(), page.getPages());
relabels.getOrDefault(order.getId(), List.of()), businessSources.get(order.getId()), quantities.get(order.getId()))).toList();
}
/** 全部页签合并订单服务的未开船头程数据与本服务已有尾程单,尾程记录优先覆盖同一来源订单。 */
@@ -132,18 +137,14 @@ public class LastlegOrderService {
if (source == null || source.data() == null) throw new ResponseStatusException(HttpStatus.SERVICE_UNAVAILABLE, "订单服务暂时不可用");
List<LastlegOrder> existing = orderMapper.selectList(filter(customerId, query, null)
.orderByDesc(LastlegOrder::getCreatedAt).orderByDesc(LastlegOrder::getId));
Map<String, String> existingNodes = containerNodes(existing);
Map<Long, LastlegOrderMapper.OrderWeightRow> existingWeights = orderWeights(existing);
Map<String, LastlegOrderSummary> merged = new LinkedHashMap<>();
source.data().records().forEach(row -> {
var summary = preDepartureSummary(row);
merged.put(orderKey(summary.customerId(), summary.sourceOrderNo()), summary);
});
for (LastlegOrder order : existing) {
String key = orderKey(order.getCustomerId(), StringUtils.hasText(order.getSourceOrderNo()) ? order.getSourceOrderNo() : order.getOrderNo());
merged.put(key, summary(order, List.of(), StringUtils.hasText(order.getSourceContainerBookingId())
? existingNodes.get(order.getSourceContainerBookingId()) : null, "UNSCHEDULED",
existingWeights.get(order.getId()), List.of(), null, null));
for (LastlegOrderSummary order : nativeSummaries(existing)) {
String key = orderKey(order.customerId(), StringUtils.hasText(order.sourceOrderNo()) ? order.sourceOrderNo() : order.orderNo());
merged.put(key, order);
}
List<LastlegOrderSummary> rows = merged.values().stream().sorted(java.util.Comparator.comparing(LastlegOrderSummary::createdAt,
java.util.Comparator.nullsLast(java.util.Comparator.reverseOrder()))).toList();