approveflow/app/http/module/flow_instance/api_instances_create.go

57 lines
1.7 KiB
Go

package flow_instance
import (
"approveflow/app/base"
"approveflow/app/http/base/res"
"approveflow/app/provider/flow_definition"
"approveflow/app/provider/flow_instance"
"approveflow/app/utils"
"github.com/Superdanda/hade/framework/gin"
)
type InstancesCreateParam struct {
FlowID int64 `json:"flow_id"`
ApplicantKey string `json:"applicant_key"` //申请人ID
CreatorKey string `json:"creator_key"`
AssociateKey string `json:"associate_key"`
TenantKey string `json:"tenant_key"`
}
// InstancesCreate handler
// @Summary 创建流程实例
// @Description 通过流程模板创建流程实例
// @ID instances-create
// @Tags flow-instances
// @Accept json
// @Produce json
// @Param InstancesCreateParam body InstancesCreateParam true "创建参数"
// @Success 200 {object} base.Result "返回成功的流程定义数据"
// @Failure 500 {object} base.Result "返回失败的流程定义数据"
// @Router /instances/create [post]
func (api *FlowInstanceApi) InstancesCreate(c *gin.Context) {
param := utils.QuickBind[InstancesCreateParam](c)
instanceService := c.MustMake(flow_instance.FlowInstanceKey).(flow_instance.Service)
definitionService := c.MustMake(flow_definition.FlowDefinitionKey).(flow_definition.Service)
data := make(map[string]interface{})
data[base.ApplicantKey] = param.ApplicantKey
data[base.CreatorKey] = param.CreatorKey
if param.AssociateKey != "" {
data[base.AssociateKey] = param.AssociateKey
}
if param.TenantKey != "" {
data[base.TenantKey] = param.TenantKey
}
flow, err := definitionService.GetFlow(c, param.FlowID)
if err != nil {
res.FailWithErr(c, err)
return
}
_, err = instanceService.CreateInstance(c, flow, data)
if err != nil {
res.FailWithErr(c, err)
return
}
res.Success(c)
}