-
Notifications
You must be signed in to change notification settings - Fork 0
/
activity.go
94 lines (82 loc) · 2.51 KB
/
activity.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
package workflow
//流程参数
type EventArgs struct {
AppData *map[string]string //业务数据
CurrStatus string //当前状态
CurrUser string //当前用户
UserChoice string //用户选择结果
}
//流程环节接口对象
type IActivity interface {
GetName() string
GetDescript() string
CanEnter(args *EventArgs) bool //是否可以进入
CanExit(args *EventArgs) bool //是否可以退出
Enter(args *EventArgs) //进入
Execute(args *EventArgs) //执行
Exit(args *EventArgs) //退出
IsRoot() bool //是否跟节点
}
//流程环节
type Activity struct {
name string //环节名称
descript string //描述
isRoot bool //是否根节点
EnterMode ActivityRunMode //进入模式
ExitMode ActivityRunMode //退出模式
JoinMode TransitJoinMode //迁入模式
SplitMode TransitSplitMode //迁出模式
CheckEnter func(*map[string]string) bool //检查是否可以进入的函数
CheckExit func(*map[string]string) bool //检查是否可以退出的函数
EnterHandler func(*EventArgs) //进入事件处理器
ExcuteHandler func(*EventArgs) //执行事件处理
ExitHandler func(*EventArgs) //退出事件处理器
}
func New_Activity(name string) *Activity {
act := &Activity{
name: name,
EnterMode: ActivityRunMode_Auto,
ExitMode: ActivityRunMode_Auto,
JoinMode: TransitJoinMode_XOR,
SplitMode: TransitSplitMode_XOR,
}
return act
}
//-------IActivity interface----------
func (this *Activity) GetName() string {
return this.name
}
func (this *Activity) GetDescript() string {
return this.descript
}
func (this *Activity) CanEnter(args *EventArgs) bool {
if this.CheckEnter == nil {
return true
}
return this.CheckEnter(args.AppData)
}
func (this *Activity) CanExit(args *EventArgs) bool {
if this.CanExit == nil {
return true
}
return this.CheckExit(args.AppData)
}
func (this *Activity) Enter(args *EventArgs) {
if this.EnterHandler != nil {
this.EnterHandler(args)
}
}
func (this *Activity) Excute(args *EventArgs) {
if this.ExcuteHandler != nil {
this.ExcuteHandler(args)
}
}
func (this *Activity) Exit(args *EventArgs) {
if this.ExitHandler != nil {
this.ExitHandler(args)
}
}
func (this *Activity) IsRoot() bool {
return this.isRoot
}
//-------IActivity interface----------