-
Notifications
You must be signed in to change notification settings - Fork 0
/
act_event.go
167 lines (134 loc) · 3.88 KB
/
act_event.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
package loong
import (
"context"
"errors"
"fmt"
"maps"
"time"
"github.com/it512/loong/bpmn"
)
type StartProcCmd struct {
ProcID string `json:"proc_id,omitempty"` // 流程ID
Starter string `json:"starter,omitempty"` // 启动人人组
BusiKey string `json:"busi_key,omitempty"` // 业务单据ID
BusiType string `json:"busi_type,omitempty"` // 业务单据类型
Input map[string]any `json:"input,omitempty"` // 启动参数 map[string]any
Var map[string]any `json:"var,omitempty"` // 启动参数 map[string]any
Tags map[string]any `json:"tags,omitempty"` // 流程标志 map[string]any
Variable
bpmn.TStartEvent
InOut
}
func (n StartProcCmd) check() error {
if n.BusiKey == "" {
return errors.New("参数BusiKey为空")
}
if n.BusiType == "" {
return errors.New("参数BusiType为空")
}
if n.Starter == "" {
return errors.New("参数Starter为空")
}
return nil
}
func (n *StartProcCmd) Bind(ctx context.Context, e *Engine) error {
if err := n.check(); err != nil {
return err
}
var t *Template
if t = e.GetTemplate(n.ProcID); t == nil {
return fmt.Errorf("未找到流程(ProcID = %s)", n.ProcID)
}
if !t.Definitions.Process.IsExecutable {
return fmt.Errorf("流程已停用(ProcID = %s)", n.ProcID)
}
var ok bool
if n.TStartEvent, ok = t.FindNormalStartEvent(); !ok {
return errors.New("没有找到合适的StartEvnet")
}
n.Variable.Input = Merge(n.Variable.Input, n.Input)
n.Variable.Exec.ProcInst = &ProcInst{
InstID: e.NewID(),
ProcID: n.ProcID,
BusiKey: n.BusiKey,
BusiType: n.BusiType,
Starter: n.Starter,
Init: Merge(nil, n.Var),
Var: Merge(nil, n.Var),
Tags: maps.Clone(n.Tags),
Template: t,
Engine: e,
}
return nil
}
func (n *StartProcCmd) Do(ctx context.Context) error {
// n.IoConnector.Call(ctx, n)
n.Exec.ProcInst.StartTime = time.Now()
n.Exec.ProcInst.Status = STATUS_START
return n.Storer.CreateProcInst(ctx, n.Exec.ProcInst)
}
func (n *StartProcCmd) Emit(ctx context.Context, emit Emitter) error {
return emit.Emit(fromOuter(ctx, n.Variable, n))
}
func (n StartProcCmd) Type() ActivityType {
return OP_START_EVENT
}
type EndEventOp struct {
Exec
bpmn.TEndEvent
UnimplementedActivity
}
func (n *EndEventOp) Do(ctx context.Context) error {
n.ProcInst.Status = STATUS_FINISH
n.ProcInst.EndTime = time.Now()
return n.EndProcInst(ctx, n.ProcInst)
}
func (n EndEventOp) Type() ActivityType {
return OP_END_EVENT
}
func doIntermediationThrowEvent(v Variable, i bpmn.TIntermediateThrowEvent) Activity {
if i.HasLinkEventDefinition() {
return &linkEventOp{Variable: v, Throw: i.GetLinkEventDefinition()}
}
if i.HasMessageEventDefinitio() {
return &messageIntermediateThrowEventOp{Variable: v, InOut: newInOut(), TIntermediateThrowEvent: i}
}
panic("不支持的IntermediateThrowEvent类型")
}
type linkEventOp struct {
Variable
Throw bpmn.TLinkEventDefinition
UnimplementedActivity
}
func (n linkEventOp) Emit(ctx context.Context, emt Emitter) error {
for _, c := range n.Template.Definitions.Process.IntermediateCatchEvent {
if c.HasLinkEventDefinition() {
if c.GetLinkEventDefinition().Name == n.Throw.Name {
return emt.Emit(fromVariable(n.Variable, c.OutgoingAssociation[0]))
}
}
}
panic("LinkEvent错误, Throw 没有找到 Catch")
}
type messageIntermediateThrowEventOp struct {
InOut
Variable
bpmn.TIntermediateThrowEvent
UnimplementedActivity
}
func (s *messageIntermediateThrowEventOp) Do(ctx context.Context) (err error) {
if err = io(ctx, s, s); err == nil { // err == nil
err = s.Variable.saveTo(ctx, s.Storer)
}
return
}
func (s *messageIntermediateThrowEventOp) Emit(ctx context.Context, emt Emitter) error {
return emt.Emit(fromOuter(ctx, s.Variable, s))
}
func (s *messageIntermediateThrowEventOp) GetTaskDefinition(ctx context.Context) TaskDefinition {
return newTaskDef(
ctx,
s,
s.TaskDefinition,
)
}