2024-02-29 22:12:50 +08:00
|
|
|
|
package application
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
|
"context"
|
|
|
|
|
|
"mayfly-go/internal/flow/domain/entity"
|
|
|
|
|
|
"mayfly-go/pkg/errorx"
|
|
|
|
|
|
"mayfly-go/pkg/logx"
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2024-03-02 19:08:19 +08:00
|
|
|
|
type BizHandleParam struct {
|
2024-10-16 17:24:50 +08:00
|
|
|
|
Procinst entity.Procinst // 流程实例
|
2024-03-02 19:08:19 +08:00
|
|
|
|
}
|
2024-02-29 22:12:50 +08:00
|
|
|
|
|
|
|
|
|
|
// 业务流程处理器(流程状态变更后会根据流程业务类型获取对应的处理器进行回调处理)
|
|
|
|
|
|
type FlowBizHandler interface {
|
|
|
|
|
|
|
|
|
|
|
|
// 业务流程处理函数
|
2024-03-02 19:08:19 +08:00
|
|
|
|
// @param bizHandleParam 业务处理信息,可获取实例状态、关联业务key等信息
|
2024-10-16 17:24:50 +08:00
|
|
|
|
// @return any 返回业务处理结果
|
|
|
|
|
|
// @return error 错误信息
|
|
|
|
|
|
FlowBizHandle(ctx context.Context, bizHandleParam *BizHandleParam) (any, error)
|
2024-02-29 22:12:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
|
|
handlers map[string]FlowBizHandler = make(map[string]FlowBizHandler, 0)
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
// 注册流程业务处理函数
|
|
|
|
|
|
func RegisterBizHandler(flowBizType string, handler FlowBizHandler) {
|
|
|
|
|
|
logx.Infof("flow register biz handelr: bizType=%s", flowBizType)
|
|
|
|
|
|
handlers[flowBizType] = handler
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 流程业务处理
|
2024-10-16 17:24:50 +08:00
|
|
|
|
func FlowBizHandle(ctx context.Context, bizHandleParam *BizHandleParam) (any, error) {
|
|
|
|
|
|
flowBizType := bizHandleParam.Procinst.BizType
|
2024-02-29 22:12:50 +08:00
|
|
|
|
if handler, ok := handlers[flowBizType]; !ok {
|
|
|
|
|
|
logx.Warnf("flow biz handler not found: bizType=%s", flowBizType)
|
2024-11-20 22:43:53 +08:00
|
|
|
|
return nil, errorx.NewBiz("flow biz handler not found")
|
2024-02-29 22:12:50 +08:00
|
|
|
|
} else {
|
2024-03-02 19:08:19 +08:00
|
|
|
|
return handler.FlowBizHandle(ctx, bizHandleParam)
|
2024-02-29 22:12:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|