fix(firstleg): project latest port schedule in platform containers
This commit is contained in:
@@ -53,8 +53,29 @@ public interface ContainerBookingMapper extends BaseMapper<ContainerBookingEntit
|
|||||||
SELECT 1 FROM fl_loading_plan_item active_item
|
SELECT 1 FROM fl_loading_plan_item active_item
|
||||||
WHERE active_item.loading_plan_id = p.id AND active_item.deleted = 0
|
WHERE active_item.loading_plan_id = p.id AND active_item.deleted = 0
|
||||||
) THEN 'WAIT_LOADING'
|
) THEN 'WAIT_LOADING'
|
||||||
ELSE p.plan_status END AS plan_status
|
ELSE p.plan_status END AS plan_status,
|
||||||
|
COALESCE(schedule.vessel_name,b.vessel_name) AS vessel_name,
|
||||||
|
COALESCE(schedule.voyage_no,b.voyage_no) AS voyage_no,
|
||||||
|
COALESCE(schedule.etd_at,b.estimated_sailing_at) AS estimated_sailing_at,
|
||||||
|
COALESCE(schedule.eta_at,b.estimated_port_arrival_at) AS estimated_port_arrival_at
|
||||||
FROM fl_container_booking b LEFT JOIN fl_loading_plan p ON p.container_booking_id = b.id
|
FROM fl_container_booking b LEFT JOIN fl_loading_plan p ON p.container_booking_id = b.id
|
||||||
|
LEFT JOIN (
|
||||||
|
SELECT ranked.customer_id,ranked.ocean_booking_id,ranked.container_booking_id,
|
||||||
|
ranked.vessel_name,ranked.voyage_no,ranked.etd_at,ranked.eta_at
|
||||||
|
FROM (
|
||||||
|
SELECT candidate.customer_id,candidate.ocean_booking_id,candidate.container_booking_id,
|
||||||
|
candidate.vessel_name,candidate.voyage_no,candidate.etd_at,candidate.eta_at,
|
||||||
|
ROW_NUMBER() OVER (
|
||||||
|
PARTITION BY candidate.customer_id,candidate.ocean_booking_id,candidate.container_booking_id
|
||||||
|
ORDER BY candidate.observed_at DESC,candidate.updated_at DESC,candidate.id DESC
|
||||||
|
) AS schedule_rank
|
||||||
|
FROM fl_port_schedule candidate
|
||||||
|
) ranked
|
||||||
|
WHERE ranked.schedule_rank=1
|
||||||
|
) schedule
|
||||||
|
ON schedule.customer_id=b.customer_id
|
||||||
|
AND schedule.ocean_booking_id=b.ocean_booking_id
|
||||||
|
AND schedule.container_booking_id=b.id
|
||||||
WHERE b.record_status = 'ACTIVE'
|
WHERE b.record_status = 'ACTIVE'
|
||||||
AND (#{query.containerNo} IS NULL OR b.container_no = #{query.containerNo})
|
AND (#{query.containerNo} IS NULL OR b.container_no = #{query.containerNo})
|
||||||
AND (#{query.cabinetNo} IS NULL OR b.cabinet_no = #{query.cabinetNo})
|
AND (#{query.cabinetNo} IS NULL OR b.cabinet_no = #{query.cabinetNo})
|
||||||
@@ -139,8 +160,29 @@ public interface ContainerBookingMapper extends BaseMapper<ContainerBookingEntit
|
|||||||
SELECT 1 FROM fl_loading_plan_item active_item
|
SELECT 1 FROM fl_loading_plan_item active_item
|
||||||
WHERE active_item.loading_plan_id = p.id AND active_item.deleted = 0
|
WHERE active_item.loading_plan_id = p.id AND active_item.deleted = 0
|
||||||
) THEN 'WAIT_LOADING'
|
) THEN 'WAIT_LOADING'
|
||||||
ELSE p.plan_status END AS plan_status
|
ELSE p.plan_status END AS plan_status,
|
||||||
|
COALESCE(schedule.vessel_name,b.vessel_name) AS vessel_name,
|
||||||
|
COALESCE(schedule.voyage_no,b.voyage_no) AS voyage_no,
|
||||||
|
COALESCE(schedule.etd_at,b.estimated_sailing_at) AS estimated_sailing_at,
|
||||||
|
COALESCE(schedule.eta_at,b.estimated_port_arrival_at) AS estimated_port_arrival_at
|
||||||
FROM fl_container_booking b LEFT JOIN fl_loading_plan p ON p.container_booking_id = b.id
|
FROM fl_container_booking b LEFT JOIN fl_loading_plan p ON p.container_booking_id = b.id
|
||||||
|
LEFT JOIN (
|
||||||
|
SELECT ranked.customer_id,ranked.ocean_booking_id,ranked.container_booking_id,
|
||||||
|
ranked.vessel_name,ranked.voyage_no,ranked.etd_at,ranked.eta_at
|
||||||
|
FROM (
|
||||||
|
SELECT candidate.customer_id,candidate.ocean_booking_id,candidate.container_booking_id,
|
||||||
|
candidate.vessel_name,candidate.voyage_no,candidate.etd_at,candidate.eta_at,
|
||||||
|
ROW_NUMBER() OVER (
|
||||||
|
PARTITION BY candidate.customer_id,candidate.ocean_booking_id,candidate.container_booking_id
|
||||||
|
ORDER BY candidate.observed_at DESC,candidate.updated_at DESC,candidate.id DESC
|
||||||
|
) AS schedule_rank
|
||||||
|
FROM fl_port_schedule candidate
|
||||||
|
) ranked
|
||||||
|
WHERE ranked.schedule_rank=1
|
||||||
|
) schedule
|
||||||
|
ON schedule.customer_id=b.customer_id
|
||||||
|
AND schedule.ocean_booking_id=b.ocean_booking_id
|
||||||
|
AND schedule.container_booking_id=b.id
|
||||||
WHERE b.id = #{id} AND b.record_status = 'ACTIVE'
|
WHERE b.id = #{id} AND b.record_status = 'ACTIVE'
|
||||||
""")
|
""")
|
||||||
ContainerBookingEntity selectBooking(@Param("id") long id);
|
ContainerBookingEntity selectBooking(@Param("id") long id);
|
||||||
|
|||||||
+20
@@ -57,6 +57,26 @@ class ContainerBookingMapperContractTest {
|
|||||||
.contains("customer_item.account_id = #{query.customerId}");
|
.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
|
@Test
|
||||||
@DisplayName("关联订舱 SQL 的预计到港参数与 Mapper 参数名一致")
|
@DisplayName("关联订舱 SQL 的预计到港参数与 Mapper 参数名一致")
|
||||||
void linkReleasedBookingUsesDeclaredEstimatedArrivalParameter() {
|
void linkReleasedBookingUsesDeclaredEstimatedArrivalParameter() {
|
||||||
|
|||||||
Reference in New Issue
Block a user