优化
This commit is contained in:
@@ -62,6 +62,7 @@ export async function run(context) {
|
||||
const changed = await request(context, 'POST', `${path}/change-request`, { expectedVersion: version, vesselName: `改船-${suffix}`, voyageNo: `CV${suffix}`, reason: context.marker }, { 'Idempotency-Key': `${context.marker}-change` })
|
||||
context.apiSuccess(MODULE, '申请改船', changed, '', OPTIONS); version = Number(data(changed)?.oceanBooking?.version)
|
||||
const changeConfirmed = await action('确认改船', 'change-confirm', version, 'confirm change')
|
||||
let allocatedContainerBookingId = id(changeConfirmed?.containerAllocations?.[0]?.containerBookingId)
|
||||
if (containerFlow?.finalStatus === 'COMPLETED' || containerFlow?.finalStatus === 'LOADED') {
|
||||
context.assert(MODULE, '订舱与本轮柜次客户归属一致', changed,
|
||||
id(containerFlow?.tenantId) === id(changeConfirmed?.oceanBooking?.customerId),
|
||||
@@ -70,22 +71,9 @@ 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 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)
|
||||
}
|
||||
context.assert(MODULE, '确认订舱自动生成并关联柜次', changed,
|
||||
Boolean(allocatedContainerBookingId) && Number.isInteger(version),
|
||||
`containerBookingId=${allocatedContainerBookingId || 'missing'}, version=${version}`, OPTIONS)
|
||||
}
|
||||
const released = await request(context, 'POST', `${path}/release`, {
|
||||
expectedVersion: version, billOfLadingNo: `BL-${suffix}`, vesselName: `放舱船-${suffix}`,
|
||||
@@ -99,12 +87,12 @@ export async function run(context) {
|
||||
context.apiSuccess(MODULE, '回查 RELEASED 订舱详情', final, '', OPTIONS)
|
||||
context.assert(MODULE, '订舱状态历史、审计操作者、柜次关联和终态完整', final,
|
||||
fd?.oceanBooking?.status === 'RELEASED' && fd.histories?.length >= 5 && fd.histories.every((h) => h.operatorName)
|
||||
&& (!containerFlow || fd?.containerAllocations?.some?.((item) => id(item?.containerBookingId) === id(containerFlow.containerBookingId))),
|
||||
&& fd?.containerAllocations?.some?.((item) => id(item?.containerBookingId) === allocatedContainerBookingId),
|
||||
`status=${fd?.oceanBooking?.status || 'missing'}, histories=${fd?.histories?.length ?? 'n/a'}, allocations=${fd?.containerAllocations?.length ?? 'n/a'}`, OPTIONS)
|
||||
context.createdResources.oceanBooking = {
|
||||
id: bookingId, customerId: id(fd?.oceanBooking?.customerId), marker: context.marker,
|
||||
containerBookingId: containerFlow ? id(containerFlow.containerBookingId) : null,
|
||||
loadingPlanId: containerFlow ? id(containerFlow.loadingPlanId) : null,
|
||||
containerBookingId: allocatedContainerBookingId || null,
|
||||
loadingPlanId: null,
|
||||
finalStatus: fd?.oceanBooking?.status || null,
|
||||
}
|
||||
const missingDetail = await request(context, 'GET', `${BASE}/999999999999999999`)
|
||||
|
||||
Reference in New Issue
Block a user