-- ============================================
-- RentEase 租房管理系统 - 基础数据初始化
-- 执行此脚本可让超级管理员正常使用系统
-- ============================================

SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;

-- ============================================
-- 1. 初始化默认租户（系统租户）
-- 说明：租户只保留编码，不区分类型
-- ============================================
INSERT IGNORE INTO `tenants` (`id`, `code`, `contactName`, `contactPhone`, `status`, `billingStatus`, `planId`, `paidStartDate`, `paidEndDate`, `currentPeriodStart`, `currentPeriodEnd`, `maxUsers`, `maxApartments`, `maxRooms`, `createTime`, `updateTime`) VALUES
(1, 'system', '系统管理员', '13800138000', 'active', 'paid_active', 4, NOW(), DATE_ADD(NOW(), INTERVAL 10 YEAR), NOW(), DATE_ADD(NOW(), INTERVAL 10 YEAR), 100, 1000, 10000, NOW(), NOW());

-- ============================================
-- 2. 初始化订阅套餐
-- ============================================
INSERT IGNORE INTO `subscription_plans` (`id`, `code`, `name`, `description`, `maxApartments`, `maxRooms`, `maxUsers`, `monthlyPrice`, `yearlyPrice`, `isDefault`, `status`, `sort`) VALUES
(1, 'free', '免费版', '适合个人房东试用', 3, 30, 2, 0.00, 0.00, 1, 'active', 1),
(2, 'basic', '基础版', '适合小型房东', 10, 100, 5, 99.00, 999.00, 0, 'active', 2),
(3, 'professional', '专业版', '适合中型公寓运营商', 50, 500, 20, 299.00, 2999.00, 0, 'active', 3),
(4, 'enterprise', '企业版', '适合大型公寓运营企业', 200, 2000, 100, 999.00, 9999.00, 0, 'active', 4);

INSERT IGNORE INTO `tenant_subscriptions` (`id`, `tenantId`, `planId`, `orderId`, `status`, `billingCycle`, `months`, `startDate`, `endDate`, `amount`, `createTime`, `updateTime`) VALUES
(1, 1, 4, NULL, 'active', 'custom', 120, NOW(), DATE_ADD(NOW(), INTERVAL 10 YEAR), 0.00, NOW(), NOW());

-- ============================================
-- 3. 初始化角色（仅租户管理员和普通用户使用）
-- 说明：超级管理员不需要角色，通过userType判断
-- ============================================
INSERT IGNORE INTO `roles` (`id`, `name`, `code`, `description`, `permissions`, `tenantId`, `status`, `createTime`, `updateTime`) VALUES
(1, '租户管理员', 'tenant_admin', '租户管理员，管理租户下的所有资源', '["*"]', 1, 'active', NOW(), NOW()),
(2, '普通用户', 'user', '普通用户，权限由管理员分配', '[]', 1, 'active', NOW(), NOW());

-- ============================================
-- 4. 初始化超级管理员账号
-- 用户名: admin
-- 密码: [REDACTED]
-- 说明：超级管理员roleId为NULL，通过userType='super_admin'判断权限
-- ============================================
-- 密码使用 bcrypt 加密，明文密码为: admin123
INSERT IGNORE INTO `users` (`id`, `username`, `password`, `nickname`, `roleId`, `tenantId`, `userType`, `status`, `lastLoginTime`, `createTime`, `updateTime`) VALUES
(1, 'admin', '$2b$10$yN1CYcm7hnG9gUnZ3YWgdec6lAx8kaJKGE4C3qc3EFZrIhzzJuXku', '系统管理员', NULL, 1, 'super_admin', 'active', NOW(), NOW(), NOW());

-- ============================================
-- 5. 初始化基础菜单
-- ============================================

-- 清空现有菜单（可选，如果需要全新初始化请取消注释）
-- DELETE FROM `menus` WHERE `id` > 0;
-- ALTER TABLE `menus` AUTO_INCREMENT = 1;

-- 1. 首页
INSERT IGNORE INTO `menus` (`id`, `name`, `code`, `type`, `path`, `component`, `icon`, `sort`, `visible`, `status`, `isBasic`, `isDeleted`, `createTime`, `updateTime`) VALUES
(1, '首页', 'dashboard', 'menu', '/dashboard', 'Dashboard', 'el-icon-s-home', 1, 'show', 'active', 1, 0, NOW(), NOW());

-- 2. 房源管理（父菜单）
INSERT IGNORE INTO `menus` (`id`, `name`, `code`, `type`, `path`, `component`, `icon`, `sort`, `visible`, `status`, `isBasic`, `isDeleted`, `createTime`, `updateTime`) VALUES
(2, '房源管理', 'property', 'menu', '/property', NULL, 'el-icon-office-building', 2, 'show', 'active', 1, 0, NOW(), NOW());

