-- =====================================================
-- BPM 采购审核流程 - SQL 初始化
-- =====================================================

-- =====================================================
-- 01. 创建流程分类（采购管理）
-- =====================================================

INSERT INTO bpm_category (id, name, code, description, status, sort, creator, create_time, updater, update_time, deleted)
VALUES (100, '采购审核', 'purchase_approve', '采购订单审批流程分类', 0, 10, '1', NOW(), '1', NOW(), 0)
ON DUPLICATE KEY UPDATE name = VALUES(name), code = VALUES(code);

-- =====================================================
-- 02. 创建采购订单审批表单
-- =====================================================

INSERT INTO bpm_form (id, name, status, conf, fields, remark, creator, create_time, updater, update_time, deleted)
VALUES (
    100,
    '采购订单审批表单',
    0,
    '{"formRef":"elForm","size":"medium","labelPosition":"right","labelWidth":100,"formRules":"rules","gutter":15,"disabled":false,"span":24,"formBtns":true}',
    '[
        {"type":"input","label":"订单编号","placeholder":"请输入订单编号","field":"orderNo","defaultValue":"","required":true},
        {"type":"input","label":"供应商名称","placeholder":"请输入供应商名称","field":"supplierName","defaultValue":"","required":true},
        {"type":"input","label":"采购金额","placeholder":"请输入采购金额","field":"amount","defaultValue":"","required":true},
        {"type":"input","label":"订单数量","placeholder":"请输入订单数量","field":"quantity","defaultValue":"","required":true},
        {"type":"textarea","label":"订单明细","placeholder":"请输入订单明细","field":"orderDetail","defaultValue":"","required":false},
        {"type":"textarea","label":"备注","placeholder":"请输入备注","field":"remark","defaultValue":"","required":false}
    ]',
    '采购订单审批表单',
    '1',
    NOW(),
    '1',
    NOW(),
    0
) ON DUPLICATE KEY UPDATE name = VALUES(name);

-- =====================================================
-- 03. 说明：流程模型和定义需要通过前端界面创建
-- =====================================================
--
-- 采购审批流程建议配置：
--
-- 流程名称：采购订单审批
-- 流程分类：采购审核 (code = purchase_approve)
-- 表单类型：动态表单（关联上面的表单 id=100）
--
-- 流程节点配置（Simple 设计器）：
--
-- 1. 开始节点
--    - 发起人：全员可发起
--
-- 2. 主管审批节点
--    - 审批人：发起人的直属主管
--    - 审批类型：审批
--
-- 3. 采购经理审批节点（金额 > 5000 时）
--    - 条件分支：采购金额 > 5000
--    - 审批人：采购经理角色或指定用户
--    - 审批类型：审批
--
-- 4. 财务审批节点（金额 > 10000 时）
--    - 条件分支：采购金额 > 10000
--    - 审批人：财务经理角色或指定用户
--    - 审批类型：审批
--
-- 5. 总经理审批节点（金额 > 50000 时）
--    - 条件分支：采购金额 > 50000
--    - 审批人：总经理角色或指定用户
--    - 审批类型：审批
--
-- 6. 结束节点
--    - 审批通过后自动结束
--
-- =====================================================

-- =====================================================
-- 04. 查询验证
-- =====================================================

-- 验证分类创建
SELECT * FROM bpm_category WHERE code = 'purchase_approve';

-- 验证表单创建
SELECT * FROM bpm_form WHERE name = '采购订单审批表单';