This commit is contained in:
2026-08-13 19:19:29 +08:00
parent cca1bc002e
commit 808fabaf41
11 changed files with 176 additions and 37 deletions
@@ -70,15 +70,22 @@ export async function run(context) {
context.assert(MODULE, '订舱存在匹配本轮柜型的箱型需求', changed,
Boolean(requirement?.id), `requirementId=${id(requirement?.id) || 'missing'}`, OPTIONS)
if (!requirement?.id || id(containerFlow?.tenantId) !== id(changeConfirmed?.oceanBooking?.customerId)) return
const allocation = await request(context, 'POST', `${path}/allocations`, {
requirementId: id(requirement.id), containerBookingId: id(containerFlow.containerBookingId), expectedVersion: version,
}, { 'Idempotency-Key': `${context.marker}-ocean-container-allocation`.slice(0, 128) })
const allocated = context.apiSuccess(MODULE, '放舱前分配本轮柜次', allocation, '', OPTIONS)
version = Number(allocated?.oceanBooking?.version)
context.assert(MODULE, '订舱柜次分配持久化且版本递增', allocation,
allocated?.containerAllocations?.some?.((item) => id(item?.containerBookingId) === id(containerFlow.containerBookingId))
&& Number.isInteger(version),
`containerBookingId=${id(containerFlow.containerBookingId)}, version=${version}`, OPTIONS)
const existingAllocation = changeConfirmed?.containerAllocations?.find?.(
(item) => id(item?.containerBookingId) === id(containerFlow.containerBookingId))
if (existingAllocation) {
context.assert(MODULE, '确认订舱已自动关联本轮柜次', changed, true,
`containerBookingId=${id(containerFlow.containerBookingId)}`, OPTIONS)
} else {
const allocation = await request(context, 'POST', `${path}/allocations`, {
requirementId: id(requirement.id), containerBookingId: id(containerFlow.containerBookingId), expectedVersion: version,
}, { 'Idempotency-Key': `${context.marker}-ocean-container-allocation`.slice(0, 128) })
const allocated = context.apiSuccess(MODULE, '放舱前分配本轮柜次', allocation, '', OPTIONS)
version = Number(allocated?.oceanBooking?.version)
context.assert(MODULE, '订舱柜次分配持久化且版本递增', allocation,
allocated?.containerAllocations?.some?.((item) => id(item?.containerBookingId) === id(containerFlow.containerBookingId))
&& Number.isInteger(version),
`containerBookingId=${id(containerFlow.containerBookingId)}, version=${version}`, OPTIONS)
}
}
const released = await request(context, 'POST', `${path}/release`, {
expectedVersion: version, billOfLadingNo: `BL-${suffix}`, vesselName: `放舱船-${suffix}`,