-- 2.1 公寓管理
INSERT IGNORE INTO `menus` (`id`, `parentId`, `name`, `code`, `type`, `path`, `component`, `icon`, `sort`, `visible`, `status`, `isBasic`, `isDeleted`, `createTime`, `updateTime`) VALUES
(3, 2, '公寓管理', 'apartment', 'menu', '/apartment', 'views/apartment/List', 'el-icon-office-building', 1, 'show', 'active', 1, 0, NOW(), NOW());

-- 2.1.1 公寓管理子页面
INSERT IGNORE INTO `menus` (`id`, `parentId`, `name`, `code`, `type`, `path`, `component`, `icon`, `sort`, `visible`, `status`, `isBasic`, `isDeleted`, `createTime`, `updateTime`) VALUES
(31, 3, '新增公寓', 'apartment_add', 'menu', '/apartment/add', 'views/apartment/Add', NULL, 1, 'hide', 'active', 1, 0, NOW(), NOW()),
(32, 3, '编辑公寓', 'apartment_edit', 'menu', '/apartment/edit/:id', 'views/apartment/Edit', NULL, 2, 'hide', 'active', 1, 0, NOW(), NOW()),
(33, 3, '公寓详情', 'apartment_detail', 'menu', '/apartment/detail/:id', 'views/apartment/Detail', NULL, 3, 'hide', 'active', 1, 0, NOW(), NOW());

-- 2.2 房间管理
INSERT IGNORE INTO `menus` (`id`, `parentId`, `name`, `code`, `type`, `path`, `component`, `icon`, `sort`, `visible`, `status`, `isBasic`, `isDeleted`, `createTime`, `updateTime`) VALUES
(4, 2, '房间管理', 'room', 'menu', '/room', 'views/room/List', 'el-icon-house', 2, 'show', 'active', 1, 0, NOW(), NOW());

-- 2.2.1 房间管理子页面
INSERT IGNORE INTO `menus` (`id`, `parentId`, `name`, `code`, `type`, `path`, `component`, `icon`, `sort`, `visible`, `status`, `isBasic`, `isDeleted`, `createTime`, `updateTime`) VALUES
(34, 4, '新增房间', 'room_add', 'menu', '/room/add', 'views/room/Add', NULL, 1, 'hide', 'active', 1, 0, NOW(), NOW()),
(35, 4, '编辑房间', 'room_edit', 'menu', '/room/edit/:id', 'views/room/Edit', NULL, 2, 'hide', 'active', 1, 0, NOW(), NOW()),
(36, 4, '房间详情', 'room_detail', 'menu', '/room/detail/:id', 'views/room/Detail', NULL, 3, 'hide', 'active', 1, 0, NOW(), NOW());

-- 2.3 房态图
INSERT IGNORE INTO `menus` (`id`, `parentId`, `name`, `code`, `type`, `path`, `component`, `icon`, `sort`, `visible`, `status`, `isBasic`, `isDeleted`, `createTime`, `updateTime`) VALUES
(5, 2, '房态图', 'room_status', 'menu', '/room/status', 'views/room/Status', 'el-icon-s-grid', 3, 'show', 'active', 1, 0, NOW(), NOW());

-- 3. 住户管理
INSERT IGNORE INTO `menus` (`id`, `name`, `code`, `type`, `path`, `component`, `icon`, `sort`, `visible`, `status`, `isBasic`, `isDeleted`, `createTime`, `updateTime`) VALUES
(6, '住户管理', 'resident', 'menu', '/resident', 'views/renter/List', 'el-icon-user', 3, 'show', 'active', 1, 0, NOW(), NOW());

-- 3.1 住户管理子页面
INSERT IGNORE INTO `menus` (`id`, `parentId`, `name`, `code`, `type`, `path`, `component`, `icon`, `sort`, `visible`, `status`, `isBasic`, `isDeleted`, `createTime`, `updateTime`) VALUES
(37, 6, '新增住户', 'resident_add', 'menu', '/resident/add', 'views/renter/Add', NULL, 1, 'hide', 'active', 1, 0, NOW(), NOW()),
(38, 6, '编辑住户', 'resident_edit', 'menu', '/resident/edit/:id', 'views/renter/Edit', NULL, 2, 'hide', 'active', 1, 0, NOW(), NOW()),
(39, 6, '住户详情', 'resident_detail', 'menu', '/resident/detail/:id', 'views/renter/Detail', NULL, 3, 'hide', 'active', 1, 0, NOW(), NOW());

