-- 1.0.382：Phase 1J S7 FQC 检验单详情统一页 result-detail 隐藏菜单 + 角色授权
-- 背景：抽屉 + 旧录入页收敛为单一路由页 /aidop/s7/fqc/result-detail（组件 fqcInspResultDetail）。
--       任务列表/结果列表/审批中心 N1-N3 均跳此页；页面按 flowState 决定录入/审核/处置/只读。
-- 幂等：菜单按 Id NOT EXISTS 插入；授权按 (RoleId,MenuId) NOT EXISTS 插入，SysRoleMenu.Id = MAX(Id)+每行固定 rn（确定唯一，避免 @变量在 MySQL8 求值顺序未定义导致重复 PK）。
-- 授权口径：并集 = 旧 insp-detail(1329017010007) ∪ result-list(1329017010002) 的 14 个既有角色
--            + S5 IQC / S6 IPQC / S7 FQC 共 9 个检验角色（保证仅绑检验角色的用户也能进详情页）。
-- 方言：MySQL（主库 aidopdev）。SysMenu / SysRoleMenu 为框架表 PascalCase。

-- ① 隐藏菜单：FQC检验单详情（Id=1329017010008，Pid=成品质量管理目录 1322000000023）
INSERT INTO SysMenu (Id, Pid, Type, Title, Name, Path, Component, Icon, IsIframe, IsHide, IsKeepAlive, IsAffix, OrderNo, Status, CreateTime)
SELECT 1329017010008, 1322000000023, 2, 'FQC检验单详情', 'aidopS7FqcResultDetail',
       '/aidop/s7/fqc/result-detail', '/aidop/s7/fqc/fqcInspResultDetail', 'ele-Document',
       0, 1, 1, 0, 45, 1, NOW()
WHERE NOT EXISTS (SELECT 1 FROM SysMenu WHERE Id = 1329017010008);

-- ② 角色授权（并集 14 + 检验角色 9；仅补缺，Id = MAX+固定行号 rn）
INSERT INTO SysRoleMenu (Id, RoleId, MenuId)
SELECT base.m + t.rn, t.RoleId, 1329017010008
FROM (SELECT COALESCE(MAX(Id), 0) AS m FROM SysRoleMenu) base
CROSS JOIN (
    SELECT 1300000000101 AS RoleId, 1 AS rn
    UNION ALL SELECT 1300000000106, 2
    UNION ALL SELECT 1300000000777, 3
    UNION ALL SELECT 1300000000888, 4
    UNION ALL SELECT 789818613628997, 5
    UNION ALL SELECT 795859517808709, 6
    UNION ALL SELECT 795859651027013, 7
    UNION ALL SELECT 795860051161157, 8
    UNION ALL SELECT 798583831580741, 9
    UNION ALL SELECT 829309961850949, 10
    UNION ALL SELECT 837196242882629, 11
    UNION ALL SELECT 838258976469061, 12
    UNION ALL SELECT 838258980438085, 13
    UNION ALL SELECT 838259499909189, 14
    UNION ALL SELECT 1329915010001, 15
    UNION ALL SELECT 1329915010002, 16
    UNION ALL SELECT 1329915010003, 17
    UNION ALL SELECT 1329915020001, 18
    UNION ALL SELECT 1329915020002, 19
    UNION ALL SELECT 1329915020003, 20
    UNION ALL SELECT 1329916010001, 21
    UNION ALL SELECT 1329916010002, 22
    UNION ALL SELECT 1329916010003, 23
) t
WHERE NOT EXISTS (SELECT 1 FROM SysRoleMenu x WHERE x.RoleId = t.RoleId AND x.MenuId = 1329017010008);
