作者 郑周

1. 增加权限字段

... ... @@ -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,
},
}
}
... ...
... ... @@ -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 {
... ...
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 '周期评估各业务截止时间';
... ...