作者 tangxvhui

更新

... ... @@ -2,6 +2,7 @@ package service
import (
"fmt"
"time"
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
... ... @@ -12,7 +13,7 @@ import (
// 超管直接修改考核结果分数
// 修改周期考核的分数
func (srv *SummaryEvaluationService) ModifyFinishScoreV2(param *command.ModifyFinishScore) error {
func (srv *SummaryEvaluationService) ModifyFinishScore(param *command.ModifyFinishScore) error {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
... ... @@ -60,13 +61,20 @@ func (srv *SummaryEvaluationService) ModifyFinishScoreV2(param *command.ModifyFi
if len(evaluationFinishValue) == 0 {
saveNewValue = true
evaluationFinishValue, err = srv.buildSummaryFinishValue(transactionContext, evaluationFinishData)
if err != nil {
return application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
}
if len(evaluationFinishValue) == 0 {
//尝试获取目标人员的360评估、人资评估、自评的评估内容
if saveNewValue {
// 重置评级汇总
for _, val := range evaluationFinishValue {
err = evaluationValueRepo.Save(val)
if err != nil {
return application.ThrowError(application.BUSINESS_ERROR, "修改考核结果"+err.Error())
}
}
}
scoreStr := fmt.Sprintf("%.2f", param.Score)
evaluationFinishData.TotalScore = scoreStr
evaluationFinishData.Status = domain.EvaluationCompleted
... ... @@ -75,14 +83,6 @@ func (srv *SummaryEvaluationService) ModifyFinishScoreV2(param *command.ModifyFi
return application.ThrowError(application.BUSINESS_ERROR, "修改考核结果"+err.Error())
}
if saveNewValue {
for _, val := range evaluationFinishValue {
err = evaluationValueRepo.Save(val)
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())
}
... ... @@ -119,8 +119,9 @@ func (srv *SummaryEvaluationService) buildSummaryFinishValue(transactionContext
break
}
}
//使用上级评估的评估内容
if evaluationData != nil {
//使用上级评估的评估内容
_, itemValue, err := evaluationValueRepo.Find(map[string]interface{}{"summaryEvaluationId": evaluationData.Id})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
... ... @@ -141,40 +142,64 @@ func (srv *SummaryEvaluationService) buildSummaryFinishValue(transactionContext
}
evaluationFinishValue = append(evaluationFinishValue, newItemValue)
}
return evaluationFinishValue, nil
}
//使用360评估、人资评估、自评 构建考核结果的评估项内容
var itemValueBack []*domain.SummaryEvaluationValue
var summaryEvaluationId []int
for _, val := range evaluationList {
if val.Types == domain.Evaluation360 || val.Types == domain.EvaluationHrbp || val.Types == domain.EvaluationSelf {
summaryEvaluationId = append(summaryEvaluationId, val.Id)
} else {
//使用360评估、人资评估、自评 构建考核结果的评估项内容
var itemValueBack []*domain.SummaryEvaluationValue
var summaryEvaluationId []int
for _, val := range evaluationList {
if val.Types == domain.Evaluation360 || val.Types == domain.EvaluationHrbp || val.Types == domain.EvaluationSelf {
summaryEvaluationId = append(summaryEvaluationId, val.Id)
}
}
}
if len(summaryEvaluationId) > 0 {
_, itemValueBack, err = evaluationValueRepo.Find(map[string]interface{}{"summaryEvaluationIdList": summaryEvaluationId})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
if len(summaryEvaluationId) > 0 {
_, itemValueBack, err = evaluationValueRepo.Find(map[string]interface{}{"summaryEvaluationIdList": summaryEvaluationId})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
}
}
tempSelf := map[int]*domain.SummaryEvaluationValue{}
temp360 := map[int]*domain.SummaryEvaluationValue{}
tempHRBP := map[int]*domain.SummaryEvaluationValue{}
for i := range itemValueBack {
it := itemValueBack[i]
switch it.Types {
case domain.EvaluationSelf:
tempSelf[it.EvaluationItemId] = it
case domain.Evaluation360:
temp360[it.EvaluationItemId] = it
case domain.EvaluationHrbp:
tempHRBP[it.EvaluationItemId] = it
tempSelf := map[int]*domain.SummaryEvaluationValue{}
temp360 := map[int]*domain.SummaryEvaluationValue{}
tempHRBP := map[int]*domain.SummaryEvaluationValue{}
for i := range itemValueBack {
it := itemValueBack[i]
switch it.Types {
case domain.EvaluationSelf:
tempSelf[it.EvaluationItemId] = it
case domain.Evaluation360:
temp360[it.EvaluationItemId] = it
case domain.EvaluationHrbp:
tempHRBP[it.EvaluationItemId] = it
}
}
nowTime := time.Now()
for _, val := range itemUsed {
var newItemValue *domain.SummaryEvaluationValue
if val.EvaluatorId == 0 {
newItemValue = tempSelf[val.Id]
} else if val.EvaluatorId == -1 {
newItemValue = tempHRBP[val.Id]
} else {
newItemValue = temp360[val.Id]
}
if newItemValue == nil {
newItemValue = &domain.SummaryEvaluationValue{}
newItemValue.SetBlankValue(evaluationFinisih, val)
}
newItemValue.SummaryEvaluationId = 0
newItemValue.Id = 0
newItemValue.CreatedAt = nowTime
newItemValue.UpdatedAt = nowTime
evaluationFinishValue = append(evaluationFinishValue, newItemValue)
}
}
for _, val := range itemUsed {
var newItemValue *domain.SummaryEvaluationValue
// 重置评级汇总
evaluationFinisih.TotalRating = nil
for i := range itemUsed {
evaluationFinisih.ResetTotalRating(itemUsed[i])
}
// 计算分数
if err := evaluationFinisih.EvaluationTotalScore(evaluationFinishValue); err != nil {
return evaluationFinishValue, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return evaluationFinishValue, nil
}
... ...
... ... @@ -849,55 +849,55 @@ func (srv *SummaryEvaluationService) GetEvaluationHRBPComplete(param *command.Qu
// }
// 修改周期考核的分数
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, "没有操作权限")
}
// 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})
_, 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
}
evaluationData := evaluationList[0]
if evaluationData.Types != domain.EvaluationFinish {
return nil
}
scoreStr := fmt.Sprintf("%.2f", param.Score)
evaluationData.TotalScore = scoreStr
evaluationData.Status = domain.EvaluationCompleted
// evaluationData.CheckResult = domain.EvaluationCheckCompleted
err = evaluationRepo.Save(evaluationData)
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
}
// //获取周期评估任务finish
// evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{"transactionContext": transactionContext})
// _, evaluationList, err := evaluationRepo.Find(map[string]interface{}{
// "id": []int{param.SummaryEvaluationId},
// "companyId": param.CompanyId,
// })
// if err != nil {
// return application.ThrowError(application.BUSINESS_ERROR, err.Error())
// }
// if len(evaluationList) == 0 {
// return nil
// }
// evaluationData := evaluationList[0]
// if evaluationData.Types != domain.EvaluationFinish {
// return nil
// }
// scoreStr := fmt.Sprintf("%.2f", param.Score)
// evaluationData.TotalScore = scoreStr
// evaluationData.Status = domain.EvaluationCompleted
// // evaluationData.CheckResult = domain.EvaluationCheckCompleted
// err = evaluationRepo.Save(evaluationData)
// 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) {
... ...