project_adapter.go
2.1 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
package adapter
import (
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
"strconv"
)
type UserAdapter struct {
Id int64 `json:"id,string" comment:"用户Id"`
Name string `json:"name" comment:"用户名称"`
}
type EvaluationProjectAdapter struct {
*domain.EvaluationProject
RecipientList []*UserAdapter `json:"recipientList" comment:"被评估人"`
Principal *UserAdapter `json:"principal" comment:"任务负责人"`
PmpList []*UserAdapter `json:"pmpList" comment:"项目管理员"`
}
func (adapter *EvaluationProjectAdapter) TransformRecipientAdapter(recipients []*domain.User, principalId string) {
// 任务负责人ID
var principalIdInt = int64(0)
if len(principalId) > 0 {
i, err := strconv.ParseInt(principalId, 10, 64)
if err == nil {
principalIdInt = i
}
}
adapter.RecipientList = make([]*UserAdapter, 0)
for i := range recipients {
ua := &UserAdapter{
Id: recipients[i].Id,
Name: recipients[i].Name,
}
adapter.RecipientList = append(adapter.RecipientList, ua)
if ua.Id == principalIdInt {
adapter.Principal = ua
}
}
}
func (adapter *EvaluationProjectAdapter) TransformPmpAdapter(pms []*domain.User) {
adapter.PmpList = make([]*UserAdapter, 0)
for i := range pms {
adapter.PmpList = append(adapter.PmpList, &UserAdapter{
Id: pms[i].Id,
Name: pms[i].Name,
})
}
}
func TransformProjectListAdapter(projects []*domain.EvaluationProject, users []*domain.User) []*EvaluationProjectAdapter {
pmpUserMap := map[int64]*domain.User{}
for i := range users {
pmpUserMap[users[i].Id] = users[i]
}
projectAdapters := make([]*EvaluationProjectAdapter, 0)
for i := range projects {
project := projects[i]
epa := &EvaluationProjectAdapter{}
epa.EvaluationProject = project
epa.PmpList = make([]*UserAdapter, 0)
projectAdapters = append(projectAdapters, epa)
for j := range project.PmpIds {
userId, _ := strconv.ParseInt(project.PmpIds[j], 10, 64)
if v, ok := pmpUserMap[userId]; ok {
epa.PmpList = append(epa.PmpList, &UserAdapter{
Id: v.Id,
Name: v.Name,
})
}
}
}
return projectAdapters
}