Files
2026-10-20 14:22:55 +08:00

40 lines
2.1 KiB
JavaScript

function count(value) {
const number = Number(value)
return Number.isFinite(number) ? number : NaN
}
export async function run(context) {
const module = 'self-operated-analytics'
const base = '/api/platform/v1/last-leg/self-operated-analytics'
const dashboardResponse = await context.request('GET', `${base}/dashboard`)
if (dashboardResponse.http === 200 && String(dashboardResponse.body?.code) === '200') {
const dashboard = context.apiSuccess(module, '查询自营经营看板', dashboardResponse)
context.assert(module, '经营看板六项指标与趋势结构完整', dashboardResponse,
dashboard && typeof dashboard === 'object'
&& (dashboard.metrics == null || Array.isArray(dashboard.metrics))
&& (dashboard.trend == null || Array.isArray(dashboard.trend)),
`keys=${Object.keys(dashboard || {}).length}`)
} else {
context.addCoverageGap(module, 'self-operated-analytics', '经营看板',
`需要本轮采集账号与仓库上下文;当前空参请求 HTTP=${dashboardResponse.http}, code=${dashboardResponse.body?.code ?? 'missing'}`,
'not-implemented', { blocking: false })
}
const ownersResponse = await context.request('GET', `${base}/owners?page=1&size=20`)
if (ownersResponse.http === 200 && String(ownersResponse.body?.code) === '200') {
const owners = context.apiSuccess(module, '查询自营货主目录', ownersResponse)
context.assert(module, '货主目录分页字段完整', ownersResponse,
owners && Array.isArray(owners.records) && Number.isFinite(count(owners.total)),
`total=${owners?.total ?? 'missing'}`)
} else {
context.addCoverageGap(module, 'self-operated-analytics', '货主目录',
`需要本轮采集账号上下文;HTTP=${ownersResponse.http}, code=${ownersResponse.body?.code ?? 'missing'}`,
'not-implemented', { blocking: false })
}
context.addCoverageGap(module, 'self-operated-analytics', '数据采集任务与重试',
'采集任务同步/重试依赖领星外部账号与真实采集批次;本模块只读核对看板与货主目录,缺账号时记录覆盖缺口',
'external-third-party', { blocking: false })
}