-- 4. 租赁管理
INSERT IGNORE INTO `menus` (`id`, `name`, `code`, `type`, `path`, `component`, `icon`, `sort`, `visible`, `status`, `isBasic`, `isDeleted`, `createTime`, `updateTime`) VALUES
(7, '租赁管理', 'rental', 'menu', '/rental', 'views/rental/List', 'el-icon-s-order', 4, 'show', 'active', 1, 0, NOW(), NOW());

-- 4.1 租赁管理子页面
INSERT IGNORE INTO `menus` (`id`, `parentId`, `name`, `code`, `type`, `path`, `component`, `icon`, `sort`, `visible`, `status`, `isBasic`, `isDeleted`, `createTime`, `updateTime`) VALUES
(40, 7, '新增租赁', 'rental_add', 'menu', '/rental/add', 'views/rental/Add', NULL, 1, 'hide', 'active', 1, 0, NOW(), NOW()),
(41, 7, '编辑租赁', 'rental_edit', 'menu', '/rental/edit/:id', 'views/rental/Edit', NULL, 2, 'hide', 'active', 1, 0, NOW(), NOW()),
(42, 7, '租赁详情', 'rental_detail', 'menu', '/rental/detail/:id', 'views/rental/Detail', NULL, 3, 'hide', 'active', 1, 0, NOW(), NOW()),
(43, 7, '续租', 'rental_renew', 'menu', '/rental/renew/:id', 'views/rental/Renew', NULL, 4, 'hide', 'active', 1, 0, NOW(), NOW()),
(44, 7, '退租', 'rental_checkout', 'menu', '/rental/checkout/:id', 'views/rental/Checkout', NULL, 5, 'hide', 'active', 1, 0, NOW(), NOW()),
(75, 7, '换房', 'rental_change_room', 'menu', '/rental/change-room/:id', 'views/rental/ChangeRoom', NULL, 6, 'hide', 'active', 1, 0, NOW(), NOW());

-- 5. 财务管理（父菜单）
INSERT IGNORE INTO `menus` (`id`, `name`, `code`, `type`, `path`, `component`, `icon`, `sort`, `visible`, `status`, `isBasic`, `isDeleted`, `createTime`, `updateTime`) VALUES
(8, '财务管理', 'finance', 'menu', '/finance', NULL, 'el-icon-money', 5, 'show', 'active', 1, 0, NOW(), NOW());

-- 5.1 账单管理
INSERT IGNORE INTO `menus` (`id`, `parentId`, `name`, `code`, `type`, `path`, `component`, `icon`, `sort`, `visible`, `status`, `isBasic`, `isDeleted`, `createTime`, `updateTime`) VALUES
(9, 8, '账单管理', 'bill', 'menu', '/bill', 'views/bill/List', 'el-icon-document', 1, 'show', 'active', 1, 0, NOW(), NOW());

-- 5.1.1 账单管理子页面
INSERT IGNORE INTO `menus` (`id`, `parentId`, `name`, `code`, `type`, `path`, `component`, `icon`, `sort`, `visible`, `status`, `isBasic`, `isDeleted`, `createTime`, `updateTime`) VALUES
(45, 9, '新增账单', 'bill_add', 'menu', '/bill/add', 'views/bill/Add', NULL, 1, 'hide', 'active', 1, 0, NOW(), NOW()),
(46, 9, '编辑账单', 'bill_edit', 'menu', '/bill/edit/:id', 'views/bill/Edit', NULL, 2, 'hide', 'active', 1, 0, NOW(), NOW()),
(47, 9, '账单详情', 'bill_detail', 'menu', '/bill/detail/:id', 'views/bill/Detail', NULL, 3, 'hide', 'active', 1, 0, NOW(), NOW());

-- 5.2 抄表管理（整合水费、电费）
INSERT IGNORE INTO `menus` (`id`, `parentId`, `name`, `code`, `type`, `path`, `component`, `icon`, `sort`, `visible`, `status`, `isBasic`, `isDeleted`, `createTime`, `updateTime`) VALUES
(10, 8, '抄表管理', 'meter_reading', 'menu', '/meter-reading', 'views/bill/MeterReadingList', 'el-icon-water-cup', 2, 'show', 'active', 1, 0, NOW(), NOW());

-- 5.2.1 抄表管理子页面
INSERT IGNORE INTO `menus` (`id`, `parentId`, `name`, `code`, `type`, `path`, `component`, `icon`, `sort`, `visible`, `status`, `isBasic`, `isDeleted`, `createTime`, `updateTime`) VALUES
(48, 10, '新增抄表', 'meter_reading_add', 'menu', '/meter-reading/add', 'views/bill/MeterReadingAdd', NULL, 1, 'hide', 'active', 1, 0, NOW(), NOW()),
(49, 10, '编辑抄表', 'meter_reading_edit', 'menu', '/meter-reading/edit/:id', 'views/bill/MeterReadingEdit', NULL, 2, 'hide', 'active', 1, 0, NOW(), NOW()),
(50, 10, '抄表详情', 'meter_reading_detail', 'menu', '/meter-reading/detail/:id', 'views/bill/MeterReadingDetail', NULL, 3, 'hide', 'active', 1, 0, NOW(), NOW());

