作者 tangxvhui
... ... @@ -56,13 +56,15 @@ func (srv *SummaryEvaluationService) GetEvaluationFinish(param *command.QueryEva
}
// 考核结果不存在 -> 获取上级考核 -> 获取360+HRBP+自评
if len(itemValues) == 0 {
itemValues, evaluationList, err := srv.findCycleItemValueByType(transactionContext, result.CycleId, result.TargetUser.UserId, []int{int(domain.EvaluationSuper)})
superValues, evaluationList, err := srv.findCycleItemValueByType(transactionContext, result.CycleId, result.TargetUser.UserId, []int{int(domain.EvaluationSuper)})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 上级评估不存在(有上级考核类型时,不管分数有没有填写都算,没填写当作零)
if len(evaluationList) == 0 {
itemValues, _, err = srv.findCycleItemValueByType(transactionContext, result.CycleId, result.TargetUser.UserId, []int{int(domain.EvaluationSelf)})
// 上级评估存在(有上级考核类型时,不管分数有没有填写都算,没填写当作零)
if len(evaluationList) > 0 {
itemValues = superValues
} else {
selfValues, _, err := srv.findCycleItemValueByType(transactionContext, result.CycleId, result.TargetUser.UserId, []int{int(domain.EvaluationSelf)})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
... ... @@ -71,7 +73,7 @@ func (srv *SummaryEvaluationService) GetEvaluationFinish(param *command.QueryEva
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 自评分数
if len(itemValues) == 0 {
if len(selfValues) == 0 {
itemValues = hrItemValues
} else {
// HR360分数 替换 自评分数
... ... @@ -79,13 +81,23 @@ func (srv *SummaryEvaluationService) GetEvaluationFinish(param *command.QueryEva
for i := range hrItemValues {
hrItemMap[hrItemValues[i].EvaluationItemId] = hrItemValues[i]
}
for i := range itemValues {
it := itemValues[i]
for i := range selfValues {
it := selfValues[i]
if v, ok := hrItemMap[it.EvaluationItemId]; ok {
itemValues[i] = v
selfValues[i] = v
}
}
itemValues = selfValues
}
}
// 重新计算成绩
result.TotalRating = nil
for i := range itemList {
result.ResetTotalRating(itemList[i])
}
if err = result.EvaluationTotalScore(itemValues); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
}
... ... @@ -203,6 +215,7 @@ func (srv *SummaryEvaluationService) EditEvaluationFinish(param *command.EditEva
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
}
result.Status = domain.EvaluationCompleted
result.CheckResult = domain.EvaluationCheckUncompleted
err = evaluationRepo.Save(result)
... ...
... ... @@ -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,23 +1400,19 @@ 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())
}
if super != nil {
_, itemValues, err = itemValueRepo.Find(map[string]interface{}{"summaryEvaluationId": super.Id}) // 获取已填写的评估内容
_, 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, itemValues, true)
itemValues, err = srv.updateItemValuePriority(result, itemList, superValues, true)
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
... ... @@ -1430,13 +1427,13 @@ func (srv *SummaryEvaluationService) ConfirmScoreEvaluation(param *command.Confi
}
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 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 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,27 +1607,24 @@ 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())
}
}
}
}
// 未完成考核,需要重新计算分数
if result.CheckResult == domain.EvaluationCheckUncompleted {
result.TotalRating = nil
for i := range itemList {
result.ResetTotalRating(itemList[i])
}
//存在 超级管理员直接修改填写 总分的情况,此时不重新计算总分
if result.TotalScore == "0" || result.TotalScore == "" {
if err = result.EvaluationTotalScore(itemValues); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
... ...
... ... @@ -724,172 +724,136 @@ 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()
// }()
// ModifyFinishScore 修改周期考核的分数
// func (srv *SummaryEvaluationService) ModifyFinishScore(param *command.ModifyFinishScore) error {
// transactionContext, err := factory.CreateTransactionContext(nil)
// if err != nil {
// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
// return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
// }
// if err := transactionContext.StartTransaction(); err != nil {
// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
// return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
// }
// defer func() {
// _ = transactionContext.RollbackTransaction()
// }()
// // 只有超级管理员可以使用的功能
// superAdmin, err := roleService.GetSuperAdmin(transactionContext, param.CompanyId, param.UserId)
// if err != nil {
// return err
// }
// if superAdmin != domain.RoleTypeSuperAdmin {
// return application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")
// }
// userRepo := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext})
// // 获取周期评估任务finish
// 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)
// _, evaluationList, err := evaluationRepo.Find(map[string]interface{}{"id": []int{param.SummaryEvaluationId}, "companyId": param.CompanyId})
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// return application.ThrowError(application.BUSINESS_ERROR, err.Error())
// }
// if hrbp != domain.RoleTypeSystem {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")
// if len(evaluationList) == 0 {
// return nil
// }
// result := evaluationList[0]
// if result.Types != domain.EvaluationFinish {
// return nil
// }
// summaryEvaluation, err := evaluationRepo.FindOne(map[string]interface{}{"id": param.SummaryEvaluationId})
// // 获取考核结果评分
// _, itemValues, err := itemValueRepo.Find(map[string]interface{}{"summaryEvaluationId": result.Id})
// 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, "没有操作权限")
// 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{}{
// "targetUserId": summaryEvaluation.TargetUser.UserId,
// "typesList": []int{int(domain.EvaluationFinish)},
// "cycleId": summaryEvaluation.CycleId,
// "limit": 1,
// "companyId": result.CompanyId,
// "cycleId": result.CycleId,
// "targetUserId": result.TargetUser.UserId,
// })
// 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, "用户已经确认该周期的考核结果,不能再编辑!")
// return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.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())
// var super *domain.SummaryEvaluation // 上级评估
// for i := range evaluationList {
// it := evaluationList[i]
// if it.Types == domain.EvaluationSuper {
// super = it
// break
// }
// }
// // 评估内容对应的分数
// _, itemValueList, err := itemValueRepo.Find(map[string]interface{}{"summaryEvaluationId": summaryEvaluation.Id})
// // 获取自评模板
// _, 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())
// return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// err = srv.editEvaluationValue(summaryEvaluation, &itemValueList, itemList, param.EvaluationItems, nil, param.IsTemporary)
// if super != nil {
// _, superValues, err := itemValueRepo.Find(map[string]interface{}{"summaryEvaluationId": super.Id}) // 获取已填写的评估内容
// if err != nil {
// return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
// }
// if !param.IsTemporary {
// //变更评估状态为已填写
// summaryEvaluation.Status = domain.EvaluationCompleted
// return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// //保存填写值
// for _, v := range itemValueList {
// err = itemValueRepo.Save(v)
// // 更新填写值
// itemValues, err = srv.updateItemValuePriority(result, itemList, superValues, true)
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// 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)
// }
// // 针对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 len(evaluationIds) > 0 {
// // 已填写的评估内容
// _, otherValues, err := itemValueRepo.Find(map[string]interface{}{"summaryEvaluationIdList": evaluationIds})
// 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())
// return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// if !param.IsTemporary {
// err = srv.AfterCompletedEvaluation360Hrbp(summaryEvaluation)
// // 更新填写值
// itemValues, err = srv.updateItemValuePriority(result, itemList, otherValues, false)
// if err != nil {
// return nil, err
// }
// }
// itemValueAdapter := srv.buildSummaryItemValue(itemList, itemValueList)
// return map[string][]adapter.EvaluationItemAdapter{
// "evaluationItems": itemValueAdapter,
// }, nil
// return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// 修改周期考核的分数
// func (srv *SummaryEvaluationService) ModifyFinishScore(param *command.ModifyFinishScore) error {
// 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()
// }()
// // 只有超级管理员可以使用的功能
// superAdmin, err := roleService.GetSuperAdmin(transactionContext, param.CompanyId, param.UserId)
// err = itemValueRepo.RemoveBySummaryEvaluationId(result.Id)
// if err != nil {
// return err
// return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// if superAdmin != domain.RoleTypeSuperAdmin {
// return application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")
// for i := range itemValues {
// if err := itemValueRepo.Save(itemValues[i]); err != nil {
// return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// //获取周期评估任务finish
// evaluationRepo := factory.CreateSummaryEvaluationRepository(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
// // 重置评级汇总
// result.TotalRating = nil
// for i := range itemList {
// result.ResetTotalRating(itemList[i])
// }
// evaluationData := evaluationList[0]
// if evaluationData.Types != domain.EvaluationFinish {
// return nil
// //// 计算分数
// //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())
// }
... ...