-- 备品备件：按产品目录拆分为单品记录（替代「一条里写多个品名」的种子数据）
-- 执行前请备份数据库。使用 UTF-8 客户端执行。
-- 封面图 cover_image 留空，可在后台「备品备件」里逐条上传。
-- 备件插入后执行 patch_spare_part_categories.sql：左侧为五大类分组，并联表 category_id。

SET NAMES utf8mb4 COLLATE utf8mb4_unicode_ci;

SET @cid := COALESCE(
  (SELECT product_category_id FROM f_product_category
   WHERE del_flag = 0 AND parent_id IS NULL AND name_zh = '备品备件'
   ORDER BY product_category_id ASC LIMIT 1),
  6
);

-- 若你的项目里 module_type 已启用，也可仅用备品备件根节点：
-- SET @cid := (SELECT MIN(product_category_id) FROM f_product_category WHERE module_type = 'spare_part' AND parent_id IS NULL AND del_flag = 0 LIMIT 1);

UPDATE f_spare_part
SET del_flag = 1
WHERE del_flag = 0
  AND name_zh IN ('辐射管（W/I/U型）', '换热器', '炉辊与张力辊');

INSERT INTO f_spare_part (
  category_id, name_zh, name_en,
  description_zh, description_en,
  sort_order, is_published, del_flag
) VALUES
(@cid, '翅片管换热器', 'Finned Tube Heat Exchanger', '备品备件', 'Spare parts', 10, 1, 0),
(@cid, 'RJC 换热器', 'RJC Heat exchanger', '备品备件', 'Spare parts', 20, 1, 0),
(@cid, 'W 型辐射管', 'W-radiant tube', '备品备件', 'Spare parts', 30, 1, 0),
(@cid, 'I 型辐射管', 'I-type Radiant Tube', '备品备件', 'Spare parts', 40, 1, 0),
(@cid, 'U 型辐射管', 'U-Radiant Tube', '备品备件', 'Spare parts', 50, 1, 0),
(@cid, '滑块', 'Slide Block', '备品备件', 'Spare parts', 60, 1, 0),
(@cid, '轴套衬套', 'Bush and Sleeve', '备品备件', 'Spare parts', 70, 1, 0),
(@cid, '支臂', 'Support Arm', '备品备件', 'Spare parts', 80, 1, 0),
(@cid, '炉辊', 'Hearth Roll', '备品备件', 'Spare parts', 90, 1, 0),
(@cid, '大炉辊', 'Big Hearth Roll', '备品备件', 'Spare parts', 100, 1, 0),
(@cid, '镀铬辊', 'Chromed Roll', '备品备件', 'Spare parts', 110, 1, 0),
(@cid, '氯丁胶转向辊', 'Rubber Turning Roll', '备品备件', 'Spare parts', 120, 1, 0),
(@cid, '聚氨酯辊', 'PU Roll', '备品备件', 'Spare parts', 130, 1, 0),
(@cid, '汲料辊', 'Pick Up Roll', '备品备件', 'Spare parts', 140, 1, 0),
(@cid, '托辊', 'Support Roll', '备品备件', 'Spare parts', 150, 1, 0),
(@cid, '水淬辊', 'Water Quenching Roll', '备品备件', 'Spare parts', 160, 1, 0),
(@cid, '张力辊', 'Bridle Roll', '备品备件', 'Spare parts', 170, 1, 0);