-- 5.3 收支统计
INSERT IGNORE INTO `menus` (`id`, `parentId`, `name`, `code`, `type`, `path`, `component`, `icon`, `sort`, `visible`, `status`, `isBasic`, `isDeleted`, `createTime`, `updateTime`) VALUES
(12, 8, '收支统计', 'finance_stats', 'menu', '/finance/stats', 'views/statistics/Finance', 'el-icon-s-data', 3, 'show', 'active', 1, 0, NOW(), NOW());

-- 6. 计费中心
INSERT IGNORE INTO `menus` (`id`, `name`, `code`, `type`, `path`, `component`, `icon`, `sort`, `visible`, `status`, `isBasic`, `isDeleted`, `createTime`, `updateTime`) VALUES
(13, '计费中心', 'billing_center', 'menu', '/billing/center', 'views/billing/BillingCenter', 'el-icon-wallet', 6, 'show', 'active', 1, 0, NOW(), NOW());

-- 8. 系统设置（父菜单）
INSERT IGNORE INTO `menus` (`id`, `name`, `code`, `type`, `path`, `component`, `icon`, `sort`, `visible`, `status`, `isBasic`, `isDeleted`, `createTime`, `updateTime`) VALUES
(17, '系统设置', 'settings', 'menu', '/settings', NULL, 'el-icon-setting', 8, 'show', 'active', 1, 0, NOW(), NOW());

-- 8.1 用户管理
INSERT IGNORE INTO `menus` (`id`, `parentId`, `name`, `code`, `type`, `path`, `component`, `icon`, `sort`, `visible`, `status`, `isBasic`, `isDeleted`, `createTime`, `updateTime`) VALUES
(18, 17, '用户管理', 'user', 'menu', '/user', 'views/user/List', 'el-icon-user', 1, 'show', 'active', 1, 0, NOW(), NOW());

-- 8.1.1 用户管理子页面
INSERT IGNORE INTO `menus` (`id`, `parentId`, `name`, `code`, `type`, `path`, `component`, `icon`, `sort`, `visible`, `status`, `isBasic`, `isDeleted`, `createTime`, `updateTime`) VALUES
(54, 18, '新增用户', 'user_add', 'menu', '/user/add', 'views/user/Add', NULL, 1, 'hide', 'active', 1, 0, NOW(), NOW()),
(55, 18, '编辑用户', 'user_edit', 'menu', '/user/edit/:id', 'views/user/Edit', NULL, 2, 'hide', 'active', 1, 0, NOW(), NOW()),
(56, 18, '用户详情', 'user_detail', 'menu', '/user/detail/:id', 'views/user/Detail', NULL, 3, 'hide', 'active', 1, 0, NOW(), NOW());

-- 8.2 角色管理
INSERT IGNORE INTO `menus` (`id`, `parentId`, `name`, `code`, `type`, `path`, `component`, `icon`, `sort`, `visible`, `status`, `isBasic`, `isDeleted`, `createTime`, `updateTime`) VALUES
(19, 17, '角色管理', 'role', 'menu', '/role', 'views/role/List', 'el-icon-s-custom', 2, 'show', 'active', 1, 0, NOW(), NOW());

-- 8.2.1 角色管理子页面
INSERT IGNORE INTO `menus` (`id`, `parentId`, `name`, `code`, `type`, `path`, `component`, `icon`, `sort`, `visible`, `status`, `isBasic`, `isDeleted`, `createTime`, `updateTime`) VALUES
(57, 19, '新增角色', 'role_add', 'menu', '/role/add', 'views/role/Add', NULL, 1, 'hide', 'active', 1, 0, NOW(), NOW()),
(58, 19, '编辑角色', 'role_edit', 'menu', '/role/edit/:id', 'views/role/Edit', NULL, 2, 'hide', 'active', 1, 0, NOW(), NOW()),
(59, 19, '角色详情', 'role_detail', 'menu', '/role/detail/:id', 'views/role/Detail', NULL, 3, 'hide', 'active', 1, 0, NOW(), NOW()),
(60, 19, '分配权限', 'role_permission', 'menu', '/role/permission/:id', 'views/role/Permission', NULL, 4, 'hide', 'active', 1, 0, NOW(), NOW());

