This commit is contained in:
2026-10-19 17:56:36 +08:00
parent bb917c954c
commit dcfba1053c
232 changed files with 15655 additions and 6005 deletions
@@ -0,0 +1,30 @@
package com.baiyue.lastleg.delivery;
import com.baiyue.lastleg.delivery.model.DeliveryCargoGroups;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test;
import java.util.List;
import static com.baiyue.lastleg.delivery.DeliveryDispatchFixtures.*;
import static org.junit.jupiter.api.Assertions.*;
class DeliveryCargoGroupsTest {
private final DeliveryCargoGroups policy=new DeliveryCargoGroups(new ObjectMapper().findAndRegisterModules());
/** 同目的仓不同客户分开,同托多来源保留且物理托盘仅计一次。 */
@Test void groupsByCustomerAndDestinationWithoutLosingMixedPalletSources() {
var a=cargo(1,"101","ONT8",51,2);var b=cargo(2,"101","ONT8",51,3);
var c=cargo(3,"101","LAX9",52,4);var d=cargo(4,"102","ONT8",53,5);
var groups=policy.groups(context(List.of(d,c,b,a),false));
assertEquals(3,groups.size());
var mixed=groups.stream().filter(g->g.customerId().equals("101")&&g.destination().warehouseCode().equals("ONT8")).findFirst().orElseThrow();
assertEquals(5,mixed.packages());assertEquals(1,mixed.palletCount());assertEquals(2,mixed.cargo().size());
assertEquals(mixed.cargoHash(),policy.groups(context(List.of(a,b,c,d),false)).stream().filter(g->g.key().equals(mixed.key())).findFirst().orElseThrow().cargoHash());
assertNotEquals(policy.groupKey("101",a.destination()),policy.groupKey("102",a.destination()));
}
/** 空车和重复归属不能靠总箱数相等冒充完整真实来源。 */
@Test void emptyOrDuplicatedAttributionCannotBecomeArrangement() {
assertThrows(org.springframework.web.server.ResponseStatusException.class,()->policy.groups(context(List.of(),false)));
var row=cargo(1,"101","ONT8",51,2);
assertThrows(org.springframework.web.server.ResponseStatusException.class,()->policy.groups(context(List.of(row,row),false)));
assertThrows(org.springframework.web.server.ResponseStatusException.class,()->policy.groups(context(List.of(row,cargo(2,"101","LAX9",51,3)),false)));
}
}