-- 钉钉技术方案申请归档 — 菜单
-- parent_id：1 = 系统管理（可按实际菜单树修改）
-- menu_id 由 MAX+1 动态分配，避免与现有 ID 冲突；可重复执行（幂等）
-- 执行前可选：SELECT IFNULL(MAX(menu_id), 0) + 1 FROM sys_menu;

-- 菜单页
INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
SELECT (SELECT IFNULL(MAX(menu_id), 0) + 1 FROM sys_menu),
       '技术方案申请',
       1,
       21,
       'dingSchemeApplication',
       'system/dingSchemeApplication/index',
       1, 0, 'C', '0', '0',
       'system:dingSchemeApplication:list',
       'form',
       'admin', sysdate(), '', NULL,
       '钉钉技术方案申请归档与 PLM 推送'
FROM DUAL
WHERE NOT EXISTS (SELECT 1 FROM sys_menu WHERE perms = 'system:dingSchemeApplication:list');

-- 查询按钮权限
INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
SELECT (SELECT IFNULL(MAX(menu_id), 0) + 1 FROM sys_menu),
       '技术方案申请查询',
       m.menu_id,
       1,
       '#',
       '',
       1, 0, 'F', '0', '0',
       'system:dingSchemeApplication:query',
       '#',
       'admin', sysdate(), '', NULL,
       ''
FROM sys_menu m
WHERE m.path = 'dingSchemeApplication'
  AND m.menu_type = 'C'
  AND NOT EXISTS (SELECT 1 FROM sys_menu WHERE perms = 'system:dingSchemeApplication:query');
