From 5133b20ccacc76c79382888e24828a6b2c185c39 Mon Sep 17 00:00:00 2001 From: shihongwei <178899525@qq.com> Date: Sat, 6 Jun 2026 16:45:12 +0800 Subject: [PATCH] =?UTF-8?q?docs:=20=E6=96=87=E6=A1=A3=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/待办移动到历史表.md | 63 ++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 docs/待办移动到历史表.md diff --git a/docs/待办移动到历史表.md b/docs/待办移动到历史表.md new file mode 100644 index 0000000..b449217 --- /dev/null +++ b/docs/待办移动到历史表.md @@ -0,0 +1,63 @@ +```sql + +-- 传入你的 taskId +set @taskId = 'f5e730e3bfaf57ce00af7c0f7228958a'; + +start transaction; + +-- 1. 归档到历史表 +insert into sys_flow_task_his (his_id, + task_id, + instance_id, + node_code, + node_name, + approver_id, + status, + comment, + audit_time, + company_id, + is_read, + create_by, + create_time, + update_by, + update_time) +select replace(uuid(), '-', '') as his_id, + t.task_id, + t.instance_id, + t.node_code, + t.node_name, + t.approver_id, + case + when i.status = 1 then 1 + when i.status in (2, 9) then 2 + else 2 + end as status, + '手工归档待办' as comment, + coalesce(i.finish_time, t.update_time, now()) as audit_time, + t.company_id, + t.is_read, + t.create_by, + t.create_time, + t.update_by, + t.update_time +from sys_flow_task t + left join sys_flow_instance i + on i.instance_id = t.instance_id +where t.task_id = @taskId + and not exists (select 1 + from sys_flow_task_his th + where th.task_id = t.task_id + and th.instance_id = t.instance_id); + +-- 2. 删除当前待办 +delete +from sys_flow_task +where task_id = @taskId + and exists (select 1 + from sys_flow_task_his th + where th.task_id = @taskId + and th.instance_id = sys_flow_task.instance_id); + +commit; + +```