feat(consignment): 寄售仓库按寄卖分类筛选并支持动态规格过滤

This commit is contained in:
2026-11-06 16:12:26 +08:00
parent 1044948c99
commit f68375fa71
16 changed files with 1022 additions and 130 deletions
@@ -0,0 +1,66 @@
-- 144_consignment_inventory_category_backfill.sql
-- 寄售仓库按「寄卖配置分类」筛选的前置数据修复。
--
-- 背景:分类级寄卖配置(142)上线前入库的提报与库存没有写 category_id/profile_id,
-- 线上 784 条库存、877 条提报全部为空;不补的话「按分类筛选」在老数据上永远是空列表。
--
-- 口径:这批历史数据全部是苏尔南手枪(item_name 含「苏尔南」,spec_values_json 固定
-- system/serverZone/series/diamondLevel/brillianceCount 五个键),因此按该分类的
-- 已发布配置回填,幂等且只影响 category_id 为空的记录。
DO $migration$
DECLARE
v_category_id BIGINT;
v_profile_id BIGINT;
v_version_id BIGINT;
v_snapshot JSONB;
BEGIN
SELECT id INTO v_category_id
FROM work_categories
WHERE category_key = 'shouqiang'
LIMIT 1;
IF v_category_id IS NULL THEN
RETURN;
END IF;
SELECT p.id, p.current_version_id, v.config_json
INTO v_profile_id, v_version_id, v_snapshot
FROM consignment_profiles p
LEFT JOIN consignment_profile_versions v ON v.id = p.current_version_id
WHERE p.category_id = v_category_id
AND p.status = 'published'
LIMIT 1;
IF v_profile_id IS NULL THEN
RETURN;
END IF;
UPDATE consignment_inventories
SET category_id = v_category_id,
profile_id = COALESCE(profile_id, v_profile_id),
profile_version_id = COALESCE(profile_version_id, v_version_id),
profile_snapshot_json = COALESCE(profile_snapshot_json, v_snapshot)
WHERE category_id IS NULL
AND (
item_name LIKE '%苏尔南%'
OR (spec_values_json ? 'series' AND spec_values_json ? 'diamondLevel')
);
UPDATE consignment_submissions
SET category_id = v_category_id,
profile_id = COALESCE(profile_id, v_profile_id),
profile_version_id = COALESCE(profile_version_id, v_version_id),
profile_snapshot_json = COALESCE(profile_snapshot_json, v_snapshot)
WHERE category_id IS NULL
AND (
item_name LIKE '%苏尔南%'
OR (spec_values_json ? 'series' AND spec_values_json ? 'diamondLevel')
);
END $migration$;
CREATE INDEX IF NOT EXISTS idx_consignment_inventories_category
ON consignment_inventories (category_id, status);
COMMENT ON COLUMN consignment_inventories.category_id IS
'寄卖配置分类:寄售仓库按分类筛选的依据;142 之前的历史数据由 144 回填';