优化
This commit is contained in:
@@ -57,7 +57,18 @@ function oceanDraft(context, suffix, master) {
|
||||
}
|
||||
|
||||
async function ensureOceanBooking(context, suffix, master) {
|
||||
if (context.createdResources?.oceanBooking?.id) return context.createdResources.oceanBooking
|
||||
if (context.createdResources?.oceanBooking?.id) {
|
||||
const existingId = id(context.createdResources.oceanBooking.id)
|
||||
const response = await request(context, 'GET', `${OCEAN}/${existingId}`)
|
||||
const detail = context.apiSuccess(MODULE, '读取船期关联订舱真实柜次分配', response,
|
||||
`oceanBookingId=${existingId}`, OPTIONS)
|
||||
return detail?.oceanBooking ? {
|
||||
id: existingId,
|
||||
customerId: id(detail.oceanBooking.customerId),
|
||||
allocatedContainerBookingIds: (detail.containerAllocations || [])
|
||||
.map((item) => id(item?.containerBookingId)).filter(Boolean),
|
||||
} : null
|
||||
}
|
||||
const response = await request(context, 'POST', OCEAN, { expectedVersion: 0, data: oceanDraft(context, suffix, master) },
|
||||
{ 'Idempotency-Key': `${context.marker}-port-ocean`.slice(0, 128) })
|
||||
const detail = context.apiSuccess(MODULE, '创建本轮隔离船期关联订舱', response, '', OPTIONS)
|
||||
@@ -65,7 +76,11 @@ async function ensureOceanBooking(context, suffix, master) {
|
||||
context.assert(MODULE, '船期关联订舱客户归属明确', response,
|
||||
Boolean(oceanBookingId) && id(detail?.oceanBooking?.customerId) === id(master.customerId),
|
||||
`oceanBookingId=${oceanBookingId || 'missing'}, customerId=${id(detail?.oceanBooking?.customerId) || 'missing'}`, OPTIONS)
|
||||
return oceanBookingId ? { id: oceanBookingId, customerId: master.customerId } : null
|
||||
return oceanBookingId ? {
|
||||
id: oceanBookingId, customerId: id(detail.oceanBooking.customerId),
|
||||
allocatedContainerBookingIds: (detail.containerAllocations || [])
|
||||
.map((item) => id(item?.containerBookingId)).filter(Boolean),
|
||||
} : null
|
||||
}
|
||||
|
||||
function scheduleData(context, suffix, oceanBookingId, containerBookingId, customerId, expired = false) {
|
||||
@@ -109,9 +124,15 @@ export async function run(context) {
|
||||
|| context.createdResources?.phase3ContainerLoading
|
||||
const containerBookingId = ['COMPLETED', 'LOADED'].includes(flow?.finalStatus)
|
||||
? id(flow.containerBookingId) : null
|
||||
const knownAllocation = context.createdResources?.oceanBooking?.id === ocean.id && containerBookingId
|
||||
? containerBookingId : null
|
||||
const payload = { expectedVersion: 0, data: scheduleData(context, suffix, ocean.id, knownAllocation, master.customerId), reason: context.marker }
|
||||
const knownAllocation = containerBookingId
|
||||
&& ocean.allocatedContainerBookingIds?.includes(containerBookingId) ? containerBookingId : null
|
||||
if (containerBookingId && !knownAllocation) {
|
||||
context.addStep(MODULE, '船期订舱真实分配包含本轮装货柜次', null, false,
|
||||
`oceanBookingId=${ocean.id}, containerBookingId=${containerBookingId}, allocations=${ocean.allocatedContainerBookingIds?.join(',') || 'none'}`,
|
||||
OPTIONS)
|
||||
return
|
||||
}
|
||||
const payload = { expectedVersion: 0, data: scheduleData(context, suffix, ocean.id, knownAllocation, ocean.customerId), reason: context.marker }
|
||||
const createKey = `${context.marker}-port-create`.slice(0, 128)
|
||||
const createResponse = await request(context, 'POST', BASE, payload, { 'Idempotency-Key': createKey })
|
||||
const created = context.apiSuccess(MODULE, '新增独立港务船期观测', createResponse, '', OPTIONS)
|
||||
@@ -135,7 +156,7 @@ export async function run(context) {
|
||||
`first=${scheduleId}, replay=${id(data(replay)?.portSchedule?.schedule?.id) || 'missing'}`, OPTIONS)
|
||||
|
||||
for (const [name, query] of [
|
||||
['按客户查询船期', `customerId=${encodeURIComponent(master.customerId)}`],
|
||||
['按客户查询船期', `customerId=${encodeURIComponent(ocean.customerId)}`],
|
||||
['按订舱查询船期', `oceanBookingId=${ocean.id}`],
|
||||
...(knownAllocation ? [['按柜次查询船期', `containerBookingId=${knownAllocation}`]] : []),
|
||||
]) {
|
||||
@@ -225,7 +246,7 @@ export async function run(context) {
|
||||
|
||||
const forged = await request(context, 'POST', BASE, {
|
||||
expectedVersion: 0,
|
||||
data: { ...scheduleData(context, `${suffix}X`, ocean.id, null, master.customerId), customerId: `${master.customerId}999` },
|
||||
data: { ...scheduleData(context, `${suffix}X`, ocean.id, null, ocean.customerId), customerId: `${ocean.customerId}999` },
|
||||
reason: '伪造客户归属',
|
||||
}, { 'Idempotency-Key': `${context.marker}-port-forged-customer`.slice(0, 128) })
|
||||
step(context, '伪造船期客户归属被拒绝', forged,
|
||||
|
||||
Reference in New Issue
Block a user