|
@@ -2,6 +2,8 @@ package domain |
|
@@ -2,6 +2,8 @@ package domain |
2
|
|
2
|
|
3
|
import (
|
3
|
import (
|
4
|
"errors"
|
4
|
"errors"
|
|
|
5
|
+ "fmt"
|
|
|
6
|
+ "strconv"
|
5
|
"time"
|
7
|
"time"
|
6
|
)
|
8
|
)
|
7
|
|
9
|
|
|
@@ -56,9 +58,9 @@ type EvaluationRule struct { |
|
@@ -56,9 +58,9 @@ type EvaluationRule struct { |
56
|
DeletedAt *time.Time `json:"deletedAt" comment:"删除时间"`
|
58
|
DeletedAt *time.Time `json:"deletedAt" comment:"删除时间"`
|
57
|
}
|
59
|
}
|
58
|
|
60
|
|
59
|
-//根据评估填写的值,得出等级名称,
|
|
|
60
|
-//如果 评估方式是评分,对评估填写的值 的小数点进行处理
|
|
|
61
|
-//value 根据评估填写的值
|
61
|
+// 根据评估填写的值,得出等级名称
|
|
|
62
|
+// 如果 评估方式是评分,对评估填写的值的小数点后的位数进行处理,
|
|
|
63
|
+// value 根据评估填写的值
|
62
|
func (rule *EvaluationRule) ScoreOrRating(value *string) (string, error) {
|
64
|
func (rule *EvaluationRule) ScoreOrRating(value *string) (string, error) {
|
63
|
switch rule.Type {
|
65
|
switch rule.Type {
|
64
|
case EvaluationTypeRating:
|
66
|
case EvaluationTypeRating:
|
|
@@ -71,20 +73,27 @@ func (rule *EvaluationRule) ScoreOrRating(value *string) (string, error) { |
|
@@ -71,20 +73,27 @@ func (rule *EvaluationRule) ScoreOrRating(value *string) (string, error) { |
71
|
|
73
|
|
72
|
//根据评估填写的值,得出等级名称,
|
74
|
//根据评估填写的值,得出等级名称,
|
73
|
func (rule *EvaluationRule) ScoreValue(value *string) (string, error) {
|
75
|
func (rule *EvaluationRule) ScoreValue(value *string) (string, error) {
|
74
|
- // valueFloat, err := strconv.ParseFloat(*value, 64)
|
|
|
75
|
- // if err != nil {
|
|
|
76
|
- // return "", errors.New("评分填写的值错误")
|
|
|
77
|
- // }
|
|
|
78
|
- // if valueFloat < rule.Score.Min || valueFloat > rule.Score.Max {
|
|
|
79
|
- // return "", errors.New("评分填写的值超出限制")
|
|
|
80
|
- // }
|
|
|
81
|
-
|
76
|
+ valueFloat, err := strconv.ParseFloat(*value, 64)
|
|
|
77
|
+ if err != nil {
|
|
|
78
|
+ return "", errors.New("评分填写的值错误")
|
|
|
79
|
+ }
|
|
|
80
|
+ if valueFloat < rule.Score.Min || valueFloat > rule.Score.Max {
|
|
|
81
|
+ return "", fmt.Errorf("评分填写的值超出限制,>=%f且<=%f", rule.Score.Min, rule.Score.Max)
|
|
|
82
|
+ }
|
|
|
83
|
+ //保留小数处理
|
|
|
84
|
+ fStr := fmt.Sprintf("%%.%df", rule.Score.DecimalPlaces)
|
|
|
85
|
+ valueStr := fmt.Sprintf(fStr, valueFloat)
|
|
|
86
|
+ *value = valueStr
|
|
|
87
|
+ if rule.Score.IntervalState == 0 {
|
|
|
88
|
+ // 未开启按分数子区间匹配等级
|
|
|
89
|
+ return "", nil
|
|
|
90
|
+ }
|
82
|
valueDescrip := ""
|
91
|
valueDescrip := ""
|
83
|
- // for _, v := range rule.Score.Levels {
|
|
|
84
|
- // if valueFloat >= v.Start && valueFloat <= v.End {
|
|
|
85
|
- // valueDescrip = v.Name
|
|
|
86
|
- // }
|
|
|
87
|
- // }
|
92
|
+ for _, v := range rule.Score.Levels {
|
|
|
93
|
+ if valueFloat >= v.Start && valueFloat <= v.End {
|
|
|
94
|
+ valueDescrip = v.Name
|
|
|
95
|
+ }
|
|
|
96
|
+ }
|
88
|
return valueDescrip, nil
|
97
|
return valueDescrip, nil
|
89
|
}
|
98
|
}
|
90
|
|
99
|
|