This commit is contained in:
2026-10-20 10:35:52 +08:00
parent ce189f062f
commit c13175bf77
202 changed files with 38397 additions and 7138 deletions
@@ -72,6 +72,43 @@ class DispatchDeliveryServiceTest {
verify(fees,times(3)).publish(any(),any(),any(),any(),isNull(),any(),eq("OP-A"),anyString());
}
/** 同实托的两申请分别冻结原货源,出库引用逐次归属且真实客户目的地与履约订单不被替换。 */
@Test void relabelOriginsStayFrozenBehindOutboundAttributionReferences() throws Exception {
var first=new SourceOrigin(10001L,201L,301L,401L,701L,"IN-701","CODE-701",null);
var second=new SourceOrigin(10002L,202L,302L,402L,702L,"IN-702","CODE-702",null);
var third=new SourceOrigin(10003L,203L,303L,403L,703L,"IN-703","CODE-703",null);
var fourth=new SourceOrigin(10004L,204L,304L,404L,704L,"IN-704","CODE-704",6L);
context=context(List.of(relabelCargo(1,"101","ONT8",51,2,first),relabelCargo(3,"101","ONT8",51,3,second),
relabelCargo(2,"102","ONT8",51,4,third),relabelCargo(4,"101","LAX9",52,1,fourth)),false);
var result=(ArrangementResult)service.arrange(actor,"DP-10",request("RELABEL-ARRANGE")).result();
assertEquals(2,result.outbounds().size());
assertEquals(3,result.deliveries().size());
var ont8=result.deliveries().stream().filter(d->d.customerId().equals("101")&&d.destination().warehouseCode().equals("ONT8"))
.findFirst().orElseThrow();
assertEquals(5,ont8.packageCount());assertEquals(1,ont8.palletCount());
assertEquals(2,result.deliveries().stream().filter(d->d.destination().warehouseCode().equals("ONT8"))
.map(DeliveryReference::customerId).distinct().count());
List<CargoLine> cargo=json.readValue(arrangement.getCargoJson(),json.getTypeFactory().constructCollectionType(List.class,CargoLine.class));
assertEquals(context.cargo(),cargo);
var created=org.mockito.ArgumentCaptor.forClass(OutboundPalletItem.class);
verify(repository,times(4)).create(created.capture());
for (var item:created.getAllValues()) {
var source=cargo.stream().filter(c->c.customerId().equals(item.getCustomerId())
&& c.attributionId().equals(item.getSourceAttributionId())).findFirst().orElseThrow();
assertEquals(source.orderId(),item.getSourceOrderId());
assertNotEquals(source.sourceOrigin().sourceInboundOrderId(),item.getSourceOrderId());
assertEquals(source.dispatchItemId(),item.getDispatchItemId());
assertEquals(source.packages(),item.getPackageCount().longValue());
assertNull(item.getGrossWeightKg());assertNull(item.getVolumeCbm());
}
assertEquals(3,cargo.stream().filter(c->c.sourceOrigin().productQuantity()==null).count());
assertTrue(outbounds.stream().allMatch(o->o.getGrossWeightKg()==null&&o.getVolumeCbm()==null));
assertTrue(deliveries.stream().allMatch(d->d.getTotalWeightKg()==null&&d.getTotalVolumeCbm()==null));
var orders=org.mockito.ArgumentCaptor.forClass(Long.class);
verify(repository,times(4)).lockSource(anyString(),orders.capture());
assertEquals(List.of(1L,2L,3L,4L),orders.getAllValues());
}
/** 原命令恢复先于新阶段和版本判断,不能再次写任何客户单据。 */
@Test void strictReplayDelegatesToAuthoritativeLedgerBeforeCreatingDocuments() {
var snapshot=new CommandResult("DP-10",Action.ARRANGE_DELIVERY,"KEY-1",4,Status.ACTIVE,Stage.AFTER_LOADING,