perf(pipeline): 已入队的异常不再重复 upsert,未映射只算已定渠道

- 载体/人工配置/人工成本三类扫描跳过已有未解决异常的订单项
- 成本中心「未映射订单项」只统计 assigned,待分类单归履约队列
This commit is contained in:
yml2213
2026-10-31 20:26:10 +08:00
parent 3f13b8a5f7
commit 657e49f324
2 changed files with 26 additions and 1 deletions
@@ -97,6 +97,14 @@ export async function runCarrierDispatchJob(job: JsonObject = {}) {
SELECT 1 FROM manual_fulfillment_configs cfg
WHERE cfg.sku_key = oi.manual_sku_key AND cfg.enabled
)
AND NOT EXISTS (
SELECT 1
FROM cost_exception_items i
JOIN cost_exceptions ce ON ce.id = i.exception_id
WHERE i.order_item_id = oi.id
AND ce.reason = 'manual_config_missing'
AND ce.status <> 'resolved'
)
ORDER BY oi.id
LIMIT $1
`,
@@ -126,6 +134,14 @@ export async function runCarrierDispatchJob(job: JsonObject = {}) {
AND cs.order_item_id = oi.id
AND cs.superseded_at IS NULL
)
AND NOT EXISTS (
SELECT 1
FROM cost_exception_items i
JOIN cost_exceptions ce ON ce.id = i.exception_id
WHERE i.order_item_id = oi.id
AND ce.reason = 'manual_cost_missing'
AND ce.status <> 'resolved'
)
ORDER BY oi.id
LIMIT $1
`,
@@ -156,6 +172,14 @@ export async function runCarrierDispatchJob(job: JsonObject = {}) {
AND NOT EXISTS (
SELECT 1 FROM work_orders wo WHERE wo.order_item_id = oi.id
)
AND NOT EXISTS (
SELECT 1
FROM cost_exception_items i
JOIN cost_exceptions ce ON ce.id = i.exception_id
WHERE i.order_item_id = oi.id
AND ce.reason = 'carrier_missing'
AND ce.status <> 'resolved'
)
ORDER BY oi.id
LIMIT $1
`,