fix(firstleg): avoid limit in latest schedule projection

This commit is contained in:
2026-09-27 21:33:30 +08:00
parent ac3acfce6a
commit f1218cef02
@@ -23,16 +23,37 @@ public interface UnifiedInboundTransportMapper {
FROM fl_loading_plan_item i FROM fl_loading_plan_item i
JOIN fl_loading_plan p ON p.id = i.loading_plan_id JOIN fl_loading_plan p ON p.id = i.loading_plan_id
JOIN fl_container_booking b ON b.id = p.container_booking_id JOIN fl_container_booking b ON b.id = p.container_booking_id
LEFT JOIN fl_port_schedule schedule LEFT JOIN (
ON schedule.id = ( SELECT ranked.customer_id,
SELECT latest.id ranked.ocean_booking_id,
FROM fl_port_schedule latest ranked.container_booking_id,
WHERE latest.customer_id = i.account_id ranked.vessel_name,
AND latest.ocean_booking_id = b.ocean_booking_id ranked.voyage_no,
AND latest.container_booking_id = b.id ranked.etd_at,
ORDER BY latest.observed_at DESC, latest.updated_at DESC, latest.id DESC ranked.eta_at
LIMIT 1 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 = i.account_id
AND schedule.ocean_booking_id = b.ocean_booking_id
AND schedule.container_booking_id = b.id
WHERE i.deleted = 0 WHERE i.deleted = 0
AND p.plan_status IN ('LOADING', 'COMPLETED') AND p.plan_status IN ('LOADING', 'COMPLETED')
AND i.inbound_id IN AND i.inbound_id IN