作者 郑周

1. 添加超级管理员类型

... ... @@ -117,20 +117,28 @@ func (rs *RoleUserService) ListRole(in *command.UserRoleQueryCommand) (interface
// GetHrBp 当前操作人是否拥有HR-BP权限 (1表示有权限)
func GetHrBp(transactionContext application.TransactionContext, companyId int, operatorId int) (int, error) {
roleRepo := factory.CreateRoleRepository(map[string]interface{}{"transactionContext": transactionContext})
roleUserRepo := factory.CreateRoleUserRepository(map[string]interface{}{"transactionContext": transactionContext})
_, roleList, err := roleRepo.Find(map[string]interface{}{"type": domain.RoleTypeSystem, "companyId": companyId})
roleRepository := factory.CreateRoleRepository(map[string]interface{}{"transactionContext": transactionContext})
roleUserRepository := factory.CreateRoleUserRepository(map[string]interface{}{"transactionContext": transactionContext})
_, roles, err := roleRepository.Find(map[string]interface{}{"type": domain.RoleTypeSystem, "companyId": companyId})
if err != nil {
return -1, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取角色信息列表"+err.Error())
}
_, userRoleList, err := roleUserRepo.Find(map[string]interface{}{"companyId": companyId, "userId": operatorId})
if len(roles) == 0 {
return -1, nil
}
_, userRoles, err := roleUserRepository.Find(map[string]interface{}{"companyId": companyId, "userId": operatorId})
if err != nil {
return -1, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取用户的角色信息列表"+err.Error())
}
if len(userRoles) == 0 {
return -1, nil
}
hrBp := -1
loopFinish:
for _, userRole := range userRoleList {
for _, role := range roleList {
for _, userRole := range userRoles {
for _, role := range roles {
if userRole.RoleId == role.Id {
hrBp = domain.RoleTypeSystem
break loopFinish
... ... @@ -142,20 +150,28 @@ loopFinish:
// GetSuperAdmin 当前操作人是否拥有超级管理员权限 (2表示有权限)
func GetSuperAdmin(transactionContext application.TransactionContext, companyId int, operatorId int) (int, error) {
roleRepo := factory.CreateRoleRepository(map[string]interface{}{"transactionContext": transactionContext})
roleUserRepo := factory.CreateRoleUserRepository(map[string]interface{}{"transactionContext": transactionContext})
_, roleList, err := roleRepo.Find(map[string]interface{}{"type": domain.RoleTypeSuperAdmin, "companyId": companyId})
roleRepository := factory.CreateRoleRepository(map[string]interface{}{"transactionContext": transactionContext})
roleUserRepository := factory.CreateRoleUserRepository(map[string]interface{}{"transactionContext": transactionContext})
_, roles, err := roleRepository.Find(map[string]interface{}{"type": domain.RoleTypeSuperAdmin, "companyId": companyId})
if err != nil {
return -1, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取角色信息列表"+err.Error())
}
_, userRoleList, err := roleUserRepo.Find(map[string]interface{}{"companyId": companyId, "userId": operatorId})
if len(roles) == 0 {
return -1, nil
}
_, userRoles, err := roleUserRepository.Find(map[string]interface{}{"companyId": companyId, "userId": operatorId})
if err != nil {
return -1, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取用户的角色信息列表"+err.Error())
}
if len(userRoles) == 0 {
return -1, nil
}
superAdmin := -1
loopFinish:
for _, userRole := range userRoleList {
for _, role := range roleList {
for _, userRole := range userRoles {
for _, role := range roles {
if userRole.RoleId == role.Id {
superAdmin = domain.RoleTypeSuperAdmin
break loopFinish
... ...