fix(firstleg): project latest port schedule to merchant transport
This commit is contained in:
+17
-3
@@ -13,12 +13,26 @@ public interface UnifiedInboundTransportMapper {
|
|||||||
@Select("""
|
@Select("""
|
||||||
<script>
|
<script>
|
||||||
SELECT DISTINCT i.inbound_id, i.account_id, p.container_booking_id,
|
SELECT DISTINCT i.inbound_id, i.account_id, p.container_booking_id,
|
||||||
b.container_no, b.cabinet_no, b.vessel_name, b.voyage_no,
|
b.container_no, b.cabinet_no,
|
||||||
b.estimated_sailing_at, b.actual_sailing_at,
|
COALESCE(schedule.vessel_name, b.vessel_name) AS vessel_name,
|
||||||
b.estimated_port_arrival_at, b.actual_port_arrival_at
|
COALESCE(schedule.voyage_no, b.voyage_no) AS voyage_no,
|
||||||
|
COALESCE(schedule.etd_at, b.estimated_sailing_at) AS estimated_sailing_at,
|
||||||
|
b.actual_sailing_at,
|
||||||
|
COALESCE(schedule.eta_at, b.estimated_port_arrival_at) AS estimated_port_arrival_at,
|
||||||
|
b.actual_port_arrival_at
|
||||||
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
|
||||||
|
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
|
||||||
|
)
|
||||||
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
|
||||||
|
|||||||
Reference in New Issue
Block a user