@@ -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+
288307func (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