...
|
...
|
@@ -5,11 +5,13 @@ import ( |
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain"
|
|
|
)
|
|
|
|
|
|
/***** 1.快速模块 *****/
|
|
|
|
|
|
// FastPgUser 快速返回领域用户
|
|
|
//
|
|
|
// transactionContext 事务
|
|
|
// userId 用户ID
|
|
|
func FastPgUser(transactionContext application.TransactionContext, userId int64) (domain.UserRepository, *domain.User, error) {
|
|
|
func FastPgUser(transactionContext application.TransactionContext, userId int64, options ...option) (domain.UserRepository, *domain.User, error) {
|
|
|
var rep domain.UserRepository
|
|
|
var mod *domain.User
|
|
|
var err error
|
...
|
...
|
@@ -28,6 +30,9 @@ func FastPgUser(transactionContext application.TransactionContext, userId int64) |
|
|
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
|
|
|
}
|
|
|
|
...
|
...
|
@@ -61,7 +66,7 @@ func FastPgUserBase(transactionContext application.TransactionContext, userBaseI |
|
|
//
|
|
|
// transactionContext 事务
|
|
|
// roleId 角色Id
|
|
|
func FastPgRole(transactionContext application.TransactionContext, roleId int64) (domain.RoleRepository, *domain.Role, error) {
|
|
|
func FastPgRole(transactionContext application.TransactionContext, roleId int64, options ...option) (domain.RoleRepository, *domain.Role, error) {
|
|
|
var rep domain.RoleRepository
|
|
|
var mod *domain.Role
|
|
|
var err error
|
...
|
...
|
@@ -80,6 +85,9 @@ func FastPgRole(transactionContext application.TransactionContext, roleId int64) |
|
|
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
|
|
|
}
|
|
|
|
...
|
...
|
@@ -213,6 +221,49 @@ func FastPgAccountDestroyRecord(transactionContext application.TransactionContex |
|
|
return rep, mod, err
|
|
|
}
|
|
|
|
|
|
func FastPgDataAuth(transactionContext application.TransactionContext, operateInfo *domain.OperateInfo) error {
|
|
|
// fastPgDataAuth 快速数据权限验证
|
|
|
//
|
|
|
// data 待认证的数据
|
|
|
// options 配置项
|
|
|
func fastPgDataAuth(transactionContext application.TransactionContext, data domain.AuthedData, options ...option) error {
|
|
|
option := NewFastOptions(options...)
|
|
|
if option.DataAuthRequired && data != nil {
|
|
|
if data.BelongOrg() != option.OperateInfo.OrgId {
|
|
|
return application.ThrowError(application.BUSINESS_ERROR, "当前登录的组织机构与操作数据组织机构不一致")
|
|
|
}
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
/***** 2.配置 *****/
|
|
|
|
|
|
type FastOptions struct {
|
|
|
DataAuthRequired 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
|
|
|
}
|
|
|
} |
...
|
...
|
|