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)
|
||||
|
||||
+26
@@ -376,6 +376,32 @@ class LoadingCompletedOutboxServiceTest {
|
||||
.doesNotStartWith("sha256:");
|
||||
}
|
||||
|
||||
@Test void mergesOneDropshipSourceDetailSplitAcrossTwoPalletsBeforePublishing() throws Exception {
|
||||
Row first = row(11, 100, 101); first.setFulfillmentType("ONE_CLICK_DROPSHIP");
|
||||
Row second = row(11, 100, 101); second.setFulfillmentType("ONE_CLICK_DROPSHIP");
|
||||
second.setLoadingPlanItemId(102L);
|
||||
when(snapshots.rows(90L)).thenReturn(List.of(first, second));
|
||||
when(snapshots.workPalletCount(90L)).thenReturn(2);
|
||||
when(snapshots.actualPalletRows(90L)).thenReturn(List.of(
|
||||
actualPallet(11,100,"DP-260914-0021",101,"SKU101","BOX-001",10),
|
||||
actualPallet(11,100,"DP-260914-0022",101,"SKU101","BOX-002",10)));
|
||||
|
||||
service.publish(90L);
|
||||
|
||||
ArgumentCaptor<InboundOutboxEntity> captor = ArgumentCaptor.forClass(InboundOutboxEntity.class);
|
||||
verify(outbox).insert(captor.capture());
|
||||
EventEnvelope event = mapper.readValue(captor.getValue().getPayloadJson(), EventEnvelope.class);
|
||||
assertThat(event.payload().at("/orders/0/items")).hasSize(1);
|
||||
assertThat(event.payload().at("/orders/0/items/0/sourceInboundDetailId").asText()).isEqualTo("101");
|
||||
assertThat(event.payload().at("/orders/0/items/0/packageCount").asInt()).isEqualTo(2);
|
||||
assertThat(event.payload().at("/orders/0/items/0/productQuantity").asInt()).isEqualTo(20);
|
||||
assertThat(event.payload().at("/orders/0/pallets")).hasSize(2);
|
||||
assertThat(event.payload().at("/orders/0/pallets/0/skuPackages/0/sourceInboundDetailId").asText())
|
||||
.isEqualTo("101");
|
||||
assertThat(event.payload().at("/orders/0/pallets/1/skuPackages/0/sourceInboundDetailId").asText())
|
||||
.isEqualTo("101");
|
||||
}
|
||||
|
||||
@Test
|
||||
void pricingBusinessTypeCannotTurnAStandardOrderIntoDropship() throws Exception {
|
||||
Row value = row(11, 100, 101);
|
||||
|
||||
Reference in New Issue
Block a user