审查视图

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

// 周期综合评估填写的内容
type SummaryEvaluationValue struct {
tangxvhui authored
13 14 15 16 17 18 19
	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"`              //填写的内容反馈
20
	Executor            StaffDesc      `json:"executor"`            //填写评估的用户,执行人
tangxvhui authored
21
	Weight              float64        `json:"weight"`              //"权重"
tangxvhui authored
22
	Rating              RatingLevel    `json:"rating"`              //评级时的填写值
tangxvhui authored
23 24
	CreatedAt           time.Time      `json:"createdAt"`           //数据创建时间
	UpdatedAt           time.Time      `json:"updatedAt"`           //数据更新时间
tangxvhui authored
25
	HrCheck             int            `json:"hrCheck"`             // 记录人员id,人资稽查谁填写评估 ;>0:代表是人资稽查填写的评估
tangxvhui authored
26
}
tangxvhui authored
27 28 29 30

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

// 初始化一个空的value
func (itemValue *SummaryEvaluationValue) SetBlankValue(evaluation *SummaryEvaluation, item *EvaluationItemUsed) {
tangxvhui authored
38
	itemValue.Types = evaluation.Types
tangxvhui authored
39 40 41
	itemValue.EvaluationItemId = item.Id
	itemValue.SummaryEvaluationId = evaluation.Id
	itemValue.Value = ""
tangxvhui authored
42
	itemValue.Score = "0"
tangxvhui authored
43 44 45 46
	itemValue.Remark = ""
	itemValue.Weight = item.Weight
	itemValue.CreatedAt = time.Now()
	itemValue.UpdatedAt = time.Now()
47
	itemValue.Executor = evaluation.Executor
tangxvhui authored
48
	itemValue.HrCheck = 0
tangxvhui authored
49
}
tangxvhui authored
50
tangxvhui authored
51
// 自评 填充评估的内容的规则
tangxvhui authored
52 53 54
func (itemValue *SummaryEvaluationValue) FillValue(item *EvaluationItemUsed, value string, remark string) error {
	itemValue.Remark = remark
	if item.Weight == 0 {
tangxvhui authored
55
		//使用评级的形式
56 57
		err := itemValue.valueTypeRating(item, value)
		return err
tangxvhui authored
58 59
	}
	//使用评分的形式
tangxvhui authored
60 61
	err := itemValue.valueTypeScore(item, value)
tangxvhui authored
62 63
	return err
}
64 65 66 67 68 69

// 填写的值是 评级
func (itemValue *SummaryEvaluationValue) valueTypeRating(item *EvaluationItemUsed, value string) error {
	if item.Weight != 0 {
		return errors.New("评级方式错误")
	}
70
	value = strings.TrimSpace(value)
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
	itemValue.Value = value
	itemValue.Score = "0"
	// 使用评级
	if len(value) == 0 {
		itemValue.Rating = RatingLevel{}
		return nil
	}

	var ratingValue *RatingLevel
	for _, v := range item.Rule.Rating.Levels {
		if v.Code == value {
			ratingValue = v
		}
	}
	if (ratingValue == nil) && len(value) > 0 {
tangxvhui authored
86
		return fmt.Errorf("条目%d:%s-%s评级值异常", item.Id, item.Category, item.Name)
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
	}
	itemValue.Rating = *ratingValue
	return nil
}

// 填写的值是 评分
func (itemValue *SummaryEvaluationValue) valueTypeScore(item *EvaluationItemUsed, value string) error {
	if item.Weight <= 0 {
		return errors.New("评分方式错误")
	}
	value = strings.TrimSpace(value)
	itemValue.Value = value
	//处理空值
	if len(value) == 0 {
		itemValue.Score = "0"
		return nil
	}
tangxvhui authored
104 105 106 107
	valueNumber, err := strconv.ParseFloat(value, 64)
	if err != nil {
		return fmt.Errorf("条目%d:%s-%s评分值异常", item.Id, item.Category, item.Name)
	}
108 109 110 111 112 113 114 115 116 117 118 119
	if item.EvaluatorId < 0 {
		//hrbp 的评分方式
		itemValue.Score = value
		return nil
	} else {
		// 非hrbp的评分方式
		// 分数保留2位小数
		score := valueNumber * item.Weight
		itemValue.Score = fmt.Sprintf("%.2f", score)
	}
	return nil
}
tangxvhui authored
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151

// 360评估,上级评估 ,人资评估  填写评估值的规则
func (itemValue *SummaryEvaluationValue) FillValueV2(item *EvaluationItemUsed, value string) error {
	value = strings.TrimSpace(value)
	itemValue.Value = value
	//处理空值
	if len(value) == 0 {
		itemValue.Score = "0"
		return nil
	}
	valueNumber, err := strconv.ParseFloat(value, 64)
	if err != nil {
		return fmt.Errorf("条目%d:%s-%s评分值异常", item.Id, item.Category, item.Name)
	}
	if item.Weight <= 0 {
		//无权重的情况
		itemValue.Score = value
		return nil
	}
	// 有权重的情况
	if item.EvaluatorId < 0 {
		//hrbp 的评分方式
		itemValue.Score = value
		return nil
	} else {
		// 非hrbp的评分方式 分值=评分*权重
		// 分数保留2位小数
		score := valueNumber * item.Weight
		itemValue.Score = fmt.Sprintf("%.2f", score)
	}
	return nil
}