-- 审批流程模板数据初始化
-- 版本: V49
-- 描述: 添加奖励审批和角色变更的默认审批流程模板

-- 1. 奖励风控审批流程 (单级)
INSERT INTO sys_approval_flow (flow_code, flow_name, trigger_event, conditions, nodes, timeout_hours, timeout_action, status, created_at)
VALUES (
    'REWARD_RISK_APPROVAL',
    '奖励风控审批',
    'REWARD_RISK_APPROVAL',
    'reward points >= 1000 AND reward points < 10000',
    '[{"approverType": "ROLE", "roleCode": "RISK_MANAGER", "nodeName": "风控审批"}]',
    24,
    'ESCALATE',
    'ENABLED',
    CURRENT_TIMESTAMP
) ON CONFLICT DO NOTHING;

-- 2. 奖励风控+财务审批流程 (两级)
INSERT INTO sys_approval_flow (flow_code, flow_name, trigger_event, conditions, nodes, timeout_hours, timeout_action, status, created_at)
VALUES (
    'REWARD_RISK_FINANCE_APPROVAL',
    '奖励风控+财务审批',
    'REWARD_RISK_FINANCE_APPROVAL',
    'reward points >= 10000 AND reward points < 50000',
    '[{"approverType": "ROLE", "roleCode": "RISK_MANAGER", "nodeName": "风控审批"}, {"approverType": "ROLE", "roleCode": "FINANCE_MANAGER", "nodeName": "财务审批"}]',
    48,
    'ESCALATE',
    'ENABLED',
    CURRENT_TIMESTAMP
) ON CONFLICT DO NOTHING;

-- 3. 奖励风控+财务+总监审批流程 (三级)
INSERT INTO sys_approval_flow (flow_code, flow_name, trigger_event, conditions, nodes, timeout_hours, timeout_action, status, created_at)
VALUES (
    'REWARD_RISK_FINANCE_DIRECTOR_APPROVAL',
    '奖励风控+财务+总监审批',
    'REWARD_RISK_FINANCE_DIRECTOR_APPROVAL',
    'reward points >= 50000',
    '[{"approverType": "ROLE", "roleCode": "RISK_MANAGER", "nodeName": "风控审批"}, {"approverType": "ROLE", "roleCode": "FINANCE_MANAGER", "nodeName": "财务审批"}, {"approverType": "ROLE", "roleCode": "OPERATIONS_DIRECTOR", "nodeName": "总监审批"}]',
    72,
    'ESCALATE',
    'ENABLED',
    CURRENT_TIMESTAMP
) ON CONFLICT DO NOTHING;

-- 4. 角色变更审批流程
INSERT INTO sys_approval_flow (flow_code, flow_name, trigger_event, conditions, nodes, timeout_hours, timeout_action, status, created_at)
VALUES (
    'ROLE_CHANGE_APPROVAL',
    '角色变更审批',
    'ROLE_CHANGE',
    NULL,
    '[{"approverType": "ROLE", "roleCode": "SYS_ADMIN", "nodeName": "系统管理员审批"}]',
    24,
    'ESCALATE',
    'ENABLED',
    CURRENT_TIMESTAMP
) ON CONFLICT DO NOTHING;

-- 5. 活动创建审批流程
INSERT INTO sys_approval_flow (flow_code, flow_name, trigger_event, conditions, nodes, timeout_hours, timeout_action, status, created_at)
VALUES (
    'ACTIVITY_SUBMIT_APPROVAL',
    '活动创建审批',
    'ACTIVITY_SUBMIT',
    NULL,
    '[{"approverType": "ROLE", "roleCode": "OPERATIONS_MANAGER", "nodeName": "运营经理审批"}]',
    24,
    'ESCALATE',
    'ENABLED',
    CURRENT_TIMESTAMP
) ON CONFLICT DO NOTHING;
