优化
This commit is contained in:
@@ -16,6 +16,12 @@ function nullableText(value) { return value == null || typeof value === 'string'
|
||||
function nullableId(value) { return value == null || Boolean(id(value)) }
|
||||
function nullableIso(value) { return value == null || (typeof value === 'string' && !Number.isNaN(Date.parse(value))) }
|
||||
|
||||
export function markerOwnedCarrierQuery(context) {
|
||||
const resource = context?.createdResources?.phase3CarrierScheduleQuery
|
||||
return resource?.ownedByModule === true && Boolean(id(resource.queryId)) && resource.marker === context?.marker
|
||||
? resource : null
|
||||
}
|
||||
|
||||
function validTask(task) {
|
||||
return Boolean(id(task?.id) && task?.queryNo && id(task?.customerId) && id(task?.oceanBookingId))
|
||||
&& QUERY_STATUSES.includes(task?.status)
|
||||
@@ -73,14 +79,15 @@ export async function run(context) {
|
||||
&& records.every((item) => typeof item?.expired === 'boolean' && validTask(item?.query)),
|
||||
`records=${records.length}, total=${page?.total ?? 'missing'}`, OPTIONS)
|
||||
|
||||
if (records.length === 0) {
|
||||
const ownedResource = markerOwnedCarrierQuery(context)
|
||||
if (records.length === 0 && !ownedResource) {
|
||||
context.assert(MODULE, '无真实任务时返回稳定分页空态', pageResponse,
|
||||
Number(page?.total) === 0 && Number(page?.pages) === 0,
|
||||
`records=0, total=${page?.total ?? 'missing'}, pages=${page?.pages ?? 'missing'}`, OPTIONS)
|
||||
return
|
||||
}
|
||||
|
||||
const queryId = id(records[0]?.query?.id)
|
||||
const queryId = ownedResource ? id(ownedResource.queryId) : id(records[0]?.query?.id)
|
||||
const detailResponse = await context.request('GET', `${BASE}/${encodeURIComponent(queryId)}`)
|
||||
const detail = context.apiSuccess(MODULE, '查询真实船节点任务详情', detailResponse, `queryId=${queryId}`, OPTIONS)
|
||||
const nodes = Array.isArray(detail?.nodes) ? detail.nodes : []
|
||||
@@ -94,6 +101,20 @@ export async function run(context) {
|
||||
`status=${detail?.query?.query?.status || 'missing'}, nodes=${nodes.length}, exceptions=${exceptions.length}, histories=${histories.length}`, OPTIONS)
|
||||
|
||||
const task = detail.query.query
|
||||
if (!ownedResource) {
|
||||
context.assert(MODULE, 'standalone无本轮marker资源时严格只读并跳过人工写', detailResponse,
|
||||
true, `readOnlyQueryId=${queryId}`, OPTIONS)
|
||||
const historyResponse = await context.request('GET', `${BASE}/${encodeURIComponent(queryId)}/history`)
|
||||
const history = context.apiSuccess(MODULE, '只读查询历史任务历史', historyResponse, `queryId=${queryId}`, OPTIONS)
|
||||
context.assert(MODULE, 'standalone历史详情只读且结构稳定', historyResponse,
|
||||
Array.isArray(history) && history.every(validHistory),
|
||||
`history=${Array.isArray(history) ? history.length : 'missing'}`, OPTIONS)
|
||||
return
|
||||
}
|
||||
const ownershipMatches = id(task?.id) === queryId && task?.trackingNo === ownedResource.trackingNo
|
||||
context.assert(MODULE, 'phase4写入目标严格匹配本轮phase3登记', detailResponse,
|
||||
ownershipMatches, `registered=${queryId}, actual=${id(task?.id) || 'missing'}`, OPTIONS)
|
||||
if (!ownershipMatches) return
|
||||
const observedAt = task.latestActualAt || '2026-08-21T00:00:00'
|
||||
const manualResponse = await context.request('POST', `${BASE}/${encodeURIComponent(queryId)}/manual-nodes`, {
|
||||
expectedVersion: task.version,
|
||||
|
||||
Reference in New Issue
Block a user