修复履约与工单热路径二次超时(迁移188)
This commit is contained in:
@@ -0,0 +1,244 @@
|
|||||||
|
-- 188_order_site_worker_fulfillment_hotpaths.sql
|
||||||
|
--
|
||||||
|
-- 继续收敛生产 15s 超时与高 CPU:
|
||||||
|
-- 1. carrier_dispatch 新单窗口必须能直接按 fulfillments.created_at 定位;
|
||||||
|
-- 2. 斗鱼人工任务同步按最近订单驱动,并提供 effective ordered_at 覆盖索引;
|
||||||
|
-- 3. 工单店铺下拉维护窄投影,避免每次扫描 orders/work_orders 全表;
|
||||||
|
-- 4. v_fulfillment_queue 先完成桶过滤,再执行活跃载体探测。
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_fulfillments_assigned_carrier_created
|
||||||
|
ON fulfillments (created_at DESC, order_item_id DESC)
|
||||||
|
WHERE status = 'assigned'
|
||||||
|
AND channel IN ('affiliate_dash', 'work_order');
|
||||||
|
|
||||||
|
COMMENT ON INDEX idx_fulfillments_assigned_carrier_created IS
|
||||||
|
'carrier-dispatch 新单窗口:直接定位已分配自动发货/接单履约记录';
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_fulfillments_assigned_manual_created
|
||||||
|
ON fulfillments (created_at DESC, order_item_id DESC)
|
||||||
|
WHERE status = 'assigned'
|
||||||
|
AND channel = 'manual';
|
||||||
|
|
||||||
|
COMMENT ON INDEX idx_fulfillments_assigned_manual_created IS
|
||||||
|
'carrier-dispatch 人工新单窗口:直接定位已分配人工履约记录';
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_fulfillments_manual_config_order
|
||||||
|
ON fulfillments (fulfillment_config_id, order_id DESC, order_item_id)
|
||||||
|
INCLUDE (id)
|
||||||
|
WHERE channel = 'manual'
|
||||||
|
AND status IN ('assigned', 'processing', 'completed');
|
||||||
|
|
||||||
|
COMMENT ON INDEX idx_fulfillments_manual_config_order IS
|
||||||
|
'斗鱼人工任务同步:按人工配置与最近订单驱动,避免扫描全部人工履约';
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_orders_effective_ordered_at_cover
|
||||||
|
ON orders (
|
||||||
|
COALESCE(paid_at, created_at) DESC NULLS LAST,
|
||||||
|
id DESC
|
||||||
|
)
|
||||||
|
INCLUDE (platform_order_id);
|
||||||
|
|
||||||
|
COMMENT ON INDEX idx_orders_effective_ordered_at_cover IS
|
||||||
|
'最近订单同步覆盖索引:按支付/创建时间倒序读取 platform_order_id';
|
||||||
|
|
||||||
|
-- 工单店铺下拉的窄投影:每个工单一条,最多 24 万行,但只保存工单和店铺两个业务键。
|
||||||
|
CREATE TABLE IF NOT EXISTS work_order_shop_name_projection (
|
||||||
|
work_order_id BIGINT PRIMARY KEY REFERENCES work_orders(id) ON DELETE CASCADE,
|
||||||
|
shop_name TEXT NOT NULL,
|
||||||
|
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_work_order_shop_name_projection_shop
|
||||||
|
ON work_order_shop_name_projection (shop_name);
|
||||||
|
|
||||||
|
COMMENT ON TABLE work_order_shop_name_projection IS
|
||||||
|
'后台工单店铺下拉只读投影;可由 work_orders + orders 全量重建';
|
||||||
|
|
||||||
|
INSERT INTO work_order_shop_name_projection (work_order_id, shop_name, updated_at)
|
||||||
|
SELECT
|
||||||
|
work_order.id,
|
||||||
|
BTRIM(order_record.shop_name),
|
||||||
|
NOW()
|
||||||
|
FROM work_orders work_order
|
||||||
|
JOIN orders order_record ON order_record.id = work_order.order_id
|
||||||
|
WHERE BTRIM(order_record.shop_name) <> ''
|
||||||
|
ON CONFLICT (work_order_id) DO UPDATE SET
|
||||||
|
shop_name = EXCLUDED.shop_name,
|
||||||
|
updated_at = NOW();
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION sync_work_order_shop_name_projection()
|
||||||
|
RETURNS TRIGGER
|
||||||
|
LANGUAGE plpgsql
|
||||||
|
AS $$
|
||||||
|
DECLARE
|
||||||
|
projected_shop_name TEXT;
|
||||||
|
BEGIN
|
||||||
|
IF TG_OP = 'DELETE' THEN
|
||||||
|
DELETE FROM work_order_shop_name_projection
|
||||||
|
WHERE work_order_id = OLD.id;
|
||||||
|
RETURN OLD;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
SELECT BTRIM(order_record.shop_name)
|
||||||
|
INTO projected_shop_name
|
||||||
|
FROM orders order_record
|
||||||
|
WHERE order_record.id = NEW.order_id;
|
||||||
|
|
||||||
|
IF COALESCE(projected_shop_name, '') = '' THEN
|
||||||
|
DELETE FROM work_order_shop_name_projection
|
||||||
|
WHERE work_order_id = NEW.id;
|
||||||
|
ELSE
|
||||||
|
INSERT INTO work_order_shop_name_projection (work_order_id, shop_name, updated_at)
|
||||||
|
VALUES (NEW.id, projected_shop_name, NOW())
|
||||||
|
ON CONFLICT (work_order_id) DO UPDATE SET
|
||||||
|
shop_name = EXCLUDED.shop_name,
|
||||||
|
updated_at = NOW();
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
RETURN NEW;
|
||||||
|
END;
|
||||||
|
$$;
|
||||||
|
|
||||||
|
DROP TRIGGER IF EXISTS trg_sync_work_order_shop_name_projection
|
||||||
|
ON work_orders;
|
||||||
|
CREATE TRIGGER trg_sync_work_order_shop_name_projection
|
||||||
|
AFTER INSERT OR UPDATE OF order_id OR DELETE
|
||||||
|
ON work_orders
|
||||||
|
FOR EACH ROW EXECUTE FUNCTION sync_work_order_shop_name_projection();
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION sync_order_shop_name_work_order_projection()
|
||||||
|
RETURNS TRIGGER
|
||||||
|
LANGUAGE plpgsql
|
||||||
|
AS $$
|
||||||
|
BEGIN
|
||||||
|
IF BTRIM(OLD.shop_name) IS NOT DISTINCT FROM BTRIM(NEW.shop_name) THEN
|
||||||
|
RETURN NEW;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
IF BTRIM(NEW.shop_name) = '' THEN
|
||||||
|
DELETE FROM work_order_shop_name_projection projection
|
||||||
|
USING work_orders work_order
|
||||||
|
WHERE work_order.order_id = NEW.id
|
||||||
|
AND projection.work_order_id = work_order.id;
|
||||||
|
RETURN NEW;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
UPDATE work_order_shop_name_projection projection
|
||||||
|
SET shop_name = BTRIM(NEW.shop_name),
|
||||||
|
updated_at = NOW()
|
||||||
|
FROM work_orders work_order
|
||||||
|
WHERE work_order.order_id = NEW.id
|
||||||
|
AND projection.work_order_id = work_order.id;
|
||||||
|
|
||||||
|
RETURN NEW;
|
||||||
|
END;
|
||||||
|
$$;
|
||||||
|
|
||||||
|
DROP TRIGGER IF EXISTS trg_sync_order_shop_name_work_order_projection
|
||||||
|
ON orders;
|
||||||
|
CREATE TRIGGER trg_sync_order_shop_name_work_order_projection
|
||||||
|
AFTER UPDATE OF shop_name
|
||||||
|
ON orders
|
||||||
|
FOR EACH ROW EXECUTE FUNCTION sync_order_shop_name_work_order_projection();
|
||||||
|
|
||||||
|
-- 仅对满足可执行前置条件的 pending 行探测活跃任务/工单。
|
||||||
|
-- 语义与 185 相同,但避免对 configuration / operator_review / terminal 行做无用探测。
|
||||||
|
CREATE OR REPLACE VIEW v_fulfillment_queue AS
|
||||||
|
WITH classified AS (
|
||||||
|
SELECT
|
||||||
|
state.*,
|
||||||
|
CASE
|
||||||
|
WHEN state.pay_status = 'refunded'
|
||||||
|
OR state.order_status IN ('refunded', 'cancelled', 'closed')
|
||||||
|
OR state.issue_code IN ('user_refund', 'platform_cancelled')
|
||||||
|
THEN 'terminal'
|
||||||
|
WHEN state.issue_category IN ('configuration', 'classification')
|
||||||
|
OR state.issue_code IN (
|
||||||
|
'missing_internal_sku',
|
||||||
|
'missing_channel',
|
||||||
|
'manual_config_missing',
|
||||||
|
'work_rule_missing',
|
||||||
|
'affiliate_mapping_missing'
|
||||||
|
)
|
||||||
|
OR COALESCE(state.fulfillment_pending_detail ->> 'carrierIssue', '') IN (
|
||||||
|
'manual_config_missing',
|
||||||
|
'work_rule_missing',
|
||||||
|
'affiliate_mapping_missing',
|
||||||
|
'missing_internal_sku',
|
||||||
|
'missing_channel'
|
||||||
|
)
|
||||||
|
THEN 'configuration'
|
||||||
|
WHEN state.issue_category = 'manual_review'
|
||||||
|
OR state.issue_code IN (
|
||||||
|
'carrier_manual_review',
|
||||||
|
'carrier_retry_pending',
|
||||||
|
'carrier_expired',
|
||||||
|
'carrier_closed'
|
||||||
|
)
|
||||||
|
OR COALESCE(state.fulfillment_pending_detail ->> 'carrierIssue', '') IN (
|
||||||
|
'carrier_task_closed',
|
||||||
|
'carrier_task_user_refund',
|
||||||
|
'carrier_task_retry_pending',
|
||||||
|
'carrier_task_cancelled',
|
||||||
|
'carrier_task_expired',
|
||||||
|
'carrier_task_manual_review'
|
||||||
|
)
|
||||||
|
THEN 'operator_review'
|
||||||
|
WHEN state.issue_code = 'state_inconsistent'
|
||||||
|
AND state.issue_category = 'system'
|
||||||
|
AND COALESCE(state.fulfillment_pending_detail ->> 'carrierIssue', '')
|
||||||
|
IN ('', 'carrier_not_attempted')
|
||||||
|
THEN 'actionable'
|
||||||
|
WHEN state.issue_category = 'system'
|
||||||
|
THEN 'operator_review'
|
||||||
|
ELSE 'actionable'
|
||||||
|
END AS queue_bucket
|
||||||
|
FROM v_fulfillment_item_state state
|
||||||
|
WHERE state.fulfillment_status IN ('pending', 'assigned')
|
||||||
|
),
|
||||||
|
eligible AS (
|
||||||
|
SELECT
|
||||||
|
classified.*,
|
||||||
|
CASE
|
||||||
|
WHEN classified.fulfillment_status = 'pending'
|
||||||
|
AND classified.pay_status = 'paid'
|
||||||
|
AND classified.order_status NOT IN ('refunded', 'cancelled', 'closed')
|
||||||
|
AND classified.fulfillment_locked = FALSE
|
||||||
|
THEN
|
||||||
|
NOT EXISTS (
|
||||||
|
SELECT 1
|
||||||
|
FROM fulfillment_tasks task
|
||||||
|
WHERE task.order_item_id = classified.order_item_id
|
||||||
|
AND task.executor_key = 'affiliate_dash'
|
||||||
|
AND task.task_status NOT IN (
|
||||||
|
'closed', 'expired', 'failed', 'manual_review', 'retry_pending', 'cancelled'
|
||||||
|
)
|
||||||
|
)
|
||||||
|
AND NOT EXISTS (
|
||||||
|
SELECT 1
|
||||||
|
FROM work_orders work_order
|
||||||
|
WHERE work_order.order_item_id = classified.order_item_id
|
||||||
|
AND work_order.status <> 'cancelled'
|
||||||
|
)
|
||||||
|
ELSE FALSE
|
||||||
|
END AS carrier_queue_candidate
|
||||||
|
FROM classified
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
eligible.order_item_id AS id,
|
||||||
|
eligible.*,
|
||||||
|
(
|
||||||
|
eligible.carrier_queue_candidate
|
||||||
|
AND eligible.queue_bucket = 'actionable'
|
||||||
|
) AS actionable_for_carrier,
|
||||||
|
item.manual_sku_key
|
||||||
|
FROM eligible
|
||||||
|
JOIN order_items item ON item.id = eligible.order_item_id;
|
||||||
|
|
||||||
|
COMMENT ON VIEW v_fulfillment_queue IS
|
||||||
|
'履约待办只读投影:先分桶,再对 actionable/pending 行探测活跃载体';
|
||||||
|
|
||||||
|
ANALYZE fulfillments;
|
||||||
|
ANALYZE orders;
|
||||||
|
ANALYZE manual_fulfillment_configs;
|
||||||
|
ANALYZE work_order_shop_name_projection;
|
||||||
@@ -89,12 +89,11 @@ test('指定打手的运营状态统计保留可见范围和拼单汇总关联',
|
|||||||
useOperationalStatus: true,
|
useOperationalStatus: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
assert.match(query.joins, /worker_visible/)
|
assert.match(query.whereClause, /wo\.id = ANY\(ARRAY\(/)
|
||||||
|
assert.match(query.whereClause, /assigned\.assigned_worker_id = \$1::bigint/)
|
||||||
assert.match(query.joins, /operational_share_summary/)
|
assert.match(query.joins, /operational_share_summary/)
|
||||||
assert.match(query.joins, /LEFT JOIN LATERAL/)
|
assert.match(query.joins, /LEFT JOIN LATERAL/)
|
||||||
assert.ok(
|
assert.ok(query.whereClause.indexOf('assigned.id AS work_order_id') >= 0)
|
||||||
query.joins.indexOf('worker_visible') < query.joins.indexOf('operational_share_summary'),
|
|
||||||
)
|
|
||||||
assert.deepEqual(query.params, [3])
|
assert.deepEqual(query.params, [3])
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -215,10 +214,10 @@ test('普通关键词仍然走 trgm 表达式模糊搜索', () => {
|
|||||||
|
|
||||||
test('内部现货不再因上一手 last_assigned 进入打手可见集', async () => {
|
test('内部现货不再因上一手 last_assigned 进入打手可见集', async () => {
|
||||||
const query = buildWorkOrderWhere({ workerSharingId: 183, statuses: ['in_progress'] })
|
const query = buildWorkOrderWhere({ workerSharingId: 183, statuses: ['in_progress'] })
|
||||||
assert.match(query.joins, /historical\.last_assigned_worker_id = \$1/)
|
assert.match(query.whereClause, /historical\.last_assigned_worker_id = \$1/)
|
||||||
assert.match(query.joins, /consignment,fulfillmentType/)
|
assert.match(query.whereClause, /consignment,fulfillmentType/)
|
||||||
assert.match(query.joins, /worker_deposit/)
|
assert.match(query.whereClause, /worker_deposit/)
|
||||||
assert.match(query.joins, /historical\.assigned_worker_id IS NULL/)
|
assert.match(query.whereClause, /historical\.assigned_worker_id IS NULL/)
|
||||||
|
|
||||||
const { readFile } = await import('node:fs/promises')
|
const { readFile } = await import('node:fs/promises')
|
||||||
const src = await readFile(
|
const src = await readFile(
|
||||||
@@ -240,7 +239,7 @@ test('「待提交打手资料」只筛本人名下 3 天赠送的 material_requ
|
|||||||
assert.match(query.whereClause, /gift_cooldown_hours/)
|
assert.match(query.whereClause, /gift_cooldown_hours/)
|
||||||
assert.match(query.whereClause, /gift_cooldown_minutes/)
|
assert.match(query.whereClause, /gift_cooldown_minutes/)
|
||||||
assert.match(query.whereClause, /\) = 4320/)
|
assert.match(query.whereClause, /\) = 4320/)
|
||||||
// 复用 worker_visible 的打手参数,不额外占位
|
// 复用可见集合数组条件的打手参数,不额外占位
|
||||||
assert.deepEqual(query.params, [7])
|
assert.deepEqual(query.params, [7])
|
||||||
|
|
||||||
// 普通状态筛选不产生赠送资料条件
|
// 普通状态筛选不产生赠送资料条件
|
||||||
@@ -253,14 +252,14 @@ test('后台接单人员筛选把寄售供货人的绑定工单纳入可见集
|
|||||||
workerSharingId: 1494,
|
workerSharingId: 1494,
|
||||||
consignmentSupplierWorkerId: 1494,
|
consignmentSupplierWorkerId: 1494,
|
||||||
})
|
})
|
||||||
assert.match(query.joins, /FROM consignment_inventories supplier_ci/)
|
assert.match(query.whereClause, /FROM consignment_inventories supplier_ci/)
|
||||||
assert.match(query.joins, /supplier_ci\.worker_id = \$2::bigint/)
|
assert.match(query.whereClause, /supplier_ci\.worker_id = \$2::bigint/)
|
||||||
assert.match(query.joins, /supplier_ci\.bound_work_order_id IS NOT NULL/)
|
assert.match(query.whereClause, /supplier_ci\.bound_work_order_id IS NOT NULL/)
|
||||||
assert.deepEqual(query.params, [1494, 1494])
|
assert.deepEqual(query.params, [1494, 1494])
|
||||||
|
|
||||||
// 打手端「我的订单」不传扩展口径,可见范围必须保持原样
|
// 打手端「我的订单」不传扩展口径,可见范围必须保持原样
|
||||||
const plain = buildWorkOrderWhere({ workerSharingId: 1494 })
|
const plain = buildWorkOrderWhere({ workerSharingId: 1494 })
|
||||||
assert.doesNotMatch(plain.joins, /supplier_ci/)
|
assert.doesNotMatch(plain.whereClause, /supplier_ci/)
|
||||||
assert.deepEqual(plain.params, [1494])
|
assert.deepEqual(plain.params, [1494])
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -274,7 +273,7 @@ test('「仅问题单」检索走短路分支,从 pending 表反查而非枚
|
|||||||
assert.match(query.whereClause, /status = 'pending'/)
|
assert.match(query.whereClause, /status = 'pending'/)
|
||||||
// 不得再生成完整派生表达式(那会强制对该打手全部可见单逐行求值)
|
// 不得再生成完整派生表达式(那会强制对该打手全部可见单逐行求值)
|
||||||
assert.doesNotMatch(query.whereClause, /THEN 'problem'\s+ELSE CASE/)
|
assert.doesNotMatch(query.whereClause, /THEN 'problem'\s+ELSE CASE/)
|
||||||
// 第一个 7 来自 worker_visible 连接,第二个 7 是短路分支的打手 id
|
// 第一个 7 来自可见集合数组条件,第二个 7 是短路分支的打手 id
|
||||||
assert.deepEqual(query.params, [7, 7])
|
assert.deepEqual(query.params, [7, 7])
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -513,41 +513,11 @@ export async function listWorkOrders({
|
|||||||
*/
|
*/
|
||||||
export async function listWorkOrderShopNames(): Promise<string[]> {
|
export async function listWorkOrderShopNames(): Promise<string[]> {
|
||||||
const result = await query<{ shop_name: string }>(
|
const result = await query<{ shop_name: string }>(
|
||||||
// 先通过递归松散索引扫描(idx_orders_shop_name_trimmed)在毫秒级列出全部非空店铺,
|
// orders 与 work_orders 都是数十万行大表;下拉只需要固定候选集合,
|
||||||
// 再按 idx_orders_shop_name_trimmed_id_desc 倒序探测最新订单是否存在工单,
|
// 由迁移 188 的触发器维护窄投影,查询走 Shop 索引去重。
|
||||||
// 避免对 55 万 orders + 24 万 work_orders 做全表哈希半连接。
|
`SELECT DISTINCT shop_name
|
||||||
`WITH RECURSIVE distinct_shops AS (
|
FROM work_order_shop_name_projection
|
||||||
(
|
ORDER BY shop_name ASC`,
|
||||||
SELECT BTRIM(o.shop_name) AS shop_name
|
|
||||||
FROM orders o
|
|
||||||
WHERE BTRIM(o.shop_name) <> ''
|
|
||||||
ORDER BY BTRIM(o.shop_name) ASC
|
|
||||||
LIMIT 1
|
|
||||||
)
|
|
||||||
UNION ALL
|
|
||||||
SELECT next_shop.shop_name
|
|
||||||
FROM distinct_shops ds
|
|
||||||
CROSS JOIN LATERAL (
|
|
||||||
SELECT BTRIM(o.shop_name) AS shop_name
|
|
||||||
FROM orders o
|
|
||||||
WHERE BTRIM(o.shop_name) <> ''
|
|
||||||
AND BTRIM(o.shop_name) > ds.shop_name
|
|
||||||
ORDER BY BTRIM(o.shop_name) ASC
|
|
||||||
LIMIT 1
|
|
||||||
) next_shop
|
|
||||||
)
|
|
||||||
SELECT ds.shop_name
|
|
||||||
FROM distinct_shops ds
|
|
||||||
CROSS JOIN LATERAL (
|
|
||||||
SELECT 1 AS has_work_order
|
|
||||||
FROM orders o
|
|
||||||
WHERE BTRIM(o.shop_name) <> ''
|
|
||||||
AND BTRIM(o.shop_name) = ds.shop_name
|
|
||||||
AND EXISTS (SELECT 1 FROM work_orders wo WHERE wo.order_id = o.id)
|
|
||||||
ORDER BY BTRIM(o.shop_name) ASC, o.id DESC
|
|
||||||
LIMIT 1
|
|
||||||
) wo_probe
|
|
||||||
ORDER BY ds.shop_name ASC`,
|
|
||||||
)
|
)
|
||||||
return result.rows
|
return result.rows
|
||||||
.map((row) => String(row.shop_name || '').trim())
|
.map((row) => String(row.shop_name || '').trim())
|
||||||
@@ -1361,8 +1331,7 @@ export function buildWorkOrderWhere({
|
|||||||
WHERE supplier_ci.worker_id = ${supplierPlaceholder}::bigint
|
WHERE supplier_ci.worker_id = ${supplierPlaceholder}::bigint
|
||||||
AND supplier_ci.bound_work_order_id IS NOT NULL`
|
AND supplier_ci.bound_work_order_id IS NOT NULL`
|
||||||
}
|
}
|
||||||
joins.push(`
|
filters.push(`wo.id = ANY(ARRAY(
|
||||||
INNER JOIN (
|
|
||||||
SELECT assigned.id AS work_order_id
|
SELECT assigned.id AS work_order_id
|
||||||
FROM work_orders assigned
|
FROM work_orders assigned
|
||||||
WHERE assigned.assigned_worker_id = ${workerSharePlaceholder}::bigint
|
WHERE assigned.assigned_worker_id = ${workerSharePlaceholder}::bigint
|
||||||
@@ -1380,7 +1349,8 @@ export function buildWorkOrderWhere({
|
|||||||
FROM work_order_events timeout_ev
|
FROM work_order_events timeout_ev
|
||||||
WHERE timeout_ev.event_type LIKE 'timeout_%'
|
WHERE timeout_ev.event_type LIKE 'timeout_%'
|
||||||
AND timeout_ev.payload_json->>'workerId' = ${workerSharePlaceholder}::text${consignmentSupplierUnion}
|
AND timeout_ev.payload_json->>'workerId' = ${workerSharePlaceholder}::text${consignmentSupplierUnion}
|
||||||
) worker_visible ON worker_visible.work_order_id = wo.id
|
))`)
|
||||||
|
joins.push(`
|
||||||
LEFT JOIN LATERAL (
|
LEFT JOIN LATERAL (
|
||||||
SELECT wos.status, wos.created_at
|
SELECT wos.status, wos.created_at
|
||||||
FROM work_order_shares wos
|
FROM work_order_shares wos
|
||||||
|
|||||||
@@ -914,17 +914,14 @@ export async function rematchManualFulfillments(input: Record<string, unknown> =
|
|||||||
}>(
|
}>(
|
||||||
`
|
`
|
||||||
WITH target AS (
|
WITH target AS (
|
||||||
SELECT DISTINCT ON (oi.id)
|
SELECT DISTINCT ON (f.order_item_id)
|
||||||
oi.id AS order_item_id,
|
f.order_item_id AS order_item_id,
|
||||||
cfg.id AS config_id,
|
cfg.id AS config_id,
|
||||||
cfg.canonical_product_id
|
cfg.canonical_product_id
|
||||||
FROM fulfillments f
|
FROM fulfillments f
|
||||||
JOIN order_items oi ON oi.id = f.order_item_id
|
JOIN orders o ON o.id = f.order_id
|
||||||
JOIN orders o ON o.id = oi.order_id
|
|
||||||
JOIN manual_fulfillment_configs cfg
|
JOIN manual_fulfillment_configs cfg
|
||||||
ON canonicalize_internal_sku(cfg.sku_key) = resolve_internal_sku(
|
ON cfg.sku_key = f.internal_sku
|
||||||
oi.manual_sku_key, oi.sku_name, oi.sku_code
|
|
||||||
)
|
|
||||||
WHERE f.status = 'assigned' AND f.channel = 'manual'
|
WHERE f.status = 'assigned' AND f.channel = 'manual'
|
||||||
AND cfg.enabled = TRUE
|
AND cfg.enabled = TRUE
|
||||||
AND ($1 = '' OR canonicalize_internal_sku(cfg.sku_key) = $1)
|
AND ($1 = '' OR canonicalize_internal_sku(cfg.sku_key) = $1)
|
||||||
@@ -937,7 +934,7 @@ export async function rematchManualFulfillments(input: Record<string, unknown> =
|
|||||||
$4::date IS NULL
|
$4::date IS NULL
|
||||||
OR (COALESCE(o.paid_at, o.created_at) AT TIME ZONE 'Asia/Shanghai')::date <= $4::date
|
OR (COALESCE(o.paid_at, o.created_at) AT TIME ZONE 'Asia/Shanghai')::date <= $4::date
|
||||||
)
|
)
|
||||||
ORDER BY oi.id, cfg.id
|
ORDER BY f.order_item_id, cfg.id
|
||||||
)
|
)
|
||||||
SELECT order_item_id, config_id, canonical_product_id
|
SELECT order_item_id, config_id, canonical_product_id
|
||||||
FROM target
|
FROM target
|
||||||
|
|||||||
@@ -327,7 +327,21 @@ async function materializeDouyuFulfillmentTasks(input: {
|
|||||||
createdAfter?: string
|
createdAfter?: string
|
||||||
onlyMissing?: boolean
|
onlyMissing?: boolean
|
||||||
}) {
|
}) {
|
||||||
const params: unknown[] = []
|
const configResult = await query<{ id: number }>(
|
||||||
|
`
|
||||||
|
SELECT id
|
||||||
|
FROM manual_fulfillment_configs
|
||||||
|
WHERE enabled = TRUE
|
||||||
|
AND douyu_fulfillment_enabled = TRUE
|
||||||
|
ORDER BY id
|
||||||
|
`,
|
||||||
|
)
|
||||||
|
const configIds = configResult.rows.map((row) => Number(row.id)).filter((id) => id > 0)
|
||||||
|
if (configIds.length === 0) {
|
||||||
|
return { created: 0, updated: 0 }
|
||||||
|
}
|
||||||
|
|
||||||
|
const params: unknown[] = [configIds]
|
||||||
const filters: string[] = []
|
const filters: string[] = []
|
||||||
const orderNo = String(input.orderNo || '').trim()
|
const orderNo = String(input.orderNo || '').trim()
|
||||||
if (orderNo) {
|
if (orderNo) {
|
||||||
@@ -354,6 +368,29 @@ async function materializeDouyuFulfillmentTasks(input: {
|
|||||||
: null
|
: null
|
||||||
const limitSql = limit ? `LIMIT ${limit}` : ''
|
const limitSql = limit ? `LIMIT ${limit}` : ''
|
||||||
const onlyMissingFilter = input.onlyMissing ? 'AND existing.id IS NULL' : ''
|
const onlyMissingFilter = input.onlyMissing ? 'AND existing.id IS NULL' : ''
|
||||||
|
const targetedByOrderItem = orderItemIds.length > 0
|
||||||
|
const candidateSourceSql = targetedByOrderItem
|
||||||
|
? `
|
||||||
|
FROM order_items oi
|
||||||
|
JOIN orders o ON o.id = oi.order_id
|
||||||
|
JOIN fulfillments f ON f.order_item_id = oi.id
|
||||||
|
`
|
||||||
|
: `
|
||||||
|
FROM orders o
|
||||||
|
CROSS JOIN LATERAL (
|
||||||
|
SELECT
|
||||||
|
fulfillment.id,
|
||||||
|
fulfillment.order_item_id,
|
||||||
|
fulfillment.fulfillment_config_id
|
||||||
|
FROM fulfillments fulfillment
|
||||||
|
WHERE fulfillment.order_id = o.id
|
||||||
|
AND fulfillment.channel = 'manual'
|
||||||
|
AND fulfillment.status IN ('assigned', 'processing', 'completed')
|
||||||
|
AND fulfillment.fulfillment_config_id = ANY($1::bigint[])
|
||||||
|
OFFSET 0
|
||||||
|
) f
|
||||||
|
JOIN order_items oi ON oi.id = f.order_item_id
|
||||||
|
`
|
||||||
|
|
||||||
const result = await query<{
|
const result = await query<{
|
||||||
task_id: number
|
task_id: number
|
||||||
@@ -368,22 +405,21 @@ async function materializeDouyuFulfillmentTasks(input: {
|
|||||||
o.platform_order_id,
|
o.platform_order_id,
|
||||||
oi.id AS order_item_id,
|
oi.id AS order_item_id,
|
||||||
f.id AS fulfillment_id,
|
f.id AS fulfillment_id,
|
||||||
cfg.id AS config_id,
|
f.fulfillment_config_id AS config_id,
|
||||||
existing.id AS existing_task_id
|
existing.id AS existing_task_id
|
||||||
FROM orders o
|
${candidateSourceSql}
|
||||||
JOIN order_items oi ON oi.order_id = o.id
|
|
||||||
JOIN fulfillments f ON f.order_item_id = oi.id
|
|
||||||
JOIN manual_fulfillment_configs cfg ON cfg.id = f.fulfillment_config_id
|
|
||||||
JOIN douyu_fulfillment_settings settings ON settings.id = 1
|
|
||||||
LEFT JOIN douyu_fulfillment_tasks existing ON existing.order_item_id = oi.id
|
LEFT JOIN douyu_fulfillment_tasks existing ON existing.order_item_id = oi.id
|
||||||
WHERE cfg.enabled = TRUE
|
WHERE f.fulfillment_config_id = ANY($1::bigint[])
|
||||||
AND cfg.douyu_fulfillment_enabled = TRUE
|
|
||||||
AND f.channel = 'manual'
|
AND f.channel = 'manual'
|
||||||
AND f.status IN ('assigned', 'processing', 'completed')
|
AND f.status IN ('assigned', 'processing', 'completed')
|
||||||
AND COALESCE(o.paid_at, o.created_at) >= settings.order_match_started_at
|
AND COALESCE(o.paid_at, o.created_at) >= (
|
||||||
|
SELECT order_match_started_at
|
||||||
|
FROM douyu_fulfillment_settings
|
||||||
|
WHERE id = 1
|
||||||
|
)
|
||||||
${filters.length > 0 ? `AND ${filters.join('\n AND ')}` : ''}
|
${filters.length > 0 ? `AND ${filters.join('\n AND ')}` : ''}
|
||||||
${onlyMissingFilter}
|
${onlyMissingFilter}
|
||||||
ORDER BY o.id DESC, oi.id ASC
|
ORDER BY COALESCE(o.paid_at, o.created_at) DESC, o.id DESC, oi.id ASC
|
||||||
${limitSql}
|
${limitSql}
|
||||||
),
|
),
|
||||||
upserted AS (
|
upserted AS (
|
||||||
|
|||||||
@@ -455,6 +455,20 @@ test(
|
|||||||
await touchWatermark('carrier_dispatch', { lastItemId: item1Id - 1 })
|
await touchWatermark('carrier_dispatch', { lastItemId: item1Id - 1 })
|
||||||
await runCarrierDispatchJob({ config: { limit: 1, afterId: item1Id - 1 } })
|
await runCarrierDispatchJob({ config: { limit: 1, afterId: item1Id - 1 } })
|
||||||
assert.ok((await readWatermarkItemId('carrier_dispatch')) >= item1Id)
|
assert.ok((await readWatermarkItemId('carrier_dispatch')) >= item1Id)
|
||||||
|
|
||||||
|
const renamedShop = `AAA_改名工单店铺_${suffix}`
|
||||||
|
await query(`UPDATE orders SET shop_name = $2, updated_at = NOW() WHERE id = $1`, [
|
||||||
|
orderWithWoId,
|
||||||
|
renamedShop,
|
||||||
|
])
|
||||||
|
const renamedShops = await listWorkOrderShopNames()
|
||||||
|
assert.ok(renamedShops.includes(renamedShop))
|
||||||
|
assert.ok(!renamedShops.includes(shopWithWo))
|
||||||
|
|
||||||
|
await query(`DELETE FROM work_orders WHERE id = $1`, [workOrderId])
|
||||||
|
workOrderId = 0
|
||||||
|
const shopsAfterDelete = await listWorkOrderShopNames()
|
||||||
|
assert.ok(!shopsAfterDelete.includes(renamedShop))
|
||||||
} finally {
|
} finally {
|
||||||
await touchWatermark('carrier_dispatch', { lastItemId: originalDispatchCursor }).catch(
|
await touchWatermark('carrier_dispatch', { lastItemId: originalDispatchCursor }).catch(
|
||||||
() => undefined,
|
() => undefined,
|
||||||
|
|||||||
@@ -66,29 +66,31 @@ async function loadCandidateItems(input: {
|
|||||||
.map(Number)
|
.map(Number)
|
||||||
.filter((value) => Number.isInteger(value) && value > 0)
|
.filter((value) => Number.isInteger(value) && value > 0)
|
||||||
const params: unknown[] = [input.limit]
|
const params: unknown[] = [input.limit]
|
||||||
|
const scopeAlias = input.assignedMissingCarrier ? 'f' : 'oi'
|
||||||
|
const idColumn = input.assignedMissingCarrier ? 'f.order_item_id' : 'oi.id'
|
||||||
let idFilter = ''
|
let idFilter = ''
|
||||||
if (ids.length > 0) {
|
if (ids.length > 0) {
|
||||||
params.push(ids)
|
params.push(ids)
|
||||||
idFilter = `AND oi.id = ANY($${params.length}::bigint[])`
|
idFilter = `AND ${idColumn} = ANY($${params.length}::bigint[])`
|
||||||
} else if (Number(input.afterId || 0) > 0) {
|
} else if (Number(input.afterId || 0) > 0) {
|
||||||
params.push(Math.max(0, Math.trunc(Number(input.afterId))))
|
params.push(Math.max(0, Math.trunc(Number(input.afterId))))
|
||||||
idFilter = `AND oi.id > $${params.length}`
|
idFilter = `AND ${idColumn} > $${params.length}`
|
||||||
}
|
}
|
||||||
const cutoffCreatedAt = String(input.cutoffCreatedAt || '').trim()
|
const cutoffCreatedAt = String(input.cutoffCreatedAt || '').trim()
|
||||||
let cutoffFilter = ''
|
let cutoffFilter = ''
|
||||||
if (cutoffCreatedAt && Number.isFinite(Date.parse(cutoffCreatedAt))) {
|
if (cutoffCreatedAt && Number.isFinite(Date.parse(cutoffCreatedAt))) {
|
||||||
params.push(cutoffCreatedAt)
|
params.push(cutoffCreatedAt)
|
||||||
cutoffFilter = `AND oi.created_at >= $${params.length}::timestamptz`
|
cutoffFilter = `AND ${scopeAlias}.created_at >= $${params.length}::timestamptz`
|
||||||
}
|
}
|
||||||
const createdAfter = String(input.createdAfter || '').trim()
|
const createdAfter = String(input.createdAfter || '').trim()
|
||||||
if (createdAfter && Number.isFinite(Date.parse(createdAfter))) {
|
if (createdAfter && Number.isFinite(Date.parse(createdAfter))) {
|
||||||
params.push(createdAfter)
|
params.push(createdAfter)
|
||||||
cutoffFilter += ` AND oi.created_at >= $${params.length}::timestamptz`
|
cutoffFilter += ` AND ${scopeAlias}.created_at >= $${params.length}::timestamptz`
|
||||||
}
|
}
|
||||||
const createdBefore = String(input.createdBefore || '').trim()
|
const createdBefore = String(input.createdBefore || '').trim()
|
||||||
if (createdBefore && Number.isFinite(Date.parse(createdBefore))) {
|
if (createdBefore && Number.isFinite(Date.parse(createdBefore))) {
|
||||||
params.push(createdBefore)
|
params.push(createdBefore)
|
||||||
cutoffFilter += ` AND oi.created_at < $${params.length}::timestamptz`
|
cutoffFilter += ` AND ${scopeAlias}.created_at < $${params.length}::timestamptz`
|
||||||
}
|
}
|
||||||
const orderDirection = input.orderDirection === 'desc' ? 'DESC' : 'ASC'
|
const orderDirection = input.orderDirection === 'desc' ? 'DESC' : 'ASC'
|
||||||
|
|
||||||
@@ -115,9 +117,7 @@ async function loadCandidateItems(input: {
|
|||||||
FROM sku_channel_routes route
|
FROM sku_channel_routes route
|
||||||
JOIN internal_skus sku ON sku.id = route.internal_sku_id
|
JOIN internal_skus sku ON sku.id = route.internal_sku_id
|
||||||
WHERE route.enabled = TRUE
|
WHERE route.enabled = TRUE
|
||||||
AND sku.internal_sku_key = resolve_internal_sku(
|
AND sku.internal_sku_key = oi.internal_sku
|
||||||
oi.manual_sku_key, oi.sku_name, oi.sku_code
|
|
||||||
)
|
|
||||||
`
|
`
|
||||||
const lateralChannelsSql = `
|
const lateralChannelsSql = `
|
||||||
JOIN LATERAL (${lateralChannelsSelect}) capability ON jsonb_array_length(capability.channels) > 0
|
JOIN LATERAL (${lateralChannelsSelect}) capability ON jsonb_array_length(capability.channels) > 0
|
||||||
@@ -131,13 +131,10 @@ async function loadCandidateItems(input: {
|
|||||||
? `
|
? `
|
||||||
WITH candidate_items AS (
|
WITH candidate_items AS (
|
||||||
SELECT
|
SELECT
|
||||||
oi.id,
|
f.order_item_id AS id,
|
||||||
oi.order_id,
|
f.order_id,
|
||||||
oi.manual_sku_key,
|
f.internal_sku
|
||||||
oi.sku_name,
|
|
||||||
oi.sku_code
|
|
||||||
FROM fulfillments f
|
FROM fulfillments f
|
||||||
JOIN order_items oi ON oi.id = f.order_item_id
|
|
||||||
JOIN orders o ON o.id = f.order_id
|
JOIN orders o ON o.id = f.order_id
|
||||||
WHERE f.status = 'assigned'
|
WHERE f.status = 'assigned'
|
||||||
AND f.channel IN ('affiliate_dash', 'work_order')
|
AND f.channel IN ('affiliate_dash', 'work_order')
|
||||||
@@ -196,13 +193,13 @@ async function loadCandidateItems(input: {
|
|||||||
), '') NOT IN ('USER_APPLY_REFUND', 'affiliate_dash_cancelled')
|
), '') NOT IN ('USER_APPLY_REFUND', 'affiliate_dash_cancelled')
|
||||||
${idFilter}
|
${idFilter}
|
||||||
${cutoffFilter}
|
${cutoffFilter}
|
||||||
ORDER BY oi.id ${orderDirection}
|
ORDER BY f.order_item_id ${orderDirection}
|
||||||
LIMIT $1
|
LIMIT $1
|
||||||
)
|
)
|
||||||
SELECT
|
SELECT
|
||||||
oi.id,
|
oi.id,
|
||||||
oi.order_id,
|
oi.order_id,
|
||||||
resolve_internal_sku(oi.manual_sku_key, oi.sku_name, oi.sku_code) AS internal_sku,
|
oi.internal_sku,
|
||||||
capability.channels
|
capability.channels
|
||||||
FROM candidate_items oi
|
FROM candidate_items oi
|
||||||
${assignedMissingLateralSql}
|
${assignedMissingLateralSql}
|
||||||
@@ -212,16 +209,20 @@ async function loadCandidateItems(input: {
|
|||||||
SELECT
|
SELECT
|
||||||
oi.id,
|
oi.id,
|
||||||
oi.order_id,
|
oi.order_id,
|
||||||
resolve_internal_sku(oi.manual_sku_key, oi.sku_name, oi.sku_code) AS internal_sku,
|
oi.internal_sku,
|
||||||
capability.channels
|
capability.channels
|
||||||
FROM v_fulfillment_queue oi
|
FROM v_fulfillment_queue oi
|
||||||
${lateralChannelsSql}
|
${lateralChannelsSql}
|
||||||
WHERE oi.fulfillment_status = 'pending'
|
WHERE oi.fulfillment_status = 'pending'
|
||||||
AND oi.carrier_queue_candidate = TRUE
|
|
||||||
${
|
${
|
||||||
input.includeNonActionable
|
input.includeNonActionable || input.includeLocked
|
||||||
? `AND oi.queue_bucket IN ('actionable', 'configuration', 'operator_review')`
|
? `AND oi.carrier_queue_candidate = TRUE
|
||||||
: `AND oi.queue_bucket = 'actionable'`
|
AND oi.queue_bucket IN (${
|
||||||
|
input.includeNonActionable
|
||||||
|
? `'actionable', 'configuration', 'operator_review'`
|
||||||
|
: `'actionable'`
|
||||||
|
})`
|
||||||
|
: `AND oi.actionable_for_carrier = TRUE`
|
||||||
}
|
}
|
||||||
${input.includeLocked ? '' : 'AND oi.fulfillment_locked = FALSE'}
|
${input.includeLocked ? '' : 'AND oi.fulfillment_locked = FALSE'}
|
||||||
${idFilter}
|
${idFilter}
|
||||||
|
|||||||
@@ -141,8 +141,9 @@ test('新单快速推进只处理 actionable 履约桶', () => {
|
|||||||
assert.ok(!advance.includes('includeNonActionable'))
|
assert.ok(!advance.includes('includeNonActionable'))
|
||||||
})
|
})
|
||||||
|
|
||||||
test('热路径数据库优化迁移 187 与对应仓储查询守卫生效', () => {
|
test('热路径数据库优化迁移 187/188 与对应仓储查询守卫生效', () => {
|
||||||
const migration187 = source('../../db/migrations/187_order_site_hotpath_optimization.sql')
|
const migration187 = source('../../db/migrations/187_order_site_hotpath_optimization.sql')
|
||||||
|
const migration188 = source('../../db/migrations/188_order_site_worker_fulfillment_hotpaths.sql')
|
||||||
const taskRepo = source('../../repositories/task-repo.ts')
|
const taskRepo = source('../../repositories/task-repo.ts')
|
||||||
const affiliateFallback = source('./affiliate-fallback-service.ts')
|
const affiliateFallback = source('./affiliate-fallback-service.ts')
|
||||||
const financeJobs = source('../scheduler/finance-pipeline-jobs.ts')
|
const financeJobs = source('../scheduler/finance-pipeline-jobs.ts')
|
||||||
@@ -158,6 +159,12 @@ test('热路径数据库优化迁移 187 与对应仓储查询守卫生效', ()
|
|||||||
assert.ok(migration187.includes('idx_orders_shop_name_trimmed_id_desc'))
|
assert.ok(migration187.includes('idx_orders_shop_name_trimmed_id_desc'))
|
||||||
assert.ok(migration187.includes('idx_admin_notifications_visible_pending_rank'))
|
assert.ok(migration187.includes('idx_admin_notifications_visible_pending_rank'))
|
||||||
assert.ok(migration187.includes('idx_work_orders_leaderboard_accepted'))
|
assert.ok(migration187.includes('idx_work_orders_leaderboard_accepted'))
|
||||||
|
assert.ok(migration188.includes('idx_fulfillments_assigned_carrier_created'))
|
||||||
|
assert.ok(migration188.includes('idx_fulfillments_assigned_manual_created'))
|
||||||
|
assert.ok(migration188.includes('idx_fulfillments_manual_config_order'))
|
||||||
|
assert.ok(migration188.includes('idx_orders_effective_ordered_at_cover'))
|
||||||
|
assert.ok(migration188.includes('work_order_shop_name_projection'))
|
||||||
|
assert.ok(migration188.includes('eligible.queue_bucket ='))
|
||||||
|
|
||||||
const jsonLookup = taskRepo.slice(
|
const jsonLookup = taskRepo.slice(
|
||||||
taskRepo.indexOf('async function findExecutorTaskByJsonKeys'),
|
taskRepo.indexOf('async function findExecutorTaskByJsonKeys'),
|
||||||
@@ -173,9 +180,24 @@ test('热路径数据库优化迁移 187 与对应仓储查询守卫生效', ()
|
|||||||
financeJobs.indexOf('export async function runCarrierDispatchJob'),
|
financeJobs.indexOf('export async function runCarrierDispatchJob'),
|
||||||
financeJobs.indexOf('export async function runProductNormalizeJob'),
|
financeJobs.indexOf('export async function runProductNormalizeJob'),
|
||||||
)
|
)
|
||||||
|
const douyuService = source('../douyu-fulfillment/douyu-fulfillment-service.ts')
|
||||||
|
const douyuMaterializeBody = douyuService.slice(
|
||||||
|
douyuService.indexOf('async function materializeDouyuFulfillmentTasks'),
|
||||||
|
douyuService.indexOf('async function loadPendingDouyuOrderHints'),
|
||||||
|
)
|
||||||
|
const carrierReconciliation = source('./carrier-reconciliation-service.ts')
|
||||||
assert.ok(carrierDispatchBody.includes('WITH candidate_page AS'))
|
assert.ok(carrierDispatchBody.includes('WITH candidate_page AS'))
|
||||||
assert.ok(carrierDispatchBody.includes('scanned_max_id'))
|
assert.ok(carrierDispatchBody.includes('scanned_max_id'))
|
||||||
|
assert.ok(carrierDispatchBody.includes('f.created_at'))
|
||||||
|
assert.ok(carrierDispatchBody.includes('f.internal_sku'))
|
||||||
assert.ok(!carrierDispatchBody.includes('FROM v_order_item_current oi'))
|
assert.ok(!carrierDispatchBody.includes('FROM v_order_item_current oi'))
|
||||||
|
assert.ok(!carrierDispatchBody.includes('FROM manual_fulfillment_configs WHERE enabled'))
|
||||||
|
assert.ok(douyuMaterializeBody.includes('const configIds'))
|
||||||
|
assert.ok(douyuMaterializeBody.includes('CROSS JOIN LATERAL'))
|
||||||
|
assert.ok(douyuMaterializeBody.includes('COALESCE(o.paid_at, o.created_at) DESC'))
|
||||||
|
assert.ok(!douyuMaterializeBody.includes('JOIN manual_fulfillment_configs cfg'))
|
||||||
|
assert.ok(carrierReconciliation.includes('sku.internal_sku_key = oi.internal_sku'))
|
||||||
|
assert.ok(!carrierReconciliation.includes('resolve_internal_sku(\\n oi.manual_sku_key'))
|
||||||
assert.ok(
|
assert.ok(
|
||||||
!manualConfig
|
!manualConfig
|
||||||
.slice(manualConfig.indexOf('export async function rematchManualFulfillments'))
|
.slice(manualConfig.indexOf('export async function rematchManualFulfillments'))
|
||||||
@@ -186,8 +208,15 @@ test('热路径数据库优化迁移 187 与对应仓储查询守卫生效', ()
|
|||||||
workOrderQueryRepo.indexOf('export async function listWorkOrderShopNames'),
|
workOrderQueryRepo.indexOf('export async function listWorkOrderShopNames'),
|
||||||
workOrderQueryRepo.indexOf('export async function countWorkOrders'),
|
workOrderQueryRepo.indexOf('export async function countWorkOrders'),
|
||||||
)
|
)
|
||||||
assert.ok(shopNamesBody.includes('WITH RECURSIVE distinct_shops AS'))
|
assert.ok(shopNamesBody.includes('work_order_shop_name_projection'))
|
||||||
assert.ok(shopNamesBody.includes('ORDER BY BTRIM(o.shop_name) ASC, o.id DESC'))
|
assert.ok(!shopNamesBody.includes('WITH RECURSIVE distinct_shops AS'))
|
||||||
|
|
||||||
|
const workerVisibleBody = workOrderQueryRepo.slice(
|
||||||
|
workOrderQueryRepo.indexOf('if (workerSharingId) {'),
|
||||||
|
workOrderQueryRepo.indexOf('if (useOperationalStatus)'),
|
||||||
|
)
|
||||||
|
assert.ok(workerVisibleBody.includes('wo.id = ANY(ARRAY('))
|
||||||
|
assert.ok(!workerVisibleBody.includes('worker_visible ON worker_visible.work_order_id'))
|
||||||
|
|
||||||
assert.ok(adminNotificationService.includes('pendingNotificationsCache.getOrSet('))
|
assert.ok(adminNotificationService.includes('pendingNotificationsCache.getOrSet('))
|
||||||
assert.ok(adminNotificationService.includes('pendingNotificationsCache.clear()'))
|
assert.ok(adminNotificationService.includes('pendingNotificationsCache.clear()'))
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ test('补载体自动扫描只读取 actionable 队列', () => {
|
|||||||
assert.ok(
|
assert.ok(
|
||||||
queueActiveScopeMigration.includes("WHERE state.fulfillment_status IN ('pending', 'assigned')"),
|
queueActiveScopeMigration.includes("WHERE state.fulfillment_status IN ('pending', 'assigned')"),
|
||||||
)
|
)
|
||||||
assert.ok(carrierReconciliation.includes("oi.queue_bucket = 'actionable'"))
|
assert.ok(carrierReconciliation.includes('oi.actionable_for_carrier = TRUE'))
|
||||||
assert.ok(carrierReconciliation.includes('oi.carrier_queue_candidate = TRUE'))
|
assert.ok(carrierReconciliation.includes('oi.carrier_queue_candidate = TRUE'))
|
||||||
assert.ok(carrierReconciliation.includes('createdBefore'))
|
assert.ok(carrierReconciliation.includes('createdBefore'))
|
||||||
assert.ok(carrierReconciliation.includes("orderDirection === 'desc'"))
|
assert.ok(carrierReconciliation.includes("orderDirection === 'desc'"))
|
||||||
|
|||||||
@@ -173,12 +173,8 @@ export async function runCarrierDispatchJob(job: JsonObject = {}) {
|
|||||||
? Math.max(0, Math.trunc(Number(config.afterId)))
|
? Math.max(0, Math.trunc(Number(config.afterId)))
|
||||||
: await readWatermarkItemId('carrier_dispatch')
|
: await readWatermarkItemId('carrier_dispatch')
|
||||||
const freshCutoff = new Date(Date.now() - freshWindowMinutes * 60_000).toISOString()
|
const freshCutoff = new Date(Date.now() - freshWindowMinutes * 60_000).toISOString()
|
||||||
const configKeysResult = await query<{ sku_key: string }>(
|
const manualParams: unknown[] = [limit, cursor]
|
||||||
'SELECT canonicalize_internal_sku(sku_key) AS sku_key FROM manual_fulfillment_configs WHERE enabled',
|
const manualCutoff = fulfillmentCreatedAfterSql(manualParams, cutoffCreatedAt, 'f')
|
||||||
)
|
|
||||||
const configKeys = configKeysResult.rows.map((row) => row.sku_key)
|
|
||||||
const manualParams: unknown[] = [limit, cursor, configKeys]
|
|
||||||
const manualCutoff = fulfillmentCreatedAfterSql(manualParams, cutoffCreatedAt)
|
|
||||||
|
|
||||||
const manual = await query<{
|
const manual = await query<{
|
||||||
id: number
|
id: number
|
||||||
@@ -187,21 +183,17 @@ export async function runCarrierDispatchJob(job: JsonObject = {}) {
|
|||||||
config_id: number
|
config_id: number
|
||||||
}>(
|
}>(
|
||||||
`
|
`
|
||||||
SELECT oi.id,
|
SELECT f.order_item_id AS id,
|
||||||
oi.order_id,
|
f.order_id,
|
||||||
resolve_internal_sku(oi.manual_sku_key, oi.sku_name, oi.sku_code) AS sku_key,
|
f.internal_sku AS sku_key,
|
||||||
cfg.id AS config_id
|
cfg.id AS config_id
|
||||||
FROM fulfillments f
|
FROM fulfillments f
|
||||||
JOIN order_items oi ON oi.id = f.order_item_id
|
|
||||||
JOIN manual_fulfillment_configs cfg
|
JOIN manual_fulfillment_configs cfg
|
||||||
ON canonicalize_internal_sku(cfg.sku_key) = resolve_internal_sku(
|
ON cfg.sku_key = f.internal_sku
|
||||||
oi.manual_sku_key, oi.sku_name, oi.sku_code
|
|
||||||
)
|
|
||||||
AND cfg.enabled
|
AND cfg.enabled
|
||||||
WHERE f.status = 'assigned'
|
WHERE f.status = 'assigned'
|
||||||
AND f.channel = 'manual'
|
AND f.channel = 'manual'
|
||||||
AND f.fulfillment_config_id IS NULL
|
AND f.fulfillment_config_id IS NULL
|
||||||
AND resolve_internal_sku(oi.manual_sku_key, oi.sku_name, oi.sku_code) = ANY($3::text[])
|
|
||||||
AND f.order_item_id > $2
|
AND f.order_item_id > $2
|
||||||
${manualCutoff}
|
${manualCutoff}
|
||||||
ORDER BY f.order_item_id
|
ORDER BY f.order_item_id
|
||||||
@@ -308,12 +300,12 @@ export async function runCarrierDispatchJob(job: JsonObject = {}) {
|
|||||||
const missingManualRows: Array<{ id: number; sku_key: string }> = []
|
const missingManualRows: Array<{ id: number; sku_key: string }> = []
|
||||||
const missingManualPageMaxIds: number[] = []
|
const missingManualPageMaxIds: number[] = []
|
||||||
for (const mode of ['fresh', 'historical'] as const) {
|
for (const mode of ['fresh', 'historical'] as const) {
|
||||||
const params: unknown[] =
|
const params: unknown[] = mode === 'fresh' ? [freshLimit, freshCutoff] : [limit, cursor]
|
||||||
mode === 'fresh' ? [freshLimit, freshCutoff, configKeys] : [limit, cursor, configKeys]
|
const cutoffSql = fulfillmentCreatedAfterSql(params, cutoffCreatedAt, 'f')
|
||||||
const cutoffSql = fulfillmentCreatedAfterSql(params, cutoffCreatedAt)
|
|
||||||
const scopeSql =
|
const scopeSql =
|
||||||
mode === 'fresh' ? 'AND oi.created_at >= $2::timestamptz' : 'AND f.order_item_id > $2'
|
mode === 'fresh' ? 'AND f.created_at >= $2::timestamptz' : 'AND f.order_item_id > $2'
|
||||||
const orderSql = mode === 'fresh' ? 'DESC' : 'ASC'
|
const orderSql =
|
||||||
|
mode === 'fresh' ? 'f.created_at DESC, f.order_item_id DESC' : 'f.order_item_id ASC'
|
||||||
const res = await query<{
|
const res = await query<{
|
||||||
id: number | null
|
id: number | null
|
||||||
sku_key: string | null
|
sku_key: string | null
|
||||||
@@ -323,16 +315,20 @@ export async function runCarrierDispatchJob(job: JsonObject = {}) {
|
|||||||
WITH candidate_page AS (
|
WITH candidate_page AS (
|
||||||
SELECT
|
SELECT
|
||||||
f.order_item_id,
|
f.order_item_id,
|
||||||
resolve_internal_sku(oi.manual_sku_key, oi.sku_name, oi.sku_code) AS sku_key
|
f.internal_sku AS sku_key
|
||||||
FROM fulfillments f
|
FROM fulfillments f
|
||||||
JOIN order_items oi ON oi.id = f.order_item_id
|
|
||||||
WHERE f.status = 'assigned'
|
WHERE f.status = 'assigned'
|
||||||
AND f.channel = 'manual'
|
AND f.channel = 'manual'
|
||||||
AND f.fulfillment_config_id IS NULL
|
AND f.fulfillment_config_id IS NULL
|
||||||
AND NOT (resolve_internal_sku(oi.manual_sku_key, oi.sku_name, oi.sku_code) = ANY($3::text[]))
|
AND NOT EXISTS (
|
||||||
|
SELECT 1
|
||||||
|
FROM manual_fulfillment_configs cfg
|
||||||
|
WHERE cfg.enabled
|
||||||
|
AND cfg.sku_key = f.internal_sku
|
||||||
|
)
|
||||||
${scopeSql}
|
${scopeSql}
|
||||||
${cutoffSql}
|
${cutoffSql}
|
||||||
ORDER BY f.order_item_id ${orderSql}
|
ORDER BY ${orderSql}
|
||||||
LIMIT $1
|
LIMIT $1
|
||||||
),
|
),
|
||||||
page_bounds AS (
|
page_bounds AS (
|
||||||
@@ -383,10 +379,11 @@ export async function runCarrierDispatchJob(job: JsonObject = {}) {
|
|||||||
const pendingManualCostPageMaxIds: number[] = []
|
const pendingManualCostPageMaxIds: number[] = []
|
||||||
for (const mode of ['fresh', 'historical'] as const) {
|
for (const mode of ['fresh', 'historical'] as const) {
|
||||||
const params: unknown[] = mode === 'fresh' ? [freshLimit, freshCutoff] : [limit, cursor]
|
const params: unknown[] = mode === 'fresh' ? [freshLimit, freshCutoff] : [limit, cursor]
|
||||||
const cutoffSql = fulfillmentCreatedAfterSql(params, cutoffCreatedAt)
|
const cutoffSql = fulfillmentCreatedAfterSql(params, cutoffCreatedAt, 'f')
|
||||||
const scopeSql =
|
const scopeSql =
|
||||||
mode === 'fresh' ? 'AND oi.created_at >= $2::timestamptz' : 'AND f.order_item_id > $2'
|
mode === 'fresh' ? 'AND f.created_at >= $2::timestamptz' : 'AND f.order_item_id > $2'
|
||||||
const orderSql = mode === 'fresh' ? 'DESC' : 'ASC'
|
const orderSql =
|
||||||
|
mode === 'fresh' ? 'f.created_at DESC, f.order_item_id DESC' : 'f.order_item_id ASC'
|
||||||
const res = await query<{
|
const res = await query<{
|
||||||
id: number | null
|
id: number | null
|
||||||
sku_key: string | null
|
sku_key: string | null
|
||||||
@@ -396,15 +393,14 @@ export async function runCarrierDispatchJob(job: JsonObject = {}) {
|
|||||||
WITH candidate_page AS (
|
WITH candidate_page AS (
|
||||||
SELECT
|
SELECT
|
||||||
f.order_item_id,
|
f.order_item_id,
|
||||||
resolve_internal_sku(oi.manual_sku_key, oi.sku_name, oi.sku_code) AS sku_key
|
f.internal_sku AS sku_key
|
||||||
FROM fulfillments f
|
FROM fulfillments f
|
||||||
JOIN order_items oi ON oi.id = f.order_item_id
|
|
||||||
WHERE f.status = 'assigned'
|
WHERE f.status = 'assigned'
|
||||||
AND f.channel = 'manual'
|
AND f.channel = 'manual'
|
||||||
AND f.fulfillment_config_id IS NOT NULL
|
AND f.fulfillment_config_id IS NOT NULL
|
||||||
${scopeSql}
|
${scopeSql}
|
||||||
${cutoffSql}
|
${cutoffSql}
|
||||||
ORDER BY f.order_item_id ${orderSql}
|
ORDER BY ${orderSql}
|
||||||
LIMIT $1
|
LIMIT $1
|
||||||
),
|
),
|
||||||
page_bounds AS (
|
page_bounds AS (
|
||||||
@@ -465,10 +461,11 @@ export async function runCarrierDispatchJob(job: JsonObject = {}) {
|
|||||||
const missingCarrierPageMaxIds: number[] = []
|
const missingCarrierPageMaxIds: number[] = []
|
||||||
for (const mode of ['fresh', 'historical'] as const) {
|
for (const mode of ['fresh', 'historical'] as const) {
|
||||||
const params: unknown[] = mode === 'fresh' ? [freshLimit, freshCutoff] : [limit, cursor]
|
const params: unknown[] = mode === 'fresh' ? [freshLimit, freshCutoff] : [limit, cursor]
|
||||||
const cutoffSql = fulfillmentCreatedAfterSql(params, cutoffCreatedAt)
|
const cutoffSql = fulfillmentCreatedAfterSql(params, cutoffCreatedAt, 'f')
|
||||||
const scopeSql =
|
const scopeSql =
|
||||||
mode === 'fresh' ? 'AND oi.created_at >= $2::timestamptz' : 'AND f.order_item_id > $2'
|
mode === 'fresh' ? 'AND f.created_at >= $2::timestamptz' : 'AND f.order_item_id > $2'
|
||||||
const orderSql = mode === 'fresh' ? 'DESC' : 'ASC'
|
const orderSql =
|
||||||
|
mode === 'fresh' ? 'f.created_at DESC, f.order_item_id DESC' : 'f.order_item_id ASC'
|
||||||
const res = await query<{
|
const res = await query<{
|
||||||
id: number | null
|
id: number | null
|
||||||
channel: string | null
|
channel: string | null
|
||||||
@@ -482,14 +479,14 @@ export async function runCarrierDispatchJob(job: JsonObject = {}) {
|
|||||||
f.order_item_id,
|
f.order_item_id,
|
||||||
f.channel,
|
f.channel,
|
||||||
oi.sku_code,
|
oi.sku_code,
|
||||||
resolve_internal_sku(oi.manual_sku_key, oi.sku_name, oi.sku_code) AS internal_sku
|
f.internal_sku
|
||||||
FROM fulfillments f
|
FROM fulfillments f
|
||||||
JOIN order_items oi ON oi.id = f.order_item_id
|
JOIN order_items oi ON oi.id = f.order_item_id
|
||||||
WHERE f.status = 'assigned'
|
WHERE f.status = 'assigned'
|
||||||
AND f.channel IN ('affiliate_dash', 'work_order')
|
AND f.channel IN ('affiliate_dash', 'work_order')
|
||||||
${scopeSql}
|
${scopeSql}
|
||||||
${cutoffSql}
|
${cutoffSql}
|
||||||
ORDER BY f.order_item_id ${orderSql}
|
ORDER BY ${orderSql}
|
||||||
LIMIT $1
|
LIMIT $1
|
||||||
),
|
),
|
||||||
page_bounds AS (
|
page_bounds AS (
|
||||||
@@ -623,35 +620,29 @@ export async function runCarrierDispatchJob(job: JsonObject = {}) {
|
|||||||
async function resolveCarrierDispatchExceptions(cutoffCreatedAt: string): Promise<number> {
|
async function resolveCarrierDispatchExceptions(cutoffCreatedAt: string): Promise<number> {
|
||||||
// 游标会跳过已扫过的订单项;配置是后来补的,这里兜底把配置挂上。
|
// 游标会跳过已扫过的订单项;配置是后来补的,这里兜底把配置挂上。
|
||||||
const attachParams: unknown[] = []
|
const attachParams: unknown[] = []
|
||||||
const attachCutoff = fulfillmentCreatedAfterSql(attachParams, cutoffCreatedAt)
|
const attachCutoff = fulfillmentCreatedAfterSql(attachParams, cutoffCreatedAt, 'f')
|
||||||
const attachCandidates = await query<{ order_item_id: number; config_id: number }>(
|
const attachCandidates = await query<{ order_item_id: number; config_id: number }>(
|
||||||
`
|
`
|
||||||
SELECT DISTINCT ON (oi.id)
|
SELECT DISTINCT ON (f.order_item_id)
|
||||||
oi.id AS order_item_id,
|
f.order_item_id AS order_item_id,
|
||||||
cfg.id AS config_id
|
cfg.id AS config_id
|
||||||
FROM fulfillments f
|
FROM fulfillments f
|
||||||
JOIN order_items oi ON oi.id = f.order_item_id
|
|
||||||
JOIN manual_fulfillment_configs cfg
|
JOIN manual_fulfillment_configs cfg
|
||||||
ON canonicalize_internal_sku(cfg.sku_key) = resolve_internal_sku(
|
ON cfg.sku_key = f.internal_sku
|
||||||
oi.manual_sku_key, oi.sku_name, oi.sku_code
|
|
||||||
)
|
|
||||||
AND cfg.enabled
|
AND cfg.enabled
|
||||||
WHERE canonicalize_internal_sku(cfg.sku_key) = resolve_internal_sku(
|
WHERE f.status = 'assigned'
|
||||||
oi.manual_sku_key, oi.sku_name, oi.sku_code
|
|
||||||
)
|
|
||||||
AND f.status = 'assigned'
|
|
||||||
AND f.channel = 'manual'
|
AND f.channel = 'manual'
|
||||||
AND f.fulfillment_config_id IS NULL
|
AND f.fulfillment_config_id IS NULL
|
||||||
AND EXISTS (
|
AND EXISTS (
|
||||||
SELECT 1
|
SELECT 1
|
||||||
FROM cost_exception_items i
|
FROM cost_exception_items i
|
||||||
JOIN cost_exceptions ce ON ce.id = i.exception_id
|
JOIN cost_exceptions ce ON ce.id = i.exception_id
|
||||||
WHERE i.order_item_id = oi.id
|
WHERE i.order_item_id = f.order_item_id
|
||||||
AND ce.reason = 'manual_config_missing'
|
AND ce.reason = 'manual_config_missing'
|
||||||
AND ce.status <> 'resolved'
|
AND ce.status <> 'resolved'
|
||||||
)
|
)
|
||||||
${attachCutoff}
|
${attachCutoff}
|
||||||
ORDER BY oi.id, cfg.id
|
ORDER BY f.order_item_id, cfg.id
|
||||||
LIMIT 500
|
LIMIT 500
|
||||||
`,
|
`,
|
||||||
attachParams,
|
attachParams,
|
||||||
|
|||||||
@@ -4,11 +4,9 @@ import { WorkerListCache } from './worker-list-cache.js'
|
|||||||
/**
|
/**
|
||||||
* 后台工单「店铺」筛选下拉的缓存归属模块。
|
* 后台工单「店铺」筛选下拉的缓存归属模块。
|
||||||
*
|
*
|
||||||
* 为什么要缓存:这条 SQL 从 orders(约 43 万行)出发做并行全表扫描,再与 work_orders
|
* 为什么要缓存:结果只有十几个店铺名,且只在「某个店铺第一次产生工单」时才会变。
|
||||||
* 做哈希半连接,生产实测单次 1.6 秒、读 22~28 万块(≈200MB 磁盘),而结果只有十几个
|
* 迁移 188 后底层读取窄投影,但后台工单页每次挂载、每次改单后的 refreshAll 仍会重复查询;
|
||||||
* 店铺名,且只在「某个店铺第一次产生工单」时才会变。后台工单页每次挂载、每次改单后的
|
* 缓存继续合并并发请求并避免无意义往返。
|
||||||
* refreshAll 都会重新全表扫一遍,几条并发就能吃掉 4 核里的一到两个核,连接池随即见底
|
|
||||||
* (2026-10-30 18:57 的生产事故就是这么放大的)。
|
|
||||||
*
|
*
|
||||||
* 为什么单独一个文件:缓存实例要同时被「读」(admin-work-order-query-service)和
|
* 为什么单独一个文件:缓存实例要同时被「读」(admin-work-order-query-service)和
|
||||||
* 「写」(建单/删单路径主动失效)引用,抽成只依赖 WorkerListCache 的中立模块,
|
* 「写」(建单/删单路径主动失效)引用,抽成只依赖 WorkerListCache 的中立模块,
|
||||||
|
|||||||
@@ -1966,7 +1966,7 @@ test('打手订单状态筛选使用个人拼单份额状态', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
assert.deepEqual(params, [42, ['in_progress', 'pending_acceptance']])
|
assert.deepEqual(params, [42, ['in_progress', 'pending_acceptance']])
|
||||||
assert.match(joins, /work_order_shares share_source/)
|
assert.match(whereClause, /work_order_shares share_source/)
|
||||||
// 份额关联改为按工单取一条代表份额,避免多份拼单把列表/统计行放大。
|
// 份额关联改为按工单取一条代表份额,避免多份拼单把列表/统计行放大。
|
||||||
assert.match(joins, /LEFT JOIN LATERAL \(/)
|
assert.match(joins, /LEFT JOIN LATERAL \(/)
|
||||||
assert.match(joins, /wos\.worker_id = \$1/)
|
assert.match(joins, /wos\.worker_id = \$1/)
|
||||||
@@ -1999,7 +1999,7 @@ test('工单筛选支持内部寄售来源叠加人员条件,并保持好友
|
|||||||
acceptanceMode: 'internal_consignment',
|
acceptanceMode: 'internal_consignment',
|
||||||
workerSharingId: 25,
|
workerSharingId: 25,
|
||||||
})
|
})
|
||||||
assert.match(workerScopedInternalQuery.joins, /worker_visible\.work_order_id = wo\.id/)
|
assert.match(workerScopedInternalQuery.whereClause, /wo\.id = ANY\(ARRAY\(/)
|
||||||
assert.match(
|
assert.match(
|
||||||
workerScopedInternalQuery.whereClause,
|
workerScopedInternalQuery.whereClause,
|
||||||
/wo\.material_json->'consignment'->>'inventoryId' IS NOT NULL/,
|
/wo\.material_json->'consignment'->>'inventoryId' IS NOT NULL/,
|
||||||
@@ -3051,13 +3051,10 @@ test('筛选统计必须有短缓存 + 并发合并,避免成本随工单量
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
test('后台「店铺」筛选下拉必须缓存 + 写路径失效(单次全表扫约 200MB)', async () => {
|
test('后台「店铺」筛选下拉必须缓存 + 写路径失效', async () => {
|
||||||
const { readFile } = await import('node:fs/promises')
|
const { readFile } = await import('node:fs/promises')
|
||||||
|
|
||||||
// 背景:listWorkOrderShopNames 从 orders(43 万行)做并行全表扫描,再与 work_orders
|
// 迁移 188 后用窄投影消除大表探测;页面高频刷新仍必须保持缓存和主动失效。
|
||||||
// 做哈希半连接。生产实测单次 1.6 秒、读 22~28 万块(≈200MB),结果却只有十几个店铺名。
|
|
||||||
// 2026-10-30 18:57 的事故里,后台工单页每次挂载、每次改单后的 refreshAll 都重算一遍,
|
|
||||||
// 几条并发就把 4 核打满并拖垮连接池,所以这里必须有缓存 + 主动失效。
|
|
||||||
const cacheModule = await readFile(
|
const cacheModule = await readFile(
|
||||||
new URL('./work-order-shop-options-cache.ts', import.meta.url),
|
new URL('./work-order-shop-options-cache.ts', import.meta.url),
|
||||||
'utf8',
|
'utf8',
|
||||||
|
|||||||
+11
-4
@@ -11,8 +11,8 @@ updated_at: 2026-11-28
|
|||||||
|
|
||||||
> 状态:**唯一权威文档**。
|
> 状态:**唯一权威文档**。
|
||||||
> 最后校准:2026-11-28。
|
> 最后校准:2026-11-28。
|
||||||
> 生产基线:迁移 `186`(2026-11-28 部署验证)。
|
> 生产基线:迁移 `187`(2026-11-28 部署验证)。
|
||||||
> 开发基线:迁移 `187`(热路径索引与 SQL 优化,仅本地)。
|
> 开发基线:迁移 `188`(履约/工单热路径二次收敛,未部署)。
|
||||||
>
|
>
|
||||||
> 从本文件生效起,订单、内部 SKU、履约渠道、履约载体、标准商品、成本和财务相关实现,
|
> 从本文件生效起,订单、内部 SKU、履约渠道、履约载体、标准商品、成本和财务相关实现,
|
||||||
> 只能以本文件为业务口径。其他旧分析只作为历史资料,不再具备设计或验收效力。
|
> 只能以本文件为业务口径。其他旧分析只作为历史资料,不再具备设计或验收效力。
|
||||||
@@ -1263,7 +1263,7 @@ docs/archive/
|
|||||||
|
|
||||||
## 十三、当前下一步
|
## 十三、当前下一步
|
||||||
|
|
||||||
截至 2026-11-28,生产基线为 `185`,当前开发基线为 `186`。迁移 `152` 保护订单来源快照,
|
截至 2026-11-28,生产基线为 `187`,当前开发基线为 `188`。迁移 `152` 保护订单来源快照,
|
||||||
迁移 `158–160` 收口寄卖登记人同步、寄卖平台与自动匹配设置;
|
迁移 `158–160` 收口寄卖登记人同步、寄卖平台与自动匹配设置;
|
||||||
迁移 `161` 一次建立人工渠道半自动任务、内置 Connector 默认值、账号级 Cookie JSON 凭证、
|
迁移 `161` 一次建立人工渠道半自动任务、内置 Connector 默认值、账号级 Cookie JSON 凭证、
|
||||||
任务凭证引用和最终约束;迁移 `162` 建立履约待办四桶只读投影、补载体专用索引和新单优先扫描口径。
|
任务凭证引用和最终约束;迁移 `162` 建立履约待办四桶只读投影、补载体专用索引和新单优先扫描口径。
|
||||||
@@ -1300,7 +1300,14 @@ pending 角色快照、`role_identity_source` 与 `verification_basis`。
|
|||||||
`pending / assigned` 履约记录,`archived` 不再进入待办投影或阻塞补载体扫描。
|
`pending / assigned` 履约记录,`archived` 不再进入待办投影或阻塞补载体扫描。
|
||||||
迁移 `186` 增加 `idx_fulfillments_assigned_carrier_active` 与 `idx_fulfillments_assigned_manual_unconfigured` 热路径部分索引,
|
迁移 `186` 增加 `idx_fulfillments_assigned_carrier_active` 与 `idx_fulfillments_assigned_manual_unconfigured` 热路径部分索引,
|
||||||
配合渠道分配同轮挂接 `fulfillment_config_id`、`carrier-dispatch` 直连 `fulfillments` 的两段式有界游标扫描(`carrier_assigned_repair`)与斗鱼后台严格纯读(精确单号未物化时返回只读 `pendingHints`),消除后台超时、`carrier-dispatch` 长查询锁竞争与 `manual` 新单卡在未配置态等待 12–26 分钟的链路断层。
|
配合渠道分配同轮挂接 `fulfillment_config_id`、`carrier-dispatch` 直连 `fulfillments` 的两段式有界游标扫描(`carrier_assigned_repair`)与斗鱼后台严格纯读(精确单号未物化时返回只读 `pendingHints`),消除后台超时、`carrier-dispatch` 长查询锁竞争与 `manual` 新单卡在未配置态等待 12–26 分钟的链路断层。
|
||||||
迁移 `187` 补齐 `fulfillment_tasks` 回调 JSONB 表达式索引(`affiliate_dash` / `kuaishou_feifei`)、自动发货失败任务窄索引、`fulfillments` 已配人工及自动/工单载体部分索引、`orders` 修剪店铺名倒序索引、`admin_notifications` 待办排序表达式部分索引及 `work_orders` 排行榜覆盖索引;配合 `carrier_dispatch` 有界分页游标与 `runAffiliateFallback` 失败任务反查,消除 15s 语句超时、店铺下拉/通知排序/总榜全表扫描与 `carrier_dispatch` 零异常回绕。
|
迁移 `187` 补齐 `fulfillment_tasks` 回调 JSONB 表达式索引(`affiliate_dash` / `kuaishou_feifei`)、自动发货失败任务窄索引、`fulfillments` 已配人工及自动/工单载体部分索引、`orders` 修剪店铺名倒序索引、`admin_notifications` 待办排序表达式部分索引及 `work_orders` 排行榜覆盖索引;配合 `carrier_dispatch` 有界分页游标与 `runAffiliateFallback` 失败任务反查,收敛回调反查、通知排序、排行榜和零异常游标回绕。
|
||||||
|
2026-11-28 生产部署后只读验证确认 `187` 已生效,但高峰流量下 `carrier_dispatch` 新单窗口、
|
||||||
|
斗鱼 7 天人工任务同步和店铺下拉仍可达到 5–20 秒,部分请求继续触发 15 秒超时。
|
||||||
|
迁移 `188` 因此补齐:`fulfillments.created_at` 的自动/人工新单窗口部分索引;人工配置按
|
||||||
|
`order_id` 倒序的斗鱼同步索引;`orders` 有效下单时间覆盖索引;`work_orders` 店铺名窄投影及
|
||||||
|
触发器;并重写 `v_fulfillment_queue`,先判桶再对满足条件的 pending 记录探测活跃任务/工单。
|
||||||
|
查询侧同步改为使用 `fulfillments.internal_sku` 权威字段,避免在 500–5000 行候选页上重复调用
|
||||||
|
`resolve_internal_sku()`;打手可见工单集合改为数组索引探测,避免先把 `work_orders` 全表哈希。
|
||||||
迁移 `169` 增加客户游戏角色资料字段(`customer_game_role_name` / `customer_game_role_id` /
|
迁移 `169` 增加客户游戏角色资料字段(`customer_game_role_name` / `customer_game_role_id` /
|
||||||
`customer_game_server_zone`),并允许从工单素材回退合并;当前客户资料要求角色名、UID 和区服三项齐全,
|
`customer_game_server_zone`),并允许从工单素材回退合并;当前客户资料要求角色名、UID 和区服三项齐全,
|
||||||
其中 `customer_game_role_id` 只校验非空,不校验格式。客户页流程收敛为
|
其中 `customer_game_role_id` 只校验非空,不校验格式。客户页流程收敛为
|
||||||
|
|||||||
Reference in New Issue
Block a user