-- 8.3 操作日志
INSERT IGNORE INTO `menus` (`id`, `parentId`, `name`, `code`, `type`, `path`, `component`, `icon`, `sort`, `visible`, `status`, `isBasic`, `isDeleted`, `createTime`, `updateTime`) VALUES
(20, 17, '操作日志', 'operation_log', 'menu', '/log/operation', 'views/log/OperationLog', 'el-icon-document-checked', 3, 'show', 'active', 1, 0, NOW(), NOW());

-- 8.4 登录日志
INSERT IGNORE INTO `menus` (`id`, `parentId`, `name`, `code`, `type`, `path`, `component`, `icon`, `sort`, `visible`, `status`, `isBasic`, `isDeleted`, `createTime`, `updateTime`) VALUES
(21, 17, '登录日志', 'login_log', 'menu', '/log/login', 'views/log/LoginLog', 'el-icon-document-copy', 4, 'show', 'active', 1, 0, NOW(), NOW());

-- 8.5 个人设置
INSERT IGNORE INTO `menus` (`id`, `parentId`, `name`, `code`, `type`, `path`, `component`, `icon`, `sort`, `visible`, `status`, `isBasic`, `isDeleted`, `createTime`, `updateTime`) VALUES
(22, 17, '个人设置', 'profile', 'menu', '/profile', 'views/user/Profile', 'el-icon-user-solid', 5, 'show', 'active', 1, 0, NOW(), NOW());

-- 8.6 参数设置
INSERT IGNORE INTO `menus` (`id`, `parentId`, `name`, `code`, `type`, `path`, `component`, `icon`, `sort`, `visible`, `status`, `isBasic`, `isDeleted`, `createTime`, `updateTime`) VALUES
(67, 17, '参数设置', 'setting', 'menu', '/setting', 'views/setting/Index', 'el-icon-s-tools', 6, 'show', 'active', 1, 0, NOW(), NOW());

-- 9. 平台管理（父菜单）- 仅系统管理员
INSERT IGNORE INTO `menus` (`id`, `name`, `code`, `type`, `path`, `component`, `icon`, `sort`, `visible`, `status`, `isBasic`, `isDeleted`, `createTime`, `updateTime`) VALUES
(23, '平台管理', 'platform', 'menu', '/platform', NULL, 'el-icon-s-platform', 9, 'show', 'active', 0, 0, NOW(), NOW());

-- 9.1 租户管理
INSERT IGNORE INTO `menus` (`id`, `parentId`, `name`, `code`, `type`, `path`, `component`, `icon`, `sort`, `visible`, `status`, `isBasic`, `isDeleted`, `createTime`, `updateTime`) VALUES
(24, 23, '租户管理', 'tenant_manage', 'menu', '/tenant/manage', 'views/tenant/List', 'el-icon-s-platform', 1, 'show', 'active', 0, 0, NOW(), NOW());

-- 9.1.1 租户管理子页面
INSERT IGNORE INTO `menus` (`id`, `parentId`, `name`, `code`, `type`, `path`, `component`, `icon`, `sort`, `visible`, `status`, `isBasic`, `isDeleted`, `createTime`, `updateTime`) VALUES
(61, 24, '新增租户', 'tenant_add', 'menu', '/tenant/manage/add', 'views/tenant/Add', NULL, 1, 'hide', 'active', 0, 0, NOW(), NOW()),
(62, 24, '编辑租户', 'tenant_edit', 'menu', '/tenant/manage/edit/:id', 'views/tenant/Edit', NULL, 2, 'hide', 'active', 0, 0, NOW(), NOW()),
(63, 24, '租户详情', 'tenant_detail', 'menu', '/tenant/manage/detail/:id', 'views/tenant/Detail', NULL, 3, 'hide', 'active', 0, 0, NOW(), NOW());

-- 9.2 套餐管理
INSERT IGNORE INTO `menus` (`id`, `parentId`, `name`, `code`, `type`, `path`, `component`, `icon`, `sort`, `visible`, `status`, `isBasic`, `isDeleted`, `createTime`, `updateTime`) VALUES
(25, 23, '套餐管理', 'plan_manage', 'menu', '/plan', 'views/billing/PlanManage', 'el-icon-s-goods', 2, 'show', 'active', 0, 0, NOW(), NOW());

-- 9.3 计费管理
INSERT IGNORE INTO `menus` (`id`, `parentId`, `name`, `code`, `type`, `path`, `component`, `icon`, `sort`, `visible`, `status`, `isBasic`, `isDeleted`, `createTime`, `updateTime`) VALUES
(26, 23, '计费管理', 'billing_manage', 'menu', '/billing/manage', 'views/billing/BillingManage', 'el-icon-coin', 3, 'show', 'active', 0, 0, NOW(), NOW());

