function text(value) { return value == null ? '' : String(value).trim() } export async function resolveOceanBookingMaster(context, module) { const resources = context.createdResources || {} const candidates = [resources.phase3Loading, resources.phase3ContainerLoading, resources.orchestrationFixtures?.phase3Container, resources.inboundMeasurement, resources.orders].filter(Boolean) const source = candidates.find((item) => item.marker === context.marker) || candidates[0] const tenantId = text(source?.tenantId || source?.customerId) const inboundId = text(source?.inboundId) let summary = source?.summary || null if (inboundId && typeof context.request === 'function') { const response = await context.request('GET', `/api/platform/inbounds/${encodeURIComponent(inboundId)}?tenantId=${encodeURIComponent(tenantId)}`) if (response?.body?.code === '200') summary = response.body.data?.summary || summary } const master = { customerId: text(summary?.tenantId || tenantId), customerName: text(summary?.customerName || source?.customerName), channelCode: text(summary?.channelCode || source?.channelCode), channelName: text(summary?.channelName || source?.channelName), warehouseId: text(summary?.warehouseId || source?.warehouseId || source?.receivingWarehouseId), warehouseName: text(summary?.warehouseName || source?.warehouseName), } const missing = ['customerId', 'customerName', 'channelCode', 'channelName', 'warehouseId', 'warehouseName'] .filter((key) => !master[key]) if (missing.length) { context.addStep(module, '订舱 fixture 使用本轮正式客户/渠道/仓库主数据', null, false, `marker=${context.marker}, inboundId=${inboundId || 'missing'}, missing=${missing.join(',')}`, { scenario: 'ocean-booking-master-data', deploymentBlocker: true }) return null } return master } export function oceanBookingDraft(context, suffix, master, labels = {}) { return { ...master, shippingCompanyId: null, shippingCompanyName: labels.shippingCompanyName || `验收船公司-${suffix}`, bookingAgentId: null, bookingAgentName: labels.bookingAgentName || `验收代理-${suffix}`, vesselName: labels.vesselName || `验收船-${suffix}`, voyageNo: labels.voyageNo || `V${suffix}`, departurePortCode: 'CNSZX', departurePortName: '深圳', destinationPortCode: 'USLAX', destinationPortName: '洛杉矶', placeOfDelivery: 'LAX', serviceTerm: 'CY/CY', freightTerm: 'PREPAID', estimatedSailingAt: labels.estimatedSailingAt, estimatedArrivalAt: labels.estimatedArrivalAt, remark: context.marker, parties: [{ partyType: 'SHIPPER', partyName: `发货方-${suffix}` }, { partyType: 'CONSIGNEE', partyName: `收货方-${suffix}` }, { partyType: 'NOTIFY_PARTY', partyName: `通知方-${suffix}` }], containerRequirements: [{ containerType: '40HQ', containerKind: 'FCL', capacityCbm: 68, maxWeightKg: 28000, quantity: 1 }], } }