|
|
|
@@ -7,6 +7,7 @@ import { iso6346ContainerNumber } from './iso6346-container-number.mjs'
|
|
|
|
|
const MODULE = 'phase3-container-loading'
|
|
|
|
|
const OPTIONS = { scenario: 'phase3-container-smart-loading-pda', deploymentBlocker: true }
|
|
|
|
|
const CONTAINERS = '/api/platform/v1/containers'
|
|
|
|
|
const DOMESTIC_CONTAINERS = `${CONTAINERS}/domestic`
|
|
|
|
|
const SMART = '/api/platform/v1/first-leg/smart-loading'
|
|
|
|
|
const PDA = '/api/platform/v1/first-leg/pda-loading'
|
|
|
|
|
const FIRST_LEG = '/api/platform/v1/first-leg'
|
|
|
|
@@ -21,6 +22,7 @@ function failure(response) {
|
|
|
|
|
|| (response?.http === 200 && codeOf(response) !== '200')
|
|
|
|
|
}
|
|
|
|
|
function records(page) { return Array.isArray(page?.records) ? page.records : [] }
|
|
|
|
|
function containerRecord(value) { return value?.container || value }
|
|
|
|
|
|
|
|
|
|
async function waitForCompletedTask(context, taskId, warehouseId, attempts = 45) {
|
|
|
|
|
let response = null
|
|
|
|
@@ -258,9 +260,8 @@ export async function run(context) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const containerDetailResponse = await context.request('GET', `${CONTAINERS}/domestic/${containerId}`)
|
|
|
|
|
const containerWorkbench = context.apiSuccess(MODULE, '回查货柜详情', containerDetailResponse, '', OPTIONS)
|
|
|
|
|
const containerDetail = containerWorkbench?.container
|
|
|
|
|
const containerDetailResponse = await context.request('GET', `${DOMESTIC_CONTAINERS}/${containerId}`)
|
|
|
|
|
const containerDetail = containerRecord(context.apiSuccess(MODULE, '回查货柜详情', containerDetailResponse, '', OPTIONS))
|
|
|
|
|
context.assert(MODULE, '货柜详情保留候选货物路线约束', containerDetailResponse,
|
|
|
|
|
(!containerDetail?.destinationWarehouseCode || !candidate.destinationWarehouseCode
|
|
|
|
|
|| containerDetail.destinationWarehouseCode === candidate.destinationWarehouseCode)
|
|
|
|
@@ -399,9 +400,8 @@ export async function run(context) {
|
|
|
|
|
unlinkedTaskAbsent, responseEvidence(unlinkedTaskResponse), OPTIONS)
|
|
|
|
|
if (!unlinkedTaskAbsent) return
|
|
|
|
|
|
|
|
|
|
const simulationBeforeLinkResponse = await context.request('GET', `${CONTAINERS}/domestic/${containerId}`)
|
|
|
|
|
const simulationWorkbench = context.apiSuccess(MODULE, '预装确认前读取模拟柜最新版本', simulationBeforeLinkResponse, '', OPTIONS)
|
|
|
|
|
const simulationBeforeLink = simulationWorkbench?.container
|
|
|
|
|
const simulationBeforeLinkResponse = await context.request('GET', `${DOMESTIC_CONTAINERS}/${containerId}`)
|
|
|
|
|
const simulationBeforeLink = containerRecord(context.apiSuccess(MODULE, '预装确认前读取模拟柜最新版本', simulationBeforeLinkResponse, '', OPTIONS))
|
|
|
|
|
if (!Number.isInteger(Number(simulationBeforeLink?.version))) return
|
|
|
|
|
|
|
|
|
|
const bookingCreate = await request(context, 'POST', '/api/platform/v1/ocean-bookings',
|
|
|
|
@@ -473,11 +473,9 @@ export async function run(context) {
|
|
|
|
|
`containerBookingId=${containerId}, cabinetNo=${linkedContainer?.cabinetNo || 'missing'}, loadingPlanId=${id(afterLinkPlan?.id) || 'missing'}`, OPTIONS)
|
|
|
|
|
|
|
|
|
|
const activeContainersResponse = await context.request('GET',
|
|
|
|
|
`${CONTAINERS}/domestic?scope=ACTIVE&page=1&size=50&keyword=${encodeURIComponent(realContainerNo)}`)
|
|
|
|
|
const activeWorkbench = context.apiSuccess(MODULE, '关联后按真实柜号回查正常货柜列表', activeContainersResponse, '', OPTIONS)
|
|
|
|
|
const activeContainers = { ...activeWorkbench,
|
|
|
|
|
records: records(activeWorkbench).map((item) => item?.container).filter(Boolean) }
|
|
|
|
|
const activeRealRows = records(activeContainers).filter((item) => item.containerNo === realContainerNo)
|
|
|
|
|
`${DOMESTIC_CONTAINERS}?page=1&size=50&scope=ACTIVE&keyword=${encodeURIComponent(realContainerNo)}`)
|
|
|
|
|
const activeContainers = context.apiSuccess(MODULE, '关联后按真实柜号回查正常货柜列表', activeContainersResponse, '', OPTIONS)
|
|
|
|
|
const activeRealRows = records(activeContainers).map(containerRecord).filter((item) => item.containerNo === realContainerNo)
|
|
|
|
|
context.assert(MODULE, '关联后列表仅保留模拟柜原地补全的一条 ACTIVE 操作身份', activeContainersResponse,
|
|
|
|
|
activeRealRows.length === 1 && id(activeRealRows[0]?.id) === containerId,
|
|
|
|
|
`activeIds=${activeRealRows.map((item) => id(item?.id)).join('|') || 'none'}`, OPTIONS)
|
|
|
|
@@ -593,9 +591,8 @@ export async function run(context) {
|
|
|
|
|
`taskId=${taskId || 'missing'}, itemId=${id(pickItem?.id) || 'missing'}`, OPTIONS)
|
|
|
|
|
if (!taskId || !pickItem?.id) return
|
|
|
|
|
|
|
|
|
|
const releasedContainerResponse = await context.request('GET', `${CONTAINERS}/domestic/${containerId}`)
|
|
|
|
|
const releasedWorkbench = context.apiSuccess(MODULE, '任务生成后回查货柜运输版本', releasedContainerResponse, '', OPTIONS)
|
|
|
|
|
const releasedContainer = releasedWorkbench?.container
|
|
|
|
|
const releasedContainerResponse = await context.request('GET', `${DOMESTIC_CONTAINERS}/${containerId}`)
|
|
|
|
|
const releasedContainer = context.apiSuccess(MODULE, '任务生成后回查货柜运输版本', releasedContainerResponse, '', OPTIONS)
|
|
|
|
|
|
|
|
|
|
const stableIdentity = {
|
|
|
|
|
taskId, loadingPlanId: id(task.loadingPlanId), containerBookingId: id(task.containerBookingId),
|
|
|
|
|