diff --git a/internal/dms/service/data_export_workflow.go b/internal/dms/service/data_export_workflow.go index 4a8712cd..cee84b2d 100644 --- a/internal/dms/service/data_export_workflow.go +++ b/internal/dms/service/data_export_workflow.go @@ -146,9 +146,8 @@ func (d *DMSService) ListDataExportWorkflow(ctx context.Context, req *dmsV1.List if len(creater) > 0 { ret[i].Creater = creater[0] } - // 结束时不显示当前步骤操作人,其他状态显示当前步骤操作人 - if w.Status != string(dmsV1.StatusFinish) { - ret[i].CurrentStepAssigneeUsers = convertBizUidWithName(d.UserUsecase.GetBizUserIncludeDeletedWithNameByUids(ctx, w.WorkflowRecord.WorkflowSteps[w.WorkflowRecord.CurrentWorkflowStepId-1].Assignees)) + if uids := currentStepAssigneeUIDsForList(w); len(uids) > 0 { + ret[i].CurrentStepAssigneeUsers = convertBizUidWithName(d.UserUsecase.GetBizUserIncludeDeletedWithNameByUids(ctx, uids)) } } @@ -191,9 +190,8 @@ func (d *DMSService) GetGlobalWorkflowsList(ctx context.Context, req *dmsV1.Filt if len(creater) > 0 { ret[i].Creater = creater[0] } - // 结束时不显示当前步骤操作人,其他状态显示当前步骤操作人 - if w.Status != string(dmsV1.StatusFinish) { - ret[i].CurrentStepAssigneeUsers = convertBizUidWithName(d.UserUsecase.GetBizUserIncludeDeletedWithNameByUids(ctx, w.WorkflowRecord.WorkflowSteps[w.WorkflowRecord.CurrentWorkflowStepId-1].Assignees)) + if uids := currentStepAssigneeUIDsForList(w); len(uids) > 0 { + ret[i].CurrentStepAssigneeUsers = convertBizUidWithName(d.UserUsecase.GetBizUserIncludeDeletedWithNameByUids(ctx, uids)) } } @@ -376,3 +374,27 @@ 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) } + +func currentStepAssigneeUIDsForList(w *biz.Workflow) []string { + if w == nil || w.WorkflowRecord == nil { + return nil + } + switch w.WorkflowRecord.Status { + case biz.DataExportWorkflowStatusFinish, biz.DataExportWorkflowStatusCancel: + return nil + case biz.DataExportWorkflowStatusWaitForExport, biz.DataExportWorkflowStatusRejected, biz.DataExportWorkflowStatusFailed: + if w.CreateUserUID == "" { + return nil + } + return []string{w.CreateUserUID} + default: + if w.WorkflowRecord.CurrentWorkflowStepId == 0 { + return nil + } + idx := w.WorkflowRecord.CurrentWorkflowStepId - 1 + if int(idx) >= len(w.WorkflowRecord.WorkflowSteps) { + return nil + } + return w.WorkflowRecord.WorkflowSteps[idx].Assignees + } +} diff --git a/internal/dms/storage/workflow.go b/internal/dms/storage/workflow.go index aa96437e..c3bf0999 100644 --- a/internal/dms/storage/workflow.go +++ b/internal/dms/storage/workflow.go @@ -384,7 +384,11 @@ SELECT w.create_user_uid, CAST("" AS DATETIME) AS create_user_deleted_at, w.created_at AS create_time, - IF(wr.status = 'rejected', JSON_ARRAY(w.create_user_uid), curr_ws.assignees) AS current_step_assignee_user_id_list, + CASE + WHEN wr.status IN ('finish', 'cancel') THEN JSON_ARRAY() + WHEN wr.status IN ('rejected', 'wait_for_export', 'failed') THEN JSON_ARRAY(w.create_user_uid) + ELSE curr_ws.assignees + END AS current_step_assignee_user_id_list, curr_ws.state AS current_step_state, wr.status, wr.current_workflow_step_id AS current_workflow_step_id, @@ -441,7 +445,7 @@ AND wr.status IN (:filter_status) {{- end }} {{- if .filter_current_step_assignee_user_id }} -AND ((wr.status != 'rejected' AND curr_ws.assignees REGEXP :filter_current_step_assignee_user_id) OR (wr.status = 'rejected' AND w.create_user_uid = :filter_current_step_assignee_user_id)) +AND ((wr.status NOT IN ('rejected', 'wait_for_export', 'failed') AND curr_ws.assignees REGEXP :filter_current_step_assignee_user_id) OR (wr.status IN ('rejected', 'wait_for_export', 'failed') AND w.create_user_uid = :filter_current_step_assignee_user_id)) {{- end }} {{- if .filter_db_service_uid }}