service3.go
7.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
package service
import (
"fmt"
"github.com/linmadan/egglib-go/core/application"
"github.com/linmadan/egglib-go/utils/tool_funs"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
permissionSrv "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/permission"
permissionCmd "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/permission/command"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/summary_evaluation/adapter"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/summary_evaluation/command"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/dao"
)
func getPermission(companyId int64) (*domain.Permission, error) {
srv := &permissionSrv.PermissionService{}
permissionData, err := srv.Get(&permissionCmd.GetPermissionCommand{
CompanyId: companyId,
})
if err != nil {
return nil, err
}
return permissionData, nil
}
// ListCycleAndProject
// 自评小结列表,自评评估列表
func (srv *SummaryEvaluationService) ListCycleAndProject(param *command.QueryCycleList) (map[string]interface{}, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
limit := 600
offset := 0
if param.PageSize > 0 {
limit = param.PageSize
}
if param.PageNumber > 0 {
offset = (param.PageNumber - 1) * param.PageSize
}
assessDao := dao.NewStaffAssessDao(map[string]interface{}{
"transactionContext": transactionContext,
})
projectList, err := assessDao.ListCycleAndProject(param.UserId, param.CompanyId, param.CycleId, offset, limit)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
cycleList := []adapter.CycleAndProjctListAdapter{}
for _, v := range projectList {
m := adapter.CycleAndProjctListAdapter{
CycleId: v.CycleId,
CycleName: v.CycleName,
ProjectId: v.EvaluationProjectId,
ProjectName: v.EvaluationProjectName,
TargetUserId: v.TargetUserId,
}
cycleList = append(cycleList, m)
}
return tool_funs.SimpleWrapGridMap(int64(len(projectList)), cycleList), nil
}
// 周期综合自评小结详情
func (srv *SummaryEvaluationService) CountEvaluationSelfLevelV2(param *command.QueryEvaluationSelf) (*adapter.EvaluationInfoCountCodeAdapter, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
//统计周期内,评估项等级的数量
assessDao := dao.NewStaffAssessDao(map[string]interface{}{
"transactionContext": transactionContext,
})
evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
evaluationItemRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
itemValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
_, evaluationList, err := evaluationRepo.Find(map[string]interface{}{
"limit": 1,
"cycleId": param.CycleId,
"targetUserId": param.TargetUserId,
"types": domain.EvaluationSelf,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if len(evaluationList) == 0 {
return &adapter.EvaluationInfoCountCodeAdapter{}, nil
}
evaluationData := evaluationList[0]
levelCodeCountList, err := assessDao.CountAssessContentLevelCode(param.ProjectId, param.TargetUserId, domain.AssessSelf, param.CycleId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
_, itemList, err := evaluationItemRepo.Find(map[string]interface{}{
"evaluationProjectId": param.ProjectId,
"nodeType": int(domain.LinkNodeSelfAssessment),
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
_, itemValues, err := itemValueRepo.Find(map[string]interface{}{
"summaryEvaluationId": evaluationData.Id,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 获取组装基本信息
evaluationBase := srv.getSummaryEvaluation(transactionContext, evaluationData)
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
evaluationBase.EvaluationProjectId = param.ProjectId
evaluationBase.EvaluationProjectName = ""
evaluationItems := srv.buildSummaryItemValue(itemList, itemValues)
levelCodeMap := map[int][]adapter.LevalCodeCount{}
for _, v := range evaluationItems {
codes := v.Rule.GetLevelCodes()
levelCode := []adapter.LevalCodeCount{}
for _, v2 := range codes {
levelCode = append(levelCode, adapter.LevalCodeCount{
Code: v2,
Number: 0,
})
}
levelCodeMap[v.EvaluationItemId] = levelCode
}
levelCodeCountMap := map[string]int{}
for _, v := range levelCodeCountList {
key := fmt.Sprintf("%s-%s-%s", v.Category, v.Name, v.LevelValue)
levelCodeCountMap[key] = v.Cnt
}
evaluationItemCount := []adapter.EvaluationItemCountCodeAdapter{}
for i := range evaluationItems {
itemCount := adapter.EvaluationItemCountCodeAdapter{
EvaluationItemAdapter: evaluationItems[i],
LevelCount: []adapter.LevalCodeCount{},
}
evaluationItemCount = append(evaluationItemCount, itemCount)
itemId := evaluationItems[i].EvaluationItemId
levelCodes, ok := levelCodeMap[itemId]
if !ok {
continue
}
evaluationItemCount[i].LevelCount = levelCodes
for i2 := range levelCodes {
key := fmt.Sprintf("%s-%s-%s",
evaluationItems[i].Category,
evaluationItems[i].Name,
levelCodes[i2].Code,
)
if mVal, ok := levelCodeCountMap[key]; ok {
levelCodes[i2].Number = mVal
}
}
}
evaluationInfo := adapter.EvaluationInfoCountCodeAdapter{
EvaluationBaseAdapter: evaluationBase,
EvaluationItems: evaluationItemCount,
}
return &evaluationInfo, nil
}
// 获取已结束的周期列表
func (srv *SummaryEvaluationService) ListCycle(companyId int) (map[string]interface{}, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
summaryEvaluationDao := dao.NewSummaryEvaluationDao(map[string]interface{}{
"transactionContext": transactionContext,
})
cycleList, err := summaryEvaluationDao.ListCycle(companyId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取周期列表"+err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
result := map[string]interface{}{
"list": cycleList,
}
return result, nil
}