-- Ether业主小程序测试数据
-- 执行前请确保数据库已创建

-- 清理旧测试数据
DELETE FROM finance_fee_bill WHERE bill_no LIKE 'TEST%';
DELETE FROM ops_work_order WHERE order_no LIKE 'WO%';
DELETE FROM mdm_visitor_appointment WHERE appointment_no LIKE 'VA%';
DELETE FROM ops_complaint WHERE complaint_no LIKE 'CP%';
DELETE FROM ops_notification_history WHERE recipient_id = 'b9357f9a-1e11-45e4-b3a6-f2447bdde1a9';
DELETE FROM mdm_family_member WHERE owner_id = 'b9357f9a-1e11-45e4-b3a6-f2447bdde1a9';
DELETE FROM mdm_ownership WHERE owner_id = 'b9357f9a-1e11-45e4-b3a6-f2447bdde1a9';
DELETE FROM mdm_owner WHERE id = 'b9357f9a-1e11-45e4-b3a6-f2447bdde1a9';

-- 插入测试业主
INSERT INTO mdm_owner (id, owner_code, name, phone, id_card, owner_type, status, gender, created_at, updated_at) VALUES
('b9357f9a-1e11-45e4-b3a6-f2447bdde1a9', 'O2024001', '张三', '13800138001', '110101199001011234', 'INDIVIDUAL', 'ACTIVE', 'MALE', NOW(), NOW());

-- 插入测试房产关联
INSERT INTO mdm_ownership (id, project_id, space_node_id, owner_id, ownership_type, status, created_at, updated_at) VALUES
('c9357f9a-1e11-45e4-b3a6-f2447bdde1a8', 'a1b2c3d4-e5f6-7890-abcd-ef1234567890', 'e9357f9a-1e11-45e4-b3a6-f2447bdde1a9', 'b9357f9a-1e11-45e4-b3a6-f2447bdde1a9', 'OWNER', 'ACTIVE', NOW(), NOW());

-- 插入测试账单
INSERT INTO finance_fee_bill (id, bill_no, project_id, owner_id, fee_type, fee_item_name, amount, total_amount, paid_amount, unpaid_amount, status, due_date, billing_period_start, billing_period_end, created_at, updated_at) VALUES
('d9357f9a-1e11-45e4-b3a6-f2447bdde1a1', 'TEST2024001', 'a1b2c3d4-e5f6-7890-abcd-ef1234567890', 'b9357f9a-1e11-45e4-b3a6-f2447bdde1a9', 'PROPERTY_FEE', '物业管理费', 500.00, 500.00, 0.00, 500.00, 'PENDING', DATE_ADD(NOW(), INTERVAL 30 DAY), DATE_SUB(NOW(), INTERVAL 1 MONTH), NOW(), NOW(), NOW()),
('d9357f9a-1e11-45e4-b3a6-f2447bdde1a2', 'TEST2024002', 'a1b2c3d4-e5f6-7890-abcd-ef1234567890', 'b9357f9a-1e11-45e4-b3a6-f2447bdde1a9', 'WATER_FEE', '水费', 80.50, 80.50, 0.00, 80.50, 'PENDING', DATE_ADD(NOW(), INTERVAL 15 DAY), DATE_SUB(NOW(), INTERVAL 1 MONTH), NOW(), NOW(), NOW()),
('d9357f9a-1e11-45e4-b3a6-f2447bdde1a3', 'TEST2024003', 'a1b2c3d4-e5f6-7890-abcd-ef1234567890', 'b9357f9a-1e11-45e4-b3a6-f2447bdde1a9', 'ELECTRIC_FEE', '电费', 120.00, 120.00, 0.00, 120.00, 'PENDING', DATE_ADD(NOW(), INTERVAL 15 DAY), DATE_SUB(NOW(), INTERVAL 1 MONTH), NOW(), NOW(), NOW());

-- 插入测试工单
INSERT INTO ops_work_order (id, order_no, project_id, reporter_id, order_type, title, description, status, priority, source, created_at, updated_at) VALUES
('e9357f9a-1e11-45e4-b3a6-f2447bdde1a1', 'WO2024001', 'a1b2c3d4-e5f6-7890-abcd-ef1234567890', 'b9357f9a-1e11-45e4-b3a6-f2447bdde1a9', 'REPAIR', '厨房水龙头漏水', '厨房水龙头漏水严重，需要维修', 'CREATED', 'NORMAL', 'OWNER_APP', NOW(), NOW()),
('e9357f9a-1e11-45e4-b3a6-f2447bdde1a2', 'WO2024002', 'a1b2c3d4-e5f6-7890-abcd-ef1234567890', 'b9357f9a-1e11-45e4-b3a6-f2447bdde1a9', 'REPAIR', '电梯故障', '3号楼电梯经常卡顿', 'IN_PROGRESS', 'HIGH', 'OWNER_APP', NOW(), NOW());

