作者 郑周

1. 员工确认分数,增加判断 是否存在考核结果,如果存在就不在进行分数计算

... ... @@ -1373,88 +1373,97 @@ func (srv *SummaryEvaluationService) ConfirmScoreEvaluation(param *command.Confi
return application.ThrowError(application.TRANSACTION_ERROR, "前面流程暂未完成提交评估内容")
}
_, 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
}
}
// 评估内容和值
var itemList []*domain.EvaluationItemUsed
var itemValues []*domain.SummaryEvaluationValue
// 获取自评模板内容
_, itemList, err = evaluationItemRepo.Find(map[string]interface{}{"evaluationProjectId": result.EvaluationProjectId, "nodeType": domain.LinkNodeSelfAssessment})
// 按评估项优先级顺序(已确认考核结果 ->上级评估 ->HR或360评估或自评)
_, itemValues, err := itemValueRepo.Find(map[string]interface{}{"summaryEvaluationId": result.Id, "limit": 1})
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 按评估项优先级顺序(已确认考核结果 ->上级评估 ->HR或360评估或自评)
if super != nil {
_, itemValues, 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, itemValues, true)
// 如果已经存在考核结果分数,不再进行分数计算(如.超管多次修改员工多次确认)
if len(itemValues) > 0 {
// do nothing...
} else {
// 周期内所有评估类型
_, 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())
}
} else {
// 评估项ID(除考核结果和上级)
var evaluationIds = make([]int, 0)
var super *domain.SummaryEvaluation // 上级评估
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 it.Types == domain.EvaluationSuper {
super = it
break
}
}
if len(evaluationIds) > 0 {
// 获取已填写的评估内容
_, itemValues, err = itemValueRepo.Find(map[string]interface{}{"summaryEvaluationIdList": evaluationIds})
// 评估内容和值
var itemList []*domain.EvaluationItemUsed
var itemValues []*domain.SummaryEvaluationValue
// 获取自评模板
_, 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 {
_, itemValues, 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, itemValues, false)
itemValues, err = srv.updateItemValuePriority(result, itemList, itemValues, 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 {
// 已填写的评估内容
_, itemValues, 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, itemValues, 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 {
err = itemValueRepo.RemoveBySummaryEvaluationId(result.Id)
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
}
//重置评级汇总
result.TotalRating = nil
for i := range itemList {
result.ResetTotalRating(itemList[i])
}
//存在 超级管理员直接修改填写 总分的情况,此时不重新计算总分
if result.TotalScore == "0" || result.TotalScore == "" {
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())
}
}
result.CheckResult = domain.EvaluationCheckCompleted
if err := evaluationRepo.Save(result); err != nil {
return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
... ...