-- 9.4 菜单管理
INSERT IGNORE INTO `menus` (`id`, `parentId`, `name`, `code`, `type`, `path`, `component`, `icon`, `sort`, `visible`, `status`, `isBasic`, `isDeleted`, `createTime`, `updateTime`) VALUES
(27, 23, '菜单管理', 'menu_manage', 'menu', '/menu/manage', 'views/menu/List', 'el-icon-menu', 4, 'show', 'active', 0, 0, NOW(), NOW());

-- 9.4.1 菜单管理子页面
INSERT IGNORE INTO `menus` (`id`, `parentId`, `name`, `code`, `type`, `path`, `component`, `icon`, `sort`, `visible`, `status`, `isBasic`, `isDeleted`, `createTime`, `updateTime`) VALUES
(64, 27, '新增菜单', 'menu_add', 'menu', '/menu/manage/add', 'views/menu/Add', NULL, 1, 'hide', 'active', 0, 0, NOW(), NOW()),
(65, 27, '编辑菜单', 'menu_edit', 'menu', '/menu/manage/edit/:id', 'views/menu/Edit', NULL, 2, 'hide', 'active', 0, 0, NOW(), NOW()),
(66, 27, '菜单详情', 'menu_detail', 'menu', '/menu/manage/detail/:id', 'views/menu/Detail', NULL, 3, 'hide', 'active', 0, 0, NOW(), NOW());

-- ============================================
-- 6. 初始化按钮权限
-- ============================================

-- 公寓管理按钮
INSERT IGNORE INTO `menus` (`parentId`, `name`, `code`, `type`, `path`, `component`, `icon`, `sort`, `visible`, `status`, `isBasic`, `isDeleted`, `createTime`, `updateTime`) VALUES
(3, '添加公寓', 'apartment:add', 'button', NULL, NULL, NULL, 1, 'hide', 'active', 1, 0, NOW(), NOW()),
(3, '编辑公寓', 'apartment:edit', 'button', NULL, NULL, NULL, 2, 'hide', 'active', 1, 0, NOW(), NOW()),
(3, '删除公寓', 'apartment:delete', 'button', NULL, NULL, NULL, 3, 'hide', 'active', 1, 0, NOW(), NOW());

-- 房间管理按钮
INSERT IGNORE INTO `menus` (`parentId`, `name`, `code`, `type`, `path`, `component`, `icon`, `sort`, `visible`, `status`, `isBasic`, `isDeleted`, `createTime`, `updateTime`) VALUES
(4, '添加房间', 'room:add', 'button', NULL, NULL, NULL, 1, 'hide', 'active', 1, 0, NOW(), NOW()),
(4, '编辑房间', 'room:edit', 'button', NULL, NULL, NULL, 2, 'hide', 'active', 1, 0, NOW(), NOW()),
(4, '删除房间', 'room:delete', 'button', NULL, NULL, NULL, 3, 'hide', 'active', 1, 0, NOW(), NOW());

-- 住户管理按钮
INSERT IGNORE INTO `menus` (`parentId`, `name`, `code`, `type`, `path`, `component`, `icon`, `sort`, `visible`, `status`, `isBasic`, `isDeleted`, `createTime`, `updateTime`) VALUES
(6, '添加住户', 'resident:add', 'button', NULL, NULL, NULL, 1, 'hide', 'active', 1, 0, NOW(), NOW()),
(6, '编辑住户', 'resident:edit', 'button', NULL, NULL, NULL, 2, 'hide', 'active', 1, 0, NOW(), NOW()),
(6, '删除住户', 'resident:delete', 'button', NULL, NULL, NULL, 3, 'hide', 'active', 1, 0, NOW(), NOW());

-- 租赁管理按钮
INSERT IGNORE INTO `menus` (`parentId`, `name`, `code`, `type`, `path`, `component`, `icon`, `sort`, `visible`, `status`, `isBasic`, `isDeleted`, `createTime`, `updateTime`) VALUES
(7, '添加租赁', 'rental:add', 'button', NULL, NULL, NULL, 1, 'hide', 'active', 1, 0, NOW(), NOW()),
(7, '编辑租赁', 'rental:edit', 'button', NULL, NULL, NULL, 2, 'hide', 'active', 1, 0, NOW(), NOW()),
(7, '删除租赁', 'rental:delete', 'button', NULL, NULL, NULL, 3, 'hide', 'active', 1, 0, NOW(), NOW()),
(7, '终止租约', 'rental:terminate', 'button', NULL, NULL, NULL, 4, 'hide', 'active', 1, 0, NOW(), NOW());

