fix: complete overseas PDA inventory ledgers

This commit is contained in:
2026-09-02 01:47:00 +08:00
parent cc02037f78
commit 666add1cf9
8 changed files with 48 additions and 6 deletions
@@ -34,6 +34,19 @@ function receivingSnapshot(data) {
})
}
export function expandOverseasCartonCandidates(inbounds, producerCartonMarks = []) {
const marks = (Array.isArray(producerCartonMarks) ? producerCartonMarks : [producerCartonMarks])
.map(id).filter(nonBlank)
return inbounds.filter((item) => item?.destinationType === 'OVERSEAS').flatMap((inbound) => {
const patterns = marks.map((cartonMark) => ({ cartonMark, match: /^(.*)#(\d+)-(\d+)$/.exec(cartonMark) }))
.filter(({ match }) => match && match[1] === inbound.inboundCode)
const totals = [...new Set(patterns.map(({ match }) => Number(match[2]))
.filter((total) => Number.isSafeInteger(total) && total > 0 && total <= 2000))]
if (totals.length !== 1) return []
return Array.from({ length: totals[0] }, (_, index) => `${inbound.inboundCode}#${totals[0]}-${index + 1}`)
})
}
function blockerGap(context, name, reason, category = 'fixture-unavailable', response = null) {
context.addCoverageGap(MODULE, SCENARIO, name, reason, category, { deploymentBlocker: true })
context.assert(MODULE, `${name}覆盖前置`, response, false, reason, OPTIONS)
@@ -364,7 +377,7 @@ async function resolveCartonFixtures(context, token, inbounds, producerCartonMar
.map(id).filter(nonBlank)
const fbaCartons = inbounds.filter((item) => item.destinationType === 'FBA')
.map((item, index) => `${item.inboundCode}#PDA-CONTRACT-${index + 1}`)
const overseasCartons = inbounds.some((item) => item.destinationType === 'OVERSEAS') ? manifestCartons : []
const overseasCartons = expandOverseasCartonCandidates(inbounds, manifestCartons)
const cartonCandidates = [...new Set([...fbaCartons, ...overseasCartons])]
if (!cartonCandidates.length) {
blockerGap(context, '统一箱码解析链', 'FBA缺少当前柜入仓码或OVERSEAS缺少真实manifest箱码')
@@ -374,6 +387,12 @@ async function resolveCartonFixtures(context, token, inbounds, producerCartonMar
for (const [index, cartonMark] of cartonCandidates.entries()) {
const response = await context.requestOverseas('POST',
'/api/pda/v1/last-leg/receiving-containers/current/cartons/resolve', { cartonMark }, {}, token)
if (overseasCartons.includes(cartonMark)
&& a0404Message(response, /^Carton mark was not found$/)) {
context.addStep(MODULE, `排除未实装箱码候选${index + 1}`, response, true,
`cartonMark=${cartonMark}; ${trace(response)}`, OPTIONS)
continue
}
const resolved = response.body?.data
const matches = inbounds.filter((item) => item.inboundCode === resolved?.inboundCode)
const destinations = new Set(matches.map((item) => item?.destinationType).filter(nonBlank))
@@ -385,7 +404,7 @@ async function resolveCartonFixtures(context, token, inbounds, producerCartonMar
unique, `cartonMark=${cartonMark}, inboundCode=${resolved?.inboundCode || 'missing'}, matches=${matches.length}; ${trace(response)}`, OPTIONS)
if (!unique) {
blockerGap(context, `箱码${cartonMark}唯一归属`,
`FBA和OVERSEAS箱码resolve都必须HTTP 200/code 200并返回当前柜唯一入仓码;inboundCode=${resolved?.inboundCode || 'missing'}, matches=${matches.length}`,
`FBA箱码与OVERSEAS真实manifest箱码必须HTTP 200/code 200并返回当前柜唯一入仓码;inboundCode=${resolved?.inboundCode || 'missing'}, matches=${matches.length}`,
'fixture-mismatch', response)
return null
}