优化
This commit is contained in:
@@ -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}`,
|
||||
|
||||
Reference in New Issue
Block a user