/* 修改人:Ld 修改时间:2026-08-06 16:23:41; 将工艺查询、工艺管理迁到APS，并将通用件装配、专机装配下二级菜单迁到MES */
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
(84, 159, 2),
(95, 159, 3),
(94, 161, 1),
(78, 161, 2),
(28, 161, 3),
(98, 161, 4),
(80, 161, 5),
(29, 161, 6),
(79, 161, 7),
(30, 161, 8),
(100, 161, 9),
(153, 161, 10),
(154, 161, 11),
(149, 161, 12),
(64, 161, 13),
(65, 161, 14),
(66, 161, 15),
(70, 161, 16),
(89, 161, 17),
(90, 161, 18),
(91, 161, 19),
(101, 161, 20),
(72, 161, 21),
(73, 161, 22),
(74, 161, 23);

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;
