perf(finance): 消除定时同步与后台页面的重查询
- 新增 order_items.manual_sku_key 生成列(迁移 106),统一内部 SKU 口径(skuNick → outSkuSn → sku_code → sku_name,去空格) - 人工渠道匹配 8.4s → 62ms;人工商品归一写回 7.0s → 307ms - 销售事实重算改为物化订单集合 + 预聚合成本/退款,6.9s → 0.5s 内 - 成本异常写入去掉逐项 LATERAL 工单探测,收口按最近 7 天窗口,7–8s → 0.5s 内 - 销售毛利订单统计去掉重复 NOT EXISTS,9.4s → 0.4s - 接单平台店铺下拉改 EXISTS 半连接,3.1s → 0.3s - cost-finance-sync 默认间隔 5 分钟 → 15 分钟;完整同步 51.2s → 34.9s
This commit is contained in:
@@ -79,13 +79,14 @@ test('人工确认必须单事务:扣款与快照同事务,且使用 with-cl
|
||||
})
|
||||
|
||||
test('人工确认前必须自动匹配履约配置,配置保存/定时任务也要回填', async () => {
|
||||
const [manualSource, configSource, jobSource] = await Promise.all([
|
||||
const [manualSource, configSource, jobSource, migrationSource] = await Promise.all([
|
||||
readFile(new URL('./manual-fulfillment-service.ts', import.meta.url), 'utf8'),
|
||||
readFile(
|
||||
new URL('../cost-center/manual-fulfillment-config-service.ts', import.meta.url),
|
||||
'utf8',
|
||||
),
|
||||
readFile(new URL('../scheduler/cost-finance-sync-job.ts', import.meta.url), 'utf8'),
|
||||
readFile(new URL('../../db/migrations/106_manual_sku_key.sql', import.meta.url), 'utf8'),
|
||||
])
|
||||
assert.ok(
|
||||
manualSource.includes('matchManualFulfillmentConfigWithClient(client, orderItemId, now)'),
|
||||
@@ -104,8 +105,15 @@ test('人工确认前必须自动匹配履约配置,配置保存/定时任务
|
||||
'定时同步必须自动回填未匹配的人工订单项,并限制在最近窗口',
|
||||
)
|
||||
assert.ok(
|
||||
manualSource.includes('NULLIF(oi.sku_code') && configSource.includes('NULLIF(oi.sku_code'),
|
||||
'SKU 匹配必须有 sku_code / sku_name 兜底,不能只认 spec_json',
|
||||
configSource.includes('manual_sku_key'),
|
||||
'人工 SKU 匹配必须统一走 order_items.manual_sku_key 生成列',
|
||||
)
|
||||
assert.ok(
|
||||
migrationSource.includes("spec_json->>'skuNick'") &&
|
||||
migrationSource.includes("spec_json->>'outSkuSn'") &&
|
||||
migrationSource.includes('sku_code') &&
|
||||
migrationSource.includes('sku_name'),
|
||||
'生成列必须保留 sku_code / sku_name 兜底',
|
||||
)
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user