1
|
package service
|
1
|
package service
|
2
|
|
2
|
|
3
|
-import (
|
|
|
4
|
- "fmt"
|
|
|
5
|
- "strconv"
|
|
|
6
|
- "time"
|
|
|
7
|
-
|
|
|
8
|
- "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
|
|
|
9
|
- "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/notify"
|
|
|
10
|
- "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
|
|
|
11
|
- "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/dao"
|
|
|
12
|
- "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/log"
|
|
|
13
|
-)
|
|
|
14
|
-
|
|
|
15
|
// sendSummaryEvaluafionTask 根据评估项目设置,确认是否下发评估任务
|
3
|
// sendSummaryEvaluafionTask 根据评估项目设置,确认是否下发评估任务
|
16
|
// project 需要处理的项目
|
4
|
// project 需要处理的项目
|
17
|
// userList 全体的员工数据 map[id]=>domain.User
|
5
|
// userList 全体的员工数据 map[id]=>domain.User
|
18
|
// departmetList 全部的部门数据 map[id]=>domain.Department
|
6
|
// departmetList 全部的部门数据 map[id]=>domain.Department
|
19
|
-func sendSummaryEvaluation(project *domain.EvaluationProject,
|
|
|
20
|
- userMap map[int64]*domain.User, departmentMap map[int64]*domain.Department) ([]domain.SummaryEvaluation, error) {
|
|
|
21
|
- //自评的时间范围
|
|
|
22
|
- beginTimeSelf := project.EndTime
|
|
|
23
|
- endTimeSelf := dayZeroTime(project.EndTime).Add(4*24*time.Hour - time.Second)
|
|
|
24
|
- //人资、360评估的时间范围
|
|
|
25
|
- beginTime360 := endTimeSelf
|
|
|
26
|
- endTime360 := endTimeSelf.Add(2 * 24 * time.Hour)
|
|
|
27
|
- //上级评估的是时间范围
|
|
|
28
|
- beginTimeSuper := endTime360
|
|
|
29
|
- endTimeSuper := endTime360.Add(2 * 24 * time.Hour)
|
|
|
30
|
- //
|
|
|
31
|
- transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
32
|
- if err != nil {
|
|
|
33
|
- return nil, err
|
|
|
34
|
- }
|
|
|
35
|
- if err := transactionContext.StartTransaction(); err != nil {
|
|
|
36
|
- return nil, err
|
|
|
37
|
- }
|
|
|
38
|
- defer func() {
|
|
|
39
|
- _ = transactionContext.RollbackTransaction()
|
|
|
40
|
- }()
|
|
|
41
|
- cycleRepo := factory.CreateEvaluationCycleRepository(map[string]interface{}{"transactionContext": transactionContext})
|
|
|
42
|
-
|
|
|
43
|
- evaluationItemRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{"transactionContext": transactionContext})
|
7
|
+// func sendSummaryEvaluation(project *domain.EvaluationProject,
|
|
|
8
|
+// userMap map[int64]*domain.User, departmentMap map[int64]*domain.Department) ([]domain.SummaryEvaluation, error) {
|
|
|
9
|
+// //自评的时间范围
|
|
|
10
|
+// beginTimeSelf := project.EndTime
|
|
|
11
|
+// endTimeSelf := dayZeroTime(project.EndTime).Add(4*24*time.Hour - time.Second)
|
|
|
12
|
+// //人资、360评估的时间范围
|
|
|
13
|
+// beginTime360 := endTimeSelf
|
|
|
14
|
+// endTime360 := endTimeSelf.Add(2 * 24 * time.Hour)
|
|
|
15
|
+// //上级评估的是时间范围
|
|
|
16
|
+// beginTimeSuper := endTime360
|
|
|
17
|
+// endTimeSuper := endTime360.Add(2 * 24 * time.Hour)
|
|
|
18
|
+// //
|
|
|
19
|
+// transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
20
|
+// if err != nil {
|
|
|
21
|
+// return nil, err
|
|
|
22
|
+// }
|
|
|
23
|
+// if err := transactionContext.StartTransaction(); err != nil {
|
|
|
24
|
+// return nil, err
|
|
|
25
|
+// }
|
|
|
26
|
+// defer func() {
|
|
|
27
|
+// _ = transactionContext.RollbackTransaction()
|
|
|
28
|
+// }()
|
|
|
29
|
+// cycleRepo := factory.CreateEvaluationCycleRepository(map[string]interface{}{"transactionContext": transactionContext})
|
44
|
|
30
|
|
45
|
- cycleData, err := cycleRepo.FindOne(map[string]interface{}{"id": project.CycleId})
|
|
|
46
|
- if err != nil {
|
|
|
47
|
- return nil, err
|
|
|
48
|
- }
|
|
|
49
|
- //确定 被评估的人
|
|
|
50
|
- targetUserId := []int64{}
|
|
|
51
|
- for _, v := range project.Recipients {
|
|
|
52
|
- id, err := strconv.ParseInt(v, 10, 64)
|
|
|
53
|
- if err == nil {
|
|
|
54
|
- targetUserId = append(targetUserId, id)
|
|
|
55
|
- }
|
|
|
56
|
- }
|
|
|
57
|
- if len(targetUserId) == 0 {
|
|
|
58
|
- return nil, nil
|
|
|
59
|
- }
|
|
|
60
|
- //被评估的员工
|
|
|
61
|
- targetUserMap := map[int64]*domain.User{}
|
31
|
+// evaluationItemRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{"transactionContext": transactionContext})
|
62
|
|
32
|
|
63
|
- for _, v := range targetUserId {
|
|
|
64
|
- u, ok := userMap[v]
|
|
|
65
|
- if ok {
|
|
|
66
|
- targetUserMap[v] = u
|
|
|
67
|
- }
|
|
|
68
|
- }
|
|
|
69
|
- //确定360评估的执行人
|
|
|
70
|
- _, itemList, err := evaluationItemRepo.Find(map[string]interface{}{"evaluationProjectId": project.Id, "nodeType": int(domain.LinkNodeSelfAssessment)})
|
|
|
71
|
- if err != nil {
|
|
|
72
|
- return nil, err
|
|
|
73
|
- }
|
|
|
74
|
- nodeId := 0
|
|
|
75
|
- executor360Map := map[int64]*domain.User{}
|
|
|
76
|
- hrbpExist := false
|
|
|
77
|
- for _, v := range itemList {
|
|
|
78
|
- nodeId = v.NodeId
|
|
|
79
|
- if v.EvaluatorId < 0 {
|
|
|
80
|
- hrbpExist = true
|
|
|
81
|
- }
|
|
|
82
|
- if v.EvaluatorId <= 0 {
|
|
|
83
|
- continue
|
|
|
84
|
- }
|
|
|
85
|
- if u, ok := userMap[int64(v.EvaluatorId)]; ok {
|
|
|
86
|
- executor360Map[u.Id] = u
|
|
|
87
|
- }
|
|
|
88
|
- }
|
|
|
89
|
- //创建周期评估任务
|
|
|
90
|
- var newEvaluationList []domain.SummaryEvaluation
|
|
|
91
|
- evaluationTemp := domain.SummaryEvaluation{
|
|
|
92
|
- Id: 0,
|
|
|
93
|
- CompanyId: int(project.CompanyId),
|
|
|
94
|
- EvaluationProjectId: int(project.Id),
|
|
|
95
|
- EvaluationProjectName: project.Name,
|
|
|
96
|
- CycleId: cycleData.Id,
|
|
|
97
|
- CycleName: cycleData.Name,
|
|
|
98
|
- NodeId: nodeId,
|
|
|
99
|
- TargetUser: domain.StaffDesc{},
|
|
|
100
|
- TargetDepartment: []domain.StaffDepartment{},
|
|
|
101
|
- Executor: domain.StaffDesc{},
|
|
|
102
|
- Types: 0,
|
|
|
103
|
- Status: domain.EvaluationUncompleted,
|
|
|
104
|
- CheckResult: domain.EvaluationCheckUncompleted,
|
|
|
105
|
- BeginTime: time.Time{},
|
|
|
106
|
- EndTime: time.Time{},
|
|
|
107
|
- TotalScore: "",
|
|
|
108
|
- CreatedAt: time.Now(),
|
|
|
109
|
- UpdatedAt: time.Now(),
|
|
|
110
|
- DeletedAt: nil,
|
|
|
111
|
- }
|
33
|
+// cycleData, err := cycleRepo.FindOne(map[string]interface{}{"id": project.CycleId})
|
|
|
34
|
+// if err != nil {
|
|
|
35
|
+// return nil, err
|
|
|
36
|
+// }
|
|
|
37
|
+// //确定 被评估的人
|
|
|
38
|
+// targetUserId := []int64{}
|
|
|
39
|
+// for _, v := range project.Recipients {
|
|
|
40
|
+// id, err := strconv.ParseInt(v, 10, 64)
|
|
|
41
|
+// if err == nil {
|
|
|
42
|
+// targetUserId = append(targetUserId, id)
|
|
|
43
|
+// }
|
|
|
44
|
+// }
|
|
|
45
|
+// if len(targetUserId) == 0 {
|
|
|
46
|
+// return nil, nil
|
|
|
47
|
+// }
|
|
|
48
|
+// //被评估的员工
|
|
|
49
|
+// targetUserMap := map[int64]*domain.User{}
|
112
|
|
50
|
|
113
|
- //确定周期评估
|
51
|
+// for _, v := range targetUserId {
|
|
|
52
|
+// u, ok := userMap[v]
|
|
|
53
|
+// if ok {
|
|
|
54
|
+// targetUserMap[v] = u
|
|
|
55
|
+// }
|
|
|
56
|
+// }
|
|
|
57
|
+// //确定360评估的执行人
|
|
|
58
|
+// _, itemList, err := evaluationItemRepo.Find(map[string]interface{}{"evaluationProjectId": project.Id, "nodeType": int(domain.LinkNodeSelfAssessment)})
|
|
|
59
|
+// if err != nil {
|
|
|
60
|
+// return nil, err
|
|
|
61
|
+// }
|
|
|
62
|
+// nodeId := 0
|
|
|
63
|
+// executor360Map := map[int64]*domain.User{}
|
|
|
64
|
+// hrbpExist := false
|
|
|
65
|
+// for _, v := range itemList {
|
|
|
66
|
+// nodeId = v.NodeId
|
|
|
67
|
+// if v.EvaluatorId < 0 {
|
|
|
68
|
+// hrbpExist = true
|
|
|
69
|
+// }
|
|
|
70
|
+// if v.EvaluatorId <= 0 {
|
|
|
71
|
+// continue
|
|
|
72
|
+// }
|
|
|
73
|
+// if u, ok := userMap[int64(v.EvaluatorId)]; ok {
|
|
|
74
|
+// executor360Map[u.Id] = u
|
|
|
75
|
+// }
|
|
|
76
|
+// }
|
|
|
77
|
+// //创建周期评估任务
|
|
|
78
|
+// var newEvaluationList []domain.SummaryEvaluation
|
|
|
79
|
+// evaluationTemp := domain.SummaryEvaluation{
|
|
|
80
|
+// Id: 0,
|
|
|
81
|
+// CompanyId: int(project.CompanyId),
|
|
|
82
|
+// EvaluationProjectId: int(project.Id),
|
|
|
83
|
+// EvaluationProjectName: project.Name,
|
|
|
84
|
+// CycleId: cycleData.Id,
|
|
|
85
|
+// CycleName: cycleData.Name,
|
|
|
86
|
+// NodeId: nodeId,
|
|
|
87
|
+// TargetUser: domain.StaffDesc{},
|
|
|
88
|
+// TargetDepartment: []domain.StaffDepartment{},
|
|
|
89
|
+// Executor: domain.StaffDesc{},
|
|
|
90
|
+// Types: 0,
|
|
|
91
|
+// Status: domain.EvaluationUncompleted,
|
|
|
92
|
+// CheckResult: domain.EvaluationCheckUncompleted,
|
|
|
93
|
+// BeginTime: time.Time{},
|
|
|
94
|
+// EndTime: time.Time{},
|
|
|
95
|
+// TotalScore: "",
|
|
|
96
|
+// CreatedAt: time.Now(),
|
|
|
97
|
+// UpdatedAt: time.Now(),
|
|
|
98
|
+// DeletedAt: nil,
|
|
|
99
|
+// }
|
114
|
|
100
|
|
115
|
- for _, v := range targetUserMap {
|
|
|
116
|
- //处理自评
|
|
|
117
|
- evaluationTemp.TargetUser = domain.StaffDesc{
|
|
|
118
|
- UserId: int(v.Id),
|
|
|
119
|
- Account: v.Account,
|
|
|
120
|
- UserName: v.Name,
|
|
|
121
|
- }
|
|
|
122
|
- evaluationTemp.Executor = domain.StaffDesc{
|
|
|
123
|
- UserId: int(v.Id),
|
|
|
124
|
- Account: v.Account,
|
|
|
125
|
- UserName: v.Name,
|
|
|
126
|
- }
|
|
|
127
|
- evaluationTemp.BeginTime = beginTimeSelf
|
|
|
128
|
- evaluationTemp.EndTime = endTimeSelf
|
|
|
129
|
- evaluationTemp.TargetDepartment = []domain.StaffDepartment{}
|
|
|
130
|
- evaluationTemp.Types = domain.EvaluationSelf
|
|
|
131
|
- for _, departId := range v.DepartmentId {
|
|
|
132
|
- depart, ok := departmentMap[int64(departId)]
|
|
|
133
|
- if !ok {
|
|
|
134
|
- continue
|
|
|
135
|
- }
|
|
|
136
|
- evaluationTemp.TargetDepartment = append(evaluationTemp.TargetDepartment, domain.StaffDepartment{
|
|
|
137
|
- DepartmentId: int(depart.Id),
|
|
|
138
|
- DepartmentName: depart.Name,
|
|
|
139
|
- })
|
|
|
140
|
- }
|
|
|
141
|
- newEvaluationList = append(newEvaluationList, evaluationTemp)
|
|
|
142
|
- if hrbpExist {
|
|
|
143
|
- //处理人资评估
|
|
|
144
|
- evaluationTemp.BeginTime = beginTime360
|
|
|
145
|
- evaluationTemp.EndTime = endTime360
|
|
|
146
|
- evaluationTemp.Executor = domain.StaffDesc{}
|
|
|
147
|
- evaluationTemp.Types = domain.EvaluationHrbp
|
|
|
148
|
- newEvaluationList = append(newEvaluationList, evaluationTemp)
|
|
|
149
|
- }
|
|
|
150
|
- //处理360 评估
|
|
|
151
|
- for _, v2 := range executor360Map {
|
|
|
152
|
- evaluationTemp.BeginTime = beginTime360
|
|
|
153
|
- evaluationTemp.EndTime = endTime360
|
|
|
154
|
- evaluationTemp.Executor = domain.StaffDesc{
|
|
|
155
|
- UserId: int(v2.Id),
|
|
|
156
|
- Account: v2.Account,
|
|
|
157
|
- UserName: v2.Name,
|
|
|
158
|
- }
|
|
|
159
|
- evaluationTemp.Types = domain.Evaluation360
|
|
|
160
|
- newEvaluationList = append(newEvaluationList, evaluationTemp)
|
|
|
161
|
- }
|
101
|
+// //确定周期评估
|
162
|
|
102
|
|
163
|
- //处理上级评估
|
|
|
164
|
- superUser, ok := userMap[v.ParentId]
|
|
|
165
|
- if ok {
|
|
|
166
|
- evaluationTemp.Types = domain.EvaluationSuper
|
|
|
167
|
- evaluationTemp.Executor = domain.StaffDesc{
|
|
|
168
|
- UserId: int(superUser.Id),
|
|
|
169
|
- Account: superUser.Account,
|
|
|
170
|
- UserName: superUser.Name,
|
|
|
171
|
- }
|
|
|
172
|
- evaluationTemp.BeginTime = beginTimeSuper
|
|
|
173
|
- evaluationTemp.EndTime = endTimeSuper
|
|
|
174
|
- //确定上级评估
|
|
|
175
|
- newEvaluationList = append(newEvaluationList, evaluationTemp)
|
|
|
176
|
- }
|
|
|
177
|
- // 确定 考核结果 的评估记录
|
|
|
178
|
- evaluationTemp.Types = domain.EvaluationFinish
|
|
|
179
|
- evaluationTemp.Executor = domain.StaffDesc{}
|
|
|
180
|
- evaluationTemp.BeginTime = endTimeSuper
|
|
|
181
|
- evaluationTemp.EndTime = endTimeSuper.Add(2 * 24 * time.Hour)
|
|
|
182
|
- newEvaluationList = append(newEvaluationList, evaluationTemp)
|
|
|
183
|
- }
|
|
|
184
|
- summaryEvaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{"transactionContext": transactionContext})
|
|
|
185
|
- for i := range newEvaluationList {
|
|
|
186
|
- err = summaryEvaluationRepo.Save(&newEvaluationList[i])
|
|
|
187
|
- if err != nil {
|
|
|
188
|
- return nil, err
|
|
|
189
|
- }
|
|
|
190
|
- }
|
|
|
191
|
- //回填 项目的状态
|
|
|
192
|
- projectDao := dao.NewEvaluationProjectDao(map[string]interface{}{"transactionContext": transactionContext})
|
|
|
193
|
- err = projectDao.UpdateSummaryState(project.Id, domain.ProjectSummaryStateYes)
|
|
|
194
|
- if err != nil {
|
|
|
195
|
- return nil, err
|
|
|
196
|
- }
|
|
|
197
|
- if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
198
|
- return nil, err
|
|
|
199
|
- }
|
|
|
200
|
- return newEvaluationList, nil
|
|
|
201
|
-}
|
103
|
+// for _, v := range targetUserMap {
|
|
|
104
|
+// //处理自评
|
|
|
105
|
+// evaluationTemp.TargetUser = domain.StaffDesc{
|
|
|
106
|
+// UserId: int(v.Id),
|
|
|
107
|
+// Account: v.Account,
|
|
|
108
|
+// UserName: v.Name,
|
|
|
109
|
+// }
|
|
|
110
|
+// evaluationTemp.Executor = domain.StaffDesc{
|
|
|
111
|
+// UserId: int(v.Id),
|
|
|
112
|
+// Account: v.Account,
|
|
|
113
|
+// UserName: v.Name,
|
|
|
114
|
+// }
|
|
|
115
|
+// evaluationTemp.BeginTime = beginTimeSelf
|
|
|
116
|
+// evaluationTemp.EndTime = endTimeSelf
|
|
|
117
|
+// evaluationTemp.TargetDepartment = []domain.StaffDepartment{}
|
|
|
118
|
+// evaluationTemp.Types = domain.EvaluationSelf
|
|
|
119
|
+// for _, departId := range v.DepartmentId {
|
|
|
120
|
+// depart, ok := departmentMap[int64(departId)]
|
|
|
121
|
+// if !ok {
|
|
|
122
|
+// continue
|
|
|
123
|
+// }
|
|
|
124
|
+// evaluationTemp.TargetDepartment = append(evaluationTemp.TargetDepartment, domain.StaffDepartment{
|
|
|
125
|
+// DepartmentId: int(depart.Id),
|
|
|
126
|
+// DepartmentName: depart.Name,
|
|
|
127
|
+// })
|
|
|
128
|
+// }
|
|
|
129
|
+// newEvaluationList = append(newEvaluationList, evaluationTemp)
|
|
|
130
|
+// if hrbpExist {
|
|
|
131
|
+// //处理人资评估
|
|
|
132
|
+// evaluationTemp.BeginTime = beginTime360
|
|
|
133
|
+// evaluationTemp.EndTime = endTime360
|
|
|
134
|
+// evaluationTemp.Executor = domain.StaffDesc{}
|
|
|
135
|
+// evaluationTemp.Types = domain.EvaluationHrbp
|
|
|
136
|
+// newEvaluationList = append(newEvaluationList, evaluationTemp)
|
|
|
137
|
+// }
|
|
|
138
|
+// //处理360 评估
|
|
|
139
|
+// for _, v2 := range executor360Map {
|
|
|
140
|
+// evaluationTemp.BeginTime = beginTime360
|
|
|
141
|
+// evaluationTemp.EndTime = endTime360
|
|
|
142
|
+// evaluationTemp.Executor = domain.StaffDesc{
|
|
|
143
|
+// UserId: int(v2.Id),
|
|
|
144
|
+// Account: v2.Account,
|
|
|
145
|
+// UserName: v2.Name,
|
|
|
146
|
+// }
|
|
|
147
|
+// evaluationTemp.Types = domain.Evaluation360
|
|
|
148
|
+// newEvaluationList = append(newEvaluationList, evaluationTemp)
|
|
|
149
|
+// }
|
202
|
|
150
|
|
203
|
-func dayZeroTime(t time.Time) time.Time {
|
|
|
204
|
- y, m, d := t.Local().Date()
|
|
|
205
|
- t2 := time.Date(y, m, d, 0, 0, 0, 0, time.Local)
|
|
|
206
|
- return t2
|
|
|
207
|
-}
|
151
|
+// //处理上级评估
|
|
|
152
|
+// superUser, ok := userMap[v.ParentId]
|
|
|
153
|
+// if ok {
|
|
|
154
|
+// evaluationTemp.Types = domain.EvaluationSuper
|
|
|
155
|
+// evaluationTemp.Executor = domain.StaffDesc{
|
|
|
156
|
+// UserId: int(superUser.Id),
|
|
|
157
|
+// Account: superUser.Account,
|
|
|
158
|
+// UserName: superUser.Name,
|
|
|
159
|
+// }
|
|
|
160
|
+// evaluationTemp.BeginTime = beginTimeSuper
|
|
|
161
|
+// evaluationTemp.EndTime = endTimeSuper
|
|
|
162
|
+// //确定上级评估
|
|
|
163
|
+// newEvaluationList = append(newEvaluationList, evaluationTemp)
|
|
|
164
|
+// }
|
|
|
165
|
+// // 确定 考核结果 的评估记录
|
|
|
166
|
+// evaluationTemp.Types = domain.EvaluationFinish
|
|
|
167
|
+// evaluationTemp.Executor = domain.StaffDesc{}
|
|
|
168
|
+// evaluationTemp.BeginTime = endTimeSuper
|
|
|
169
|
+// evaluationTemp.EndTime = endTimeSuper.Add(2 * 24 * time.Hour)
|
|
|
170
|
+// newEvaluationList = append(newEvaluationList, evaluationTemp)
|
|
|
171
|
+// }
|
|
|
172
|
+// summaryEvaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{"transactionContext": transactionContext})
|
|
|
173
|
+// for i := range newEvaluationList {
|
|
|
174
|
+// err = summaryEvaluationRepo.Save(&newEvaluationList[i])
|
|
|
175
|
+// if err != nil {
|
|
|
176
|
+// return nil, err
|
|
|
177
|
+// }
|
|
|
178
|
+// }
|
|
|
179
|
+// //回填 项目的状态
|
|
|
180
|
+// projectDao := dao.NewEvaluationProjectDao(map[string]interface{}{"transactionContext": transactionContext})
|
|
|
181
|
+// err = projectDao.UpdateSummaryState(project.Id, domain.ProjectSummaryStateYes)
|
|
|
182
|
+// if err != nil {
|
|
|
183
|
+// return nil, err
|
|
|
184
|
+// }
|
|
|
185
|
+// if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
186
|
+// return nil, err
|
|
|
187
|
+// }
|
|
|
188
|
+// return newEvaluationList, nil
|
|
|
189
|
+// }
|
208
|
|
190
|
|
209
|
-// 下发周期评估
|
|
|
210
|
-func TaskSendSummaryEvaluation() error {
|
|
|
211
|
- nowTime := time.Now()
|
|
|
212
|
- defer func() {
|
|
|
213
|
- str := fmt.Sprintf("下发周期评估耗时%.2f s", time.Since(nowTime).Seconds())
|
|
|
214
|
- log.Logger.Info(str)
|
|
|
215
|
- }()
|
|
|
216
|
- transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
217
|
- if err != nil {
|
|
|
218
|
- return err
|
|
|
219
|
- }
|
|
|
220
|
- if err := transactionContext.StartTransaction(); err != nil {
|
|
|
221
|
- return err
|
|
|
222
|
- }
|
|
|
223
|
- defer func() {
|
|
|
224
|
- _ = transactionContext.RollbackTransaction()
|
|
|
225
|
- }()
|
191
|
+// func dayZeroTime(t time.Time) time.Time {
|
|
|
192
|
+// y, m, d := t.Local().Date()
|
|
|
193
|
+// t2 := time.Date(y, m, d, 0, 0, 0, 0, time.Local)
|
|
|
194
|
+// return t2
|
|
|
195
|
+// }
|
226
|
|
196
|
|
227
|
- projectRepo := factory.CreateEvaluationProjectRepository(map[string]interface{}{
|
|
|
228
|
- "transactionContext": transactionContext,
|
|
|
229
|
- })
|
197
|
+// // 下发周期评估
|
|
|
198
|
+// func TaskSendSummaryEvaluation() error {
|
|
|
199
|
+// nowTime := time.Now()
|
|
|
200
|
+// defer func() {
|
|
|
201
|
+// str := fmt.Sprintf("下发周期评估耗时%.2f s", time.Since(nowTime).Seconds())
|
|
|
202
|
+// log.Logger.Info(str)
|
|
|
203
|
+// }()
|
|
|
204
|
+// transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
205
|
+// if err != nil {
|
|
|
206
|
+// return err
|
|
|
207
|
+// }
|
|
|
208
|
+// if err := transactionContext.StartTransaction(); err != nil {
|
|
|
209
|
+// return err
|
|
|
210
|
+// }
|
|
|
211
|
+// defer func() {
|
|
|
212
|
+// _ = transactionContext.RollbackTransaction()
|
|
|
213
|
+// }()
|
230
|
|
214
|
|
231
|
- userRepo := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext})
|
215
|
+// projectRepo := factory.CreateEvaluationProjectRepository(map[string]interface{}{
|
|
|
216
|
+// "transactionContext": transactionContext,
|
|
|
217
|
+// })
|
232
|
|
218
|
|
233
|
- departmentRepo := factory.CreateDepartmentRepository(map[string]interface{}{"transactionContext": transactionContext})
|
219
|
+// userRepo := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext})
|
234
|
|
220
|
|
235
|
- _, projectList, err := projectRepo.Find(map[string]interface{}{
|
|
|
236
|
- "endTime": time.Now(),
|
|
|
237
|
- "summaryState": domain.ProjectSummaryStateNo,
|
|
|
238
|
- "state": domain.ProjectStateEnable,
|
|
|
239
|
- }, "template")
|
|
|
240
|
- if err != nil {
|
|
|
241
|
- return fmt.Errorf("获取可用的项目数据,%s", err)
|
|
|
242
|
- }
|
|
|
243
|
- companyIdMap := map[int64]struct{}{}
|
|
|
244
|
- for _, v := range projectList {
|
|
|
245
|
- companyIdMap[v.CompanyId] = struct{}{}
|
|
|
246
|
- }
|
221
|
+// departmentRepo := factory.CreateDepartmentRepository(map[string]interface{}{"transactionContext": transactionContext})
|
247
|
|
222
|
|
248
|
- var createdEvalationList []domain.SummaryEvaluation
|
223
|
+// _, projectList, err := projectRepo.Find(map[string]interface{}{
|
|
|
224
|
+// "endTime": time.Now(),
|
|
|
225
|
+// "summaryState": domain.ProjectSummaryStateNo,
|
|
|
226
|
+// "state": domain.ProjectStateEnable,
|
|
|
227
|
+// }, "template")
|
|
|
228
|
+// if err != nil {
|
|
|
229
|
+// return fmt.Errorf("获取可用的项目数据,%s", err)
|
|
|
230
|
+// }
|
|
|
231
|
+// companyIdMap := map[int64]struct{}{}
|
|
|
232
|
+// for _, v := range projectList {
|
|
|
233
|
+// companyIdMap[v.CompanyId] = struct{}{}
|
|
|
234
|
+// }
|
249
|
|
235
|
|
250
|
- //获取可执行的项目
|
|
|
251
|
- for companyId := range companyIdMap {
|
|
|
252
|
- //获取员工数据,部门数据
|
|
|
253
|
- _, userList, err := userRepo.Find(map[string]interface{}{"companyId": companyId})
|
|
|
254
|
- if err != nil {
|
|
|
255
|
- log.Logger.Error("TaskSendSummaryEvaluation 获取员工数据:" + err.Error())
|
|
|
256
|
- continue
|
|
|
257
|
- }
|
|
|
258
|
- _, departmentList, err := departmentRepo.Find(map[string]interface{}{"companyId": companyId})
|
|
|
259
|
- if err != nil {
|
|
|
260
|
- log.Logger.Error("TaskSendSummaryEvaluation 获取部门数据:" + err.Error())
|
|
|
261
|
- continue
|
|
|
262
|
- }
|
|
|
263
|
- //转map
|
|
|
264
|
- userMap := map[int64]*domain.User{}
|
|
|
265
|
- for _, v := range userList {
|
|
|
266
|
- userMap[v.Id] = v
|
|
|
267
|
- }
|
|
|
268
|
- departmentMap := map[int64]*domain.Department{}
|
|
|
269
|
- for _, v := range departmentList {
|
|
|
270
|
- departmentMap[v.Id] = v
|
|
|
271
|
- }
|
|
|
272
|
- for _, v := range projectList {
|
|
|
273
|
- if v.CompanyId != companyId {
|
|
|
274
|
- continue
|
|
|
275
|
- }
|
|
|
276
|
- evalationList, err := sendSummaryEvaluation(v, userMap, departmentMap)
|
|
|
277
|
- if err != nil {
|
|
|
278
|
- log.Logger.Error("TaskSendSummaryEvaluation 下发评估任务:" + err.Error())
|
|
|
279
|
- continue
|
|
|
280
|
- }
|
|
|
281
|
- createdEvalationList = append(createdEvalationList, evalationList...)
|
|
|
282
|
- }
|
|
|
283
|
- }
|
|
|
284
|
- if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
285
|
- return err
|
|
|
286
|
- }
|
|
|
287
|
- //添加待发送的短信通知
|
|
|
288
|
- err = sendSmsEvalation(createdEvalationList)
|
|
|
289
|
- return err
|
|
|
290
|
-}
|
236
|
+// var createdEvalationList []domain.SummaryEvaluation
|
291
|
|
237
|
|
292
|
-// 添加待发送的短信通知
|
|
|
293
|
-func sendSmsEvalation(param []domain.SummaryEvaluation) error {
|
|
|
294
|
- for i := range param {
|
|
|
295
|
- if param[i].Types == domain.EvaluationSelf {
|
|
|
296
|
- notify.AddNotifySummaryEvaluation(¶m[i])
|
|
|
297
|
- }
|
|
|
298
|
- }
|
|
|
299
|
- return nil
|
|
|
300
|
-} |
238
|
+// //获取可执行的项目
|
|
|
239
|
+// for companyId := range companyIdMap {
|
|
|
240
|
+// //获取员工数据,部门数据
|
|
|
241
|
+// _, userList, err := userRepo.Find(map[string]interface{}{"companyId": companyId})
|
|
|
242
|
+// if err != nil {
|
|
|
243
|
+// log.Logger.Error("TaskSendSummaryEvaluation 获取员工数据:" + err.Error())
|
|
|
244
|
+// continue
|
|
|
245
|
+// }
|
|
|
246
|
+// _, departmentList, err := departmentRepo.Find(map[string]interface{}{"companyId": companyId})
|
|
|
247
|
+// if err != nil {
|
|
|
248
|
+// log.Logger.Error("TaskSendSummaryEvaluation 获取部门数据:" + err.Error())
|
|
|
249
|
+// continue
|
|
|
250
|
+// }
|
|
|
251
|
+// //转map
|
|
|
252
|
+// userMap := map[int64]*domain.User{}
|
|
|
253
|
+// for _, v := range userList {
|
|
|
254
|
+// userMap[v.Id] = v
|
|
|
255
|
+// }
|
|
|
256
|
+// departmentMap := map[int64]*domain.Department{}
|
|
|
257
|
+// for _, v := range departmentList {
|
|
|
258
|
+// departmentMap[v.Id] = v
|
|
|
259
|
+// }
|
|
|
260
|
+// for _, v := range projectList {
|
|
|
261
|
+// if v.CompanyId != companyId {
|
|
|
262
|
+// continue
|
|
|
263
|
+// }
|
|
|
264
|
+// evalationList, err := sendSummaryEvaluation(v, userMap, departmentMap)
|
|
|
265
|
+// if err != nil {
|
|
|
266
|
+// log.Logger.Error("TaskSendSummaryEvaluation 下发评估任务:" + err.Error())
|
|
|
267
|
+// continue
|
|
|
268
|
+// }
|
|
|
269
|
+// createdEvalationList = append(createdEvalationList, evalationList...)
|
|
|
270
|
+// }
|
|
|
271
|
+// }
|
|
|
272
|
+// if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
273
|
+// return err
|
|
|
274
|
+// }
|
|
|
275
|
+// //添加待发送的短信通知
|
|
|
276
|
+// err = sendSmsEvalation(createdEvalationList)
|
|
|
277
|
+// return err
|
|
|
278
|
+// } |