fix(firstleg): avoid limit in latest schedule projection
This commit is contained in:
+31
-10
@@ -23,16 +23,37 @@ public interface UnifiedInboundTransportMapper {
|
||||
FROM fl_loading_plan_item i
|
||||
JOIN fl_loading_plan p ON p.id = i.loading_plan_id
|
||||
JOIN fl_container_booking b ON b.id = p.container_booking_id
|
||||
LEFT JOIN fl_port_schedule schedule
|
||||
ON schedule.id = (
|
||||
SELECT latest.id
|
||||
FROM fl_port_schedule latest
|
||||
WHERE latest.customer_id = i.account_id
|
||||
AND latest.ocean_booking_id = b.ocean_booking_id
|
||||
AND latest.container_booking_id = b.id
|
||||
ORDER BY latest.observed_at DESC, latest.updated_at DESC, latest.id DESC
|
||||
LIMIT 1
|
||||
)
|
||||
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 = i.account_id
|
||||
AND schedule.ocean_booking_id = b.ocean_booking_id
|
||||
AND schedule.container_booking_id = b.id
|
||||
WHERE i.deleted = 0
|
||||
AND p.plan_status IN ('LOADING', 'COMPLETED')
|
||||
AND i.inbound_id IN
|
||||
|
||||
Reference in New Issue
Block a user