From 309abc42877c588fd50e26f616bc071f7e3e1165 Mon Sep 17 00:00:00 2001 From: iwanghc Date: Fri, 15 May 2026 16:08:56 +0800 Subject: [PATCH] fix(workflow): correct current step assignee logic and handle rejected status --- internal/dms/service/data_export_workflow.go | 47 +++++++++++++------- internal/dms/storage/workflow.go | 7 ++- 2 files changed, 37 insertions(+), 17 deletions(-) diff --git a/internal/dms/service/data_export_workflow.go b/internal/dms/service/data_export_workflow.go index e02b6a1e5..97248fec4 100644 --- a/internal/dms/service/data_export_workflow.go +++ b/internal/dms/service/data_export_workflow.go @@ -146,14 +146,7 @@ func (d *DMSService) ListDataExportWorkflow(ctx context.Context, req *dmsV1.List if len(creater) > 0 { ret[i].Creater = creater[0] } - // 结束时不显示当前步骤操作人,其他状态显示当前步骤操作人 - if w.Status == string(dmsV1.DataExportWorkflowStatusWaitForExport) || w.Status == string(dmsV1.DataExportWorkflowStatusWaitForExporting) { - // wait_for_export/wait_for_exporting 状态下,待操作人为工单创建者 - ret[i].CurrentStepAssigneeUsers = convertBizUidWithName(d.UserUsecase.GetBizUserIncludeDeletedWithNameByUids(ctx, []string{w.CreateUserUID})) - } else if w.Status != string(dmsV1.StatusFinish) && w.WorkflowRecord.CurrentWorkflowStepId > 0 && - int(w.WorkflowRecord.CurrentWorkflowStepId-1) < len(w.WorkflowRecord.WorkflowSteps) { - ret[i].CurrentStepAssigneeUsers = convertBizUidWithName(d.UserUsecase.GetBizUserIncludeDeletedWithNameByUids(ctx, w.WorkflowRecord.WorkflowSteps[w.WorkflowRecord.CurrentWorkflowStepId-1].Assignees)) - } + ret[i].CurrentStepAssigneeUsers = d.dataExportWorkflowCurrentStepAssigneeUsers(ctx, w) } return &dmsV1.ListDataExportWorkflowsReply{ @@ -195,14 +188,7 @@ func (d *DMSService) GetGlobalWorkflowsList(ctx context.Context, req *dmsV1.Filt if len(creater) > 0 { ret[i].Creater = creater[0] } - // 结束时不显示当前步骤操作人,其他状态显示当前步骤操作人 - if w.Status == string(dmsV1.DataExportWorkflowStatusWaitForExport) || w.Status == string(dmsV1.DataExportWorkflowStatusWaitForExporting) { - // wait_for_export/wait_for_exporting 状态下,待操作人为工单创建者 - ret[i].CurrentStepAssigneeUsers = convertBizUidWithName(d.UserUsecase.GetBizUserIncludeDeletedWithNameByUids(ctx, []string{w.CreateUserUID})) - } else if w.Status != string(dmsV1.StatusFinish) && w.WorkflowRecord.CurrentWorkflowStepId > 0 && - int(w.WorkflowRecord.CurrentWorkflowStepId-1) < len(w.WorkflowRecord.WorkflowSteps) { - ret[i].CurrentStepAssigneeUsers = convertBizUidWithName(d.UserUsecase.GetBizUserIncludeDeletedWithNameByUids(ctx, w.WorkflowRecord.WorkflowSteps[w.WorkflowRecord.CurrentWorkflowStepId-1].Assignees)) - } + ret[i].CurrentStepAssigneeUsers = d.dataExportWorkflowCurrentStepAssigneeUsers(ctx, w) } return &dmsV1.GetGlobalDataExportWorkflowsReply{ @@ -384,3 +370,32 @@ func (d *DMSService) DownloadDataExportTask(ctx context.Context, req *dmsV1.Down func (d *DMSService) DownloadDataExportTaskSQLs(ctx context.Context, req *dmsV1.DownloadDataExportTaskSQLsReq, userId string) (string, []byte, error) { return d.DataExportWorkflowUsecase.DownloadDataExportTaskSQLs(ctx, req, userId) } + +// dataExportWorkflowCurrentStepAssigneeUsers 返回工单待操作人;终态(完成/关闭/失败)不返回待操作人。 +func (d *DMSService) dataExportWorkflowCurrentStepAssigneeUsers(ctx context.Context, w *biz.Workflow) []dmsV1.UidWithName { + if isDataExportWorkflowTerminalStatus(w.Status) { + return nil + } + if w.Status == string(dmsV1.DataExportWorkflowStatusWaitForExport) || + w.Status == string(dmsV1.DataExportWorkflowStatusWaitForExporting) || + w.Status == string(dmsV1.DataExportWorkflowStatusRejected) { + // wait_for_export/wait_for_exporting/rejected 状态下,待操作人为工单创建者 + return convertBizUidWithName(d.UserUsecase.GetBizUserIncludeDeletedWithNameByUids(ctx, []string{w.CreateUserUID})) + } + if w.WorkflowRecord != nil && w.WorkflowRecord.CurrentWorkflowStepId > 0 && + int(w.WorkflowRecord.CurrentWorkflowStepId-1) < len(w.WorkflowRecord.WorkflowSteps) { + return convertBizUidWithName(d.UserUsecase.GetBizUserIncludeDeletedWithNameByUids(ctx, w.WorkflowRecord.WorkflowSteps[w.WorkflowRecord.CurrentWorkflowStepId-1].Assignees)) + } + return nil +} + +func isDataExportWorkflowTerminalStatus(status string) bool { + switch status { + case string(dmsV1.DataExportWorkflowStatusFinish), + string(dmsV1.DataExportWorkflowStatusCancel), + string(dmsV1.DataExportWorkflowStatusFailed): + return true + default: + return false + } +} diff --git a/internal/dms/storage/workflow.go b/internal/dms/storage/workflow.go index cd983a466..84405b06b 100644 --- a/internal/dms/storage/workflow.go +++ b/internal/dms/storage/workflow.go @@ -184,7 +184,12 @@ func (d *WorkflowRepo) GetDataExportWorkflowsByAssignUser(ctx context.Context, u LEFT JOIN workflow_steps ws on wr.uid = ws.workflow_record_uid and wr.current_workflow_step_id = ws.step_id left join data_export_tasks det on JSON_SEARCH(wr.task_ids ,'one',det.uid) IS NOT NULL WHERE JSON_SEARCH(ws.assignees,"one",?) IS NOT NULL AND ws.state = "init" - `, userUid).Find(&workflowUids).Error; err != nil { + UNION + SELECT DISTINCT w.uid + FROM workflows w + left join workflow_records wr on w.workflow_record_uid = wr.uid + WHERE wr.status = 'rejected' AND w.create_user_uid = ? + `, userUid, userUid).Find(&workflowUids).Error; err != nil { return fmt.Errorf("failed to find workflow by assignee user: %v", err) } return nil