作者 陈志颖

feat:添加用户REST客户端adaptor和translator

1 package adaptor 1 package adaptor
2 2
  3 +import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
  4 +
3 type CompanyAdaptor struct { 5 type CompanyAdaptor struct {
4 } 6 }
5 7
6 -func (adaptor *CompanyAdaptor) ToCompany() {  
7 - 8 +func (adaptor *CompanyAdaptor) ToCompany(companyId int64) (*domain.Company, error) {
  9 + return nil, nil
8 } 10 }
1 package adaptor 1 package adaptor
2 2
  3 +import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
  4 +
3 type DepartmentAdaptor struct { 5 type DepartmentAdaptor struct {
4 } 6 }
5 7
6 -func (adaptor *DepartmentAdaptor) ToDepartment() {  
7 - 8 +func (adaptor *DepartmentAdaptor) ToDepartment(companyId int64, departmentId int64) (*domain.Department, error) {
  9 + return nil, nil
8 } 10 }
1 package adaptor 1 package adaptor
2 2
  3 +import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
  4 +
3 type OrganizationAdaptor struct { 5 type OrganizationAdaptor struct {
4 } 6 }
5 7
6 -func (adaptor *OrganizationAdaptor) ToOrganization() {  
7 - 8 +func (adaptor *OrganizationAdaptor) ToOrganization(companyId int64, orgId int64) (*domain.Org, error) {
  9 + return nil, nil
8 } 10 }
1 package adaptor 1 package adaptor
2 2
3 -type UserAdaptor struct {  
4 -}  
5 -  
6 -func (adaptor *UserAdaptor) ToRelevant() {  
7 -  
8 -}  
9 -  
10 -func (adaptor *UserAdaptor) ToReferrer() {  
11 -  
12 -}  
13 -  
14 -func (adaptor *UserAdaptor) ToSalesman() {  
15 -  
16 -}  
17 -  
18 -func (adaptor *UserAdaptor) ToUndertaker() { 3 +import (
  4 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/service_gateway"
  5 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/service_gateway/translator"
  6 +)
19 7
  8 +type UserAdaptor struct {
20 } 9 }
21 10
22 -func (adaptor *UserAdaptor) ToOperator() {  
23 - 11 +func (adaptor *UserAdaptor) ToParticipator(companyId int64, orgId int64, userId int64, aRoleName string) (interface{}, error) {
  12 + userServiceGateway := service_gateway.NewHttplibUserServiceGateway()
  13 + response, err := userServiceGateway.GetUser(companyId, orgId, userId)
  14 + userTranslator := &translator.UserTranslator{}
  15 + if err != nil {
  16 + return struct{}{}, err
  17 + }
  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
  24 + }
  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 + }
  51 + }
  52 + return struct{}{}, nil
