get_evaluation.go 3.4 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
	_, evaluationList, 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())
	}
	// 查找上级评估数据
	// 如果没有就查找 360 或人资评估数据
	if len(evaluationList) == 0 {
		_, evaluationList, 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())
		}
	}
	if len(evaluationList) == 0 {
		return nil, application.ThrowError(application.BUSINESS_ERROR, "该人员没有上级评估、人资评估、360评估。")
	}

	var evaluationIds []int64
	for _, val := range evaluationList {
		evaluationIds = append(evaluationIds, int64(val.Id))
	}
	_, 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
}