正在显示
5 个修改的文件
包含
170 行增加
和
48 行删除
1 | package factory | 1 | package factory |
2 | + | ||
3 | +import ( | ||
4 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain/service" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/domain_service" | ||
6 | +) | ||
7 | + | ||
8 | +func CreateUserService(options map[string]interface{}) (service.UserService, error) { | ||
9 | + return domain_service.NewUserService() | ||
10 | +} |
1 | package domain_service | 1 | package domain_service |
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | + "encoding/json" | ||
4 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain" | 5 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain" |
6 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/service_gateway/adaptor" | ||
5 | ) | 7 | ) |
6 | 8 | ||
7 | type UserService struct { | 9 | type UserService struct { |
8 | } | 10 | } |
9 | 11 | ||
12 | +// ReferrerFrom 获取推荐人 | ||
10 | func (service *UserService) ReferrerFrom(companyId int64, orgId int64, userId int64) (*domain.Referrer, error) { | 13 | func (service *UserService) ReferrerFrom(companyId int64, orgId int64, userId int64) (*domain.Referrer, error) { |
11 | - return nil, nil | 14 | + var returnData *domain.Referrer |
15 | + if userAdaptor, err := adaptor.NewUserAdaptor(); err != nil { | ||
16 | + return nil, err | ||
17 | + } else { | ||
18 | + if referrer, err := userAdaptor.ToParticipator(companyId, orgId, userId, "Referrer"); err != nil { | ||
19 | + return nil, err | ||
20 | + } else { | ||
21 | + err := json.Unmarshal(referrer.([]byte), returnData) | ||
22 | + if err != nil { | ||
23 | + return nil, err | ||
24 | + } | ||
25 | + return returnData, nil | ||
26 | + } | ||
27 | + } | ||
12 | } | 28 | } |
13 | 29 | ||
30 | +// UndertakerFrom 获取承接人 | ||
14 | func (service *UserService) UndertakerFrom(companyId int64, orgId int64, userId int64) (*domain.Undertaker, error) { | 31 | func (service *UserService) UndertakerFrom(companyId int64, orgId int64, userId int64) (*domain.Undertaker, error) { |
15 | - return nil, nil | 32 | + var returnData *domain.Undertaker |
33 | + if userAdaptor, err := adaptor.NewUserAdaptor(); err != nil { | ||
34 | + return nil, err | ||
35 | + } else { | ||
36 | + if referrer, err := userAdaptor.ToParticipator(companyId, orgId, userId, "Undertaker"); err != nil { | ||
37 | + return nil, err | ||
38 | + } else { | ||
39 | + err := json.Unmarshal(referrer.([]byte), returnData) | ||
40 | + if err != nil { | ||
41 | + return nil, err | ||
42 | + } | ||
43 | + return returnData, nil | ||
44 | + } | ||
45 | + } | ||
16 | } | 46 | } |
17 | 47 | ||
48 | +// RelevantFrom 获取相关人 | ||
18 | func (service *UserService) RelevantFrom(companyId int64, orgId int64, userId int64) (*domain.Relevant, error) { | 49 | func (service *UserService) RelevantFrom(companyId int64, orgId int64, userId int64) (*domain.Relevant, error) { |
19 | - return nil, nil | 50 | + var returnData *domain.Relevant |
51 | + if userAdaptor, err := adaptor.NewUserAdaptor(); err != nil { | ||
52 | + return nil, err | ||
53 | + } else { | ||
54 | + if referrer, err := userAdaptor.ToParticipator(companyId, orgId, userId, "Relevant"); err != nil { | ||
55 | + return nil, err | ||
56 | + } else { | ||
57 | + err := json.Unmarshal(referrer.([]byte), returnData) | ||
58 | + if err != nil { | ||
59 | + return nil, err | ||
60 | + } | ||
61 | + return returnData, nil | ||
62 | + } | ||
63 | + } | ||
20 | } | 64 | } |
21 | 65 | ||
66 | +// SalesmanFrom 获取业务员 | ||
22 | func (service *UserService) SalesmanFrom(companyId int64, orgId int64, userId int64) (*domain.Salesman, error) { | 67 | func (service *UserService) SalesmanFrom(companyId int64, orgId int64, userId int64) (*domain.Salesman, error) { |
23 | - return nil, nil | 68 | + var returnData *domain.Salesman |
69 | + if userAdaptor, err := adaptor.NewUserAdaptor(); err != nil { | ||
70 | + return nil, err | ||
71 | + } else { | ||
72 | + if referrer, err := userAdaptor.ToParticipator(companyId, orgId, userId, "Salesman"); err != nil { | ||
73 | + return nil, err | ||
74 | + } else { | ||
75 | + err := json.Unmarshal(referrer.([]byte), returnData) | ||
76 | + if err != nil { | ||
77 | + return nil, err | ||
78 | + } | ||
79 | + return returnData, nil | ||
80 | + } | ||
81 | + } | ||
24 | } | 82 | } |
25 | 83 | ||
84 | +// OperatorFrom 获取操作人 | ||
26 | func (service *UserService) OperatorFrom(companyId int64, orgId int64, userId int64) (*domain.User, error) { | 85 | func (service *UserService) OperatorFrom(companyId int64, orgId int64, userId int64) (*domain.User, error) { |
27 | - return nil, nil | 86 | + var returnData *domain.User |
87 | + if userAdaptor, err := adaptor.NewUserAdaptor(); err != nil { | ||
88 | + return nil, err | ||
89 | + } else { | ||
90 | + if referrer, err := userAdaptor.ToParticipator(companyId, orgId, userId, "Operator"); err != nil { | ||
91 | + return nil, err | ||
92 | + } else { | ||
93 | + err := json.Unmarshal(referrer.([]byte), returnData) | ||
94 | + if err != nil { | ||
95 | + return nil, err | ||
96 | + } | ||
97 | + return returnData, nil | ||
98 | + } | ||
99 | + } | ||
28 | } | 100 | } |
29 | 101 | ||
30 | func (service *UserService) UserInMenu(companyId int64, orgId int64, userId int64, code string) (bool, error) { | 102 | func (service *UserService) UserInMenu(companyId int64, orgId int64, userId int64, code string) (bool, error) { |
@@ -11,42 +11,45 @@ type UserAdaptor struct { | @@ -11,42 +11,45 @@ type UserAdaptor struct { | ||
11 | func (adaptor *UserAdaptor) ToParticipator(companyId int64, orgId int64, userId int64, aRoleName string) (interface{}, error) { | 11 | func (adaptor *UserAdaptor) ToParticipator(companyId int64, orgId int64, userId int64, aRoleName string) (interface{}, error) { |
12 | userServiceGateway := service_gateway.NewHttplibUserServiceGateway() | 12 | userServiceGateway := service_gateway.NewHttplibUserServiceGateway() |
13 | response, err := userServiceGateway.GetUser(companyId, orgId, userId) | 13 | response, err := userServiceGateway.GetUser(companyId, orgId, userId) |
14 | - userTranslator := &translator.UserTranslator{} | ||
15 | if err != nil { | 14 | if err != nil { |
16 | - return struct{}{}, err | 15 | + return map[string]interface{}{}, err |
17 | } | 16 | } |
18 | - if response["code"] == 200 { | ||
19 | - switch aRoleName { | ||
20 | - case "Relevant": | ||
21 | - relevant, err := userTranslator.ToRelevantFromRepresentation(response) | ||
22 | - if err != nil { | ||
23 | - return struct{}{}, err | 17 | + if userTranslator, err := translator.NewUserTranslator(); err != nil { |
18 | + return map[string]interface{}{}, err | ||
19 | + } else { | ||
20 | + if response["code"] == 200 { | ||
21 | + switch aRoleName { | ||
22 | + case "Relevant": | ||
23 | + relevant, err := userTranslator.ToRelevantFromRepresentation(response) | ||
24 | + if err != nil { | ||
25 | + return map[string]interface{}{}, err | ||
26 | + } | ||
27 | + return relevant, nil | ||
28 | + case "Referrer": | ||
29 | + referrer, err := userTranslator.ToReferrerFromRepresentation(response) | ||
30 | + if err != nil { | ||
31 | + return struct{}{}, err | ||
32 | + } | ||
33 | + return referrer, nil | ||
34 | + case "Salesman": | ||
35 | + salesman, err := userTranslator.ToSalesmanFromRepresentation(response) | ||
36 | + if err != nil { | ||
37 | + return struct{}{}, nil | ||
38 | + } | ||
39 | + return salesman, nil | ||
40 | + case "Undertaker": | ||
41 | + undertaker, err := userTranslator.ToUndertakerFromRepresentation(response) | ||
42 | + if err != nil { | ||
43 | + return struct{}{}, nil | ||
44 | + } | ||
45 | + return undertaker, nil | ||
46 | + case "Operator": | ||
47 | + operator, err := userTranslator.ToOperatorFromRepresentation(response) | ||
48 | + if err != nil { | ||
49 | + return struct{}{}, nil | ||
50 | + } | ||
51 | + return operator, nil | ||
24 | } | 52 | } |
25 | - return relevant, nil | ||
26 | - case "Referrer": | ||
27 | - referrer, err := userTranslator.ToReferrerFromRepresentation(response) | ||
28 | - if err != nil { | ||
29 | - return struct{}{}, err | ||
30 | - } | ||
31 | - return referrer, nil | ||
32 | - case "Salesman": | ||
33 | - salesman, err := userTranslator.ToSalesmanFromRepresentation(response) | ||
34 | - if err != nil { | ||
35 | - return struct{}{}, nil | ||
36 | - } | ||
37 | - return salesman, nil | ||
38 | - case "Undertaker": | ||
39 | - undertaker, err := userTranslator.ToUndertakerFromRepresentation(response) | ||
40 | - if err != nil { | ||
41 | - return struct{}{}, nil | ||
42 | - } | ||
43 | - return undertaker, nil | ||
44 | - case "Operator": | ||
45 | - operator, err := userTranslator.ToOperatorFromRepresentation(response) | ||
46 | - if err != nil { | ||
47 | - return struct{}{}, nil | ||
48 | - } | ||
49 | - return operator, nil | ||
50 | } | 53 | } |
51 | } | 54 | } |
52 | return struct{}{}, nil | 55 | return struct{}{}, nil |
@@ -59,3 +62,7 @@ func (adaptor *UserAdaptor) UserInMenu() { | @@ -59,3 +62,7 @@ func (adaptor *UserAdaptor) UserInMenu() { | ||
59 | func (adaptor *UserAdaptor) UserInOrganization() { | 62 | func (adaptor *UserAdaptor) UserInOrganization() { |
60 | 63 | ||
61 | } | 64 | } |
65 | + | ||
66 | +func NewUserAdaptor() (*UserAdaptor, error) { | ||
67 | + return &UserAdaptor{}, nil | ||
68 | +} |
@@ -18,9 +18,15 @@ func (serviceGateway *HttplibUserServiceGateway) GetUser(companyId int64, orgId | @@ -18,9 +18,15 @@ func (serviceGateway *HttplibUserServiceGateway) GetUser(companyId int64, orgId | ||
18 | request := serviceGateway.createRequest(url, "get") | 18 | request := serviceGateway.createRequest(url, "get") |
19 | options := make(map[string]interface{}) | 19 | options := make(map[string]interface{}) |
20 | options["uid"] = uid | 20 | options["uid"] = uid |
21 | - request.JSONBody(options) | 21 | + _, err1 := request.JSONBody(options) |
22 | + if err1 != nil { | ||
23 | + return nil, err1 | ||
24 | + } | ||
22 | response := make(map[string]interface{}) | 25 | response := make(map[string]interface{}) |
23 | - request.ToJSON(&response) | 26 | + err2 := request.ToJSON(&response) |
27 | + if err2 != nil { | ||
28 | + return nil, err2 | ||
29 | + } | ||
24 | data, err := serviceGateway.responseHandle(response) | 30 | data, err := serviceGateway.responseHandle(response) |
25 | return data, err | 31 | return data, err |
26 | } | 32 | } |
@@ -32,9 +38,15 @@ func (serviceGateway *HttplibUserServiceGateway) GetCompany(companyId int64) (ma | @@ -32,9 +38,15 @@ func (serviceGateway *HttplibUserServiceGateway) GetCompany(companyId int64) (ma | ||
32 | request := serviceGateway.createRequest(url, "get") | 38 | request := serviceGateway.createRequest(url, "get") |
33 | options := make(map[string]interface{}) | 39 | options := make(map[string]interface{}) |
34 | options["companyId"] = companyId | 40 | options["companyId"] = companyId |
35 | - request.JSONBody(options) | 41 | + _, err1 := request.JSONBody(options) |
42 | + if err1 != nil { | ||
43 | + return nil, err1 | ||
44 | + } | ||
36 | response := make(map[string]interface{}) | 45 | response := make(map[string]interface{}) |
37 | - request.ToJSON(&response) | 46 | + err2 := request.ToJSON(&response) |
47 | + if err2 != nil { | ||
48 | + return nil, err2 | ||
49 | + } | ||
38 | data, err := serviceGateway.responseHandle(response) | 50 | data, err := serviceGateway.responseHandle(response) |
39 | return data, err | 51 | return data, err |
40 | } | 52 | } |
@@ -47,9 +59,15 @@ func (serviceGateway *HttplibUserServiceGateway) GetOrganization(companyId int64 | @@ -47,9 +59,15 @@ func (serviceGateway *HttplibUserServiceGateway) GetOrganization(companyId int64 | ||
47 | request := serviceGateway.createRequest(url, "get") | 59 | request := serviceGateway.createRequest(url, "get") |
48 | options := make(map[string]interface{}) | 60 | options := make(map[string]interface{}) |
49 | options["orgId"] = organizationId | 61 | options["orgId"] = organizationId |
50 | - request.JSONBody(options) | 62 | + _, err1 := request.JSONBody(options) |
63 | + if err1 != nil { | ||
64 | + return nil, err1 | ||
65 | + } | ||
51 | response := make(map[string]interface{}) | 66 | response := make(map[string]interface{}) |
52 | - request.ToJSON(&response) | 67 | + err2 := request.ToJSON(&response) |
68 | + if err2 != nil { | ||
69 | + return nil, err2 | ||
70 | + } | ||
53 | data, err := serviceGateway.responseHandle(response) | 71 | data, err := serviceGateway.responseHandle(response) |
54 | return data, err | 72 | return data, err |
55 | } | 73 | } |
@@ -60,9 +78,15 @@ func (serviceGateway *HttplibUserServiceGateway) UserInMenu(companyId int64, use | @@ -60,9 +78,15 @@ func (serviceGateway *HttplibUserServiceGateway) UserInMenu(companyId int64, use | ||
60 | request := serviceGateway.createRequest(url, "get") | 78 | request := serviceGateway.createRequest(url, "get") |
61 | options := make(map[string]interface{}) | 79 | options := make(map[string]interface{}) |
62 | options["code"] = menuCode | 80 | options["code"] = menuCode |
63 | - request.JSONBody(options) | 81 | + _, err1 := request.JSONBody(options) |
82 | + if err1 != nil { | ||
83 | + return nil, err1 | ||
84 | + } | ||
64 | response := make(map[string]interface{}) | 85 | response := make(map[string]interface{}) |
65 | - request.ToJSON(&response) | 86 | + err2 := request.ToJSON(&response) |
87 | + if err2 != nil { | ||
88 | + return nil, err2 | ||
89 | + } | ||
66 | data, err := serviceGateway.responseHandle(response) | 90 | data, err := serviceGateway.responseHandle(response) |
67 | return data, err | 91 | return data, err |
68 | } | 92 | } |
@@ -73,9 +97,15 @@ func (serviceGateway *HttplibUserServiceGateway) UserInOrganization(companyId in | @@ -73,9 +97,15 @@ func (serviceGateway *HttplibUserServiceGateway) UserInOrganization(companyId in | ||
73 | request := serviceGateway.createRequest(url, "get") | 97 | request := serviceGateway.createRequest(url, "get") |
74 | options := make(map[string]interface{}) | 98 | options := make(map[string]interface{}) |
75 | options["orgId"] = orgId | 99 | options["orgId"] = orgId |
76 | - request.JSONBody(options) | 100 | + _, err1 := request.JSONBody(options) |
101 | + if err1 != nil { | ||
102 | + return nil, err1 | ||
103 | + } | ||
77 | response := make(map[string]interface{}) | 104 | response := make(map[string]interface{}) |
78 | - request.ToJSON(&response) | 105 | + err2 := request.ToJSON(&response) |
106 | + if err2 != nil { | ||
107 | + return nil, err2 | ||
108 | + } | ||
79 | data, err := serviceGateway.responseHandle(response) | 109 | data, err := serviceGateway.responseHandle(response) |
80 | return data, err | 110 | return data, err |
81 | } | 111 | } |
@@ -78,3 +78,7 @@ func (translator *UserTranslator) ToOperatorFromRepresentation(data map[string]i | @@ -78,3 +78,7 @@ func (translator *UserTranslator) ToOperatorFromRepresentation(data map[string]i | ||
78 | Company: nil, | 78 | Company: nil, |
79 | }, nil | 79 | }, nil |
80 | } | 80 | } |
81 | + | ||
82 | +func NewUserTranslator() (*UserTranslator, error) { | ||
83 | + return &UserTranslator{}, nil | ||
84 | +} |
-
请 注册 或 登录 后发表评论