From 36be34b1bbcedff2886512a8aa1de0c77b55638c Mon Sep 17 00:00:00 2001 From: "bai.zixv" Date: Fri, 5 Jul 2024 10:21:21 +0800 Subject: [PATCH] fix: approval, approvalExecution snapshot (#1274) Reviewed-on: https://git.daoyoucloud.com:8443/daoyoucloud/tachybase/pulls/1274 Co-authored-by: bai.zixv Co-committed-by: bai.zixv --- .../src/server/features/approval/ApprovalTrigger.ts | 10 +++++++++- .../src/server/features/approval/actions.ts | 9 ++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/packages/plugins/@tachybase/plugin-workflow/src/server/features/approval/ApprovalTrigger.ts b/packages/plugins/@tachybase/plugin-workflow/src/server/features/approval/ApprovalTrigger.ts index d7b1292a5..08c595130 100644 --- a/packages/plugins/@tachybase/plugin-workflow/src/server/features/approval/ApprovalTrigger.ts +++ b/packages/plugins/@tachybase/plugin-workflow/src/server/features/approval/ApprovalTrigger.ts @@ -73,12 +73,20 @@ export default class ApprovalTrigger extends Trigger { return; } const { approvalId, data, summary, collectionName } = execution.context; + + // NOTE: 因为这里的原本的 data, 在重新提交后再次重新提交, 丢失了审批人之类的多对多关系数据 + // 找不到上下文传递数据的来源在哪里, 因此在这里重新取数据.因为存储的是快照, 这样是有其合理性的. + const approval = await this.workflow.db.getRepository('approvals').findOne({ + filterByTk: approvalId, + transaction, + }); + const approvalExecution = await this.workflow.db.getRepository('approvalExecutions').create({ values: { approvalId, executionId: execution.id, status: execution.status, - snapshot: data, + snapshot: approval?.data || data, summary, collectionName, }, diff --git a/packages/plugins/@tachybase/plugin-workflow/src/server/features/approval/actions.ts b/packages/plugins/@tachybase/plugin-workflow/src/server/features/approval/actions.ts index 5d65b6069..18c12a12c 100644 --- a/packages/plugins/@tachybase/plugin-workflow/src/server/features/approval/actions.ts +++ b/packages/plugins/@tachybase/plugin-workflow/src/server/features/approval/actions.ts @@ -107,7 +107,7 @@ const approvals = { context.action.mergeParams({ values: { status: status ?? APPROVAL_STATUS.SUBMITTED, - data: target.toJSON(), + data: data, applicantRoleName: context.state.currentRole, summary, }, @@ -255,11 +255,10 @@ const approvals = { job.set('status', JOB_STATUS.CANCELED); workflowPlugin.resume(job); }); - } else { - await execution.update({ - status: EXECUTION_STATUS.CANCELED, - }); } + await execution.update({ + status: EXECUTION_STATUS.CANCELED, + }); }, async listCentralized(context, next) { const centralizedApprovalFlow = await context.db.getRepository('workflows').find({