|
@@ -5,11 +5,13 @@ import ( |
|
@@ -5,11 +5,13 @@ import ( |
|
5
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain"
|
5
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain"
|
|
6
|
)
|
6
|
)
|
|
7
|
|
7
|
|
|
|
|
8
|
+/***** 1.快速模块 *****/
|
|
|
|
9
|
+
|
|
8
|
// FastPgUser 快速返回领域用户
|
10
|
// FastPgUser 快速返回领域用户
|
|
9
|
//
|
11
|
//
|
|
10
|
// transactionContext 事务
|
12
|
// transactionContext 事务
|
|
11
|
// userId 用户ID
|
13
|
// userId 用户ID
|
|
12
|
-func FastPgUser(transactionContext application.TransactionContext, userId int64) (domain.UserRepository, *domain.User, error) {
|
14
|
+func FastPgUser(transactionContext application.TransactionContext, userId int64, options ...option) (domain.UserRepository, *domain.User, error) {
|
|
13
|
var rep domain.UserRepository
|
15
|
var rep domain.UserRepository
|
|
14
|
var mod *domain.User
|
16
|
var mod *domain.User
|
|
15
|
var err error
|
17
|
var err error
|
|
@@ -28,6 +30,9 @@ func FastPgUser(transactionContext application.TransactionContext, userId int64) |
|
@@ -28,6 +30,9 @@ func FastPgUser(transactionContext application.TransactionContext, userId int64) |
|
28
|
return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
30
|
return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
29
|
}
|
31
|
}
|
|
30
|
}
|
32
|
}
|
|
|
|
33
|
+ if err = fastPgDataAuth(transactionContext, mod, options...); err != nil {
|
|
|
|
34
|
+ return nil, nil, err
|
|
|
|
35
|
+ }
|
|
31
|
return rep, mod, err
|
36
|
return rep, mod, err
|
|
32
|
}
|
37
|
}
|
|
33
|
|
38
|
|
|
@@ -61,7 +66,7 @@ func FastPgUserBase(transactionContext application.TransactionContext, userBaseI |
|
@@ -61,7 +66,7 @@ func FastPgUserBase(transactionContext application.TransactionContext, userBaseI |
|
61
|
//
|
66
|
//
|
|
62
|
// transactionContext 事务
|
67
|
// transactionContext 事务
|
|
63
|
// roleId 角色Id
|
68
|
// roleId 角色Id
|
|
64
|
-func FastPgRole(transactionContext application.TransactionContext, roleId int64) (domain.RoleRepository, *domain.Role, error) {
|
69
|
+func FastPgRole(transactionContext application.TransactionContext, roleId int64, options ...option) (domain.RoleRepository, *domain.Role, error) {
|
|
65
|
var rep domain.RoleRepository
|
70
|
var rep domain.RoleRepository
|
|
66
|
var mod *domain.Role
|
71
|
var mod *domain.Role
|
|
67
|
var err error
|
72
|
var err error
|
|
@@ -80,6 +85,9 @@ func FastPgRole(transactionContext application.TransactionContext, roleId int64) |
|
@@ -80,6 +85,9 @@ func FastPgRole(transactionContext application.TransactionContext, roleId int64) |
|
80
|
return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
85
|
return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
81
|
}
|
86
|
}
|
|
82
|
}
|
87
|
}
|
|
|
|
88
|
+ if err = fastPgDataAuth(transactionContext, mod, options...); err != nil {
|
|
|
|
89
|
+ return nil, nil, err
|
|
|
|
90
|
+ }
|
|
83
|
return rep, mod, err
|
91
|
return rep, mod, err
|
|
84
|
}
|
92
|
}
|
|
85
|
|
93
|
|
|
@@ -213,6 +221,49 @@ func FastPgAccountDestroyRecord(transactionContext application.TransactionContex |
|
@@ -213,6 +221,49 @@ func FastPgAccountDestroyRecord(transactionContext application.TransactionContex |
|
213
|
return rep, mod, err
|
221
|
return rep, mod, err
|
|
214
|
}
|
222
|
}
|
|
215
|
|
223
|
|
|
216
|
-func FastPgDataAuth(transactionContext application.TransactionContext, operateInfo *domain.OperateInfo) error {
|
224
|
+// fastPgDataAuth 快速数据权限验证
|
|
|
|
225
|
+//
|
|
|
|
226
|
+// data 待认证的数据
|
|
|
|
227
|
+// options 配置项
|
|
|
|
228
|
+func fastPgDataAuth(transactionContext application.TransactionContext, data domain.AuthedData, options ...option) error {
|
|
|
|
229
|
+ option := NewFastOptions(options...)
|
|
|
|
230
|
+ if option.DataAuthRequired && data != nil {
|
|
|
|
231
|
+ if data.BelongOrg() != option.OperateInfo.OrgId {
|
|
|
|
232
|
+ return application.ThrowError(application.BUSINESS_ERROR, "当前登录的组织机构与操作数据组织机构不一致")
|
|
|
|
233
|
+ }
|
|
|
|
234
|
+ }
|
|
217
|
return nil
|
235
|
return nil
|
|
218
|
}
|
236
|
}
|
|
|
|
237
|
+
|
|
|
|
238
|
+/***** 2.配置 *****/
|
|
|
|
239
|
+
|
|
|
|
240
|
+type FastOptions struct {
|
|
|
|
241
|
+ DataAuthRequired bool
|
|
|
|
242
|
+ OperateInfo *domain.OperateInfo
|
|
|
|
243
|
+}
|
|
|
|
244
|
+
|
|
|
|
245
|
+func NewFastOptions(options ...option) *FastOptions {
|
|
|
|
246
|
+ o := &FastOptions{
|
|
|
|
247
|
+ DataAuthRequired: false,
|
|
|
|
248
|
+ }
|
|
|
|
249
|
+ for i := 0; i < len(options); i++ {
|
|
|
|
250
|
+ options[i](o)
|
|
|
|
251
|
+ }
|
|
|
|
252
|
+ return o
|
|
|
|
253
|
+}
|
|
|
|
254
|
+
|
|
|
|
255
|
+type option func(options *FastOptions)
|
|
|
|
256
|
+
|
|
|
|
257
|
+// 需要数据权限
|
|
|
|
258
|
+func WithDataAuthRequired() option {
|
|
|
|
259
|
+ return func(options *FastOptions) {
|
|
|
|
260
|
+ options.DataAuthRequired = true
|
|
|
|
261
|
+ }
|
|
|
|
262
|
+}
|
|
|
|
263
|
+
|
|
|
|
264
|
+// WithOperator 操作人
|
|
|
|
265
|
+func WithOperator(op *domain.OperateInfo) option {
|
|
|
|
266
|
+ return func(options *FastOptions) {
|
|
|
|
267
|
+ options.OperateInfo = op
|
|
|
|
268
|
+ }
|
|
|
|
269
|
+} |