Skip to content

Commit

Permalink
refactor:support workflow execution
Browse files Browse the repository at this point in the history
  • Loading branch information
taolx0 committed Sep 7, 2023
1 parent a17ae10 commit d9f19e3
Showing 1 changed file with 10 additions and 23 deletions.
33 changes: 10 additions & 23 deletions sqle/api/controller/v2/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func ApproveWorkflowV2(c echo.Context) error {

nextStep := workflow.NextStep()

err = v1.CheckUserCanOperateStep(user, workflow, stepId)
err = server.CheckUserCanOperateStep(user, workflow, stepId)
if err != nil {
return controller.JSONBaseErrorReq(c, errors.New(errors.DataInvalid, err))
}
Expand All @@ -108,9 +108,9 @@ func ApproveWorkflowV2(c echo.Context) error {
return controller.JSONBaseErrorReq(c, err)
}

go im.UpdateApprove(workflow.ID, user.Phone, model.ApproveStatusAgree, "")
go im.UpdateApprove(workflow.ID, user, model.ApproveStatusAgree, "")

if nextStep.Template.Typ != model.WorkflowStepTypeSQLExecute {
if nextStep != nil {
go im.CreateApprove(strconv.Itoa(int(workflow.ID)))
}

Expand Down Expand Up @@ -184,7 +184,7 @@ func RejectWorkflowV2(c echo.Context) error {
return controller.JSONBaseErrorReq(c, v1.ErrWorkflowNoAccess)
}

err = v1.CheckUserCanOperateStep(user, workflow, stepId)
err = server.CheckUserCanOperateStep(user, workflow, stepId)
if err != nil {
return controller.JSONBaseErrorReq(c, errors.New(errors.DataInvalid, err))
}
Expand All @@ -202,7 +202,7 @@ func RejectWorkflowV2(c echo.Context) error {
return controller.JSONBaseErrorReq(c, err)
}

go im.UpdateApprove(workflow.ID, user.Phone, model.ApproveStatusRefuse, req.Reason)
go im.UpdateApprove(workflow.ID, user, model.ApproveStatusRefuse, req.Reason)

return c.JSON(http.StatusOK, controller.NewBaseReq(nil))
}
Expand Down Expand Up @@ -985,7 +985,7 @@ func UpdateWorkflowScheduleV2(c echo.Context) error {
fmt.Errorf("workflow need to be approved first")))
}

err = v1.CheckUserCanOperateStep(user, workflow, int(currentStep.ID))
err = server.CheckUserCanOperateStep(user, workflow, int(currentStep.ID))
if err != nil {
return controller.JSONBaseErrorReq(c, errors.New(errors.DataInvalid, err))
}
Expand Down Expand Up @@ -1052,33 +1052,20 @@ func ExecuteTasksOnWorkflowV2(c echo.Context) error {
return controller.JSONBaseErrorReq(c, v1.ErrWorkflowNoAccess)
}

workflowId = fmt.Sprintf("%v", workflow.ID)

workflow, exist, err = s.GetWorkflowDetailById(workflowId)
if err != nil {
return controller.JSONBaseErrorReq(c, err)
}
if !exist {
return controller.JSONBaseErrorReq(c, v1.ErrWorkflowNoAccess)
}
user, err := controller.GetCurrentUser(c)
if err != nil {
return controller.JSONBaseErrorReq(c, err)
}
if err := v1.PrepareForWorkflowExecution(c, projectName, workflow, user); err != nil {
return err
}

needExecTaskIds, err := v1.GetNeedExecTaskIds(s, workflow, user)
if err != nil {
return err
}
workflowId = fmt.Sprintf("%v", workflow.ID)

err = server.ExecuteWorkflow(workflow, needExecTaskIds)
err = server.ExecuteTasksProcess(workflowId, projectName, user)
if err != nil {
return controller.JSONBaseErrorReq(c, err)
}

im.UpdateApprove(workflow.ID, user, model.ApproveStatusAgree, "")

return c.JSON(http.StatusOK, controller.NewBaseReq(nil))
}

Expand Down

0 comments on commit d9f19e3

Please sign in to comment.