-- 总成检具NG点位参数：菜单 + 角色授权（整段执行）
-- menu_code 必须是：2099040100000000001（注意末尾有 4 个 0 再 1）

DELETE FROM `js_sys_role_menu` WHERE `menu_code` = '2099040100000000001';
DELETE FROM `js_sys_menu` WHERE `menu_code` = '2099040100000000001';

INSERT INTO `js_sys_menu`
(`menu_code`, `parent_code`, `parent_codes`, `tree_sort`, `tree_sorts`, `tree_leaf`, `tree_level`,
 `tree_names`, `menu_name`, `menu_type`, `menu_href`, `menu_target`, `menu_icon`, `menu_color`, `menu_title`,
 `permission`, `weight`, `is_show`, `sys_code`, `module_codes`, `component`, `params`, `status`,
 `create_by`, `create_date`, `update_by`, `update_date`, `remarks`)
VALUES
('2099040100000000001', '2042038662094802944', '0,1672118505143263232,2042038662094802944,',
 220, '0000009290,0000000660,0000000220,', '1', 2,
 '生产管理/工艺过程参数/总成检具NG点位参数', '总成检具NG点位参数', '1',
 '/mes/mesProductGaugeNg/list', '', '', '', '',
 'mes:mesProductGaugeNg:view,mes:mesProductGaugeNg:edit',
 40, '1', 'default', 'core', NULL, NULL, '0',
 'system', NOW(), 'system', NOW(), '总成检具NG点位参数');

-- 给所有角色都授权这个菜单（超级管理员也能看到）
INSERT INTO `js_sys_role_menu` (`role_code`, `menu_code`)
SELECT r.`role_code`, '2099040100000000001'
FROM `js_sys_role` r
WHERE r.`status` = '0'
  AND NOT EXISTS (
    SELECT 1 FROM `js_sys_role_menu` x
    WHERE x.`role_code` = r.`role_code`
      AND x.`menu_code` = '2099040100000000001'
  );

-- 执行后自检（应各有结果）
SELECT menu_code, menu_name, menu_href FROM js_sys_menu WHERE menu_code = '2099040100000000001';
SELECT COUNT(*) AS role_menu_count FROM js_sys_role_menu WHERE menu_code = '2099040100000000001';
