Files
admin-web/src/modules/container-loading/api/containerArrivalTimes.ts
T

48 lines
2.0 KiB
TypeScript
Raw Normal View History

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
2026-10-21 15:49:35 +08:00
planCount: number
plannedDate?: string | null
isDefault?: boolean
2026-10-21 15:49:35 +08:00
}
function normalizeArrival(item: ContainerArrivalTime): ContainerArrivalTime {
if (typeof item.planCount !== 'number' && (typeof item.planCount !== 'string' || !/^(0|[1-9]\d*)$/.test(item.planCount))) throw new Error('到仓记录的入库计划数量无效,请刷新后重试')
const count = Number(item.planCount)
if (item.planCount == null || !Number.isSafeInteger(count) || count < 0) throw new Error('到仓记录的入库计划数量无效,请刷新后重试')
return { ...item, version: Number(item.version), planCount: count }
2026-09-15 15:53:03 +08:00
}
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 },
)
2026-10-21 15:49:35 +08:00
return (unwrapApiResponse(response) || []).map(normalizeArrival)
2026-09-15 15:53:03 +08:00
}
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)
2026-10-21 15:49:35 +08:00
return normalizeArrival(result)
2026-09-15 15:53:03 +08:00
}