作者 tangxvhui

更新评估的填写规则

package service
import (
"fmt"
"strings"
"time"
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/summary_evaluation/adapter"
... ... @@ -10,6 +14,117 @@ import (
)
// EditEvaluation360 编辑提交360综评
// func (srv *SummaryEvaluationService) EditEvaluation360(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})
// summaryEvaluation, err := evaluationRepo.FindOne(map[string]interface{}{"id": param.SummaryEvaluationId})
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// if summaryEvaluation.Executor.UserId != param.ExecutorId {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")
// }
// if summaryEvaluation.CompanyId != param.CompanyId {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")
// }
// // 按照 被评估人加锁
// lock := xredis.NewLockSummaryEvaluation(summaryEvaluation.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": summaryEvaluation.TargetUser.UserId,
// "typesList": []int{int(domain.EvaluationFinish)},
// "cycleId": summaryEvaluation.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": summaryEvaluation.EvaluationProjectId,
// "nodeType": domain.LinkNodeSelfAssessment,
// "evaluatorId": param.ExecutorId,
// })
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// // 评估内容对应的分数
// _, itemValueList, err := itemValueRepo.Find(map[string]interface{}{"summaryEvaluationId": summaryEvaluation.Id})
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// err = srv.editEvaluationValue(summaryEvaluation, &itemValueList, itemList, param.EvaluationItems, nil, param.IsTemporary)
// if err != nil {
// return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
// }
// if !param.IsTemporary {
// //变更评估状态为已填写
// summaryEvaluation.Status = domain.EvaluationCompleted
// //删除旧的填写值,使用新的填写内容
// err = itemValueRepo.RemoveBySummaryEvaluationId(summaryEvaluation.Id)
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// for _, val := range itemValueList {
// val.Id = 0
// }
// }
// //保存填写值
// for _, v := range itemValueList {
// v.Id = 0
// err = itemValueRepo.Save(v)
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// }
// //保存填写值
// err = evaluationRepo.Save(summaryEvaluation)
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// if !param.IsTemporary {
// err = srv.AfterCompletedEvaluation360Hrbp(transactionContext, summaryEvaluation, 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
// }
// EditEvaluation360 编辑提交360综评
// 填写规则变更。v2
func (srv *SummaryEvaluationService) EditEvaluation360(param *command.EditEvaluationValue) (map[string][]adapter.EvaluationItemAdapter, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
... ... @@ -57,6 +172,9 @@ func (srv *SummaryEvaluationService) EditEvaluation360(param *command.EditEvalua
if len(evaluationList) > 0 && evaluationList[0].CheckResult == domain.EvaluationCheckCompleted {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "用户已经确认该周期的考核结果,不能再编辑!")
}
if ok := summaryEvaluation.EndTime.Before(time.Now()); ok {
return nil, application.ThrowError(application.BUSINESS_ERROR, "评估时间已截止")
}
// 自评评估内容(自评模板、筛选项目评估人)
_, itemList, err := itemUsedRepo.Find(map[string]interface{}{
... ... @@ -74,10 +192,56 @@ func (srv *SummaryEvaluationService) EditEvaluation360(param *command.EditEvalua
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
err = srv.editEvaluationValue(summaryEvaluation, &itemValueList, itemList, param.EvaluationItems, nil, param.IsTemporary)
//更新填写值
var evaluationValueSlice []*domain.SummaryEvaluationValue // 提交的填写值
{
evaluationItemMap := map[int]*domain.EvaluationItemUsed{} // 需要填写那些项 Id=>&domain.EvaluationItemUsed{}
evaluationValueMap := map[int]*domain.SummaryEvaluationValue{} // 提交的填写值 EvaluationItemId=>&domain.domain.SummaryEvaluationValue{}
summaryEvaluation.TotalRating = nil // 清空评级数量统计
// 按照需要填写那些项 设置SummaryEvaluationValue的空白值
for _, v := range itemList {
newValue := &domain.SummaryEvaluationValue{}
newValue.SetBlankValue(summaryEvaluation, 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 := summaryEvaluation.FillItemValue(evaluationItem, newItemValue, v.Value)
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
}
summaryEvaluation.EvaluationTotalScore(evaluationValueSlice)
}
if !param.IsTemporary {
//变更评估状态为已填写
summaryEvaluation.Status = domain.EvaluationCompleted
... ... @@ -86,13 +250,13 @@ func (srv *SummaryEvaluationService) EditEvaluation360(param *command.EditEvalua
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
for _, val := range itemValueList {
for _, val := range evaluationValueSlice {
val.Id = 0
}
}
//保存填写值
for _, v := range itemValueList {
for _, v := range evaluationValueSlice {
v.Id = 0
err = itemValueRepo.Save(v)
if err != nil {
... ...
package service
import (
"fmt"
"strings"
"time"
"github.com/linmadan/egglib-go/core/application"
... ... @@ -15,6 +17,226 @@ import (
)
// EditEvaluationHRBP 编辑提交人资综评
// func (srv *SummaryEvaluationService) EditEvaluationHRBP(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()
// }()
// userRepo := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext})
// 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)
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// if hrbp != domain.RoleTypeSystem {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")
// }
// summaryEvaluation, err := evaluationRepo.FindOne(map[string]interface{}{"id": param.SummaryEvaluationId})
// 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, "没有操作权限")
// }
// // 按照 被评估人加锁
// lock := xredis.NewLockSummaryEvaluation(summaryEvaluation.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": summaryEvaluation.TargetUser.UserId,
// "typesList": []int{int(domain.EvaluationFinish)},
// "cycleId": summaryEvaluation.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": summaryEvaluation.EvaluationProjectId,
// "nodeType": domain.LinkNodeSelfAssessment,
// "evaluatorId": -1,
// })
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// // 评估内容对应的分数
// _, itemValueList, err := itemValueRepo.Find(map[string]interface{}{"summaryEvaluationId": summaryEvaluation.Id})
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// err = srv.editEvaluationValue(summaryEvaluation, &itemValueList, itemList, param.EvaluationItems, nil, param.IsTemporary)
// if err != nil {
// return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
// }
// if !param.IsTemporary {
// //变更评估状态为已填写
// summaryEvaluation.Status = domain.EvaluationCompleted
// //删除旧的填写值,使用新的填写内容
// err = itemValueRepo.RemoveBySummaryEvaluationId(summaryEvaluation.Id)
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// for _, val := range itemValueList {
// val.Id = 0
// }
// }
// //保存填写值
// for _, v := range itemValueList {
// err = itemValueRepo.Save(v)
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// }
// // 针对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 err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// if !param.IsTemporary {
// err = srv.AfterCompletedEvaluation360Hrbp(transactionContext, summaryEvaluation, 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
// }
// 提交员工的人资评估 或者 360 评估
// 变更上级评估的开始时间
// 或者生成考核结果
func (srv *SummaryEvaluationService) AfterCompletedEvaluation360Hrbp(
transactionContext application.TransactionContext,
evaluationData *domain.SummaryEvaluation,
evaluationValue []*domain.SummaryEvaluationValue,
) error {
evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
_, evaluation360HrbList, err := evaluationRepo.Find(map[string]interface{}{
"targetUserId": evaluationData.TargetUser.UserId,
"typesList": []int{int(domain.Evaluation360), int(domain.EvaluationHrbp)},
"cycleId": evaluationData.CycleId,
"limit": 500,
})
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
allCompleted := true
for _, v := range evaluation360HrbList {
if v.Status == domain.EvaluationUncompleted {
allCompleted = false
break
}
}
_, evaluationList, err := evaluationRepo.Find(map[string]interface{}{
"targetUserId": evaluationData.TargetUser.UserId,
"typesList": []int{int(domain.EvaluationSuper)},
"cycleId": evaluationData.CycleId,
"limit": 1,
})
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
_, evaluationFinishList, 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 !allCompleted {
return nil
}
nowTime := time.Now()
updatedId := []int{}
// 变更上级评估的开始时间
for _, v := range evaluationList {
if v.BeginTime.After(nowTime) {
v.BeginTime = nowTime
updatedId = append(updatedId, v.Id)
}
}
evaluationDao := dao.NewSummaryEvaluationDao(map[string]interface{}{
"transactionContext": transactionContext,
})
err = evaluationDao.UpdateBeginTime(updatedId, nowTime)
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if len(evaluationList) == 0 {
//没有上级评估
//直接进入考核结果阶段
if len(evaluationFinishList) > 0 {
if evaluationFinishList[0].BeginTime.After(nowTime) {
evaluationFinishList[0].BeginTime = nowTime
}
evaluationFinishList[0].Status = domain.EvaluationCompleted
err = evaluationRepo.Save(evaluationFinishList[0])
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存考核结果,"+err.Error())
}
//添加确认绩效成绩提醒短信提醒
err = notify.AddNotifyConfirmEvaluationScore(evaluationFinishList[0])
if err != nil {
return application.ThrowError(application.TRANSACTION_ERROR, "创建短信提醒失败"+err.Error())
}
}
}
return nil
}
// EditEvaluationHRBP 编辑提交人资综评
func (srv *SummaryEvaluationService) EditEvaluationHRBP(param *command.EditEvaluationValue) (map[string][]adapter.EvaluationItemAdapter, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
... ... @@ -73,7 +295,9 @@ func (srv *SummaryEvaluationService) EditEvaluationHRBP(param *command.EditEvalu
if len(evaluationList) > 0 && evaluationList[0].CheckResult == domain.EvaluationCheckCompleted {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "用户已经确认该周期的考核结果,不能再编辑!")
}
if ok := summaryEvaluation.EndTime.Before(time.Now()); ok {
return nil, application.ThrowError(application.BUSINESS_ERROR, "评估时间已截止")
}
// 自评评估内容(自评模板、筛选项目评估人)
_, itemList, err := itemUsedRepo.Find(map[string]interface{}{
"evaluationProjectId": summaryEvaluation.EvaluationProjectId,
... ... @@ -89,11 +313,56 @@ func (srv *SummaryEvaluationService) EditEvaluationHRBP(param *command.EditEvalu
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
//更新填写值
var evaluationValueSlice []*domain.SummaryEvaluationValue // 提交的填写值
{
err = srv.editEvaluationValue(summaryEvaluation, &itemValueList, itemList, param.EvaluationItems, nil, param.IsTemporary)
evaluationItemMap := map[int]*domain.EvaluationItemUsed{} // 需要填写那些项 Id=>&domain.EvaluationItemUsed{}
evaluationValueMap := map[int]*domain.SummaryEvaluationValue{} // 提交的填写值 EvaluationItemId=>&domain.domain.SummaryEvaluationValue{}
summaryEvaluation.TotalRating = nil // 清空评级数量统计
// 按照需要填写那些项 设置SummaryEvaluationValue的空白值
for _, v := range itemList {
newValue := &domain.SummaryEvaluationValue{}
newValue.SetBlankValue(summaryEvaluation, 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 := summaryEvaluation.FillItemValue(evaluationItem, newItemValue, v.Value)
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
}
summaryEvaluation.EvaluationTotalScore(evaluationValueSlice)
}
if !param.IsTemporary {
//变更评估状态为已填写
summaryEvaluation.Status = domain.EvaluationCompleted
... ... @@ -102,12 +371,12 @@ func (srv *SummaryEvaluationService) EditEvaluationHRBP(param *command.EditEvalu
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
for _, val := range itemValueList {
for _, val := range evaluationValueSlice {
val.Id = 0
}
}
//保存填写值
for _, v := range itemValueList {
for _, v := range evaluationValueSlice {
err = itemValueRepo.Save(v)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ... @@ -145,113 +414,3 @@ func (srv *SummaryEvaluationService) EditEvaluationHRBP(param *command.EditEvalu
"evaluationItems": itemValueAdapter,
}, nil
}
// 提交员工的人资评估 或者 360 评估
// 变更上级评估的开始时间
// 或者生成考核结果
func (srv *SummaryEvaluationService) AfterCompletedEvaluation360Hrbp(
transactionContext application.TransactionContext,
evaluationData *domain.SummaryEvaluation,
evaluationValue []*domain.SummaryEvaluationValue,
) error {
evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
_, evaluation360HrbList, err := evaluationRepo.Find(map[string]interface{}{
"targetUserId": evaluationData.TargetUser.UserId,
"typesList": []int{int(domain.Evaluation360), int(domain.EvaluationHrbp)},
"cycleId": evaluationData.CycleId,
"limit": 500,
})
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
allCompleted := true
for _, v := range evaluation360HrbList {
if v.Status == domain.EvaluationUncompleted {
allCompleted = false
break
}
}
_, evaluationList, err := evaluationRepo.Find(map[string]interface{}{
"targetUserId": evaluationData.TargetUser.UserId,
"typesList": []int{int(domain.EvaluationSuper)},
"cycleId": evaluationData.CycleId,
"limit": 1,
})
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
//noSuper := (len(evaluationList) == 0)
_, evaluationFinishList, 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 !allCompleted {
//仅同步评估内容到考核结果
// if noSuper && len(evaluationFinishList) > 0 {
// //不存在上级评估
// err = srv.syncEvaluationFinishValue(transactionContext, evaluationFinishList[0], evaluationValue)
// if err != nil {
// return err
// }
// }
return nil
}
nowTime := time.Now()
updatedId := []int{}
// 变更上级评估的开始时间
for _, v := range evaluationList {
if v.BeginTime.After(nowTime) {
v.BeginTime = nowTime
updatedId = append(updatedId, v.Id)
}
}
evaluationDao := dao.NewSummaryEvaluationDao(map[string]interface{}{
"transactionContext": transactionContext,
})
err = evaluationDao.UpdateBeginTime(updatedId, nowTime)
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if len(evaluationList) == 0 {
//没有上级评估
//直接进入考核结果阶段
if len(evaluationFinishList) > 0 {
if evaluationFinishList[0].BeginTime.After(nowTime) {
evaluationFinishList[0].BeginTime = nowTime
}
evaluationFinishList[0].Status = domain.EvaluationCompleted
err = evaluationRepo.Save(evaluationFinishList[0])
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存考核结果,"+err.Error())
}
//添加确认绩效成绩提醒短信提醒
err = notify.AddNotifyConfirmEvaluationScore(evaluationFinishList[0])
if err != nil {
return application.ThrowError(application.TRANSACTION_ERROR, "创建短信提醒失败"+err.Error())
}
}
}
// if noSuper && len(evaluationFinishList) > 0 {
//不存在上级评估
// err = srv.syncEvaluationFinishValue(transactionContext, evaluationFinishList[0], evaluationValue)
// if err != nil {
// return err
// }
// } else if len(evaluationList) == 0 && len(evaluationFinishList) > 0 {
// err = evaluationRepo.Save(evaluationFinishList[0])
// if err != nil {
// return application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存考核结果,"+err.Error())
// }
// }
return nil
}
... ...
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
}
... ...
... ... @@ -480,375 +480,6 @@ func (srv *SummaryEvaluationService) getSummaryEvaluation(transactionContext app
return result
}
// 编辑综合自评详情
// func (srv *SummaryEvaluationService) EditEvaluationSelf(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()
// }()
// 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, "没有操作权限")
// }
// _, 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())
// }
// err = srv.editEvaluationValue(evaluationData, &itemValueList, itemList, param.EvaluationItems, nil, param.IsTemporary)
// if err != nil {
// return nil, application.ThrowError(application.BUSINESS_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 {
// evaluationData.Status = domain.EvaluationCompleted
// }
// err = evaluationRepo.Save(evaluationData)
// 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())
// }
// if !param.IsTemporary {
// err = srv.AfterCompletedEvaluationSelf(evaluationData)
// if err != nil {
// return nil, err
// }
// }
// itemValueAdapter := srv.buildSummaryItemValue(itemList, itemValueList)
// return map[string][]adapter.EvaluationItemAdapter{
// "EvaluationItems": itemValueAdapter,
// }, nil
// }
// // 员工提交自评内容后,
// // 员工作为被评估人,
// // 变更360评估/人资评估/的开始时间
// // 或者变更上级评估的开始时间
// // 或者生成考核结果
// func (srv *SummaryEvaluationService) AfterCompletedEvaluationSelf(param *domain.SummaryEvaluation) error {
// lock := xredis.NewLockSummaryEvaluation(param.TargetUser.UserId)
// err := lock.Lock()
// if err != nil {
// return application.ThrowError(application.INTERNAL_SERVER_ERROR, "未能完全提交评估内容")
// }
// defer func() {
// lock.UnLock()
// }()
// 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()
// }()
// evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{
// "transactionContext": transactionContext,
// })
// _, evaluationList, err := evaluationRepo.Find(map[string]interface{}{
// "targetUserId": param.TargetUser.UserId,
// "typesList": []int{int(domain.Evaluation360), int(domain.EvaluationHrbp)},
// "cycleId": param.CycleId,
// "limit": 1000,
// })
// if err != nil {
// return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// if len(evaluationList) == 0 {
// //如果没有360评估和hrbp 评估,查找上级评估
// _, evaluationList, err = evaluationRepo.Find(map[string]interface{}{
// "targetUserId": param.TargetUser.UserId,
// "typesList": []int{int(domain.EvaluationSuper)},
// "cycleId": param.CycleId,
// "limit": 10,
// })
// if err != nil {
// return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// }
// nowTime := time.Now()
// updatedId := []int{}
// // 变更360评估/人资评估/上级评估的开始时间
// for _, v := range evaluationList {
// if v.BeginTime.After(nowTime) {
// v.BeginTime = nowTime
// updatedId = append(updatedId, v.Id)
// }
// }
// evaluationDao := dao.NewSummaryEvaluationDao(map[string]interface{}{
// "transactionContext": transactionContext,
// })
// err = evaluationDao.UpdateBeginTime(updatedId, nowTime)
// if err != nil {
// return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// if len(evaluationList) == 0 {
// //没有上级评估、360评估、hrbp 评估
// //直接进入考核结果阶段
// _, evaluationFinishList, err := evaluationRepo.Find(map[string]interface{}{
// "targetUserId": param.TargetUser.UserId,
// "typesList": []int{int(domain.EvaluationFinish)},
// "cycleId": param.CycleId,
// "limit": 1,
// })
// if err != nil {
// return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// if len(evaluationFinishList) > 0 {
// //进入考核结果
// //自评的结束时间
// if evaluationFinishList[0].BeginTime.After(nowTime) {
// evaluationFinishList[0].BeginTime = nowTime
// }
// evaluationFinishList[0].Status = domain.EvaluationCompleted
// err = evaluationRepo.Save(evaluationFinishList[0])
// if err != nil {
// return application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存考核结果,"+err.Error())
// }
// //添加确认绩效成绩提醒短信提醒
// err = notify.AddNotifyConfirmEvaluationScore(evaluationFinishList[0])
// if err != nil {
// return application.ThrowError(application.TRANSACTION_ERROR, "创建短信提醒失败"+err.Error())
// }
// }
// }
// if err := transactionContext.CommitTransaction(); err != nil {
// return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// return nil
// }
// 提交员工的人资评估 或者 360 评估
// 变更上级评估的开始时间
// 或者生成考核结果
// func (srv *SummaryEvaluationService) AfterCompletedEvaluation360Hrbp(param *domain.SummaryEvaluation) error {
// lock := xredis.NewLockSummaryEvaluation(param.TargetUser.UserId)
// err := lock.Lock()
// if err != nil {
// return application.ThrowError(application.INTERNAL_SERVER_ERROR, "未能完全提交评估内容")
// }
// defer func() {
// lock.UnLock()
// }()
// 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()
// }()
// evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{
// "transactionContext": transactionContext,
// })
// _, evaluation360HrbList, err := evaluationRepo.Find(map[string]interface{}{
// "targetUserId": param.TargetUser.UserId,
// "typesList": []int{int(domain.Evaluation360), int(domain.EvaluationHrbp)},
// "cycleId": param.CycleId,
// "limit": 1000,
// })
// if err != nil {
// return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// allCompleted := true
// for _, v := range evaluation360HrbList {
// if v.Status == domain.EvaluationUncompleted {
// allCompleted = false
// break
// }
// }
// if !allCompleted {
// return nil
// }
// _, evaluationList, err := evaluationRepo.Find(map[string]interface{}{
// "targetUserId": param.TargetUser.UserId,
// "typesList": []int{int(domain.EvaluationSuper)},
// "cycleId": param.CycleId,
// "limit": 1,
// })
// if err != nil {
// return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// nowTime := time.Now()
// updatedId := []int{}
// // 变更上级评估的开始时间
// for _, v := range evaluationList {
// if v.BeginTime.After(nowTime) {
// v.BeginTime = nowTime
// updatedId = append(updatedId, v.Id)
// }
// }
// evaluationDao := dao.NewSummaryEvaluationDao(map[string]interface{}{
// "transactionContext": transactionContext,
// })
// err = evaluationDao.UpdateBeginTime(updatedId, nowTime)
// if err != nil {
// return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// if len(evaluationList) == 0 {
// //没有上级评估
// //直接进入考核结果阶段
// _, evaluationFinishList, err := evaluationRepo.Find(map[string]interface{}{
// "targetUserId": param.TargetUser.UserId,
// "typesList": []int{int(domain.EvaluationFinish)},
// "cycleId": param.CycleId,
// "limit": 1,
// })
// if err != nil {
// return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// if len(evaluationFinishList) > 0 {
// if evaluationFinishList[0].BeginTime.After(nowTime) {
// evaluationFinishList[0].BeginTime = nowTime
// }
// evaluationFinishList[0].Status = domain.EvaluationCompleted
// err = evaluationRepo.Save(evaluationFinishList[0])
// if err != nil {
// return application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存考核结果,"+err.Error())
// }
// //添加确认绩效成绩提醒短信提醒
// err = notify.AddNotifyConfirmEvaluationScore(evaluationFinishList[0])
// if err != nil {
// return application.ThrowError(application.TRANSACTION_ERROR, "创建短信提醒失败"+err.Error())
// }
// }
// }
// if err := transactionContext.CommitTransaction(); err != nil {
// return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// return nil
// }
// // 员工提交上级评估后
// // 生成考核结果
// func (srv *SummaryEvaluationService) AfterCompletedEvaluationSuper(param *domain.SummaryEvaluation) error {
// lock := xredis.NewLockSummaryEvaluation(param.TargetUser.UserId)
// err := lock.Lock()
// if err != nil {
// return application.ThrowError(application.INTERNAL_SERVER_ERROR, "未能完全提交评估内容")
// }
// defer func() {
// lock.UnLock()
// }()
// 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()
// }()
// evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{
// "transactionContext": transactionContext,
// })
// //没有上级评估
// //直接进入考核结果阶段
// _, evaluationList, err := evaluationRepo.Find(map[string]interface{}{
// "targetUserId": param.TargetUser.UserId,
// "typesList": []int{int(domain.EvaluationFinish)},
// "cycleId": param.CycleId,
// "limit": 1,
// })
// if err != nil {
// return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// if len(evaluationList) > 0 {
// //上级评估的结束时间
// // evaluationList[0].BeginTime = param.EndTime
// nowTime := time.Now()
// if evaluationList[0].BeginTime.After(nowTime) {
// evaluationList[0].BeginTime = nowTime
// }
// evaluationList[0].Status = domain.EvaluationCompleted
// err = evaluationRepo.Save(evaluationList[0])
// if err != nil {
// return application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存考核结果,"+err.Error())
// }
// //TODO 更新考核成绩
// //添加确认绩效成绩提醒短信提醒
// err = notify.AddNotifyConfirmEvaluationScore(evaluationList[0])
// if err != nil {
// return application.ThrowError(application.TRANSACTION_ERROR, "创建短信提醒失败"+err.Error())
// }
// }
// if err := transactionContext.CommitTransaction(); err != nil {
// return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// return nil
// }
// GetTargetUserCycleList
// 获取周期列表,被评估的周期列表
func (srv *SummaryEvaluationService) GetTargetUserCycleList(param *command.QueryCycleList) (map[string]interface{}, error) {
... ... @@ -1116,76 +747,6 @@ func (srv *SummaryEvaluationService) GetEvaluationSuper(param *command.QueryEval
return &result, nil
}
// getEvaluationSuperDefaultValue
// 按照权限设置,是否获取上级评估内容的默认值
func (srv *SummaryEvaluationService) getEvaluationSuperDefaultValue(transactionContext application.TransactionContext, evaluationData *domain.SummaryEvaluation) (
[]*domain.SummaryEvaluationValue, error) {
evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
itemValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
permissionData, err := getPermission(int64(evaluationData.CompanyId))
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if permissionData.OptEvalScore == domain.PermissionOn && permissionData.OptHrScore == domain.PermissionOn {
return nil, nil
}
// 获取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 nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
evaluationIds := []int{}
for _, v := range evaluationListOther {
evaluationIds = append(evaluationIds, v.Id)
}
if len(evaluationIds) == 0 {
return nil, nil
}
// 将360评估,人资评估填写的值 作为默认值
_, itemValuesOther, err := itemValueRepo.Find(map[string]interface{}{
"summaryEvaluationIdList": evaluationIds,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 记录人资评估或者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)
}
}
if permissionData.OptHrScore == domain.PermissionOff {
//上级是否可以修改人资综评分数
//获取人资综合评分
for _, v := range itemValuesOther {
//记录人资评估或者360评估的填写值
if v.Types != domain.EvaluationHrbp {
continue
}
hrbpOr360ItemValue = append(hrbpOr360ItemValue, v)
}
}
return hrbpOr360ItemValue, nil
}
// 获取执行人的上级评估的列表
func (srv *SummaryEvaluationService) ListExecutorEvaluationSuper(param *command.QueryExecutorEvaluationList) (map[string]interface{}, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
... ... @@ -1824,8 +1385,6 @@ func (srv *SummaryEvaluationService) editEvaluationValueUnlimited(
evaluationValueMap[v.Id] = newValue
evaluationItemMap[v.Id] = v
evaluationValueSlice = append(evaluationValueSlice, newValue)
//重置计数
evaluationData.ResetTotalRating(v)
}
//如果存在旧值
//新值的id 替换为旧值id
... ... @@ -1858,12 +1417,12 @@ func (srv *SummaryEvaluationService) editEvaluationValueUnlimited(
}
}
}
newItemValue.Remark = v.Remark
//填充评估填写值
err := newItemValue.FillValue(evaluationItem, v.Value, v.Remark)
err := evaluationData.FillItemValue(evaluationItem, newItemValue, v.Value)
if err != nil {
return err
}
// }
}
// 填入固定的默认值
for _, v := range defaultItemValue {
... ... @@ -1875,6 +1434,7 @@ func (srv *SummaryEvaluationService) editEvaluationValueUnlimited(
if !ok {
continue
}
//填充评估填写值
err := newItemValue.FillValue(evaluationItem, v.Value, newItemValue.Remark)
if err != nil {
... ...
... ... @@ -335,110 +335,6 @@ func (srv *SummaryEvaluationService) GetEvaluation360Complete(param *command.Que
return &itemValuesAdapter, nil
}
// EditEvaluation360 编辑提交360综评
// func (srv *SummaryEvaluationService) EditEvaluation360(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()
// }()
// 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})
// summaryEvaluation, err := evaluationRepo.FindOne(map[string]interface{}{"id": param.SummaryEvaluationId})
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// if summaryEvaluation.Executor.UserId != param.ExecutorId {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")
// }
// if summaryEvaluation.CompanyId != param.CompanyId {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")
// }
// _, evaluationList, err := evaluationRepo.Find(map[string]interface{}{
// "targetUserId": summaryEvaluation.TargetUser.UserId,
// "typesList": []int{int(domain.EvaluationFinish)},
// "cycleId": summaryEvaluation.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": summaryEvaluation.EvaluationProjectId,
// "nodeType": domain.LinkNodeSelfAssessment,
// "evaluatorId": param.ExecutorId,
// })
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// // 评估内容对应的分数
// _, itemValueList, err := itemValueRepo.Find(map[string]interface{}{"summaryEvaluationId": summaryEvaluation.Id})
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// err = srv.editEvaluationValue(summaryEvaluation, &itemValueList, itemList, param.EvaluationItems, nil, param.IsTemporary)
// if err != nil {
// return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
// }
// if !param.IsTemporary {
// //变更评估状态为已填写
// summaryEvaluation.Status = domain.EvaluationCompleted
// }
// //保存填写值
// for _, v := range itemValueList {
// err = itemValueRepo.Save(v)
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// }
// //保存填写值
// err = evaluationRepo.Save(summaryEvaluation)
// 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())
// }
// if !param.IsTemporary {
// err = srv.AfterCompletedEvaluation360Hrbp(summaryEvaluation)
// if err != nil {
// return nil, err
// }
// }
// itemValueAdapter := srv.buildSummaryItemValue(itemList, itemValueList)
// return map[string][]adapter.EvaluationItemAdapter{
// "evaluationItems": itemValueAdapter,
// }, nil
// }
// EvaluationHRBPList 获取人资综评列表
func (srv *SummaryEvaluationService) EvaluationHRBPList(param *command.QueryEvaluationHRList) (map[string]interface{}, error) {
transactionContext, err := factory.ValidateStartTransaction(param)
... ... @@ -724,145 +620,6 @@ func (srv *SummaryEvaluationService) GetEvaluationHRBPComplete(param *command.Qu
return &itemValuesAdapter, nil
}
// 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
// }
// // 获取考核结果评分
// _, 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())
// }
// var super *domain.SummaryEvaluation // 上级评估
// for i := range evaluationList {
// it := evaluationList[i]
// if it.Types == domain.EvaluationSuper {
// super = it
// break
// }
// }
// // 获取自评模板
// _, 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 {
// _, 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
// }
// GetUnconfirmedCycleList 获取未确认绩效成绩的周期列表
func (srv *SummaryEvaluationService) GetUnconfirmedCycleList(companyId int, userId int) (map[string]interface{}, error) {
transactionContext, err := factory.StartTransaction()
... ...
... ... @@ -25,6 +25,7 @@ type SummaryEvaluation struct {
EndTime time.Time `json:"endTime"` //截止时间
TotalScore string `json:"totalScore"` //最终上级评估得分.
TotalRating []RatingCodeNumber `json:"totalRating"` //汇总各个评级的数量
Version string `json:"version"` //填写评估值的规则版本 v1,v2
CreatedAt time.Time `json:"createdAt"` //数据创建时间
UpdatedAt time.Time `json:"updatedAt"` //数据更新时间
DeletedAt *time.Time `json:"deletedAt"` //数据删除时间
... ... @@ -135,3 +136,23 @@ func (evaluation *SummaryEvaluation) SumRatingCode(code string) {
})
}
}
// 更新填写的评估值
func (evaluation *SummaryEvaluation) FillItemValue(item *EvaluationItemUsed, itemValue *SummaryEvaluationValue, value string) error {
evaluation.ResetTotalRating(item) //重置计数
//自评
if evaluation.Types == EvaluationSelf {
return itemValue.FillValue(item, value, "")
}
// 非自评的情况
// 按照版本使用不同的填写规则
switch evaluation.Version {
case "v1":
itemValue.FillValue(item, value, "")
case "v2":
itemValue.FillValueV2(item, value)
default:
itemValue.FillValue(item, value, "")
}
return nil
}
... ...
... ... @@ -22,6 +22,7 @@ type SummaryEvaluationValue struct {
Rating RatingLevel `json:"rating"` //评级时的填写值
CreatedAt time.Time `json:"createdAt"` //数据创建时间
UpdatedAt time.Time `json:"updatedAt"` //数据更新时间
Version string `json:"version"`
}
type SummaryEvaluationValueRepository interface {
... ... @@ -46,7 +47,7 @@ func (itemValue *SummaryEvaluationValue) SetBlankValue(evaluation *SummaryEvalua
itemValue.Executor = evaluation.Executor
}
// 填充评估的内容
// 自评 填充评估的内容的规则
func (itemValue *SummaryEvaluationValue) FillValue(item *EvaluationItemUsed, value string, remark string) error {
itemValue.Remark = remark
if item.Weight == 0 {
... ... @@ -115,3 +116,35 @@ func (itemValue *SummaryEvaluationValue) valueTypeScore(item *EvaluationItemUsed
}
return nil
}
// 360评估,上级评估 ,人资评估 填写评估值的规则
func (itemValue *SummaryEvaluationValue) FillValueV2(item *EvaluationItemUsed, value string) error {
value = strings.TrimSpace(value)
itemValue.Value = value
//处理空值
if len(value) == 0 {
itemValue.Score = "0"
return nil
}
valueNumber, err := strconv.ParseFloat(value, 64)
if err != nil {
return fmt.Errorf("条目%d:%s-%s评分值异常", item.Id, item.Category, item.Name)
}
if item.Weight <= 0 {
//无权重的情况
itemValue.Score = value
return nil
}
// 有权重的情况
if item.EvaluatorId < 0 {
//hrbp 的评分方式
itemValue.Score = value
return nil
} else {
// 非hrbp的评分方式 分值=评分*权重
// 分数保留2位小数
score := valueNumber * item.Weight
itemValue.Score = fmt.Sprintf("%.2f", score)
}
return nil
}
... ...
... ... @@ -25,6 +25,7 @@ type SummaryEvaluation struct {
BeginTime time.Time //开始时间
EndTime time.Time //截止时间
TotalScore string //最终上级评估得分.
Version string //填写评估值的规则版本 v1,v2
TotalRating []domain.RatingCodeNumber //汇总评级
CreatedAt time.Time //数据创建时间
UpdatedAt time.Time //数据更新时间
... ...
... ... @@ -36,6 +36,7 @@ func (repo *SummaryEvaluationRepository) TransformToDomain(d *models.SummaryEval
Types: domain.EvaluationType(d.Types),
Status: domain.EvaluationStatus(d.Status),
CheckResult: domain.EvaluationCheckResult(d.CheckResult),
Version: d.Version,
BeginTime: d.BeginTime,
EndTime: d.EndTime,
TotalScore: d.TotalScore,
... ... @@ -61,6 +62,7 @@ func (repo *SummaryEvaluationRepository) Save(param *domain.SummaryEvaluation) e
Types: int(param.Types),
Status: string(param.Status),
CheckResult: string(param.CheckResult),
Version: param.Version,
BeginTime: param.BeginTime,
EndTime: param.EndTime,
TotalScore: param.TotalScore,
... ...
... ... @@ -25,7 +25,7 @@ func init() {
web.NSCtrlPost("/evaluation-hrAll", (*controllers.SummaryEvaluationController).GetEvaluationHRBPComplete),
web.NSCtrlPost("/evaluation-hr/edit", (*controllers.SummaryEvaluationController).EditEvaluationHRBP),
web.NSCtrlPost("/evaluation-hr/list", (*controllers.SummaryEvaluationController).EvaluationHRBPList),
web.NSCtrlPost("/self/summary", (*controllers.SummaryEvaluationController).CountEvaluationSelfLevel),
// web.NSCtrlPost("/self/summary", (*controllers.SummaryEvaluationController).CountEvaluationSelfLevel),
web.NSCtrlPost("/evaluation-super", (*controllers.SummaryEvaluationController).GetEvaluationSuper),
web.NSCtrlPost("/evaluation-super/edit", (*controllers.SummaryEvaluationController).EditEvaluationSuper),
web.NSCtrlPost("/evaluation-super/list", (*controllers.SummaryEvaluationController).ListExecutorEvaluationSuper),
... ...