-- 插入测试访客预约
INSERT INTO mdm_visitor_appointment (id, appointment_no, visitor_name, visitor_phone, visitor_type, visit_purpose, visit_date, expected_arrival_time, booker_id, host_owner_id, host_address, status, created_at, updated_at) VALUES
('f9357f9a-1e11-45e4-b3a6-f2447bdde1a1', 'VA2024001', '李四', '13900139001', 'FAMILY', 'VISIT', DATE_ADD(CURDATE(), INTERVAL 1 DAY), '10:00:00', 'b9357f9a-1e11-45e4-b3a6-f2447bdde1a9', 'b9357f9a-1e11-45e4-b3a6-f2447bdde1a9', '1栋1单元101', 'APPROVED', NOW(), NOW()),
('f9357f9a-1e11-45e4-b3a6-f2447bdde1a2', 'VA2024002', '王五', '13900139002', 'DELIVERY', 'DELIVERY', CURDATE(), '14:00:00', 'b9357f9a-1e11-45e4-b3a6-f2447bdde1a9', 'b9357f9a-1e11-45e4-b3a6-f2447bdde1a9', '1栋1单元101', 'CHECKED_IN', NOW(), NOW());

-- 插入测试投诉建议
INSERT INTO ops_complaint (id, complaint_no, type, title, content, reporter_id, status, created_at, updated_at) VALUES
('a9357f9a-1e11-45e4-b3a6-f2447bdde1a1', 'CP2024001', 'COMPLAINT', '小区绿化问题', '小区绿化带杂草丛生，希望物业及时处理', 'b9357f9a-1e11-45e4-b3a6-f2447bdde1a9', 'PROCESSING', NOW(), NOW()),
('a9357f9a-1e11-45e4-b3a6-f2447bdde1a2', 'CP2024002', 'SUGGESTION', '增加健身设施建议', '建议在小区内增加一些健身器材', 'b9357f9a-1e11-45e4-b3a6-f2447bdde1a9', 'SUBMITTED', NOW(), NOW());

-- 插入测试消息通知
INSERT INTO ops_notification_history (id, title, content, recipient_id, business_type, business_id, status, created_at) VALUES
('b9357f9a-1e11-45e4-b3a6-f2447bdde1a1', '工单进度通知', '您的工单WO2024002已开始处理', 'b9357f9a-1e11-45e4-b3a6-f2447bdde1a9', 'WORK_ORDER', 'e9357f9a-1e11-45e4-b3a6-f2447bdde1a2', 'SENT', NOW()),
('b9357f9a-1e11-45e4-b3a6-f2447bdde1a2', '账单提醒', '您有新的待缴费账单，请及时缴费', 'b9357f9a-1e11-45e4-b3a6-f2447bdde1a9', 'BILL', 'd9357f9a-1e11-45e4-b3a6-f2447bdde1a1', 'SENT', NOW()),
('b9357f9a-1e11-45e4-b3a6-f2447bdde1a3', '访客到访通知', '您的访客李四已到达', 'b9357f9a-1e11-45e4-b3a6-f2447bdde1a9', 'VISITOR', 'f9357f9a-1e11-45e4-b3a6-f2447bdde1a2', 'SENT', NOW());

-- 插入测试家庭成员
INSERT INTO mdm_family_member (id, owner_id, name, phone, relation, status, created_at, updated_at) VALUES
('c9357f9a-1e11-45e4-b3a6-f2447bdde1a1', 'b9357f9a-1e11-45e4-b3a6-f2447bdde1a9', '张三妻子', '13800138002', 'SPOUSE', 'ACTIVE', NOW(), NOW()),
('c9357f9a-1e11-45e4-b3a6-f2447bdde1a2', 'b9357f9a-1e11-45e4-b3a6-f2447bdde1a9', '张三儿子', '13800138003', 'CHILD', 'ACTIVE', NOW(), NOW());

SELECT '测试数据插入完成' AS result;