24 } 53 }
25 54
26 func (adaptor *UserAdaptor) UserInMenu() { 55 func (adaptor *UserAdaptor) UserInMenu() {
@@ -12,7 +12,7 @@ type HttplibUserServiceGateway struct { @@ -12,7 +12,7 @@ type HttplibUserServiceGateway struct {
12 } 12 }
13 13
14 // GetUser 获取用户 14 // GetUser 获取用户
15 -func (serviceGateway *HttplibUserServiceGateway) GetUser(companyId int64, uid int64) (map[string]interface{}, error) { 15 +func (serviceGateway *HttplibUserServiceGateway) GetUser(companyId int64, orgId int64, uid int64) (map[string]interface{}, error) {
16 companyIdStr := strconv.FormatInt(companyId, 10) 16 companyIdStr := strconv.FormatInt(companyId, 10)
17 url := strings.Join([]string{serviceGateway.baseURL, "companies/" + companyIdStr + "/users/get-user"}, "/") 17 url := strings.Join([]string{serviceGateway.baseURL, "companies/" + companyIdStr + "/users/get-user"}, "/")
18 request := serviceGateway.createRequest(url, "get") 18 request := serviceGateway.createRequest(url, "get")
1 package service_gateway 1 package service_gateway
2 2
3 type UserServiceGateway interface { 3 type UserServiceGateway interface {
4 - GetUser(companyId int64, uid int64) (map[string]interface{}, error) 4 + GetUser(companyId int64, orgId int64, uid int64) (map[string]interface{}, error)
5 GetCompany(companyId int64) (map[string]interface{}, error) 5 GetCompany(companyId int64) (map[string]interface{}, error)
6 GetOrganization(companyId int64, organizationId int64) (map[string]interface{}, error) 6 GetOrganization(companyId int64, organizationId int64) (map[string]interface{}, error)
7 UserInMenu(companyId int64, userId int64, menuCode string) (map[string]interface{}, error) 7 UserInMenu(companyId int64, userId int64, menuCode string) (map[string]interface{}, error)
@@ -6,5 +6,8 @@ type CompanyTranslator struct { @@ -6,5 +6,8 @@ type CompanyTranslator struct {
6 } 6 }
7 7
8 func (translator *CompanyTranslator) ToCompanyFromRepresentation(data map[string]interface{}) (*domain.Company, error) { 8 func (translator *CompanyTranslator) ToCompanyFromRepresentation(data map[string]interface{}) (*domain.Company, error) {
9 - return &domain.Company{}, nil 9 + return &domain.Company{
  10 + CompanyId: 0,
  11 + CompanyName: "",
  12 + }, nil
10 } 13 }
@@ -6,5 +6,10 @@ type DepartmentTranslator struct { @@ -6,5 +6,10 @@ type DepartmentTranslator struct {
6 } 6 }
7 7
8 func (translator *DepartmentTranslator) ToDepartmentFromRepresentation(data map[string]interface{}) (*domain.Department, error) { 8 func (translator *DepartmentTranslator) ToDepartmentFromRepresentation(data map[string]interface{}) (*domain.Department, error) {
9 - return &domain.Department{}, nil 9 + return &domain.Department{
  10 + DepartmentId: 0,
  11 + DepartmentName: "",
  12 + DepartmentNumber: "",
  13 + IsOrganization: false,
  14 + }, nil
10 } 15 }
@@ -6,5 +6,9 @@ type OrganizationTranslator struct { @@ -6,5 +6,9 @@ type OrganizationTranslator struct {
6 } 6 }
7 7
8 func (translator *OrganizationTranslator) ToOrganizationFromRepresentation(data map[string]interface{}) (*domain.Org, error) { 8 func (translator *OrganizationTranslator) ToOrganizationFromRepresentation(data map[string]interface{}) (*domain.Org, error) {
9 - return &domain.Org{}, nil 9 + return &domain.Org{
  10 + OrgId: 0,
  11 + OrgName: "",
  12 + Company: nil,
  13 + }, nil
10 } 14 }
@@ -6,21 +6,75 @@ type UserTranslator struct { @@ -6,21 +6,75 @@ type UserTranslator struct {
6 } 6 }
7 7
8 func (translator *UserTranslator) ToRelevantFromRepresentation(data map[string]interface{}) (*domain.Relevant, error) { 8 func (translator *UserTranslator) ToRelevantFromRepresentation(data map[string]interface{}) (*domain.Relevant, error) {
9 - return &domain.Relevant{}, nil 9 + return &domain.Relevant{
  10 + UserId: 0,
  11 + UserBaseId: 0,
  12 + Org: nil,
  13 + Orgs: nil,
  14 + Department: nil,
  15 + Role: nil,
  16 + UserInfo: nil,
  17 + UserType: 0,
  18 + Status: 0,
  19 + Company: nil,
  20 + }, nil
10 } 21 }
11 22
12 func (translator *UserTranslator) ToReferrerFromRepresentation(data map[string]interface{}) (*domain.Referrer, error) { 23 func (translator *UserTranslator) ToReferrerFromRepresentation(data map[string]interface{}) (*domain.Referrer, error) {
13 - return &domain.Referrer{}, nil 24 + return &domain.Referrer{
  25 + UserId: 0,
  26 + UserBaseId: 0,
  27 + Role: nil,
  28 + Orgs: nil,
  29 + Org: nil,
  30 + Department: nil,
  31 + Company: nil,
  32 + UserInfo: nil,
  33 + UserType: 0,
  34 + }, nil
14 } 35 }
15 36
16 func (translator *UserTranslator) ToUndertakerFromRepresentation(data map[string]interface{}) (*domain.Undertaker, error) { 37 func (translator *UserTranslator) ToUndertakerFromRepresentation(data map[string]interface{}) (*domain.Undertaker, error) {
17 - return &domain.Undertaker{}, nil 38 + return &domain.Undertaker{
  39 + UserId: 0,
  40 + UserBaseId: 0,
  41 + Org: nil,
  42 + Orgs: nil,
  43 + Department: nil,
  44 + Role: nil,
  45 + UserInfo: nil,
  46 + UserType: 0,
  47 + Status: 0,
  48 + Company: nil,
  49 + ContractAttachment: nil,
  50 + }, nil
18 } 51 }
19 52
20 func (translator *UserTranslator) ToSalesmanFromRepresentation(data map[string]interface{}) (*domain.Salesman, error) { 53 func (translator *UserTranslator) ToSalesmanFromRepresentation(data map[string]interface{}) (*domain.Salesman, error) {
21 - return &domain.Salesman{}, nil 54 + return &domain.Salesman{
  55 + UserId: 0,
  56 + UserBaseId: 0,
  57 + Role: nil,
  58 + Orgs: nil,
  59 + Org: nil,
  60 + Department: nil,
  61 + Company: nil,
  62 + UserInfo: nil,
  63 + UserType: 0,
  64 + }, nil
22 } 65 }
23 66
24 func (translator *UserTranslator) ToOperatorFromRepresentation(data map[string]interface{}) (*domain.User, error) { 67 func (translator *UserTranslator) ToOperatorFromRepresentation(data map[string]interface{}) (*domain.User, error) {
25 - return &domain.User{}, nil 68 + return &domain.User{
  69 + UserId: 0,
  70 + UserBaseId: 0,
  71 + Org: nil,
  72 + Orgs: nil,
  73 + Department: nil,
  74 + Role: nil,
  75 + UserInfo: nil,
  76 + UserType: 0,
  77 + Status: 0,
  78 + Company: nil,
  79 + }, nil
26 } 80 }