fix: count distinct SKU codes across shared pallet inbounds

This commit is contained in:
2026-09-16 10:18:56 +08:00
parent c099b19176
commit a4c659f4c6
3 changed files with 23 additions and 2 deletions
@@ -231,7 +231,8 @@ public class DropshipPalletizationService {
values.stream().map(v->v.carton().getBoxCode()).toList());}).toList();
int discrepancies=(int)cartons.stream().filter(c->"ACCEPTED_VARIANCE".equals(c.getDiscrepancyStatus())).count();
PalletMetrics metrics=mapper.metrics(row.getId());
return new Pallet(row.getId(),row.getPalletNo(),row.getPalletStatus(),cartons.size(),items.size(),discrepancies,
int skuCount=(int)items.stream().map(SkuItem::skuCode).distinct().count();
return new Pallet(row.getId(),row.getPalletNo(),row.getPalletStatus(),cartons.size(),skuCount,discrepancies,
metrics==null?BigDecimal.ZERO:metrics.weightKg(),metrics==null?BigDecimal.ZERO:metrics.volumeCbm(),row.getVersion(),items,
cartons.stream().map(c->cartonView(c,c.getInboundCode(),false,null)).toList(),row.getCompletedAt());
}
@@ -163,7 +163,7 @@ components:
palletNo: {$ref: '#/components/schemas/PalletNo'}
status: {type: string, enum: [OPEN, SEALED]}
cartonCount: {type: integer, minimum: 0}
skuCount: {type: integer, minimum: 0}
skuCount: {type: integer, minimum: 0, description: '整托按 SKU 编码去重的种类数,包含合托全部入仓码,不是商品件数或入仓明细数'}
discrepancyCartons: {type: integer, minimum: 0}
weightKg: {type: number, minimum: 0}
volumeCbm: {type: number, minimum: 0}
@@ -26,6 +26,26 @@ class DropshipPalletizationServiceTest {
private final DropshipPalletizationService service=new DropshipPalletizationService();
DropshipPalletizationServiceTest(){ ReflectionTestUtils.setField(service,"mapper",mapper); ReflectionTestUtils.setField(service,"documentNumbers",numbers); when(mapper.labelSkus(anyLong(),anyLong())).thenAnswer(call -> java.util.List.of(labelSku())); when(mapper.cartonSkus(anyLong())).thenAnswer(call -> java.util.List.of(cartonSku())); }
@Test void sharedPalletCountsDistinctSkuCodesWithoutMergingInboundDetails(){
when(mapper.inboundCode(1L,30L)).thenReturn("IN-1");
when(mapper.palletsByInbound(1L,30L)).thenReturn(java.util.List.of(pallet()));
CartonRow first=carton(),second=carton(); second.setId(61L); second.setInboundId(31L); second.setBoxCode("BOX-2");
CartonSkuRow sameSku=cartonSku(); sameSku.setInboundDetailId(41L);
CartonSkuRow differentSku=cartonSku(); differentSku.setInboundDetailId(42L); differentSku.setSkuCode("SKU-2");
when(mapper.cartons(20L)).thenReturn(java.util.List.of(first,second));
when(mapper.cartonSkus(61L)).thenReturn(java.util.List.of(sameSku));
var shared=service.inboundPallets(1L,30L).get(0);
assertThat(shared.cartonCount()).isEqualTo(2);
assertThat(shared.skuCount()).isEqualTo(1);
assertThat(shared.items()).hasSize(2);
when(mapper.cartonSkus(61L)).thenReturn(java.util.List.of(sameSku,differentSku));
assertThat(service.inboundPallets(1L,30L).get(0).skuCount()).isEqualTo(2);
when(mapper.cartons(20L)).thenReturn(java.util.List.of(first));
assertThat(service.inboundPallets(1L,30L).get(0).skuCount()).isEqualTo(1);
when(mapper.cartons(20L)).thenReturn(java.util.List.of());
assertThat(service.inboundPallets(1L,30L).get(0).skuCount()).isZero();
}
@Test void reviewCreatesExpectedNumberOfPrintablePalletCodes(){
InboundOrderEntity inbound=dropshipInbound(); when(mapper.insertTask(anyLong(),eq(1L),eq(30L),eq(100L),eq(8))).thenReturn(1);
when(numbers.next("DP")).thenReturn("DP-260911-0001","DP-260911-0002");