作者 tangxvhui

暂存

package service
import (
"fmt"
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
roleService "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/role"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/summary_evaluation/command"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
)
// 超管直接修改考核结果分数
// 修改周期考核的分数
func (srv *SummaryEvaluationService) ModifyFinishScoreV2(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})
evaluationValueRepo := 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
}
evaluationFinishData := evaluationList[0]
if evaluationFinishData.Types != domain.EvaluationFinish {
return nil
}
// 获取考核评估项
var evaluationFinishValue []*domain.SummaryEvaluationValue
var saveNewValue bool //是否需要保存新的考核评估项评估
//尝试 获取考核结果的评估项
_, evaluationFinishValue, err = evaluationValueRepo.Find(map[string]interface{}{"summaryEvaluationId": evaluationFinishData.Id})
if err != nil {
return application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
if len(evaluationFinishValue) == 0 {
saveNewValue = true
// 尝试获取目标人员的上级评估内容
_, itemValue, err := evaluationRepo.Find(map[string]interface{}{
"targetUserId": evaluationFinishData.TargetUser.UserId,
"cycleId": evaluationFinishData.CycleId,
"types": domain.EvaluationSuper,
})
if err != nil {
return application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
}
if len(evaluationFinishValue) == 0 {
//尝试获取目标人员的360评估、人资评估、自评的评估内容
}
scoreStr := fmt.Sprintf("%.2f", param.Score)
evaluationFinishData.TotalScore = scoreStr
evaluationFinishData.Status = domain.EvaluationCompleted
err = evaluationRepo.Save(evaluationFinishData)
if err != nil {
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())
}
return nil
}
// buildSummaryFinishValue
// 当未能按照id直接查询到考核结果的评估项时,
// 从目标人员的上级评估 或者360评估、人资评估、自评 构建考核结果的评估项内容
func (srv *SummaryEvaluationService) buildSummaryFinishValue(transactionContext application.TransactionContext, evaluationFinisih *domain.SummaryEvaluation) (
[]*domain.SummaryEvaluationValue, error) {
evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{"transactionContext": transactionContext})
evaluationValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{"transactionContext": transactionContext})
//尝试获取目标人员的所有评估
_, evaluationList, err := evaluationRepo.Find(map[string]interface{}{
"targetUserId": evaluationFinisih.TargetUser.UserId,
"cycleId": evaluationFinisih.CycleId,
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
var evaluationFinishValue []*domain.SummaryEvaluationValue
var evaluationData *domain.SummaryEvaluation
//尝试获取目标人员的上级评估
for _, val := range evaluationList {
evaluationData = val
}
if evaluationData != nil {
return evaluationFinishValue, nil
}
return nil, nil
}
... ...