Skip to content

Commit a055461

Browse files
committed
feat: support multi-level approval flow for data export workflow (CE)
1 parent 1fcedc6 commit a055461

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

internal/dms/biz/data_export_workflow.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ type WorkflowRepo interface {
108108
GetDataExportWorkflowsByIds(ctx context.Context, dataExportWorkflowUid []string) ([]*Workflow, error)
109109
CancelWorkflow(ctx context.Context, workflowRecordIds []string, workflowSteps []*WorkflowStep, operateId string) error
110110
AuditWorkflow(ctx context.Context, dataExportWorkflowUid string, status DataExportWorkflowStatus, step *WorkflowStep, operateId, reason string) error
111+
AdvanceWorkflowStep(ctx context.Context, dataExportWorkflowUid string, currentStep *WorkflowStep, nextStepId uint64, operateId string) error
111112
GetDataExportWorkflowsForView(ctx context.Context, userUid string) ([]string, error)
112113
GetProjectDataExportWorkflowsForView(ctx context.Context, projectUid string) ([]string, error)
113114
GetDataExportWorkflowsByStatus(ctx context.Context, status string) ([]string, error)

internal/dms/storage/workflow.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,25 @@ func (d *WorkflowRepo) AuditWorkflow(ctx context.Context, dataExportWorkflowUid
285285
})
286286
}
287287

288+
// AdvanceWorkflowStep 推进工单审批到下一步骤:标记当前步骤为 approved 并更新 CurrentWorkflowStepId,工单状态保持 wait_for_approve
289+
func (d *WorkflowRepo) AdvanceWorkflowStep(ctx context.Context, dataExportWorkflowUid string, currentStep *biz.WorkflowStep, nextStepId uint64, operateId string) error {
290+
return transaction(d.log, ctx, d.db, func(tx *gorm.DB) error {
291+
// 更新当前步骤状态为 approved
292+
operateTime := time.Now()
293+
stepFields := map[string]interface{}{"operation_user_uid": operateId, "operate_at": operateTime, "state": currentStep.State}
294+
if err := tx.WithContext(ctx).Model(&model.WorkflowStep{}).Where("step_id = ? and workflow_record_uid = ?", currentStep.StepId, currentStep.WorkflowRecordUid).Updates(stepFields).Error; err != nil {
295+
return fmt.Errorf("failed to update current workflow step, err: %v", err)
296+
}
297+
298+
// 推进 CurrentWorkflowStepId 到下一步
299+
if err := tx.WithContext(ctx).Model(&model.WorkflowRecord{}).Where("uid = ?", dataExportWorkflowUid).Update("current_workflow_step_id", nextStepId).Error; err != nil {
300+
return fmt.Errorf("failed to advance workflow step, err: %v", err)
301+
}
302+
303+
return nil
304+
})
305+
}
306+
288307
func (d *WorkflowRepo) UpdateWorkflowStatusById(ctx context.Context, dataExportWorkflowUid string, status biz.DataExportWorkflowStatus) error {
289308
return transaction(d.log, ctx, d.db, func(tx *gorm.DB) error {
290309
if err := tx.WithContext(ctx).Model(&model.WorkflowRecord{}).Where("uid = ?", dataExportWorkflowUid).Update("status", status).Error; err != nil {

0 commit comments

Comments
 (0)