-- 文件对象储存菜单 + 权限 (QA & PROD 通用)
-- 需要先查 gateway 系统ID 和 "系统管理" 目录ID，然后执行

-- ====== QA 数据库 ======
USE mokeegatewayqa;

SET @gw_id = (SELECT id FROM sys_system WHERE system_code='gateway');
SET @sys_mgmt_id = (SELECT id FROM sys_menu WHERE system_id=@gw_id AND parent_id='0' AND menu_name='系统管理' AND menu_type=1);

-- 文件对象储存菜单 (type=2 菜单)
INSERT INTO sys_menu (id, system_id, parent_id, menu_name, menu_type, menu_path, component, icon, permission, sort_order, status, created_at)
VALUES (REPLACE(UUID(),'-',''), @gw_id, @sys_mgmt_id, '文件对象储存', 2, '/admin/file', 'admin/file/FileList', 'FolderOpened', 'system:file:list', 4, 1, NOW());

SET @file_menu_id = (SELECT id FROM sys_menu WHERE system_id=@gw_id AND menu_path='/admin/file');

-- 按钮权限
INSERT INTO sys_menu (id, system_id, parent_id, menu_name, menu_type, permission, sort_order, status, created_at)
VALUES (REPLACE(UUID(),'-',''), @gw_id, @file_menu_id, '上传文件', 3, 'system:file:upload', 1, 1, NOW());

INSERT INTO sys_menu (id, system_id, parent_id, menu_name, menu_type, permission, sort_order, status, created_at)
VALUES (REPLACE(UUID(),'-',''), @gw_id, @file_menu_id, '删除文件', 3, 'system:file:delete', 2, 1, NOW());

-- ====== PROD 数据库 ======
USE mokeegateway;

SET @gw_id = (SELECT id FROM sys_system WHERE system_code='gateway');
SET @sys_mgmt_id = (SELECT id FROM sys_menu WHERE system_id=@gw_id AND parent_id='0' AND menu_name='系统管理' AND menu_type=1);

-- 文件对象储存菜单
INSERT INTO sys_menu (id, system_id, parent_id, menu_name, menu_type, menu_path, component, icon, permission, sort_order, status, created_at)
VALUES (REPLACE(UUID(),'-',''), @gw_id, @sys_mgmt_id, '文件对象储存', 2, '/admin/file', 'admin/file/FileList', 'FolderOpened', 'system:file:list', 4, 1, NOW());

SET @file_menu_id = (SELECT id FROM sys_menu WHERE system_id=@gw_id AND menu_path='/admin/file');

INSERT INTO sys_menu (id, system_id, parent_id, menu_name, menu_type, permission, sort_order, status, created_at)
VALUES (REPLACE(UUID(),'-',''), @gw_id, @file_menu_id, '上传文件', 3, 'system:file:upload', 1, 1, NOW());

INSERT INTO sys_menu (id, system_id, parent_id, menu_name, menu_type, permission, sort_order, status, created_at)
VALUES (REPLACE(UUID(),'-',''), @gw_id, @file_menu_id, '删除文件', 3, 'system:file:delete', 2, 1, NOW());

SELECT 'QA:' AS env, id, menu_name, menu_type, permission FROM sys_menu WHERE menu_path='/admin/file' OR permission LIKE 'system:file:%';
