2024-11-14 17:02:41 +08:00
|
|
|
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"`
|
2024-11-19 17:03:12 +08:00
|
|
|
AssociateKey string `json:"associate_key"`
|
|
|
|
TenantKey string `json:"tenant_key"`
|
2024-11-14 17:02:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// InstancesCreate handler
|
|
|
|
// @Summary 创建流程实例
|
|
|
|
// @Description 通过流程模板创建流程实例
|
2024-11-15 16:53:35 +08:00
|
|
|
// @ID instances-create
|
|
|
|
// @Tags flow-instances
|
2024-11-14 17:02:41 +08:00
|
|
|
// @Accept json
|
|
|
|
// @Produce json
|
|
|
|
// @Param InstancesCreateParam body InstancesCreateParam true "创建参数"
|
2024-11-15 16:53:35 +08:00
|
|
|
// @Success 200 {object} base.Result "返回成功的流程定义数据"
|
|
|
|
// @Failure 500 {object} base.Result "返回失败的流程定义数据"
|
2024-11-14 17:02:41 +08:00
|
|
|
// @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
|
2024-11-19 17:03:12 +08:00
|
|
|
|
|
|
|
if param.AssociateKey != "" {
|
|
|
|
data[base.AssociateKey] = param.AssociateKey
|
|
|
|
}
|
|
|
|
if param.TenantKey != "" {
|
|
|
|
data[base.TenantKey] = param.TenantKey
|
|
|
|
}
|
2024-11-14 17:02:41 +08:00
|
|
|
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)
|
|
|
|
}
|