/* 修改人:Ld 修改时间:2026-08-06 16:15:15; 按确认归属补迁订单投产、物料采购进度和新产品合同类二级组件 */
SET XACT_ABORT ON;
BEGIN TRAN;

DECLARE @MoveMap TABLE
(
    id INT PRIMARY KEY,
    目标pid INT NOT NULL,
    顺序 INT NOT NULL
);

INSERT INTO @MoveMap (id, 目标pid, 顺序)
VALUES
(88, 160, 31),
(149, 161, 15),
(125, 162, 12),
(126, 162, 13),
(133, 162, 14);

UPDATE r
SET r.pid = m.目标pid,
    r.模块顺序 = r.id,
    r.是否启用 = 1,
    r.角色模块顺序 = m.顺序
FROM dbo.基础表_角色模块信息 r
INNER JOIN @MoveMap m ON m.id = r.id
WHERE r.角色编号 = 2;

SELECT p.title AS 新一级菜单, c.id AS 二级ID, c.title AS 二级菜单, r.角色模块顺序
FROM @MoveMap m
INNER JOIN dbo.基础表_角色模块信息 r ON r.id = m.id AND r.角色编号 = 2
INNER JOIN dbo.基础表_模块信息 c ON c.id = r.id
INNER JOIN dbo.基础表_模块信息 p ON p.id = r.pid
ORDER BY p.id, r.角色模块顺序, c.id;

COMMIT TRAN;
