user_adaptor.go
2.2 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
package adaptor
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/service_gateway"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/service_gateway/translator"
)
type UserAdaptor struct {
}
func (adaptor *UserAdaptor) ToParticipator(companyId int64, orgId int64, userId int64, aRoleName string) (interface{}, error) {
userServiceGateway := service_gateway.NewHttplibUserServiceGateway()
response, err := userServiceGateway.GetUser(companyId, orgId, userId)
if err != nil {
return map[string]interface{}{}, err
}
if userTranslator, err := translator.NewUserTranslator(); err != nil {
return map[string]interface{}{}, err
} else {
switch aRoleName {
case "Relevant": // 相关人
relevant, err := userTranslator.ToRelevantFromRepresentation(response)
if err != nil {
return map[string]interface{}{}, err
}
return relevant, nil
case "Referrer": // 推荐人
referrer, err := userTranslator.ToReferrerFromRepresentation(response)
if err != nil {
return map[string]interface{}{}, err
}
return referrer, nil
case "Salesman": // 业务员
salesman, err := userTranslator.ToSalesmanFromRepresentation(response)
if err != nil {
return map[string]interface{}{}, nil
}
return salesman, nil
case "Undertaker": // 承接人
undertaker, err := userTranslator.ToUndertakerFromRepresentation(response)
if err != nil {
return map[string]interface{}{}, nil
}
return undertaker, nil
case "Operator": // 操作人
operator, err := userTranslator.ToOperatorFromRepresentation(response)
if err != nil {
return map[string]interface{}{}, nil
}
return operator, nil
case "User": // 用户
user, err := userTranslator.ToUserFromRepresentation(response)
if err != nil {
return map[string]interface{}{}, nil
}
return user, nil
case "Visitor": // 游客
visitor, err := userTranslator.ToVisitorFromRepresentation(response)
if err != nil {
return map[string]interface{}{}, nil
}
return visitor, nil
}
}
return map[string]interface{}{}, nil
}
func NewUserAdaptor() (*UserAdaptor, error) {
return &UserAdaptor{}, nil
}