作者 tangxvhui
... ... @@ -6,9 +6,11 @@ import (
)
type UpdatePermissionCommand struct {
CompanyId int64 `cname:"公司Id"`
OptHrScore int `cname:"上级修改人资综评分数" json:"optHrScore" valid:"Required"`
OptEvalScore int `cname:"上级修改360°综评分数" json:"optEvalScore" valid:"Required"`
CompanyId int64 `cname:"公司Id"`
OptHrScore int `cname:"上级修改人资综评分数" json:"optHrScore" valid:"Required"`
OptEvalScore int `cname:"上级修改360°综评分数" json:"optEvalScore" valid:"Required"`
OptConfirmPerf int `cname:"是否需要员工确认绩效" json:"optConfirmPerf"`
CycleDeadLine *domain.CycleDeadline `cname:"周期评估各业务截止时间" json:"cycleDeadline"`
}
func (in *UpdatePermissionCommand) Valid(validation *validation.Validation) {
... ...
... ... @@ -64,10 +64,12 @@ func (rs *PermissionService) Get(in *command.GetPermissionCommand) (*domain.Perm
var permission *domain.Permission
if len(permissions) == 0 { // 不存在时,新增权限配置
value := &domain.Permission{
Id: 0,
CompanyId: in.CompanyId,
OptHrScore: domain.PermissionOff,
OptEvalScore: domain.PermissionOff,
Id: 0,
CompanyId: in.CompanyId,
OptHrScore: domain.PermissionOff,
OptEvalScore: domain.PermissionOff,
OptConfirmPerf: domain.PermissionOff,
CycleDeadLine: rs.defaultCycleDeadline(),
}
permission, err = permissionRepository.Insert(value)
if err != nil {
... ... @@ -75,9 +77,59 @@ func (rs *PermissionService) Get(in *command.GetPermissionCommand) (*domain.Perm
}
} else {
permission = permissions[0]
// 纠正数据
var isChange = false
if permission.OptHrScore == 0 {
isChange = true
permission.OptHrScore = domain.PermissionOff
}
if permission.OptEvalScore == 0 {
isChange = true
permission.OptEvalScore = domain.PermissionOff
}
if permission.OptConfirmPerf == 0 {
isChange = true
permission.OptConfirmPerf = domain.PermissionOff
}
if permission.CycleDeadLine == nil {
isChange = true
permission.CycleDeadLine = rs.defaultCycleDeadline()
}
if isChange {
permission, err = permissionRepository.Insert(permission)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
}
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return permission, nil
}
// 创建默认周期截止时间
func (rs *PermissionService) defaultCycleDeadline() *domain.CycleDeadline {
return &domain.CycleDeadline{
AssessmentSelf: domain.DeadlineTime{
Hour: 3 * 24,
Minute: 0,
},
AssessmentAll: domain.DeadlineTime{
Hour: 5 * 24,
Minute: 0,
},
AssessmentHr: domain.DeadlineTime{
Hour: 5 * 24,
Minute: 0,
},
AssessmentSuperior: domain.DeadlineTime{
Hour: 7 * 24,
Minute: 0,
},
ViewMyPerf: domain.DeadlineTime{
Hour: 9 * 24,
Minute: 0,
},
}
}
... ...
... ... @@ -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,32 +115,68 @@ 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) {
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})
// GetHrBp 当前操作人是否拥有HR-BP权限 (1表示有权限)
func GetHrBp(transactionContext application.TransactionContext, companyId int, operatorId int) (int, error) {
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())
}
// 拥有HRBP权限
hrbp := -1
for _, v := range userRoleList {
for _, v2 := range roleList {
if v.RoleId == v2.Id {
hrbp = 1
break
if len(userRoles) == 0 {
return -1, nil
}
hrBp := -1
loopFinish:
for _, userRole := range userRoles {
for _, role := range roles {
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) {
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())
}
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 userRoles {
for _, role := range roles {
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})
... ...
... ... @@ -8,13 +8,29 @@ const (
)
type Permission struct {
Id int64 `json:"id,string"`
CompanyId int64 `json:"companyId" comment:"公司ID" `
OptHrScore int `json:"optHrScore" comment:"上级是否可以修改人资综评分数"`
OptEvalScore int `json:"optEvalScore" comment:"上级是否可以修改360°综评分数"`
CreatedAt time.Time `json:"createdAt" comment:"创建时间"`
UpdatedAt time.Time `json:"updatedAt" comment:"更新时间"`
DeletedAt *time.Time `json:"deletedAt" comment:"删除时间"`
Id int64 `json:"id,string"`
CompanyId int64 `json:"companyId" comment:"公司ID" `
OptHrScore int `json:"optHrScore" comment:"上级是否可以修改人资综评分数"`
OptEvalScore int `json:"optEvalScore" comment:"上级是否可以修改360°综评分数"`
OptConfirmPerf int `json:"optConfirmPerf " comment:"是否需要员工确认绩效"`
CycleDeadLine *CycleDeadline `json:"cycleDeadline" comment:"周期评估各业务截止时间"`
CreatedAt time.Time `json:"createdAt" comment:"创建时间"`
UpdatedAt time.Time `json:"updatedAt" comment:"更新时间"`
DeletedAt *time.Time `json:"deletedAt" comment:"删除时间"`
}
// CycleDeadline 周期评估截止时间
type CycleDeadline struct {
AssessmentSelf DeadlineTime `json:"assessmentSelf" comment:"综合自评"`
AssessmentAll DeadlineTime `json:"assessmentAll" comment:"360评估"`
AssessmentHr DeadlineTime `json:"assessmentHr" comment:"人资评估"`
AssessmentSuperior DeadlineTime `json:"assessmentSuperior" comment:"上级评估"`
ViewMyPerf DeadlineTime `json:"viewMyPerf" comment:"查看我的绩效"`
}
type DeadlineTime struct {
Hour int `json:"hour" comment:"时"`
Minute int `json:"minute" comment:"分"`
}
type PermissionRepository interface {
... ...
... ... @@ -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 {
... ...
package models
import "time"
import (
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
"time"
)
type Permission struct {
tableName struct{} `comment:"配置权限" pg:"permission"`
Id int64 `comment:"ID" pg:"pk:id"`
CompanyId int64 `comment:"公司ID"`
OptHrScore int `comment:"上级是否可以修改人资综评分数"`
OptEvalScore int `comment:"上级是否可以修改360°综评分数"`
CreatedAt time.Time `comment:"创建时间"`
UpdatedAt time.Time `comment:"更新时间"`
DeletedAt *time.Time `comment:"删除时间"`
tableName struct{} `comment:"配置权限" pg:"permission"`
Id int64 `comment:"ID" pg:"pk:id"`
CompanyId int64 `comment:"公司ID"`
OptHrScore int `comment:"上级是否可以修改人资综评分数"`
OptEvalScore int `comment:"上级是否可以修改360°综评分数"`
OptConfirmPerf int `comment:"是否需要员工确认绩效"`
CycleDeadLine *domain.CycleDeadline `comment:"周期评估各业务截止时间"`
CreatedAt time.Time `comment:"创建时间"`
UpdatedAt time.Time `comment:"更新时间"`
DeletedAt *time.Time `comment:"删除时间"`
}
... ...
... ... @@ -22,25 +22,29 @@ func NewPermissionRepository(transactionContext *pgTransaction.TransactionContex
func (repo *PermissionRepository) TransformToDomain(m *models.Permission) domain.Permission {
return domain.Permission{
Id: m.Id,
CompanyId: m.CompanyId,
OptHrScore: m.OptHrScore,
OptEvalScore: m.OptEvalScore,
CreatedAt: m.CreatedAt.Local(),
UpdatedAt: m.UpdatedAt.Local(),
DeletedAt: m.DeletedAt,
Id: m.Id,
CompanyId: m.CompanyId,
OptHrScore: m.OptHrScore,
OptEvalScore: m.OptEvalScore,
OptConfirmPerf: m.OptConfirmPerf,
CycleDeadLine: m.CycleDeadLine,
CreatedAt: m.CreatedAt.Local(),
UpdatedAt: m.UpdatedAt.Local(),
DeletedAt: m.DeletedAt,
}
}
func (repo *PermissionRepository) TransformToModel(d *domain.Permission) models.Permission {
return models.Permission{
Id: d.Id,
CompanyId: d.CompanyId,
OptHrScore: d.OptHrScore,
OptEvalScore: d.OptEvalScore,
CreatedAt: d.CreatedAt,
UpdatedAt: d.UpdatedAt,
DeletedAt: d.DeletedAt,
Id: d.Id,
CompanyId: d.CompanyId,
OptHrScore: d.OptHrScore,
OptEvalScore: d.OptEvalScore,
OptConfirmPerf: d.OptConfirmPerf,
CycleDeadLine: d.CycleDeadLine,
CreatedAt: d.CreatedAt,
UpdatedAt: d.UpdatedAt,
DeletedAt: d.DeletedAt,
}
}
... ...
-- 权限表建新列
ALTER TABLE public."permission" ADD opt_confirm_perf int8 NULL DEFAULT 1;
COMMENT ON COLUMN public."permission".opt_confirm_perf IS '是否需要员工确认绩效';
ALTER TABLE public."permission" ADD cycle_deadline jsonb NULL;
COMMENT ON COLUMN public."permission".cycle_deadline IS '周期评估各业务截止时间';
... ...