重构:硬切履约状态唯一真源
This commit is contained in:
@@ -626,7 +626,7 @@ async function resetImportedTemplateProductBootstrap(range: { fromDate: string;
|
||||
`
|
||||
WITH candidates AS (
|
||||
SELECT oi.id, oi.canonical_product_id AS expected_product_id
|
||||
FROM order_items oi
|
||||
FROM v_order_item_current oi
|
||||
JOIN orders o ON o.id = oi.order_id
|
||||
JOIN channel_product_mappings m
|
||||
ON m.provider = o.provider
|
||||
@@ -680,7 +680,7 @@ async function resetImportedTemplateProductBootstrap(range: { fromDate: string;
|
||||
AND m.note LIKE '接单模板 %自动初始化%'
|
||||
AND EXISTS (
|
||||
SELECT 1
|
||||
FROM order_items oi
|
||||
FROM v_order_item_current oi
|
||||
JOIN orders o ON o.id = oi.order_id
|
||||
WHERE oi.canonical_product_id = m.canonical_product_id
|
||||
AND (COALESCE(o.paid_at, o.created_at) AT TIME ZONE 'Asia/Shanghai')::date
|
||||
@@ -732,7 +732,7 @@ async function loadTemplateProductBootstrapData(range: { fromDate: string; toDat
|
||||
wo.product_rule_id,
|
||||
r.rule_key,
|
||||
COUNT(DISTINCT oi.id)::int AS item_count
|
||||
FROM order_items oi
|
||||
FROM v_order_item_current oi
|
||||
JOIN orders o ON o.id = oi.order_id
|
||||
JOIN work_orders wo ON wo.order_item_id = oi.id AND wo.status <> 'cancelled'
|
||||
JOIN work_product_rules r ON r.id = wo.product_rule_id AND r.enabled = TRUE
|
||||
|
||||
Reference in New Issue
Block a user