|
|
package service
|
|
|
|
|
|
import (
|
|
|
"fmt"
|
|
|
"strings"
|
|
|
"time"
|
|
|
|
|
|
"github.com/linmadan/egglib-go/core/application"
|
...
|
...
|
@@ -172,15 +174,11 @@ func (srv *SummaryEvaluationService) AfterCompletedEvaluationSelf( |
|
|
}
|
|
|
|
|
|
var evaluationFinish *domain.SummaryEvaluation
|
|
|
noSuper := true
|
|
|
//查找综合评估结果
|
|
|
for _, v := range evaluationList {
|
|
|
if v.Types == domain.EvaluationFinish {
|
|
|
evaluationFinish = v
|
|
|
}
|
|
|
if v.Types == domain.EvaluationSuper {
|
|
|
noSuper = false
|
|
|
}
|
|
|
}
|
|
|
if len(targetEvaluation) == 0 {
|
|
|
//没有上级评估、360评估、hrbp 评估
|
...
|
...
|
@@ -203,45 +201,154 @@ func (srv *SummaryEvaluationService) AfterCompletedEvaluationSelf( |
|
|
}
|
|
|
}
|
|
|
}
|
|
|
_ = noSuper
|
|
|
// if noSuper && evaluationFinish != nil {
|
|
|
//没有上级评估 同步数据到考核结果
|
|
|
|
|
|
// itemUsedRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{
|
|
|
// "transactionContext": transactionContext,
|
|
|
// })
|
|
|
// _, itemList, err := itemUsedRepo.Find(map[string]interface{}{
|
|
|
// "evaluationProjectId": evaluationData.EvaluationProjectId,
|
|
|
// "nodeType": domain.LinkNodeSelfAssessment,
|
|
|
// })
|
|
|
// if err != nil {
|
|
|
// return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
// }
|
|
|
// //提取非360,hrbp 的评估项
|
|
|
// updateValue := []*domain.SummaryEvaluationValue{}
|
|
|
// for _, val := range itemList {
|
|
|
// if val.EvaluatorId != 0 {
|
|
|
// continue
|
|
|
// }
|
|
|
// for _, val2 := range evaluationValue {
|
|
|
// if val.Id == val2.EvaluationItemId {
|
|
|
// updateValue = append(updateValue, val2)
|
|
|
// break
|
|
|
// }
|
|
|
// }
|
|
|
// }
|
|
|
// //同步数据
|
|
|
// err = srv.syncEvaluationFinishValue(transactionContext, evaluationFinish, updateValue)
|
|
|
// if err != nil {
|
|
|
// return err
|
|
|
// }
|
|
|
|
|
|
// } else if len(targetEvaluation) == 0 && evaluationFinish != nil {
|
|
|
// err = evaluationRepo.Save(evaluationFinish)
|
|
|
// if err != nil {
|
|
|
// return application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存考核结果,"+err.Error())
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
// 编辑综合自评详情
|
|
|
func (srv *SummaryEvaluationService) EditEvaluationSelfV2(param *command.EditEvaluationValue) (map[string][]adapter.EvaluationItemAdapter, error) {
|
|
|
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()
|
|
|
}()
|
|
|
evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
itemUsedRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
|
|
|
itemValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
evaluationData, err := evaluationRepo.FindOne(map[string]interface{}{
|
|
|
"id": param.SummaryEvaluationId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取评估"+err.Error())
|
|
|
}
|
|
|
if evaluationData.Types != domain.EvaluationSelf {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")
|
|
|
}
|
|
|
|
|
|
if evaluationData.Executor.UserId != param.ExecutorId {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")
|
|
|
}
|
|
|
if evaluationData.CompanyId != param.CompanyId {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")
|
|
|
}
|
|
|
//按照 被评估人加锁
|
|
|
lock := xredis.NewLockSummaryEvaluation(evaluationData.TargetUser.UserId)
|
|
|
err = lock.Lock()
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "未能完全提交评估内容")
|
|
|
}
|
|
|
defer func() {
|
|
|
lock.UnLock()
|
|
|
}()
|
|
|
_, itemList, err := itemUsedRepo.Find(map[string]interface{}{
|
|
|
"evaluationProjectId": evaluationData.EvaluationProjectId,
|
|
|
"nodeType": domain.LinkNodeSelfAssessment,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
_, itemValueList, err := itemValueRepo.Find(map[string]interface{}{
|
|
|
"summaryEvaluationId": evaluationData.Id,
|
|
|
})
|
|
|
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
//更新填写值
|
|
|
var evaluationValueSlice []*domain.SummaryEvaluationValue // 提交的填写值
|
|
|
{
|
|
|
|
|
|
evaluationItemMap := map[int]*domain.EvaluationItemUsed{} // 需要填写那些项 Id=>&domain.EvaluationItemUsed{}
|
|
|
evaluationValueMap := map[int]*domain.SummaryEvaluationValue{} // 提交的填写值 EvaluationItemId=>&domain.domain.SummaryEvaluationValue{}
|
|
|
evaluationData.TotalRating = nil // 清空评级数量统计
|
|
|
// 按照需要填写那些项 设置SummaryEvaluationValue的空白值
|
|
|
for _, v := range itemList {
|
|
|
newValue := &domain.SummaryEvaluationValue{}
|
|
|
newValue.SetBlankValue(evaluationData, v)
|
|
|
evaluationValueMap[v.Id] = newValue
|
|
|
evaluationItemMap[v.Id] = v
|
|
|
evaluationValueSlice = append(evaluationValueSlice, newValue)
|
|
|
}
|
|
|
//如果存在旧值
|
|
|
//新值的id 替换为旧值id
|
|
|
for _, v := range itemValueList {
|
|
|
if mValue, ok := evaluationValueMap[v.EvaluationItemId]; ok {
|
|
|
mValue.Id = v.Id
|
|
|
}
|
|
|
}
|
|
|
//填入提交的更新值
|
|
|
for _, v := range param.EvaluationItems {
|
|
|
v.Value = strings.TrimSpace(v.Value)
|
|
|
newItemValue, ok := evaluationValueMap[v.EvaluationItemId]
|
|
|
if !ok {
|
|
|
continue
|
|
|
}
|
|
|
evaluationItem, ok := evaluationItemMap[v.EvaluationItemId]
|
|
|
if !ok {
|
|
|
continue
|
|
|
}
|
|
|
if !param.IsTemporary {
|
|
|
//除了综合自评,其他的评估任务 评估项直接全部按必填项处理
|
|
|
if len(v.Value) == 0 {
|
|
|
e := fmt.Sprintf("%s-%s 未填写", evaluationItem.Category, evaluationItem.Name)
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, e)
|
|
|
}
|
|
|
}
|
|
|
//填充评估填写值
|
|
|
newItemValue.Remark = v.Remark
|
|
|
err := evaluationData.FillItemValue(evaluationItem, newItemValue, v.Value)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
}
|
|
|
}
|
|
|
evaluationData.EvaluationTotalScore(evaluationValueSlice)
|
|
|
}
|
|
|
|
|
|
if !param.IsTemporary {
|
|
|
evaluationData.Status = domain.EvaluationCompleted
|
|
|
//删除旧的填写值,使用新的填写内容
|
|
|
err = itemValueRepo.RemoveBySummaryEvaluationId(evaluationData.Id)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
for _, val := range itemValueList {
|
|
|
val.Id = 0
|
|
|
}
|
|
|
}
|
|
|
err = evaluationRepo.Save(evaluationData)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
//保存填写值
|
|
|
for _, v := range itemValueList {
|
|
|
err = itemValueRepo.Save(v)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
}
|
|
|
if !param.IsTemporary {
|
|
|
err = srv.AfterCompletedEvaluationSelf(transactionContext, evaluationData, itemValueList)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
}
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
itemValueAdapter := srv.buildSummaryItemValue(itemList, itemValueList)
|
|
|
return map[string][]adapter.EvaluationItemAdapter{
|
|
|
"EvaluationItems": itemValueAdapter,
|
|
|
}, nil
|
|
|
} |
...
|
...
|
|