summary_evaluation.go 4.6 KB
package domain

import (
	"fmt"
	"strconv"
	"time"
)

// 周综合评估
type SummaryEvaluation struct {
	Id                    int                   `json:"id"`
	CompanyId             int                   `json:"companyId"`             //公司id
	EvaluationProjectId   int                   `json:"evaluationProjectId"`   //对应的项目id
	EvaluationProjectName string                `json:"evaluationProjectName"` //对应的项目名称
	CycleId               int64                 `json:"cycleId"`               //对应的周期id
	CycleName             string                `json:"cycleName"`             //对应的周期名称
	NodeId                int                   `json:"nodeId"`                //对应的节点id
	TargetUser            StaffDesc             `json:"targetUser"`            //被评估的目标用户,被执行的
	TargetDepartment      []StaffDepartment     `json:"targetDepartment"`      //被评估的目标用户所在的部门
	Executor              StaffDesc             `json:"executor"`              //填写评估的用户,执行人
	Types                 EvaluationType        `json:"types"`                 //评估类型
	Status                EvaluationStatus      `json:"status"`                //评估的填写状态
	CheckResult           EvaluationCheckResult `json:"checkResult"`           //被执行的人确认评估结果
	BeginTime             time.Time             `json:"beginTime"`             //开始时间
	EndTime               time.Time             `json:"endTime"`               //截止时间
	TotalScore            string                `json:"totalScore"`            //最终上级评估得分.
	TotalRating           []RatingCodeNumber    `json:"totalRating"`           //汇总各个评级的数量
	CreatedAt             time.Time             `json:"createdAt"`             //数据创建时间
	UpdatedAt             time.Time             `json:"updatedAt"`             //数据更新时间
	DeletedAt             *time.Time            `json:"deletedAt"`             //数据删除时间
}

// 各个评级的数量
type RatingCodeNumber struct {
	Code   string `json:"code"`
	Number int    `json:"number"`
}

type EvaluationType int //综合评估类型

const (
	EvaluationSelf  EvaluationType = 1 //自评
	Evaluation360   EvaluationType = 2 //360评估
	EvaluationSuper EvaluationType = 3 //上级评估
	EvaluationHrbp  EvaluationType = 4 //人资评估
)

// 评估的填写状态
type EvaluationStatus string

const (
	EvaluationUncompleted EvaluationStatus = "uncompleted" //未提交填写的内容
	EvaluationCompleted   EvaluationStatus = "completed"   //已提交填写的内容
)

// 被执行的人确认评估结果
type EvaluationCheckResult string

const (
	EvaluationCheckUncompleted EvaluationCheckResult = "uncompleted" //未确认结果
	EvaluationCheckCompleted   EvaluationCheckResult = "completed"   //已确认结果
)

type SummaryEvaluationRepository interface {
	Save(param *SummaryEvaluation) error
	Remove(id int) error
	FindOne(queryOptions map[string]interface{}) (*SummaryEvaluation, error)
	Find(queryOptions map[string]interface{}) (int, []*SummaryEvaluation, error)
}

// 计算总分。TotalScore 保留1位小数
func (evaluation *SummaryEvaluation) EvaluationTotalScore(valueList []*SummaryEvaluationValue) error {
	var totalScore float64
	for _, v := range valueList {
		if v.Weight == 0 {
			evaluation.SumRatingCode(v.Rating.Code)
		} else {
			score, _ := strconv.ParseFloat(v.Score, 64)
			totalScore += score
		}
	}
	evaluation.TotalScore = fmt.Sprintf("%.1f", totalScore)
	return nil
}

// 重置评级统计数量
func (evaluation *SummaryEvaluation) ResetTotalRating(param *EvaluationItemUsed) {
	if param.Weight > 0 {
		return
	}
	if len(evaluation.TotalRating) == 0 {
		evaluation.TotalRating = make([]RatingCodeNumber, 0)
	}
	for _, v := range param.Rule.Rating.Levels {
		isExist := false
		for i2, v2 := range evaluation.TotalRating {
			if v.Code == v2.Code {
				isExist = true
				evaluation.TotalRating[i2].Number = 0
			}
		}
		if isExist {
			evaluation.TotalRating = append(evaluation.TotalRating, RatingCodeNumber{
				Code:   v.Code,
				Number: 0,
			})
		}
	}
}

// 增加对应评级的数量
func (evaluation *SummaryEvaluation) SumRatingCode(code string) {
	if len(code) == 0 {
		return
	}
	codeNotFound := true
	for i := range evaluation.TotalRating {
		if evaluation.TotalRating[i].Code == code {
			evaluation.TotalRating[i].Number += 1
			codeNotFound = false
			break
		}
	}
	if codeNotFound {
		evaluation.TotalRating = append(evaluation.TotalRating, RatingCodeNumber{
			Code:   code,
			Number: 1,
		})
	}
}