-- 初始化菜单数据
-- 注意：请确保menus表已经创建

-- 首先清空现有菜单数据
SET FOREIGN_KEY_CHECKS = 0;
TRUNCATE TABLE menus;
SET FOREIGN_KEY_CHECKS = 1;

-- 插入父级菜单
INSERT INTO menus (name, key, path, icon, parent_id, component, `order`, status, show, created_at, updated_at)
VALUES
  ('仪表板', 'Dashboard', '/dashboard', 'DashboardOutlined', NULL, 'views/Dashboard.vue', 1, 'active', true, NOW(), NOW()),
  ('数据揽仓', 'DataWarehouse', '/data-warehouse', 'DatabaseOutlined', NULL, '', 2, 'active', true, NOW(), NOW()),
  ('监管任务', 'SupervisionTask', '/supervision-task', 'CheckCircleOutlined', NULL, '', 3, 'active', true, NOW(), NOW()),
  ('待安装任务', 'PendingInstallationTask', '/pending-installation', 'ExclamationCircleOutlined', NULL, '', 4, 'active', true, NOW(), NOW()),
  ('监管任务已结项', 'CompletedTask', '/completed-tasks', 'FileDoneOutlined', NULL, '', 5, 'active', true, NOW(), NOW()),
  ('投保客户单', 'InsuredCustomers', '/insured-customers', 'ShopOutlined', NULL, '', 6, 'active', true, NOW(), NOW()),
  ('生资保单', 'AgriculturalInsurance', '/agricultural-insurance', 'FileProtectOutlined', NULL, '', 7, 'active', true, NOW(), NOW()),
  ('险种管理', 'InsuranceTypeManagement', '/insurance-types', 'MedicineBoxOutlined', NULL, '', 8, 'active', true, NOW(), NOW()),
  ('客户理赔', 'CustomerClaims', '/customer-claims', 'AlertCircleOutlined', NULL, '', 9, 'active', true, NOW(), NOW()),
  ('消息通知', 'Notifications', '/notifications', 'BellOutlined', NULL, '', 10, 'active', true, NOW(), NOW()),
  ('子账号管理', 'UserManagement', '/users', 'UserAddOutlined', NULL, 'views/UserManagement.vue', 11, 'active', true, NOW(), NOW()),
  ('系统设置', 'SystemSettings', '/system-settings', 'SettingOutlined', NULL, '', 12, 'active', true, NOW(), NOW()),
  ('个人中心', 'UserProfile', '/profile', 'UserSwitchOutlined', NULL, '', 13, 'active', true, NOW(), NOW());

-- 插入子菜单
-- 投保客户单的子菜单
INSERT INTO menus (name, key, path, icon, parent_id, component, `order`, status, show, created_at, updated_at)
SELECT
  '参保申请', 'ApplicationManagement', '/applications', 'FileTextOutlined', id, 'views/ApplicationManagement.vue', 1, 'active', true, NOW(), NOW()
FROM menus
WHERE `key` = 'InsuredCustomers';

-- 生资保单的子菜单
INSERT INTO menus (name, key, path, icon, parent_id, component, `order`, status, show, created_at, updated_at)
SELECT
  '生资保单列表', 'PolicyManagement', '/policies', 'FileDoneOutlined', id, 'views/PolicyManagement.vue', 1, 'active', true, NOW(), NOW()
FROM menus
WHERE `key` = 'AgriculturalInsurance';

-- 险种管理的子菜单
INSERT INTO menus (name, key, path, icon, parent_id, component, `order`, status, show, created_at, updated_at)
SELECT
  '险种管理', 'InsuranceTypeList', '/insurance-types', 'MedicineBoxOutlined', id, 'views/InsuranceTypeManagement.vue', 1, 'active', true, NOW(), NOW()
FROM menus
WHERE `key` = 'InsuranceTypeManagement';

-- 客户理赔的子菜单
INSERT INTO menus (name, key, path, icon, parent_id, component, `order`, status, show, created_at, updated_at)
SELECT
  '客户理赔', 'ClaimManagement', '/claims', 'SafetyCertificateOutlined', id, 'views/ClaimManagement.vue', 1, 'active', true, NOW(), NOW()
FROM menus
WHERE `key` = 'CustomerClaims';

-- 查询插入结果
SELECT * FROM menus ORDER BY parent_id, `order`;

-- 输出插入的记录数
SELECT CONCAT('成功插入 ', COUNT(*), ' 条菜单记录') AS result FROM menus;