作者 yangfu

修改: 1.系统功能模块 2.角色管理 3.用户管理 4.权限设置

@@ -11,6 +11,7 @@ import ( @@ -11,6 +11,7 @@ import (
11 "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/application/factory" 11 "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/application/factory"
12 "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/domain" 12 "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/domain"
13 "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/infrastructure/dao" 13 "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/infrastructure/dao"
  14 + "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/infrastructure/utils"
14 "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol" 15 "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol"
15 protocolx "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol/auth" 16 protocolx "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol/auth"
16 "time" 17 "time"
@@ -36,7 +37,7 @@ func (svr *AuthService) Login(header *protocol.RequestHeader, request *protocolx @@ -36,7 +37,7 @@ func (svr *AuthService) Login(header *protocol.RequestHeader, request *protocolx
36 transactionContext.RollbackTransaction() 37 transactionContext.RollbackTransaction()
37 }() 38 }()
38 39
39 - var user *domain.User 40 + var user *domain.Users
40 if user, err = UserRepository.FindOne(map[string]interface{}{"phone": request.UserName}); err != nil || user == nil { 41 if user, err = UserRepository.FindOne(map[string]interface{}{"phone": request.UserName}); err != nil || user == nil {
41 err = protocol.NewCustomMessage(1, "用户不存在!") 42 err = protocol.NewCustomMessage(1, "用户不存在!")
42 return 43 return
@@ -97,7 +98,7 @@ func (svr *AuthService) Profile(header *protocol.RequestHeader, request *protoco @@ -97,7 +98,7 @@ func (svr *AuthService) Profile(header *protocol.RequestHeader, request *protoco
97 transactionContext.RollbackTransaction() 98 transactionContext.RollbackTransaction()
98 }() 99 }()
99 100
100 - var user *domain.User 101 + var user *domain.Users
101 if user, err = UserRepository.FindOne(map[string]interface{}{"id": request.UserId}); err != nil { 102 if user, err = UserRepository.FindOne(map[string]interface{}{"id": request.UserId}); err != nil {
102 err = protocol.NewCustomMessage(1, "用户不存在") 103 err = protocol.NewCustomMessage(1, "用户不存在")
103 return 104 return
@@ -111,9 +112,8 @@ func (svr *AuthService) Profile(header *protocol.RequestHeader, request *protoco @@ -111,9 +112,8 @@ func (svr *AuthService) Profile(header *protocol.RequestHeader, request *protoco
111 "name": user.Name, 112 "name": user.Name,
112 "id": user.Id, 113 "id": user.Id,
113 "phone": user.Phone, 114 "phone": user.Phone,
114 - "address": user.Address,  
115 - "isAdmin": user.IsAdmin,  
116 - "roles": roles, 115 + "adminType": user.AdminType,
  116 + "roles": utils.LoadCustomField(roles, "Id", "RoleName"),
117 } 117 }
118 118
119 accessIds, _ := RoleAccessDao.GetRoleAccess(user.Roles...) 119 accessIds, _ := RoleAccessDao.GetRoleAccess(user.Roles...)
@@ -36,7 +36,7 @@ func (svr *CacheService) CacheUserAccess(userId int64) func() (interface{}, erro @@ -36,7 +36,7 @@ func (svr *CacheService) CacheUserAccess(userId int64) func() (interface{}, erro
36 transactionContext.RollbackTransaction() 36 transactionContext.RollbackTransaction()
37 }() 37 }()
38 38
39 - var user *domain.User 39 + var user *domain.Users
40 if user, err = UserRepository.FindOne(map[string]interface{}{"id": userId}); err != nil { 40 if user, err = UserRepository.FindOne(map[string]interface{}{"id": userId}); err != nil {
41 return []*domain.Access{}, nil 41 return []*domain.Access{}, nil
42 } 42 }
@@ -34,6 +34,6 @@ func CreateRoleRepository(transactionContext *transaction.TransactionContext) (d @@ -34,6 +34,6 @@ func CreateRoleRepository(transactionContext *transaction.TransactionContext) (d
34 return repository.NewRoleRepository(transactionContext) 34 return repository.NewRoleRepository(transactionContext)
35 } 35 }
36 36
37 -func CreateUserRepository(transactionContext *transaction.TransactionContext) (domain.UserRepository, error) { 37 +func CreateUserRepository(transactionContext *transaction.TransactionContext) (domain.UsersRepository, error) {
38 return repository.NewUserRepository(transactionContext) 38 return repository.NewUserRepository(transactionContext)
39 } 39 }
@@ -31,7 +31,7 @@ func (svr *RbacService) Access(header *protocol.RequestHeader, request *protocol @@ -31,7 +31,7 @@ func (svr *RbacService) Access(header *protocol.RequestHeader, request *protocol
31 31
32 var AccessRepository, _ = factory.CreateAccessRepository(transactionContext) 32 var AccessRepository, _ = factory.CreateAccessRepository(transactionContext)
33 var access []*domain.Access 33 var access []*domain.Access
34 - if _, access, err = AccessRepository.Find(map[string]interface{}{}); err != nil { 34 + if _, access, err = AccessRepository.Find(map[string]interface{}{"sortByParentId": "ASC", "sortBySort": "ASC"}); err != nil {
35 return 35 return
36 } 36 }
37 var rspList []interface{} 37 var rspList []interface{}
@@ -5,6 +5,7 @@ import ( @@ -5,6 +5,7 @@ import (
5 "github.com/tiptok/gocomm/pkg/log" 5 "github.com/tiptok/gocomm/pkg/log"
6 "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/application/factory" 6 "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/application/factory"
7 "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/domain" 7 "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/domain"
  8 + "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/infrastructure/utils"
8 "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol" 9 "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol"
9 protocolx "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol/role" 10 protocolx "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol/role"
10 "time" 11 "time"
@@ -45,7 +46,7 @@ func (svr *RoleService) CreateRole(header *protocol.RequestHeader, request *prot @@ -45,7 +46,7 @@ func (svr *RoleService) CreateRole(header *protocol.RequestHeader, request *prot
45 if m, err := RoleRepository.Save(newRole); err != nil { 46 if m, err := RoleRepository.Save(newRole); err != nil {
46 return nil, err 47 return nil, err
47 } else { 48 } else {
48 - rsp = m 49 + rsp = utils.LoadCustomField(m, "Id", "RoleName", "ParentId")
49 } 50 }
50 err = transactionContext.CommitTransaction() 51 err = transactionContext.CommitTransaction()
51 return 52 return
@@ -73,13 +74,17 @@ func (svr *RoleService) UpdateRole(header *protocol.RequestHeader, request *prot @@ -73,13 +74,17 @@ func (svr *RoleService) UpdateRole(header *protocol.RequestHeader, request *prot
73 if role, err = RoleRepository.FindOne(common.ObjectToMap(request)); err != nil { 74 if role, err = RoleRepository.FindOne(common.ObjectToMap(request)); err != nil {
74 return 75 return
75 } 76 }
  77 + if role.Id == request.ParentId {
  78 + err = protocol.NewCustomMessage(1, "父角色不能设为自己")
  79 + return
  80 + }
76 if request.ParentId > 0 { 81 if request.ParentId > 0 {
77 if role, e := RoleRepository.FindOne(map[string]interface{}{"id": request.ParentId}); e != nil || role == nil { 82 if role, e := RoleRepository.FindOne(map[string]interface{}{"id": request.ParentId}); e != nil || role == nil {
78 err = protocol.NewCustomMessage(1, "父角色不存在") 83 err = protocol.NewCustomMessage(1, "父角色不存在")
79 return 84 return
80 } 85 }
81 } 86 }
82 - if err = role.Update(common.ObjectToMap(request)); err != nil { 87 + if err = role.Update(map[string]interface{}{"roleName": request.RoleName, "parentId": request.ParentId}); err != nil {
83 return 88 return
84 } 89 }
85 if role, err = RoleRepository.Save(role); err != nil { 90 if role, err = RoleRepository.Save(role); err != nil {
@@ -111,7 +116,7 @@ func (svr *RoleService) GetRole(header *protocol.RequestHeader, request *protoco @@ -111,7 +116,7 @@ func (svr *RoleService) GetRole(header *protocol.RequestHeader, request *protoco
111 if role, err = RoleRepository.FindOne(common.ObjectToMap(request)); err != nil { 116 if role, err = RoleRepository.FindOne(common.ObjectToMap(request)); err != nil {
112 return 117 return
113 } 118 }
114 - rsp = map[string]interface{}{"role": role, "permission": ""} 119 + rsp = map[string]interface{}{"role": utils.LoadCustomField(role, "Id", "RoleName", "ParentId"), "permission": ""}
115 err = transactionContext.CommitTransaction() 120 err = transactionContext.CommitTransaction()
116 return 121 return
117 } 122 }
@@ -145,7 +150,7 @@ func (svr *RoleService) DeleteRole(header *protocol.RequestHeader, request *prot @@ -145,7 +150,7 @@ func (svr *RoleService) DeleteRole(header *protocol.RequestHeader, request *prot
145 if role, err = RoleRepository.Remove(role); err != nil { 150 if role, err = RoleRepository.Remove(role); err != nil {
146 return 151 return
147 } 152 }
148 - rsp = role 153 + rsp = utils.LoadCustomField(role, "Id", "RoleName", "ParentId")
149 err = transactionContext.CommitTransaction() 154 err = transactionContext.CommitTransaction()
150 return 155 return
151 } 156 }
@@ -169,12 +174,12 @@ func (svr *RoleService) ListRole(header *protocol.RequestHeader, request *protoc @@ -169,12 +174,12 @@ func (svr *RoleService) ListRole(header *protocol.RequestHeader, request *protoc
169 var RoleRepository, _ = factory.CreateRoleRepository(transactionContext) 174 var RoleRepository, _ = factory.CreateRoleRepository(transactionContext)
170 var role []*domain.Role 175 var role []*domain.Role
171 var total int64 176 var total int64
172 - if total, role, err = RoleRepository.Find(common.ObjectToMap(request)); err != nil { 177 + if _, role, err = RoleRepository.Find(map[string]interface{}{"orderById": "DESC"}); err != nil {
173 return 178 return
174 } 179 }
175 rsp = map[string]interface{}{ 180 rsp = map[string]interface{}{
176 "total": total, 181 "total": total,
177 - "list": role, 182 + "list": utils.LoadCustomField(role, "Id", "RoleName", "ParentId"),
178 } 183 }
179 err = transactionContext.CommitTransaction() 184 err = transactionContext.CommitTransaction()
180 return 185 return
@@ -8,6 +8,7 @@ import ( @@ -8,6 +8,7 @@ import (
8 "github.com/tiptok/gocomm/pkg/log" 8 "github.com/tiptok/gocomm/pkg/log"
9 "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/application/factory" 9 "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/application/factory"
10 "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/domain" 10 "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/domain"
  11 + "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/infrastructure/utils"
11 "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol" 12 "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol"
12 protocolx "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol/user" 13 protocolx "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol/user"
13 ) 14 )
@@ -31,13 +32,12 @@ func (svr *UserService) CreateUser(header *protocol.RequestHeader, request *prot @@ -31,13 +32,12 @@ func (svr *UserService) CreateUser(header *protocol.RequestHeader, request *prot
31 defer func() { 32 defer func() {
32 transactionContext.RollbackTransaction() 33 transactionContext.RollbackTransaction()
33 }() 34 }()
34 - newUser := &domain.User{ 35 + newUser := &domain.Users{
35 Name: request.Name, 36 Name: request.Name,
36 - Address: request.Address,  
37 Phone: request.Phone, 37 Phone: request.Phone,
38 - //Passwd: request.Passwd,  
39 Roles: request.Roles, 38 Roles: request.Roles,
40 - IsAdmin: request.IsAdmin, 39 + Status: 1,
  40 + AdminType: request.AdminType,
41 } 41 }
42 42
43 var UserRepository, _ = factory.CreateUserRepository(transactionContext) 43 var UserRepository, _ = factory.CreateUserRepository(transactionContext)
@@ -81,7 +81,7 @@ func (svr *UserService) UpdateUser(header *protocol.RequestHeader, request *prot @@ -81,7 +81,7 @@ func (svr *UserService) UpdateUser(header *protocol.RequestHeader, request *prot
81 }() 81 }()
82 82
83 var UserRepository, _ = factory.CreateUserRepository(transactionContext) 83 var UserRepository, _ = factory.CreateUserRepository(transactionContext)
84 - var user *domain.User 84 + var user *domain.Users
85 if user, err = UserRepository.FindOne(map[string]interface{}{"id": request.Id}); err != nil { 85 if user, err = UserRepository.FindOne(map[string]interface{}{"id": request.Id}); err != nil {
86 err = protocol.NewCustomMessage(1, "用户不存在") 86 err = protocol.NewCustomMessage(1, "用户不存在")
87 return 87 return
@@ -110,6 +110,7 @@ func (svr *UserService) UpdateUser(header *protocol.RequestHeader, request *prot @@ -110,6 +110,7 @@ func (svr *UserService) UpdateUser(header *protocol.RequestHeader, request *prot
110 func (svr *UserService) GetUser(header *protocol.RequestHeader, request *protocolx.GetUserRequest) (rsp interface{}, err error) { 110 func (svr *UserService) GetUser(header *protocol.RequestHeader, request *protocolx.GetUserRequest) (rsp interface{}, err error) {
111 var ( 111 var (
112 transactionContext, _ = factory.CreateTransactionContext(nil) 112 transactionContext, _ = factory.CreateTransactionContext(nil)
  113 + RoleRepository, _ = factory.CreateRoleRepository(transactionContext)
113 ) 114 )
114 rsp = &protocolx.GetUserResponse{} 115 rsp = &protocolx.GetUserResponse{}
115 if err = request.ValidateCommand(); err != nil { 116 if err = request.ValidateCommand(); err != nil {
@@ -125,12 +126,18 @@ func (svr *UserService) GetUser(header *protocol.RequestHeader, request *protoco @@ -125,12 +126,18 @@ func (svr *UserService) GetUser(header *protocol.RequestHeader, request *protoco
125 }() 126 }()
126 127
127 var UserRepository, _ = factory.CreateUserRepository(transactionContext) 128 var UserRepository, _ = factory.CreateUserRepository(transactionContext)
128 - var user *domain.User 129 + var user *domain.Users
129 if user, err = UserRepository.FindOne(common.ObjectToMap(request)); err != nil { 130 if user, err = UserRepository.FindOne(common.ObjectToMap(request)); err != nil {
130 err = application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 131 err = application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
131 return 132 return
132 } 133 }
133 - rsp = user 134 + retMap := map[string]interface{}{"id": user.Id, "name": user.Name, "phone": user.Phone, "adminType": user.AdminType, "status": user.Status}
  135 + if len(user.Roles) > 0 {
  136 + if _, roles, e := RoleRepository.Find(map[string]interface{}{"inRoleIds": user.Roles}); len(roles) > 0 && e == nil {
  137 + retMap["roles"] = utils.LoadCustomField(roles, "Id", "RoleName")
  138 + }
  139 + }
  140 + rsp = map[string]interface{}{"user": retMap}
134 if err = transactionContext.CommitTransaction(); err != nil { 141 if err = transactionContext.CommitTransaction(); err != nil {
135 err = application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 142 err = application.ThrowError(application.TRANSACTION_ERROR, err.Error())
136 return 143 return
@@ -156,7 +163,7 @@ func (svr *UserService) DeleteUser(header *protocol.RequestHeader, request *prot @@ -156,7 +163,7 @@ func (svr *UserService) DeleteUser(header *protocol.RequestHeader, request *prot
156 }() 163 }()
157 164
158 var UserRepository, _ = factory.CreateUserRepository(transactionContext) 165 var UserRepository, _ = factory.CreateUserRepository(transactionContext)
159 - var user *domain.User 166 + var user *domain.Users
160 if user, err = UserRepository.FindOne(common.ObjectToMap(request)); err != nil { 167 if user, err = UserRepository.FindOne(common.ObjectToMap(request)); err != nil {
161 err = application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 168 err = application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
162 return 169 return
@@ -191,15 +198,16 @@ func (svr *UserService) ListUser(header *protocol.RequestHeader, request *protoc @@ -191,15 +198,16 @@ func (svr *UserService) ListUser(header *protocol.RequestHeader, request *protoc
191 }() 198 }()
192 199
193 var UserRepository, _ = factory.CreateUserRepository(transactionContext) 200 var UserRepository, _ = factory.CreateUserRepository(transactionContext)
194 - var user []*domain.User 201 + var user []*domain.Users
195 var total int64 202 var total int64
196 - if total, user, err = UserRepository.Find(common.ObjectToMap(request)); err != nil { 203 + if total, user, err = UserRepository.Find(map[string]interface{}{"offset": request.PageNumber * request.PageSize, "limit": request.PageSize, "sortById": "DESC"}); err != nil {
197 err = application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 204 err = application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
198 return 205 return
199 } 206 }
200 rsp = map[string]interface{}{ 207 rsp = map[string]interface{}{
201 - "total": total,  
202 - "list": user, 208 + "totalRow": total,
  209 + "pageNumber": request.PageNumber,
  210 + "list": utils.LoadCustomField(user, "Id", "Name", "Phone", "IsAdmin", "Status"),
203 } 211 }
204 if err = transactionContext.CommitTransaction(); err != nil { 212 if err = transactionContext.CommitTransaction(); err != nil {
205 err = application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 213 err = application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -7,9 +7,9 @@ type Access struct { @@ -7,9 +7,9 @@ type Access struct {
7 // 父级id 7 // 父级id
8 ParentId int64 `json:"parentId"` 8 ParentId int64 `json:"parentId"`
9 // 权限名称 9 // 权限名称
10 - AccessName string `json:"accessName"` 10 + AccessName string `json:"name"`
11 // 权限编码 11 // 权限编码
12 - AccessCode string `json:"accessCode"` 12 + AccessCode string `json:"code"`
13 // 权限类型 menu button data 13 // 权限类型 menu button data
14 AccessType string `json:"accessType"` 14 AccessType string `json:"accessType"`
15 // 排序 15 // 排序
@@ -20,6 +20,10 @@ type Access struct { @@ -20,6 +20,10 @@ type Access struct {
20 Action string `json:"action"` 20 Action string `json:"action"`
21 // 所属功能模块 21 // 所属功能模块
22 Module string `json:"module"` 22 Module string `json:"module"`
  23 + // icon
  24 + Icon string `json:"icon"`
  25 + // 状态 1-启用 0-禁用
  26 + Status int `json:"status"`
23 } 27 }
24 28
25 type AccessRepository interface { 29 type AccessRepository interface {
1 package domain 1 package domain
2 2
3 -// User  
4 -type User struct { 3 +// Users
  4 +type Users struct {
5 // 唯一标识 5 // 唯一标识
6 Id int64 `json:"id"` 6 Id int64 `json:"id"`
7 // 名称 7 // 名称
8 Name string `json:"name"` 8 Name string `json:"name"`
9 // 地址 9 // 地址
10 - Address string `json:"address"` 10 + //Address string `json:"address"`
11 // 手机号 11 // 手机号
12 Phone string `json:"phone"` 12 Phone string `json:"phone"`
13 // 密码 13 // 密码
14 Passwd string `json:"-"` 14 Passwd string `json:"-"`
15 // 用户角色 15 // 用户角色
16 Roles []int64 `json:"roles"` 16 Roles []int64 `json:"roles"`
17 - // 是否是超级管理员 true:是 false:否  
18 - IsAdmin bool `json:"isAdmin"` 17 + // 1启用 2禁用
  18 + Status int `json:"status"`
  19 + // 管理员类型
  20 + AdminType int `json:"adminType"`
19 } 21 }
20 22
21 -type UserRepository interface {  
22 - Save(dm *User) (*User, error)  
23 - Remove(dm *User) (*User, error)  
24 - FindOne(queryOptions map[string]interface{}) (*User, error)  
25 - Find(queryOptions map[string]interface{}) (int64, []*User, error) 23 +type UsersRepository interface {
  24 + Save(dm *Users) (*Users, error)
  25 + Remove(dm *Users) (*Users, error)
  26 + FindOne(queryOptions map[string]interface{}) (*Users, error)
  27 + Find(queryOptions map[string]interface{}) (int64, []*Users, error)
26 } 28 }
27 29
28 -func (m *User) Identify() interface{} { 30 +func (m *Users) Identify() interface{} {
29 if m.Id == 0 { 31 if m.Id == 0 {
30 return nil 32 return nil
31 } 33 }
32 return m.Id 34 return m.Id
33 } 35 }
34 36
35 -func (m *User) Update(data map[string]interface{}) error { 37 +func (m *Users) Update(data map[string]interface{}) error {
36 if name, ok := data["name"]; ok { 38 if name, ok := data["name"]; ok {
37 m.Name = name.(string) 39 m.Name = name.(string)
38 } 40 }
39 - if address, ok := data["address"]; ok {  
40 - m.Address = address.(string)  
41 - }  
42 if phone, ok := data["phone"]; ok { 41 if phone, ok := data["phone"]; ok {
43 m.Phone = phone.(string) 42 m.Phone = phone.(string)
44 } 43 }
@@ -48,8 +47,11 @@ func (m *User) Update(data map[string]interface{}) error { @@ -48,8 +47,11 @@ func (m *User) Update(data map[string]interface{}) error {
48 if roles, ok := data["roles"]; ok { 47 if roles, ok := data["roles"]; ok {
49 m.Roles = roles.([]int64) 48 m.Roles = roles.([]int64)
50 } 49 }
51 - if isAdmin, ok := data["isAdmin"]; ok {  
52 - m.IsAdmin = isAdmin.(bool) 50 + if adminType, ok := data["adminType"]; ok {
  51 + m.AdminType = adminType.(int)
  52 + }
  53 + if status, ok := data["status"]; ok {
  54 + m.Status = status.(int)
53 } 55 }
54 return nil 56 return nil
55 } 57 }
@@ -33,7 +33,7 @@ func init() { @@ -33,7 +33,7 @@ func init() {
33 (*models.ProjectModuleVersion)(nil), 33 (*models.ProjectModuleVersion)(nil),
34 (*models.Role)(nil), 34 (*models.Role)(nil),
35 (*models.RoleAccess)(nil), 35 (*models.RoleAccess)(nil),
36 - (*models.User)(nil), 36 + (*models.Users)(nil),
37 } { 37 } {
38 err := DB.CreateTable(model, &orm.CreateTableOptions{ 38 err := DB.CreateTable(model, &orm.CreateTableOptions{
39 Temp: false, 39 Temp: false,
@@ -21,4 +21,8 @@ type Access struct { @@ -21,4 +21,8 @@ type Access struct {
21 Action string 21 Action string
22 // 所属功能模块 22 // 所属功能模块
23 Module string 23 Module string
  24 + // icon
  25 + Icon string
  26 + // 状态 1-启用 0-禁用
  27 + Status int
24 } 28 }
1 package models 1 package models
2 2
3 -// User  
4 -type User struct {  
5 - tableName struct{} `pg:"user"` 3 +// Users
  4 +type Users struct {
  5 + tableName struct{} `pg:"users"`
6 // 唯一标识 6 // 唯一标识
7 Id int64 7 Id int64
8 // 名称 8 // 名称
9 Name string 9 Name string
10 - // 地址  
11 - Address string  
12 // 手机号 10 // 手机号
13 Phone string 11 Phone string
14 // 密码 12 // 密码
15 Passwd string 13 Passwd string
16 // 用户角色 14 // 用户角色
17 Roles []int64 15 Roles []int64
18 - // 是否是超级管理员 true:是 false:否  
19 - IsAdmin bool 16 + // 1启用 2禁用
  17 + Status int
  18 + // 管理员类型 1:超级管理员 2:普通账号
  19 + AdminType int
20 } 20 }
@@ -66,8 +66,9 @@ func (repository *AccessRepository) Find(queryOptions map[string]interface{}) (i @@ -66,8 +66,9 @@ func (repository *AccessRepository) Find(queryOptions map[string]interface{}) (i
66 Accesss := make([]*domain.Access, 0) 66 Accesss := make([]*domain.Access, 0)
67 query := NewQuery(tx.Model(&AccessModels), queryOptions). 67 query := NewQuery(tx.Model(&AccessModels), queryOptions).
68 SetOrder("create_time", "sortByCreateTime"). 68 SetOrder("create_time", "sortByCreateTime").
69 - SetOrder("update_time", "sortByUpdateTime")  
70 - 69 + SetOrder("update_time", "sortByUpdateTime").
  70 + SetOrder("parent_id", "sortByParentId").
  71 + SetOrder("sort", "sortBySort")
71 if inAccessIds, ok := queryOptions["inAccessIds"]; ok { 72 if inAccessIds, ok := queryOptions["inAccessIds"]; ok {
72 query.Where("id in (?)", pg.In(inAccessIds)) 73 query.Where("id in (?)", pg.In(inAccessIds))
73 } 74 }
@@ -27,9 +27,10 @@ func (repository *RoleRepository) Save(dm *domain.Role) (*domain.Role, error) { @@ -27,9 +27,10 @@ func (repository *RoleRepository) Save(dm *domain.Role) (*domain.Role, error) {
27 if err = tx.Insert(m); err != nil { 27 if err = tx.Insert(m); err != nil {
28 return nil, err 28 return nil, err
29 } 29 }
  30 + dm.Id = m.Id
30 return dm, nil 31 return dm, nil
31 } 32 }
32 - if err = tx.Update(m); err != nil { 33 + if _, err = tx.Exec(`update role set role_name=?,parent_id=?,update_time=now() where id = ?`, m.RoleName, m.ParentId, m.Id); err != nil {
33 return nil, err 34 return nil, err
34 } 35 }
35 return dm, nil 36 return dm, nil
@@ -67,7 +68,9 @@ func (repository *RoleRepository) Find(queryOptions map[string]interface{}) (int @@ -67,7 +68,9 @@ func (repository *RoleRepository) Find(queryOptions map[string]interface{}) (int
67 query := NewQuery(tx.Model(&RoleModels), queryOptions). 68 query := NewQuery(tx.Model(&RoleModels), queryOptions).
68 SetWhere("parent_id=?", "parentId"). 69 SetWhere("parent_id=?", "parentId").
69 SetOrder("create_time", "sortByCreateTime"). 70 SetOrder("create_time", "sortByCreateTime").
70 - SetOrder("update_time", "sortByUpdateTime") 71 + SetOrder("update_time", "sortByUpdateTime").
  72 + SetOrder("id", "orderById")
  73 +
71 var err error 74 var err error
72 if inRoleIds, ok := queryOptions["inRoleIds"]; ok { 75 if inRoleIds, ok := queryOptions["inRoleIds"]; ok {
73 query.Where("id in (?)", pg.In(inRoleIds)) 76 query.Where("id in (?)", pg.In(inRoleIds))
@@ -9,14 +9,14 @@ import ( @@ -9,14 +9,14 @@ import (
9 "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/infrastructure/pg/transaction" 9 "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/infrastructure/pg/transaction"
10 ) 10 )
11 11
12 -type UserRepository struct { 12 +type UsersRepository struct {
13 transactionContext *transaction.TransactionContext 13 transactionContext *transaction.TransactionContext
14 } 14 }
15 15
16 -func (repository *UserRepository) Save(dm *domain.User) (*domain.User, error) { 16 +func (repository *UsersRepository) Save(dm *domain.Users) (*domain.Users, error) {
17 var ( 17 var (
18 err error 18 err error
19 - m = &models.User{} 19 + m = &models.Users{}
20 tx = repository.transactionContext.PgTx 20 tx = repository.transactionContext.PgTx
21 ) 21 )
22 if err = common.GobModelTransform(m, dm); err != nil { 22 if err = common.GobModelTransform(m, dm); err != nil {
@@ -35,10 +35,10 @@ func (repository *UserRepository) Save(dm *domain.User) (*domain.User, error) { @@ -35,10 +35,10 @@ func (repository *UserRepository) Save(dm *domain.User) (*domain.User, error) {
35 return dm, nil 35 return dm, nil
36 } 36 }
37 37
38 -func (repository *UserRepository) Remove(User *domain.User) (*domain.User, error) { 38 +func (repository *UsersRepository) Remove(User *domain.Users) (*domain.Users, error) {
39 var ( 39 var (
40 tx = repository.transactionContext.PgTx 40 tx = repository.transactionContext.PgTx
41 - UserModel = &models.User{Id: User.Identify().(int64)} 41 + UserModel = &models.Users{Id: User.Identify().(int64)}
42 ) 42 )
43 if _, err := tx.Model(UserModel).Where("id = ?", User.Id).Delete(); err != nil { 43 if _, err := tx.Model(UserModel).Where("id = ?", User.Id).Delete(); err != nil {
44 return User, err 44 return User, err
@@ -46,9 +46,9 @@ func (repository *UserRepository) Remove(User *domain.User) (*domain.User, error @@ -46,9 +46,9 @@ func (repository *UserRepository) Remove(User *domain.User) (*domain.User, error
46 return User, nil 46 return User, nil
47 } 47 }
48 48
49 -func (repository *UserRepository) FindOne(queryOptions map[string]interface{}) (*domain.User, error) { 49 +func (repository *UsersRepository) FindOne(queryOptions map[string]interface{}) (*domain.Users, error) {
50 tx := repository.transactionContext.PgTx 50 tx := repository.transactionContext.PgTx
51 - UserModel := new(models.User) 51 + UserModel := new(models.Users)
52 query := NewQuery(tx.Model(UserModel), queryOptions) 52 query := NewQuery(tx.Model(UserModel), queryOptions)
53 query.SetWhere("id = ?", "id") 53 query.SetWhere("id = ?", "id")
54 query.SetWhere("phone = ?", "phone") 54 query.SetWhere("phone = ?", "phone")
@@ -61,13 +61,15 @@ func (repository *UserRepository) FindOne(queryOptions map[string]interface{}) ( @@ -61,13 +61,15 @@ func (repository *UserRepository) FindOne(queryOptions map[string]interface{}) (
61 return repository.transformPgModelToDomainModel(UserModel) 61 return repository.transformPgModelToDomainModel(UserModel)
62 } 62 }
63 63
64 -func (repository *UserRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.User, error) { 64 +func (repository *UsersRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.Users, error) {
65 tx := repository.transactionContext.PgTx 65 tx := repository.transactionContext.PgTx
66 - var UserModels []*models.User  
67 - Users := make([]*domain.User, 0) 66 + var UserModels []*models.Users
  67 + Users := make([]*domain.Users, 0)
68 query := NewQuery(tx.Model(&UserModels), queryOptions). 68 query := NewQuery(tx.Model(&UserModels), queryOptions).
69 SetOrder("create_time", "sortByCreateTime"). 69 SetOrder("create_time", "sortByCreateTime").
70 - SetOrder("update_time", "sortByUpdateTime") 70 + SetOrder("update_time", "sortByUpdateTime").
  71 + SetOrder("id", "sortById").
  72 + SetLimit()
71 var err error 73 var err error
72 if query.AffectRow, err = query.SelectAndCount(); err != nil { 74 if query.AffectRow, err = query.SelectAndCount(); err != nil {
73 return 0, Users, err 75 return 0, Users, err
@@ -82,15 +84,15 @@ func (repository *UserRepository) Find(queryOptions map[string]interface{}) (int @@ -82,15 +84,15 @@ func (repository *UserRepository) Find(queryOptions map[string]interface{}) (int
82 return int64(query.AffectRow), Users, nil 84 return int64(query.AffectRow), Users, nil
83 } 85 }
84 86
85 -func (repository *UserRepository) transformPgModelToDomainModel(UserModel *models.User) (*domain.User, error) {  
86 - m := &domain.User{} 87 +func (repository *UsersRepository) transformPgModelToDomainModel(UserModel *models.Users) (*domain.Users, error) {
  88 + m := &domain.Users{}
87 err := common.GobModelTransform(m, UserModel) 89 err := common.GobModelTransform(m, UserModel)
88 return m, err 90 return m, err
89 } 91 }
90 92
91 -func NewUserRepository(transactionContext *transaction.TransactionContext) (*UserRepository, error) { 93 +func NewUserRepository(transactionContext *transaction.TransactionContext) (*UsersRepository, error) {
92 if transactionContext == nil { 94 if transactionContext == nil {
93 return nil, fmt.Errorf("transactionContext参数不能为nil") 95 return nil, fmt.Errorf("transactionContext参数不能为nil")
94 } 96 }
95 - return &UserRepository{transactionContext: transactionContext}, nil 97 + return &UsersRepository{transactionContext: transactionContext}, nil
96 } 98 }
  1 +package utils
  2 +
  3 +import (
  4 + "github.com/tiptok/gocomm/common"
  5 + "reflect"
  6 +)
  7 +
  8 +func LoadCustomField(src interface{}, fields ...string) interface{} {
  9 + typeSrc := reflect.TypeOf(src)
  10 + valueSrc := reflect.ValueOf(src)
  11 +
  12 + if v, ok := src.(reflect.Value); ok {
  13 + valueSrc = v
  14 + typeSrc = v.Type()
  15 + }
  16 + if typeSrc.Kind() == reflect.Ptr {
  17 + valueSrc = valueSrc.Elem()
  18 + }
  19 + k := valueSrc.Kind()
  20 + switch k {
  21 + case reflect.Array, reflect.Slice:
  22 + len := valueSrc.Len()
  23 + retSliceMap := make([]map[string]interface{}, 0)
  24 + if len == 0 {
  25 + return retSliceMap
  26 + }
  27 + for i := 0; i < len; i++ {
  28 + v := valueSrc.Index(i)
  29 + //if v.Kind()==reflect.Ptr
  30 + //item :=make(map[string]interface{})
  31 + //for _,filed :=range fields{
  32 + // f:= v.FieldByName(filed)
  33 + // item[common.CamelCase(filed, false)] = f.Interface()
  34 + //}
  35 + retSliceMap = append(retSliceMap, (LoadCustomField(v, fields...)).(map[string]interface{}))
  36 + }
  37 + return retSliceMap
  38 + case reflect.Struct:
  39 + retSliceMap := make(map[string]interface{})
  40 + for _, filed := range fields {
  41 + f := valueSrc.FieldByName(filed)
  42 + retSliceMap[common.CamelCase(filed, false)] = f.Interface()
  43 + }
  44 + return retSliceMap
  45 + default:
  46 + return src
  47 + }
  48 + return src
  49 +}
  1 +package utils
  2 +
  3 +import (
  4 + "github.com/tiptok/gocomm/common"
  5 + "testing"
  6 +)
  7 +
  8 +func TestLoadCustomField(t *testing.T) {
  9 +
  10 + type User struct {
  11 + Name string
  12 + Id int
  13 + }
  14 + v := []struct {
  15 + Name string
  16 + Id int
  17 + }{{Name: "c1", Id: 1}, {Name: "c2", Id: 2}, {Name: "c3", Id: 3}}
  18 + ret := LoadCustomField(&v, "Name")
  19 + t.Log(common.JsonAssertString(ret))
  20 +
  21 + v2 := struct {
  22 + Name string
  23 + Id int
  24 + }{Name: "c1", Id: 1}
  25 + ret2 := LoadCustomField(v2, "Name", "Id")
  26 + t.Log(common.JsonAssertString(ret2))
  27 +
  28 + v3 := []*User{&User{Name: "c1", Id: 1}, &User{Name: "c2", Id: 2}, &User{Name: "c3", Id: 3}}
  29 + ret3 := LoadCustomField(&v3, "Name")
  30 + t.Log(common.JsonAssertString(ret3))
  31 +}
@@ -3,6 +3,7 @@ package beego @@ -3,6 +3,7 @@ package beego
3 import ( 3 import (
4 "github.com/astaxie/beego" 4 "github.com/astaxie/beego"
5 "github.com/astaxie/beego/plugins/cors" 5 "github.com/astaxie/beego/plugins/cors"
  6 + "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/port/beego/middleware"
6 _ "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/port/beego/routers" 7 _ "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/port/beego/routers"
7 ) 8 )
8 9
@@ -15,10 +16,11 @@ func init() { @@ -15,10 +16,11 @@ func init() {
15 AllowCredentials: true, 16 AllowCredentials: true,
16 })) 17 }))
17 18
18 - //beego.InsertFilter("/user/*", beego.BeforeExec, middleware.InspectRoleAccess(""))  
19 - //beego.InsertFilter("/role/*", beego.BeforeExec, middleware.InspectRoleAccess(""))  
20 - //beego.InsertFilter("/project_module/*", beego.BeforeExec, middleware.InspectRoleAccess(""))  
21 - //beego.InsertFilter("/project_module_version/*", beego.BeforeExec, middleware.InspectRoleAccess("/project_module/*"))  
22 - //beego.InsertFilter("/project_module_files/*", beego.BeforeExec, middleware.InspectRoleAccess("/project_module/*"))  
23 - //beego.InsertFilter("/rbac/*", beego.BeforeExec, middleware.InspectRoleAccess("/role/*")) 19 + beego.InsertFilter("/auth/profile", beego.BeforeExec, middleware.CheckAuthorization)
  20 + beego.InsertFilter("/user/*", beego.BeforeExec, middleware.InspectRoleAccess(""))
  21 + beego.InsertFilter("/role/*", beego.BeforeExec, middleware.InspectRoleAccess(""))
  22 + beego.InsertFilter("/project_module/*", beego.BeforeExec, middleware.InspectRoleAccess(""))
  23 + beego.InsertFilter("/project_module_version/*", beego.BeforeExec, middleware.InspectRoleAccess("/project_module/*"))
  24 + beego.InsertFilter("/project_module_files/*", beego.BeforeExec, middleware.InspectRoleAccess("/project_module/*"))
  25 + beego.InsertFilter("/rbac/*", beego.BeforeExec, middleware.InspectRoleAccess("/role/*"))
24 } 26 }
@@ -13,20 +13,20 @@ type AuthController struct { @@ -13,20 +13,20 @@ type AuthController struct {
13 13
14 // Login 14 // Login
15 // 登录 15 // 登录
16 -func (this *AuthController) Login() { 16 +func (controller *AuthController) Login() {
17 var ( 17 var (
18 msg *protocol.ResponseMessage 18 msg *protocol.ResponseMessage
19 svr = auth.NewAuthService(nil) 19 svr = auth.NewAuthService(nil)
20 request *protocolx.LoginRequest 20 request *protocolx.LoginRequest
21 ) 21 )
22 defer func() { 22 defer func() {
23 - this.Resp(msg) 23 + controller.Resp(msg)
24 }() 24 }()
25 - if err := this.JsonUnmarshal(&request); err != nil {  
26 - msg = protocol.NewResponseMessage(2, "") 25 + if err := controller.JsonUnmarshal(&request); err != nil {
  26 + msg = protocol.NewResponseMessage(2, err.Error())
27 return 27 return
28 } 28 }
29 - header := this.GetRequestHeader(this.Ctx) 29 + header := controller.GetRequestHeader(controller.Ctx)
30 data, err := svr.Login(header, request) 30 data, err := svr.Login(header, request)
31 if err != nil { 31 if err != nil {
32 log.Error(err) 32 log.Error(err)
@@ -36,20 +36,20 @@ func (this *AuthController) Login() { @@ -36,20 +36,20 @@ func (this *AuthController) Login() {
36 36
37 // Logout 37 // Logout
38 // 测试 38 // 测试
39 -func (this *AuthController) Logout() { 39 +func (controller *AuthController) Logout() {
40 var ( 40 var (
41 msg *protocol.ResponseMessage 41 msg *protocol.ResponseMessage
42 svr = auth.NewAuthService(nil) 42 svr = auth.NewAuthService(nil)
43 request *protocolx.LogoutRequest 43 request *protocolx.LogoutRequest
44 ) 44 )
45 defer func() { 45 defer func() {
46 - this.Resp(msg) 46 + controller.Resp(msg)
47 }() 47 }()
48 - if err := this.JsonUnmarshal(&request); err != nil { 48 + if err := controller.JsonUnmarshal(&request); err != nil {
49 msg = protocol.NewResponseMessage(2, "") 49 msg = protocol.NewResponseMessage(2, "")
50 return 50 return
51 } 51 }
52 - header := this.GetRequestHeader(this.Ctx) 52 + header := controller.GetRequestHeader(controller.Ctx)
53 data, err := svr.Logout(header, request) 53 data, err := svr.Logout(header, request)
54 if err != nil { 54 if err != nil {
55 log.Error(err) 55 log.Error(err)
@@ -59,20 +59,17 @@ func (this *AuthController) Logout() { @@ -59,20 +59,17 @@ func (this *AuthController) Logout() {
59 59
60 // Profile 60 // Profile
61 // 获取当前用户数据 61 // 获取当前用户数据
62 -func (this *AuthController) Profile() { 62 +func (controller *AuthController) Profile() {
63 var ( 63 var (
64 msg *protocol.ResponseMessage 64 msg *protocol.ResponseMessage
65 svr = auth.NewAuthService(nil) 65 svr = auth.NewAuthService(nil)
66 - request *protocolx.ProfileRequest 66 + request = &protocolx.ProfileRequest{}
67 ) 67 )
68 defer func() { 68 defer func() {
69 - this.Resp(msg) 69 + controller.Resp(msg)
70 }() 70 }()
71 - if err := this.JsonUnmarshal(&request); err != nil {  
72 - msg = protocol.NewResponseMessage(2, "")  
73 - return  
74 - }  
75 - header := this.GetRequestHeader(this.Ctx) 71 + header := controller.GetRequestHeader(controller.Ctx)
  72 + request.UserId = header.UserId
76 data, err := svr.Profile(header, request) 73 data, err := svr.Profile(header, request)
77 if err != nil { 74 if err != nil {
78 log.Error(err) 75 log.Error(err)
@@ -82,17 +79,17 @@ func (this *AuthController) Profile() { @@ -82,17 +79,17 @@ func (this *AuthController) Profile() {
82 79
83 // CaptchaInit 80 // CaptchaInit
84 // 图形验证码初始化 81 // 图形验证码初始化
85 -func (this *AuthController) CaptchaInit() { 82 +func (controller *AuthController) CaptchaInit() {
86 var ( 83 var (
87 msg *protocol.ResponseMessage 84 msg *protocol.ResponseMessage
88 svr = auth.NewAuthService(nil) 85 svr = auth.NewAuthService(nil)
89 request = &protocolx.CaptchaInitRequest{} 86 request = &protocolx.CaptchaInitRequest{}
90 ) 87 )
91 defer func() { 88 defer func() {
92 - this.Resp(msg) 89 + controller.Resp(msg)
93 }() 90 }()
94 - request.UserIp = this.Ctx.Input.IP()  
95 - header := this.GetRequestHeader(this.Ctx) 91 + request.UserIp = controller.Ctx.Input.IP()
  92 + header := controller.GetRequestHeader(controller.Ctx)
96 data, err := svr.CaptchaInit(header, request) 93 data, err := svr.CaptchaInit(header, request)
97 if err != nil { 94 if err != nil {
98 log.Error(err) 95 log.Error(err)
@@ -102,20 +99,20 @@ func (this *AuthController) CaptchaInit() { @@ -102,20 +99,20 @@ func (this *AuthController) CaptchaInit() {
102 99
103 // ChangePassword 100 // ChangePassword
104 // 修改密码 101 // 修改密码
105 -func (this *AuthController) ChangePassword() { 102 +func (controller *AuthController) ChangePassword() {
106 var ( 103 var (
107 msg *protocol.ResponseMessage 104 msg *protocol.ResponseMessage
108 svr = auth.NewAuthService(nil) 105 svr = auth.NewAuthService(nil)
109 request *protocolx.ChangePasswordRequest 106 request *protocolx.ChangePasswordRequest
110 ) 107 )
111 defer func() { 108 defer func() {
112 - this.Resp(msg) 109 + controller.Resp(msg)
113 }() 110 }()
114 - if err := this.JsonUnmarshal(&request); err != nil { 111 + if err := controller.JsonUnmarshal(&request); err != nil {
115 msg = protocol.NewResponseMessage(2, "") 112 msg = protocol.NewResponseMessage(2, "")
116 return 113 return
117 } 114 }
118 - header := this.GetRequestHeader(this.Ctx) 115 + header := controller.GetRequestHeader(controller.Ctx)
119 data, err := svr.ChangePassword(header, request) 116 data, err := svr.ChangePassword(header, request)
120 if err != nil { 117 if err != nil {
121 log.Error(err) 118 log.Error(err)
@@ -6,7 +6,6 @@ import ( @@ -6,7 +6,6 @@ import (
6 "github.com/astaxie/beego" 6 "github.com/astaxie/beego"
7 "github.com/astaxie/beego/context" 7 "github.com/astaxie/beego/context"
8 "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol" 8 "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol"
9 - "strconv"  
10 ) 9 )
11 10
12 type BaseController struct { 11 type BaseController struct {
@@ -42,6 +41,9 @@ func (controller BaseController) GetLimitInfo() (offset int, limit int) { @@ -42,6 +41,9 @@ func (controller BaseController) GetLimitInfo() (offset int, limit int) {
42 //获取请求头信息 41 //获取请求头信息
43 func (controller *BaseController) GetRequestHeader(ctx *context.Context) *protocol.RequestHeader { 42 func (controller *BaseController) GetRequestHeader(ctx *context.Context) *protocol.RequestHeader {
44 h := &protocol.RequestHeader{} 43 h := &protocol.RequestHeader{}
45 - h.UserId, _ = strconv.ParseInt(ctx.Input.Header("x-mmm-id"), 10, 64) 44 + if ctx.Input.GetData("x-mmm-id") != nil {
  45 + v := ctx.Input.GetData("x-mmm-id")
  46 + h.UserId = int64(v.(int))
  47 + }
46 return h 48 return h
47 } 49 }
@@ -118,5 +118,5 @@ func (controller *UserController) ListUser() { @@ -118,5 +118,5 @@ func (controller *UserController) ListUser() {
118 if err != nil { 118 if err != nil {
119 log.Error(err) 119 log.Error(err)
120 } 120 }
121 - msg = protocol.NewResponseMessageData(data, err) 121 + msg = protocol.NewResponseMessageListData(data, err)
122 } 122 }
@@ -26,7 +26,7 @@ func CheckAuthorization(ctx *context.Context) { @@ -26,7 +26,7 @@ func CheckAuthorization(ctx *context.Context) {
26 }() 26 }()
27 authorization := ctx.Input.Header("Authorization") 27 authorization := ctx.Input.Header("Authorization")
28 if len(authorization) == 0 { 28 if len(authorization) == 0 {
29 - msg = protocol.NewResponseMessage(1, errAuthorization.Error()) 29 + msg = protocol.NewResponseMessage(-1, errAuthorization.Error())
30 return 30 return
31 } 31 }
32 var token string 32 var token string
@@ -38,7 +38,7 @@ func CheckAuthorization(ctx *context.Context) { @@ -38,7 +38,7 @@ func CheckAuthorization(ctx *context.Context) {
38 } 38 }
39 claim, err := common.ParseJWTToken(token) 39 claim, err := common.ParseJWTToken(token)
40 if err != nil { 40 if err != nil {
41 - msg = protocol.NewResponseMessage(1, errAuthorizationExpire.Error()) 41 + msg = protocol.NewResponseMessage(-1, errAuthorizationExpire.Error())
42 return 42 return
43 } 43 }
44 userId, _ := strconv.Atoi(claim.Username) 44 userId, _ := strconv.Atoi(claim.Username)
@@ -57,12 +57,12 @@ func CheckRoleAccess(ctx *context.Context, object, method string) { @@ -57,12 +57,12 @@ func CheckRoleAccess(ctx *context.Context, object, method string) {
57 }() 57 }()
58 userId := ctx.Input.GetData("x-mmm-id") 58 userId := ctx.Input.GetData("x-mmm-id")
59 if userId == nil { 59 if userId == nil {
60 - msg = protocol.NewResponseMessage(1, errAuthorization.Error()) 60 + msg = protocol.NewResponseMessage(-1, errAuthorization.Error())
61 return 61 return
62 } 62 }
63 validUserRole := cachex.CacheService{} 63 validUserRole := cachex.CacheService{}
64 if ok, _ := validUserRole.ValidUserAccess(int64(userId.(int)), object, method); !ok { 64 if ok, _ := validUserRole.ValidUserAccess(int64(userId.(int)), object, method); !ok {
65 - msg = protocol.NewResponseMessage(1, errAuthorization.Error()) 65 + msg = protocol.NewResponseMessage(-1, errAuthorization.Error())
66 return 66 return
67 } 67 }
68 return 68 return
@@ -9,6 +9,6 @@ func init() { @@ -9,6 +9,6 @@ func init() {
9 beego.Router("/auth/login", &controllers.AuthController{}, "post:Login") 9 beego.Router("/auth/login", &controllers.AuthController{}, "post:Login")
10 beego.Router("/auth/logout", &controllers.AuthController{}, "post:Logout") 10 beego.Router("/auth/logout", &controllers.AuthController{}, "post:Logout")
11 beego.Router("/auth/profile", &controllers.AuthController{}, "post:Profile") 11 beego.Router("/auth/profile", &controllers.AuthController{}, "post:Profile")
12 - beego.Router("/auth/captchaInit", &controllers.AuthController{}, "get:CaptchaInit") 12 + beego.Router("/auth/captcha-init", &controllers.AuthController{}, "post:CaptchaInit")
13 beego.Router("/auth/changePassword", &controllers.AuthController{}, "post:ChangePassword") 13 beego.Router("/auth/changePassword", &controllers.AuthController{}, "post:ChangePassword")
14 } 14 }
@@ -83,6 +83,11 @@ func NewResponseMessageData(data interface{}, err error) *ResponseMessage { @@ -83,6 +83,11 @@ func NewResponseMessageData(data interface{}, err error) *ResponseMessage {
83 return NewMesage(1) 83 return NewMesage(1)
84 } 84 }
85 85
  86 +func NewResponseMessageListData(data interface{}, err error) *ResponseMessage {
  87 + mapData := map[string]interface{}{"gridResult": data}
  88 + return NewResponseMessageData(mapData, err)
  89 +}
  90 +
86 func NewResponseMessage(code int, err string) *ResponseMessage { 91 func NewResponseMessage(code int, err string) *ResponseMessage {
87 return &ResponseMessage{ 92 return &ResponseMessage{
88 ErrorCode: ErrorCode{ 93 ErrorCode: ErrorCode{
@@ -16,8 +16,8 @@ type CreateUserRequest struct { @@ -16,8 +16,8 @@ type CreateUserRequest struct {
16 Passwd string `json:"passwd,omitempty"` 16 Passwd string `json:"passwd,omitempty"`
17 // 用户角色 17 // 用户角色
18 Roles []int64 `json:"roles,omitempty"` 18 Roles []int64 `json:"roles,omitempty"`
19 - // 是否是超级管理员 true:是 false:否  
20 - IsAdmin bool `json:"isAdmin,omitempty"` 19 + // 管理员类型 1:超级管理员 2:普通账号
  20 + AdminType int `json:"adminType"`
21 } 21 }
22 22
23 func (CreateUserRequest *CreateUserRequest) ValidateCommand() error { 23 func (CreateUserRequest *CreateUserRequest) ValidateCommand() error {
@@ -17,8 +17,10 @@ type UpdateUserRequest struct { @@ -17,8 +17,10 @@ type UpdateUserRequest struct {
17 Passwd string `json:"passwd,omitempty"` 17 Passwd string `json:"passwd,omitempty"`
18 // 用户角色 18 // 用户角色
19 Roles []int64 `json:"roles,omitempty"` 19 Roles []int64 `json:"roles,omitempty"`
20 - // 是否是超级管理员 true:是 false:否  
21 - IsAdmin bool `json:"isAdmin,omitempty"` 20 + // 1启用 2禁用
  21 + Status int `json:"status,omitempty"`
  22 + // 管理员类型 1:超级管理员 2:普通账号
  23 + AdminType int `json:"adminType"`
22 } 24 }
23 25
24 func (UpdateUserRequest *UpdateUserRequest) ValidateCommand() error { 26 func (UpdateUserRequest *UpdateUserRequest) ValidateCommand() error {
@@ -6,10 +6,15 @@ import ( @@ -6,10 +6,15 @@ import (
6 ) 6 )
7 7
8 type ListUserRequest struct { 8 type ListUserRequest struct {
  9 + PageSize int `json:"pageSize"`
  10 + PageNumber int `json:"pageNumber"`
9 } 11 }
10 12
11 func (ListUserRequest *ListUserRequest) ValidateCommand() error { 13 func (ListUserRequest *ListUserRequest) ValidateCommand() error {
12 valid := validation.Validation{} 14 valid := validation.Validation{}
  15 + if ListUserRequest.PageNumber == 0 {
  16 + ListUserRequest.PageNumber = 20
  17 + }
13 b, err := valid.Valid(ListUserRequest) 18 b, err := valid.Valid(ListUserRequest)
14 if err != nil { 19 if err != nil {
15 return err 20 return err