-- V53: 修复审批流表名错误并补齐历史数据
-- 修复: V52使用了错误的表名sys_approval_flows，应为sys_approval_flow
-- 补充: 添加正确的审批模板数据（使用正确的表名）

-- 1. 修复V52插入的数据（使用正确表名重新插入）
-- 由于V52使用了错误表名，数据实际未插入，这里用正确表名补录

-- 用户冻结审批模板
INSERT INTO sys_approval_flow (flow_code, flow_name, trigger_event, conditions, nodes, timeout_hours, timeout_action, status, created_at)
SELECT 'USER_FREEZE', '用户冻结审批', 'USER_FREEZE', NULL,
'[{"nodeIndex":1,"nodeName":"风控审核","approverType":"ROLE","approverCodes":["risk_manager"]}]',
24, 'ESCALATE', 'ENABLED', CURRENT_TIMESTAMP
WHERE NOT EXISTS (SELECT 1 FROM sys_approval_flow WHERE trigger_event = 'USER_FREEZE');

-- 用户解冻审批模板
INSERT INTO sys_approval_flow (flow_code, flow_name, trigger_event, conditions, nodes, timeout_hours, timeout_action, status, created_at)
SELECT 'USER_UNFREEZE', '用户解冻审批', 'USER_UNFREEZE', NULL,
'[{"nodeIndex":1,"nodeName":"运营经理审核","approverType":"ROLE","approverCodes":["operation_manager"]}]',
24, 'ESCALATE', 'ENABLED', CURRENT_TIMESTAMP
WHERE NOT EXISTS (SELECT 1 FROM sys_approval_flow WHERE trigger_event = 'USER_UNFREEZE');

-- 敏感数据导出审批模板
INSERT INTO sys_approval_flow (flow_code, flow_name, trigger_event, conditions, nodes, timeout_hours, timeout_action, status, created_at)
SELECT 'SENSITIVE_EXPORT', '敏感数据导出审批', 'SENSITIVE_EXPORT', NULL,
'[{"nodeIndex":1,"nodeName":"安全主管审核","approverType":"ROLE","approverCodes":["security_leader"]}]',
24, 'ESCALATE', 'ENABLED', CURRENT_TIMESTAMP
WHERE NOT EXISTS (SELECT 1 FROM sys_approval_flow WHERE trigger_event = 'SENSITIVE_EXPORT');

-- 活动更新审批模板
INSERT INTO sys_approval_flow (flow_code, flow_name, trigger_event, conditions, nodes, timeout_hours, timeout_action, status, created_at)
SELECT 'ACTIVITY_UPDATE', '活动更新审批', 'ACTIVITY_UPDATE', NULL,
'[{"nodeIndex":1,"nodeName":"运营经理审核","approverType":"ROLE","approverCodes":["operation_manager"]}]',
24, 'ESCALATE', 'ENABLED', CURRENT_TIMESTAMP
WHERE NOT EXISTS (SELECT 1 FROM sys_approval_flow WHERE trigger_event = 'ACTIVITY_UPDATE');

-- 活动删除审批模板
INSERT INTO sys_approval_flow (flow_code, flow_name, trigger_event, conditions, nodes, timeout_hours, timeout_action, status, created_at)
SELECT 'ACTIVITY_DELETE', '活动删除审批', 'ACTIVITY_DELETE', NULL,
'[{"nodeIndex":1,"nodeName":"运营总监审核","approverType":"ROLE","approverCodes":["operation_director"]}]',
24, 'ESCALATE', 'ENABLED', CURRENT_TIMESTAMP
WHERE NOT EXISTS (SELECT 1 FROM sys_approval_flow WHERE trigger_event = 'ACTIVITY_DELETE');
