This commit is contained in:
2026-08-13 16:14:54 +08:00
parent 8bcd23f307
commit 226ef6a839
20 changed files with 486 additions and 58 deletions
@@ -3,6 +3,7 @@ const OPTIONS = { scenario: 'carrier-schedule-query-policy', deploymentBlocker:
const BASE = '/api/platform/v1/carrier-schedule-queries'
const OCEAN = '/api/platform/v1/ocean-bookings'
const PORT = '/api/platform/v1/port-schedules'
import { resolveOceanBookingMaster, oceanBookingDraft } from './ocean-booking-fixture.mjs'
function id(value) { return value == null ? '' : String(value) }
export function matchesManualScheduleScope(resource, expected) {
@@ -38,40 +39,40 @@ async function request(context, method, path, body, headers = {}) {
}
}
function oceanDraft(context, suffix) {
function oceanDraft(context, suffix, master) {
return {
customerId: '10001', customerName: `船司查询客户-${suffix}`, billOfLadingNo: `CSQ-BL-${suffix}`,
...oceanBookingDraft(context, suffix, master),
shippingCompanyName: 'ZIM', bookingAgentName: `船司查询代理-${suffix}`,
vesselName: `船司查询船-${suffix}`, voyageNo: `CQ${suffix}`, departurePortCode: 'CNSZX',
departurePortCode: 'CNSZX',
departurePortName: '深圳', destinationPortCode: 'USLAX', destinationPortName: '洛杉矶',
placeOfDelivery: 'LAX', serviceTerm: 'CY/CY', freightTerm: 'PREPAID',
estimatedSailingAt: at(7 * 24 * 60), estimatedArrivalAt: at(28 * 24 * 60), remark: context.marker,
remark: context.marker,
parties: [
{ partyType: 'SHIPPER', partyName: `发货方-${suffix}` },
{ partyType: 'CONSIGNEE', partyName: `收货方-${suffix}` },
{ partyType: 'NOTIFY_PARTY', partyName: `通知方-${suffix}` },
],
containerRequirements: [{ containerType: '40HQ', containerKind: 'FCL', quantity: 1 }],
containerRequirements: [{ containerType: '40HQ', containerKind: 'FCL', capacityCbm: 68, maxWeightKg: 28000, quantity: 1 }],
}
}
async function ensureOcean(context, suffix) {
async function ensureOcean(context, suffix, master) {
const existing = context.createdResources?.oceanBooking
if (existing?.id && id(existing.customerId || '10001') === '10001') return { id: id(existing.id), containerBookingId: null }
const response = await request(context, 'POST', OCEAN, { expectedVersion: 0, data: oceanDraft(context, suffix) },
if (existing?.id && id(existing.customerId) === id(master.customerId)) return { id: id(existing.id), containerBookingId: null }
const response = await request(context, 'POST', OCEAN, { expectedVersion: 0, data: oceanDraft(context, suffix, master) },
{ 'Idempotency-Key': `${context.marker}-carrier-query-ocean`.slice(0, 128) })
const detail = context.apiSuccess(MODULE, '创建船司查询隔离订舱', response, '', OPTIONS)
return { id: id(detail?.oceanBooking?.id), containerBookingId: null }
}
async function createManualSchedule(context, suffix, oceanBookingId) {
async function createManualSchedule(context, suffix, oceanBookingId, customerId) {
const existing = context.createdResources?.portSchedule
const expectedScope = { customerId: '10001', oceanBookingId, containerBookingId: null }
const expectedScope = { customerId, oceanBookingId, containerBookingId: null }
if (matchesManualScheduleScope(existing, expectedScope)) return id(existing.id)
const body = {
expectedVersion: 0,
data: {
customerId: '10001', oceanBookingId, containerBookingId: null, sourceType: 'MANUAL',
customerId, oceanBookingId, containerBookingId: null, sourceType: 'MANUAL',
sourceName: `船司查询人工兜底-${suffix}`, sourceRef: `${context.marker}-CARRIER-MANUAL`,
vesselName: `人工船期船-${suffix}`, voyageNo: `CM${suffix}`, departurePortCode: 'CNSZX',
departurePortName: '深圳', destinationPortCode: 'USLAX', destinationPortName: '洛杉矶',
@@ -106,10 +107,12 @@ export async function run(context) {
&& [...byCode.values()].every((item) => item.officialUrl?.startsWith('http') && item.automated === false),
`codes=${[...byCode.keys()].join(',') || 'missing'}`, OPTIONS)
const ocean = await ensureOcean(context, suffix)
const master = await resolveOceanBookingMaster(context, MODULE)
if (!master) return
const ocean = await ensureOcean(context, suffix, master)
if (!ocean.id) return
const createBody = {
expectedVersion: 0, customerId: '10001', oceanBookingId: ocean.id,
expectedVersion: 0, customerId: master.customerId, oceanBookingId: ocean.id,
containerBookingId: ocean.containerBookingId, carrierCode: 'ZIM', trackingType: 'BILL_OF_LADING',
trackingNo: `${context.marker}-ZIM`, remark: context.marker,
}
@@ -167,7 +170,7 @@ export async function run(context) {
forgedCustomer.http === 200 && ['A0400', '400'].includes(codeOf(forgedCustomer)),
`HTTP=${forgedCustomer.http}, code=${codeOf(forgedCustomer)}`)
const scheduleId = await createManualSchedule(context, suffix, ocean.id)
const scheduleId = await createManualSchedule(context, suffix, ocean.id, master.customerId)
if (!scheduleId) return
const manual = await request(context, 'POST', `${BASE}/${queryId}/manual-results`,
{ expectedVersion: version, portScheduleId: scheduleId, reason: '人工完成官网查询并复核船期' },