|
|
package service
|
|
|
|
|
|
import (
|
|
|
"fmt"
|
|
|
"strings"
|
|
|
"time"
|
|
|
|
|
|
"github.com/linmadan/egglib-go/core/application"
|
...
|
...
|
@@ -13,7 +15,275 @@ import ( |
|
|
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/log"
|
|
|
)
|
|
|
|
|
|
//编辑上级周期评估
|
|
|
// 编辑上级周期评估
|
|
|
// EditEvaluationSuper 更新上级评估内容
|
|
|
// func (srv *SummaryEvaluationService) EditEvaluationSuper(param *command.EditEvaluationValue) (interface{}, 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.EvaluationSuper {
|
|
|
// 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, "没有操作权限")
|
|
|
// }
|
|
|
// ok := evaluationData.EndTime.Before(time.Now())
|
|
|
// if ok {
|
|
|
// return nil, application.ThrowError(application.BUSINESS_ERROR, "评估时间已截止")
|
|
|
// }
|
|
|
// //按照被评估人id ,加锁
|
|
|
// lock := xredis.NewLockSummaryEvaluation(evaluationData.TargetUser.UserId)
|
|
|
// err = lock.Lock()
|
|
|
// if err != nil {
|
|
|
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "未能完全提交评估内容")
|
|
|
// }
|
|
|
// defer func() {
|
|
|
// lock.UnLock()
|
|
|
// }()
|
|
|
// _, evaluationList, err := evaluationRepo.Find(map[string]interface{}{
|
|
|
// "targetUserId": evaluationData.TargetUser.UserId,
|
|
|
// "typesList": []int{int(domain.EvaluationFinish)},
|
|
|
// "cycleId": evaluationData.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": 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())
|
|
|
// }
|
|
|
// //记录人资评估或者360评估的 填写项id
|
|
|
// hrbpOr360ItemValue, err := srv.getEvaluationSuperDefaultValue(transactionContext, evaluationData)
|
|
|
// if err != nil {
|
|
|
// return nil, err
|
|
|
// }
|
|
|
|
|
|
// err = srv.editEvaluationValue(evaluationData, &itemValueList, itemList, param.EvaluationItems, hrbpOr360ItemValue, param.IsTemporary)
|
|
|
// if err != nil {
|
|
|
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
// }
|
|
|
// 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.AfterCompletedEvaluationSuper(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
|
|
|
// }
|
|
|
|
|
|
// 员工提交上级评估后
|
|
|
// 生成考核结果
|
|
|
func (srv *SummaryEvaluationService) AfterCompletedEvaluationSuper(
|
|
|
transactionContext application.TransactionContext,
|
|
|
evaluationData *domain.SummaryEvaluation,
|
|
|
evaluationValue []*domain.SummaryEvaluationValue,
|
|
|
) error {
|
|
|
evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
//没有上级评估
|
|
|
//直接进入考核结果阶段
|
|
|
_, evaluationList, err := evaluationRepo.Find(map[string]interface{}{
|
|
|
"targetUserId": evaluationData.TargetUser.UserId,
|
|
|
"typesList": []int{int(domain.EvaluationFinish)},
|
|
|
"cycleId": evaluationData.CycleId,
|
|
|
"limit": 1,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
if len(evaluationList) > 0 {
|
|
|
//调整考核结果的开始时间
|
|
|
nowTime := time.Now()
|
|
|
if evaluationList[0].BeginTime.After(nowTime) {
|
|
|
evaluationList[0].BeginTime = nowTime
|
|
|
}
|
|
|
evaluationList[0].Status = domain.EvaluationCompleted
|
|
|
err = srv.syncEvaluationFinishValue(transactionContext, evaluationList[0], evaluationValue)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
//添加确认绩效成绩提醒短信提醒
|
|
|
err = notify.AddNotifyConfirmEvaluationScore(evaluationList[0])
|
|
|
if err != nil {
|
|
|
log.Logger.Error("添加确认绩效成绩提醒短信提醒失败:" + err.Error())
|
|
|
}
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
// 从其他评估那边同步考核结果的评估内容
|
|
|
// evaluationData 考核结果评估
|
|
|
// updateValue 更新评估项需要的值
|
|
|
func (srv *SummaryEvaluationService) syncEvaluationFinishValue(
|
|
|
transactionContext application.TransactionContext,
|
|
|
evaluationData *domain.SummaryEvaluation,
|
|
|
updateValue []*domain.SummaryEvaluationValue,
|
|
|
) error {
|
|
|
if len(updateValue) == 0 {
|
|
|
return nil
|
|
|
}
|
|
|
if evaluationData.CheckResult == domain.EvaluationCheckCompleted {
|
|
|
return nil
|
|
|
}
|
|
|
evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
evaluationValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
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())
|
|
|
}
|
|
|
//填写项的map EvaluationItemId =>SummaryEvaluationValue
|
|
|
oldEvaluationValue := map[int]*domain.SummaryEvaluationValue{}
|
|
|
//查询已有的考核结果评估内容
|
|
|
_, evaluationValueList, err := evaluationValueRepo.Find(map[string]interface{}{"summaryEvaluationId": evaluationData.Id})
|
|
|
if err != nil {
|
|
|
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
for i, val := range evaluationValueList {
|
|
|
oldEvaluationValue[val.EvaluationItemId] = evaluationValueList[i]
|
|
|
}
|
|
|
// 待更新的评估填写项map EvaluationItemId =>SummaryEvaluationValue
|
|
|
updateValueMap := map[int]*domain.SummaryEvaluationValue{}
|
|
|
for i, val := range updateValue {
|
|
|
updateValueMap[val.EvaluationItemId] = updateValue[i]
|
|
|
}
|
|
|
|
|
|
//更新考核结果
|
|
|
for _, val := range itemList {
|
|
|
oldValue, ok := oldEvaluationValue[val.Id]
|
|
|
if !ok {
|
|
|
//补全考核结果中可能缺失的评估项
|
|
|
newValue := &domain.SummaryEvaluationValue{}
|
|
|
newValue.SetBlankValue(evaluationData, val)
|
|
|
oldEvaluationValue[val.Id] = newValue
|
|
|
oldValue = oldEvaluationValue[val.Id]
|
|
|
}
|
|
|
if item, ok := updateValueMap[val.Id]; ok {
|
|
|
oldValue.Executor = item.Executor
|
|
|
oldValue.Types = item.Types
|
|
|
oldValue.Rating = item.Rating
|
|
|
oldValue.Value = item.Value
|
|
|
oldValue.Score = item.Score
|
|
|
oldValue.Remark = item.Remark
|
|
|
}
|
|
|
}
|
|
|
// 重置各个评级数量
|
|
|
evaluationData.TotalRating = nil
|
|
|
for i := range itemList {
|
|
|
evaluationData.ResetTotalRating(itemList[i])
|
|
|
}
|
|
|
|
|
|
newEvaluationValue := []*domain.SummaryEvaluationValue{}
|
|
|
for _, val := range oldEvaluationValue {
|
|
|
newEvaluationValue = append(newEvaluationValue, val)
|
|
|
}
|
|
|
//计算总分
|
|
|
evaluationData.EvaluationTotalScore(newEvaluationValue)
|
|
|
|
|
|
err = evaluationRepo.Save(evaluationData)
|
|
|
if err != nil {
|
|
|
return application.ThrowError(application.INTERNAL_SERVER_ERROR, "同步考核结果"+err.Error())
|
|
|
}
|
|
|
err = evaluationValueRepo.RemoveBySummaryEvaluationId(evaluationData.Id)
|
|
|
if err != nil {
|
|
|
return application.ThrowError(application.INTERNAL_SERVER_ERROR, "同步考核结果"+err.Error())
|
|
|
}
|
|
|
for _, val := range newEvaluationValue {
|
|
|
val.Id = 0
|
|
|
err = evaluationValueRepo.Save(val)
|
|
|
if err != nil {
|
|
|
return application.ThrowError(application.INTERNAL_SERVER_ERROR, "同步考核结果"+err.Error())
|
|
|
}
|
|
|
}
|
|
|
return nil
|
|
|
|
|
|
}
|
|
|
|
|
|
// EditEvaluationSuper 更新上级评估内容
|
|
|
func (srv *SummaryEvaluationService) EditEvaluationSuper(param *command.EditEvaluationValue) (interface{}, error) {
|
...
|
...
|
@@ -100,11 +370,72 @@ func (srv *SummaryEvaluationService) EditEvaluationSuper(param *command.EditEval |
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
err = srv.editEvaluationValue(evaluationData, &itemValueList, itemList, param.EvaluationItems, hrbpOr360ItemValue, param.IsTemporary)
|
|
|
//更新填写值
|
|
|
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.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
}
|
|
|
}
|
|
|
// 填入固定的默认值
|
|
|
for _, v := range hrbpOr360ItemValue {
|
|
|
newItemValue, ok := evaluationValueMap[v.EvaluationItemId]
|
|
|
if !ok {
|
|
|
continue
|
|
|
}
|
|
|
evaluationItem, ok := evaluationItemMap[v.EvaluationItemId]
|
|
|
if !ok {
|
|
|
continue
|
|
|
}
|
|
|
//填充评估填写值
|
|
|
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
|
...
|
...
|
@@ -113,7 +444,7 @@ func (srv *SummaryEvaluationService) EditEvaluationSuper(param *command.EditEval |
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
for _, val := range itemValueList {
|
|
|
for _, val := range evaluationValueSlice {
|
|
|
val.Id = 0
|
|
|
}
|
|
|
}
|
...
|
...
|
@@ -122,7 +453,7 @@ func (srv *SummaryEvaluationService) EditEvaluationSuper(param *command.EditEval |
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
for _, v := range itemValueList {
|
|
|
for _, v := range evaluationValueSlice {
|
|
|
//保存填写值
|
|
|
err = itemValueRepo.Save(v)
|
|
|
if err != nil {
|
...
|
...
|
@@ -145,141 +476,72 @@ func (srv *SummaryEvaluationService) EditEvaluationSuper(param *command.EditEval |
|
|
}, nil
|
|
|
}
|
|
|
|
|
|
// 员工提交上级评估后
|
|
|
// 生成考核结果
|
|
|
func (srv *SummaryEvaluationService) AfterCompletedEvaluationSuper(
|
|
|
transactionContext application.TransactionContext,
|
|
|
evaluationData *domain.SummaryEvaluation,
|
|
|
evaluationValue []*domain.SummaryEvaluationValue,
|
|
|
) error {
|
|
|
// getEvaluationSuperDefaultValue
|
|
|
// 按照权限设置,是否获取上级评估内容的默认值
|
|
|
func (srv *SummaryEvaluationService) getEvaluationSuperDefaultValue(transactionContext application.TransactionContext, evaluationData *domain.SummaryEvaluation) (
|
|
|
[]*domain.SummaryEvaluationValue, error) {
|
|
|
evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
//没有上级评估
|
|
|
//直接进入考核结果阶段
|
|
|
_, evaluationList, err := evaluationRepo.Find(map[string]interface{}{
|
|
|
"targetUserId": evaluationData.TargetUser.UserId,
|
|
|
"typesList": []int{int(domain.EvaluationFinish)},
|
|
|
"cycleId": evaluationData.CycleId,
|
|
|
"limit": 1,
|
|
|
|
|
|
itemValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
if len(evaluationList) > 0 {
|
|
|
//调整考核结果的开始时间
|
|
|
nowTime := time.Now()
|
|
|
if evaluationList[0].BeginTime.After(nowTime) {
|
|
|
evaluationList[0].BeginTime = nowTime
|
|
|
}
|
|
|
evaluationList[0].Status = domain.EvaluationCompleted
|
|
|
err = srv.syncEvaluationFinishValue(transactionContext, evaluationList[0], evaluationValue)
|
|
|
permissionData, err := getPermission(int64(evaluationData.CompanyId))
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
//添加确认绩效成绩提醒短信提醒
|
|
|
err = notify.AddNotifyConfirmEvaluationScore(evaluationList[0])
|
|
|
if err != nil {
|
|
|
log.Logger.Error("添加确认绩效成绩提醒短信提醒失败:" + err.Error())
|
|
|
}
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
// 从其他评估那边同步考核结果的评估内容
|
|
|
// evaluationData 考核结果评估
|
|
|
// updateValue 更新评估项需要的值
|
|
|
func (srv *SummaryEvaluationService) syncEvaluationFinishValue(
|
|
|
transactionContext application.TransactionContext,
|
|
|
evaluationData *domain.SummaryEvaluation,
|
|
|
updateValue []*domain.SummaryEvaluationValue,
|
|
|
) error {
|
|
|
if len(updateValue) == 0 {
|
|
|
return nil
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if evaluationData.CheckResult == domain.EvaluationCheckCompleted {
|
|
|
return nil
|
|
|
if permissionData.OptEvalScore == domain.PermissionOn && permissionData.OptHrScore == domain.PermissionOn {
|
|
|
return nil, nil
|
|
|
}
|
|
|
evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
evaluationValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
itemUsedRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
_, itemList, err := itemUsedRepo.Find(map[string]interface{}{
|
|
|
"evaluationProjectId": evaluationData.EvaluationProjectId,
|
|
|
"nodeType": domain.LinkNodeSelfAssessment,
|
|
|
// 获取360评估,人资评估填写的值
|
|
|
_, evaluationListOther, err := evaluationRepo.Find(map[string]interface{}{
|
|
|
"typesList": []int{int(domain.Evaluation360), int(domain.EvaluationHrbp)},
|
|
|
"targetUserId": evaluationData.TargetUser.UserId,
|
|
|
"cycleId": evaluationData.CycleId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
//填写项的map EvaluationItemId =>SummaryEvaluationValue
|
|
|
oldEvaluationValue := map[int]*domain.SummaryEvaluationValue{}
|
|
|
//查询已有的考核结果评估内容
|
|
|
_, evaluationValueList, err := evaluationValueRepo.Find(map[string]interface{}{"summaryEvaluationId": evaluationData.Id})
|
|
|
if err != nil {
|
|
|
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
for i, val := range evaluationValueList {
|
|
|
oldEvaluationValue[val.EvaluationItemId] = evaluationValueList[i]
|
|
|
evaluationIds := []int{}
|
|
|
for _, v := range evaluationListOther {
|
|
|
evaluationIds = append(evaluationIds, v.Id)
|
|
|
}
|
|
|
// 待更新的评估填写项map EvaluationItemId =>SummaryEvaluationValue
|
|
|
updateValueMap := map[int]*domain.SummaryEvaluationValue{}
|
|
|
for i, val := range updateValue {
|
|
|
updateValueMap[val.EvaluationItemId] = updateValue[i]
|
|
|
if len(evaluationIds) == 0 {
|
|
|
return nil, nil
|
|
|
}
|
|
|
|
|
|
//更新考核结果
|
|
|
for _, val := range itemList {
|
|
|
oldValue, ok := oldEvaluationValue[val.Id]
|
|
|
if !ok {
|
|
|
//补全考核结果中可能缺失的评估项
|
|
|
newValue := &domain.SummaryEvaluationValue{}
|
|
|
newValue.SetBlankValue(evaluationData, val)
|
|
|
oldEvaluationValue[val.Id] = newValue
|
|
|
oldValue = oldEvaluationValue[val.Id]
|
|
|
// 将360评估,人资评估填写的值 作为默认值
|
|
|
_, itemValuesOther, err := itemValueRepo.Find(map[string]interface{}{
|
|
|
"summaryEvaluationIdList": evaluationIds,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if item, ok := updateValueMap[val.Id]; ok {
|
|
|
oldValue.Executor = item.Executor
|
|
|
oldValue.Types = item.Types
|
|
|
oldValue.Rating = item.Rating
|
|
|
oldValue.Value = item.Value
|
|
|
oldValue.Score = item.Score
|
|
|
oldValue.Remark = item.Remark
|
|
|
// 记录人资评估或者360评估的 填写项id
|
|
|
hrbpOr360ItemValue := []*domain.SummaryEvaluationValue{}
|
|
|
if permissionData.OptEvalScore == domain.PermissionOff {
|
|
|
//上级是否可以修改360°综评分数
|
|
|
//获取360综合评分
|
|
|
for _, v := range itemValuesOther {
|
|
|
//记录人资评估或者360评估的填写值
|
|
|
if v.Types != domain.Evaluation360 {
|
|
|
continue
|
|
|
}
|
|
|
hrbpOr360ItemValue = append(hrbpOr360ItemValue, v)
|
|
|
}
|
|
|
// 重置各个评级数量
|
|
|
evaluationData.TotalRating = nil
|
|
|
for i := range itemList {
|
|
|
evaluationData.ResetTotalRating(itemList[i])
|
|
|
}
|
|
|
|
|
|
newEvaluationValue := []*domain.SummaryEvaluationValue{}
|
|
|
for _, val := range oldEvaluationValue {
|
|
|
newEvaluationValue = append(newEvaluationValue, val)
|
|
|
if permissionData.OptHrScore == domain.PermissionOff {
|
|
|
//上级是否可以修改人资综评分数
|
|
|
//获取人资综合评分
|
|
|
for _, v := range itemValuesOther {
|
|
|
//记录人资评估或者360评估的填写值
|
|
|
if v.Types != domain.EvaluationHrbp {
|
|
|
continue
|
|
|
}
|
|
|
//计算总分
|
|
|
evaluationData.EvaluationTotalScore(newEvaluationValue)
|
|
|
|
|
|
err = evaluationRepo.Save(evaluationData)
|
|
|
if err != nil {
|
|
|
return application.ThrowError(application.INTERNAL_SERVER_ERROR, "同步考核结果"+err.Error())
|
|
|
}
|
|
|
err = evaluationValueRepo.RemoveBySummaryEvaluationId(evaluationData.Id)
|
|
|
if err != nil {
|
|
|
return application.ThrowError(application.INTERNAL_SERVER_ERROR, "同步考核结果"+err.Error())
|
|
|
}
|
|
|
for _, val := range newEvaluationValue {
|
|
|
val.Id = 0
|
|
|
err = evaluationValueRepo.Save(val)
|
|
|
if err != nil {
|
|
|
return application.ThrowError(application.INTERNAL_SERVER_ERROR, "同步考核结果"+err.Error())
|
|
|
hrbpOr360ItemValue = append(hrbpOr360ItemValue, v)
|
|
|
}
|
|
|
}
|
|
|
return nil
|
|
|
|
|
|
return hrbpOr360ItemValue, nil
|
|
|
} |
...
|
...
|
|