perf(pipeline): 已入队的异常不再重复 upsert,未映射只算已定渠道
- 载体/人工配置/人工成本三类扫描跳过已有未解决异常的订单项 - 成本中心「未映射订单项」只统计 assigned,待分类单归履约队列
This commit is contained in:
@@ -90,7 +90,8 @@ export async function getAdminCostCenterOverview(params: { scope?: string } = {}
|
||||
SELECT COUNT(*)::int
|
||||
FROM order_items oi
|
||||
WHERE oi.canonical_product_id IS NULL
|
||||
AND oi.fulfillment_status <> 'archived'
|
||||
-- 只统计已定渠道的单:待分类单还没有渠道,不能算「未映射」。
|
||||
AND oi.fulfillment_status = 'assigned'
|
||||
AND ($1::text IS NULL OR COALESCE(oi.fulfillment_channel, CASE WHEN oi.fulfillment_status = 'archived' THEN 'archived' ELSE 'pending' END) = $1)
|
||||
) AS unmapped_order_item_count
|
||||
`,
|
||||
|
||||
@@ -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
|
||||
`,
|
||||
|
||||
Reference in New Issue
Block a user