-- 数据管理 / 仓库管理 菜单及按钮权限
-- 执行前请确认 menu_id 未被占用：SELECT MAX(menu_id) FROM sys_menu;
-- 父菜单：数据管理 (menu_id = 2121)
-- 权限标识与后端接口保持一致

-- 1. 菜单：仓库管理
INSERT INTO `sys_menu` (
    `menu_id`, `menu_name`, `parent_id`, `order_num`, `path`, `component`,
    `query`, `route_name`, `is_frame`, `is_cache`, `menu_type`, `visible`,
    `status`, `perms`, `icon`, `create_by`, `create_time`, `update_by`,
    `update_time`, `remark`, `use_type`
) VALUES (
    2700, '仓库管理', 2121, 5, 'warehouse', 'data/warehouse/index',
    NULL, '', 1, 0, 'C', '0',
    '0', 'activation:bookActivationCodeRepository:list', 'HomeOutlined', 'admin', NOW(), '',
    NULL, '图书激活码仓库管理', 1
);

-- 2. 按钮：新增
INSERT INTO `sys_menu` (
    `menu_id`, `menu_name`, `parent_id`, `order_num`, `path`, `component`,
    `query`, `route_name`, `is_frame`, `is_cache`, `menu_type`, `visible`,
    `status`, `perms`, `icon`, `create_by`, `create_time`, `update_by`,
    `update_time`, `remark`, `use_type`
) VALUES (
    2701, '新增', 2700, 1, '', NULL,
    NULL, '', 1, 0, 'F', '0',
    '0', 'activation:bookActivationCodeRepository:add', '#', 'admin', NOW(), '',
    NULL, '', 1
);

-- 3. 按钮：详情/查询
INSERT INTO `sys_menu` (
    `menu_id`, `menu_name`, `parent_id`, `order_num`, `path`, `component`,
    `query`, `route_name`, `is_frame`, `is_cache`, `menu_type`, `visible`,
    `status`, `perms`, `icon`, `create_by`, `create_time`, `update_by`,
    `update_time`, `remark`, `use_type`
) VALUES (
    2702, '详情', 2700, 2, '', NULL,
    NULL, '', 1, 0, 'F', '0',
    '0', 'activation:bookActivationCodeRepository:query', '#', 'admin', NOW(), '',
    NULL, '', 1
);

-- 4. 按钮：修改
INSERT INTO `sys_menu` (
    `menu_id`, `menu_name`, `parent_id`, `order_num`, `path`, `component`,
    `query`, `route_name`, `is_frame`, `is_cache`, `menu_type`, `visible`,
    `status`, `perms`, `icon`, `create_by`, `create_time`, `update_by`,
    `update_time`, `remark`, `use_type`
) VALUES (
    2703, '修改', 2700, 3, '', NULL,
    NULL, '', 1, 0, 'F', '0',
    '0', 'activation:bookActivationCodeRepository:update', '#', 'admin', NOW(), '',
    NULL, '', 1
);

-- 5. 按钮：启用/禁用
INSERT INTO `sys_menu` (
    `menu_id`, `menu_name`, `parent_id`, `order_num`, `path`, `component`,
    `query`, `route_name`, `is_frame`, `is_cache`, `menu_type`, `visible`,
    `status`, `perms`, `icon`, `create_by`, `create_time`, `update_by`,
    `update_time`, `remark`, `use_type`
) VALUES (
    2704, '启用/禁用', 2700, 4, '', NULL,
    NULL, '', 1, 0, 'F', '0',
    '0', 'activation:bookActivationCodeRepository:openClose', '#', 'admin', NOW(), '',
    NULL, '', 1
);

-- 6. 给超级管理员角色授权（role_id = 1，按实际调整）
INSERT INTO `sys_role_menu` (`role_id`, `menu_id`)
SELECT 1, m.menu_id
FROM `sys_menu` m
WHERE m.menu_id IN (2700, 2701, 2702, 2703, 2704)
  AND NOT EXISTS (
      SELECT 1 FROM `sys_role_menu` rm
      WHERE rm.role_id = 1 AND rm.menu_id = m.menu_id
  );
