rest_user_service.go
5.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
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
package domain_service
import (
"encoding/json"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/service_gateway/adaptor"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/log"
)
type UserService struct {
}
// UserFrom 获取普通用户
func (service *UserService) UserFrom(companyId int64, orgId int64, userId int64) (*domain.User, error) {
var returnData *domain.User
if userAdaptor, err := adaptor.NewUserAdaptor(); err != nil {
return nil, err
} else {
if user, err := userAdaptor.ToParticipator(companyId, orgId, userId, "User"); err != nil {
return nil, err
} else {
if user != nil {
log.Logger.Debug("普通用户", map[string]interface{}{
"user interface": user,
})
userJson, err1 := json.Marshal(user)
if err1 != nil {
return nil, err
}
err2 := json.Unmarshal(userJson, &returnData)
if err2 != nil {
return nil, err2
}
}
return returnData, nil
}
}
}
// ReferrerFrom 获取推荐人
func (service *UserService) ReferrerFrom(companyId int64, orgId int64, userId int64) (*domain.Referrer, error) {
var returnData *domain.Referrer
if userAdaptor, err := adaptor.NewUserAdaptor(); err != nil {
return nil, err
} else {
if referrer, err := userAdaptor.ToParticipator(companyId, orgId, userId, "Referrer"); err != nil {
return nil, err
} else {
if referrer != nil {
log.Logger.Debug("推荐人", map[string]interface{}{
"referrer interface": referrer,
})
referrerJson, err1 := json.Marshal(referrer)
if err1 != nil {
return nil, err
}
err2 := json.Unmarshal(referrerJson, &returnData)
if err2 != nil {
return nil, err2
}
}
return returnData, nil
}
}
}
// UndertakerFrom 获取承接人
func (service *UserService) UndertakerFrom(companyId int64, orgId int64, userId int64) (*domain.Undertaker, error) {
var returnData *domain.Undertaker
if userAdaptor, err := adaptor.NewUserAdaptor(); err != nil {
return nil, err
} else {
if undertaker, err := userAdaptor.ToParticipator(companyId, orgId, userId, "Undertaker"); err != nil {
return nil, err
} else {
if undertaker != nil {
log.Logger.Debug("承接人", map[string]interface{}{
"undertaker interface": undertaker,
})
undertakerJson, err1 := json.Marshal(undertaker)
if err1 != nil {
return nil, err
}
err2 := json.Unmarshal(undertakerJson, &returnData)
if err2 != nil {
return nil, err2
}
}
return returnData, nil
}
}
}
// RelevantFrom 获取相关人
func (service *UserService) RelevantFrom(companyId int64, orgId int64, userId int64) (*domain.Relevant, error) {
var returnData *domain.Relevant
if userAdaptor, err := adaptor.NewUserAdaptor(); err != nil {
return nil, err
} else {
if relevant, err := userAdaptor.ToParticipator(companyId, orgId, userId, "Relevant"); err != nil {
return nil, err
} else {
if relevant != nil {
log.Logger.Debug("相关人", map[string]interface{}{
"relevant interface": relevant,
})
relevantJson, err1 := json.Marshal(relevant)
if err1 != nil {
return nil, err
}
err2 := json.Unmarshal(relevantJson, &returnData)
if err2 != nil {
return nil, err2
}
}
return returnData, nil
}
}
}
// SalesmanFrom 获取业务员
func (service *UserService) SalesmanFrom(companyId int64, orgId int64, userId int64) (*domain.Salesman, error) {
var returnData *domain.Salesman
if userAdaptor, err := adaptor.NewUserAdaptor(); err != nil {
return nil, err
} else {
if salesman, err := userAdaptor.ToParticipator(companyId, orgId, userId, "Salesman"); err != nil {
return nil, err
} else {
if salesman != nil {
log.Logger.Debug("业务员", map[string]interface{}{
"salesman interface": salesman,
})
salesmanJson, err1 := json.Marshal(salesman)
if err1 != nil {
return nil, err
}
err2 := json.Unmarshal(salesmanJson, &returnData)
if err2 != nil {
return nil, err2
}
}
return returnData, nil
}
}
}
// OperatorFrom 获取操作人
func (service *UserService) OperatorFrom(companyId int64, orgId int64, userId int64) (*domain.User, error) {
var returnData *domain.User
if userAdaptor, err := adaptor.NewUserAdaptor(); err != nil {
return nil, err
} else {
if operator, err := userAdaptor.ToParticipator(companyId, orgId, userId, "Operator"); err != nil {
return nil, err
} else {
if operator != nil {
log.Logger.Debug("操作人", map[string]interface{}{
"operator interface": operator,
})
operatorJson, err1 := json.Marshal(operator)
if err1 != nil {
return nil, err
}
err2 := json.Unmarshal(operatorJson, &returnData)
if err2 != nil {
return nil, err2
}
}
return returnData, nil
}
}
}
// VisitorFrom 获取游客
func (service *UserService) VisitorFrom(companyId int64, orgId int64, userBaseId int64) (*domain.User, error) {
var returnData *domain.User
if userAdaptor, err := adaptor.NewUserAdaptor(); err != nil {
return nil, err
} else {
if visitor, err := userAdaptor.ToVisitor(companyId, orgId, userBaseId); err != nil {
return nil, err
} else {
if visitor != nil {
log.Logger.Debug("游客", map[string]interface{}{
"visitor interface": visitor,
})
visitorJson, err1 := json.Marshal(visitor)
if err1 != nil {
return nil, err
}
err2 := json.Unmarshal(visitorJson, &returnData)
if err2 != nil {
return nil, err2
}
}
return returnData, nil
}
}
}
func NewUserService() (*UserService, error) {
return &UserService{}, nil
}