作者 郑周

1. 添加超级管理员类型

... ... @@ -113,6 +113,9 @@ func (rs *RoleService) Remove(in *command.DeleteRoleCommand) (interface{}, error
if role.Type == domain.RoleTypeSystem {
return nil, application.ThrowError(application.BUSINESS_ERROR, "系统预制角色不可删除")
}
if role.Type == domain.RoleTypeSuperAdmin {
return nil, application.ThrowError(application.BUSINESS_ERROR, "超级管理员角色不可删除")
}
if _, err := roleRepository.Remove(role); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ... @@ -160,7 +163,7 @@ func (rs *RoleService) ListForUser(in *command.QueryRoleUserCommand) (interface{
adapterList := make([]*adapter.RoleUserAdapter, 0)
// 如果不存在系统预支hrbp角色时,插入一条数据
// 如果不存在系统预支hr-bp角色时,新增数据
var havaSystemType = false
for i := range roles {
if roles[i].Type == domain.RoleTypeSystem {
... ... @@ -190,6 +193,10 @@ func (rs *RoleService) ListForUser(in *command.QueryRoleUserCommand) (interface{
for i := range roles {
v := roles[i]
if v.Type == domain.RoleTypeSuperAdmin { // 超级管理员角色不显示到界面上
continue
}
_, tempList, err := ruRepository.FindAllContainUser(1, 10, in.CompanyId, v.Id)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ...
... ... @@ -115,10 +115,8 @@ func (rs *RoleUserService) ListRole(in *command.UserRoleQueryCommand) (interface
return tool_funs.SimpleWrapGridMap(total, tempList), nil
}
// GetHRBP 当前操作人是否拥有HRBP权限
// 返回 1 是 表示具有hrbp 权限
func GetHRBP(transactionContext application.TransactionContext, companyId int, operatorId int) (int, error) {
// 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})
... ... @@ -129,18 +127,40 @@ func GetHRBP(transactionContext application.TransactionContext, companyId int, o
if err != nil {
return -1, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取用户的角色信息列表"+err.Error())
}
// 拥有HRBP权限
hrbp := -1
for _, v := range userRoleList {
for _, v2 := range roleList {
if v.RoleId == v2.Id {
hrbp = 1
break
hrBp := -1
loopFinish:
for _, userRole := range userRoleList {
for _, role := range roleList {
if userRole.RoleId == role.Id {
hrBp = domain.RoleTypeSystem
break loopFinish
}
}
if hrbp == 1 {
break
}
return hrBp, nil
}
// 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})
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 err != nil {
return -1, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取用户的角色信息列表"+err.Error())
}
superAdmin := -1
loopFinish:
for _, userRole := range userRoleList {
for _, role := range roleList {
if userRole.RoleId == role.Id {
superAdmin = domain.RoleTypeSuperAdmin
break loopFinish
}
}
}
return hrbp, nil
return superAdmin, nil
}
... ...
... ... @@ -2,6 +2,7 @@ package service
import (
"fmt"
service "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/role"
"sort"
"strconv"
"time"
... ... @@ -29,28 +30,9 @@ func NewStaffAssessServeice() *StaffAssessServeice {
// 获取HRBP标记值
func (srv StaffAssessServeice) 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})
hrbp, err := service.GetHrBp(transactionContext, companyId, operatorId)
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 err != nil {
return -1, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取用户的角色信息列表"+err.Error())
}
// 拥有HRBP权限
hrbp := -1
for _, v := range userRoleList {
for _, v2 := range roleList {
if v.RoleId == v2.Id {
hrbp = 1
break
}
}
if hrbp == 1 {
break
}
return -1, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
return hrbp, nil
}
... ...
... ... @@ -26,11 +26,11 @@ func (srv *SummaryEvaluationService) ExportAllEvaluationFinish(param *command.Qu
_ = transactionContext.RollbackTransaction()
}()
//判断是否是hrbp
flagHrbp, err := roleService.GetHRBP(transactionContext, param.CompanyId, param.UserId)
flagHrbp, err := roleService.GetHrBp(transactionContext, param.CompanyId, param.UserId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if flagHrbp != 1 {
if flagHrbp != domain.RoleTypeSystem {
return nil, application.ThrowError(application.BUSINESS_ERROR, "暂无数据")
}
//判断是否是上级
... ... @@ -41,7 +41,7 @@ func (srv *SummaryEvaluationService) ExportAllEvaluationFinish(param *command.Qu
"parentId": param.UserId,
"limit": 1,
})
if len(parentUser) == 0 && flagHrbp != 1 {
if len(parentUser) == 0 && flagHrbp != domain.RoleTypeSystem {
return nil, application.ThrowError(application.BUSINESS_ERROR, "暂无数据")
}
evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{
... ...
... ... @@ -43,7 +43,7 @@ func (srv *SummaryEvaluationService) GetExecutorCycleList(param *command.QueryCy
"transactionContext": transactionContext,
})
flagHrbp, err := roleService.GetHRBP(transactionContext, param.CompanyId, param.UserId)
flagHrbp, err := roleService.GetHrBp(transactionContext, param.CompanyId, param.UserId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
... ... @@ -194,7 +194,7 @@ func (srv *SummaryEvaluationService) GetMenu(param *command.QueryMenu) (map[stri
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
}
isHrbp, err := roleService.GetHRBP(transactionContext, param.CompanyId, param.UserId)
isHrbp, err := roleService.GetHrBp(transactionContext, param.CompanyId, param.UserId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
... ... @@ -1772,11 +1772,11 @@ func (srv *SummaryEvaluationService) ListAllEvaluationFinish(param *command.Quer
_ = transactionContext.RollbackTransaction()
}()
//判断是否是hrbp
flagHrbp, err := roleService.GetHRBP(transactionContext, param.CompanyId, param.UserId)
flagHrbp, err := roleService.GetHrBp(transactionContext, param.CompanyId, param.UserId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if flagHrbp != 1 {
if flagHrbp != domain.RoleTypeSystem {
return tool_funs.SimpleWrapGridMap(0, []string{}), nil
}
//判断是否是上级
... ... @@ -1788,7 +1788,7 @@ func (srv *SummaryEvaluationService) ListAllEvaluationFinish(param *command.Quer
"parentId": param.UserId,
"limit": 1,
})
if len(parentUser) == 0 && flagHrbp != 1 {
if len(parentUser) == 0 && flagHrbp != domain.RoleTypeSystem {
return tool_funs.SimpleWrapGridMap(0, []string{}), nil
}
evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{
... ...
... ... @@ -437,11 +437,11 @@ func (srv *SummaryEvaluationService) EvaluationHRBPList(param *command.QueryEval
}()
// 必须是HRBP权限的人才能编辑操作
hrbp, err := service.GetHRBP(transactionContext, param.CompanyId, param.UserId)
hrbp, err := service.GetHrBp(transactionContext, param.CompanyId, param.UserId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if hrbp != 1 {
if hrbp != domain.RoleTypeSystem {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")
}
... ... @@ -738,11 +738,11 @@ func (srv *SummaryEvaluationService) EditEvaluationHRBP(param *command.EditEvalu
itemValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{"transactionContext": transactionContext})
// 必须是HRBP权限的人才能编辑操作
hrbp, err := service.GetHRBP(transactionContext, param.CompanyId, param.ExecutorId)
hrbp, err := service.GetHrBp(transactionContext, param.CompanyId, param.ExecutorId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if hrbp != 1 {
if hrbp != domain.RoleTypeSystem {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")
}
... ...
... ... @@ -135,11 +135,11 @@ func (us *UserService) EditParentUser(in *command.EditParentCommand) error {
transactionContext.RollbackTransaction()
}()
hrbp, err := service.GetHRBP(transactionContext, in.CompanyId, in.OperatorId)
hrbp, err := service.GetHrBp(transactionContext, in.CompanyId, in.OperatorId)
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if hrbp != 1 {
if hrbp != domain.RoleTypeSystem {
return application.ThrowError(application.BUSINESS_ERROR, "HRBP权限的员工才能操作")
}
... ... @@ -177,11 +177,11 @@ func (us *UserService) ImportParentUser(in *command.ImportParentUserCommand) (in
transactionContext.RollbackTransaction()
}()
hrbp, err := service.GetHRBP(transactionContext, in.CompanyId, in.OperatorId)
hrbp, err := service.GetHrBp(transactionContext, in.CompanyId, in.OperatorId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if hrbp != 1 {
if hrbp != domain.RoleTypeSystem {
return nil, application.ThrowError(application.BUSINESS_ERROR, "HRBP权限的员工才能操作")
}
userRepo := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext})
... ...
... ... @@ -3,8 +3,9 @@ package domain
import "time"
const (
RoleTypeCommon int = 0 // 角色类型-后台添加角色
RoleTypeSystem int = 1 // 角色类型-系统预制角色(不可删除、编辑)
RoleTypeCommon int = 0 // 角色类型-添加角色
RoleTypeSystem int = 1 // 角色类型-系统预制角色HR-BP(不可删除、编辑)
RoleTypeSuperAdmin int = 2 // 角色类型-系统预制超级管理员(不可删除、编辑)
)
type Role struct {
... ...