作者 tangxvhui

处理绩效评估的填写值

@@ -1694,6 +1694,12 @@ func (srv StaffAssessServeice) SaveAssessInfo(param *command.SaveAssessInfoComma @@ -1694,6 +1694,12 @@ func (srv StaffAssessServeice) SaveAssessInfo(param *command.SaveAssessInfoComma
1694 continue 1694 continue
1695 } 1695 }
1696 v.Value = item.Value 1696 v.Value = item.Value
  1697 + //填入评估值描述
  1698 + reteResult, err := v.Rule.ScoreOrRating(&v.Value)
  1699 + if err != nil {
  1700 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  1701 + }
  1702 + v.ReteResult = reteResult
1697 for ii := range v.Remark { 1703 for ii := range v.Remark {
1698 for _, vvv := range item.Remark { 1704 for _, vvv := range item.Remark {
1699 if v.Remark[ii].Title == vvv.Title { 1705 if v.Remark[ii].Title == vvv.Title {
@@ -1702,6 +1708,7 @@ func (srv StaffAssessServeice) SaveAssessInfo(param *command.SaveAssessInfoComma @@ -1702,6 +1708,7 @@ func (srv StaffAssessServeice) SaveAssessInfo(param *command.SaveAssessInfoComma
1702 } 1708 }
1703 } 1709 }
1704 } 1710 }
  1711 +
1705 } 1712 }
1706 1713
1707 //保存信息 1714 //保存信息
@@ -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