作者 郑周

1. 修复BUG 4096 考核评分结果显示优先级顺序(考核评分 -> 上级评分 -> 360+HR+自评)

... ... @@ -1349,7 +1349,6 @@ func (srv *SummaryEvaluationService) ConfirmScoreEvaluation(param *command.Confi
}()
evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{"transactionContext": transactionContext})
evaluationItemRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{"transactionContext": transactionContext})
itemValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{"transactionContext": transactionContext})
// 考核结果
... ... @@ -1380,6 +1379,8 @@ func (srv *SummaryEvaluationService) ConfirmScoreEvaluation(param *command.Confi
if len(itemValues) > 0 {
// do nothing...
} else {
evaluationItemRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{"transactionContext": transactionContext})
// 周期内所有评估类型
_, evaluationList, err := evaluationRepo.Find(map[string]interface{}{
"companyId": result.CompanyId,
... ... @@ -1399,12 +1400,8 @@ func (srv *SummaryEvaluationService) ConfirmScoreEvaluation(param *command.Confi
}
}
// 评估内容和值
var itemList []*domain.EvaluationItemUsed
var itemValues []*domain.SummaryEvaluationValue
// 获取自评模板
_, itemList, err = evaluationItemRepo.Find(map[string]interface{}{"evaluationProjectId": result.EvaluationProjectId, "nodeType": domain.LinkNodeSelfAssessment})
_, itemList, err := evaluationItemRepo.Find(map[string]interface{}{"evaluationProjectId": result.EvaluationProjectId, "nodeType": domain.LinkNodeSelfAssessment})
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
... ... @@ -1559,41 +1556,41 @@ func (srv *SummaryEvaluationService) GetTargetEvaluationResult(param *command.Qu
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
var result *domain.SummaryEvaluation // 绩效考核结果项
var super *domain.SummaryEvaluation // 上级评估
for i := range evaluationList {
it := evaluationList[i]
if it.Types == domain.EvaluationFinish {
result = it
continue
}
if it.Types == domain.EvaluationSuper {
super = it
continue
break
}
}
if result == nil {
return &adapter.EvaluationInfoSuperAdapter{}, nil
}
// 评估内容和值
var itemList []*domain.EvaluationItemUsed
var itemValues []*domain.SummaryEvaluationValue
// 获取自评模板内容
_, itemList, err = evaluationItemRepo.Find(map[string]interface{}{"evaluationProjectId": result.EvaluationProjectId, "nodeType": domain.LinkNodeSelfAssessment})
_, itemList, err := evaluationItemRepo.Find(map[string]interface{}{"evaluationProjectId": result.EvaluationProjectId, "nodeType": domain.LinkNodeSelfAssessment})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 获取考核结果评分
_, itemValues, err = itemValueRepo.Find(map[string]interface{}{"summaryEvaluationId": result.Id})
_, itemValues, err := itemValueRepo.Find(map[string]interface{}{"summaryEvaluationId": result.Id})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 不存在考核结果评分时(考核评分 -> 上级评分 -> 360+HR+自评)
if len(itemValues) == 0 {
var super *domain.SummaryEvaluation // 上级评估
for i := range evaluationList {
it := evaluationList[i]
if it.Types == domain.EvaluationSuper {
super = it
break
}
}
if super != nil {
_, itemValues, err = itemValueRepo.Find(map[string]interface{}{"summaryEvaluationId": super.Id}) // 获取已填写的评估内容
if err != nil {
... ... @@ -1610,13 +1607,13 @@ func (srv *SummaryEvaluationService) GetTargetEvaluationResult(param *command.Qu
}
if len(evaluationIds) > 0 {
// 获取已填写的评估内容
_, itemValues, err = itemValueRepo.Find(map[string]interface{}{"summaryEvaluationIdList": evaluationIds})
_, otherValues, err := itemValueRepo.Find(map[string]interface{}{"summaryEvaluationIdList": evaluationIds})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 更新填写值
itemValues, err = srv.updateItemValuePriority(result, itemList, itemValues, false)
itemValues, err = srv.updateItemValuePriority(result, itemList, otherValues, false)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
... ...
... ... @@ -724,131 +724,7 @@ func (srv *SummaryEvaluationService) GetEvaluationHRBPComplete(param *command.Qu
return &itemValuesAdapter, nil
}
// EditEvaluationHRBP 编辑提交人资综评
// func (srv *SummaryEvaluationService) EditEvaluationHRBP(param *command.EditEvaluationValue) (map[string][]adapter.EvaluationItemAdapter, error) {
// lock := xredis.NewLockSummaryEvaluationId(param.SummaryEvaluationId)
// err := lock.Lock()
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "未能完全提交评估内容")
// }
// defer func() {
// lock.UnLock()
// }()
// transactionContext, err := factory.CreateTransactionContext(nil)
// if err != nil {
// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
// }
// if err := transactionContext.StartTransaction(); err != nil {
// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
// }
// defer func() {
// _ = transactionContext.RollbackTransaction()
// }()
// userRepo := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext})
// evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{"transactionContext": transactionContext})
// itemUsedRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{"transactionContext": transactionContext})
// itemValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{"transactionContext": transactionContext})
// // 必须是HRBP权限的人才能编辑操作
// hrbp, err := roleService.GetHrBp(transactionContext, param.CompanyId, param.ExecutorId)
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// if hrbp != domain.RoleTypeSystem {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")
// }
// summaryEvaluation, err := evaluationRepo.FindOne(map[string]interface{}{"id": param.SummaryEvaluationId})
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// if summaryEvaluation.Types != domain.EvaluationHrbp {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")
// }
// if summaryEvaluation.CompanyId != param.CompanyId {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")
// }
// _, evaluationList, err := evaluationRepo.Find(map[string]interface{}{
// "targetUserId": summaryEvaluation.TargetUser.UserId,
// "typesList": []int{int(domain.EvaluationFinish)},
// "cycleId": summaryEvaluation.CycleId,
// "limit": 1,
// })
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// // 如果目标员工已经确认考核结果,就不能在进行评估编辑
// if len(evaluationList) > 0 && evaluationList[0].CheckResult == domain.EvaluationCheckCompleted {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "用户已经确认该周期的考核结果,不能再编辑!")
// }
// // 自评评估内容(自评模板、筛选项目评估人)
// _, itemList, err := itemUsedRepo.Find(map[string]interface{}{
// "evaluationProjectId": summaryEvaluation.EvaluationProjectId,
// "nodeType": domain.LinkNodeSelfAssessment,
// "evaluatorId": -1,
// })
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// // 评估内容对应的分数
// _, itemValueList, err := itemValueRepo.Find(map[string]interface{}{"summaryEvaluationId": summaryEvaluation.Id})
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// err = srv.editEvaluationValue(summaryEvaluation, &itemValueList, itemList, param.EvaluationItems, nil, param.IsTemporary)
// if err != nil {
// return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
// }
// if !param.IsTemporary {
// //变更评估状态为已填写
// summaryEvaluation.Status = domain.EvaluationCompleted
// }
// //保存填写值
// for _, v := range itemValueList {
// err = itemValueRepo.Save(v)
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// }
// // 针对HRBP类型,更新最后一次操作的HRBP人
// user, err := userRepo.FindOne(map[string]interface{}{"id": param.ExecutorId})
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// summaryEvaluation.Executor.UserId = param.ExecutorId
// summaryEvaluation.Executor.Account = user.Account
// summaryEvaluation.Executor.UserName = user.Name
// summaryEvaluation.Executor.CompanyName = "" // 暂时无用
// summaryEvaluation.Status = domain.EvaluationCompleted
// //保存填写值
// err = evaluationRepo.Save(summaryEvaluation)
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// if err := transactionContext.CommitTransaction(); err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// if !param.IsTemporary {
// err = srv.AfterCompletedEvaluation360Hrbp(summaryEvaluation)
// if err != nil {
// return nil, err
// }
// }
// itemValueAdapter := srv.buildSummaryItemValue(itemList, itemValueList)
// return map[string][]adapter.EvaluationItemAdapter{
// "evaluationItems": itemValueAdapter,
// }, nil
// }
// 修改周期考核的分数
// ModifyFinishScore 修改周期考核的分数
func (srv *SummaryEvaluationService) ModifyFinishScore(param *command.ModifyFinishScore) error {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
... ... @@ -869,27 +745,115 @@ func (srv *SummaryEvaluationService) ModifyFinishScore(param *command.ModifyFini
return application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")
}
//获取周期评估任务finish
// 获取周期评估任务finish
evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{"transactionContext": transactionContext})
_, evaluationList, err := evaluationRepo.Find(map[string]interface{}{
"id": []int{param.SummaryEvaluationId},
"companyId": param.CompanyId,
})
itemValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{"transactionContext": transactionContext})
_, evaluationList, err := evaluationRepo.Find(map[string]interface{}{"id": []int{param.SummaryEvaluationId}, "companyId": param.CompanyId})
if err != nil {
return application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
if len(evaluationList) == 0 {
return nil
}
evaluationData := evaluationList[0]
if evaluationData.Types != domain.EvaluationFinish {
result := evaluationList[0]
if result.Types != domain.EvaluationFinish {
return nil
}
// 获取考核结果评分
_, itemValues, err := itemValueRepo.Find(map[string]interface{}{"summaryEvaluationId": result.Id})
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 如果已经存在考核结果分数,只更新分数(反之先默认生成考核结果,再更新分数)
if len(itemValues) > 0 {
// do nothing...
} else {
evaluationItemRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{"transactionContext": transactionContext})
// 周期内所有评估类型
_, evaluationList, err := evaluationRepo.Find(map[string]interface{}{
"companyId": result.CompanyId,
"cycleId": result.CycleId,
"targetUserId": result.TargetUser.UserId,
})
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
var super *domain.SummaryEvaluation // 上级评估
for i := range evaluationList {
it := evaluationList[i]
if it.Types == domain.EvaluationSuper {
super = it
break
}
}
// 获取自评模板
_, itemList, err := evaluationItemRepo.Find(map[string]interface{}{"evaluationProjectId": result.EvaluationProjectId, "nodeType": domain.LinkNodeSelfAssessment})
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if super != nil {
_, superValues, err := itemValueRepo.Find(map[string]interface{}{"summaryEvaluationId": super.Id}) // 获取已填写的评估内容
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 更新填写值
itemValues, err = srv.updateItemValuePriority(result, itemList, superValues, true)
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
} else {
// 评估项ID(除考核结果和上级)
var evaluationIds = make([]int, 0)
for i := range evaluationList {
it := evaluationList[i]
if it.Types == domain.EvaluationSelf || it.Types == domain.Evaluation360 || it.Types == domain.EvaluationHrbp {
evaluationIds = append(evaluationIds, it.Id)
}
}
if len(evaluationIds) > 0 {
// 已填写的评估内容
_, otherValues, err := itemValueRepo.Find(map[string]interface{}{"summaryEvaluationIdList": evaluationIds})
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 更新填写值
itemValues, err = srv.updateItemValuePriority(result, itemList, otherValues, false)
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
}
}
err = itemValueRepo.RemoveBySummaryEvaluationId(result.Id)
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
for i := range itemValues {
if err := itemValueRepo.Save(itemValues[i]); err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
}
// 重置评级汇总
result.TotalRating = nil
for i := range itemList {
result.ResetTotalRating(itemList[i])
}
//// 计算分数
//if err := result.EvaluationTotalScore(itemValues); err != nil {
// return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
//}
}
scoreStr := fmt.Sprintf("%.2f", param.Score)
evaluationData.TotalScore = scoreStr
evaluationData.Status = domain.EvaluationCompleted
// evaluationData.CheckResult = domain.EvaluationCheckCompleted
err = evaluationRepo.Save(evaluationData)
result.TotalScore = scoreStr
result.Status = domain.EvaluationCompleted
err = evaluationRepo.Save(result)
if err != nil {
return application.ThrowError(application.BUSINESS_ERROR, "修改考核结果"+err.Error())
}
... ...