审查视图

pkg/domain/summary_evaluation_value.go 3.5 KB
tangxvhui authored
1 2
package domain
tangxvhui authored
3 4 5 6 7
import (
	"fmt"
	"strconv"
	"time"
)
tangxvhui authored
8 9 10

// 周期综合评估填写的内容
type SummaryEvaluationValue struct {
tangxvhui authored
11 12 13 14 15 16 17
	Id                  int            `json:"id"`                  //
	EvaluationItemId    int            `json:"evaluationItemId"`    //评估条目的id
	SummaryEvaluationId int            `json:"summaryEvaluationId"` //综合评估任务(SummaryEvaluation)的id
	Value               string         `json:"value"`               //评估填写的评分
	Score               string         `json:"score"`               //评定得分
	Types               EvaluationType `json:"types"`               //评估类型
	Remark              string         `json:"remark"`              //填写的内容反馈
tangxvhui authored
18
	Weight              float64        `json:"weight"`              //"权重"
tangxvhui authored
19
	Rating              RatingLevel    `json:"rating"`              //评级时的填写值
tangxvhui authored
20 21
	CreatedAt           time.Time      `json:"createdAt"`           //数据创建时间
	UpdatedAt           time.Time      `json:"updatedAt"`           //数据更新时间
22
	IsTemporary         int            `json:"IsTemporary"`         // 0-正式数据 1-临时提交的数据
tangxvhui authored
23
}
tangxvhui authored
24 25 26 27 28 29 30

type SummaryEvaluationValueRepository interface {
	Save(param *SummaryEvaluationValue) error
	Remove(id int) error
	FindOne(queryOptions map[string]interface{}) (*SummaryEvaluationValue, error)
	Find(queryOptions map[string]interface{}) (int, []*SummaryEvaluationValue, error)
}
tangxvhui authored
31 32 33 34 35 36

// 计算周期评估
// 当指标项没有权重的时候,还是进行评级操作,不计算分数
// 分数保留2位小数
func (itemValue *SummaryEvaluationValue) SummaryEvaluationScore() error {
	//计算方式
tangxvhui authored
37
	score, err := itemValue.SumScore()
tangxvhui authored
38 39 40 41 42 43 44
	if err != nil {
		return err
	}
	itemValue.Score = fmt.Sprintf("%.2f", score)
	return nil
}
45
func (itemValue *SummaryEvaluationValue) SumScore() (float64, error) {
46 47 48
	if len(itemValue.Value) == 0 {
		return 0, nil
	}
tangxvhui authored
49 50 51 52
	if itemValue.Weight == 0 {
		//使用评级
		return 0, nil
	}
53
	if itemValue.Types == EvaluationHrbp {
tangxvhui authored
54
		//hrbp 填写值就是得分
55 56 57 58 59 60 61
		valueFloat, err := strconv.ParseFloat(itemValue.Value, 64)
		if err != nil {
			return 0, fmt.Errorf("条目%d系数值异常,%s", itemValue.Id, itemValue.Value)
		}
		return valueFloat, nil
	}
	valueFloat, err := strconv.ParseFloat(itemValue.Value, 64)
tangxvhui authored
62
	if err != nil {
63
		return 0, fmt.Errorf("条目%d系数值异常,%s", itemValue.Id, itemValue.Value)
tangxvhui authored
64
	}
tangxvhui authored
65
	//得分计算方式
66
	score := itemValue.Weight * valueFloat
tangxvhui authored
67 68 69 70 71
	return score, nil
}

// 初始化一个空的value
func (itemValue *SummaryEvaluationValue) SetBlankValue(evaluation *SummaryEvaluation, item *EvaluationItemUsed) {
tangxvhui authored
72
	itemValue.Types = evaluation.Types
tangxvhui authored
73 74 75 76 77 78 79 80 81
	itemValue.EvaluationItemId = item.Id
	itemValue.SummaryEvaluationId = evaluation.Id
	itemValue.Value = ""
	itemValue.Score = ""
	itemValue.Remark = ""
	itemValue.Weight = item.Weight
	itemValue.CreatedAt = time.Now()
	itemValue.UpdatedAt = time.Now()
}
tangxvhui authored
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107

// 填充评估的内容
func (itemValue *SummaryEvaluationValue) FillValue(item *EvaluationItemUsed, value string, remark string) error {
	itemValue.Remark = remark
	itemValue.Value = value
	if item.Weight == 0 {
		//使用评级
		if len(value) == 0 {
			return nil
		}
		var ratingValue *RatingLevel
		for _, v := range item.Rule.Rating.Levels {
			if v.Code == value {
				ratingValue = v
			}
		}
		if (ratingValue == nil) && len(value) > 0 {
			return fmt.Errorf("条目%d系评级值异常", itemValue.EvaluationItemId)
		}
		itemValue.Rating = *ratingValue
		return nil
	}
	//使用评分的形式
	err := itemValue.SummaryEvaluationScore()
	return err
}