|
|
package domain
|
|
|
|
|
|
import (
|
|
|
"errors"
|
|
|
"time"
|
|
|
)
|
|
|
|
...
|
...
|
@@ -55,6 +56,48 @@ type EvaluationRule struct { |
|
|
DeletedAt *time.Time `json:"deletedAt" comment:"删除时间"`
|
|
|
}
|
|
|
|
|
|
//根据评估填写的值,得出等级名称,
|
|
|
//如果 评估方式是评分,对评估填写的值 的小数点进行处理
|
|
|
//value 根据评估填写的值
|
|
|
func (rule *EvaluationRule) ScoreOrRating(value *string) (string, error) {
|
|
|
switch rule.Type {
|
|
|
case EvaluationTypeRating:
|
|
|
return rule.RatingValue(value)
|
|
|
case EvaluationTypeScore:
|
|
|
return rule.ScoreValue(value)
|
|
|
}
|
|
|
return "", errors.New("rule.Type 错误")
|
|
|
}
|
|
|
|
|
|
//根据评估填写的值,得出等级名称,
|
|
|
func (rule *EvaluationRule) ScoreValue(value *string) (string, error) {
|
|
|
// valueFloat, err := strconv.ParseFloat(*value, 64)
|
|
|
// if err != nil {
|
|
|
// return "", errors.New("评分填写的值错误")
|
|
|
// }
|
|
|
// if valueFloat < rule.Score.Min || valueFloat > rule.Score.Max {
|
|
|
// return "", errors.New("评分填写的值超出限制")
|
|
|
// }
|
|
|
|
|
|
valueDescrip := ""
|
|
|
// for _, v := range rule.Score.Levels {
|
|
|
// if valueFloat >= v.Start && valueFloat <= v.End {
|
|
|
// valueDescrip = v.Name
|
|
|
// }
|
|
|
// }
|
|
|
return valueDescrip, nil
|
|
|
}
|
|
|
|
|
|
//根据评估填写的值,得出等级名称,
|
|
|
func (rule *EvaluationRule) RatingValue(value *string) (string, error) {
|
|
|
for _, v := range rule.Rating.Levels {
|
|
|
if v.Code == *value {
|
|
|
return v.Name, nil
|
|
|
}
|
|
|
}
|
|
|
return "", errors.New("评估填写的值错误")
|
|
|
}
|
|
|
|
|
|
// GenerateSysRule 当前公司下的生成默认规则
|
|
|
func GenerateSysRule(companyId int64) *EvaluationRule {
|
|
|
levels := make([]*RatingLevel, 0)
|
...
|
...
|
|