This commit is contained in:
2026-09-20 19:48:49 +08:00
parent 93b58fdd6d
commit db07111e63
3 changed files with 37 additions and 3 deletions
@@ -104,6 +104,25 @@ export async function run(context) {
`appointmentId=${appointmentId || 'missing'}, oceanBookingId=${appointment?.oceanBookingId || 'missing'}, containerBookingId=${appointment?.containerBookingId || 'n/a'}, loadingPlanId=${appointment?.loadingPlanId || 'n/a'}, version=${appointment?.version ?? 'missing'}`, OPTIONS)
if (!appointmentId) return
const path = `${TRUCK}/${appointmentId}`
// This consumer can run after all booking containers have departed. Creation then
// completes the appointment transactionally; trying SUBMIT would be an illegal reversal.
if (appointment.status === 'COMPLETED') {
const currentResponse = await context.request('GET', path)
const current = context.apiSuccess(MODULE, '回查离仓后创建拖车的自动完成状态', currentResponse, '', OPTIONS)
const historyResponse = await context.request('GET', `${path}/history`)
const history = context.apiSuccess(MODULE, '回查拖车自动完成权威历史', historyResponse, '', OPTIONS)
const verified = current?.status === 'COMPLETED' && id(current.oceanBookingId) === id(ocean.id)
&& Array.isArray(history) && history.some(row => row.action === 'CREATE' && id(row.appointmentId) === appointmentId)
&& history.some(row => row.action === 'AUTO_COMPLETE' && row.toStatus === 'COMPLETED'
&& id(row.appointmentId) === appointmentId && Boolean(row.createdAt))
context.assert(MODULE, '订舱已全部离仓时拖车自动完成且不逆向提交', currentResponse, verified,
`appointmentId=${appointmentId}, status=${current?.status || 'missing'}`, OPTIONS)
if (verified) context.createdResources.serviceCenterFlow = {
marker: context.marker, appointmentId, oceanBookingId: ocean.id, finalStatus: 'COMPLETED',
completionMode: 'AUTO_COMPLETE_AFTER_DEPARTURE',
}
return
}
const dispatchUpload = await uploadDispatchOrder(context, appointmentId)
const dispatchAttachment = context.apiSuccess(MODULE, '跨服务拖车上传有效派车单附件', dispatchUpload, '', OPTIONS)
if (!dispatchAttachment?.id) return