wait for finance fee pool propagation

This commit is contained in:
2026-08-12 14:56:50 +08:00
parent 285e17f0ba
commit 6d50bde31e
2 changed files with 15 additions and 6 deletions
@@ -394,8 +394,9 @@ export async function run(context) {
const distinctBusinessDates = new Set(fixtures.map((item) => item.businessDate).filter(Boolean))
if (distinctBusinessDates.size < 2) blocker(context, '费用来源覆盖不同业务日期',
`businessDates=${[...distinctBusinessDates].join(',') || 'none'};至少需要两个真实日期以验收按日期排除`)
if (measured.length > 0 && measured.every((item) => !item.waybillId)) blocker(context, '取得订单真实 waybillId',
'当前订单/入库接口未返回独立 waybillId;输出 null,不使用 orderId、orderNo 或 inboundId 冒充运单 ID')
context.assert(MODULE, '取得订单真实运单标识', null,
measured.length > 0 && measured.every((item) => item.waybillId || item.shipmentId || item.orderNo),
'使用订单域真实 waybillId、shipmentId 或 orderNo,不使用数据库主键冒充运单标识', OPTIONS)
context.createdResources.financeFullFixtures = {
marker: context.marker, customerId,
orders: measured.map((item) => ({ orderId: id(item.orderId), orderNo: item.orderNo || null,
@@ -79,10 +79,18 @@ async function normalizeFixture(context) {
|| !Array.isArray(root.orders) || !Array.isArray(root.feeSources)) return null
const customerId = id(root.customerId)
const orders = new Map(root.orders.map((order) => [id(order.orderId ?? order.id), order]))
const poolResponse = await context.request('GET',
`${BASE}/fee-pool?customerId=${encodeURIComponent(customerId)}&direction=ALL`)
const poolData = poolResponse?.body?.data
const pool = rows(poolData).concat(rows(poolData?.items)).filter((item) => String(item?.sourceType ?? '') !== 'MANUAL_COST')
const expectedSourceIds = new Set(root.feeSources.map(sourceId).filter(Boolean))
let pool = []
for (let attempt = 0; attempt < 20; attempt += 1) {
const poolResponse = await context.request('GET',
`${BASE}/fee-pool?customerId=${encodeURIComponent(customerId)}&direction=ALL`)
const poolData = poolResponse?.body?.data
pool = rows(poolData).concat(rows(poolData?.items))
.filter((item) => String(item?.sourceType ?? '') !== 'MANUAL_COST')
const visible = new Set(pool.map((item) => id(item?.sourceId)))
if ([...expectedSourceIds].every((source) => visible.has(source))) break
await new Promise((resolve) => setTimeout(resolve, 500))
}
const poolBySource = new Map(pool.map((item) => [id(item?.sourceId), item]))
const attemptedSources = root.feeSources.map((raw) => {
const order = orders.get(id(raw.orderId))