project_adapter.go
1.6 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
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:"被评估人"`
PmpList []*UserAdapter `json:"pmpList" comment:"项目管理员"`
}
func (adapter *EvaluationProjectAdapter) TransformRecipientAdapter(recipients []*domain.User) {
for i := range recipients {
adapter.RecipientList = append(adapter.RecipientList, &UserAdapter{
Id: recipients[i].Id,
Name: recipients[i].Name,
})
}
}
func (adapter *EvaluationProjectAdapter) TransformPmpAdapter(pms []*domain.User) {
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
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
}