1
|
-package domain
|
|
|
2
|
-
|
|
|
3
|
-import (
|
|
|
4
|
- "errors"
|
|
|
5
|
- "fmt"
|
|
|
6
|
- "strconv"
|
|
|
7
|
- "time"
|
|
|
8
|
-)
|
|
|
9
|
-
|
|
|
10
|
-//填写的评估内容
|
|
|
11
|
-type StaffAssessContent struct {
|
|
|
12
|
- Id int `json:"id"` //id
|
|
|
13
|
- StaffAssessId int `json:"staffAssessId"` //用户需要的评估项id
|
|
|
14
|
- SortBy int `json:"sortBy"` //排序
|
|
|
15
|
- Category string `json:"category"` //类别
|
|
|
16
|
- Name string `json:"name"` //名称
|
|
|
17
|
- PromptTitle string `json:"promptTitle"` //提示项标题
|
|
|
18
|
- PromptText string `json:"promptText"` //提示项正文
|
|
|
19
|
- Remark []AssessContemtRemark `json:"remark"` //填写的反馈
|
|
|
20
|
- Value string `json:"value"` //评估填写的值
|
|
|
21
|
- ScoreValue float64 `json:"scoreValue"` // 填写值按规则Rule转换为相应的量化值
|
|
|
22
|
- LevelValue string `json:"levelValue"` // 填写值按规则Rule转换为相应的等级值
|
|
|
23
|
- ReteResult string `json:"reteResult"` //评估的结果
|
|
|
24
|
- Rule EvaluationRule `json:"rule"` //评估的选项规则
|
|
|
25
|
- Weight float64 `json:"weight" ` //"权重"
|
|
|
26
|
- CreatedAt time.Time `json:"createdAt"` //数据创建时间
|
|
|
27
|
- UpdatedAt time.Time `json:"updatedAt"` //数据更新时间
|
|
|
28
|
- DeletedAt *time.Time `json:"deletedAt"`
|
|
|
29
|
-}
|
|
|
30
|
-
|
|
|
31
|
-type AssessContemtRemark struct {
|
|
|
32
|
- Title string `json:"title"` //comment:"填写标题"
|
|
|
33
|
- HintText string `json:"hintText"` // comment:"文本内容提示"
|
|
|
34
|
- Definition string `json:"definition"` //comment:"定义"
|
|
|
35
|
- RemarkText string `json:"remarkText"` // comment:"填写文本内容"
|
|
|
36
|
-}
|
|
|
37
|
-
|
|
|
38
|
-//TransformValue
|
|
|
39
|
-//根据规则 rule 转换评填写的值
|
|
|
40
|
-func (content *StaffAssessContent) TransformValue() error {
|
|
|
41
|
- switch content.Rule.Type {
|
|
|
42
|
- case EvaluationTypeRating:
|
|
|
43
|
- return content.ratingValue()
|
|
|
44
|
- case EvaluationTypeScore:
|
|
|
45
|
- return content.scoreValue()
|
|
|
46
|
- }
|
|
|
47
|
- return nil
|
|
|
48
|
-}
|
|
|
49
|
-
|
|
|
50
|
-// 规则是评级方式
|
|
|
51
|
-func (content *StaffAssessContent) ratingValue() error {
|
|
|
52
|
- levels := content.Rule.Rating.Levels
|
|
|
53
|
- for _, v := range levels {
|
|
|
54
|
- if v.Code != content.Value {
|
|
|
55
|
- continue
|
|
|
56
|
- }
|
|
|
57
|
- content.LevelValue = v.Code
|
|
|
58
|
- content.ScoreValue = v.QuantizedValue
|
|
|
59
|
- content.ReteResult = v.Name
|
|
|
60
|
- return nil
|
|
|
61
|
- }
|
|
|
62
|
- return errors.New("评级填写的值错误")
|
|
|
63
|
-}
|
|
|
64
|
-
|
|
|
65
|
-// 规则是评分方式
|
|
|
66
|
-func (content *StaffAssessContent) scoreValue() error {
|
|
|
67
|
- valueFloat, err := strconv.ParseFloat(content.Value, 64)
|
|
|
68
|
- if err != nil {
|
|
|
69
|
- return errors.New("评分填写的值错误")
|
|
|
70
|
- }
|
|
|
71
|
- rule := &content.Rule
|
|
|
72
|
- if valueFloat < rule.Score.Min || valueFloat > rule.Score.Max {
|
|
|
73
|
- return fmt.Errorf("评分填写的值超出限制,>=%f且<=%f", rule.Score.Min, rule.Score.Max)
|
|
|
74
|
- }
|
|
|
75
|
- //保留小数处理
|
|
|
76
|
- fStr := fmt.Sprintf("%%.%df", rule.Score.DecimalPlaces)
|
|
|
77
|
- valueStr := fmt.Sprintf(fStr, valueFloat)
|
|
|
78
|
- content.Value = valueStr
|
|
|
79
|
- if rule.Score.IntervalState == 0 {
|
|
|
80
|
- // 未开启按分数子区间匹配等级
|
|
|
81
|
- return nil
|
|
|
82
|
- }
|
|
|
83
|
- for _, v := range rule.Score.Levels {
|
|
|
84
|
- if valueFloat < v.Start || valueFloat > v.End {
|
|
|
85
|
- continue
|
|
|
86
|
- }
|
|
|
87
|
- content.LevelValue = v.Code
|
|
|
88
|
- content.ScoreValue = valueFloat
|
|
|
89
|
- content.ReteResult = v.Name
|
|
|
90
|
- return nil
|
|
|
91
|
- }
|
|
|
92
|
- return errors.New("评分填写的值错误")
|
|
|
93
|
-}
|
|
|
94
|
-
|
|
|
95
|
-type StaffAssessContentRepository interface {
|
|
|
96
|
- Save(param *StaffAssessContent) (*StaffAssessContent, error)
|
|
|
97
|
- Remove(id int) error
|
|
|
98
|
- FindOne(queryOptions map[string]interface{}) (*StaffAssessContent, error)
|
|
|
99
|
- Find(queryOptions map[string]interface{}) (int, []*StaffAssessContent, error)
|
|
|
100
|
-} |
1
|
+package domain
|
|
|
2
|
+
|
|
|
3
|
+import (
|
|
|
4
|
+ "errors"
|
|
|
5
|
+ "fmt"
|
|
|
6
|
+ "strconv"
|
|
|
7
|
+ "time"
|
|
|
8
|
+)
|
|
|
9
|
+
|
|
|
10
|
+//填写的评估内容
|
|
|
11
|
+type StaffAssessContent struct {
|
|
|
12
|
+ Id int `json:"id"` //id
|
|
|
13
|
+ StaffAssessId int `json:"staffAssessId"` //用户需要的评估项id
|
|
|
14
|
+ SortBy int `json:"sortBy"` //排序
|
|
|
15
|
+ Category string `json:"category"` //类别
|
|
|
16
|
+ Name string `json:"name"` //名称
|
|
|
17
|
+ PromptTitle string `json:"promptTitle"` //提示项标题
|
|
|
18
|
+ PromptText string `json:"promptText"` //提示项正文
|
|
|
19
|
+ Remark []AssessContemtRemark `json:"remark"` //填写的反馈
|
|
|
20
|
+ Value string `json:"value"` //评估填写的值
|
|
|
21
|
+ ScoreValue float64 `json:"scoreValue"` // 填写值按规则Rule转换为相应的量化值
|
|
|
22
|
+ LevelValue string `json:"levelValue"` // 填写值按规则Rule转换为相应的等级值
|
|
|
23
|
+ ReteResult string `json:"reteResult"` //评估的结果
|
|
|
24
|
+ Rule EvaluationRule `json:"rule"` //评估的选项规则
|
|
|
25
|
+ Weight float64 `json:"weight" ` //"权重"
|
|
|
26
|
+ Required int `json:"required"` // 必填项
|
|
|
27
|
+ CreatedAt time.Time `json:"createdAt"` //数据创建时间
|
|
|
28
|
+ UpdatedAt time.Time `json:"updatedAt"` //数据更新时间
|
|
|
29
|
+ DeletedAt *time.Time `json:"deletedAt"`
|
|
|
30
|
+}
|
|
|
31
|
+
|
|
|
32
|
+type AssessContemtRemark struct {
|
|
|
33
|
+ Title string `json:"title"` //comment:"填写标题"
|
|
|
34
|
+ HintText string `json:"hintText"` // comment:"文本内容提示"
|
|
|
35
|
+ Definition string `json:"definition"` //comment:"定义"
|
|
|
36
|
+ RemarkText string `json:"remarkText"` // comment:"填写文本内容"
|
|
|
37
|
+}
|
|
|
38
|
+
|
|
|
39
|
+//TransformValue
|
|
|
40
|
+//根据规则 rule 转换评填写的值
|
|
|
41
|
+func (content *StaffAssessContent) TransformValue() error {
|
|
|
42
|
+ switch content.Rule.Type {
|
|
|
43
|
+ case EvaluationTypeRating:
|
|
|
44
|
+ return content.ratingValue()
|
|
|
45
|
+ case EvaluationTypeScore:
|
|
|
46
|
+ return content.scoreValue()
|
|
|
47
|
+ }
|
|
|
48
|
+ return nil
|
|
|
49
|
+}
|
|
|
50
|
+
|
|
|
51
|
+// 规则是评级方式
|
|
|
52
|
+func (content *StaffAssessContent) ratingValue() error {
|
|
|
53
|
+ levels := content.Rule.Rating.Levels
|
|
|
54
|
+ for _, v := range levels {
|
|
|
55
|
+ if v.Code != content.Value {
|
|
|
56
|
+ continue
|
|
|
57
|
+ }
|
|
|
58
|
+ content.LevelValue = v.Code
|
|
|
59
|
+ content.ScoreValue = v.QuantizedValue
|
|
|
60
|
+ content.ReteResult = v.Name
|
|
|
61
|
+ return nil
|
|
|
62
|
+ }
|
|
|
63
|
+ return errors.New("评级填写的值错误")
|
|
|
64
|
+}
|
|
|
65
|
+
|
|
|
66
|
+// 规则是评分方式
|
|
|
67
|
+func (content *StaffAssessContent) scoreValue() error {
|
|
|
68
|
+ valueFloat, err := strconv.ParseFloat(content.Value, 64)
|
|
|
69
|
+ if err != nil {
|
|
|
70
|
+ return errors.New("评分填写的值错误")
|
|
|
71
|
+ }
|
|
|
72
|
+ rule := &content.Rule
|
|
|
73
|
+ if valueFloat < rule.Score.Min || valueFloat > rule.Score.Max {
|
|
|
74
|
+ return fmt.Errorf("评分填写的值超出限制,>=%f且<=%f", rule.Score.Min, rule.Score.Max)
|
|
|
75
|
+ }
|
|
|
76
|
+ //保留小数处理
|
|
|
77
|
+ fStr := fmt.Sprintf("%%.%df", rule.Score.DecimalPlaces)
|
|
|
78
|
+ valueStr := fmt.Sprintf(fStr, valueFloat)
|
|
|
79
|
+ content.Value = valueStr
|
|
|
80
|
+ if rule.Score.IntervalState == 0 {
|
|
|
81
|
+ // 未开启按分数子区间匹配等级
|
|
|
82
|
+ return nil
|
|
|
83
|
+ }
|
|
|
84
|
+ for _, v := range rule.Score.Levels {
|
|
|
85
|
+ if valueFloat < v.Start || valueFloat > v.End {
|
|
|
86
|
+ continue
|
|
|
87
|
+ }
|
|
|
88
|
+ content.LevelValue = v.Code
|
|
|
89
|
+ content.ScoreValue = valueFloat
|
|
|
90
|
+ content.ReteResult = v.Name
|
|
|
91
|
+ return nil
|
|
|
92
|
+ }
|
|
|
93
|
+ return errors.New("评分填写的值错误")
|
|
|
94
|
+}
|
|
|
95
|
+
|
|
|
96
|
+type StaffAssessContentRepository interface {
|
|
|
97
|
+ Save(param *StaffAssessContent) (*StaffAssessContent, error)
|
|
|
98
|
+ Remove(id int) error
|
|
|
99
|
+ FindOne(queryOptions map[string]interface{}) (*StaffAssessContent, error)
|
|
|
100
|
+ Find(queryOptions map[string]interface{}) (int, []*StaffAssessContent, error)
|
|
|
101
|
+} |