Documentation
¶
Overview ¶
Package engine 引擎接口 + 常量
委托代理自动生效(issues/116,规范 06 §4.5 运行期语义 / 05 §SurrogateInterceptor)—— 引擎内置、默认开启、可显式关闭。
此前各栈只有 `processSurrogate/*` 五个台账 action,"建任务那一刻应用生效委托" 无人实现(Go 全仓 grep surrogate 命中 interceptor/hook 0 处),用户配好"休假期间 张三替我批"后单子仍只发给张三本人。本文件把它变成引擎能力:
- 时机:任务参与者解析完成后、参与者落库前——并入**任务自身的参与者集合** (nt.ActorIDs),随后由 SaveTask 与任务一起落库。 ⚠️ 不走"事后 AddTaskActor 补写"路:补写依赖 taskId 已分配,且与 saveTask 的 全量替换语义(jdbc replaceTaskActors)打架,是 Java 首版静默无效的病根。
- 动作:命中则追加被委托人,**授权人保留**(任一可办;委托不是转办,不摘原人)。
- 默认开启、可显式关闭(WithSurrogateAutoApply(false) / SetSurrogateAutoApply(false))。
- 未配置扩展仓储(surrogateRepo == nil)时静默跳过,不打断建单。
Index ¶
- Constants
- func IsCountersign(v interface{}) bool
- func RegisterBuiltinAssignments(reg *HandlerRegistry, userProv spi.UserProvider, orgProv spi.OrgUserProvider)
- type ApplicantDeptLeaderAssignmentHandler
- type ApplicantDeptMainLeaderAssignmentHandler
- type AssignmentHandler
- type DecisionHandler
- type DeptLeaderAssignmentHandler
- type DeptMainLeaderAssignmentHandler
- type Engine
- type EngineImpl
- func (e *EngineImpl) EvalExpr(expr string, vars map[string]interface{}) (interface{}, error)
- func (e *EngineImpl) ExecuteAndJumpTask(ctx context.Context, taskID int64, operator string, ...) (*model.ProcessInstance, error)
- func (e *EngineImpl) ExecuteAndJumpToEnd(ctx context.Context, taskID int64, operator string, ...) (*model.ProcessInstance, error)
- func (e *EngineImpl) ExecuteAndJumpToFirstTaskNode(ctx context.Context, taskID int64, operator string, ...) (*model.ProcessInstance, error)
- func (e *EngineImpl) ExecuteProcessTask(ctx context.Context, taskID int64, operator string, ...) (*model.ProcessInstance, error)
- func (e *EngineImpl) FireEvent(evt ProcessEvent)
- func (e *EngineImpl) SetExtensions(ext *Extensions)
- func (e *EngineImpl) SetRegistry(reg *HandlerRegistry)
- func (e *EngineImpl) SetSurrogateAutoApply(on bool) *EngineImpl
- func (e *EngineImpl) SetSurrogateRepository(ext spi.ProcessExtRepository) *EngineImpl
- func (e *EngineImpl) StartProcessInstanceByID(ctx context.Context, defineID int64, operator string, ...) (*model.ProcessInstance, error)
- func (e *EngineImpl) SurrogateAutoApply() bool
- func (e *EngineImpl) SurrogateRepository() spi.ProcessExtRepository
- func (e *EngineImpl) UserProvider() spi.UserProvider
- type EventType
- type Extensions
- type FlowInterceptor
- type FormFieldAssigneeHandler
- type HandlerRegistry
- func (r *HandlerRegistry) RegisterAssignment(name string, h IAssignmentHandler)
- func (r *HandlerRegistry) RegisterDecision(name string, h IDecisionHandler)
- func (r *HandlerRegistry) ResolveAssignment(name string) IAssignmentHandler
- func (r *HandlerRegistry) ResolveDecision(name string) IDecisionHandler
- type IAssignmentHandler
- type IDecisionHandler
- type OperatorAssignmentHandler
- type Option
- type ProcessEvent
- type ProcessEventListener
- type TaskRoleAssigneeHandler
Constants ¶
const ( // OperatorAssignmentHandler 流程发起人 HandlerOperatorAssignment = "com.mldong.jeeflow.interceptor.impl.OperatorAssignmentHandler" // FormFieldAssigneeHandler 按表单字段值分配参与者 HandlerFormFieldAssignee = "com.mldong.jeeflow.interceptor.impl.FormFieldAssigneeHandler" // DeptLeaderAssignmentHandler 当前用户部门领导 HandlerDeptLeader = orgHandlersPrefix + "DeptLeaderAssignmentHandler" // DeptMainLeaderAssignmentHandler 当前用户部门分管领导 HandlerDeptMainLeader = orgHandlersPrefix + "DeptMainLeaderAssignmentHandler" // ApplicantDeptLeaderAssignmentHandler 发起人部门领导 HandlerApplicantDeptLeader = orgHandlersPrefix + "ApplicantDeptLeaderAssignmentHandler" // ApplicantDeptMainLeaderAssignmentHandler 发起人部门分管领导 HandlerApplicantDeptMainLeader = orgHandlersPrefix + "ApplicantDeptMainLeaderAssignmentHandler" // TaskRoleAssigneeHandler 任务节点唯一编码关联角色 HandlerTaskRoleAssignee = orgHandlersPrefix + "TaskRoleAssigneeHandler" )
const ( KeySubmitType = "submitType" KeyBusinessNo = "BUSINESS_NO" KeyUserID = "u_userId" KeyRealName = "u_realName" KeyDeptID = "u_deptId" KeyDeptName = "u_deptName" KeyPostID = "u_postId" KeyPostName = "u_postName" KeyAutoGenTitle = "autoGenTitle" // v1.0.1:下一节点处理人(对齐 boot3 tf_nextNodeOperator) KeyNextNodeOperator = "tf_nextNodeOperator" // v1.6.0:流程启动时预指派人(对齐 boot3 f_nextNodeOperator)——startAndExecute 时转换为 tf_ KeyProcessStartNextNodeOperator = "f_nextNodeOperator" // v1.0.1:系统代执行 / 超级管理员(对齐 boot3 FlowConst) KeyAutoExecute = "flow.auto" KeyAdminID = "flow.admin" // issues/121 P1:行级首任务节点标记(引擎建单时落库,对齐 Java FlowConst.IS_FIRST_TASK_NODE) // 值与 model.IsFirstTaskNodeKey 同——建单写入在 model.CreateTask(唯一工厂),此处供引擎/门面读出口引用 KeyIsFirstTaskNode = model.IsFirstTaskNodeKey )
Variables ¶
This section is empty.
Functions ¶
func IsCountersign ¶ added in v1.8.7
func IsCountersign(v interface{}) bool
isCountersign 会签判定(issue 42,对齐 Java ProcessTaskPerformTypeEnum.codeOf): '1'/'ALL'/'COUNTERSIGN'(大小写不敏感)→ 会签。设计器属性面板保存 'ALL' 字符串符合契约 IsCountersign 会签判定(issue 42,对齐 Java ProcessTaskPerformTypeEnum.codeOf): '1'/'ALL'/'COUNTERSIGN'(大小写不敏感)→ 会签。设计器属性面板保存 'ALL' 字符串符合契约
func RegisterBuiltinAssignments ¶ added in v1.6.0
func RegisterBuiltinAssignments(reg *HandlerRegistry, userProv spi.UserProvider, orgProv spi.OrgUserProvider)
RegisterBuiltinAssignments 注册内置通用参与者处理器到注册表。 组织维度 handler 依赖 userProv/orgProv;纯引擎语义 handler 无需数据源。
Types ¶
type ApplicantDeptLeaderAssignmentHandler ¶ added in v1.6.0
type ApplicantDeptLeaderAssignmentHandler struct {
// contains filtered or unexported fields
}
ApplicantDeptLeaderAssignmentHandler 发起人部门领导
func (*ApplicantDeptLeaderAssignmentHandler) Assign ¶ added in v1.6.0
func (h *ApplicantDeptLeaderAssignmentHandler) Assign(node *model.FlowNode, inst *model.ProcessInstance, operator string) []string
type ApplicantDeptMainLeaderAssignmentHandler ¶ added in v1.6.0
type ApplicantDeptMainLeaderAssignmentHandler struct {
// contains filtered or unexported fields
}
ApplicantDeptMainLeaderAssignmentHandler 发起人部门分管领导
func (*ApplicantDeptMainLeaderAssignmentHandler) Assign ¶ added in v1.6.0
func (h *ApplicantDeptMainLeaderAssignmentHandler) Assign(node *model.FlowNode, inst *model.ProcessInstance, operator string) []string
type AssignmentHandler ¶
type AssignmentHandler func(handlerName string, node *model.FlowNode, inst *model.ProcessInstance) []string
AssignmentHandler 动态参与者指派——对标 Java AssignmentHandler.assign handlerName: 节点配置的 assignmentHandler 类名(如 "com.xxx.MyHandler") 返回参与者 ID 列表(nil 表示不处理)
type DecisionHandler ¶
type DecisionHandler func(handlerName string, node *model.FlowNode, inst *model.ProcessInstance, vars map[string]interface{}) string
DecisionHandler 自定义决策处理器——对标 Java DecisionHandler handlerName: 节点配置的 decisionHandler 类名 返回选中的分支边 ID(空字符串表示不处理)
type DeptLeaderAssignmentHandler ¶ added in v1.6.0
type DeptLeaderAssignmentHandler struct {
// contains filtered or unexported fields
}
DeptLeaderAssignmentHandler 当前用户(任务操作人)部门领导
func (*DeptLeaderAssignmentHandler) Assign ¶ added in v1.6.0
func (h *DeptLeaderAssignmentHandler) Assign(node *model.FlowNode, inst *model.ProcessInstance, operator string) []string
type DeptMainLeaderAssignmentHandler ¶ added in v1.6.0
type DeptMainLeaderAssignmentHandler struct {
// contains filtered or unexported fields
}
DeptMainLeaderAssignmentHandler 当前用户(任务操作人)部门分管领导
func (*DeptMainLeaderAssignmentHandler) Assign ¶ added in v1.6.0
func (h *DeptMainLeaderAssignmentHandler) Assign(node *model.FlowNode, inst *model.ProcessInstance, operator string) []string
type Engine ¶
type Engine interface {
StartProcessInstanceByID(ctx context.Context, defineID int64, operator string, args map[string]interface{}) (*model.ProcessInstance, error)
ExecuteProcessTask(ctx context.Context, taskID int64, operator string, args map[string]interface{}) (*model.ProcessInstance, error)
ExecuteAndJumpToEnd(ctx context.Context, taskID int64, operator string, args map[string]interface{}) (*model.ProcessInstance, error)
ExecuteAndJumpTask(ctx context.Context, taskID int64, operator string, args map[string]interface{}, targetTaskName string) (*model.ProcessInstance, error)
ExecuteAndJumpToFirstTaskNode(ctx context.Context, taskID int64, operator string, args map[string]interface{}) (*model.ProcessInstance, error)
}
type EngineImpl ¶
type EngineImpl struct {
// contains filtered or unexported fields
}
func New ¶
func New(repo spi.ProcessRepository, userProv spi.UserProvider, idGen spi.IDGenerator, exprEval spi.ExpressionEvaluator, opts ...Option) *EngineImpl
func (*EngineImpl) EvalExpr ¶ added in v1.5.0
func (e *EngineImpl) EvalExpr(expr string, vars map[string]interface{}) (interface{}, error)
EvalExpr 表达式求值(v1.5.0,门面 highLight 决策分支过滤用)
func (*EngineImpl) ExecuteAndJumpTask ¶
func (e *EngineImpl) ExecuteAndJumpTask(ctx context.Context, taskID int64, operator string, args map[string]interface{}, targetTaskName string) (*model.ProcessInstance, error)
func (*EngineImpl) ExecuteAndJumpToEnd ¶
func (e *EngineImpl) ExecuteAndJumpToEnd(ctx context.Context, taskID int64, operator string, args map[string]interface{}) (*model.ProcessInstance, error)
func (*EngineImpl) ExecuteAndJumpToFirstTaskNode ¶
func (e *EngineImpl) ExecuteAndJumpToFirstTaskNode(ctx context.Context, taskID int64, operator string, args map[string]interface{}) (*model.ProcessInstance, error)
func (*EngineImpl) ExecuteProcessTask ¶
func (e *EngineImpl) ExecuteProcessTask(ctx context.Context, taskID int64, operator string, args map[string]interface{}) (*model.ProcessInstance, error)
func (*EngineImpl) FireEvent ¶ added in v1.8.24
func (e *EngineImpl) FireEvent(evt ProcessEvent)
FireEvent 公开事件发布入口(facade 层事件源调用,issues/102 CC_CREATE): Go 栈的 cc 实例创建在 facade(CreateCcInstance),fire 通道在引擎侧私有, 故 facade 经此入口发布事件——纯增量:未装配 Extensions/监听器时零副作用。
func (*EngineImpl) SetExtensions ¶
func (e *EngineImpl) SetExtensions(ext *Extensions)
func (*EngineImpl) SetRegistry ¶
func (e *EngineImpl) SetRegistry(reg *HandlerRegistry)
func (*EngineImpl) SetSurrogateAutoApply ¶ added in v1.8.28
func (e *EngineImpl) SetSurrogateAutoApply(on bool) *EngineImpl
SetSurrogateAutoApply 运行期开关:false = 显式关闭委托自动生效(回退仅台账)。
func (*EngineImpl) SetSurrogateRepository ¶ added in v1.8.28
func (e *EngineImpl) SetSurrogateRepository(ext spi.ProcessExtRepository) *EngineImpl
SetSurrogateRepository 注入/替换委托扩展仓储(链式,对齐 SetRegistry/SetExtensions 风格)。 传 nil 即"未配置"——静默跳过。
func (*EngineImpl) StartProcessInstanceByID ¶
func (e *EngineImpl) StartProcessInstanceByID(ctx context.Context, defineID int64, operator string, args map[string]interface{}) (*model.ProcessInstance, error)
func (*EngineImpl) SurrogateAutoApply ¶ added in v1.8.28
func (e *EngineImpl) SurrogateAutoApply() bool
SurrogateAutoApply 当前是否启用委托自动生效(集成层自检用)。
关闭位以 surrogateOff 存储而非 surrogateEnabled bool——零值 EngineImpl{} 直构 (内部测试/反射构造)也要落在"默认开启"上,反向标记才成立。
func (*EngineImpl) SurrogateRepository ¶ added in v1.8.28
func (e *EngineImpl) SurrogateRepository() spi.ProcessExtRepository
SurrogateRepository 当前注入的委托扩展仓储(未注入返回 nil)。
func (*EngineImpl) UserProvider ¶ added in v1.8.8
func (e *EngineImpl) UserProvider() spi.UserProvider
UserProvider 用户提供者访问(issue 41 补强:nodeProgress 姓名解析用)
type Extensions ¶
type Extensions struct {
Interceptors []FlowInterceptor
// 定义级拦截器注册表(issue 34):名字 → 实例;流程定义顶层 postInterceptors 按名解析
InterceptorRegistry map[string]FlowInterceptor
AssignmentHandler AssignmentHandler
DecisionHandler DecisionHandler
Listeners []ProcessEventListener
}
Extensions 引擎扩展配置
type FlowInterceptor ¶
type FlowInterceptor interface {
// PreHandle 节点执行前调用,返回 false 则跳过该节点
PreHandle(node *model.FlowNode, inst *model.ProcessInstance) (proceed bool)
// PostHandle 节点执行后调用
PostHandle(node *model.FlowNode, inst *model.ProcessInstance)
// Order 拦截器排序,越小越先执行
Order() int
}
FlowInterceptor 流程拦截器——对标 Java FlowInterceptor
type FormFieldAssigneeHandler ¶ added in v1.6.0
type FormFieldAssigneeHandler struct{}
FormFieldAssigneeHandler 按表单字段值分配参与者: issues/48:f_ 前缀优先 → 裸名回落 → _数字 后缀去后缀再匹配。 字段值支持逗号分隔字符串 / []string / []interface{}。
func (*FormFieldAssigneeHandler) Assign ¶ added in v1.6.0
func (h *FormFieldAssigneeHandler) Assign(node *model.FlowNode, inst *model.ProcessInstance, operator string) []string
type HandlerRegistry ¶
type HandlerRegistry struct {
// contains filtered or unexported fields
}
HandlerRegistry 处理器注册表——按名称注册/解析
func NewHandlerRegistry ¶
func NewHandlerRegistry() *HandlerRegistry
func (*HandlerRegistry) RegisterAssignment ¶
func (r *HandlerRegistry) RegisterAssignment(name string, h IAssignmentHandler)
RegisterAssignment 注册参与者指派处理器
func (*HandlerRegistry) RegisterDecision ¶
func (r *HandlerRegistry) RegisterDecision(name string, h IDecisionHandler)
RegisterDecision 注册决策处理器
func (*HandlerRegistry) ResolveAssignment ¶
func (r *HandlerRegistry) ResolveAssignment(name string) IAssignmentHandler
ResolveAssignment 按名称解析指派处理器
func (*HandlerRegistry) ResolveDecision ¶
func (r *HandlerRegistry) ResolveDecision(name string) IDecisionHandler
ResolveDecision 按名称解析决策处理器
type IAssignmentHandler ¶
type IAssignmentHandler interface {
// Assign 返回参与者列表(operator: 当前任务操作人,issues/16 对齐 Java Execution.getOperator)
Assign(node *model.FlowNode, inst *model.ProcessInstance, operator string) []string
}
IAssignmentHandler 参与者指派处理器接口
type IDecisionHandler ¶
type IDecisionHandler interface {
// Decide 返回选中的分支边 ID
Decide(node *model.FlowNode, inst *model.ProcessInstance, vars map[string]interface{}) string
}
IDecisionHandler 决策处理器接口
type OperatorAssignmentHandler ¶ added in v1.6.0
type OperatorAssignmentHandler struct{}
OperatorAssignmentHandler 流程发起人(兜底 "apply.operator")
func (*OperatorAssignmentHandler) Assign ¶ added in v1.6.0
func (h *OperatorAssignmentHandler) Assign(node *model.FlowNode, inst *model.ProcessInstance, operator string) []string
type Option ¶ added in v1.8.28
type Option func(*EngineImpl)
Option 引擎构造选项(issues/116 引入;后续构造期配置统一走这里)。 New 的四个必填参数不变,故现有 `engine.New(repo, userProv, idGen, exprEval)` 调用零改动。
func WithSurrogateAutoApply ¶ added in v1.8.28
WithSurrogateAutoApply 委托自动生效开关(默认开启);传 false 显式关闭, 行为回退到"仅台账 CRUD"(配了委托也不会并入参与者)。
func WithSurrogateRepository ¶ added in v1.8.28
func WithSurrogateRepository(ext spi.ProcessExtRepository) Option
WithSurrogateRepository 注入委托扩展仓储(spi.ProcessExtRepository)。 不注入(或注入 nil)= 委托自动生效静默跳过,建单流程不受影响。
type ProcessEvent ¶
type ProcessEvent struct {
Type EventType
InstanceID int64
TaskID int64
NodeID string
Operator string
// CcActorID 抄送人 id(仅 CC_CREATE 事件非空,直传事件体,监听器免反查 cc 表——
// 对齐 Java ProcessEvent.ccActorId / PHP ccActorId / issues/102 语义铁律 2)
CcActorID string
}
ProcessEvent 流程事件
type ProcessEventListener ¶
type ProcessEventListener func(event ProcessEvent)
ProcessEventListener 事件监听器
type TaskRoleAssigneeHandler ¶ added in v1.6.0
type TaskRoleAssigneeHandler struct {
// contains filtered or unexported fields
}
TaskRoleAssigneeHandler 任务节点唯一编码关联角色(roleCode = 节点 ID)
func (*TaskRoleAssigneeHandler) Assign ¶ added in v1.6.0
func (h *TaskRoleAssigneeHandler) Assign(node *model.FlowNode, inst *model.ProcessInstance, operator string) []string