742 lines
51 KiB
Transact-SQL
742 lines
51 KiB
Transact-SQL
/* ============================================================================
|
||
FMS 工作流运行态模拟数据 —— 费用报销审批(expense_approval v1)
|
||
|
||
用途:给「流程管理 → 运行监控」与「审批中心(我的待办 / 我发起的 / 我已处理 /
|
||
抄送我的)」造一批可直接查看、可继续操作的运行数据。
|
||
|
||
前置条件:
|
||
1. 已执行 sql/fms_workflow.sql(wf_* 建表)。
|
||
2. 已执行 sql/fms_workflow_mock.sql(流程定义 expense_approval + 已发布版本
|
||
expense_approval_v1)。本脚本以该版本为模板,不重复定义流程。
|
||
3. 已执行 sql/fms_workflow_org_ext.sql(岗位 / 组织角色等组织主数据表)。
|
||
|
||
本脚本写入:
|
||
- 演示组织数据:1 个部门 + 4 个演示用户 + 5 个岗位 + 4 个组织角色 + 授权
|
||
(演示用户密码与账号相同,仅供演示环境登录)
|
||
- 1 条停用的流程绑定(给运行数据一个真实出处,不拦截真实送审)
|
||
- 6 条流程实例及其节点运行 / 待办任务 / 动作流水 / 抄送记录
|
||
- 把 mock 脚本里的占位用户 U001 / U002 / U003 就地替换为演示用户
|
||
|
||
覆盖的场景(6 条实例):
|
||
模拟-费用报销-001 运行中 · 部门负责人审批(或签,两条待办)
|
||
模拟-费用报销-002 运行中 · 并行分支(法务串行会签第 2 签 + 风控按比例 2/3 + 抄送)
|
||
模拟-费用报销-003 运行中 · 总经理审批(金额 > 1 万分支)
|
||
模拟-费用报销-004 已通过 · 完整链路(会签 → 并行 → 董事长 N 人通过 → 归档 → 结束)
|
||
模拟-费用报销-005 已驳回 · 总经理终止(reject_mode = terminate)
|
||
模拟-费用报销-006 已退回 · 部门负责人退回发起人(return_initiator)
|
||
|
||
用 g3soft 登录后的预期结果:
|
||
我的待办 2 条(002 法务串行会签、003 总经理审批)
|
||
我发起的 2 条(001 运行中、006 已退回)
|
||
我已处理 2 条(004 董事长审批通过、005 总经理驳回)
|
||
抄送我的 2 条(002 未读、004 已读)
|
||
运行监控 6 条实例,其中 3 条运行中
|
||
|
||
可重复执行:先按业务单号前缀「模拟-」清理旧运行数据,再重建;
|
||
组织数据 / 绑定 / 规则补丁都按「不存在才写入」处理。
|
||
全部清理(含演示组织数据)见文件末尾注释。
|
||
|
||
说明:只写运行表与演示组织数据;不写 wf_outbox(避免触发通知派发),
|
||
不写任何业务表(运行监控与审批中心都不依赖业务表数据)。
|
||
============================================================================ */
|
||
|
||
SET NOCOUNT ON;
|
||
GO
|
||
|
||
/* ----------------------------------------------------------------------------
|
||
0. 前置检查与清理
|
||
---------------------------------------------------------------------------- */
|
||
|
||
if not exists (select 1 from dbo.wf_version where b_id = 'expense_approval_v1' and b_status = 'published')
|
||
begin
|
||
raiserror (N'缺少已发布版本 expense_approval_v1:请先执行 sql/fms_workflow_mock.sql', 16, 1);
|
||
return;
|
||
end
|
||
GO
|
||
|
||
if not exists (select 1 from dbo.wf_definition where b_id = 'expense_approval')
|
||
begin
|
||
raiserror (N'缺少流程定义 expense_approval:请先执行 sql/fms_workflow_mock.sql', 16, 1);
|
||
return;
|
||
end
|
||
GO
|
||
|
||
/* 清理本脚本上一次造出来的运行数据(业务单号前缀「模拟-」是识别标记) */
|
||
declare @old table (b_id uniqueidentifier primary key);
|
||
|
||
insert into @old (b_id)
|
||
select b_id from dbo.wf_instance where b_business_no like N'模拟-%';
|
||
|
||
delete from dbo.wf_action where b_instance_id in (select b_id from @old);
|
||
delete from dbo.wf_cc where b_instance_id in (select b_id from @old);
|
||
delete from dbo.wf_task where b_instance_id in (select b_id from @old);
|
||
delete from dbo.wf_node_run where b_instance_id in (select b_id from @old);
|
||
delete from dbo.wf_instance where b_id in (select b_id from @old);
|
||
GO
|
||
|
||
/* ----------------------------------------------------------------------------
|
||
1. 演示组织数据
|
||
|
||
演示用户的身兼数职只为把 mock 流程的审批人规则解析完整,不代表真实职务设计:
|
||
张伟 demo_zhangwei 演示事业部负责人(dept_manager)+ 财务经理 + 法务负责人
|
||
李强 demo_liqiang 分管副总(vice_president)
|
||
g3soft 总经理(gm)+ 指定审批人 U001
|
||
王芳 demo_wangfang 财务 + 财务总监(抄送对象)+ 法务专员
|
||
刘敏 demo_liumin 风控 + 风控经理 + 指定审批人 U003
|
||
---------------------------------------------------------------------------- */
|
||
|
||
/* 1.1 部门:演示事业部 */
|
||
declare @now datetime2 = sysutcdatetime();
|
||
|
||
if not exists (select 1 from dbo.b_dept where b_id = 'demo_dept')
|
||
begin
|
||
insert into dbo.b_dept (b_id, b_parent_id, b_depth, b_path, b_name, b_i18n, b_canuse, b_xh, b_bz, b_manager_id,
|
||
b_created_by, b_created_at, b_updated_by, b_updated_at)
|
||
values ('demo_dept', null, 0, '/demo_dept/', N'演示事业部', null, 1, 10, N'工作流模拟数据:演示用部门', null,
|
||
'g3soft', @now, 'g3soft', @now);
|
||
end
|
||
|
||
update dbo.b_dept
|
||
set b_manager_id = 'demo_zhangwei', b_updated_by = 'g3soft', b_updated_at = @now
|
||
where b_id = 'demo_dept'
|
||
and (b_manager_id is null or b_manager_id <> 'demo_zhangwei');
|
||
|
||
/* 1.2 演示用户(密码与账号相同) */
|
||
declare @users table (b_id varchar(50) primary key, b_name nvarchar(200) not null, b_bz nvarchar(800));
|
||
|
||
insert into @users (b_id, b_name, b_bz)
|
||
values ('demo_zhangwei', N'张伟', N'工作流模拟数据:演示事业部负责人 / 财务经理 / 法务负责人'),
|
||
('demo_liqiang', N'李强', N'工作流模拟数据:分管副总'),
|
||
('demo_wangfang', N'王芳', N'工作流模拟数据:财务 / 财务总监 / 法务专员'),
|
||
('demo_liumin', N'刘敏', N'工作流模拟数据:风控 / 风控经理');
|
||
|
||
insert into dbo.b_user (b_id, b_name, b_dept_id, b_bz, b_password, b_canuse, b_logincount,
|
||
b_created_by, b_created_at, b_updated_by, b_updated_at)
|
||
select u.b_id, u.b_name, 'demo_dept', u.b_bz, u.b_id, 1, 0, 'g3soft', @now, 'g3soft', @now
|
||
from @users u
|
||
where not exists (select 1 from dbo.b_user x where x.b_id = u.b_id);
|
||
GO
|
||
|
||
/* 1.3 岗位 */
|
||
declare @now datetime2 = sysutcdatetime();
|
||
declare @positions table (b_id varchar(50) primary key, b_name nvarchar(200) not null, b_xh int);
|
||
|
||
insert into @positions (b_id, b_name, b_xh)
|
||
values ('gm', N'总经理', 10),
|
||
('vice_president', N'分管副总', 20),
|
||
('finance_manager', N'财务经理', 30),
|
||
('legal_staff', N'法务专员', 40),
|
||
('risk_manager', N'风控经理', 50);
|
||
|
||
insert into dbo.b_position (b_id, b_name, b_canuse, b_xh, b_bz, b_created_by, b_created_at, b_updated_by, b_updated_at)
|
||
select p.b_id, p.b_name, 1, p.b_xh, N'工作流模拟数据', 'g3soft', @now, 'g3soft', @now
|
||
from @positions p
|
||
where not exists (select 1 from dbo.b_position x where x.b_id = p.b_id);
|
||
|
||
/* 1.4 组织角色 */
|
||
declare @roles table (b_id varchar(50) primary key, b_name nvarchar(200) not null, b_xh int);
|
||
|
||
insert into @roles (b_id, b_name, b_xh)
|
||
values ('finance', N'财务', 10),
|
||
('legal_lead', N'法务负责人', 20),
|
||
('cfo', N'财务总监', 30),
|
||
('risk', N'风控', 40);
|
||
|
||
insert into dbo.b_org_role (b_id, b_name, b_canuse, b_xh, b_bz, b_created_by, b_created_at, b_updated_by, b_updated_at)
|
||
select r.b_id, r.b_name, 1, r.b_xh, N'工作流模拟数据', 'g3soft', @now, 'g3soft', @now
|
||
from @roles r
|
||
where not exists (select 1 from dbo.b_org_role x where x.b_id = r.b_id);
|
||
|
||
/* 1.5 用户岗位 */
|
||
declare @userPositions table (b_user_id varchar(50), b_position_id varchar(50));
|
||
|
||
insert into @userPositions (b_user_id, b_position_id)
|
||
values ('demo_zhangwei', 'finance_manager'),
|
||
('demo_liqiang', 'vice_president'),
|
||
('g3soft', 'gm'),
|
||
('demo_wangfang', 'legal_staff'),
|
||
('demo_wangfang', 'risk_manager'),
|
||
('demo_liumin', 'risk_manager');
|
||
|
||
insert into dbo.b_user_position (b_user_id, b_position_id, b_canuse, b_created_by, b_created_at, b_updated_by, b_updated_at)
|
||
select up.b_user_id, up.b_position_id, 1, 'g3soft', @now, 'g3soft', @now
|
||
from @userPositions up
|
||
where not exists (select 1 from dbo.b_user_position x
|
||
where x.b_user_id = up.b_user_id and x.b_position_id = up.b_position_id);
|
||
|
||
/* 1.6 用户组织角色 */
|
||
declare @userRoles table (b_user_id varchar(50), b_role_id varchar(50));
|
||
|
||
insert into @userRoles (b_user_id, b_role_id)
|
||
values ('demo_zhangwei', 'legal_lead'),
|
||
('demo_wangfang', 'finance'),
|
||
('demo_wangfang', 'cfo'),
|
||
('demo_liumin', 'risk');
|
||
|
||
insert into dbo.b_user_org_role (b_user_id, b_role_id, b_canuse, b_created_by, b_created_at, b_updated_by, b_updated_at)
|
||
select ur.b_user_id, ur.b_role_id, 1, 'g3soft', @now, 'g3soft', @now
|
||
from @userRoles ur
|
||
where not exists (select 1 from dbo.b_user_org_role x
|
||
where x.b_user_id = ur.b_user_id and x.b_role_id = ur.b_role_id);
|
||
GO
|
||
|
||
/* 1.7 演示用户授权:审批中心菜单 + 审批动作(演示用户登录后要能处理待办) */
|
||
declare @now datetime2 = sysutcdatetime();
|
||
|
||
insert into dbo.s_user_power (b_user_id, b_power_id, b_canuse, b_created_by, b_created_at, b_updated_by, b_updated_at)
|
||
select u.b_id, p.b_id, 1, 'g3soft', @now, 'g3soft', @now
|
||
from (values ('demo_zhangwei'), ('demo_liqiang'), ('demo_wangfang'), ('demo_liumin')) as u(b_id)
|
||
cross join dbo.s_power p
|
||
where (p.b_id like 'menu.approval%' or p.b_id like 'action.v_b_othercompany.%')
|
||
and not exists (select 1 from dbo.s_user_power x where x.b_user_id = u.b_id and x.b_power_id = p.b_id);
|
||
GO
|
||
|
||
/* ----------------------------------------------------------------------------
|
||
2. 流程绑定与审批人规则补丁
|
||
---------------------------------------------------------------------------- */
|
||
|
||
/*
|
||
2.1 演示绑定:故意 b_canuse = 0(停用)。
|
||
绑定的作用是给运行数据一个真实出处;停用是为了不让「合作伙伴」模块的真实送审
|
||
命中这个演示流程(expense_approval 的条件引用 b_amount,合作伙伴表没有该字段,
|
||
真送审会走成「条件出线没有一条命中」)。要真实跑通送审,请另建启用绑定,
|
||
并把流程条件字段对准业务模块自己的列。
|
||
*/
|
||
if not exists (select 1 from dbo.wf_binding where b_id = 'demo_expense_binding')
|
||
begin
|
||
insert into dbo.wf_binding (b_id, b_module_id, b_event, b_version_id, b_match_json, b_org_scope_json,
|
||
b_status_field, b_status_map_json, b_priority, b_effective_from, b_effective_to,
|
||
b_canuse, b_bz, b_created_by, b_created_at, b_updated_by, b_updated_at)
|
||
values ('demo_expense_binding', 'v_b_othercompany', 'submit', 'expense_approval_v1', null, null,
|
||
null, null, 10, null, null,
|
||
0, N'工作流模拟数据:停用的演示绑定,仅为运行数据提供出处', 'g3soft', sysutcdatetime(), 'g3soft', sysutcdatetime());
|
||
end
|
||
|
||
/*
|
||
2.2 审批人规则补丁:fms_workflow_mock.sql 里的 U001 / U002 / U003 是占位用户,
|
||
库里并不存在,解析时会被剔除。这里替换为本脚本的演示用户,让后续流转解析得到人:
|
||
U001 → g3soft(总经理)
|
||
U002 → demo_zhangwei(张伟)
|
||
U003 → demo_liqiang(李强)
|
||
*/
|
||
update dbo.wf_actor_rule
|
||
set b_actor_ref = 'g3soft'
|
||
where b_version_id = 'expense_approval_v1' and b_actor_ref = 'U001' and b_actor_type = 'user';
|
||
|
||
update dbo.wf_actor_rule
|
||
set b_actor_ref = 'demo_zhangwei'
|
||
where b_version_id = 'expense_approval_v1' and b_actor_ref = 'U002' and b_actor_type = 'user';
|
||
|
||
update dbo.wf_actor_rule
|
||
set b_actor_ref = 'demo_liqiang'
|
||
where b_version_id = 'expense_approval_v1' and b_actor_ref = 'U003' and b_actor_type = 'user';
|
||
GO
|
||
|
||
/* ============================================================================
|
||
3. 实例 A:运行中 · 部门负责人审批(或签)
|
||
|
||
模拟-费用报销-001 发起人 g3soft 金额 3,200 两小时前送审
|
||
或签两名候选人(部门负责人张伟 / 分管副总李强)各有一条待办。
|
||
============================================================================ */
|
||
|
||
declare @now datetime2 = sysutcdatetime();
|
||
declare @inst uniqueidentifier = newid();
|
||
declare @runStart uniqueidentifier = newid();
|
||
declare @runDm uniqueidentifier = newid();
|
||
declare @t0 datetime2 = dateadd(hour, -2, @now);
|
||
declare @due datetime2 = dateadd(hour, 22, @now);
|
||
declare @snap nvarchar(max) = N'{"rules":[{"b_actor_type":"dept_manager","b_actor_ref":null,"b_priority":10},{"b_actor_type":"position","b_actor_ref":"vice_president","b_priority":20}],"resolvedUsers":["demo_zhangwei","demo_liqiang"],"notes":[]}';
|
||
|
||
insert into dbo.wf_instance (b_id, b_definition_id, b_version_id, b_binding_id, b_module_id, b_event,
|
||
b_business_id, b_business_no, b_org_id, b_initiator_id, b_initiator_dept_id, b_status,
|
||
b_context_json, b_snapshot_json, b_current_summary_json, b_row_version,
|
||
b_idempotency_key, b_started_at, b_completed_at,
|
||
b_created_by, b_created_at, b_updated_by, b_updated_at)
|
||
values (@inst, 'expense_approval', 'expense_approval_v1', 'demo_expense_binding', 'v_b_othercompany', 'submit',
|
||
'MOCK-EXP-001', N'模拟-费用报销-001', 'G3HD', 'g3soft', 'demo_dept', 'running',
|
||
N'{"b_amount":3200,"b_dept_id":"demo_dept","b_initiator_dept_id":"demo_dept"}',
|
||
N'{"b_business_no":"模拟-费用报销-001","b_amount":3200,"b_reason":"客户拜访差旅费","b_dept_id":"demo_dept"}',
|
||
N'{"summary":"待审批:部门负责人审批"}', 1,
|
||
null, @t0, null,
|
||
'g3soft', @t0, 'g3soft', @t0);
|
||
|
||
insert into dbo.wf_node_run (b_id, b_instance_id, b_node_key, b_run_no, b_status, b_required_count,
|
||
b_completed_count, b_rejected_count, b_entered_at, b_exited_at,
|
||
b_actor_snapshot_json, b_created_at)
|
||
values (@runStart, @inst, 'start', 1, 'completed', null, 0, 0, @t0, @t0, null, @t0),
|
||
(@runDm, @inst, 'dept_manager', 1, 'running', 1, 0, 0, @t0, null, @snap, @t0);
|
||
|
||
insert into dbo.wf_task (b_id, b_instance_id, b_node_run_id, b_node_key, b_actor_rule_id, b_assignee_type,
|
||
b_assignee_id, b_seq, b_status, b_due_at, b_claimed_by, b_claimed_at,
|
||
b_completed_by, b_completed_at, b_rule_snapshot_json, b_created_at, b_updated_at)
|
||
values (newid(), @inst, @runDm, 'dept_manager', null, 'user', 'demo_zhangwei', 10, 'pending', @due, null, null, null, null, @snap, @t0, @t0),
|
||
(newid(), @inst, @runDm, 'dept_manager', null, 'user', 'demo_liqiang', 20, 'pending', @due, null, null, null, null, @snap, @t0, @t0);
|
||
|
||
insert into dbo.wf_action (b_id, b_instance_id, b_node_run_id, b_task_id, b_action, b_operator_id,
|
||
b_from_status, b_to_status, b_comment, b_payload_json, b_request_id, b_trace_id,
|
||
b_occurdatetime)
|
||
values (newid(), @inst, null, null, 'submit', 'g3soft', null, 'running', N'提交审批', null, null, null, @t0);
|
||
GO
|
||
|
||
/* ============================================================================
|
||
4. 实例 B:运行中 · 并行分支
|
||
|
||
模拟-费用报销-002 发起人 刘敏 金额 30,000 30 小时前送审
|
||
已过:部门负责人(或签)→ 金额判断(> 1 万)→ 总经理审批 → 并行分支
|
||
进行中:法务串行会签(第 1 签已过,第 2 签 g3soft 待办,第 3 签未激活)、
|
||
风控按比例通过(3 人过 2 人,已过 1 票)、抄送财务总监已发出
|
||
============================================================================ */
|
||
|
||
declare @now datetime2 = sysutcdatetime();
|
||
declare @inst uniqueidentifier = newid();
|
||
declare @runStart uniqueidentifier = newid();
|
||
declare @runDm uniqueidentifier = newid();
|
||
declare @runGateway uniqueidentifier = newid();
|
||
declare @runGm uniqueidentifier = newid();
|
||
declare @runSplit uniqueidentifier = newid();
|
||
declare @runLegal uniqueidentifier = newid();
|
||
declare @runCc uniqueidentifier = newid();
|
||
declare @runRisk uniqueidentifier = newid();
|
||
declare @t0 datetime2 = dateadd(hour, -30, @now);
|
||
declare @t1 datetime2 = dateadd(minute, 30, @t0);
|
||
declare @t2 datetime2 = dateadd(hour, 4, @t1);
|
||
declare @t3 datetime2 = dateadd(hour, 1, @t2);
|
||
declare @snapDm nvarchar(max) = N'{"rules":[{"b_actor_type":"dept_manager","b_actor_ref":null,"b_priority":10},{"b_actor_type":"position","b_actor_ref":"vice_president","b_priority":20}],"resolvedUsers":["demo_zhangwei","demo_liqiang"],"notes":[]}';
|
||
declare @snapGm nvarchar(max) = N'{"rules":[{"b_actor_type":"position","b_actor_ref":"gm","b_priority":10}],"resolvedUsers":["g3soft"],"notes":[]}';
|
||
declare @snapLegal nvarchar(max) = N'{"rules":[{"b_actor_type":"org_role","b_actor_ref":"legal_lead","b_priority":10},{"b_actor_type":"user","b_actor_ref":"g3soft","b_priority":20},{"b_actor_type":"position","b_actor_ref":"legal_staff","b_priority":30}],"resolvedUsers":["demo_zhangwei","g3soft","demo_wangfang"],"notes":[]}';
|
||
declare @snapRisk nvarchar(max) = N'{"rules":[{"b_actor_type":"org_role","b_actor_ref":"risk","b_priority":10},{"b_actor_type":"position","b_actor_ref":"risk_manager","b_priority":20},{"b_actor_type":"user","b_actor_ref":"demo_zhangwei","b_priority":30}],"resolvedUsers":["demo_liumin","demo_wangfang","demo_zhangwei"],"notes":[]}';
|
||
declare @snapCc nvarchar(max) = N'{"rules":[{"b_actor_type":"org_role","b_actor_ref":"cfo","b_priority":10}],"resolvedUsers":["demo_wangfang","g3soft"],"notes":["演示数据额外抄送 g3soft,便于管理员账号直接看到抄送页"]}';
|
||
|
||
insert into dbo.wf_instance (b_id, b_definition_id, b_version_id, b_binding_id, b_module_id, b_event,
|
||
b_business_id, b_business_no, b_org_id, b_initiator_id, b_initiator_dept_id, b_status,
|
||
b_context_json, b_snapshot_json, b_current_summary_json, b_row_version,
|
||
b_idempotency_key, b_started_at, b_completed_at,
|
||
b_created_by, b_created_at, b_updated_by, b_updated_at)
|
||
values (@inst, 'expense_approval', 'expense_approval_v1', 'demo_expense_binding', 'v_b_othercompany', 'submit',
|
||
'MOCK-EXP-002', N'模拟-费用报销-002', 'G3HD', 'demo_liumin', 'demo_dept', 'running',
|
||
N'{"b_amount":30000,"b_dept_id":"demo_dept","b_initiator_dept_id":"demo_dept"}',
|
||
N'{"b_business_no":"模拟-费用报销-002","b_amount":30000,"b_reason":"季度团建费用","b_dept_id":"demo_dept"}',
|
||
N'{"summary":"审批中:风控按比例通过"}', 5,
|
||
null, @t0, null,
|
||
'demo_liumin', @t0, 'demo_liumin', @t3);
|
||
|
||
insert into dbo.wf_node_run (b_id, b_instance_id, b_node_key, b_run_no, b_status, b_required_count,
|
||
b_completed_count, b_rejected_count, b_entered_at, b_exited_at,
|
||
b_actor_snapshot_json, b_created_at)
|
||
values (@runStart, @inst, 'start', 1, 'completed', null, 0, 0, @t0, @t0, null, @t0),
|
||
(@runDm, @inst, 'dept_manager', 1, 'completed', 1, 1, 0, @t0, @t1, @snapDm, @t0),
|
||
(@runGateway,@inst, 'amount_gateway', 1, 'completed', null, 0, 0, @t1, @t1, null, @t1),
|
||
(@runGm, @inst, 'gm_approve', 1, 'completed', 1, 1, 0, @t1, @t2, @snapGm, @t1),
|
||
(@runSplit, @inst, 'parallel_split', 1, 'completed', null, 0, 0, @t2, @t2, null, @t2),
|
||
(@runLegal, @inst, 'legal_countersign', 1, 'running', 3, 1, 0, @t2, null, @snapLegal, @t2),
|
||
(@runCc, @inst, 'cc_cfo', 1, 'completed', 1, 0, 0, @t2, @t2, @snapCc, @t2),
|
||
(@runRisk, @inst, 'risk_review', 1, 'running', 2, 1, 0, @t2, null, @snapRisk, @t2);
|
||
|
||
insert into dbo.wf_task (b_id, b_instance_id, b_node_run_id, b_node_key, b_actor_rule_id, b_assignee_type,
|
||
b_assignee_id, b_seq, b_status, b_due_at, b_claimed_by, b_claimed_at,
|
||
b_completed_by, b_completed_at, b_rule_snapshot_json, b_created_at, b_updated_at)
|
||
values
|
||
-- 部门负责人(或签):张伟通过,李强被自动取消
|
||
(newid(), @inst, @runDm, 'dept_manager', null, 'user', 'demo_zhangwei', 10, 'approved',
|
||
dateadd(hour, 24, @t0), null, null, 'demo_zhangwei', @t1, @snapDm, @t0, @t1),
|
||
(newid(), @inst, @runDm, 'dept_manager', null, 'user', 'demo_liqiang', 20, 'cancelled',
|
||
dateadd(hour, 24, @t0), null, null, null, null, @snapDm, @t0, @t1),
|
||
-- 总经理(单人):g3soft 通过
|
||
(newid(), @inst, @runGm, 'gm_approve', null, 'user', 'g3soft', 10, 'approved',
|
||
dateadd(hour, 48, @t1), null, null, 'g3soft', @t2, @snapGm, @t1, @t2),
|
||
-- 法务串行会签:第 1 签张伟已过,第 2 签 g3soft 待办,第 3 签王芳未激活
|
||
(newid(), @inst, @runLegal, 'legal_countersign', null, 'user', 'demo_zhangwei', 10, 'approved',
|
||
dateadd(hour, 72, @t2), null, null, 'demo_zhangwei', @t2, @snapLegal, @t2, @t2),
|
||
(newid(), @inst, @runLegal, 'legal_countersign', null, 'user', 'g3soft', 20, 'pending',
|
||
dateadd(hour, 72, @t2), null, null, null, null, @snapLegal, @t2, @t2),
|
||
(newid(), @inst, @runLegal, 'legal_countersign', null, 'user', 'demo_wangfang', 30, 'waiting',
|
||
dateadd(hour, 72, @t2), null, null, null, null, @snapLegal, @t2, @t2),
|
||
-- 风控按比例通过(3 人需过 2 人):刘敏已过 1 票,王芳已抢占,张伟待办
|
||
(newid(), @inst, @runRisk, 'risk_review', null, 'user', 'demo_liumin', 10, 'approved',
|
||
dateadd(hour, 48, @t2), null, null, 'demo_liumin', @t3, @snapRisk, @t2, @t3),
|
||
(newid(), @inst, @runRisk, 'risk_review', null, 'user', 'demo_wangfang', 20, 'claimed',
|
||
dateadd(hour, 48, @t2), 'demo_wangfang', @t3, null, null, @snapRisk, @t2, @t3),
|
||
(newid(), @inst, @runRisk, 'risk_review', null, 'user', 'demo_zhangwei', 30, 'pending',
|
||
dateadd(hour, 48, @t2), null, null, null, null, @snapRisk, @t2, @t2);
|
||
|
||
insert into dbo.wf_cc (b_id, b_instance_id, b_node_run_id, b_node_key, b_recipient_id, b_actor_rule_id,
|
||
b_status, b_read_at, b_rule_snapshot_json, b_created_at)
|
||
values (newid(), @inst, @runCc, 'cc_cfo', 'demo_wangfang', null, 'unread', null, @snapCc, @t2),
|
||
(newid(), @inst, @runCc, 'cc_cfo', 'g3soft', null, 'unread', null, @snapCc, @t2);
|
||
|
||
insert into dbo.wf_action (b_id, b_instance_id, b_node_run_id, b_task_id, b_action, b_operator_id,
|
||
b_from_status, b_to_status, b_comment, b_payload_json, b_request_id, b_trace_id,
|
||
b_occurdatetime)
|
||
values (newid(), @inst, null, null, 'submit', 'demo_liumin', null, 'running', N'提交审批', null, null, null, @t0),
|
||
(newid(), @inst, @runDm, null, 'approve', 'demo_zhangwei', 'pending', 'approved', N'费用在季度预算内,同意', null, null, null, @t1),
|
||
(newid(), @inst, @runDm, null, 'cancel', null, 'pending', 'cancelled', N'同节点其余待办已自动取消(1 条)', null, null, null, dateadd(second, 1, @t1)),
|
||
(newid(), @inst, @runGm, null, 'approve', 'g3soft', 'pending', 'approved', N'金额属实,同意', null, null, null, @t2),
|
||
(newid(), @inst, @runCc, null, 'cc', null, 'running', 'running', N'抄送「抄送财务总监」共 2 人', null, null, null, dateadd(second, 1, @t2)),
|
||
(newid(), @inst, @runLegal, null, 'approve', 'demo_zhangwei', 'pending', 'approved', N'合同条款已确认', null, null, null, dateadd(second, 2, @t2)),
|
||
(newid(), @inst, @runRisk, null, 'approve', 'demo_liumin', 'pending', 'approved', N'风险可控,同意', null, null, null, @t3);
|
||
GO
|
||
|
||
/* ============================================================================
|
||
5. 实例 C:运行中 · 总经理审批
|
||
|
||
模拟-费用报销-003 发起人 王芳 金额 15,000 6 小时前送审
|
||
金额 > 1 万走总经理;部门负责人已通过,总经理(g3soft)有一条待办。
|
||
============================================================================ */
|
||
|
||
declare @now datetime2 = sysutcdatetime();
|
||
declare @inst uniqueidentifier = newid();
|
||
declare @runStart uniqueidentifier = newid();
|
||
declare @runDm uniqueidentifier = newid();
|
||
declare @runGateway uniqueidentifier = newid();
|
||
declare @runGm uniqueidentifier = newid();
|
||
declare @t0 datetime2 = dateadd(hour, -6, @now);
|
||
declare @t1 datetime2 = dateadd(hour, 1, @t0);
|
||
declare @snapDm nvarchar(max) = N'{"rules":[{"b_actor_type":"dept_manager","b_actor_ref":null,"b_priority":10},{"b_actor_type":"position","b_actor_ref":"vice_president","b_priority":20}],"resolvedUsers":["demo_zhangwei","demo_liqiang"],"notes":[]}';
|
||
declare @snapGm nvarchar(max) = N'{"rules":[{"b_actor_type":"position","b_actor_ref":"gm","b_priority":10}],"resolvedUsers":["g3soft"],"notes":[]}';
|
||
|
||
insert into dbo.wf_instance (b_id, b_definition_id, b_version_id, b_binding_id, b_module_id, b_event,
|
||
b_business_id, b_business_no, b_org_id, b_initiator_id, b_initiator_dept_id, b_status,
|
||
b_context_json, b_snapshot_json, b_current_summary_json, b_row_version,
|
||
b_idempotency_key, b_started_at, b_completed_at,
|
||
b_created_by, b_created_at, b_updated_by, b_updated_at)
|
||
values (@inst, 'expense_approval', 'expense_approval_v1', 'demo_expense_binding', 'v_b_othercompany', 'submit',
|
||
'MOCK-EXP-003', N'模拟-费用报销-003', 'G3HD', 'demo_wangfang', 'demo_dept', 'running',
|
||
N'{"b_amount":15000,"b_dept_id":"demo_dept","b_initiator_dept_id":"demo_dept"}',
|
||
N'{"b_business_no":"模拟-费用报销-003","b_amount":15000,"b_reason":"部门年度体检费用","b_dept_id":"demo_dept"}',
|
||
N'{"summary":"待审批:总经理审批"}', 2,
|
||
null, @t0, null,
|
||
'demo_wangfang', @t0, 'demo_wangfang', dateadd(second, 1, @t1));
|
||
|
||
insert into dbo.wf_node_run (b_id, b_instance_id, b_node_key, b_run_no, b_status, b_required_count,
|
||
b_completed_count, b_rejected_count, b_entered_at, b_exited_at,
|
||
b_actor_snapshot_json, b_created_at)
|
||
values (@runStart, @inst, 'start', 1, 'completed', null, 0, 0, @t0, @t0, null, @t0),
|
||
(@runDm, @inst, 'dept_manager', 1, 'completed', 1, 1, 0, @t0, @t1, @snapDm, @t0),
|
||
(@runGateway,@inst, 'amount_gateway', 1, 'completed', null, 0, 0, @t1, @t1, null, @t1),
|
||
(@runGm, @inst, 'gm_approve', 1, 'running', 1, 0, 0, @t1, null, @snapGm, @t1);
|
||
|
||
insert into dbo.wf_task (b_id, b_instance_id, b_node_run_id, b_node_key, b_actor_rule_id, b_assignee_type,
|
||
b_assignee_id, b_seq, b_status, b_due_at, b_claimed_by, b_claimed_at,
|
||
b_completed_by, b_completed_at, b_rule_snapshot_json, b_created_at, b_updated_at)
|
||
values (newid(), @inst, @runDm, 'dept_manager', null, 'user', 'demo_zhangwei', 10, 'approved',
|
||
dateadd(hour, 24, @t0), null, null, 'demo_zhangwei', @t1, @snapDm, @t0, @t1),
|
||
(newid(), @inst, @runDm, 'dept_manager', null, 'user', 'demo_liqiang', 20, 'cancelled',
|
||
dateadd(hour, 24, @t0), null, null, null, null, @snapDm, @t0, @t1),
|
||
(newid(), @inst, @runGm, 'gm_approve', null, 'user', 'g3soft', 10, 'pending',
|
||
dateadd(hour, 48, @t1), null, null, null, null, @snapGm, @t1, @t1);
|
||
|
||
insert into dbo.wf_action (b_id, b_instance_id, b_node_run_id, b_task_id, b_action, b_operator_id,
|
||
b_from_status, b_to_status, b_comment, b_payload_json, b_request_id, b_trace_id,
|
||
b_occurdatetime)
|
||
values (newid(), @inst, null, null, 'submit', 'demo_wangfang', null, 'running', N'提交审批', null, null, null, @t0),
|
||
(newid(), @inst, @runDm, null, 'approve', 'demo_zhangwei', 'pending', 'approved', N'同意', null, null, null, @t1),
|
||
(newid(), @inst, @runDm, null, 'cancel', null, 'pending', 'cancelled', N'同节点其余待办已自动取消(1 条)', null, null, null, dateadd(second, 1, @t1));
|
||
GO
|
||
|
||
/* ============================================================================
|
||
6. 实例 D:已通过 · 完整链路
|
||
|
||
模拟-费用报销-004 发起人 刘敏 金额 60,000 六天前送审、五天前通过
|
||
完整走了:部门负责人(或签)→ 金额判断(> 1 万)→ 总经理 →
|
||
并行(法务串行会签 3 人 / 抄送财务总监 / 风控按比例 3 人过 2 人)→ 并行汇合 →
|
||
是否超阈值(>= 5 万)→ 董事长 N 人通过(3 人过 2 人)→ 结束
|
||
============================================================================ */
|
||
|
||
declare @now datetime2 = sysutcdatetime();
|
||
declare @inst uniqueidentifier = newid();
|
||
declare @runStart uniqueidentifier = newid();
|
||
declare @runDm uniqueidentifier = newid();
|
||
declare @runGateway uniqueidentifier = newid();
|
||
declare @runGm uniqueidentifier = newid();
|
||
declare @runSplit uniqueidentifier = newid();
|
||
declare @runLegal uniqueidentifier = newid();
|
||
declare @runCc uniqueidentifier = newid();
|
||
declare @runRisk uniqueidentifier = newid();
|
||
declare @runJoin uniqueidentifier = newid();
|
||
declare @runBigGateway uniqueidentifier = newid();
|
||
declare @runChairman uniqueidentifier = newid();
|
||
declare @runEnd uniqueidentifier = newid();
|
||
declare @t0 datetime2 = dateadd(day, -6, @now);
|
||
declare @t1 datetime2 = dateadd(hour, 2, @t0);
|
||
declare @t2 datetime2 = dateadd(hour, 14, @t1);
|
||
declare @t3 datetime2 = dateadd(hour, 1, @t2);
|
||
declare @t4 datetime2 = dateadd(hour, 1, @t3);
|
||
declare @t5 datetime2 = dateadd(hour, 1, @t4);
|
||
declare @t6 datetime2 = dateadd(hour, 1, @t5);
|
||
declare @t7 datetime2 = dateadd(hour, 2, @t6);
|
||
declare @t8 datetime2 = dateadd(hour, 1, @t7);
|
||
declare @t9 datetime2 = dateadd(hour, 3, @t8);
|
||
declare @snapDm nvarchar(max) = N'{"rules":[{"b_actor_type":"dept_manager","b_actor_ref":null,"b_priority":10},{"b_actor_type":"position","b_actor_ref":"vice_president","b_priority":20}],"resolvedUsers":["demo_zhangwei","demo_liqiang"],"notes":[]}';
|
||
declare @snapGm nvarchar(max) = N'{"rules":[{"b_actor_type":"position","b_actor_ref":"gm","b_priority":10}],"resolvedUsers":["g3soft"],"notes":[]}';
|
||
declare @snapLegal nvarchar(max) = N'{"rules":[{"b_actor_type":"org_role","b_actor_ref":"legal_lead","b_priority":10},{"b_actor_type":"user","b_actor_ref":"g3soft","b_priority":20},{"b_actor_type":"position","b_actor_ref":"legal_staff","b_priority":30}],"resolvedUsers":["demo_zhangwei","g3soft","demo_wangfang"],"notes":[]}';
|
||
declare @snapRisk nvarchar(max) = N'{"rules":[{"b_actor_type":"org_role","b_actor_ref":"risk","b_priority":10},{"b_actor_type":"position","b_actor_ref":"risk_manager","b_priority":20},{"b_actor_type":"user","b_actor_ref":"demo_zhangwei","b_priority":30}],"resolvedUsers":["demo_liumin","demo_wangfang","demo_zhangwei"],"notes":[]}';
|
||
declare @snapCc nvarchar(max) = N'{"rules":[{"b_actor_type":"org_role","b_actor_ref":"cfo","b_priority":10}],"resolvedUsers":["demo_wangfang","g3soft"],"notes":["演示数据额外抄送 g3soft,便于管理员账号直接看到抄送页"]}';
|
||
declare @snapChairman nvarchar(max) = N'{"rules":[{"b_actor_type":"user","b_actor_ref":"g3soft","b_priority":10},{"b_actor_type":"user","b_actor_ref":"demo_zhangwei","b_priority":20},{"b_actor_type":"user","b_actor_ref":"demo_liqiang","b_priority":30}],"resolvedUsers":["g3soft","demo_zhangwei","demo_liqiang"],"notes":[]}';
|
||
|
||
insert into dbo.wf_instance (b_id, b_definition_id, b_version_id, b_binding_id, b_module_id, b_event,
|
||
b_business_id, b_business_no, b_org_id, b_initiator_id, b_initiator_dept_id, b_status,
|
||
b_context_json, b_snapshot_json, b_current_summary_json, b_row_version,
|
||
b_idempotency_key, b_started_at, b_completed_at,
|
||
b_created_by, b_created_at, b_updated_by, b_updated_at)
|
||
values (@inst, 'expense_approval', 'expense_approval_v1', 'demo_expense_binding', 'v_b_othercompany', 'submit',
|
||
'MOCK-EXP-004', N'模拟-费用报销-004', 'G3HD', 'demo_liumin', 'demo_dept', 'approved',
|
||
N'{"b_amount":60000,"b_dept_id":"demo_dept","b_initiator_dept_id":"demo_dept"}',
|
||
N'{"b_business_no":"模拟-费用报销-004","b_amount":60000,"b_reason":"办公设备采购","b_dept_id":"demo_dept"}',
|
||
N'{"summary":"已通过","node":"结束"}', 14,
|
||
null, @t0, dateadd(second, 2, @t9),
|
||
'demo_liumin', @t0, 'demo_liumin', dateadd(second, 2, @t9));
|
||
|
||
insert into dbo.wf_node_run (b_id, b_instance_id, b_node_key, b_run_no, b_status, b_required_count,
|
||
b_completed_count, b_rejected_count, b_entered_at, b_exited_at,
|
||
b_actor_snapshot_json, b_created_at)
|
||
values (@runStart, @inst, 'start', 1, 'completed', null, 0, 0, @t0, @t0, null, @t0),
|
||
(@runDm, @inst, 'dept_manager', 1, 'completed', 1, 1, 0, @t0, @t1, @snapDm, @t0),
|
||
(@runGateway, @inst, 'amount_gateway', 1, 'completed', null, 0, 0, @t1, @t1, null, @t1),
|
||
(@runGm, @inst, 'gm_approve', 1, 'completed', 1, 1, 0, @t1, @t2, @snapGm, @t1),
|
||
(@runSplit, @inst, 'parallel_split', 1, 'completed', null, 0, 0, @t2, @t2, null, @t2),
|
||
(@runLegal, @inst, 'legal_countersign', 1, 'completed', 3, 3, 0, @t2, @t5, @snapLegal, @t2),
|
||
(@runCc, @inst, 'cc_cfo', 1, 'completed', 2, 0, 0, @t2, @t2, @snapCc, @t2),
|
||
(@runRisk, @inst, 'risk_review', 1, 'completed', 2, 2, 0, @t2, @t7, @snapRisk, @t2),
|
||
(@runJoin, @inst, 'parallel_join', 1, 'completed', null, 0, 0, @t7, @t7, null, @t7),
|
||
(@runBigGateway,@inst,'big_amount_gateway',1, 'completed', null, 0, 0, @t7, @t7, null, @t7),
|
||
(@runChairman, @inst, 'chairman_approve', 1, 'completed', 2, 2, 0, @t7, @t9, @snapChairman, @t7),
|
||
(@runEnd, @inst, 'end', 1, 'completed', null, 0, 0, @t9, @t9, null, @t9);
|
||
|
||
insert into dbo.wf_task (b_id, b_instance_id, b_node_run_id, b_node_key, b_actor_rule_id, b_assignee_type,
|
||
b_assignee_id, b_seq, b_status, b_due_at, b_claimed_by, b_claimed_at,
|
||
b_completed_by, b_completed_at, b_rule_snapshot_json, b_created_at, b_updated_at)
|
||
values
|
||
-- 部门负责人(或签)
|
||
(newid(), @inst, @runDm, 'dept_manager', null, 'user', 'demo_zhangwei', 10, 'approved',
|
||
dateadd(hour, 24, @t0), null, null, 'demo_zhangwei', @t1, @snapDm, @t0, @t1),
|
||
(newid(), @inst, @runDm, 'dept_manager', null, 'user', 'demo_liqiang', 20, 'cancelled',
|
||
dateadd(hour, 24, @t0), null, null, null, null, @snapDm, @t0, @t1),
|
||
-- 总经理(单人)
|
||
(newid(), @inst, @runGm, 'gm_approve', null, 'user', 'g3soft', 10, 'approved',
|
||
dateadd(hour, 48, @t1), null, null, 'g3soft', @t2, @snapGm, @t1, @t2),
|
||
-- 法务串行会签(3 人全部通过)
|
||
(newid(), @inst, @runLegal, 'legal_countersign', null, 'user', 'demo_zhangwei', 10, 'approved',
|
||
dateadd(hour, 72, @t2), null, null, 'demo_zhangwei', @t3, @snapLegal, @t2, @t3),
|
||
(newid(), @inst, @runLegal, 'legal_countersign', null, 'user', 'g3soft', 20, 'approved',
|
||
dateadd(hour, 72, @t2), null, null, 'g3soft', @t4, @snapLegal, @t2, @t4),
|
||
(newid(), @inst, @runLegal, 'legal_countersign', null, 'user', 'demo_wangfang', 30, 'approved',
|
||
dateadd(hour, 72, @t2), null, null, 'demo_wangfang', @t5, @snapLegal, @t2, @t5),
|
||
-- 风控按比例通过(3 人过 2 人:刘敏、王芳通过,张伟被自动取消)
|
||
(newid(), @inst, @runRisk, 'risk_review', null, 'user', 'demo_liumin', 10, 'approved',
|
||
dateadd(hour, 48, @t2), null, null, 'demo_liumin', @t6, @snapRisk, @t2, @t6),
|
||
(newid(), @inst, @runRisk, 'risk_review', null, 'user', 'demo_wangfang', 20, 'approved',
|
||
dateadd(hour, 48, @t2), null, null, 'demo_wangfang', @t7, @snapRisk, @t2, @t7),
|
||
(newid(), @inst, @runRisk, 'risk_review', null, 'user', 'demo_zhangwei', 30, 'cancelled',
|
||
dateadd(hour, 48, @t2), null, null, null, null, @snapRisk, @t2, @t7),
|
||
-- 董事长审批(N 人通过,3 人过 2 人:g3soft、张伟通过,李强被自动取消)
|
||
(newid(), @inst, @runChairman, 'chairman_approve', null, 'user', 'g3soft', 10, 'approved',
|
||
dateadd(hour, 72, @t7), null, null, 'g3soft', @t8, @snapChairman, @t7, @t8),
|
||
(newid(), @inst, @runChairman, 'chairman_approve', null, 'user', 'demo_zhangwei', 20, 'approved',
|
||
dateadd(hour, 72, @t7), null, null, 'demo_zhangwei', @t9, @snapChairman, @t7, @t9),
|
||
(newid(), @inst, @runChairman, 'chairman_approve', null, 'user', 'demo_liqiang', 30, 'cancelled',
|
||
dateadd(hour, 72, @t7), null, null, null, null, @snapChairman, @t7, @t9);
|
||
|
||
insert into dbo.wf_cc (b_id, b_instance_id, b_node_run_id, b_node_key, b_recipient_id, b_actor_rule_id,
|
||
b_status, b_read_at, b_rule_snapshot_json, b_created_at)
|
||
values (newid(), @inst, @runCc, 'cc_cfo', 'demo_wangfang', null, 'read', @t9, @snapCc, @t2),
|
||
(newid(), @inst, @runCc, 'cc_cfo', 'g3soft', null, 'read', @t9, @snapCc, @t2);
|
||
|
||
insert into dbo.wf_action (b_id, b_instance_id, b_node_run_id, b_task_id, b_action, b_operator_id,
|
||
b_from_status, b_to_status, b_comment, b_payload_json, b_request_id, b_trace_id,
|
||
b_occurdatetime)
|
||
values (newid(), @inst, null, null, 'submit', 'demo_liumin', null, 'running', N'提交审批', null, null, null, @t0),
|
||
(newid(), @inst, @runDm, null, 'approve', 'demo_zhangwei', 'pending', 'approved', N'采购必要性确认,同意', null, null, null, @t1),
|
||
(newid(), @inst, @runDm, null, 'cancel', null, 'pending', 'cancelled', N'同节点其余待办已自动取消(1 条)', null, null, null, dateadd(second, 1, @t1)),
|
||
(newid(), @inst, @runGm, null, 'approve', 'g3soft', 'pending', 'approved', N'预算内,同意', null, null, null, @t2),
|
||
(newid(), @inst, @runCc, null, 'cc', null, 'running', 'running', N'抄送「抄送财务总监」共 2 人', null, null, null, dateadd(second, 1, @t2)),
|
||
(newid(), @inst, @runLegal, null, 'approve', 'demo_zhangwei', 'pending', 'approved', N'法务条款已审核', null, null, null, @t3),
|
||
(newid(), @inst, @runLegal, null, 'approve', 'g3soft', 'pending', 'approved', N'用印流程已确认', null, null, null, @t4),
|
||
(newid(), @inst, @runLegal, null, 'approve', 'demo_wangfang', 'pending', 'approved', N'法务复核完成', null, null, null, @t5),
|
||
(newid(), @inst, @runRisk, null, 'approve', 'demo_liumin', 'pending', 'approved', N'风险可控', null, null, null, @t6),
|
||
(newid(), @inst, @runRisk, null, 'approve', 'demo_wangfang', 'pending', 'approved', N'同意采购', null, null, null, @t7),
|
||
(newid(), @inst, @runRisk, null, 'cancel', null, 'pending', 'cancelled', N'同节点其余待办已自动取消(1 条)', null, null, null, dateadd(second, 1, @t7)),
|
||
(newid(), @inst, @runChairman, null, 'approve', 'g3soft', 'pending', 'approved', N'同意', null, null, null, @t8),
|
||
(newid(), @inst, @runChairman, null, 'approve', 'demo_zhangwei', 'pending', 'approved', N'同意', null, null, null, @t9),
|
||
(newid(), @inst, @runChairman, null, 'cancel', null, 'pending', 'cancelled', N'同节点其余待办已自动取消(1 条)', null, null, null, dateadd(second, 1, @t9)),
|
||
(newid(), @inst, null, null, 'approve', null, 'running', 'approved', N'已通过', null, null, null, dateadd(second, 2, @t9));
|
||
GO
|
||
|
||
/* ============================================================================
|
||
7. 实例 E:已驳回 · 总经理终止
|
||
|
||
模拟-费用报销-005 发起人 王芳 金额 45,000 四天前送审,当天被驳回
|
||
部门负责人已通过,总经理(g3soft)驳回;reject_mode = terminate,实例直接结束。
|
||
============================================================================ */
|
||
|
||
declare @now datetime2 = sysutcdatetime();
|
||
declare @inst uniqueidentifier = newid();
|
||
declare @runStart uniqueidentifier = newid();
|
||
declare @runDm uniqueidentifier = newid();
|
||
declare @runGateway uniqueidentifier = newid();
|
||
declare @runGm uniqueidentifier = newid();
|
||
declare @t0 datetime2 = dateadd(day, -4, @now);
|
||
declare @t1 datetime2 = dateadd(hour, 2, @t0);
|
||
declare @t2 datetime2 = dateadd(hour, 2, @t1);
|
||
declare @snapDm nvarchar(max) = N'{"rules":[{"b_actor_type":"dept_manager","b_actor_ref":null,"b_priority":10},{"b_actor_type":"position","b_actor_ref":"vice_president","b_priority":20}],"resolvedUsers":["demo_zhangwei","demo_liqiang"],"notes":[]}';
|
||
declare @snapGm nvarchar(max) = N'{"rules":[{"b_actor_type":"position","b_actor_ref":"gm","b_priority":10}],"resolvedUsers":["g3soft"],"notes":[]}';
|
||
|
||
insert into dbo.wf_instance (b_id, b_definition_id, b_version_id, b_binding_id, b_module_id, b_event,
|
||
b_business_id, b_business_no, b_org_id, b_initiator_id, b_initiator_dept_id, b_status,
|
||
b_context_json, b_snapshot_json, b_current_summary_json, b_row_version,
|
||
b_idempotency_key, b_started_at, b_completed_at,
|
||
b_created_by, b_created_at, b_updated_by, b_updated_at)
|
||
values (@inst, 'expense_approval', 'expense_approval_v1', 'demo_expense_binding', 'v_b_othercompany', 'submit',
|
||
'MOCK-EXP-005', N'模拟-费用报销-005', 'G3HD', 'demo_wangfang', 'demo_dept', 'rejected',
|
||
N'{"b_amount":45000,"b_dept_id":"demo_dept","b_initiator_dept_id":"demo_dept"}',
|
||
N'{"b_business_no":"模拟-费用报销-005","b_amount":45000,"b_reason":"市场推广物料制作费","b_dept_id":"demo_dept"}',
|
||
N'{"summary":"已驳回","node":"总经理审批"}', 3,
|
||
null, @t0, dateadd(second, 1, @t2),
|
||
'demo_wangfang', @t0, 'demo_wangfang', dateadd(second, 1, @t2));
|
||
|
||
insert into dbo.wf_node_run (b_id, b_instance_id, b_node_key, b_run_no, b_status, b_required_count,
|
||
b_completed_count, b_rejected_count, b_entered_at, b_exited_at,
|
||
b_actor_snapshot_json, b_created_at)
|
||
values (@runStart, @inst, 'start', 1, 'completed', null, 0, 0, @t0, @t0, null, @t0),
|
||
(@runDm, @inst, 'dept_manager', 1, 'completed', 1, 1, 0, @t0, @t1, @snapDm, @t0),
|
||
(@runGateway,@inst, 'amount_gateway', 1, 'completed', null, 0, 0, @t1, @t1, null, @t1),
|
||
(@runGm, @inst, 'gm_approve', 1, 'completed', 1, 0, 1, @t1, @t2, @snapGm, @t1);
|
||
|
||
insert into dbo.wf_task (b_id, b_instance_id, b_node_run_id, b_node_key, b_actor_rule_id, b_assignee_type,
|
||
b_assignee_id, b_seq, b_status, b_due_at, b_claimed_by, b_claimed_at,
|
||
b_completed_by, b_completed_at, b_rule_snapshot_json, b_created_at, b_updated_at)
|
||
values (newid(), @inst, @runDm, 'dept_manager', null, 'user', 'demo_zhangwei', 10, 'approved',
|
||
dateadd(hour, 24, @t0), null, null, 'demo_zhangwei', @t1, @snapDm, @t0, @t1),
|
||
(newid(), @inst, @runDm, 'dept_manager', null, 'user', 'demo_liqiang', 20, 'cancelled',
|
||
dateadd(hour, 24, @t0), null, null, null, null, @snapDm, @t0, @t1),
|
||
(newid(), @inst, @runGm, 'gm_approve', null, 'user', 'g3soft', 10, 'rejected',
|
||
dateadd(hour, 48, @t1), null, null, 'g3soft', @t2, @snapGm, @t1, @t2);
|
||
|
||
insert into dbo.wf_action (b_id, b_instance_id, b_node_run_id, b_task_id, b_action, b_operator_id,
|
||
b_from_status, b_to_status, b_comment, b_payload_json, b_request_id, b_trace_id,
|
||
b_occurdatetime)
|
||
values (newid(), @inst, null, null, 'submit', 'demo_wangfang', null, 'running', N'提交审批', null, null, null, @t0),
|
||
(newid(), @inst, @runDm, null, 'approve', 'demo_zhangwei', 'pending', 'approved', N'同意', null, null, null, @t1),
|
||
(newid(), @inst, @runDm, null, 'cancel', null, 'pending', 'cancelled', N'同节点其余待办已自动取消(1 条)', null, null, null, dateadd(second, 1, @t1)),
|
||
(newid(), @inst, @runGm, null, 'reject', 'g3soft', 'pending', 'rejected', N'费用超出季度预算,请拆分后重新提交', N'{"rejectMode":"terminate"}', null, null, @t2),
|
||
(newid(), @inst, null, null, 'reject', null, 'running', 'rejected', N'已驳回', null, null, null, dateadd(second, 1, @t2));
|
||
GO
|
||
|
||
/* ============================================================================
|
||
8. 实例 F:已退回 · 部门负责人退回发起人
|
||
|
||
模拟-费用报销-006 发起人 g3soft 金额 2,800 三天前送审,一小时后退回
|
||
部门负责人(张伟)执行退回(return_initiator),实例直接结束。
|
||
节点运行的 b_rejected_count = 1 与真实实现一致(退回同样计入驳回计数)。
|
||
============================================================================ */
|
||
|
||
declare @now datetime2 = sysutcdatetime();
|
||
declare @inst uniqueidentifier = newid();
|
||
declare @runStart uniqueidentifier = newid();
|
||
declare @runDm uniqueidentifier = newid();
|
||
declare @t0 datetime2 = dateadd(day, -3, @now);
|
||
declare @t1 datetime2 = dateadd(hour, 1, @t0);
|
||
declare @snapDm nvarchar(max) = N'{"rules":[{"b_actor_type":"dept_manager","b_actor_ref":null,"b_priority":10},{"b_actor_type":"position","b_actor_ref":"vice_president","b_priority":20}],"resolvedUsers":["demo_zhangwei","demo_liqiang"],"notes":[]}';
|
||
|
||
insert into dbo.wf_instance (b_id, b_definition_id, b_version_id, b_binding_id, b_module_id, b_event,
|
||
b_business_id, b_business_no, b_org_id, b_initiator_id, b_initiator_dept_id, b_status,
|
||
b_context_json, b_snapshot_json, b_current_summary_json, b_row_version,
|
||
b_idempotency_key, b_started_at, b_completed_at,
|
||
b_created_by, b_created_at, b_updated_by, b_updated_at)
|
||
values (@inst, 'expense_approval', 'expense_approval_v1', 'demo_expense_binding', 'v_b_othercompany', 'submit',
|
||
'MOCK-EXP-006', N'模拟-费用报销-006', 'G3HD', 'g3soft', 'demo_dept', 'returned',
|
||
N'{"b_amount":2800,"b_dept_id":"demo_dept","b_initiator_dept_id":"demo_dept"}',
|
||
N'{"b_business_no":"模拟-费用报销-006","b_amount":2800,"b_reason":"市内交通费","b_dept_id":"demo_dept"}',
|
||
N'{"summary":"已退回","node":"部门负责人审批"}', 2,
|
||
null, @t0, dateadd(second, 2, @t1),
|
||
'g3soft', @t0, 'g3soft', dateadd(second, 2, @t1));
|
||
|
||
insert into dbo.wf_node_run (b_id, b_instance_id, b_node_key, b_run_no, b_status, b_required_count,
|
||
b_completed_count, b_rejected_count, b_entered_at, b_exited_at,
|
||
b_actor_snapshot_json, b_created_at)
|
||
values (@runStart, @inst, 'start', 1, 'completed', null, 0, 0, @t0, @t0, null, @t0),
|
||
(@runDm, @inst, 'dept_manager', 1, 'completed', 1, 0, 1, @t0, @t1, @snapDm, @t0);
|
||
|
||
insert into dbo.wf_task (b_id, b_instance_id, b_node_run_id, b_node_key, b_actor_rule_id, b_assignee_type,
|
||
b_assignee_id, b_seq, b_status, b_due_at, b_claimed_by, b_claimed_at,
|
||
b_completed_by, b_completed_at, b_rule_snapshot_json, b_created_at, b_updated_at)
|
||
values (newid(), @inst, @runDm, 'dept_manager', null, 'user', 'demo_zhangwei', 10, 'cancelled',
|
||
dateadd(hour, 24, @t0), null, null, 'demo_zhangwei', @t1, @snapDm, @t0, @t1),
|
||
(newid(), @inst, @runDm, 'dept_manager', null, 'user', 'demo_liqiang', 20, 'cancelled',
|
||
dateadd(hour, 24, @t0), null, null, null, null, @snapDm, @t0, @t1);
|
||
|
||
insert into dbo.wf_action (b_id, b_instance_id, b_node_run_id, b_task_id, b_action, b_operator_id,
|
||
b_from_status, b_to_status, b_comment, b_payload_json, b_request_id, b_trace_id,
|
||
b_occurdatetime)
|
||
values (newid(), @inst, null, null, 'submit', 'g3soft', null, 'running', N'提交审批', null, null, null, @t0),
|
||
(newid(), @inst, @runDm, null, 'return', 'demo_zhangwei', 'pending', 'returned', N'发票信息不全,请补充后重新提交', null, null, null, @t1),
|
||
(newid(), @inst, @runDm, null, 'cancel', null, 'pending', 'cancelled', N'同节点其余待办已自动取消(1 条)', null, null, null, dateadd(second, 1, @t1)),
|
||
(newid(), @inst, null, null, 'reject', null, 'running', 'returned', N'已退回', null, null, null, dateadd(second, 2, @t1));
|
||
GO
|
||
|
||
/* ============================================================================
|
||
9. 自检
|
||
============================================================================ */
|
||
|
||
select N'实例' as 项, count(1) as 行数 from dbo.wf_instance where b_business_no like N'模拟-%'
|
||
union all
|
||
select N' 运行中', count(1) from dbo.wf_instance where b_business_no like N'模拟-%' and b_status = 'running'
|
||
union all
|
||
select N'节点运行', count(1) from dbo.wf_node_run
|
||
where b_instance_id in (select b_id from dbo.wf_instance where b_business_no like N'模拟-%')
|
||
union all
|
||
select N'任务', count(1) from dbo.wf_task
|
||
where b_instance_id in (select b_id from dbo.wf_instance where b_business_no like N'模拟-%')
|
||
union all
|
||
select N' 待办(g3soft)', count(1) from dbo.wf_task
|
||
where b_assignee_id = 'g3soft' and b_status in ('pending', 'claimed')
|
||
and b_instance_id in (select b_id from dbo.wf_instance where b_business_no like N'模拟-%')
|
||
union all
|
||
select N'动作流水', count(1) from dbo.wf_action
|
||
where b_instance_id in (select b_id from dbo.wf_instance where b_business_no like N'模拟-%')
|
||
union all
|
||
select N'抄送', count(1) from dbo.wf_cc
|
||
where b_instance_id in (select b_id from dbo.wf_instance where b_business_no like N'模拟-%')
|
||
union all
|
||
select N'演示用户', count(1) from dbo.b_user where b_id like 'demo\_%' escape '\'
|
||
union all
|
||
select N'演示部门', count(1) from dbo.b_dept where b_id = 'demo_dept'
|
||
union all
|
||
select N'演示绑定(停用)', count(1) from dbo.wf_binding where b_id = 'demo_expense_binding' and b_canuse = 0;
|
||
GO
|
||
|
||
/* ============================================================================
|
||
10. 清理(需要时手动执行)
|
||
|
||
删除本脚本造出的运行数据(按业务单号前缀识别):
|
||
|
||
declare @old table (b_id uniqueidentifier primary key);
|
||
insert into @old (b_id) select b_id from dbo.wf_instance where b_business_no like N'模拟-%';
|
||
delete from dbo.wf_action where b_instance_id in (select b_id from @old);
|
||
delete from dbo.wf_cc where b_instance_id in (select b_id from @old);
|
||
delete from dbo.wf_task where b_instance_id in (select b_id from @old);
|
||
delete from dbo.wf_node_run where b_instance_id in (select b_id from @old);
|
||
delete from dbo.wf_instance where b_id in (select b_id from @old);
|
||
|
||
删除演示组织数据(确认这些用户 / 岗位 / 角色没有别的用途后再执行):
|
||
|
||
delete from dbo.s_user_power where b_user_id like 'demo\_%' escape '\';
|
||
delete from dbo.b_user_position where b_user_id like 'demo\_%' escape '\';
|
||
delete from dbo.b_user_org_role where b_user_id like 'demo\_%' escape '\';
|
||
delete from dbo.b_user where b_id like 'demo\_%' escape '\';
|
||
delete from dbo.b_dept where b_id = 'demo_dept';
|
||
delete from dbo.b_user_position where b_position_id in ('gm', 'vice_president', 'finance_manager', 'legal_staff', 'risk_manager');
|
||
delete from dbo.b_user_org_role where b_role_id in ('finance', 'legal_lead', 'cfo', 'risk');
|
||
delete from dbo.b_position where b_id in ('gm', 'vice_president', 'finance_manager', 'legal_staff', 'risk_manager');
|
||
delete from dbo.b_org_role where b_id in ('finance', 'legal_lead', 'cfo', 'risk');
|
||
delete from dbo.wf_binding where b_id = 'demo_expense_binding';
|
||
|
||
删除演示绑定与规则补丁(把 U001 / U002 / U003 还原为 mock 脚本的占位值):
|
||
|
||
update dbo.wf_actor_rule set b_actor_ref = 'U001' where b_version_id = 'expense_approval_v1' and b_actor_ref = 'g3soft' and b_actor_type = 'user';
|
||
update dbo.wf_actor_rule set b_actor_ref = 'U002' where b_version_id = 'expense_approval_v1' and b_actor_ref = 'demo_zhangwei' and b_actor_type = 'user';
|
||
update dbo.wf_actor_rule set b_actor_ref = 'U003' where b_version_id = 'expense_approval_v1' and b_actor_ref = 'demo_liqiang' and b_actor_type = 'user';
|
||
|
||
注:g3soft 岗位(b_user_position 的 gm 行)在清理演示用户时会一并删除;
|
||
如需保留请自行调整上面语句。
|
||
============================================================================ */
|