作者 郑周

1. 添加超级管理员类型

@@ -113,6 +113,9 @@ func (rs *RoleService) Remove(in *command.DeleteRoleCommand) (interface{}, error @@ -113,6 +113,9 @@ func (rs *RoleService) Remove(in *command.DeleteRoleCommand) (interface{}, error
113 if role.Type == domain.RoleTypeSystem { 113 if role.Type == domain.RoleTypeSystem {
114 return nil, application.ThrowError(application.BUSINESS_ERROR, "系统预制角色不可删除") 114 return nil, application.ThrowError(application.BUSINESS_ERROR, "系统预制角色不可删除")
115 } 115 }
  116 + if role.Type == domain.RoleTypeSuperAdmin {
  117 + return nil, application.ThrowError(application.BUSINESS_ERROR, "超级管理员角色不可删除")
  118 + }
116 119
117 if _, err := roleRepository.Remove(role); err != nil { 120 if _, err := roleRepository.Remove(role); err != nil {
118 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 121 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
@@ -160,7 +163,7 @@ func (rs *RoleService) ListForUser(in *command.QueryRoleUserCommand) (interface{ @@ -160,7 +163,7 @@ func (rs *RoleService) ListForUser(in *command.QueryRoleUserCommand) (interface{
160 163
161 adapterList := make([]*adapter.RoleUserAdapter, 0) 164 adapterList := make([]*adapter.RoleUserAdapter, 0)
162 165
163 - // 如果不存在系统预支hrbp角色时,插入一条数据 166 + // 如果不存在系统预支hr-bp角色时,新增数据
164 var havaSystemType = false 167 var havaSystemType = false
165 for i := range roles { 168 for i := range roles {
166 if roles[i].Type == domain.RoleTypeSystem { 169 if roles[i].Type == domain.RoleTypeSystem {
@@ -190,6 +193,10 @@ func (rs *RoleService) ListForUser(in *command.QueryRoleUserCommand) (interface{ @@ -190,6 +193,10 @@ func (rs *RoleService) ListForUser(in *command.QueryRoleUserCommand) (interface{
190 193
191 for i := range roles { 194 for i := range roles {
192 v := roles[i] 195 v := roles[i]
  196 +
  197 + if v.Type == domain.RoleTypeSuperAdmin { // 超级管理员角色不显示到界面上
  198 + continue
  199 + }
193 _, tempList, err := ruRepository.FindAllContainUser(1, 10, in.CompanyId, v.Id) 200 _, tempList, err := ruRepository.FindAllContainUser(1, 10, in.CompanyId, v.Id)
194 if err != nil { 201 if err != nil {
195 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 202 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
@@ -115,10 +115,8 @@ func (rs *RoleUserService) ListRole(in *command.UserRoleQueryCommand) (interface @@ -115,10 +115,8 @@ func (rs *RoleUserService) ListRole(in *command.UserRoleQueryCommand) (interface
115 return tool_funs.SimpleWrapGridMap(total, tempList), nil 115 return tool_funs.SimpleWrapGridMap(total, tempList), nil
116 } 116 }
117 117
118 -// GetHRBP 当前操作人是否拥有HRBP权限  
119 -// 返回 1 是 表示具有hrbp 权限  
120 -  
121 -func GetHRBP(transactionContext application.TransactionContext, companyId int, operatorId int) (int, error) { 118 +// GetHrBp 当前操作人是否拥有HR-BP权限 (1表示有权限)
  119 +func GetHrBp(transactionContext application.TransactionContext, companyId int, operatorId int) (int, error) {
122 roleRepo := factory.CreateRoleRepository(map[string]interface{}{"transactionContext": transactionContext}) 120 roleRepo := factory.CreateRoleRepository(map[string]interface{}{"transactionContext": transactionContext})
123 roleUserRepo := factory.CreateRoleUserRepository(map[string]interface{}{"transactionContext": transactionContext}) 121 roleUserRepo := factory.CreateRoleUserRepository(map[string]interface{}{"transactionContext": transactionContext})
124 _, roleList, err := roleRepo.Find(map[string]interface{}{"type": domain.RoleTypeSystem, "companyId": companyId}) 122 _, roleList, err := roleRepo.Find(map[string]interface{}{"type": domain.RoleTypeSystem, "companyId": companyId})
@@ -129,18 +127,40 @@ func GetHRBP(transactionContext application.TransactionContext, companyId int, o @@ -129,18 +127,40 @@ func GetHRBP(transactionContext application.TransactionContext, companyId int, o
129 if err != nil { 127 if err != nil {
130 return -1, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取用户的角色信息列表"+err.Error()) 128 return -1, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取用户的角色信息列表"+err.Error())
131 } 129 }
132 - // 拥有HRBP权限  
133 - hrbp := -1  
134 - for _, v := range userRoleList {  
135 - for _, v2 := range roleList {  
136 - if v.RoleId == v2.Id {  
137 - hrbp = 1  
138 - break 130 + hrBp := -1
  131 +loopFinish:
  132 + for _, userRole := range userRoleList {
  133 + for _, role := range roleList {
  134 + if userRole.RoleId == role.Id {
  135 + hrBp = domain.RoleTypeSystem
  136 + break loopFinish
139 } 137 }
140 } 138 }
141 - if hrbp == 1 {  
142 - break 139 + }
  140 + return hrBp, nil
  141 +}
  142 +
  143 +// GetSuperAdmin 当前操作人是否拥有超级管理员权限 (2表示有权限)
  144 +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})
  148 + if err != nil {
  149 + return -1, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取角色信息列表"+err.Error())
  150 + }
  151 + _, userRoleList, err := roleUserRepo.Find(map[string]interface{}{"companyId": companyId, "userId": operatorId})
  152 + if err != nil {
  153 + return -1, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取用户的角色信息列表"+err.Error())
  154 + }
  155 + superAdmin := -1
  156 +loopFinish:
  157 + for _, userRole := range userRoleList {
  158 + for _, role := range roleList {
  159 + if userRole.RoleId == role.Id {
  160 + superAdmin = domain.RoleTypeSuperAdmin
  161 + break loopFinish
  162 + }
143 } 163 }
144 } 164 }
145 - return hrbp, nil 165 + return superAdmin, nil
146 } 166 }
@@ -2,6 +2,7 @@ package service @@ -2,6 +2,7 @@ package service
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
  5 + service "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/role"
5 "sort" 6 "sort"
6 "strconv" 7 "strconv"
7 "time" 8 "time"
@@ -29,28 +30,9 @@ func NewStaffAssessServeice() *StaffAssessServeice { @@ -29,28 +30,9 @@ func NewStaffAssessServeice() *StaffAssessServeice {
29 30
30 // 获取HRBP标记值 31 // 获取HRBP标记值
31 func (srv StaffAssessServeice) getHRBP(transactionContext application.TransactionContext, companyId int, operatorId int) (int, error) { 32 func (srv StaffAssessServeice) getHRBP(transactionContext application.TransactionContext, companyId int, operatorId int) (int, error) {
32 - roleRepo := factory.CreateRoleRepository(map[string]interface{}{"transactionContext": transactionContext})  
33 - roleUserRepo := factory.CreateRoleUserRepository(map[string]interface{}{"transactionContext": transactionContext})  
34 - _, roleList, err := roleRepo.Find(map[string]interface{}{"type": domain.RoleTypeSystem, "companyId": companyId}) 33 + hrbp, err := service.GetHrBp(transactionContext, companyId, operatorId)
35 if err != nil { 34 if err != nil {
36 - return -1, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取角色信息列表"+err.Error())  
37 - }  
38 - _, userRoleList, err := roleUserRepo.Find(map[string]interface{}{"companyId": companyId, "userId": operatorId})  
39 - if err != nil {  
40 - return -1, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取用户的角色信息列表"+err.Error())  
41 - }  
42 - // 拥有HRBP权限  
43 - hrbp := -1  
44 - for _, v := range userRoleList {  
45 - for _, v2 := range roleList {  
46 - if v.RoleId == v2.Id {  
47 - hrbp = 1  
48 - break  
49 - }  
50 - }  
51 - if hrbp == 1 {  
52 - break  
53 - } 35 + return -1, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
54 } 36 }
55 return hrbp, nil 37 return hrbp, nil
56 } 38 }
@@ -26,11 +26,11 @@ func (srv *SummaryEvaluationService) ExportAllEvaluationFinish(param *command.Qu @@ -26,11 +26,11 @@ func (srv *SummaryEvaluationService) ExportAllEvaluationFinish(param *command.Qu
26 _ = transactionContext.RollbackTransaction() 26 _ = transactionContext.RollbackTransaction()
27 }() 27 }()
28 //判断是否是hrbp 28 //判断是否是hrbp
29 - flagHrbp, err := roleService.GetHRBP(transactionContext, param.CompanyId, param.UserId) 29 + flagHrbp, err := roleService.GetHrBp(transactionContext, param.CompanyId, param.UserId)
30 if err != nil { 30 if err != nil {
31 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 31 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
32 } 32 }
33 - if flagHrbp != 1 { 33 + if flagHrbp != domain.RoleTypeSystem {
34 return nil, application.ThrowError(application.BUSINESS_ERROR, "暂无数据") 34 return nil, application.ThrowError(application.BUSINESS_ERROR, "暂无数据")
35 } 35 }
36 //判断是否是上级 36 //判断是否是上级
@@ -41,7 +41,7 @@ func (srv *SummaryEvaluationService) ExportAllEvaluationFinish(param *command.Qu @@ -41,7 +41,7 @@ func (srv *SummaryEvaluationService) ExportAllEvaluationFinish(param *command.Qu
41 "parentId": param.UserId, 41 "parentId": param.UserId,
42 "limit": 1, 42 "limit": 1,
43 }) 43 })
44 - if len(parentUser) == 0 && flagHrbp != 1 { 44 + if len(parentUser) == 0 && flagHrbp != domain.RoleTypeSystem {
45 return nil, application.ThrowError(application.BUSINESS_ERROR, "暂无数据") 45 return nil, application.ThrowError(application.BUSINESS_ERROR, "暂无数据")
46 } 46 }
47 evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{ 47 evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{
@@ -43,7 +43,7 @@ func (srv *SummaryEvaluationService) GetExecutorCycleList(param *command.QueryCy @@ -43,7 +43,7 @@ func (srv *SummaryEvaluationService) GetExecutorCycleList(param *command.QueryCy
43 "transactionContext": transactionContext, 43 "transactionContext": transactionContext,
44 }) 44 })
45 45
46 - flagHrbp, err := roleService.GetHRBP(transactionContext, param.CompanyId, param.UserId) 46 + flagHrbp, err := roleService.GetHrBp(transactionContext, param.CompanyId, param.UserId)
47 if err != nil { 47 if err != nil {
48 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 48 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
49 } 49 }
@@ -194,7 +194,7 @@ func (srv *SummaryEvaluationService) GetMenu(param *command.QueryMenu) (map[stri @@ -194,7 +194,7 @@ func (srv *SummaryEvaluationService) GetMenu(param *command.QueryMenu) (map[stri
194 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 194 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
195 } 195 }
196 } 196 }
197 - isHrbp, err := roleService.GetHRBP(transactionContext, param.CompanyId, param.UserId) 197 + isHrbp, err := roleService.GetHrBp(transactionContext, param.CompanyId, param.UserId)
198 if err != nil { 198 if err != nil {
199 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 199 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
200 } 200 }
@@ -1772,11 +1772,11 @@ func (srv *SummaryEvaluationService) ListAllEvaluationFinish(param *command.Quer @@ -1772,11 +1772,11 @@ func (srv *SummaryEvaluationService) ListAllEvaluationFinish(param *command.Quer
1772 _ = transactionContext.RollbackTransaction() 1772 _ = transactionContext.RollbackTransaction()
1773 }() 1773 }()
1774 //判断是否是hrbp 1774 //判断是否是hrbp
1775 - flagHrbp, err := roleService.GetHRBP(transactionContext, param.CompanyId, param.UserId) 1775 + flagHrbp, err := roleService.GetHrBp(transactionContext, param.CompanyId, param.UserId)
1776 if err != nil { 1776 if err != nil {
1777 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1777 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
1778 } 1778 }
1779 - if flagHrbp != 1 { 1779 + if flagHrbp != domain.RoleTypeSystem {
1780 return tool_funs.SimpleWrapGridMap(0, []string{}), nil 1780 return tool_funs.SimpleWrapGridMap(0, []string{}), nil
1781 } 1781 }
1782 //判断是否是上级 1782 //判断是否是上级
@@ -1788,7 +1788,7 @@ func (srv *SummaryEvaluationService) ListAllEvaluationFinish(param *command.Quer @@ -1788,7 +1788,7 @@ func (srv *SummaryEvaluationService) ListAllEvaluationFinish(param *command.Quer
1788 "parentId": param.UserId, 1788 "parentId": param.UserId,
1789 "limit": 1, 1789 "limit": 1,
1790 }) 1790 })
1791 - if len(parentUser) == 0 && flagHrbp != 1 { 1791 + if len(parentUser) == 0 && flagHrbp != domain.RoleTypeSystem {
1792 return tool_funs.SimpleWrapGridMap(0, []string{}), nil 1792 return tool_funs.SimpleWrapGridMap(0, []string{}), nil
1793 } 1793 }
1794 evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{ 1794 evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{
@@ -437,11 +437,11 @@ func (srv *SummaryEvaluationService) EvaluationHRBPList(param *command.QueryEval @@ -437,11 +437,11 @@ func (srv *SummaryEvaluationService) EvaluationHRBPList(param *command.QueryEval
437 }() 437 }()
438 438
439 // 必须是HRBP权限的人才能编辑操作 439 // 必须是HRBP权限的人才能编辑操作
440 - hrbp, err := service.GetHRBP(transactionContext, param.CompanyId, param.UserId) 440 + hrbp, err := service.GetHrBp(transactionContext, param.CompanyId, param.UserId)
441 if err != nil { 441 if err != nil {
442 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 442 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
443 } 443 }
444 - if hrbp != 1 { 444 + if hrbp != domain.RoleTypeSystem {
445 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限") 445 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")
446 } 446 }
447 447
@@ -738,11 +738,11 @@ func (srv *SummaryEvaluationService) EditEvaluationHRBP(param *command.EditEvalu @@ -738,11 +738,11 @@ func (srv *SummaryEvaluationService) EditEvaluationHRBP(param *command.EditEvalu
738 itemValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{"transactionContext": transactionContext}) 738 itemValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{"transactionContext": transactionContext})
739 739
740 // 必须是HRBP权限的人才能编辑操作 740 // 必须是HRBP权限的人才能编辑操作
741 - hrbp, err := service.GetHRBP(transactionContext, param.CompanyId, param.ExecutorId) 741 + hrbp, err := service.GetHrBp(transactionContext, param.CompanyId, param.ExecutorId)
742 if err != nil { 742 if err != nil {
743 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 743 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
744 } 744 }
745 - if hrbp != 1 { 745 + if hrbp != domain.RoleTypeSystem {
746 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限") 746 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")
747 } 747 }
748 748
@@ -135,11 +135,11 @@ func (us *UserService) EditParentUser(in *command.EditParentCommand) error { @@ -135,11 +135,11 @@ func (us *UserService) EditParentUser(in *command.EditParentCommand) error {
135 transactionContext.RollbackTransaction() 135 transactionContext.RollbackTransaction()
136 }() 136 }()
137 137
138 - hrbp, err := service.GetHRBP(transactionContext, in.CompanyId, in.OperatorId) 138 + hrbp, err := service.GetHrBp(transactionContext, in.CompanyId, in.OperatorId)
139 if err != nil { 139 if err != nil {
140 return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 140 return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
141 } 141 }
142 - if hrbp != 1 { 142 + if hrbp != domain.RoleTypeSystem {
143 return application.ThrowError(application.BUSINESS_ERROR, "HRBP权限的员工才能操作") 143 return application.ThrowError(application.BUSINESS_ERROR, "HRBP权限的员工才能操作")
144 } 144 }
145 145
@@ -177,11 +177,11 @@ func (us *UserService) ImportParentUser(in *command.ImportParentUserCommand) (in @@ -177,11 +177,11 @@ func (us *UserService) ImportParentUser(in *command.ImportParentUserCommand) (in
177 transactionContext.RollbackTransaction() 177 transactionContext.RollbackTransaction()
178 }() 178 }()
179 179
180 - hrbp, err := service.GetHRBP(transactionContext, in.CompanyId, in.OperatorId) 180 + hrbp, err := service.GetHrBp(transactionContext, in.CompanyId, in.OperatorId)
181 if err != nil { 181 if err != nil {
182 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 182 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
183 } 183 }
184 - if hrbp != 1 { 184 + if hrbp != domain.RoleTypeSystem {
185 return nil, application.ThrowError(application.BUSINESS_ERROR, "HRBP权限的员工才能操作") 185 return nil, application.ThrowError(application.BUSINESS_ERROR, "HRBP权限的员工才能操作")
186 } 186 }
187 userRepo := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext}) 187 userRepo := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext})
@@ -3,8 +3,9 @@ package domain @@ -3,8 +3,9 @@ package domain
3 import "time" 3 import "time"
4 4
5 const ( 5 const (
6 - RoleTypeCommon int = 0 // 角色类型-后台添加角色  
7 - RoleTypeSystem int = 1 // 角色类型-系统预制角色(不可删除、编辑) 6 + RoleTypeCommon int = 0 // 角色类型-添加角色
  7 + RoleTypeSystem int = 1 // 角色类型-系统预制角色HR-BP(不可删除、编辑)
  8 + RoleTypeSuperAdmin int = 2 // 角色类型-系统预制超级管理员(不可删除、编辑)
8 ) 9 )
9 10
10 type Role struct { 11 type Role struct {