This commit is contained in:
2026-08-11 18:43:50 +08:00
parent e1487162a5
commit bc5d9a6215
25 changed files with 1424 additions and 28 deletions
@@ -200,12 +200,22 @@ export async function run(context) {
claimedPlan?.status === 'LOADING' && Number(claimedPlan?.version) === Number(pushed?.version) + 1,
`status=${claimedPlan?.status || 'missing'}, version=${claimedPlan?.version ?? 'missing'}`, OPTIONS)
const inventoryResponse = await context.request('GET',
`${PDA}/tasks/${taskId}/inventory-snapshot?warehouseId=${encodeURIComponent(warehouseId)}`)
const inventory = context.apiSuccess(MODULE, '读取 PDA 提交前实时库存快照', inventoryResponse, '', OPTIONS)
context.assert(MODULE, '实时库存快照包含稳定令牌和可用箱数', inventoryResponse,
typeof inventory?.snapshotToken === 'string' && inventory.snapshotToken.length === 64
&& inventory?.inbounds?.some?.((item) => Number(item.availablePackageCount) >= 1),
`token=${inventory?.snapshotToken ? 'present' : 'missing'}, inboundCount=${inventory?.inbounds?.length ?? 0}`, OPTIONS)
if (!inventory?.snapshotToken) return
const batchPath = `${PDA}/tasks/${taskId}/batch`
const batchItems = [{ itemId: id(pickItem.id), action: 'PICK', pickedPackageCount: 1,
finalPickedPackageCount: null, releaseMode: 'MANUAL', locationIds: [],
version: Number(pickItem.version), reason: null }]
const staleBatchResponse = await request(context, 'POST', batchPath, {
warehouseId, containerNo, expectedVersion: Number(task.version) + 1, items: batchItems,
warehouseId, containerNo, expectedVersion: Number(task.version) + 1,
inventorySnapshotToken: inventory.snapshotToken, items: batchItems,
}, { 'Idempotency-Key': `${context.marker}-pda-batch-stale`.slice(0, 128) })
context.addStep(MODULE, 'PDA batch 旧任务版本返回 A0409', staleBatchResponse,
staleBatchResponse.http === 200 && ['A0409', '409'].includes(codeOf(staleBatchResponse)),
@@ -222,7 +232,8 @@ export async function run(context) {
&& afterFailedItem?.itemStatus === pickItem.itemStatus,
`taskVersion=${afterFailedBatch?.version ?? 'missing'}, itemVersion=${afterFailedItem?.version ?? 'missing'}, picked=${afterFailedItem?.pickedPackageCount ?? 'missing'}`, OPTIONS)
const batchPayload = { warehouseId, containerNo, expectedVersion: Number(task.version), items: batchItems }
const batchPayload = { warehouseId, containerNo, expectedVersion: Number(task.version),
inventorySnapshotToken: inventory.snapshotToken, items: batchItems }
const batchHeaders = { 'Idempotency-Key': `${context.marker}-pda-batch`.slice(0, 128) }
const pickResponse = await request(context, 'POST', batchPath, batchPayload, batchHeaders)
const picked = context.apiSuccess(MODULE, '单次调用 PDA 原子 batch 完成拣货', pickResponse, '', OPTIONS)