go get github.com/antlinker/flow
import (
"time"
"ant-flow"
"ant-flow/service/db"
_ "github.com/go-sql-driver/mysql"
)
func main() {
flow.Init(
db.SetDSN("root:123456@tcp(127.0.0.1:3306)/flows?charset=utf8"),
db.SetTrace(true),
)
}
err := flow.LoadFile("leave.bpmn")
if err != nil {
// 处理错误
}
input := map[string]interface{}{
"day": 1,
}
result, err := flow.StartFlow("流程编号", "开始节点编号", "流程发起人ID", input)
if err != nil {
// 处理错误
}
todos, err := flow.QueryTodoFlows("流程编号", "流程待办人ID")
if err != nil {
// 处理错误
}
input := map[string]interface{}{
"action": "pass",
}
result, err = flow.HandleFlow("待办流程节点实例ID", "流程处理人ID", input)
if err != nil {
// 处理错误
}
err := flow.StopFlow("待办流程节点实例ID", func(flowInstance *schema.FlowInstance) bool {
return flowInstance.Launcher == "XXX"
})
if err != nil {
// 处理错误
}
func main() {
serverOptions := []flow.ServerOption{
flow.ServerStaticRootOption("./web"),
flow.ServerPrefixOption("/flow/"),
flow.ServerMiddlewareOption(filter),
}
http.Handle("/flow/", flow.StartServer(serverOptions...))
}
func filter(ctx *gear.Context) error {
fmt.Printf("请求参数:%s - %s \n", ctx.Path, ctx.Method)
return nil
}
result,err := flow.QueryTodoFlows("流程编号","流程处理人ID")
if err != nil {
// 处理错误
}
result,err := flow.QueryFlowHistory("待办流程实例ID")
if err != nil {
// 处理错误
}
ids,err := flow.QueryDoneFlowIDs("流程编号","流程处理人ID")
if err != nil {
// 处理错误
}
ids,err := flow.QueryNodeCandidates("待办流程节点实例ID")
if err != nil {
// 处理错误
}
err := flow.StopFlowInstance("待办流程节点实例ID", func(flowInstance *schema.FlowInstance) bool {
return flowInstance.Launcher == "XXX"
})
if err != nil {
// 处理错误
}