作者 tangxvhui

暂存

  1 +package service
  2 +
  3 +import (
  4 + "fmt"
  5 +
  6 + "github.com/linmadan/egglib-go/core/application"
  7 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
  8 + roleService "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/role"
  9 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/summary_evaluation/command"
  10 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
  11 +)
  12 +
  13 +// 超管直接修改考核结果分数
  14 +// 修改周期考核的分数
  15 +func (srv *SummaryEvaluationService) ModifyFinishScoreV2(param *command.ModifyFinishScore) error {
  16 + transactionContext, err := factory.CreateTransactionContext(nil)
  17 + if err != nil {
  18 + return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  19 + }
  20 + if err := transactionContext.StartTransaction(); err != nil {
  21 + return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  22 + }
  23 + defer func() {
  24 + _ = transactionContext.RollbackTransaction()
  25 + }()
  26 + // 只有超级管理员可以使用的功能
  27 + superAdmin, err := roleService.GetSuperAdmin(transactionContext, param.CompanyId, param.UserId)
  28 + if err != nil {
  29 + return err
  30 + }
  31 + if superAdmin != domain.RoleTypeSuperAdmin {
  32 + return application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")
  33 + }
  34 +
  35 + //获取周期评估任务finish
  36 + evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{"transactionContext": transactionContext})
  37 + evaluationValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{"transactionContext": transactionContext})
  38 + _, evaluationList, err := evaluationRepo.Find(map[string]interface{}{
  39 + "id": []int{param.SummaryEvaluationId},
  40 + "companyId": param.CompanyId,
  41 + })
  42 + if err != nil {
  43 + return application.ThrowError(application.BUSINESS_ERROR, err.Error())
  44 + }
  45 + if len(evaluationList) == 0 {
  46 + return nil
  47 + }
  48 + evaluationFinishData := evaluationList[0]
  49 + if evaluationFinishData.Types != domain.EvaluationFinish {
  50 + return nil
  51 + }
  52 + // 获取考核评估项
  53 + var evaluationFinishValue []*domain.SummaryEvaluationValue
  54 + var saveNewValue bool //是否需要保存新的考核评估项评估
  55 + //尝试 获取考核结果的评估项
  56 + _, evaluationFinishValue, err = evaluationValueRepo.Find(map[string]interface{}{"summaryEvaluationId": evaluationFinishData.Id})
  57 + if err != nil {
  58 + return application.ThrowError(application.BUSINESS_ERROR, err.Error())
  59 + }
  60 +
  61 + if len(evaluationFinishValue) == 0 {
  62 + saveNewValue = true
  63 + // 尝试获取目标人员的上级评估内容
  64 + _, itemValue, err := evaluationRepo.Find(map[string]interface{}{
  65 + "targetUserId": evaluationFinishData.TargetUser.UserId,
  66 + "cycleId": evaluationFinishData.CycleId,
  67 + "types": domain.EvaluationSuper,
  68 + })
  69 + if err != nil {
  70 + return application.ThrowError(application.BUSINESS_ERROR, err.Error())
  71 + }
  72 + }
  73 +
  74 + if len(evaluationFinishValue) == 0 {
  75 + //尝试获取目标人员的360评估、人资评估、自评的评估内容
  76 + }
  77 +
  78 + scoreStr := fmt.Sprintf("%.2f", param.Score)
  79 + evaluationFinishData.TotalScore = scoreStr
  80 + evaluationFinishData.Status = domain.EvaluationCompleted
  81 + err = evaluationRepo.Save(evaluationFinishData)
  82 + if err != nil {
  83 + return application.ThrowError(application.BUSINESS_ERROR, "修改考核结果"+err.Error())
  84 + }
  85 +
  86 + if saveNewValue {
  87 + for _, val := range evaluationFinishValue {
  88 + err = evaluationValueRepo.Save(val)
  89 + if err != nil {
  90 + return application.ThrowError(application.BUSINESS_ERROR, "修改考核结果"+err.Error())
  91 + }
  92 + }
  93 + }
  94 + if err := transactionContext.CommitTransaction(); err != nil {
  95 + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  96 + }
  97 + return nil
  98 +}
  99 +
  100 +// buildSummaryFinishValue
  101 +// 当未能按照id直接查询到考核结果的评估项时,
  102 +// 从目标人员的上级评估 或者360评估、人资评估、自评 构建考核结果的评估项内容
  103 +func (srv *SummaryEvaluationService) buildSummaryFinishValue(transactionContext application.TransactionContext, evaluationFinisih *domain.SummaryEvaluation) (
  104 + []*domain.SummaryEvaluationValue, error) {
  105 + evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{"transactionContext": transactionContext})
  106 + evaluationValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{"transactionContext": transactionContext})
  107 +
  108 + //尝试获取目标人员的所有评估
  109 + _, evaluationList, err := evaluationRepo.Find(map[string]interface{}{
  110 + "targetUserId": evaluationFinisih.TargetUser.UserId,
  111 + "cycleId": evaluationFinisih.CycleId,
  112 + })
  113 + if err != nil {
  114 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  115 + }
  116 + var evaluationFinishValue []*domain.SummaryEvaluationValue
  117 + var evaluationData *domain.SummaryEvaluation
  118 + //尝试获取目标人员的上级评估
  119 + for _, val := range evaluationList {
  120 + evaluationData = val
  121 + }
  122 + if evaluationData != nil {
  123 +
  124 + return evaluationFinishValue, nil
  125 + }
  126 +
  127 + return nil, nil
  128 +}