正在显示
10 个修改的文件
包含
196 行增加
和
122 行删除
@@ -15,3 +15,12 @@ func (in *QueryCycleCommand) Valid(validation *validation.Validation) { | @@ -15,3 +15,12 @@ func (in *QueryCycleCommand) Valid(validation *validation.Validation) { | ||
15 | return | 15 | return |
16 | } | 16 | } |
17 | } | 17 | } |
18 | + | ||
19 | +type StatisticCycleProjectUserCommand struct { | ||
20 | + CompanyId int64 `cname:"公司ID" json:"companyId"` | ||
21 | + CycleId int64 `cname:"周期ID" json:"cycleId,string"` | ||
22 | +} | ||
23 | + | ||
24 | +func (in *StatisticCycleProjectUserCommand) Valid(*validation.Validation) { | ||
25 | + | ||
26 | +} |
@@ -280,3 +280,51 @@ func (rs *EvaluationCycleService) List(in *command.QueryCycleCommand) (interface | @@ -280,3 +280,51 @@ func (rs *EvaluationCycleService) List(in *command.QueryCycleCommand) (interface | ||
280 | } | 280 | } |
281 | return tool_funs.SimpleWrapGridMap(total, cycles), nil | 281 | return tool_funs.SimpleWrapGridMap(total, cycles), nil |
282 | } | 282 | } |
283 | + | ||
284 | +func (rs *EvaluationCycleService) StatisticCycleUser(in *command.StatisticCycleProjectUserCommand) (interface{}, error) { | ||
285 | + transactionContext, err := factory.ValidateStartTransaction(in) | ||
286 | + if err != nil { | ||
287 | + return nil, err | ||
288 | + } | ||
289 | + defer func() { | ||
290 | + transactionContext.RollbackTransaction() | ||
291 | + }() | ||
292 | + projectRepository := factory.CreateEvaluationProjectRepository(map[string]interface{}{"transactionContext": transactionContext}) | ||
293 | + _, projects, err := projectRepository.Find(tool_funs.SimpleStructToMap(in), "linkNodes") | ||
294 | + if err != nil { | ||
295 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
296 | + } | ||
297 | + | ||
298 | + userIds := make([]int64, 0) | ||
299 | + userIdMap := map[int64]int64{} | ||
300 | + for i := range projects { | ||
301 | + project := projects[i] | ||
302 | + for j := range project.Recipients { | ||
303 | + userId, _ := strconv.ParseInt(project.Recipients[j], 10, 64) | ||
304 | + userIdMap[userId] = userId | ||
305 | + } | ||
306 | + } | ||
307 | + for _, v := range userIdMap { | ||
308 | + userIds = append(userIds, v) | ||
309 | + } | ||
310 | + | ||
311 | + userTotal := 0 | ||
312 | + departmentTotal := 0 | ||
313 | + if len(userIds) > 0 { | ||
314 | + userRepository := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext}) | ||
315 | + _, users, _ := userRepository.Find(map[string]interface{}{"ids": userIds, "limit": len(userIds)}) | ||
316 | + departmentIdMap := map[int]int{} | ||
317 | + for i := range users { | ||
318 | + for _, v := range users[i].DepartmentId { | ||
319 | + departmentIdMap[v] = v | ||
320 | + } | ||
321 | + } | ||
322 | + userTotal = len(users) | ||
323 | + departmentTotal = len(departmentIdMap) | ||
324 | + } | ||
325 | + | ||
326 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
327 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
328 | + } | ||
329 | + return map[string]interface{}{"userTotal": userTotal, "departmentTotal": departmentTotal}, nil | ||
330 | +} |
@@ -2,25 +2,19 @@ package command | @@ -2,25 +2,19 @@ package command | ||
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "github.com/beego/beego/v2/core/validation" | 4 | "github.com/beego/beego/v2/core/validation" |
5 | - "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" | ||
6 | ) | 5 | ) |
7 | 6 | ||
8 | -type StateProjectCommand struct { | ||
9 | - Id int64 `cname:"项目ID" json:"id,string" valid:"Required"` | ||
10 | - State int `cname:"项目状态" json:"state"` | 7 | +type ActivateProjectCommand struct { |
8 | + Id int64 `cname:"项目ID" json:"id,string" valid:"Required"` | ||
11 | } | 9 | } |
12 | 10 | ||
13 | type CopyProjectCommand struct { | 11 | type CopyProjectCommand struct { |
14 | - Id int64 `cname:"模板ID" json:"id,string" valid:"Required"` | 12 | + CreatorId int64 `cname:"创建人ID" json:"creatorId"` |
13 | + Id int64 `cname:"模板ID" json:"id,string" valid:"Required"` | ||
15 | } | 14 | } |
16 | 15 | ||
17 | -func (in *StateProjectCommand) Valid(validation *validation.Validation) { | ||
18 | - switch in.State { | ||
19 | - case domain.ProjectStateWaitConfig, domain.ProjectStateWaitActive, domain.ProjectStateEnable, domain.ProjectStateDisable: | ||
20 | - default: | ||
21 | - validation.SetError("state", "状态设置错误") | ||
22 | - return | ||
23 | - } | 16 | +func (in *ActivateProjectCommand) Valid(validation *validation.Validation) { |
17 | + | ||
24 | } | 18 | } |
25 | 19 | ||
26 | func (in *CopyProjectCommand) Valid(*validation.Validation) { | 20 | func (in *CopyProjectCommand) Valid(*validation.Validation) { |
@@ -18,12 +18,3 @@ func (in *QueryProjectCommand) Valid(validation *validation.Validation) { | @@ -18,12 +18,3 @@ func (in *QueryProjectCommand) Valid(validation *validation.Validation) { | ||
18 | return | 18 | return |
19 | } | 19 | } |
20 | } | 20 | } |
21 | - | ||
22 | -type StatisticCycleProjectUserCommand struct { | ||
23 | - CompanyId int64 `cname:"公司ID" json:"companyId"` | ||
24 | - CycleId int64 `cname:"周期ID" json:"cycleId,string"` | ||
25 | -} | ||
26 | - | ||
27 | -func (in *StatisticCycleProjectUserCommand) Valid(*validation.Validation) { | ||
28 | - | ||
29 | -} |
@@ -2,7 +2,7 @@ package command | @@ -2,7 +2,7 @@ package command | ||
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "github.com/beego/beego/v2/core/validation" | 4 | "github.com/beego/beego/v2/core/validation" |
5 | - "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" | 5 | + "time" |
6 | ) | 6 | ) |
7 | 7 | ||
8 | type UpdateProjectCommand struct { | 8 | type UpdateProjectCommand struct { |
@@ -17,22 +17,25 @@ type UpdateProjectCommand struct { | @@ -17,22 +17,25 @@ type UpdateProjectCommand struct { | ||
17 | } | 17 | } |
18 | 18 | ||
19 | type UpdateProjectTemplateCommand struct { | 19 | type UpdateProjectTemplateCommand struct { |
20 | + CompanyId int64 `cname:"公司ID" json:"companyId"` | ||
21 | + CycleId int64 `cname:"周期ID" json:"cycleId,string" valid:"Required"` | ||
22 | + Id int64 `cname:"项目ID" json:"id,string" valid:"Required"` | ||
23 | + TemplateId int64 `cname:"模板ID" json:"templateId,string"` | ||
24 | + Recipients []string `cname:"被评估人ID" json:"recipients"` | ||
25 | + TimeStart *time.Time `cname:"自评起始时间" json:"timeStart" valid:"Required"` | ||
26 | + TimeEnd *time.Time `cname:"自评截止时间" json:"timeEnd" valid:"Required"` | ||
27 | + KpiCycle int `cname:"评估周期" json:"kpiCycle" valid:"Required"` | ||
28 | + KpiResultStart *time.Time `cname:"绩效结果开始查看时间" json:"kpiResultStart"` | ||
29 | + Activate int `cname:"启动项目" json:"activate"` | ||
30 | +} | ||
31 | + | ||
32 | +type CheckRecipientCommand struct { | ||
20 | CompanyId int64 `cname:"公司ID" json:"companyId"` | 33 | CompanyId int64 `cname:"公司ID" json:"companyId"` |
21 | CycleId int64 `cname:"周期ID" json:"cycleId,string" valid:"Required"` | 34 | CycleId int64 `cname:"周期ID" json:"cycleId,string" valid:"Required"` |
22 | Id int64 `cname:"项目ID" json:"id,string" valid:"Required"` | 35 | Id int64 `cname:"项目ID" json:"id,string" valid:"Required"` |
23 | - TemplateId int64 `cname:"模板ID" json:"templateId,string"` | ||
24 | Recipients []string `cname:"被评估人ID" json:"recipients"` | 36 | Recipients []string `cname:"被评估人ID" json:"recipients"` |
25 | } | 37 | } |
26 | 38 | ||
27 | -type UpdateProjectTemplateNodeCommand struct { | ||
28 | - CompanyId int64 `cname:"公司ID" json:"companyId"` | ||
29 | - CycleId int64 `cname:"周期ID" json:"cycleId,string" valid:"Required"` | ||
30 | - Id int64 `cname:"项目ID" json:"id,string" valid:"Required"` | ||
31 | - TemplateId int64 `cname:"模板ID" json:"templateId,string" valid:"Required"` | ||
32 | - LinkNodes []*domain.LinkNode `cname:"评估流程" json:"linkNodes"` | ||
33 | - Activate int `cname:"启动项目" json:"activate"` | ||
34 | -} | ||
35 | - | ||
36 | func (in *UpdateProjectCommand) Valid(validation *validation.Validation) { | 39 | func (in *UpdateProjectCommand) Valid(validation *validation.Validation) { |
37 | if len(in.Name) > 40 { | 40 | if len(in.Name) > 40 { |
38 | validation.SetError("name", "项目名称最大长度40个字符") | 41 | validation.SetError("name", "项目名称最大长度40个字符") |
@@ -46,10 +49,3 @@ func (in *UpdateProjectTemplateCommand) Valid(validation *validation.Validation) | @@ -46,10 +49,3 @@ func (in *UpdateProjectTemplateCommand) Valid(validation *validation.Validation) | ||
46 | return | 49 | return |
47 | } | 50 | } |
48 | } | 51 | } |
49 | - | ||
50 | -func (in *UpdateProjectTemplateNodeCommand) Valid(validation *validation.Validation) { | ||
51 | - if len(in.LinkNodes) == 0 { | ||
52 | - validation.SetError("linkNodes", "请添加评估流程") | ||
53 | - return | ||
54 | - } | ||
55 | -} |
@@ -55,10 +55,19 @@ func (rs *EvaluationProjectService) Create(in *command.CreateProjectCommand) (in | @@ -55,10 +55,19 @@ func (rs *EvaluationProjectService) Create(in *command.CreateProjectCommand) (in | ||
55 | if err != nil { | 55 | if err != nil { |
56 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 56 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
57 | } | 57 | } |
58 | + | ||
59 | + projectAdapter := &adapter.EvaluationProjectAdapter{} | ||
60 | + projectAdapter.EvaluationProject = project | ||
61 | + if len(project.PmpIds) > 0 { | ||
62 | + userRepository := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext}) | ||
63 | + _, users, _ := userRepository.Find(map[string]interface{}{"ids": project.PmpIds, "limit": len(project.PmpIds)}) | ||
64 | + projectAdapter.TransformPmpAdapter(users) | ||
65 | + } | ||
66 | + | ||
58 | if err := transactionContext.CommitTransaction(); err != nil { | 67 | if err := transactionContext.CommitTransaction(); err != nil { |
59 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 68 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
60 | } | 69 | } |
61 | - return project, nil | 70 | + return projectAdapter, nil |
62 | 71 | ||
63 | } | 72 | } |
64 | 73 | ||
@@ -96,10 +105,19 @@ func (rs *EvaluationProjectService) Update(in *command.UpdateProjectCommand) (in | @@ -96,10 +105,19 @@ func (rs *EvaluationProjectService) Update(in *command.UpdateProjectCommand) (in | ||
96 | if err != nil { | 105 | if err != nil { |
97 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 106 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
98 | } | 107 | } |
108 | + | ||
109 | + projectAdapter := &adapter.EvaluationProjectAdapter{} | ||
110 | + projectAdapter.EvaluationProject = project | ||
111 | + if len(project.PmpIds) > 0 { | ||
112 | + userRepository := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext}) | ||
113 | + _, users, _ := userRepository.Find(map[string]interface{}{"ids": project.PmpIds, "limit": len(project.PmpIds)}) | ||
114 | + projectAdapter.TransformPmpAdapter(users) | ||
115 | + } | ||
116 | + | ||
99 | if err := transactionContext.CommitTransaction(); err != nil { | 117 | if err := transactionContext.CommitTransaction(); err != nil { |
100 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 118 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
101 | } | 119 | } |
102 | - return project, nil | 120 | + return projectAdapter, nil |
103 | } | 121 | } |
104 | 122 | ||
105 | func (rs *EvaluationProjectService) UpdateTemplate(in *command.UpdateProjectTemplateCommand) (interface{}, error) { | 123 | func (rs *EvaluationProjectService) UpdateTemplate(in *command.UpdateProjectTemplateCommand) (interface{}, error) { |
@@ -145,48 +163,33 @@ func (rs *EvaluationProjectService) UpdateTemplate(in *command.UpdateProjectTemp | @@ -145,48 +163,33 @@ func (rs *EvaluationProjectService) UpdateTemplate(in *command.UpdateProjectTemp | ||
145 | if err != nil { | 163 | if err != nil { |
146 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 164 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
147 | } | 165 | } |
148 | - cycleTemplate, err := cycleTemplateRepository.FindOne(map[string]interface{}{"id": in.TemplateId, "includeDeleted": true}) | ||
149 | - if err != nil { | ||
150 | - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
151 | - } | ||
152 | - | ||
153 | - project.Recipients = in.Recipients | ||
154 | - project.Template = cycleTemplate.Template | ||
155 | - | ||
156 | - project, err = projectRepository.Insert(project) | ||
157 | - if err != nil { | ||
158 | - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
159 | - } | ||
160 | - if err := transactionContext.CommitTransaction(); err != nil { | ||
161 | - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
162 | - } | ||
163 | - return project, nil | ||
164 | -} | ||
165 | 166 | ||
166 | -func (rs *EvaluationProjectService) UpdateTemplateNode(in *command.UpdateProjectTemplateNodeCommand) (interface{}, error) { | ||
167 | - transactionContext, err := factory.ValidateStartTransaction(in) | ||
168 | - if err != nil { | ||
169 | - return nil, err | ||
170 | - } | ||
171 | - defer func() { | ||
172 | - transactionContext.RollbackTransaction() | ||
173 | - }() | ||
174 | - | ||
175 | - projectRepository := factory.CreateEvaluationProjectRepository(map[string]interface{}{"transactionContext": transactionContext}) | ||
176 | - | ||
177 | - project, err := projectRepository.FindOne(map[string]interface{}{"id": in.Id}) | 167 | + cycleTemplate, err := cycleTemplateRepository.FindOne(map[string]interface{}{"id": in.TemplateId, "includeDeleted": true}) |
178 | if err != nil { | 168 | if err != nil { |
179 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 169 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
180 | } | 170 | } |
181 | 171 | ||
182 | // FIXME 启动时,需要激活定时任务 | 172 | // FIXME 启动时,需要激活定时任务 |
183 | if in.Activate == 1 { | 173 | if in.Activate == 1 { |
174 | + if len(in.Recipients) == 0 { | ||
175 | + return nil, application.ThrowError(application.BUSINESS_ERROR, "请添加被评估人") | ||
176 | + } | ||
184 | project.State = domain.ProjectStateEnable | 177 | project.State = domain.ProjectStateEnable |
185 | } | 178 | } |
186 | - for i := range in.LinkNodes { | ||
187 | - project.Template.LinkNodes[i].TimeStart = in.LinkNodes[i].TimeStart | ||
188 | - project.Template.LinkNodes[i].TimeEnd = in.LinkNodes[i].TimeEnd | ||
189 | - project.Template.LinkNodes[i].KpiCycle = in.LinkNodes[i].KpiCycle | 179 | + |
180 | + project.Recipients = in.Recipients | ||
181 | + project.Template = cycleTemplate.Template | ||
182 | + for i := range project.Template.LinkNodes { | ||
183 | + node := project.Template.LinkNodes[i] | ||
184 | + node.KpiCycle = in.KpiCycle // 设置周期 | ||
185 | + if node.Type == domain.LinkNodeViewResult { | ||
186 | + if in.KpiResultStart != nil { | ||
187 | + node.TimeStart = in.KpiResultStart | ||
188 | + } | ||
189 | + } else { | ||
190 | + node.TimeStart = in.TimeStart | ||
191 | + node.TimeEnd = in.TimeEnd | ||
192 | + } | ||
190 | } | 193 | } |
191 | 194 | ||
192 | project, err = projectRepository.Insert(project) | 195 | project, err = projectRepository.Insert(project) |
@@ -290,7 +293,7 @@ func (rs *EvaluationProjectService) List(in *command.QueryProjectCommand) (inter | @@ -290,7 +293,7 @@ func (rs *EvaluationProjectService) List(in *command.QueryProjectCommand) (inter | ||
290 | return tool_funs.SimpleWrapGridMap(total, projectAdapters), nil | 293 | return tool_funs.SimpleWrapGridMap(total, projectAdapters), nil |
291 | } | 294 | } |
292 | 295 | ||
293 | -func (rs *EvaluationProjectService) State(in *command.StateProjectCommand) (interface{}, error) { | 296 | +func (rs *EvaluationProjectService) Activate(in *command.ActivateProjectCommand) (interface{}, error) { |
294 | transactionContext, err := factory.ValidateStartTransaction(in) | 297 | transactionContext, err := factory.ValidateStartTransaction(in) |
295 | if err != nil { | 298 | if err != nil { |
296 | return nil, err | 299 | return nil, err |
@@ -300,13 +303,20 @@ func (rs *EvaluationProjectService) State(in *command.StateProjectCommand) (inte | @@ -300,13 +303,20 @@ func (rs *EvaluationProjectService) State(in *command.StateProjectCommand) (inte | ||
300 | }() | 303 | }() |
301 | 304 | ||
302 | projectRepository := factory.CreateEvaluationProjectRepository(map[string]interface{}{"transactionContext": transactionContext}) | 305 | projectRepository := factory.CreateEvaluationProjectRepository(map[string]interface{}{"transactionContext": transactionContext}) |
303 | - | ||
304 | project, err := projectRepository.FindOne(map[string]interface{}{"id": in.Id}) | 306 | project, err := projectRepository.FindOne(map[string]interface{}{"id": in.Id}) |
305 | if err != nil { | 307 | if err != nil { |
306 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 308 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
307 | } | 309 | } |
308 | 310 | ||
309 | - project.State = in.State | 311 | + if project.Template == nil { |
312 | + return nil, application.ThrowError(application.BUSINESS_ERROR, "请添加评估模板") | ||
313 | + } | ||
314 | + | ||
315 | + if len(project.Recipients) == 0 { | ||
316 | + return nil, application.ThrowError(application.BUSINESS_ERROR, "请添加被评估人") | ||
317 | + } | ||
318 | + | ||
319 | + project.State = domain.TemplateStateEnable | ||
310 | project, err = projectRepository.Insert(project) | 320 | project, err = projectRepository.Insert(project) |
311 | if err != nil { | 321 | if err != nil { |
312 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 322 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
@@ -332,6 +342,10 @@ func (rs *EvaluationProjectService) Copy(in *command.CopyProjectCommand) (interf | @@ -332,6 +342,10 @@ func (rs *EvaluationProjectService) Copy(in *command.CopyProjectCommand) (interf | ||
332 | } | 342 | } |
333 | // ID重置 | 343 | // ID重置 |
334 | project.Id = 0 | 344 | project.Id = 0 |
345 | + project.Name = project.Name + " 副本" | ||
346 | + project.CreatorId = in.CreatorId | ||
347 | + project.Recipients = make([]string, 0) // 重置被评估人 | ||
348 | + | ||
335 | // 如果拷贝已经启用的模板,默认先设置为待启用 | 349 | // 如果拷贝已经启用的模板,默认先设置为待启用 |
336 | if project.State == domain.ProjectStateEnable { | 350 | if project.State == domain.ProjectStateEnable { |
337 | project.State = domain.ProjectStateWaitActive | 351 | project.State = domain.ProjectStateWaitActive |
@@ -346,7 +360,7 @@ func (rs *EvaluationProjectService) Copy(in *command.CopyProjectCommand) (interf | @@ -346,7 +360,7 @@ func (rs *EvaluationProjectService) Copy(in *command.CopyProjectCommand) (interf | ||
346 | return project, nil | 360 | return project, nil |
347 | } | 361 | } |
348 | 362 | ||
349 | -func (rs *EvaluationProjectService) StatisticCycleUser(in *command.StatisticCycleProjectUserCommand) (interface{}, error) { | 363 | +func (rs *EvaluationProjectService) CheckRecipients(in *command.CheckRecipientCommand) (interface{}, error) { |
350 | transactionContext, err := factory.ValidateStartTransaction(in) | 364 | transactionContext, err := factory.ValidateStartTransaction(in) |
351 | if err != nil { | 365 | if err != nil { |
352 | return nil, err | 366 | return nil, err |
@@ -354,42 +368,41 @@ func (rs *EvaluationProjectService) StatisticCycleUser(in *command.StatisticCycl | @@ -354,42 +368,41 @@ func (rs *EvaluationProjectService) StatisticCycleUser(in *command.StatisticCycl | ||
354 | defer func() { | 368 | defer func() { |
355 | transactionContext.RollbackTransaction() | 369 | transactionContext.RollbackTransaction() |
356 | }() | 370 | }() |
371 | + | ||
357 | projectRepository := factory.CreateEvaluationProjectRepository(map[string]interface{}{"transactionContext": transactionContext}) | 372 | projectRepository := factory.CreateEvaluationProjectRepository(map[string]interface{}{"transactionContext": transactionContext}) |
358 | - _, projects, err := projectRepository.Find(tool_funs.SimpleStructToMap(in), "linkNodes") | 373 | + |
374 | + _, projects, err := projectRepository.Find(map[string]interface{}{"companyId": in.CompanyId, "cycleId": in.CycleId}, "linkNodes") | ||
359 | if err != nil { | 375 | if err != nil { |
360 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 376 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
361 | } | 377 | } |
362 | 378 | ||
363 | - userIds := make([]int64, 0) | ||
364 | - userIdMap := map[int64]int64{} | 379 | + // 周期内的所有项目,员工不能重复被评估 |
380 | + rids := map[string]bool{} | ||
365 | for i := range projects { | 381 | for i := range projects { |
366 | - project := projects[i] | ||
367 | - for j := range project.Recipients { | ||
368 | - userId, _ := strconv.ParseInt(project.Recipients[j], 10, 64) | ||
369 | - userIdMap[userId] = userId | 382 | + // 排除当前项目 |
383 | + if in.Id != projects[i].Id { | ||
384 | + ids := projects[i].Recipients | ||
385 | + for j := range ids { | ||
386 | + rids[ids[j]] = true | ||
387 | + } | ||
370 | } | 388 | } |
371 | } | 389 | } |
372 | - for _, v := range userIdMap { | ||
373 | - userIds = append(userIds, v) | ||
374 | - } | ||
375 | - | ||
376 | - userTotal := 0 | ||
377 | - departmentTotal := 0 | ||
378 | - if len(userIds) > 0 { | ||
379 | - userRepository := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext}) | ||
380 | - _, users, _ := userRepository.Find(map[string]interface{}{"ids": userIds, "limit": len(userIds)}) | ||
381 | - departmentIdMap := map[int]int{} | ||
382 | - for i := range users { | ||
383 | - for _, v := range users[i].DepartmentId { | ||
384 | - departmentIdMap[v] = v | ||
385 | - } | 390 | + repeatNum := 0 |
391 | + for i := range in.Recipients { | ||
392 | + id := in.Recipients[i] | ||
393 | + if _, ok := rids[id]; ok { | ||
394 | + repeatNum++ | ||
386 | } | 395 | } |
387 | - userTotal = len(users) | ||
388 | - departmentTotal = len(departmentIdMap) | ||
389 | } | 396 | } |
397 | + //if repeatNum > 0 { | ||
398 | + // return nil, application.ThrowError(application.BUSINESS_ERROR, fmt.Sprintf("有%d人已经在本周期其他项目内,需要将他们移除", repeatNum)) | ||
399 | + //} | ||
390 | 400 | ||
401 | + if err != nil { | ||
402 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
403 | + } | ||
391 | if err := transactionContext.CommitTransaction(); err != nil { | 404 | if err := transactionContext.CommitTransaction(); err != nil { |
392 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 405 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
393 | } | 406 | } |
394 | - return map[string]interface{}{"userTotal": userTotal, "departmentTotal": departmentTotal}, nil | 407 | + return repeatNum, nil |
395 | } | 408 | } |
@@ -72,7 +72,18 @@ func (controller *CycleController) ListCycle() { | @@ -72,7 +72,18 @@ func (controller *CycleController) ListCycle() { | ||
72 | } | 72 | } |
73 | ua := middlewares.GetUser(controller.Ctx) | 73 | ua := middlewares.GetUser(controller.Ctx) |
74 | in.CompanyId = ua.CompanyId | 74 | in.CompanyId = ua.CompanyId |
75 | - //in.CompanyId = middlewares.GetCompanyId(controller.Ctx) | ||
76 | controller.Response(ruService.List(in)) | 75 | controller.Response(ruService.List(in)) |
77 | } | 76 | } |
78 | } | 77 | } |
78 | + | ||
79 | +func (controller *CycleController) StatisticCycleUser() { | ||
80 | + ruService := service.NewEvaluationCycleService() | ||
81 | + in := &command.StatisticCycleProjectUserCommand{} | ||
82 | + if err := controller.Unmarshal(in); err != nil { | ||
83 | + controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error())) | ||
84 | + } else { | ||
85 | + ua := middlewares.GetUser(controller.Ctx) | ||
86 | + in.CompanyId = ua.CompanyId | ||
87 | + controller.Response(ruService.StatisticCycleUser(in)) | ||
88 | + } | ||
89 | +} |
@@ -53,19 +53,6 @@ func (controller *ProjectController) UpdateProjectForTemplate() { | @@ -53,19 +53,6 @@ func (controller *ProjectController) UpdateProjectForTemplate() { | ||
53 | } | 53 | } |
54 | } | 54 | } |
55 | 55 | ||
56 | -func (controller *ProjectController) UpdateProjectForTemplateNode() { | ||
57 | - ruService := service.NewEvaluationProjectService() | ||
58 | - in := &command.UpdateProjectTemplateNodeCommand{} | ||
59 | - if err := controller.Unmarshal(in); err != nil { | ||
60 | - controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error())) | ||
61 | - } else { | ||
62 | - ua := middlewares.GetUser(controller.Ctx) | ||
63 | - in.CompanyId = ua.CompanyId | ||
64 | - //in.CompanyId = middlewares.GetCompanyId(controller.Ctx) | ||
65 | - controller.Response(ruService.UpdateTemplateNode(in)) | ||
66 | - } | ||
67 | -} | ||
68 | - | ||
69 | func (controller *ProjectController) GetProject() { | 56 | func (controller *ProjectController) GetProject() { |
70 | ruService := service.NewEvaluationProjectService() | 57 | ruService := service.NewEvaluationProjectService() |
71 | in := &command.GetProjectCommand{} | 58 | in := &command.GetProjectCommand{} |
@@ -106,11 +93,11 @@ func (controller *ProjectController) ListProject() { | @@ -106,11 +93,11 @@ func (controller *ProjectController) ListProject() { | ||
106 | 93 | ||
107 | func (controller *ProjectController) StateProject() { | 94 | func (controller *ProjectController) StateProject() { |
108 | ruService := service.NewEvaluationProjectService() | 95 | ruService := service.NewEvaluationProjectService() |
109 | - in := &command.StateProjectCommand{} | 96 | + in := &command.ActivateProjectCommand{} |
110 | if err := controller.Unmarshal(in); err != nil { | 97 | if err := controller.Unmarshal(in); err != nil { |
111 | controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error())) | 98 | controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error())) |
112 | } else { | 99 | } else { |
113 | - controller.Response(ruService.State(in)) | 100 | + controller.Response(ruService.Activate(in)) |
114 | } | 101 | } |
115 | } | 102 | } |
116 | 103 | ||
@@ -120,19 +107,20 @@ func (controller *ProjectController) CopyProject() { | @@ -120,19 +107,20 @@ func (controller *ProjectController) CopyProject() { | ||
120 | if err := controller.Unmarshal(in); err != nil { | 107 | if err := controller.Unmarshal(in); err != nil { |
121 | controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error())) | 108 | controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error())) |
122 | } else { | 109 | } else { |
110 | + ua := middlewares.GetUser(controller.Ctx) | ||
111 | + in.CreatorId = ua.UserId | ||
123 | controller.Response(ruService.Copy(in)) | 112 | controller.Response(ruService.Copy(in)) |
124 | } | 113 | } |
125 | } | 114 | } |
126 | 115 | ||
127 | -func (controller *ProjectController) StatisticCycleUser() { | 116 | +func (controller *ProjectController) CheckRecipients() { |
128 | ruService := service.NewEvaluationProjectService() | 117 | ruService := service.NewEvaluationProjectService() |
129 | - in := &command.StatisticCycleProjectUserCommand{} | 118 | + in := &command.CheckRecipientCommand{} |
130 | if err := controller.Unmarshal(in); err != nil { | 119 | if err := controller.Unmarshal(in); err != nil { |
131 | controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error())) | 120 | controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error())) |
132 | } else { | 121 | } else { |
133 | ua := middlewares.GetUser(controller.Ctx) | 122 | ua := middlewares.GetUser(controller.Ctx) |
134 | in.CompanyId = ua.CompanyId | 123 | in.CompanyId = ua.CompanyId |
135 | - //in.CompanyId = middlewares.GetCompanyId(controller.Ctx) | ||
136 | - controller.Response(ruService.StatisticCycleUser(in)) | 124 | + controller.Response(ruService.CheckRecipients(in)) |
137 | } | 125 | } |
138 | } | 126 | } |
@@ -15,6 +15,7 @@ func init() { | @@ -15,6 +15,7 @@ func init() { | ||
15 | web.NSRouter("/", &controllers.CycleController{}, "Delete:RemoveCycle"), | 15 | web.NSRouter("/", &controllers.CycleController{}, "Delete:RemoveCycle"), |
16 | web.NSRouter("/:Id", &controllers.CycleController{}, "Get:GetCycle"), | 16 | web.NSRouter("/:Id", &controllers.CycleController{}, "Get:GetCycle"), |
17 | web.NSRouter("/list", &controllers.CycleController{}, "Post:ListCycle"), | 17 | web.NSRouter("/list", &controllers.CycleController{}, "Post:ListCycle"), |
18 | + web.NSRouter("/statistic", &controllers.CycleController{}, "Post:StatisticCycleUser"), | ||
18 | ) | 19 | ) |
19 | web.AddNamespace(ns) | 20 | web.AddNamespace(ns) |
20 | } | 21 | } |
1 | +package routers | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/beego/beego/v2/server/web" | ||
5 | + "github.com/linmadan/egglib-go/web/beego/filters" | ||
6 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego/controllers" | ||
7 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego/middlewares" | ||
8 | +) | ||
9 | + | ||
10 | +func init() { | ||
11 | + ns := web.NewNamespace("/v1/evaluation-project", | ||
12 | + web.NSBefore(filters.AllowCors(), middlewares.CheckAdminToken()), | ||
13 | + web.NSRouter("/", &controllers.ProjectController{}, "Post:CreateProject"), | ||
14 | + web.NSRouter("/", &controllers.ProjectController{}, "Put:UpdateProject"), | ||
15 | + web.NSRouter("/", &controllers.ProjectController{}, "Delete:RemoveProject"), | ||
16 | + web.NSRouter("/:Id", &controllers.ProjectController{}, "Get:GetProject"), | ||
17 | + web.NSRouter("/list", &controllers.ProjectController{}, "Post:ListProject"), | ||
18 | + web.NSRouter("/detail", &controllers.ProjectController{}, "Put:UpdateProjectForTemplate"), | ||
19 | + web.NSRouter("/check-recipients", &controllers.ProjectController{}, "Post:CheckRecipients"), | ||
20 | + web.NSRouter("/copy", &controllers.ProjectController{}, "Post:CopyProject"), | ||
21 | + ) | ||
22 | + web.AddNamespace(ns) | ||
23 | +} |
-
请 注册 或 登录 后发表评论