-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstance.go
More file actions
62 lines (52 loc) · 1.77 KB
/
instance.go
File metadata and controls
62 lines (52 loc) · 1.77 KB
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
package smart
import (
"github.com/astaxie/beego/logs"
"github.com/astaxie/beego/orm"
"github.com/pkg/errors"
)
type InstanceService interface {
// 根据流程、操作人员、父流程实例ID创建流程实例
CreateInstanceUseParentInfo(process *Process, operator string, args map[string]interface{}, parentId int64, parentNodeName string) (*Instance, error)
// 更新流程实例
UpdateInstance(instance *Instance) error
}
type SmartInstanceService struct {
Engine Engine
}
func NewSmartInstanceService(engine Engine) InstanceService {
return &SmartInstanceService{
Engine: engine,
}
}
// 根据流程、操作人员、父流程实例ID创建流程实例
// @param process 流程定义对象
// @param operator 操作人员ID
// @param args 参数列表
// @param parentId 父流程实例ID
// @param parentNodeName 父流程节点模型
// @return 活动流程实例对象
func (s *SmartInstanceService) CreateInstanceUseParentInfo(process *Process, operator string, args map[string]interface{}, parentId int64, parentNodeName string) (*Instance, error) {
instance := &Instance{
Name: process.Name,
DisplayName: process.DisplayName,
ProcessId: process.Id,
Content: process.Content,
Deployer: operator,
ParentId: parentId,
ParentNodeName: parentNodeName,
}
instance.SetVariable(args)
if _, err := orm.NewOrm().Insert(instance); err != nil {
logs.Error("create instance failed. process: %v, err: %v", *process, err)
return nil, errors.New("创建流程实例失败")
}
return instance, nil
}
func (s *SmartInstanceService) UpdateInstance(instance *Instance) error {
_, err := orm.NewOrm().Update(instance)
if nil != err {
logs.Error("update instance failed. instance: %v, err: %v", instance, err)
return errors.New("更新实例失败")
}
return nil
}