get_evaluation.go 4.6 KB
package service

import (
	"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"
	"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/summary_evaluation/command"
	"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
)

// 评估信息详情 根据页面需要提供不同的结构变体

// 人资稽查-页面列表,获取详情 用于编辑展示
func (srv *SummaryEvaluationService) GetEvaluationShow1(param command.QueryEvaluation) (result *adapter.EvaluationInfoAdapter, err error) {
	transactionContext, err := factory.ValidateStartTransaction(param)
	if err != nil {
		return nil, err
	}
	defer func() {
		_ = transactionContext.RollbackTransaction()
	}()
	//每个人员每个周期的评估目录
	evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{"transactionContext": transactionContext})
	// 评估的填写值
	evaluationValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{"transactionContext": transactionContext})
	//评估用到的题目
	itemUsedRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{"transactionContext": transactionContext})
	//获取 评估考核结果
	var evaluationList []*domain.SummaryEvaluation
	var evaluationValueList []*domain.SummaryEvaluationValue
	_, evaluationList, err = evaluationRepo.Find(map[string]interface{}{
		"limit":        1,
		"companyId":    param.CompanyId,
		"cycleId":      param.CycleId,
		"targetUserId": param.TargetUserId,
		"types":        domain.EvaluationFinish,
	})
	if err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
	if len(evaluationList) == 0 {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "该人员缺少考评评估结果")
	}
	if len(evaluationList) > 0 {
		_, evaluationValueList, err = evaluationValueRepo.Find(map[string]interface{}{"summaryEvaluationId": evaluationList[0].Id})
		if err != nil {
			return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
		}
	}
	//如果没有评估考核结果,就获取上级评估的内容
	if len(evaluationValueList) == 0 {
		_, evaluationList2, err := evaluationRepo.Find(map[string]interface{}{
			"limit":        1,
			"companyId":    param.CompanyId,
			"cycleId":      param.CycleId,
			"targetUserId": param.TargetUserId,
			"types":        domain.EvaluationSuper,
		})
		if err != nil {
			return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
		}
		if len(evaluationList2) > 0 {
			_, evaluationValueList, err = evaluationValueRepo.Find(map[string]interface{}{"summaryEvaluationId": evaluationList2[0].Id})
			if err != nil {
				return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
			}
		}
		// 如果没有评估考核结果的填写内容
		// 也没有上级评估
		// 就查找 360 或人资评估数据
		if len(evaluationList2) == 0 {
			_, evaluationList3, err := evaluationRepo.Find(map[string]interface{}{
				"limit":        500,
				"companyId":    param.CompanyId,
				"cycleId":      param.CycleId,
				"targetUserId": param.TargetUserId,
				"typesList":    []int{int(domain.EvaluationHrbp), int(domain.Evaluation360)},
			})
			if err != nil {
				return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
			}
			evaluationIds := []int{}
			for _, val := range evaluationList3 {
				evaluationIds = append(evaluationIds, val.Id)
			}
			if len(evaluationIds) > 0 {
				_, evaluationValueList, err = evaluationValueRepo.Find(map[string]interface{}{"summaryEvaluationIdList": evaluationIds})
				if err != nil {
					return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
				}
			}
		}
	}
	evaluationProjectId := evaluationList[0].EvaluationProjectId
	//获取所有题目
	_, itemUsedList, err := itemUsedRepo.Find(map[string]interface{}{
		"evaluationProjectId": evaluationProjectId,
		"nodeType":            domain.LinkNodeSelfAssessment,
	})
	// 获取组装基本信息
	evaluationBase := srv.getSummaryEvaluation(transactionContext, evaluationList[0])
	if err := transactionContext.CommitTransaction(); err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
	itemValuesAdapter := srv.buildSummaryItemValue(itemUsedList, evaluationValueList)
	result = &adapter.EvaluationInfoAdapter{
		EvaluationBaseAdapter: evaluationBase,
		EvaluationItems:       itemValuesAdapter,
	}
	return
}