-- HRM 薪酬结构配置菜单与权限（可重复执行）

INSERT INTO `system_menu`
(`id`, `name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `component_name`,
 `status`, `visible`, `keep_alive`, `always_show`, `creator`, `create_time`, `updater`, `update_time`, `deleted`)
VALUES
(6025, '薪酬结构', '', 2, 3, 6020, 'structure', 'ep:set-up',
 'hrm/salary/structure/index', 'HrmSalaryStructure', 0, b'1', b'1', b'1', '1', NOW(), '1', NOW(), b'0'),
(60251, '薪酬结构查询', 'hrm:salary-structure:query', 3, 1, 6025, '', '', '', NULL,
 0, b'1', b'1', b'1', '1', NOW(), '1', NOW(), b'0'),
(60252, '薪酬结构新增', 'hrm:salary-structure:create', 3, 2, 6025, '', '', '', NULL,
 0, b'1', b'1', b'1', '1', NOW(), '1', NOW(), b'0'),
(60253, '薪酬结构修改', 'hrm:salary-structure:update', 3, 3, 6025, '', '', '', NULL,
 0, b'1', b'1', b'1', '1', NOW(), '1', NOW(), b'0'),
(60254, '薪酬结构删除', 'hrm:salary-structure:delete', 3, 4, 6025, '', '', '', NULL,
 0, b'1', b'1', b'1', '1', NOW(), '1', NOW(), b'0')
ON DUPLICATE KEY UPDATE
`name` = VALUES(`name`), `permission` = VALUES(`permission`), `parent_id` = VALUES(`parent_id`),
`path` = VALUES(`path`), `icon` = VALUES(`icon`), `component` = VALUES(`component`),
`component_name` = VALUES(`component_name`), `status` = VALUES(`status`), `deleted` = b'0';

INSERT INTO `system_role_menu`
(`role_id`, `menu_id`, `creator`, `create_time`, `updater`, `update_time`, `deleted`)
SELECT 1, menu_id, '1', NOW(), '1', NOW(), b'0'
FROM (
    SELECT 6025 AS menu_id UNION ALL SELECT 60251 UNION ALL SELECT 60252
    UNION ALL SELECT 60253 UNION ALL SELECT 60254
) menu_ids
WHERE NOT EXISTS (
    SELECT 1 FROM `system_role_menu` role_menu
    WHERE role_menu.`role_id` = 1 AND role_menu.`menu_id` = menu_ids.menu_id AND role_menu.`deleted` = b'0'
);

SELECT 'HRM 薪酬结构菜单初始化完成' AS result;
