-- 实体库管理菜单
-- 挂载到“信息维护”目录下，可重复执行

SET @parent_menu_id = (
    SELECT menu_id
    FROM sys_menu
    WHERE menu_name = '信息维护'
      AND parent_id = 0
    LIMIT 1
);

INSERT INTO sys_menu (
    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
    '实体库管理',
    @parent_menu_id,
    12,
    'enterpriseBaseInfo',
    'ccdiEnterpriseBaseInfo/index',
    1,
    0,
    'C',
    '0',
    '0',
    'ccdi:enterpriseBaseInfo:list',
    'documentation',
    'admin',
    NOW(),
    '',
    NULL,
    '实体库管理菜单'
FROM dual
WHERE @parent_menu_id IS NOT NULL
  AND NOT EXISTS (
      SELECT 1
      FROM sys_menu
      WHERE parent_id = @parent_menu_id
        AND path = 'enterpriseBaseInfo'
  );

SET @menu_id = (
    SELECT menu_id
    FROM sys_menu
    WHERE parent_id = @parent_menu_id
      AND path = 'enterpriseBaseInfo'
    LIMIT 1
);

INSERT INTO sys_menu (
    menu_name,
    parent_id,
    order_num,
    path,
    component,
    is_frame,
    is_cache,
    menu_type,
    visible,
    status,
    perms,
    icon,
    create_by,
    create_time,
    remark
)
SELECT '实体库查询', @menu_id, 1, '', '', 1, 0, 'F', '0', '0', 'ccdi:enterpriseBaseInfo:query', '#', 'admin', NOW(), ''
FROM dual
WHERE @menu_id IS NOT NULL
  AND NOT EXISTS (
      SELECT 1
      FROM sys_menu
      WHERE parent_id = @menu_id
        AND perms = 'ccdi:enterpriseBaseInfo:query'
  );

INSERT INTO sys_menu (
    menu_name,
    parent_id,
    order_num,
    path,
    component,
    is_frame,
    is_cache,
    menu_type,
    visible,
    status,
    perms,
    icon,
    create_by,
    create_time,
    remark
)
SELECT '实体库新增', @menu_id, 2, '', '', 1, 0, 'F', '0', '0', 'ccdi:enterpriseBaseInfo:add', '#', 'admin', NOW(), ''
FROM dual
WHERE @menu_id IS NOT NULL
  AND NOT EXISTS (
      SELECT 1
      FROM sys_menu
      WHERE parent_id = @menu_id
        AND perms = 'ccdi:enterpriseBaseInfo:add'
  );

INSERT INTO sys_menu (
    menu_name,
    parent_id,
    order_num,
    path,
    component,
    is_frame,
    is_cache,
    menu_type,
    visible,
    status,
    perms,
    icon,
    create_by,
    create_time,
    remark
)
SELECT '实体库修改', @menu_id, 3, '', '', 1, 0, 'F', '0', '0', 'ccdi:enterpriseBaseInfo:edit', '#', 'admin', NOW(), ''
FROM dual
WHERE @menu_id IS NOT NULL
  AND NOT EXISTS (
      SELECT 1
      FROM sys_menu
      WHERE parent_id = @menu_id
        AND perms = 'ccdi:enterpriseBaseInfo:edit'
  );

INSERT INTO sys_menu (
    menu_name,
    parent_id,
    order_num,
    path,
    component,
    is_frame,
    is_cache,
    menu_type,
    visible,
    status,
    perms,
    icon,
    create_by,
    create_time,
    remark
)
SELECT '实体库删除', @menu_id, 4, '', '', 1, 0, 'F', '0', '0', 'ccdi:enterpriseBaseInfo:remove', '#', 'admin', NOW(), ''
FROM dual
WHERE @menu_id IS NOT NULL
  AND NOT EXISTS (
      SELECT 1
      FROM sys_menu
      WHERE parent_id = @menu_id
        AND perms = 'ccdi:enterpriseBaseInfo:remove'
  );

INSERT INTO sys_menu (
    menu_name,
    parent_id,
    order_num,
    path,
    component,
    is_frame,
    is_cache,
    menu_type,
    visible,
    status,
    perms,
    icon,
    create_by,
    create_time,
    remark
)
SELECT '实体库导入', @menu_id, 5, '', '', 1, 0, 'F', '0', '0', 'ccdi:enterpriseBaseInfo:import', '#', 'admin', NOW(), ''
FROM dual
WHERE @menu_id IS NOT NULL
  AND NOT EXISTS (
      SELECT 1
      FROM sys_menu
      WHERE parent_id = @menu_id
        AND perms = 'ccdi:enterpriseBaseInfo:import'
  );
