user_translator.go
5.8 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
package translator
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
"time"
)
type UserTranslator struct {
}
type UserDetail struct {
UserId int64 `json:"userId"`
UserBaseId int64 `json:"userBaseId"`
UserType int32 `json:"userType"`
UserCode string `json:"userCode"`
EnableStatus int32 `json:"enableStatus"`
CooperationInfo struct {
CooperationCompany string `json:"cooperationCompany"`
CooperationDeadline time.Time `json:"cooperationDeadline"`
} `json:"cooperationInfo,omitempty"`
UserInfo struct {
Phone string `json:"phone"`
UserCode string `json:"userCode"`
Email string `json:"email"`
UserName string `json:"userName"`
Avatar string `json:"avatar"`
} `json:"userInfo,omitempty"`
Company *struct {
CompanyId int64 `json:"companyId"`
CompanyName string `json:"companyName"`
Scale string `json:"scale"`
IndustryCategory string `json:"industryCategory"`
RegisteredTime time.Time `json:"registeredTime"`
Status int64 `json:"status"`
} `json:"company,omitempty"`
Org *struct {
OrgId int64 `json:"orgId"`
OrgCode string `json:"orgCode"`
OrgName string `json:"orgName"`
} `json:"org,omitempty"`
Department *struct {
DepartmentId int64 `json:"departmentId"`
DepartmentName string `json:"departmentName"`
} `json:"department,omitempty"`
UserRole []struct {
RoleID int64 `json:"roleId"`
RoleName string `json:"roleName"`
Ext struct {
OrgName string `json:"orgName"`
} `json:"ext,omitempty"`
} `json:"userRole"`
UserOrg []struct {
OrgID int64 `json:"orgId"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
DeletedAt time.Time `json:"deletedAt"`
OrgName string `json:"orgName"`
} `json:"userOrg"`
}
func (translator *UserTranslator) ToRelevantFromRepresentation(user *UserDetail) (*domain.Relevant, error) {
var orgs []*domain.Org
for _, org := range user.UserOrg {
orgs = append(orgs, &domain.Org{
OrgId: org.OrgID,
OrgName: org.OrgName,
Company: &domain.Company{
CompanyId: user.Company.CompanyId,
CompanyLogo: "",
CompanyName: user.Company.CompanyName,
},
})
}
var roles []*domain.Role
for _, role := range user.UserRole {
roles = append(roles, &domain.Role{
RoleId: int64(role.RoleID),
RoleName: role.RoleName,
})
}
return &domain.Relevant{
UserId: user.UserId,
UserBaseId: user.UserBaseId,
Org: &domain.Org{
OrgId: user.Org.OrgId,
OrgName: user.Org.OrgName,
Company: &domain.Company{
CompanyId: user.Company.CompanyId,
CompanyLogo: "",
CompanyName: user.Company.CompanyName,
},
},
Orgs: orgs,
Department: &domain.Department{
DepartmentId: user.Department.DepartmentId,
DepartmentName: user.Department.DepartmentName,
DepartmentNumber: "",
IsOrganization: false,
},
Roles: roles,
UserInfo: &domain.UserInfo{
UserAvatar: user.UserInfo.Avatar,
UserEmail: user.UserInfo.Email,
UserName: user.UserInfo.UserName,
UserPhone: user.UserInfo.Phone,
UserAccount: "",
},
UserType: user.UserType,
UserName: user.UserInfo.UserName,
UserPhone: user.UserInfo.Phone,
Status: user.EnableStatus,
Company: &domain.Company{
CompanyId: user.Company.CompanyId,
CompanyLogo: "",
CompanyName: user.Company.CompanyName,
},
}, nil
}
func (translator *UserTranslator) ToReferrerFromRepresentation(user *UserDetail) (*domain.Referrer, error) {
return &domain.Referrer{
UserId: user.UserId,
UserBaseId: user.UserBaseId,
Roles: nil,
Orgs: nil,
Org: nil,
Department: nil,
Company: nil,
UserInfo: nil,
UserType: 0,
UserName: user.UserInfo.UserName,
UserPhone: user.UserInfo.Phone,
}, nil
}
func (translator *UserTranslator) ToUndertakerFromRepresentation(user *UserDetail) (*domain.Undertaker, error) {
return &domain.Undertaker{
UserId: user.UserId,
UserBaseId: user.UserBaseId,
Org: nil,
Orgs: nil,
Department: nil,
Roles: nil,
UserInfo: nil,
UserType: 0,
UserName: user.UserInfo.UserName,
UserPhone: user.UserInfo.Phone,
Status: 0,
Company: nil,
ContractAttachment: nil,
}, nil
}
func (translator *UserTranslator) ToSalesmanFromRepresentation(user *UserDetail) (*domain.Salesman, error) {
return &domain.Salesman{
UserId: user.UserId,
UserBaseId: user.UserBaseId,
Roles: nil,
Orgs: nil,
Org: nil,
Department: nil,
Company: nil,
UserInfo: nil,
UserType: 0,
UserName: user.UserInfo.UserName,
UserPhone: user.UserInfo.Phone,
}, nil
}
func (translator *UserTranslator) ToOperatorFromRepresentation(user *UserDetail) (*domain.User, error) {
return &domain.User{
UserId: user.UserId,
UserBaseId: user.UserBaseId,
Org: nil,
Orgs: nil,
Department: nil,
Roles: nil,
UserInfo: &domain.UserInfo{
UserName: user.UserInfo.UserName,
UserPhone: user.UserInfo.Phone,
UserAvatar: user.UserInfo.Avatar,
},
UserType: 0,
UserName: user.UserInfo.UserName,
UserPhone: user.UserInfo.Phone,
Status: 0,
Company: nil,
}, nil
}
func (translator *UserTranslator) ToUserFromRepresentation(user *UserDetail) (*domain.User, error) {
return &domain.User{
UserId: user.UserId,
UserBaseId: user.UserBaseId,
Org: nil,
Orgs: nil,
Department: nil,
Roles: nil,
UserInfo: &domain.UserInfo{
UserName: user.UserInfo.UserName,
UserPhone: user.UserInfo.Phone,
UserAvatar: user.UserInfo.Avatar,
},
UserType: 0,
UserName: user.UserInfo.UserName,
UserPhone: user.UserInfo.Phone,
Status: 0,
Company: nil,
}, nil
}
func NewUserTranslator() (*UserTranslator, error) {
return &UserTranslator{}, nil
}