47 lines
1.5 KiB
Go
47 lines
1.5 KiB
Go
package flow_definition
|
|
|
|
import (
|
|
"approveflow/app/http/base"
|
|
"approveflow/app/provider/flow_definition"
|
|
"approveflow/app/utils"
|
|
"github.com/Superdanda/hade/framework/gin"
|
|
"net/http"
|
|
)
|
|
|
|
type StepAddParam struct {
|
|
FlowID int64 `json:"flow_id"`
|
|
ToStepKey string `json:"to_step_key"`
|
|
FromStepKey string `json:"from_step_key"`
|
|
StepCode string `json:"step_code"`
|
|
}
|
|
|
|
// StepAdd 添加步骤
|
|
// @Summary 添加步骤到流程
|
|
// @Description 根据传入的参数,添加步骤到指定的流程中
|
|
// @ID flow-definition-step-add
|
|
// @Tags flow-definition
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param stepAddParam body StepAddParam true "添加步骤请求参数"
|
|
// @Success 200 {object} base.Result "操作成功"
|
|
// @Failure 400 {object} base.Result "参数错误"
|
|
// @Failure 500 {object} base.Result "操作失败"
|
|
// @Router /definition/step/add [post]
|
|
func (a *FlowDefinitionApi) StepAdd(context *gin.Context) {
|
|
param := utils.QuickBind[StepAddParam](context)
|
|
definitionService := context.MustMake(flow_definition.FlowDefinitionKey).(flow_definition.Service)
|
|
step := flow_definition.NewApprovalStepByType(param.StepCode)
|
|
|
|
if step == nil {
|
|
context.ISetStatus(http.StatusInternalServerError).IJson(base.Fail("添加步骤不能为空"))
|
|
return
|
|
}
|
|
|
|
err := definitionService.AddStepWithPosition(context, param.FlowID, step, param.FromStepKey, param.ToStepKey)
|
|
if err != nil {
|
|
context.ISetStatus(http.StatusInternalServerError).IJson(base.Fail(err.Error()))
|
|
return
|
|
}
|
|
context.ISetOkStatus().IJson(base.SuccessWithOKMessage())
|
|
}
|