fix(phase3): close loading and dispatch flows

This commit is contained in:
2026-08-10 17:42:17 +08:00
parent 074a95d82b
commit 84209bffd7
19 changed files with 221 additions and 43 deletions
@@ -3,6 +3,7 @@ import { readFile } from 'node:fs/promises'
const MODULE = 'inbound-measurement'
const SCENARIO = 'mojia-carton-measurement'
const OPTIONS = { scenario: SCENARIO, deploymentBlocker: true }
const DEFAULT_PALLET_CAPACITY_CBM = 1.2
function asId(value) { return value == null ? '' : String(value) }
function asNumber(value) { return Number(value) }
@@ -23,6 +24,41 @@ function validPdf(response) {
&& response.bytes?.length > 4 && new TextDecoder().decode(response.bytes.slice(0, 4)) === '%PDF'
}
async function provisionWarehouseResources(context, { inboundId, warehouseId, totalVolumeCbm }) {
const palletCount = Math.ceil(Number(totalVolumeCbm) / DEFAULT_PALLET_CAPACITY_CBM)
if (!warehouseId || !Number.isFinite(palletCount) || palletCount < 1) return false
const suffix = `${String(context.marker).replace(/\D/g, '').slice(-8)}${String(inboundId).slice(-6)}`
const resources = []
for (let index = 1; index <= palletCount; index += 1) {
const resourceSuffix = `${suffix}${String(index).padStart(2, '0')}`
const palletResponse = await context.request('POST', '/api/platform/v1/pallets?tenantId=0', {
warehouseId, palletType: 'STANDARD', capacityCbm: DEFAULT_PALLET_CAPACITY_CBM,
weightKg: 8, color: '蓝色', remark: `${context.marker}-INBOUND-${inboundId}`,
})
const palletId = asId(context.apiSuccess(MODULE, `创建测量占用托盘 ${index}/${palletCount}`,
palletResponse, `warehouseId=${warehouseId}`, OPTIONS))
const locationResponse = await context.request('POST', '/api/platform/v1/locations?tenantId=0', {
warehouseId, zoneCode: `E2E-${String(context.marker).slice(-8)}`, zoneName: '自动化验收区',
locationCode: `E2E-${resourceSuffix}`, locationName: `测量验收库位-${index}`,
locationType: 'PALLET', maxWeightKg: 1000, status: 'AVAILABLE',
remark: `${context.marker}-INBOUND-${inboundId}`,
})
const locationId = asId(context.apiSuccess(MODULE, `创建测量占用库位 ${index}/${palletCount}`,
locationResponse, `warehouseId=${warehouseId}`, OPTIONS))
if (!palletId || !locationId) return false
resources.push({ palletId, locationId })
}
context.createdResources.inboundWarehouseResources ??= {}
context.createdResources.inboundWarehouseResources[inboundId] = {
marker: context.marker, tenantId: '0', warehouseId: asId(warehouseId), palletCount,
palletCapacityCbm: DEFAULT_PALLET_CAPACITY_CBM, resources,
}
return true
}
function findIsolatedInbound(context) {
const roots = [context.createdResources, context.context]
const visited = new Set()
@@ -311,6 +347,18 @@ export async function run(context) {
return
}
const warehouseResourcesReady = await provisionWarehouseResources(context, {
inboundId, warehouseId: asId(summary?.warehouseId), totalVolumeCbm: totalVolume,
})
context.assert(MODULE, '测量提交前已创建足量真实托盘和库位', draftResponse,
warehouseResourcesReady,
`warehouseId=${asId(summary?.warehouseId) || 'missing'}, palletCount=${Math.ceil(totalVolume / DEFAULT_PALLET_CAPACITY_CBM)}`,
OPTIONS)
if (!warehouseResourcesReady) {
finishScenario(context, start)
return
}
const submitResponse = await context.request('POST',
`/api/platform/v1/first-leg/inbounds/${inboundId}/measurement/submit?${query(tenantId)}`,
{ measurementId: draft.measurementId, version: Number(draft.version) })