本项目是根据github.com/antlinker/flow演变而来,原来的项目长时间不更新,并且代码qlang部分无法跑通.
目前这个项目支持如下类型:
- 开始/结束/终止事件
- 人工任务/脚本任务
- 排他网关/并行网关
- 支持rpc
println(Rpc("GET", "https://httpbin.org/ip", nil))
注:暂时不支持子流程,后续有支持计划
go get github.com/meixiaofei/flow-bpmn
package main
import (
"github.com/meixiaofei/flow-bpmn"
"github.com/meixiaofei/flow-bpmn/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("process_leave_test", "流程发起人ID", input)
if err != nil {
// 处理错误
}
todos, err := flow.QueryTodoFlows("process_leave_test", "1")
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("process_leave_test","流程处理人ID")
if err != nil {
// 处理错误
}
result,err := flow.QueryFlowHistory("待办流程实例ID")
if err != nil {
// 处理错误
}
ids,err := flow.QueryDoneFlowIDs("process_leave_test","流程处理人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 {
// 处理错误
}