-- 异步导出任务菜单
-- 说明：
-- 1. 在“系统设置”下补充“导出任务”页面菜单
-- 2. 权限标识为 system:exportTask:list
-- 3. 页面展示当前登录用户的异步导出任务，并支持下载已完成文件

SET @tenant_id := 1;

SET @system_menu_id := (
  SELECT id
  FROM sys_menu
  WHERE deleted = 0
    AND tenant_id = @tenant_id
    AND type = 0
    AND (
      route = '/system'
      OR component = 'system'
      OR name = 'menu.system'
    )
  ORDER BY id
  LIMIT 1
);

INSERT INTO sys_menu (
  name,
  parent_id,
  parent_name,
  path,
  path_name,
  route,
  component,
  brief,
  code,
  type,
  authority,
  icon,
  sort,
  meta,
  tenant_id,
  status,
  deleted,
  create_time,
  create_by,
  update_time,
  update_by,
  memo
)
SELECT
  'menu.exportTask',
  @system_menu_id,
  'menu.system',
  '/system/export-task',
  '/system/export-task',
  '/system/export-task',
  'exportTask',
  '异步导出任务',
  NULL,
  0,
  'system:exportTask:list',
  'History',
  90,
  NULL,
  @tenant_id,
  1,
  0,
  NOW(),
  1,
  NOW(),
  1,
  '当前用户异步导出任务列表'
FROM dual
WHERE @system_menu_id IS NOT NULL
  AND NOT EXISTS (
    SELECT 1
    FROM sys_menu
    WHERE deleted = 0
      AND tenant_id = @tenant_id
      AND authority = 'system:exportTask:list'
  );
