作者 tangxvhui

修正 评估分数的计算方式

@@ -2,6 +2,7 @@ package domain @@ -2,6 +2,7 @@ package domain
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
  5 + "strconv"
5 "time" 6 "time"
6 ) 7 )
7 8
@@ -74,11 +75,7 @@ func (evaluation *SummaryEvaluation) EvaluationTotalScore(valueList []*SummaryEv @@ -74,11 +75,7 @@ func (evaluation *SummaryEvaluation) EvaluationTotalScore(valueList []*SummaryEv
74 if v.Weight == 0 { 75 if v.Weight == 0 {
75 evaluation.SumRatingCode(v.Rating.Code) 76 evaluation.SumRatingCode(v.Rating.Code)
76 } else { 77 } else {
77 - score, err := v.SumScore()  
78 - if err != nil {  
79 - return err  
80 - }  
81 - 78 + score, _ := strconv.ParseFloat(v.Score, 64)
82 totalScore += score 79 totalScore += score
83 } 80 }
84 } 81 }
@@ -113,10 +110,21 @@ func (evaluation *SummaryEvaluation) ResetTotalRating(param *EvaluationItemUsed) @@ -113,10 +110,21 @@ func (evaluation *SummaryEvaluation) ResetTotalRating(param *EvaluationItemUsed)
113 110
114 // 增加对应评级的数量 111 // 增加对应评级的数量
115 func (evaluation *SummaryEvaluation) SumRatingCode(code string) { 112 func (evaluation *SummaryEvaluation) SumRatingCode(code string) {
  113 + if len(code) == 0 {
  114 + return
  115 + }
  116 + codeNotFound := true
116 for i := range evaluation.TotalRating { 117 for i := range evaluation.TotalRating {
117 if evaluation.TotalRating[i].Code == code { 118 if evaluation.TotalRating[i].Code == code {
118 evaluation.TotalRating[i].Number += 1 119 evaluation.TotalRating[i].Number += 1
  120 + codeNotFound = false
119 break 121 break
120 } 122 }
121 } 123 }
  124 + if codeNotFound {
  125 + evaluation.TotalRating = append(evaluation.TotalRating, RatingCodeNumber{
  126 + Code: code,
  127 + Number: 1,
  128 + })
  129 + }
122 } 130 }
1 package domain 1 package domain
2 2
3 import ( 3 import (
  4 + "errors"
4 "fmt" 5 "fmt"
5 "strconv" 6 "strconv"
  7 + "strings"
6 "time" 8 "time"
7 ) 9 )
8 10
@@ -32,40 +34,40 @@ type SummaryEvaluationValueRepository interface { @@ -32,40 +34,40 @@ type SummaryEvaluationValueRepository interface {
32 // 计算周期评估 34 // 计算周期评估
33 // 当指标项没有权重的时候,还是进行评级操作,不计算分数 35 // 当指标项没有权重的时候,还是进行评级操作,不计算分数
34 // 分数保留2位小数 36 // 分数保留2位小数
35 -func (itemValue *SummaryEvaluationValue) SummaryEvaluationScore() error {  
36 - //计算方式  
37 - score, err := itemValue.SumScore()  
38 - if err != nil {  
39 - return err  
40 - }  
41 - itemValue.Score = fmt.Sprintf("%.2f", score)  
42 - return nil  
43 -} 37 +// func (itemValue *SummaryEvaluationValue) SummaryEvaluationScore() error {
  38 +// //计算方式
  39 +// score, err := itemValue.SumScore()
  40 +// if err != nil {
  41 +// return err
  42 +// }
  43 +// itemValue.Score = fmt.Sprintf("%.2f", score)
  44 +// return nil
  45 +// }
44 46
45 -func (itemValue *SummaryEvaluationValue) SumScore() (float64, error) {  
46 - if len(itemValue.Value) == 0 {  
47 - return 0, nil  
48 - }  
49 - if itemValue.Weight == 0 {  
50 - //使用评级  
51 - return 0, nil  
52 - }  
53 - if itemValue.Types == EvaluationHrbp {  
54 - //hrbp 填写值就是得分  
55 - valueFloat, err := strconv.ParseFloat(itemValue.Value, 64)  
56 - if err != nil {  
57 - return 0, fmt.Errorf("条目%d系数值异常,%s", itemValue.Id, itemValue.Value)  
58 - }  
59 - return valueFloat, nil  
60 - }  
61 - valueFloat, err := strconv.ParseFloat(itemValue.Value, 64)  
62 - if err != nil {  
63 - return 0, fmt.Errorf("条目%d系数值异常,%s", itemValue.Id, itemValue.Value)  
64 - }  
65 - //得分计算方式  
66 - score := itemValue.Weight * valueFloat  
67 - return score, nil  
68 -} 47 +// func (itemValue *SummaryEvaluationValue) SumScore() (float64, error) {
  48 +// if len(itemValue.Value) == 0 {
  49 +// return 0, nil
  50 +// }
  51 +// if itemValue.Weight == 0 {
  52 +// //使用评级
  53 +// return 0, nil
  54 +// }
  55 +// if itemValue.Types == EvaluationHrbp {
  56 +// //hrbp 填写值就是得分
  57 +// valueFloat, err := strconv.ParseFloat(itemValue.Value, 64)
  58 +// if err != nil {
  59 +// return 0, fmt.Errorf("条目%d系数值异常,%s", itemValue.Id, itemValue.Value)
  60 +// }
  61 +// return valueFloat, nil
  62 +// }
  63 +// valueFloat, err := strconv.ParseFloat(itemValue.Value, 64)
  64 +// if err != nil {
  65 +// return 0, fmt.Errorf("条目%d系数值异常,%s", itemValue.Id, itemValue.Value)
  66 +// }
  67 +// //得分计算方式
  68 +// score := itemValue.Weight * valueFloat
  69 +// return score, nil
  70 +// }
69 71
70 // 初始化一个空的value 72 // 初始化一个空的value
71 func (itemValue *SummaryEvaluationValue) SetBlankValue(evaluation *SummaryEvaluation, item *EvaluationItemUsed) { 73 func (itemValue *SummaryEvaluationValue) SetBlankValue(evaluation *SummaryEvaluation, item *EvaluationItemUsed) {
@@ -83,25 +85,69 @@ func (itemValue *SummaryEvaluationValue) SetBlankValue(evaluation *SummaryEvalua @@ -83,25 +85,69 @@ func (itemValue *SummaryEvaluationValue) SetBlankValue(evaluation *SummaryEvalua
83 // 填充评估的内容 85 // 填充评估的内容
84 func (itemValue *SummaryEvaluationValue) FillValue(item *EvaluationItemUsed, value string, remark string) error { 86 func (itemValue *SummaryEvaluationValue) FillValue(item *EvaluationItemUsed, value string, remark string) error {
85 itemValue.Remark = remark 87 itemValue.Remark = remark
86 - itemValue.Value = value  
87 if item.Weight == 0 { 88 if item.Weight == 0 {
88 - //使用评级  
89 - if len(value) == 0 {  
90 - return nil  
91 - }  
92 - var ratingValue *RatingLevel  
93 - for _, v := range item.Rule.Rating.Levels {  
94 - if v.Code == value {  
95 - ratingValue = v  
96 - }  
97 - }  
98 - if (ratingValue == nil) && len(value) > 0 {  
99 - return fmt.Errorf("条目%d系评级值异常", itemValue.EvaluationItemId)  
100 - }  
101 - itemValue.Rating = *ratingValue  
102 - return nil 89 + err := itemValue.valueTypeRating(item, value)
  90 + return err
103 } 91 }
  92 +
  93 + err := itemValue.valueTypeScore(item, value)
104 //使用评分的形式 94 //使用评分的形式
105 - err := itemValue.SummaryEvaluationScore() 95 + // err := itemValue.SummaryEvaluationScore()
106 return err 96 return err
107 } 97 }
  98 +
  99 +// 填写的值是 评级
  100 +func (itemValue *SummaryEvaluationValue) valueTypeRating(item *EvaluationItemUsed, value string) error {
  101 + if item.Weight != 0 {
  102 + return errors.New("评级方式错误")
  103 + }
  104 + itemValue.Value = value
  105 + itemValue.Score = "0"
  106 + // 使用评级
  107 + if len(value) == 0 {
  108 + itemValue.Rating = RatingLevel{}
  109 + return nil
  110 + }
  111 +
  112 + var ratingValue *RatingLevel
  113 + for _, v := range item.Rule.Rating.Levels {
  114 + if v.Code == value {
  115 + ratingValue = v
  116 + }
  117 + }
  118 + if (ratingValue == nil) && len(value) > 0 {
  119 + return fmt.Errorf("条目%d:%s-%s系评级值异常", item.Id, item.Category, item.Name)
  120 + }
  121 + itemValue.Rating = *ratingValue
  122 + return nil
  123 +}
  124 +
  125 +// 填写的值是 评分
  126 +func (itemValue *SummaryEvaluationValue) valueTypeScore(item *EvaluationItemUsed, value string) error {
  127 + if item.Weight <= 0 {
  128 + return errors.New("评分方式错误")
  129 + }
  130 + value = strings.TrimSpace(value)
  131 +
  132 + valueNumber, err := strconv.ParseFloat(value, 64)
  133 + if err != nil {
  134 + return fmt.Errorf("条目%d:%s-%s系评分值异常", item.Id, item.Category, item.Name)
  135 + }
  136 + itemValue.Value = value
  137 + //处理空值
  138 + if len(value) == 0 {
  139 + itemValue.Score = "0"
  140 + return nil
  141 + }
  142 + if item.EvaluatorId < 0 {
  143 + //hrbp 的评分方式
  144 + itemValue.Score = value
  145 + return nil
  146 + } else {
  147 + // 非hrbp的评分方式
  148 + // 分数保留2位小数
  149 + score := valueNumber * item.Weight
  150 + itemValue.Score = fmt.Sprintf("%.2f", score)
  151 + }
  152 + return nil
  153 +}