2026-09-29 17:56:00 +08:00
|
|
|
import { http, unwrapApiResponse, type ApiEnvelope } from '@/shared/api/http'
|
|
|
|
|
|
2026-09-15 15:53:03 +08:00
|
|
|
|
|
|
|
|
export interface ContainerArrivalTime {
|
|
|
|
|
sourceContainerBookingId: string
|
|
|
|
|
estimatedWarehouseArrivalAt: string | null
|
|
|
|
|
actualWarehouseArrivalAt: string | null
|
|
|
|
|
version: number
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const queryPath = '/platform/v1/last-leg/orders/container-arrival-times/query'
|
|
|
|
|
|
|
|
|
|
function operationId(containerBookingId: string) {
|
|
|
|
|
return `container-expected-arrival-${containerBookingId}-${Date.now()}-${crypto.randomUUID()}`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function listContainerArrivalTimes(sourceContainerBookingIds: string[]) {
|
|
|
|
|
if (!sourceContainerBookingIds.length) return []
|
2026-09-29 17:56:00 +08:00
|
|
|
const response = await http.post<ApiEnvelope<ContainerArrivalTime[]>, ApiEnvelope<ContainerArrivalTime[]>>(
|
2026-09-15 15:53:03 +08:00
|
|
|
queryPath,
|
|
|
|
|
{ sourceContainerBookingIds },
|
|
|
|
|
)
|
|
|
|
|
return (unwrapApiResponse(response) || []).map((item) => ({ ...item, version: Number(item.version || 0) }))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function updateContainerExpectedArrival(
|
|
|
|
|
sourceContainerBookingId: string,
|
|
|
|
|
body: { estimatedWarehouseArrivalAt: string; expectedVersion: number; remark?: string },
|
|
|
|
|
) {
|
2026-09-29 17:56:00 +08:00
|
|
|
const response = await http.put<ApiEnvelope<ContainerArrivalTime>, ApiEnvelope<ContainerArrivalTime>>(
|
2026-09-15 15:53:03 +08:00
|
|
|
`/platform/v1/last-leg/orders/container-summaries/${encodeURIComponent(sourceContainerBookingId)}/expected-arrival`,
|
|
|
|
|
body,
|
|
|
|
|
{ headers: { 'Idempotency-Key': operationId(sourceContainerBookingId) } },
|
|
|
|
|
)
|
|
|
|
|
const result = unwrapApiResponse(response)
|
|
|
|
|
return { ...result, version: Number(result.version || 0) }
|
|
|
|
|
}
|