Skip to content

Commit 3e96b9e

Browse files
authored
Merge pull request #592 from actiontech/commit/dashboard-v2
modify: set assignee to creator when export workflow is rejected
2 parents f5265e6 + 8ed810d commit 3e96b9e

File tree

3 files changed

+40
-10
lines changed

3 files changed

+40
-10
lines changed

internal/dms/service/data_export_workflow.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,10 @@ func (d *DMSService) ListDataExportWorkflow(ctx context.Context, req *dmsV1.List
146146
if len(creater) > 0 {
147147
ret[i].Creater = creater[0]
148148
}
149-
if w.WorkflowRecord.WorkflowSteps[w.WorkflowRecord.CurrentWorkflowStepId-1].State == "init" {
149+
// 结束时不显示当前步骤操作人,其他状态显示当前步骤操作人
150+
if w.Status != string(dmsV1.StatusFinish) {
150151
ret[i].CurrentStepAssigneeUsers = convertBizUidWithName(d.UserUsecase.GetBizUserIncludeDeletedWithNameByUids(ctx, w.WorkflowRecord.WorkflowSteps[w.WorkflowRecord.CurrentWorkflowStepId-1].Assignees))
151152
}
152-
153153
}
154154

155155
return &dmsV1.ListDataExportWorkflowsReply{
@@ -191,7 +191,8 @@ func (d *DMSService) GetGlobalWorkflowsList(ctx context.Context, req *dmsV1.Filt
191191
if len(creater) > 0 {
192192
ret[i].Creater = creater[0]
193193
}
194-
if w.WorkflowRecord.WorkflowSteps[w.WorkflowRecord.CurrentWorkflowStepId-1].State == "init" {
194+
// 结束时不显示当前步骤操作人,其他状态显示当前步骤操作人
195+
if w.Status != string(dmsV1.StatusFinish) {
195196
ret[i].CurrentStepAssigneeUsers = convertBizUidWithName(d.UserUsecase.GetBizUserIncludeDeletedWithNameByUids(ctx, w.WorkflowRecord.WorkflowSteps[w.WorkflowRecord.CurrentWorkflowStepId-1].Assignees))
196197
}
197198
}

internal/dms/storage/model/model.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,18 @@ type WorkflowRecord struct {
502502
type Strings []string
503503

504504
func (t *Strings) Scan(value interface{}) error {
505-
bytesValue, _ := value.([]byte)
505+
if value == nil {
506+
return nil
507+
}
508+
var bytesValue []byte
509+
switch v := value.(type) {
510+
case []byte:
511+
bytesValue = v
512+
case string:
513+
bytesValue = []byte(v)
514+
default:
515+
return fmt.Errorf("failed to scan Strings: expected []byte or string, got %T", value)
516+
}
506517
return json.Unmarshal(bytesValue, t)
507518
}
508519

internal/dms/storage/workflow.go

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ SELECT
384384
w.create_user_uid,
385385
CAST("" AS DATETIME) AS create_user_deleted_at,
386386
w.created_at AS create_time,
387-
curr_ws.assignees AS current_step_assignee_user_id_list,
387+
IF(wr.status = 'rejected', JSON_ARRAY(w.create_user_uid), curr_ws.assignees) AS current_step_assignee_user_id_list,
388388
curr_ws.state AS current_step_state,
389389
wr.status,
390390
wr.current_workflow_step_id AS current_workflow_step_id,
@@ -413,7 +413,8 @@ w.workflow_type='data_export'
413413
{{- if .check_user_can_access }}
414414
AND (
415415
w.create_user_uid = :current_user_id
416-
OR curr_ws.assignees REGEXP :current_user_id
416+
OR (wr.status != 'rejected' AND curr_ws.assignees REGEXP :current_user_id)
417+
OR (wr.status = 'rejected' AND w.create_user_uid = :current_user_id)
417418
418419
419420
{{- if .viewable_db_service_uids }}
@@ -440,7 +441,7 @@ AND wr.status IN (:filter_status)
440441
{{- end }}
441442
442443
{{- if .filter_current_step_assignee_user_id }}
443-
AND curr_ws.assignees REGEXP :filter_current_step_assignee_user_id
444+
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))
444445
{{- end }}
445446
446447
{{- if .filter_db_service_uid }}
@@ -573,10 +574,27 @@ func (d *WorkflowRepo) GetGlobalWorkflowsByParameterMap(ctx context.Context, dat
573574
}
574575

575576
// Set the current step data
576-
if result.CurrentWorkflowStepId > 0 {
577-
currentStepIndex := result.CurrentWorkflowStepId - 1
577+
if result.CurrentWorkflowStepId > 0 || result.Status == "rejected" {
578+
currentStepIndex := int64(result.CurrentWorkflowStepId) - 1
579+
if currentStepIndex < 0 {
580+
currentStepIndex = 0
581+
}
582+
// Ensure WorkflowSteps has enough capacity
583+
if len(workflow.WorkflowRecord.WorkflowSteps) <= int(currentStepIndex) {
584+
newSteps := make([]*biz.WorkflowStep, currentStepIndex+1)
585+
copy(newSteps, workflow.WorkflowRecord.WorkflowSteps)
586+
for i := len(workflow.WorkflowRecord.WorkflowSteps); i <= int(currentStepIndex); i++ {
587+
newSteps[i] = &biz.WorkflowStep{
588+
StepId: uint64(i + 1),
589+
WorkflowRecordUid: result.WorkflowRecordUID,
590+
Assignees: []string{},
591+
}
592+
}
593+
workflow.WorkflowRecord.WorkflowSteps = newSteps
594+
}
595+
578596
workflow.WorkflowRecord.WorkflowSteps[currentStepIndex] = &biz.WorkflowStep{
579-
StepId: result.CurrentWorkflowStepId,
597+
StepId: uint64(currentStepIndex + 1),
580598
WorkflowRecordUid: result.WorkflowRecordUID,
581599
State: result.CurrentStepState,
582600
Assignees: result.CurrentStepAssigneeUserIDList,

0 commit comments

Comments
 (0)