-
Notifications
You must be signed in to change notification settings - Fork 5
/
node_model.go
140 lines (120 loc) · 3.77 KB
/
node_model.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package goflow
import "strings"
//XML节点通用信息
type NodeModel struct {
INodeModel
BaseModel
Inputs []*TransitionModel `xml:"-"` //输入变迁集合
Outputs []*TransitionModel `xml:"transition"` //输出变迁集合
PrevInterceptorsSetting string `xml:"prevInterceptors,attr"` //局部前置拦截器
PostInterceptorsSetting string `xml:"postInterceptors,attr"` //局部后置拦截器
PrevInterceptors []IInterceptor `xml:"-"` //局部前置拦截器对象
PostInterceptors []IInterceptor `xml:"-"` //局部后置拦截器对象
}
func (p *NodeModel) GetName() string {
return p.BaseModel.Name
}
//执行
func (p *NodeModel) Execute(execution *Execution) {
p.PrevIntercept(execution)
p.Exec(execution)
p.PostIntercept(execution)
}
//建立拦截器
func (p *NodeModel) BuildInterceptors(processService *ProcessService) {
p.PrevInterceptors = make([]IInterceptor, 0)
p.PostInterceptors = make([]IInterceptor, 0)
for _, v := range processService.InnerInterceptorCache {
p.PrevInterceptors = append(p.PrevInterceptors, v.Clone())
}
pris := strings.Split(p.PrevInterceptorsSetting, ",")
pois := strings.Split(p.PostInterceptorsSetting, ",")
for _, s := range pris {
if v := processService.GetCustomInterceptor(s); v != nil {
p.PrevInterceptors = append(p.PrevInterceptors, v.Clone())
}
}
for _, s := range pois {
if v := processService.GetCustomInterceptor(s); v != nil {
p.PostInterceptors = append(p.PostInterceptors, v.Clone())
}
}
}
func (p *NodeModel) AddInputs(tm ...*TransitionModel) {
p.Inputs = append(p.Inputs, tm...)
}
//得到输入变迁
func (p *NodeModel) GetInputs() []*TransitionModel {
return p.Inputs
}
//得到输出变迁
func (p *NodeModel) GetOutputs() []*TransitionModel {
return p.Outputs
}
//运行变迁
func (p *NodeModel) RunOutTransition(execution *Execution) {
for _, tm := range p.Outputs {
tm.Enabled = true
tm.Execute(execution)
}
}
//执行拦截器
func (p *NodeModel) PrevIntercept(execution *Execution) {
Intercept(p.PrevInterceptors, execution)
}
//执行拦截器
func (p *NodeModel) PostIntercept(execution *Execution) {
Intercept(p.PostInterceptors, execution)
}
//执行拦截器
func Intercept(interceptors []IInterceptor, execution *Execution) {
for _, interceptor := range interceptors {
interceptor.Intercept(execution)
}
}
//合并处理通用流程
func MergeHandle(execution *Execution, activeNodes []string) {
processModel := execution.Process.Model
isSubProcessMerged := false
if processModel.ContainsSubProcessNodeNames(activeNodes...) {
orders := GetActiveOrdersSQL(`"ParentId" = ? and "Id" <> ?`, execution.Order.Id, execution.ChildOrderId)
isSubProcessMerged = len(orders) == 0
}
isTaskMerged := false
if isSubProcessMerged && processModel.ContainsTaskNodeNames(activeNodes...) {
tasks, _ := GetActiveTasksSQL(`"OrderId" = ? and "Id" <> ? and "Name" in (?)`, execution.Order.Id, execution.Task.Id, strings.Join(activeNodes, ","))
isTaskMerged = len(tasks) == 0
}
execution.IsMerged = isSubProcessMerged && isTaskMerged
}
//能否驳回
func CanRejected(currentNode INodeModel, parentNode INodeModel) bool {
switch parentNode.(type) {
case *TaskModel:
if ProcessPerformType(parentNode.(*TaskModel).PerformType) == PO_ANY {
return false
}
default:
}
result := false
for _, tm := range currentNode.GetInputs() {
source := tm.Source
if source == parentNode {
return true
} else {
switch source.(type) {
case *ForkModel:
continue
case *JoinModel:
continue
case *SubProcessModel:
continue
case *StartModel:
continue
default:
}
result = result || CanRejected(source, parentNode)
}
}
return result
}