...
|
...
|
@@ -726,152 +726,143 @@ func (srv *SummaryEvaluationService) GetEvaluationHRBPComplete(param *command.Qu |
|
|
}
|
|
|
|
|
|
// ModifyFinishScore 修改周期考核的分数
|
|
|
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)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
if superAdmin != domain.RoleTypeSuperAdmin {
|
|
|
return application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")
|
|
|
}
|
|
|
|
|
|
// 获取周期评估任务finish
|
|
|
evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{"transactionContext": transactionContext})
|
|
|
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
|
|
|
}
|
|
|
result := evaluationList[0]
|
|
|
if result.Types != domain.EvaluationFinish {
|
|
|
return nil
|
|
|
}
|
|
|
// 按照被评估人id ,加锁
|
|
|
lock := xredis.NewLockSummaryEvaluation(result.TargetUser.UserId)
|
|
|
err = lock.Lock()
|
|
|
if err != nil {
|
|
|
return application.ThrowError(application.INTERNAL_SERVER_ERROR, "未能完全提交评估内容")
|
|
|
}
|
|
|
defer func() {
|
|
|
lock.UnLock()
|
|
|
}()
|
|
|
// 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)
|
|
|
// if err != nil {
|
|
|
// return err
|
|
|
// }
|
|
|
// if superAdmin != domain.RoleTypeSuperAdmin {
|
|
|
// return application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")
|
|
|
// }
|
|
|
|
|
|
// 获取考核结果评分
|
|
|
_, 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})
|
|
|
// // 获取周期评估任务finish
|
|
|
// evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{"transactionContext": transactionContext})
|
|
|
// itemValueRepo := factory.CreateSummaryEvaluationValueRepository(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())
|
|
|
}
|
|
|
// _, 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 := evaluationList[0]
|
|
|
// if result.Types != domain.EvaluationFinish {
|
|
|
// return nil
|
|
|
// }
|
|
|
|
|
|
var super *domain.SummaryEvaluation // 上级评估
|
|
|
for i := range evaluationList {
|
|
|
it := evaluationList[i]
|
|
|
if it.Types == domain.EvaluationSuper {
|
|
|
super = it
|
|
|
break
|
|
|
}
|
|
|
}
|
|
|
// // 获取考核结果评分
|
|
|
// _, 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())
|
|
|
// }
|
|
|
|
|
|
// 获取自评模板
|
|
|
_, 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())
|
|
|
}
|
|
|
// var super *domain.SummaryEvaluation // 上级评估
|
|
|
// for i := range evaluationList {
|
|
|
// it := evaluationList[i]
|
|
|
// if it.Types == domain.EvaluationSuper {
|
|
|
// super = it
|
|
|
// break
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
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())
|
|
|
}
|
|
|
// // 获取自评模板
|
|
|
// _, 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())
|
|
|
// }
|
|
|
|
|
|
// 更新填写值
|
|
|
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())
|
|
|
//}
|
|
|
}
|
|
|
// 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)
|
|
|
result.TotalScore = scoreStr
|
|
|
result.Status = domain.EvaluationCompleted
|
|
|
err = evaluationRepo.Save(result)
|
|
|
if err != nil {
|
|
|
return application.ThrowError(application.BUSINESS_ERROR, "修改考核结果"+err.Error())
|
|
|
}
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
// scoreStr := fmt.Sprintf("%.2f", param.Score)
|
|
|
// result.TotalScore = scoreStr
|
|
|
// result.Status = domain.EvaluationCompleted
|
|
|
// err = evaluationRepo.Save(result)
|
|
|
// if err != nil {
|
|
|
// return application.ThrowError(application.BUSINESS_ERROR, "修改考核结果"+err.Error())
|
|
|
// }
|
|
|
// if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
// return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
// }
|
|
|
// return nil
|
|
|
// }
|
|
|
|
|
|
// GetUnconfirmedCycleList 获取未确认绩效成绩的周期列表
|
|
|
func (srv *SummaryEvaluationService) GetUnconfirmedCycleList(companyId int, userId int) (map[string]interface{}, error) {
|
...
|
...
|
|