作者 郑周

1. 添加超级管理员类型

@@ -117,20 +117,28 @@ func (rs *RoleUserService) ListRole(in *command.UserRoleQueryCommand) (interface @@ -117,20 +117,28 @@ func (rs *RoleUserService) ListRole(in *command.UserRoleQueryCommand) (interface
117 117
118 // GetHrBp 当前操作人是否拥有HR-BP权限 (1表示有权限) 118 // GetHrBp 当前操作人是否拥有HR-BP权限 (1表示有权限)
119 func GetHrBp(transactionContext application.TransactionContext, companyId int, operatorId int) (int, error) { 119 func GetHrBp(transactionContext application.TransactionContext, companyId int, operatorId int) (int, error) {
120 - roleRepo := factory.CreateRoleRepository(map[string]interface{}{"transactionContext": transactionContext})  
121 - roleUserRepo := factory.CreateRoleUserRepository(map[string]interface{}{"transactionContext": transactionContext})  
122 - _, roleList, err := roleRepo.Find(map[string]interface{}{"type": domain.RoleTypeSystem, "companyId": companyId}) 120 + roleRepository := factory.CreateRoleRepository(map[string]interface{}{"transactionContext": transactionContext})
  121 + roleUserRepository := factory.CreateRoleUserRepository(map[string]interface{}{"transactionContext": transactionContext})
  122 + _, roles, err := roleRepository.Find(map[string]interface{}{"type": domain.RoleTypeSystem, "companyId": companyId})
123 if err != nil { 123 if err != nil {
124 return -1, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取角色信息列表"+err.Error()) 124 return -1, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取角色信息列表"+err.Error())
125 } 125 }
126 - _, userRoleList, err := roleUserRepo.Find(map[string]interface{}{"companyId": companyId, "userId": operatorId}) 126 + if len(roles) == 0 {
  127 + return -1, nil
  128 + }
  129 +
  130 + _, userRoles, err := roleUserRepository.Find(map[string]interface{}{"companyId": companyId, "userId": operatorId})
127 if err != nil { 131 if err != nil {
128 return -1, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取用户的角色信息列表"+err.Error()) 132 return -1, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取用户的角色信息列表"+err.Error())
129 } 133 }
  134 + if len(userRoles) == 0 {
  135 + return -1, nil
  136 + }
  137 +
130 hrBp := -1 138 hrBp := -1
131 loopFinish: 139 loopFinish:
132 - for _, userRole := range userRoleList {  
133 - for _, role := range roleList { 140 + for _, userRole := range userRoles {
  141 + for _, role := range roles {
134 if userRole.RoleId == role.Id { 142 if userRole.RoleId == role.Id {
135 hrBp = domain.RoleTypeSystem 143 hrBp = domain.RoleTypeSystem
136 break loopFinish 144 break loopFinish
@@ -142,20 +150,28 @@ loopFinish: @@ -142,20 +150,28 @@ loopFinish:
142 150
143 // GetSuperAdmin 当前操作人是否拥有超级管理员权限 (2表示有权限) 151 // GetSuperAdmin 当前操作人是否拥有超级管理员权限 (2表示有权限)
144 func GetSuperAdmin(transactionContext application.TransactionContext, companyId int, operatorId int) (int, error) { 152 func GetSuperAdmin(transactionContext application.TransactionContext, companyId int, operatorId int) (int, error) {
145 - roleRepo := factory.CreateRoleRepository(map[string]interface{}{"transactionContext": transactionContext})  
146 - roleUserRepo := factory.CreateRoleUserRepository(map[string]interface{}{"transactionContext": transactionContext})  
147 - _, roleList, err := roleRepo.Find(map[string]interface{}{"type": domain.RoleTypeSuperAdmin, "companyId": companyId}) 153 + roleRepository := factory.CreateRoleRepository(map[string]interface{}{"transactionContext": transactionContext})
  154 + roleUserRepository := factory.CreateRoleUserRepository(map[string]interface{}{"transactionContext": transactionContext})
  155 + _, roles, err := roleRepository.Find(map[string]interface{}{"type": domain.RoleTypeSuperAdmin, "companyId": companyId})
148 if err != nil { 156 if err != nil {
149 return -1, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取角色信息列表"+err.Error()) 157 return -1, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取角色信息列表"+err.Error())
150 } 158 }
151 - _, userRoleList, err := roleUserRepo.Find(map[string]interface{}{"companyId": companyId, "userId": operatorId}) 159 + if len(roles) == 0 {
  160 + return -1, nil
  161 + }
  162 +
  163 + _, userRoles, err := roleUserRepository.Find(map[string]interface{}{"companyId": companyId, "userId": operatorId})
152 if err != nil { 164 if err != nil {
153 return -1, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取用户的角色信息列表"+err.Error()) 165 return -1, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取用户的角色信息列表"+err.Error())
154 } 166 }
  167 + if len(userRoles) == 0 {
  168 + return -1, nil
  169 + }
  170 +
155 superAdmin := -1 171 superAdmin := -1
156 loopFinish: 172 loopFinish:
157 - for _, userRole := range userRoleList {  
158 - for _, role := range roleList { 173 + for _, userRole := range userRoles {
  174 + for _, role := range roles {
159 if userRole.RoleId == role.Id { 175 if userRole.RoleId == role.Id {
160 superAdmin = domain.RoleTypeSuperAdmin 176 superAdmin = domain.RoleTypeSuperAdmin
161 break loopFinish 177 break loopFinish