作者 tangxvhui

更新结构

@@ -14,3 +14,12 @@ func CreatePartnerInfoRepository(options map[string]interface{}) (domain.Partner @@ -14,3 +14,12 @@ func CreatePartnerInfoRepository(options map[string]interface{}) (domain.Partner
14 } 14 }
15 return repository.NewPartnerInfoRepository(transactionContext) 15 return repository.NewPartnerInfoRepository(transactionContext)
16 } 16 }
  17 +
  18 +//CreateAdminUserRepository 管理员信息
  19 +func CreateAdminUserRepository(options map[string]interface{}) (domain.AdminUserRepository, error) {
  20 + var transactionContext *transaction.TransactionContext
  21 + if value, ok := options["transactionContext"]; ok {
  22 + transactionContext = value.(*transaction.TransactionContext)
  23 + }
  24 + return repository.NewAdminUserRepository(transactionContext)
  25 +}
@@ -32,8 +32,8 @@ type AdminUserFindOneQuery struct { @@ -32,8 +32,8 @@ type AdminUserFindOneQuery struct {
32 } 32 }
33 33
34 type AdminUserRepository interface { 34 type AdminUserRepository interface {
35 - Save(*AdminUser) (*AdminUser, error)  
36 - Remove(user *AdminUser) (*AdminUser, error) 35 + // Save(*AdminUser) (*AdminUser, error)
  36 + // Remove(user *AdminUser) (*AdminUser, error)
37 FindOne(qureyOptions AdminUserFindOneQuery) (*AdminUser, error) 37 FindOne(qureyOptions AdminUserFindOneQuery) (*AdminUser, error)
38 - Find(queryOptions AdminUserFindQuery) (int, []AdminUser, error) 38 + // Find(queryOptions AdminUserFindQuery) (int, []*AdminUser, error)
39 } 39 }
@@ -19,8 +19,9 @@ type AdminUser struct { @@ -19,8 +19,9 @@ type AdminUser struct {
19 Password string 19 Password string
20 //是否是默认账号 20 //是否是默认账号
21 IsDefault bool `pg:",use_zero"` 21 IsDefault bool `pg:",use_zero"`
22 - //删除时间  
23 - DeleteAt int64 22 + //账号是否可用
  23 + IsUsable bool `json:"is_userable"`
  24 +
24 CreateAt time.Time 25 CreateAt time.Time
25 UpdateAt time.Time 26 UpdateAt time.Time
26 } 27 }
@@ -37,6 +38,5 @@ var _ pg.BeforeInsertHook = (*AdminUser)(nil) @@ -37,6 +38,5 @@ var _ pg.BeforeInsertHook = (*AdminUser)(nil)
37 func (user *AdminUser) BeforeInsert(ctx context.Context) (context.Context, error) { 38 func (user *AdminUser) BeforeInsert(ctx context.Context) (context.Context, error) {
38 user.CreateAt = time.Now() 39 user.CreateAt = time.Now()
39 user.UpdateAt = time.Now() 40 user.UpdateAt = time.Now()
40 - user.DeleteAt = 0  
41 return ctx, nil 41 return ctx, nil
42 } 42 }
  1 +package repository
  2 +
  3 +import (
  4 + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain"
  5 + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/models"
  6 + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/transaction"
  7 +)
  8 +
  9 +type AdminUserRepository struct {
  10 + transactionContext *transaction.TransactionContext
  11 +}
  12 +
  13 +var (
  14 + _ domain.AdminUserRepository = (*AdminUserRepository)(nil)
  15 +)
  16 +
  17 +func NewAdminUserRepository(transactionContext *transaction.TransactionContext) (*AdminUserRepository, error) {
  18 + if transactionContext == nil {
  19 + return nil, ERR_EMPTY_TC
  20 + }
  21 + return &AdminUserRepository{transactionContext: transactionContext}, nil
  22 +}
  23 +func (reponsitory AdminUserRepository) transformPgModelToDomainModel(adminuserModel *models.AdminUser) (domain.AdminUser, error) {
  24 + result := domain.AdminUser{}
  25 + return result, nil
  26 +}
  27 +
  28 +func (reponsitory AdminUserRepository) FindOne(queryOption domain.AdminUserFindOneQuery) (*domain.AdminUser, error) {
  29 + db := reponsitory.transactionContext.PgDd
  30 + adminuserModel := new(models.AdminUser)
  31 + query := db.Model(adminuserModel)
  32 +
  33 + if queryOption.AdminUserId > 0 {
  34 + query = query.Where("id=?", queryOption.AdminUserId)
  35 + }
  36 + if len(queryOption.AccountEqual) > 0 {
  37 + query = query.Where("admin_account=?", queryOption.AccountEqual)
  38 + }
  39 + err := query.First()
  40 + if err != nil {
  41 + return nil, err
  42 + }
  43 + adminUser, err := reponsitory.transformPgModelToDomainModel(adminuserModel)
  44 + return &adminUser, err
  45 +}
@@ -4,10 +4,13 @@ import ( @@ -4,10 +4,13 @@ import (
4 "github.com/astaxie/beego/context" 4 "github.com/astaxie/beego/context"
5 ) 5 )
6 6
7 -//根据权限编码检验请求是否可以执行  
8 -func PermissionCheck(permissionCode string, excludeUrl ...string) func(ctx *context.Context) { 7 +//PermissionCheck 根据权限编码检验请求是否可以执行
  8 +//permissionCode:权限编码
  9 +//excludeURL:跳过url
  10 +func AdminPermissionCheck(permissionCode string, excludeURL ...string) func(ctx *context.Context) {
9 11
10 return func(ctx *context.Context) { 12 return func(ctx *context.Context) {
11 //根据code检查权限数据,并排除excludeUrl指定的url 13 //根据code检查权限数据,并排除excludeUrl指定的url
  14 + //获取user 数据
12 } 15 }
13 } 16 }
@@ -9,7 +9,7 @@ import ( @@ -9,7 +9,7 @@ import (
9 func init() { 9 func init() {
10 adminRouter := beego.NewNamespace("/admin_user", 10 adminRouter := beego.NewNamespace("/admin_user",
11 //验证权限 11 //验证权限
12 - beego.NSBefore(middleware.PermissionCheck(domain.PERMINSSION_ADMIN_USER)), 12 + beego.NSBefore(middleware.AdminPermissionCheck(domain.PERMINSSION_ADMIN_USER)),
13 //其余的路由 13 //其余的路由
14 //... 14 //...
15 ) 15 )