From 8ed810d5b15a22725ac3d7e8a1df087cca40c44a Mon Sep 17 00:00:00 2001 From: WinfredLIN Date: Wed, 8 Apr 2026 10:41:57 +0000 Subject: [PATCH] modify: set assignee to creator when export workflow is rejected --- internal/dms/service/data_export_workflow.go | 7 +++-- internal/dms/storage/model/model.go | 13 ++++++++- internal/dms/storage/workflow.go | 30 ++++++++++++++++---- 3 files changed, 40 insertions(+), 10 deletions(-) diff --git a/internal/dms/service/data_export_workflow.go b/internal/dms/service/data_export_workflow.go index 78dfba7f..4a8712cd 100644 --- a/internal/dms/service/data_export_workflow.go +++ b/internal/dms/service/data_export_workflow.go @@ -146,10 +146,10 @@ func (d *DMSService) ListDataExportWorkflow(ctx context.Context, req *dmsV1.List if len(creater) > 0 { ret[i].Creater = creater[0] } - if w.WorkflowRecord.WorkflowSteps[w.WorkflowRecord.CurrentWorkflowStepId-1].State == "init" { + // 结束时不显示当前步骤操作人,其他状态显示当前步骤操作人 + if w.Status != string(dmsV1.StatusFinish) { ret[i].CurrentStepAssigneeUsers = convertBizUidWithName(d.UserUsecase.GetBizUserIncludeDeletedWithNameByUids(ctx, w.WorkflowRecord.WorkflowSteps[w.WorkflowRecord.CurrentWorkflowStepId-1].Assignees)) } - } return &dmsV1.ListDataExportWorkflowsReply{ @@ -191,7 +191,8 @@ func (d *DMSService) GetGlobalWorkflowsList(ctx context.Context, req *dmsV1.Filt if len(creater) > 0 { ret[i].Creater = creater[0] } - if w.WorkflowRecord.WorkflowSteps[w.WorkflowRecord.CurrentWorkflowStepId-1].State == "init" { + // 结束时不显示当前步骤操作人,其他状态显示当前步骤操作人 + if w.Status != string(dmsV1.StatusFinish) { ret[i].CurrentStepAssigneeUsers = convertBizUidWithName(d.UserUsecase.GetBizUserIncludeDeletedWithNameByUids(ctx, w.WorkflowRecord.WorkflowSteps[w.WorkflowRecord.CurrentWorkflowStepId-1].Assignees)) } } diff --git a/internal/dms/storage/model/model.go b/internal/dms/storage/model/model.go index d1d9dded..082d5a7a 100644 --- a/internal/dms/storage/model/model.go +++ b/internal/dms/storage/model/model.go @@ -502,7 +502,18 @@ type WorkflowRecord struct { type Strings []string func (t *Strings) Scan(value interface{}) error { - bytesValue, _ := value.([]byte) + if value == nil { + return nil + } + var bytesValue []byte + switch v := value.(type) { + case []byte: + bytesValue = v + case string: + bytesValue = []byte(v) + default: + return fmt.Errorf("failed to scan Strings: expected []byte or string, got %T", value) + } return json.Unmarshal(bytesValue, t) } diff --git a/internal/dms/storage/workflow.go b/internal/dms/storage/workflow.go index 6d7392ff..aa96437e 100644 --- a/internal/dms/storage/workflow.go +++ b/internal/dms/storage/workflow.go @@ -384,7 +384,7 @@ SELECT w.create_user_uid, CAST("" AS DATETIME) AS create_user_deleted_at, w.created_at AS create_time, - curr_ws.assignees AS current_step_assignee_user_id_list, + IF(wr.status = 'rejected', JSON_ARRAY(w.create_user_uid), curr_ws.assignees) 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, @@ -413,7 +413,8 @@ w.workflow_type='data_export' {{- if .check_user_can_access }} AND ( w.create_user_uid = :current_user_id -OR curr_ws.assignees REGEXP :current_user_id +OR (wr.status != 'rejected' AND curr_ws.assignees REGEXP :current_user_id) +OR (wr.status = 'rejected' AND w.create_user_uid = :current_user_id) {{- if .viewable_db_service_uids }} @@ -440,7 +441,7 @@ AND wr.status IN (:filter_status) {{- end }} {{- if .filter_current_step_assignee_user_id }} -AND curr_ws.assignees REGEXP :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)) {{- end }} {{- if .filter_db_service_uid }} @@ -573,10 +574,27 @@ func (d *WorkflowRepo) GetGlobalWorkflowsByParameterMap(ctx context.Context, dat } // Set the current step data - if result.CurrentWorkflowStepId > 0 { - currentStepIndex := result.CurrentWorkflowStepId - 1 + if result.CurrentWorkflowStepId > 0 || result.Status == "rejected" { + currentStepIndex := int64(result.CurrentWorkflowStepId) - 1 + if currentStepIndex < 0 { + currentStepIndex = 0 + } + // Ensure WorkflowSteps has enough capacity + if len(workflow.WorkflowRecord.WorkflowSteps) <= int(currentStepIndex) { + newSteps := make([]*biz.WorkflowStep, currentStepIndex+1) + copy(newSteps, workflow.WorkflowRecord.WorkflowSteps) + for i := len(workflow.WorkflowRecord.WorkflowSteps); i <= int(currentStepIndex); i++ { + newSteps[i] = &biz.WorkflowStep{ + StepId: uint64(i + 1), + WorkflowRecordUid: result.WorkflowRecordUID, + Assignees: []string{}, + } + } + workflow.WorkflowRecord.WorkflowSteps = newSteps + } + workflow.WorkflowRecord.WorkflowSteps[currentStepIndex] = &biz.WorkflowStep{ - StepId: result.CurrentWorkflowStepId, + StepId: uint64(currentStepIndex + 1), WorkflowRecordUid: result.WorkflowRecordUID, State: result.CurrentStepState, Assignees: result.CurrentStepAssigneeUserIDList,