fix(firstleg): project latest port schedule in container reads

This commit is contained in:
2026-09-27 22:05:56 +08:00
parent a6ca9a8a18
commit 2c4f1ea37b
4 changed files with 51 additions and 66 deletions
@@ -57,26 +57,6 @@ class ContainerBookingMapperContractTest {
.contains("customer_item.account_id = #{query.customerId}");
}
@Test
@DisplayName("平台货柜读模型投影最新港务船期但保留订舱事实")
void projectsLatestPortScheduleForPlatformReads() throws Exception {
String detail = String.join("\n", ContainerBookingMapper.class
.getDeclaredMethod("selectBooking", long.class).getAnnotation(Select.class).value());
String page = String.join("\n", ContainerBookingMapper.class
.getDeclaredMethod("selectBookingPage", com.baomidou.mybatisplus.extension.plugins.pagination.Page.class,
com.baiyue.firstleg.dto.ContainerDtos.Query.class, String.class)
.getAnnotation(Select.class).value());
for (String sql : java.util.List.of(detail, page)) {
assertThat(sql)
.contains("fl_port_schedule", "ROW_NUMBER() OVER", "PARTITION BY candidate.customer_id",
"COALESCE(schedule.vessel_name,b.vessel_name)",
"COALESCE(schedule.voyage_no,b.voyage_no)",
"COALESCE(schedule.etd_at,b.estimated_sailing_at)",
"COALESCE(schedule.eta_at,b.estimated_port_arrival_at)")
.doesNotContain("actual_sailing_at=schedule", "actual_port_arrival_at=schedule");
}
}
@Test
@DisplayName("关联订舱 SQL 的预计到港参数与 Mapper 参数名一致")
void linkReleasedBookingUsesDeclaredEstimatedArrivalParameter() {
@@ -2,6 +2,8 @@ package com.baiyue.firstleg.repository;
import com.baiyue.firstleg.entity.ContainerBookingEntity;
import com.baiyue.firstleg.mapper.ContainerBookingMapper;
import com.baiyue.firstleg.portschedule.entity.PortScheduleEntity;
import com.baiyue.firstleg.portschedule.mapper.PortScheduleMapper;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
@@ -16,6 +18,7 @@ import static org.mockito.Mockito.when;
@ExtendWith(MockitoExtension.class)
class ContainerRepositoryLoadingTimeTest {
@Mock private ContainerBookingMapper mapper;
@Mock private PortScheduleMapper schedules;
@InjectMocks private ContainerRepository repository;
@Test
@@ -44,4 +47,30 @@ class ContainerRepositoryLoadingTimeTest {
assertThat(result.getLoadingAt()).isEqualTo(plannedAt);
}
@Test
void projectsLatestPortScheduleWithoutChangingContainerIdentity() {
ContainerBookingEntity booking = new ContainerBookingEntity();
booking.setId(8L);
booking.setCustomerId(9L);
booking.setOceanBookingId(10L);
booking.setContainerNo("TSTU0000001");
booking.setVesselName("OLD-VESSEL");
booking.setVoyageNo("OLD-V01");
PortScheduleEntity schedule = new PortScheduleEntity();
schedule.setVesselName("NEW-VESSEL");
schedule.setVoyageNo("NEW-V01");
schedule.setEtdAt(LocalDateTime.of(2026, 10, 7, 8, 0));
schedule.setEtaAt(LocalDateTime.of(2026, 10, 27, 8, 0));
when(mapper.selectBooking(8L)).thenReturn(booking);
when(schedules.latestForDispatch(9L, 10L, 8L)).thenReturn(schedule);
ContainerBookingEntity result = repository.find(8L);
assertThat(result.getContainerNo()).isEqualTo("TSTU0000001");
assertThat(result.getVesselName()).isEqualTo("NEW-VESSEL");
assertThat(result.getVoyageNo()).isEqualTo("NEW-V01");
assertThat(result.getEstimatedSailingAt()).isEqualTo(schedule.getEtdAt());
assertThat(result.getEstimatedPortArrivalAt()).isEqualTo(schedule.getEtaAt());
}
}