summary_evaluation.go
4.7 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
132
133
134
135
package domain
import (
"fmt"
"strconv"
"time"
)
// 周综合评估
type SummaryEvaluation struct {
Id int `json:"id"`
CompanyId int `json:"companyId"` //公司id
EvaluationProjectId int `json:"evaluationProjectId"` //对应的项目id
EvaluationProjectName string `json:"evaluationProjectName"` //对应的项目名称
CycleId int64 `json:"cycleId"` //对应的周期id
CycleName string `json:"cycleName"` //对应的周期名称
NodeId int `json:"nodeId"` //对应的节点id
TargetUser StaffDesc `json:"targetUser"` //被评估的目标用户,被执行的
TargetDepartment []StaffDepartment `json:"targetDepartment"` //被评估的目标用户所在的部门
Executor StaffDesc `json:"executor"` //填写评估的用户,执行人
Types EvaluationType `json:"types"` //评估类型
Status EvaluationStatus `json:"status"` //评估的填写状态
CheckResult EvaluationCheckResult `json:"checkResult"` //被执行的人确认评估结果
BeginTime time.Time `json:"beginTime"` //开始时间
EndTime time.Time `json:"endTime"` //截止时间
TotalScore string `json:"totalScore"` //最终上级评估得分.
TotalRating []RatingCodeNumber `json:"totalRating"` //汇总各个评级的数量
CreatedAt time.Time `json:"createdAt"` //数据创建时间
UpdatedAt time.Time `json:"updatedAt"` //数据更新时间
DeletedAt *time.Time `json:"deletedAt"` //数据删除时间
}
// 各个评级的数量
type RatingCodeNumber struct {
Code string `json:"code"`
Number int `json:"number"`
}
type EvaluationType int //综合评估类型
const (
EvaluationSelf EvaluationType = 1 //自评
Evaluation360 EvaluationType = 2 //360评估
EvaluationSuper EvaluationType = 3 //上级评估
EvaluationHrbp EvaluationType = 4 //人资评估
EvaluationFinish EvaluationType = 5 //考核结果
)
// 评估的填写状态
type EvaluationStatus string
const (
EvaluationUncompleted EvaluationStatus = "uncompleted" //未提交填写的内容
EvaluationCompleted EvaluationStatus = "completed" //已提交填写的内容
)
// 被执行的人确认评估结果
type EvaluationCheckResult string
const (
EvaluationCheckUncompleted EvaluationCheckResult = "uncompleted" //未确认结果
EvaluationCheckCompleted EvaluationCheckResult = "completed" //已确认结果
)
type SummaryEvaluationRepository interface {
Save(param *SummaryEvaluation) error
Remove(id int) error
FindOne(queryOptions map[string]interface{}) (*SummaryEvaluation, error)
Find(queryOptions map[string]interface{}) (int, []*SummaryEvaluation, error)
RemoveByProjectId(id int) error
}
// 计算总分。TotalScore 保留1位小数
func (evaluation *SummaryEvaluation) EvaluationTotalScore(valueList []*SummaryEvaluationValue) error {
//重置计数
evaluation.TotalScore = "0"
//汇总评估填写值
var totalScore float64
for _, v := range valueList {
if v.Weight == 0 {
evaluation.SumRatingCode(v.Rating.Code)
} else {
score, _ := strconv.ParseFloat(v.Score, 64)
totalScore += score
}
}
evaluation.TotalScore = fmt.Sprintf("%.1f", totalScore)
return nil
}
// 重置评级统计数量
func (evaluation *SummaryEvaluation) ResetTotalRating(param *EvaluationItemUsed) {
if param.Weight > 0 {
return
}
if len(evaluation.TotalRating) == 0 {
evaluation.TotalRating = make([]RatingCodeNumber, 0)
}
for _, v := range param.Rule.Rating.Levels {
isExist := false
for i2, v2 := range evaluation.TotalRating {
if v.Code == v2.Code {
isExist = true
evaluation.TotalRating[i2].Number = 0
}
}
if !isExist {
evaluation.TotalRating = append(evaluation.TotalRating, RatingCodeNumber{
Code: v.Code,
Number: 0,
})
}
}
}
// 增加对应评级的数量
func (evaluation *SummaryEvaluation) SumRatingCode(code string) {
if len(code) == 0 {
return
}
codeNotFound := true
for i := range evaluation.TotalRating {
if evaluation.TotalRating[i].Code == code {
evaluation.TotalRating[i].Number += 1
codeNotFound = false
break
}
}
if codeNotFound {
evaluation.TotalRating = append(evaluation.TotalRating, RatingCodeNumber{
Code: code,
Number: 1,
})
}
}