fix(appointments): expose dispatch cabinet short numbers

This commit is contained in:
2026-10-22 18:03:45 +08:00
parent 9e0266b7c3
commit bfeeef130e
6 changed files with 88 additions and 39 deletions
@@ -62,16 +62,22 @@ class FleetTripCalendarMapperTest {
bindDispatches(jdbc);
assertThat(mapper.calendar(from,to)).hasSize(2001);
}
/** 实际Mapper批读同单跨客户多柜,排除其他主单与取消主单,不用货物行放大日历。 */
/** 实际Mapper批读跨客户多柜及原装柜短号,隔离订单和事件客户,排除其他及取消主单。 */
@Test void batchReadsEverySourceSnapshotOnlyForTheRequestedActiveDispatches() throws Exception {
var ds=new DriverManagerDataSource("jdbc:h2:mem:"+UUID.randomUUID()+";MODE=MySQL;DB_CLOSE_DELAY=-1","sa","");
var jdbc=new JdbcTemplate(ds);
jdbc.execute("CREATE TABLE ll_dispatch_order(id BIGINT PRIMARY KEY,dispatch_no VARCHAR(80) UNIQUE,status VARCHAR(32))");
jdbc.execute("CREATE TABLE ll_dispatch_item(id BIGINT PRIMARY KEY,dispatch_order_id BIGINT,customer_id VARCHAR(64),source_snapshot_json VARCHAR(2000))");
jdbc.execute("CREATE TABLE ll_dispatch_item(id BIGINT PRIMARY KEY,dispatch_order_id BIGINT,customer_id VARCHAR(64),source_snapshot_json VARCHAR(2000),order_id BIGINT)");
jdbc.execute("CREATE TABLE ll_order(id BIGINT PRIMARY KEY,customer_id VARCHAR(64),source_event_id VARCHAR(64))");
jdbc.execute("CREATE TABLE ll_loading_event_inbox(event_id VARCHAR(64) PRIMARY KEY,customer_id VARCHAR(64),payload_json VARCHAR(2000))");
jdbc.update("INSERT INTO ll_dispatch_order VALUES(1,'PC-A','ACTIVE'),(2,'PC-B','ACTIVE'),(3,'PC-OTHER','ACTIVE'),(4,'PC-CANCELLED','CANCELLED')");
jdbc.update("INSERT INTO ll_dispatch_item VALUES(11,1,'101',?), (12,1,'102',?), (13,1,'101',?), (21,2,'103',?), (31,3,'101',?), (41,4,'101',?)",
jdbc.update("INSERT INTO ll_dispatch_item(id,dispatch_order_id,customer_id,source_snapshot_json) VALUES(11,1,'101',?), (12,1,'102',?), (13,1,'101',?), (21,2,'103',?), (31,3,'101',?), (41,4,'101',?)",
"{\"containerNo\":\"TSTU1234567\"}","{\"containerNo\":\"TSTU1234567\"}","{\"containerNo\":\"TSTU7654321\"}",
"{\"planNo\":\"PLAN-B\"}","{\"containerNo\":\"OTHER-CARGO\"}","{\"containerNo\":\"CANCELLED-CARGO\"}");
jdbc.update("INSERT INTO ll_order VALUES(1011,'101','E1'),(1012,'102','E2'),(1013,'101','E3'),(1021,'104','E4')");
jdbc.update("INSERT INTO ll_loading_event_inbox VALUES('E1','101',?),('E2','102',?),('E3','102',?),('E4','104',?)",
"{\"cabinetNo\":\"D1821\"}","{\"cabinetNo\":\"D1822\"}","{\"cabinetNo\":\"WRONG-EVENT-CUSTOMER\"}","{\"cabinetNo\":\"WRONG-ORDER-CUSTOMER\"}");
jdbc.update("UPDATE ll_dispatch_item SET order_id=CASE id WHEN 11 THEN 1011 WHEN 12 THEN 1012 WHEN 13 THEN 1013 WHEN 21 THEN 1021 END");
var config=new MybatisConfiguration();config.setMapUnderscoreToCamelCase(true);config.addMapper(FleetTripMapper.class);
var factory=new MybatisSqlSessionFactoryBean();factory.setDataSource(ds);factory.setConfiguration(config);
var mapper=new SqlSessionTemplate(factory.getObject()).getMapper(FleetTripMapper.class);
@@ -81,5 +87,10 @@ class FleetTripCalendarMapperTest {
assertThat(rows).extracting(FleetTripCalendarRepository.Source::dispatchNo).containsExactly("PC-A","PC-A","PC-A","PC-B");
assertThat(rows).extracting(FleetTripCalendarRepository.Source::sourceSnapshotJson).containsExactly(
"{\"containerNo\":\"TSTU1234567\"}","{\"containerNo\":\"TSTU1234567\"}","{\"containerNo\":\"TSTU7654321\"}","{\"planNo\":\"PLAN-B\"}");
assertThat(rows).extracting(FleetTripCalendarRepository.Source::loadingPayloadJson).containsExactly(
"{\"cabinetNo\":\"D1821\"}","{\"cabinetNo\":\"D1822\"}",null,null);
jdbc.update("UPDATE ll_dispatch_item SET order_id=NULL WHERE id=11");
assertThat(repository.sourceSnapshots(List.of("PC-A"))).hasSize(3).first()
.extracting(FleetTripCalendarRepository.Source::loadingPayloadJson).isNull();
}
}
@@ -107,22 +107,26 @@ class FleetTripCalendarServiceTest {
var platform=new com.baiyue.common.security.AuthenticatedUser(1L,0L,0L,1L,"platform","PLATFORM","WEB",Set.of("platform:overseas-warehouse:dispatch:list"));
controller.calendar(platform,from,to);verify(calendar).calendar(from,to);
}
/** 同车全部来源只批读一次,跨客户重复柜号去重,多柜完整保留。 */
/** 同车全部来源只批读一次,跨客户重复柜号及短号去重,多柜完整保留。 */
@Test void readsAllContainerNumbersInOneBatchAndPreservesTheLocalDateFacts() {
var first=trip("PC-A",1L);first.setPlannedDepartureAt(LocalDateTime.of(2026,10,22,16,0));
when(trips.calendar(any(),any())).thenReturn(List.of(first,trip("PC-B",1L)));
when(trips.sourceSnapshots(List.of("PC-A","PC-B"))).thenReturn(List.of(
new FleetTripCalendarRepository.Source("PC-A","{\"containerNo\":\" TSTU1234567 \",\"planNo\":\"PLAN-A\"}"),
new FleetTripCalendarRepository.Source("PC-A","{\"containerNo\":\"TSTU1234567\"}"),
new FleetTripCalendarRepository.Source("PC-A","{\"containerNo\":\"TSTU7654321\"}"),
new FleetTripCalendarRepository.Source("PC-A","{\"containerNo\":null}"),
new FleetTripCalendarRepository.Source("PC-B","{}"),
new FleetTripCalendarRepository.Source("PC-B","{\"containerNo\":\" \"}")));
new FleetTripCalendarRepository.Source("PC-A","{\"containerNo\":\" TSTU1234567 \",\"planNo\":\"PLAN-A\"}","{\"cabinetNo\":\" D1821 \"}"),
new FleetTripCalendarRepository.Source("PC-A","{\"containerNo\":\"TSTU1234567\"}","{\"cabinetNo\":\"D1821\"}"),
new FleetTripCalendarRepository.Source("PC-A","{\"containerNo\":\"TSTU7654321\"}","{\"cabinetNo\":\"D1822\"}"),
new FleetTripCalendarRepository.Source("PC-A","{\"containerNo\":null}","{\"cabinetNo\":\"D1823\"}"),
new FleetTripCalendarRepository.Source("PC-B","{}",null),
new FleetTripCalendarRepository.Source("PC-B","{\"containerNo\":\" \"}","{\"cabinetNo\":null}"),
new FleetTripCalendarRepository.Source("PC-B","{}","{}"),
new FleetTripCalendarRepository.Source("PC-B","{}","{\"cabinetNo\":\" \"}")));
metadata(List.of(warehouse(1,"US","America/Los_Angeles")),List.of());
var result=service.calendar(from,to);
assertThat(result.records()).hasSize(2);
assertThat(result.records().get(0).containerNumbers()).containsExactly("TSTU1234567","TSTU7654321");
assertThat(result.records().get(1).containerNumbers()).isEmpty();
assertThat(result.records().get(0).cabinetNumbers()).containsExactly("D1821","D1822","D1823");
assertThat(result.records().get(1).cabinetNumbers()).isEmpty();
assertThat(result.records().get(0).plannedDepartureAt()).isEqualTo(Instant.parse("2026-10-22T16:00:00Z"));
assertThat(result.records().get(0).originTimezone()).isEqualTo("America/Los_Angeles");
assertThat(result.unresolvedRecords()).isEmpty();
@@ -130,15 +134,16 @@ class FleetTripCalendarServiceTest {
verify(warehouses).platformMetadata("internal-test",new FleetWarehouseClient.MetadataRequest(List.of(1L)));
verifyNoMoreInteractions(warehouses);
}
/** 缺时区的主单仍保留真实柜号,不将货物信息丢失误作起运地已核实。 */
/** 缺时区的主单仍保留真实柜号及短号,不将货物信息丢失误作起运地已核实。 */
@Test void keepsKnownContainersOnAnUnresolvedOrigin() {
when(trips.calendar(any(),any())).thenReturn(List.of(trip("PC-UNKNOWN",1L)));
when(trips.sourceSnapshots(List.of("PC-UNKNOWN"))).thenReturn(List.of(
new FleetTripCalendarRepository.Source("PC-UNKNOWN","{\"containerNo\":\"TSTU1234567\"}")));
new FleetTripCalendarRepository.Source("PC-UNKNOWN","{\"containerNo\":\"TSTU1234567\"}","{\"cabinetNo\":\"D1821\"}")));
metadata(List.of(warehouse(1,"US",null)),List.of());
var result=service.calendar(from,to);assertThat(result.records()).isEmpty();
assertThat(result.unresolvedRecords()).singleElement().satisfies(row->{
assertThat(row.containerNumbers()).containsExactly("TSTU1234567");
assertThat(row.cabinetNumbers()).containsExactly("D1821");
assertThat(row.incompleteReasons()).containsExactly("ORIGIN_TIMEZONE_UNKNOWN");
});
}
@@ -146,12 +151,22 @@ class FleetTripCalendarServiceTest {
@Test void rejectsMalformedOrForeignSourceSnapshotsExplicitly() {
when(trips.calendar(any(),any())).thenReturn(List.of(trip("PC-A",1L)));
for(var invalid:Arrays.asList(null,"","not-json","null","[]","{\"containerNo\":123}","{\"containerNo\":[\"TSTU1234567\"]}","{} {}")) {
when(trips.sourceSnapshots(List.of("PC-A"))).thenReturn(List.of(new FleetTripCalendarRepository.Source("PC-A",invalid)));
when(trips.sourceSnapshots(List.of("PC-A"))).thenReturn(List.of(new FleetTripCalendarRepository.Source("PC-A",invalid,null)));
assertThatThrownBy(()->service.calendar(from,to)).isInstanceOf(ResponseStatusException.class)
.hasMessageContaining("柜号资料暂不可用");
}
when(trips.sourceSnapshots(List.of("PC-A"))).thenReturn(List.of(new FleetTripCalendarRepository.Source("OTHER-PC","{}")));
when(trips.sourceSnapshots(List.of("PC-A"))).thenReturn(List.of(new FleetTripCalendarRepository.Source("OTHER-PC","{}",null)));
assertThatThrownBy(()->service.calendar(from,to)).isInstanceOf(ResponseStatusException.class).hasMessageContaining("柜号资料暂不可用");
verifyNoInteractions(warehouses);
}
/** 损坏短号来源明确失败,不伪装为没有关联柜次。 */
@Test void rejectsMalformedLoadingSnapshotsExplicitly() {
when(trips.calendar(any(),any())).thenReturn(List.of(trip("PC-A",1L)));
for(var invalid:List.of("","not-json","null","[]","{\"cabinetNo\":1821}","{\"cabinetNo\":[\"D1821\"]}","{} {}")) {
when(trips.sourceSnapshots(List.of("PC-A"))).thenReturn(List.of(new FleetTripCalendarRepository.Source("PC-A","{}",invalid)));
assertThatThrownBy(()->service.calendar(from,to)).isInstanceOf(ResponseStatusException.class)
.hasMessageContaining("柜号资料暂不可用");
}
verifyNoInteractions(warehouses);
}
}