-- 用印申请管理接入协同统一审核
-- 使用前确认当前数据库为业务库（如 product-inventory-management-ygcy）

-- 1. 用印申请单增加关联协同审批流程id字段
ALTER TABLE seal_application_management
    ADD COLUMN approve_process_id bigint DEFAULT NULL COMMENT '关联协同审批流程id(approve_process.id)' AFTER approve_user_id;

-- 2. 审批流程配置：新增“用印审批”(approve_type=9)审批节点
--    默认审批人：第一级 管理部(236)，第二级 赵拥军(214)，可在【审批管理】菜单调整
INSERT INTO approve_process_config_node (approve_type, node_order, approver_id, approver_name, timeout_hours, tenant_id, create_user, create_time, update_user, update_time, delete_flag, dept_id)
SELECT 9, 1, 236, '管理部', NULL, 1, 1, NOW(), 1, NOW(), 0, NULL FROM DUAL
WHERE NOT EXISTS (SELECT 1 FROM approve_process_config_node WHERE approve_type = 9 AND delete_flag = 0);

INSERT INTO approve_process_config_node (approve_type, node_order, approver_id, approver_name, timeout_hours, tenant_id, create_user, create_time, update_user, update_time, delete_flag, dept_id)
SELECT 9, 2, 214, '赵拥军', NULL, 1, 1, NOW(), 1, NOW(), 0, NULL FROM DUAL
WHERE NOT EXISTS (SELECT 1 FROM approve_process_config_node WHERE approve_type = 9 AND node_order = 2 AND delete_flag = 0);
