evaluation_rule.go
3.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package domain
import (
"time"
)
const (
EvaluationTypeRating int = 0 // 评估方式-评级
EvaluationTypeScore int = 1 // 评估方式-评分
)
const (
EvaluationSysTypeCommon int = 0 // 系统类型-系统添加
EvaluationSysTypeSystem int = 1 // 系统类型-系统预制(不可删除、编辑)
)
type Rating struct {
Levels []*RatingLevel `json:"levels" comment:"配置等级"`
}
type RatingLevel struct {
Code string `json:"code" comment:"等级代号"`
Name string `json:"name" comment:"等级名称"`
Color int `json:"color" comment:"等级颜色"`
QuantizedValue float64 `json:"quantizedValue" comment:"等级量化值"`
}
type Score struct {
Min float64 `json:"min" comment:"评分下限"`
Max float64 `json:"max" comment:"评分上限"`
IntervalState int `json:"intervalState" comment:"按分数子区间匹配等级(0关闭、1开启)"`
DecimalPlaces int `json:"decimalPlaces" comment:"保留小数点(0不保留、1保留一位、以此类推)"`
Levels []*ScoreLevel `json:"levels" comment:"配置等级区间"`
}
type ScoreLevel struct {
Code string `json:"code" comment:"等级代号"`
Name string `json:"name" comment:"等级名称"`
Start float64 `json:"start" comment:"分数区间开始值"`
End float64 `json:"end" comment:"分数区间结束值"`
}
type EvaluationRule struct {
Id int64 `json:"id,string" comment:"ID"`
Name string `json:"name" comment:"名称"`
Remark string `json:"remark" comment:"备注"`
CompanyId int64 `json:"companyId,string" comment:"公司ID"`
CreatorId int64 `json:"creatorId,string" comment:"创建人ID"`
Type int `json:"type" comment:"评估方式(0评级、1评分)"`
SysType int `json:"sysType" comment:"系统类型(0普通、1系统固定)" pg:",use_zero"`
Rating Rating `json:"rating" comment:"评级"`
Score Score `json:"score" comment:"评分"`
CreatedAt time.Time `json:"createdAt" comment:"创建时间"`
UpdatedAt time.Time `json:"updatedAt" comment:"更新时间"`
DeletedAt *time.Time `json:"deletedAt" comment:"删除时间"`
}
// GenerateSysRule 当前公司下的生成默认规则
func GenerateSysRule(companyId int64) *EvaluationRule {
levels := make([]*RatingLevel, 0)
levels = append(levels, &RatingLevel{
Code: "S",
Name: "SS",
Color: 1,
QuantizedValue: 90,
})
levels = append(levels, &RatingLevel{
Code: "A",
Name: "AA",
Color: 2,
QuantizedValue: 80,
})
levels = append(levels, &RatingLevel{
Code: "B",
Name: "BB",
Color: 3,
QuantizedValue: 70,
})
levels = append(levels, &RatingLevel{
Code: "C",
Name: "CC",
Color: 4,
QuantizedValue: 60,
})
levels = append(levels, &RatingLevel{
Code: "D",
Name: "DD",
Color: 5,
QuantizedValue: 50,
})
newRule := &EvaluationRule{
Id: 0,
Name: "评级",
Remark: "",
CompanyId: companyId,
CreatorId: 0,
Type: EvaluationTypeRating,
SysType: EvaluationSysTypeSystem,
Rating: Rating{
Levels: levels,
},
Score: Score{},
}
return newRule
}
type EvaluationRuleRepository interface {
Insert(rule *EvaluationRule) (*EvaluationRule, error)
Remove(rule *EvaluationRule) (*EvaluationRule, error)
FindOne(queryOptions map[string]interface{}) (*EvaluationRule, error)
Find(queryOptions map[string]interface{}) (int64, []*EvaluationRule, error)
Count(queryOptions map[string]interface{}) (int64, error)
}
func (rule *EvaluationRule) GetLevelCodes() []string {
codes := []string{}
if rule.Type == EvaluationTypeRating {
for _, v := range rule.Rating.Levels {
codes = append(codes, v.Code)
}
}
if rule.Type == EvaluationTypeScore {
for _, v := range rule.Score.Levels {
codes = append(codes, v.Code)
}
}
return codes
}