-- 账单管理按钮
INSERT IGNORE INTO `menus` (`parentId`, `name`, `code`, `type`, `path`, `component`, `icon`, `sort`, `visible`, `status`, `isBasic`, `isDeleted`, `createTime`, `updateTime`) VALUES
(9, '添加账单', 'bill:add', 'button', NULL, NULL, NULL, 1, 'hide', 'active', 1, 0, NOW(), NOW()),
(9, '编辑账单', 'bill:edit', 'button', NULL, NULL, NULL, 2, 'hide', 'active', 1, 0, NOW(), NOW()),
(9, '删除账单', 'bill:delete', 'button', NULL, NULL, NULL, 3, 'hide', 'active', 1, 0, NOW(), NOW()),
(9, '标记已付', 'bill:pay', 'button', NULL, NULL, NULL, 4, 'hide', 'active', 1, 0, NOW(), NOW());

-- 抄表管理按钮
INSERT IGNORE INTO `menus` (`parentId`, `name`, `code`, `type`, `path`, `component`, `icon`, `sort`, `visible`, `status`, `isBasic`, `isDeleted`, `createTime`, `updateTime`) VALUES
(10, '添加抄表', 'meter_reading:add', 'button', NULL, NULL, NULL, 1, 'hide', 'active', 1, 0, NOW(), NOW()),
(10, '编辑抄表', 'meter_reading:edit', 'button', NULL, NULL, NULL, 2, 'hide', 'active', 1, 0, NOW(), NOW()),
(10, '删除抄表', 'meter_reading:delete', 'button', NULL, NULL, NULL, 3, 'hide', 'active', 1, 0, NOW(), NOW());

-- 用户管理按钮
INSERT IGNORE INTO `menus` (`parentId`, `name`, `code`, `type`, `path`, `component`, `icon`, `sort`, `visible`, `status`, `isBasic`, `isDeleted`, `createTime`, `updateTime`) VALUES
(18, '添加用户', 'user:add', 'button', NULL, NULL, NULL, 1, 'hide', 'active', 1, 0, NOW(), NOW()),
(18, '编辑用户', 'user:edit', 'button', NULL, NULL, NULL, 2, 'hide', 'active', 1, 0, NOW(), NOW()),
(18, '删除用户', 'user:delete', 'button', NULL, NULL, NULL, 3, 'hide', 'active', 1, 0, NOW(), NOW()),
(18, '重置密码', 'user:reset-password', 'button', NULL, NULL, NULL, 4, 'hide', 'active', 1, 0, NOW(), NOW());

-- 角色管理按钮
INSERT IGNORE INTO `menus` (`parentId`, `name`, `code`, `type`, `path`, `component`, `icon`, `sort`, `visible`, `status`, `isBasic`, `isDeleted`, `createTime`, `updateTime`) VALUES
(19, '添加角色', 'role:add', 'button', NULL, NULL, NULL, 1, 'hide', 'active', 1, 0, NOW(), NOW()),
(19, '编辑角色', 'role:edit', 'button', NULL, NULL, NULL, 2, 'hide', 'active', 1, 0, NOW(), NOW()),
(19, '删除角色', 'role:delete', 'button', NULL, NULL, NULL, 3, 'hide', 'active', 1, 0, NOW(), NOW()),
(19, '分配权限', 'role:assign', 'button', NULL, NULL, NULL, 4, 'hide', 'active', 1, 0, NOW(), NOW());

-- 平台租户管理按钮
INSERT IGNORE INTO `menus` (`parentId`, `name`, `code`, `type`, `path`, `component`, `icon`, `sort`, `visible`, `status`, `isBasic`, `isDeleted`, `createTime`, `updateTime`) VALUES
(24, '添加租户', 'tenant:add', 'button', NULL, NULL, NULL, 1, 'hide', 'active', 0, 0, NOW(), NOW()),
(24, '编辑租户', 'tenant:edit', 'button', NULL, NULL, NULL, 2, 'hide', 'active', 0, 0, NOW(), NOW()),
(24, '删除租户', 'tenant:delete', 'button', NULL, NULL, NULL, 3, 'hide', 'active', 0, 0, NOW(), NOW());

-- 菜单管理按钮
INSERT IGNORE INTO `menus` (`parentId`, `name`, `code`, `type`, `path`, `component`, `icon`, `sort`, `visible`, `status`, `isBasic`, `isDeleted`, `createTime`, `updateTime`) VALUES
(27, '添加菜单', 'menu:add', 'button', NULL, NULL, NULL, 1, 'hide', 'active', 0, 0, NOW(), NOW()),
(27, '编辑菜单', 'menu:edit', 'button', NULL, NULL, NULL, 2, 'hide', 'active', 0, 0, NOW(), NOW()),
(27, '删除菜单', 'menu:delete', 'button', NULL, NULL, NULL, 3, 'hide', 'active', 0, 0, NOW(), NOW());

