-- 将 通知上报 菜单挂载到：日志报表（优先）或开发专用
-- 说明：执行本脚本后，请在“角色授权”里给对应角色勾选新菜单和“查看”权限。

SET @notify_parent_id := COALESCE(
  (
    SELECT id
    FROM sys_resource
    WHERE code = 'logReport' AND level = 1
    ORDER BY id
    LIMIT 1
  ),
  (
    SELECT id
    FROM sys_resource
    WHERE code = 'develop' AND level = 1
    ORDER BY id
    LIMIT 1
  )
);

INSERT INTO sys_resource(code, name, resource_id, level, sort, status)
SELECT 'notifyReport/notifyReport.html', '通知上报', @notify_parent_id, 2, 998, 1
FROM dual
WHERE @notify_parent_id IS NOT NULL
  AND NOT EXISTS (
    SELECT 1
    FROM sys_resource
    WHERE code = 'notifyReport/notifyReport.html' AND level = 2
  );

SET @notify_report_id := (
  SELECT id
  FROM sys_resource
  WHERE code = 'notifyReport/notifyReport.html' AND level = 2
  ORDER BY id
  LIMIT 1
);

INSERT INTO sys_resource(code, name, resource_id, level, sort, status)
SELECT 'notifyReport/notifyReport.html#view', '查看', @notify_report_id, 3, 1, 1
FROM dual
WHERE @notify_report_id IS NOT NULL
  AND NOT EXISTS (
    SELECT 1
    FROM sys_resource
    WHERE code = 'notifyReport/notifyReport.html#view' AND level = 3
  );

SELECT id, code, name, resource_id, level, sort, status
FROM sys_resource
WHERE code IN ('notifyReport/notifyReport.html', 'notifyReport/notifyReport.html#view');
