作者 tangxvhui

更新 考核结果的下发

... ... @@ -15,6 +15,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/summary_evaluation/command"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/dao"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/xredis"
)
type SummaryEvaluationService struct {
... ... @@ -596,9 +597,17 @@ func (srv *SummaryEvaluationService) EditEvaluationSelf(param *command.EditEvalu
// 员工提交自评内容后,
// 员工作为被评估人,
// 变更360评估/人资评估/的开始时间
// 或者上级评估的开始时间
// 或者变更上级评估的开始时间
// 或者生成考核结果
func (srv *SummaryEvaluationService) AfterCompletedEvaluationSelf(param *domain.SummaryEvaluation) error {
lock := xredis.NewLockSummaryEvaluation(param.TargetUser.UserId)
err := lock.Lock()
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, "未能完全提交评估内容")
}
defer func() {
lock.UnLock()
}()
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
... ... @@ -649,11 +658,32 @@ func (srv *SummaryEvaluationService) AfterCompletedEvaluationSelf(param *domain.
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if len(evaluationList) == 0 {
//没有上级评估、360评估、hrbp 评估
//直接生成考核结果记录
//
//直接进入考核结果阶段
_, evaluationList, err = evaluationRepo.Find(map[string]interface{}{
"targetUserId": param.TargetUser.UserId,
"typesList": []int{int(domain.EvaluationFinish)},
"cycleId": param.CycleId,
"limit": 1,
})
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if len(evaluationList) == 0 {
// 获取考核结果阶段
finishEvaluation := *param
finishEvaluation.BeginTime = time.Now()
finishEvaluation.CreatedAt = time.Now()
finishEvaluation.UpdatedAt = time.Now()
finishEvaluation.Executor = domain.StaffDesc{}
finishEvaluation.Id = 0
finishEvaluation.Types = domain.EvaluationFinish
err = evaluationRepo.Save(&finishEvaluation)
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存考核结果,"+err.Error())
}
}
}
if err := transactionContext.CommitTransaction(); err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ... @@ -661,9 +691,18 @@ func (srv *SummaryEvaluationService) AfterCompletedEvaluationSelf(param *domain.
return nil
}
// 被评估员工的人资评估 或者 360 评估,
// 提交员工的人资评估 或者 360 评估
// 变更上级评估的开始时间
// 或者生成考核结果
func (srv *SummaryEvaluationService) AfterCompletedEvaluation360Hrbp(param *domain.SummaryEvaluation) error {
lock := xredis.NewLockSummaryEvaluation(param.TargetUser.UserId)
err := lock.Lock()
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, "未能完全提交评估内容")
}
defer func() {
lock.UnLock()
}()
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
... ... @@ -701,7 +740,7 @@ func (srv *SummaryEvaluationService) AfterCompletedEvaluation360Hrbp(param *doma
"targetUserId": param.TargetUser.UserId,
"typesList": []int{int(domain.EvaluationSuper)},
"cycleId": param.CycleId,
"limit": 1000,
"limit": 10,
})
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ... @@ -722,6 +761,91 @@ func (srv *SummaryEvaluationService) AfterCompletedEvaluation360Hrbp(param *doma
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if len(evaluationList) == 0 {
//没有上级评估
//直接进入考核结果阶段
_, evaluationList, err = evaluationRepo.Find(map[string]interface{}{
"targetUserId": param.TargetUser.UserId,
"typesList": []int{int(domain.EvaluationFinish)},
"cycleId": param.CycleId,
"limit": 1,
})
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if len(evaluationList) == 0 {
finishEvaluation := *param
finishEvaluation.BeginTime = time.Now()
finishEvaluation.CreatedAt = time.Now()
finishEvaluation.UpdatedAt = time.Now()
finishEvaluation.Executor = domain.StaffDesc{}
finishEvaluation.Id = 0
finishEvaluation.Types = domain.EvaluationFinish
finishEvaluation.TotalScore = ""
finishEvaluation.TotalRating = []domain.RatingCodeNumber{}
err = evaluationRepo.Save(&finishEvaluation)
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存考核结果,"+err.Error())
}
}
}
if err := transactionContext.CommitTransaction(); err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
return nil
}
// 员工提交上级评估
// 生成考核结果
func (srv *SummaryEvaluationService) AfterCompletedEvaluationSuper(param *domain.SummaryEvaluation) error {
lock := xredis.NewLockSummaryEvaluation(param.TargetUser.UserId)
err := lock.Lock()
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, "未能完全提交评估内容")
}
defer func() {
lock.UnLock()
}()
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
//没有上级评估
//直接进入考核结果阶段
_, evaluationList, err := evaluationRepo.Find(map[string]interface{}{
"targetUserId": param.TargetUser.UserId,
"typesList": []int{int(domain.EvaluationFinish)},
"cycleId": param.CycleId,
"limit": 1,
})
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if len(evaluationList) == 0 {
finishEvaluation := *param
finishEvaluation.BeginTime = time.Now()
finishEvaluation.CreatedAt = time.Now()
finishEvaluation.UpdatedAt = time.Now()
finishEvaluation.Executor = domain.StaffDesc{}
finishEvaluation.Id = 0
finishEvaluation.Types = domain.EvaluationFinish
finishEvaluation.TotalScore = ""
finishEvaluation.TotalRating = []domain.RatingCodeNumber{}
err = evaluationRepo.Save(&finishEvaluation)
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存考核结果,"+err.Error())
}
}
if err := transactionContext.CommitTransaction(); err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
... ... @@ -1079,6 +1203,14 @@ func (srv *SummaryEvaluationService) EditEvaluationSuper(param *command.EditEval
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if !param.IsTemporary {
err = srv.AfterCompletedEvaluationSuper(evaluationData)
if err != nil {
return nil, err
}
}
itemValueAdapter := srv.buildSummaryItemValue(itemList, itemValueList)
return map[string][]adapter.EvaluationItemAdapter{
"EvaluationItems": itemValueAdapter,
... ...
... ... @@ -42,6 +42,7 @@ func (itemValue *SummaryEvaluationValue) SetBlankValue(evaluation *SummaryEvalua
itemValue.Weight = item.Weight
itemValue.CreatedAt = time.Now()
itemValue.UpdatedAt = time.Now()
itemValue.Executor = evaluation.Executor
}
// 填充评估的内容
... ...
... ... @@ -15,6 +15,7 @@ type SummaryEvaluationValue struct {
Value string //评估填写的评分
Score string //评定得分
Types int //评估类型
Executor domain.StaffDesc //填写评估的用户,执行人
Weight float64 //权重
Rating domain.RatingLevel //评级填写值
Remark string //填写的内容反馈
... ...
... ... @@ -30,6 +30,7 @@ func (repo *SummaryEvaluationValueRepository) TransformToDomain(d *models.Summar
Score: d.Score,
Types: domain.EvaluationType(d.Types),
Remark: d.Remark,
Executor: d.Executor,
Weight: d.Weight,
Rating: d.Rating,
CreatedAt: d.CreatedAt,
... ... @@ -45,6 +46,7 @@ func (repo *SummaryEvaluationValueRepository) Save(param *domain.SummaryEvaluati
Value: param.Value,
Score: param.Score,
Types: int(param.Types),
Executor: param.Executor,
Weight: param.Weight,
Rating: param.Rating,
Remark: param.Remark,
... ...
... ... @@ -10,8 +10,8 @@ type LockSummaryEvaluation struct {
m *redsync.Mutex
}
func NewLockSummaryEvaluation(id int) *LockSummaryEvaluation {
key := fmt.Sprintf("performance:summary_evaluation:%d", id)
func NewLockSummaryEvaluation(targetUserId int) *LockSummaryEvaluation {
key := fmt.Sprintf("performance:summary_evaluation:%d", targetUserId)
return &LockSummaryEvaluation{
m: rsync.NewMutex(key),
... ...