-- ============================================
-- 6. 初始化定价配置
-- ============================================
INSERT IGNORE INTO `pricing_configs` (`id`, `overageApartmentPrice`, `overageRoomPrice`, `overageUserPrice`, `currency`, `effectiveDate`, `isActive`, `isDeleted`, `createTime`, `updateTime`) VALUES
(1, 10.00, 2.00, 5.00, 'CNY', NOW(), 1, 0, NOW(), NOW());

-- ============================================
-- 7. 初始化系统设置
-- ============================================
-- 到期提醒天数设置（默认30天）
INSERT IGNORE INTO `settings` (`id`, `key`, `value`, `description`, `tenantId`, `createTime`, `updateTime`) VALUES
(1, 'expireReminderDays', '30', '房间到期提前提醒天数', 1, NOW(), NOW());

-- 结算策略：换房/退租即时结算
INSERT IGNORE INTO `settings` (`id`, `key`, `value`, `description`, `tenantId`, `createTime`, `updateTime`) VALUES
(2, 'rentalSettlementMode', 'instant', '租约结算模式：instant-即时结算', 1, NOW(), NOW());

-- ============================================
-- 8. 初始化支付设置
-- ============================================
-- 默认支付设置（示例数据，请根据实际情况修改）
INSERT IGNORE INTO `payment_settings` (`id`, `alipayAccount`, `alipayName`, `wechatId`, `wechatText`, `bankName`, `bankAccount`, `bankHolder`, `servicePhone`, `serviceTime`, `isDeleted`, `createTime`, `updateTime`) VALUES
(1, 'example@alipay.com', '支付宝', 'rentease001', '请添加客服微信', '中国工商银行', '6222 0000 0000 0000 000', 'RentEase科技有限公司', '400-123-4567', '9:00-18:00', 0, NOW(), NOW());

-- ============================================
-- 9. 初始化收支类目
-- ============================================
-- 收入类目
INSERT IGNORE INTO `categories` (`id`, `name`, `code`, `type`, `sort`, `status`, `isDefault`, `tenantId`, `isDeleted`, `createTime`, `updateTime`) VALUES
(1, '租金', 'rent', 'income', 1, 'active', 1, 1, 0, NOW(), NOW()),
(2, '水费', 'water', 'income', 2, 'active', 1, 1, 0, NOW(), NOW()),
(3, '电费', 'electricity', 'income', 3, 'active', 1, 1, 0, NOW(), NOW()),
(4, '燃气费', 'gas', 'income', 4, 'active', 1, 1, 0, NOW(), NOW()),
(5, '押金', 'deposit', 'income', 5, 'active', 1, 1, 0, NOW(), NOW()),
(6, '物业费', 'property_fee', 'income', 6, 'active', 1, 1, 0, NOW(), NOW()),
(7, '违约金', 'penalty', 'income', 7, 'active', 1, 1, 0, NOW(), NOW()),
(8, '其他收入', 'other_income', 'income', 8, 'active', 1, 1, 0, NOW(), NOW());

-- 支出类目
INSERT IGNORE INTO `categories` (`id`, `name`, `code`, `type`, `sort`, `status`, `isDefault`, `tenantId`, `isDeleted`, `createTime`, `updateTime`) VALUES
(9, '维修费', 'maintenance', 'expense', 1, 'active', 1, 1, 0, NOW(), NOW()),
(10, '中介费', 'agency_fee', 'expense', 2, 'active', 1, 1, 0, NOW(), NOW()),
(11, '物业费', 'property_fee_expense', 'expense', 3, 'active', 1, 1, 0, NOW(), NOW()),
(12, '水费', 'water_expense', 'expense', 4, 'active', 1, 1, 0, NOW(), NOW()),
(13, '电费', 'electricity_expense', 'expense', 5, 'active', 1, 1, 0, NOW(), NOW()),
(14, '燃气费', 'gas_expense', 'expense', 6, 'active', 1, 1, 0, NOW(), NOW()),
(15, '装修费', 'renovation', 'expense', 7, 'active', 1, 1, 0, NOW(), NOW()),
(16, '其他支出', 'other_expense', 'expense', 8, 'active', 1, 1, 0, NOW(), NOW());

-- ============================================
-- 10. 为租户管理员角色分配基础菜单权限
-- 说明：超级管理员不需要角色关联，通过userType判断拥有所有权限
-- ============================================
INSERT IGNORE INTO `role_menus` (`roleId`, `menuId`, `createTime`)
SELECT 1, `id`, NOW() FROM `menus` WHERE `isDeleted` = 0 AND `isBasic` = 1;

SET FOREIGN_KEY_CHECKS = 1;

-- ============================================
-- 初始化完成
-- ============================================
-- 超级管理员账号:
-- 用户名: admin
-- 密码: [REDACTED]
-- 说明：超级管理员通过userType='super_admin'判断，不需要角色
-- ============================================
