fast_domain_repository.go
4.2 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
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
package factory
import (
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
)
// FastPgWorkshop 快速返回车间对象
//
// transactionContext 事务
// id 对象唯一标识
func FastPgWorkshop(transactionContext application.TransactionContext, id int, options ...option) (domain.WorkshopRepository, *domain.Workshop, error) {
var rep domain.WorkshopRepository
var mod *domain.Workshop
var err error
if value, err := CreateWorkshopRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
rep = value
}
if id > 0 {
if mod, err = rep.FindOne(map[string]interface{}{"workshopId": id}); err != nil {
if err == domain.ErrorNotFound {
return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该车间不存在")
}
return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
}
//if err = fastPgDataAuth(transactionContext, mod, options...); err != nil {
// return nil, nil, err
//}
return rep, mod, err
}
// FastPgWorkstation 快速返回工作定位对象
//
// transactionContext 事务
// workshopId 车间ID
// lineId 生产线ID
// sectionId 对象ID
func FastPgWorkstation(transactionContext application.TransactionContext, workshopId, lineId, sectionId int, options ...option) (domain.WorkshopRepository, *domain.WorkStation, error) {
var rep domain.WorkshopRepository
var mod *domain.Workshop
var err error
if value, err := CreateWorkshopRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
rep = value
}
if mod, err = rep.FindOne(map[string]interface{}{"workshopId": workshopId}); err != nil {
if err == domain.ErrorNotFound {
return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该车间不存在")
}
return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
workStation, err := mod.FindWorkStation(workshopId, lineId, sectionId)
if err != nil {
return rep, nil, err
}
o := NewFastOptions(options...)
if o.SetPrincipal {
workStation.Principal = mod.Principal
}
return rep, workStation, err
}
// FastPgProductJob 快速返回工位对象
//
// transactionContext 事务
// id 对象唯一标识
func FastPgProductJob(transactionContext application.TransactionContext, id int, options ...option) (domain.ProductJobRepository, *domain.ProductJob, error) {
var rep domain.ProductJobRepository
var mod *domain.ProductJob
var err error
if value, err := CreateProductJobRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
rep = value
}
if id > 0 {
if mod, err = rep.FindOne(map[string]interface{}{"productJobId": id}); err != nil {
if err == domain.ErrorNotFound {
return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该车间不存在")
}
return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
}
//if err = fastPgDataAuth(transactionContext, mod, options...); err != nil {
// return nil, nil, err
//}
return rep, mod, err
}
/***** 2.配置 *****/
type FastOptions struct {
DataAuthRequired bool
SetPrincipal bool
OperateInfo *domain.OperateInfo
}
func NewFastOptions(options ...option) *FastOptions {
o := &FastOptions{
DataAuthRequired: false,
}
for i := 0; i < len(options); i++ {
options[i](o)
}
return o
}
type option func(options *FastOptions)
// 需要数据权限
func WithDataAuthRequired() option {
return func(options *FastOptions) {
options.DataAuthRequired = true
}
}
// WithOperator 操作人
func WithOperator(op *domain.OperateInfo) option {
return func(options *FastOptions) {
options.OperateInfo = op
}
}
// WithOperator 操作人
func WithSetPrincipal() option {
return func(options *FastOptions) {
options.SetPrincipal = true
}
}