fix: merge multi-pallet dropship handover fragments
This commit is contained in:
+37
-8
@@ -131,16 +131,17 @@ public class LoadingCompletedOutboxService {
|
||||
Map<String, PalletManifest> palletManifests) {
|
||||
List<Row> sorted = values.stream().sorted(Comparator.comparing(Row::getSourceInboundDetailId)).toList();
|
||||
Row first = sorted.get(0);
|
||||
List<FirstLegLoadingPlanCompletedV2.Item> items = sorted.stream().map(row ->
|
||||
new FirstLegLoadingPlanCompletedV2.Item(string(row.getSourceInboundDetailId()), row.getSkuCode(),
|
||||
row.getProductNameZh(), row.getProductNameEn(), row.getPackageCount(), row.getProductQuantity(),
|
||||
row.getPalletCount(), row.getGrossWeightKg(), row.getNetWeightKg(), row.getDimensionalWeightKg(),
|
||||
row.getVolumeCbm(), string(row.getDestinationWarehouseId()), row.getDestinationWarehouseCode(),
|
||||
String fulfillmentType = fulfillmentType(sorted);
|
||||
List<FirstLegLoadingPlanCompletedV2.Item> items = dropship(fulfillmentType)
|
||||
? eventItems(sorted, cartonMarks)
|
||||
: sorted.stream().map(row -> new FirstLegLoadingPlanCompletedV2.Item(
|
||||
string(row.getSourceInboundDetailId()), row.getSkuCode(), row.getProductNameZh(),
|
||||
row.getProductNameEn(), row.getPackageCount(), row.getProductQuantity(), row.getPalletCount(),
|
||||
row.getGrossWeightKg(), row.getNetWeightKg(), row.getDimensionalWeightKg(), row.getVolumeCbm(),
|
||||
string(row.getDestinationWarehouseId()), row.getDestinationWarehouseCode(),
|
||||
row.getDestinationWarehouseName(), row.getFbaTrackingNo(), row.getShipmentNo(), row.getShippingMark(),
|
||||
row.getCustomerRemark(), row.getInternalRemark(), row.getWarehouseRemark(), null,
|
||||
cartonMarks.getOrDefault(row.getLoadingPlanItemId(), List.of())))
|
||||
.toList();
|
||||
String fulfillmentType = fulfillmentType(sorted);
|
||||
cartonMarks.getOrDefault(row.getLoadingPlanItemId(), List.of()))).toList();
|
||||
String orderType = dropship(fulfillmentType) ? "ONE_CLICK_DROPSHIP" : "FIRST_LEG";
|
||||
List<FirstLegLoadingPlanCompletedV2.PalletSnapshot> pallets = dropship(fulfillmentType)
|
||||
? palletSnapshots(sorted, palletRows, palletManifests) : standardLabels.stream()
|
||||
@@ -161,6 +162,34 @@ public class LoadingCompletedOutboxService {
|
||||
destinationType(sorted), first.getLxCode());
|
||||
}
|
||||
|
||||
/** 一件代发装柜按托盘产生分配行,跨区订单明细仍须按来源入仓明细保持唯一。 */
|
||||
private List<FirstLegLoadingPlanCompletedV2.Item> eventItems(List<Row> rows,
|
||||
Map<Long, List<String>> cartonMarks) {
|
||||
Map<Long, List<Row>> byDetail = rows.stream().collect(java.util.stream.Collectors.groupingBy(
|
||||
Row::getSourceInboundDetailId, LinkedHashMap::new, java.util.stream.Collectors.toList()));
|
||||
List<FirstLegLoadingPlanCompletedV2.Item> result = new ArrayList<>();
|
||||
for (List<Row> fragments : byDetail.values()) {
|
||||
Row first = fragments.get(0);
|
||||
if (fragments.stream().anyMatch(row -> !Objects.equals(first.getSkuCode(), row.getSkuCode())
|
||||
|| !Objects.equals(first.getDestinationWarehouseId(), row.getDestinationWarehouseId())
|
||||
|| !Objects.equals(first.getDestinationWarehouseCode(), row.getDestinationWarehouseCode()))) {
|
||||
throw new BizException(ResultCode.CONFLICT, "同一入仓明细的装柜分片快照不一致");
|
||||
}
|
||||
List<String> marks = fragments.stream()
|
||||
.flatMap(row -> cartonMarks.getOrDefault(row.getLoadingPlanItemId(), List.of()).stream()).toList();
|
||||
result.add(new FirstLegLoadingPlanCompletedV2.Item(string(first.getSourceInboundDetailId()),
|
||||
first.getSkuCode(), first.getProductNameZh(), first.getProductNameEn(),
|
||||
sumInt(fragments, Row::getPackageCount), sumNullableInt(fragments, Row::getProductQuantity),
|
||||
sumNullableInt(fragments, Row::getPalletCount), sum(fragments, Row::getGrossWeightKg),
|
||||
sum(fragments, Row::getNetWeightKg), sum(fragments, Row::getDimensionalWeightKg),
|
||||
sum(fragments, Row::getVolumeCbm), string(first.getDestinationWarehouseId()),
|
||||
first.getDestinationWarehouseCode(), first.getDestinationWarehouseName(), first.getFbaTrackingNo(),
|
||||
first.getShipmentNo(), first.getShippingMark(), first.getCustomerRemark(), first.getInternalRemark(),
|
||||
first.getWarehouseRemark(), null, marks));
|
||||
}
|
||||
return List.copyOf(result);
|
||||
}
|
||||
|
||||
/** 只按 Warehouse 已分配的物理 palletId 计数;无分配事实时保持 null。 */
|
||||
private static Integer actualPalletCount(List<PalletRow> palletRows) {
|
||||
Set<Long> palletIds = palletRows.stream().map(PalletRow::getPalletId)
|
||||
|
||||
Reference in New Issue
Block a user