This commit is contained in:
2026-08-28 09:19:18 +08:00
parent e72ac14425
commit a719a903cd
10 changed files with 174 additions and 50 deletions
@@ -270,6 +270,43 @@ async function awaitProducerConsumption(context, producers) {
return expected.every((containerNo) => consumed.has(containerNo))
}
async function convertReceivingContainers(context, producers) {
for (const producer of producers) {
const containerNo = id(producer?.containerNo)
const summaryResponse = await context.requestOverseas('GET',
`/api/platform/v1/last-leg/orders/container-summaries?page=1&size=20&containerNo=${encodeURIComponent(containerNo)}`,
undefined, {}, context.overseasToken)
const summaries = success(summaryResponse) && Array.isArray(summaryResponse.body?.data?.records)
? summaryResponse.body.data.records : []
const summary = summaries.find((item) => id(item?.containerNo) === containerNo)
context.addStep(MODULE, `读取待分配柜级摘要 ${containerNo}`, summaryResponse,
Boolean(summary?.eligible && nonBlank(summary?.sourceContainerBookingId)
&& Number(summary?.inboundCodeCount) > 0),
`sourceContainerBookingId=${id(summary?.sourceContainerBookingId) || 'missing'}, eligible=${summary?.eligible === true}, inboundCodes=${summary?.inboundCodeCount ?? 'missing'}; ${trace(summaryResponse)}`, OPTIONS)
if (!summary?.eligible || !nonBlank(summary?.sourceContainerBookingId)) return false
const body = { sourceContainerBookingId: id(summary.sourceContainerBookingId) }
const key = `${context.marker}-pda-convert-${containerNo}`.slice(0, 128)
const convertedResponse = await context.requestOverseas('POST',
'/api/platform/v1/last-leg/inbound-plans/convert-container', body,
{ 'Idempotency-Key': key }, context.overseasToken)
const plans = success(convertedResponse) && Array.isArray(convertedResponse.body?.data)
? convertedResponse.body.data : []
context.addStep(MODULE, `整柜转换为逐入仓码独立计划 ${containerNo}`, convertedResponse,
plans.length === Number(summary.inboundCodeCount)
&& plans.every((item) => nonBlank(item?.planNo) && Array.isArray(item?.lines) && item.lines.length > 0),
`plans=${plans.length}, expected=${summary.inboundCodeCount}; ${trace(convertedResponse)}`, OPTIONS)
if (plans.length !== Number(summary.inboundCodeCount)) return false
const replayResponse = await context.requestOverseas('POST',
'/api/platform/v1/last-leg/inbound-plans/convert-container', body,
{ 'Idempotency-Key': key }, context.overseasToken)
context.addStep(MODULE, `整柜转换幂等重放零新增 ${containerNo}`, replayResponse,
success(replayResponse) && JSON.stringify(replayResponse.body?.data) === JSON.stringify(plans),
trace(replayResponse), OPTIONS)
if (!success(replayResponse)) return false
}
return true
}
async function awaitPickupReadyCandidates(context, token, producers, allProducers) {
const expected = [...new Set(producers.map((item) => id(item?.containerNo)).filter(nonBlank))]
const expectedSet = new Set(expected)
@@ -293,16 +330,11 @@ async function awaitPickupReadyCandidates(context, token, producers, allProducer
const missingPickupReady = expected.filter((containerNo) => !seen.has(containerNo))
const unexpectedAwaiting = awaiting.filter((containerNo) => seen.has(containerNo))
const unexpectedHistorical = [...seen].filter((containerNo) => !known.has(containerNo))
const targetContainerNo = id(context.createdResources?.phase3Loading?.containerNo)
const carrierQuery = context.createdResources?.phase3CarrierScheduleQuery
const pickup = context.createdResources?.phase4CarrierPickupReady
const targetCorrelated = nonBlank(targetContainerNo) && expectedSet.has(targetContainerNo)
&& seen.has(targetContainerNo) && carrierQuery?.marker === context.marker
&& id(carrierQuery?.trackingNo) === targetContainerNo && pickup?.marker === context.marker
&& pickup?.ready === true && id(pickup?.queryId) === id(carrierQuery?.queryId)
const targetCorrelated = producers.every((item) => item?.shippingReady === true
&& nonBlank(item?.carrierScheduleQueryId) && seen.has(id(item?.containerNo)))
const ready = missingPickupReady.length === 0 && unexpectedAwaiting.length === 0 && targetCorrelated
context.addStep(MODULE, '实际处理柜全部达到PICKUP_READY并进入PDA候选', response, ready,
`targetContainerNo=${targetContainerNo || 'missing'}, targetCorrelated=${targetCorrelated}, expected=${expected.join('|')}, awaiting=${awaiting.join('|') || 'none'}, seenExpected=${seenExpected.join('|') || 'none'}, missingPickupReady=${missingPickupReady.join('|') || 'none'}, unexpectedAwaiting=${unexpectedAwaiting.join('|') || 'none'}, unexpectedHistorical=${unexpectedHistorical.join('|') || 'none'}; ${trace(response)}`, OPTIONS)
`targetCorrelated=${targetCorrelated}, expected=${expected.join('|')}, awaiting=${awaiting.join('|') || 'none'}, seenExpected=${seenExpected.join('|') || 'none'}, missingPickupReady=${missingPickupReady.join('|') || 'none'}, unexpectedAwaiting=${unexpectedAwaiting.join('|') || 'none'}, unexpectedHistorical=${unexpectedHistorical.join('|') || 'none'}; ${trace(response)}`, OPTIONS)
return ready
}
@@ -639,6 +671,11 @@ export async function run(context) {
.filter((item) => nonBlank(item?.containerNo))
const allProducers = Array.isArray(matrix?.containers) ? matrix.containers : producers
if (allProducers.length) await awaitProducerConsumption(context, allProducers)
if (producers.length && !(await convertReceivingContainers(context, producers))) {
blockerGap(context, '实际处理柜整柜转换门禁',
'目标柜未能通过正式平台convert-container逐入仓码生成独立计划')
return
}
if (producers.length && !(await awaitPickupReadyCandidates(context, primary.token, producers, allProducers))) {
blockerGap(context, '实际处理柜PICKUP_READY门禁',
'Dropship/FBA与OVERSEAS实际处理柜尚未全部达到PICKUP_READY;跨区消费已独立验证,不回退处理历史柜')