作者 陈志颖

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

package adaptor
import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
type CompanyAdaptor struct {
}
func (adaptor *CompanyAdaptor) ToCompany() {
func (adaptor *CompanyAdaptor) ToCompany(companyId int64) (*domain.Company, error) {
return nil, nil
}
... ...
package adaptor
import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
type DepartmentAdaptor struct {
}
func (adaptor *DepartmentAdaptor) ToDepartment() {
func (adaptor *DepartmentAdaptor) ToDepartment(companyId int64, departmentId int64) (*domain.Department, error) {
return nil, nil
}
... ...
package adaptor
import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
type OrganizationAdaptor struct {
}
func (adaptor *OrganizationAdaptor) ToOrganization() {
func (adaptor *OrganizationAdaptor) ToOrganization(companyId int64, orgId int64) (*domain.Org, error) {
return nil, nil
}
... ...
package adaptor
type UserAdaptor struct {
}
func (adaptor *UserAdaptor) ToRelevant() {
}
func (adaptor *UserAdaptor) ToReferrer() {
}
func (adaptor *UserAdaptor) ToSalesman() {
}
func (adaptor *UserAdaptor) ToUndertaker() {
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) ToOperator() {
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)
userTranslator := &translator.UserTranslator{}
if err != nil {
return struct{}{}, err
}
if response["code"] == 200 {
switch aRoleName {
case "Relevant":
relevant, err := userTranslator.ToRelevantFromRepresentation(response)
if err != nil {
return struct{}{}, err
}
return relevant, nil
case "Referrer":
referrer, err := userTranslator.ToReferrerFromRepresentation(response)
if err != nil {
return struct{}{}, err
}
return referrer, nil
case "Salesman":
salesman, err := userTranslator.ToSalesmanFromRepresentation(response)
if err != nil {
return struct{}{}, nil
}
return salesman, nil
case "Undertaker":
undertaker, err := userTranslator.ToUndertakerFromRepresentation(response)
if err != nil {
return struct{}{}, nil
}
return undertaker, nil
case "Operator":
operator, err := userTranslator.ToOperatorFromRepresentation(response)
if err != nil {
return struct{}{}, nil
}
return operator, nil
}
}
return struct{}{}, nil
}
func (adaptor *UserAdaptor) UserInMenu() {
... ...
... ... @@ -12,7 +12,7 @@ type HttplibUserServiceGateway struct {
}
// GetUser 获取用户
func (serviceGateway *HttplibUserServiceGateway) GetUser(companyId int64, uid int64) (map[string]interface{}, error) {
func (serviceGateway *HttplibUserServiceGateway) GetUser(companyId int64, orgId int64, uid int64) (map[string]interface{}, error) {
companyIdStr := strconv.FormatInt(companyId, 10)
url := strings.Join([]string{serviceGateway.baseURL, "companies/" + companyIdStr + "/users/get-user"}, "/")
request := serviceGateway.createRequest(url, "get")
... ...
package service_gateway
type UserServiceGateway interface {
GetUser(companyId int64, uid int64) (map[string]interface{}, error)
GetUser(companyId int64, orgId int64, uid int64) (map[string]interface{}, error)
GetCompany(companyId int64) (map[string]interface{}, error)
GetOrganization(companyId int64, organizationId int64) (map[string]interface{}, error)
UserInMenu(companyId int64, userId int64, menuCode string) (map[string]interface{}, error)
... ...
... ... @@ -6,5 +6,8 @@ type CompanyTranslator struct {
}
func (translator *CompanyTranslator) ToCompanyFromRepresentation(data map[string]interface{}) (*domain.Company, error) {
return &domain.Company{}, nil
return &domain.Company{
CompanyId: 0,
CompanyName: "",
}, nil
}
... ...
... ... @@ -6,5 +6,10 @@ type DepartmentTranslator struct {
}
func (translator *DepartmentTranslator) ToDepartmentFromRepresentation(data map[string]interface{}) (*domain.Department, error) {
return &domain.Department{}, nil
return &domain.Department{
DepartmentId: 0,
DepartmentName: "",
DepartmentNumber: "",
IsOrganization: false,
}, nil
}
... ...
... ... @@ -6,5 +6,9 @@ type OrganizationTranslator struct {
}
func (translator *OrganizationTranslator) ToOrganizationFromRepresentation(data map[string]interface{}) (*domain.Org, error) {
return &domain.Org{}, nil
return &domain.Org{
OrgId: 0,
OrgName: "",
Company: nil,
}, nil
}
... ...
... ... @@ -6,21 +6,75 @@ type UserTranslator struct {
}
func (translator *UserTranslator) ToRelevantFromRepresentation(data map[string]interface{}) (*domain.Relevant, error) {
return &domain.Relevant{}, nil
return &domain.Relevant{
UserId: 0,
UserBaseId: 0,
Org: nil,
Orgs: nil,
Department: nil,
Role: nil,
UserInfo: nil,
UserType: 0,
Status: 0,
Company: nil,
}, nil
}
func (translator *UserTranslator) ToReferrerFromRepresentation(data map[string]interface{}) (*domain.Referrer, error) {
return &domain.Referrer{}, nil
return &domain.Referrer{
UserId: 0,
UserBaseId: 0,
Role: nil,
Orgs: nil,
Org: nil,
Department: nil,
Company: nil,
UserInfo: nil,
UserType: 0,
}, nil
}
func (translator *UserTranslator) ToUndertakerFromRepresentation(data map[string]interface{}) (*domain.Undertaker, error) {
return &domain.Undertaker{}, nil
return &domain.Undertaker{
UserId: 0,
UserBaseId: 0,
Org: nil,
Orgs: nil,
Department: nil,
Role: nil,
UserInfo: nil,
UserType: 0,
Status: 0,
Company: nil,
ContractAttachment: nil,
}, nil
}
func (translator *UserTranslator) ToSalesmanFromRepresentation(data map[string]interface{}) (*domain.Salesman, error) {
return &domain.Salesman{}, nil
return &domain.Salesman{
UserId: 0,
UserBaseId: 0,
Role: nil,
Orgs: nil,
Org: nil,
Department: nil,
Company: nil,
UserInfo: nil,
UserType: 0,
}, nil
}
func (translator *UserTranslator) ToOperatorFromRepresentation(data map[string]interface{}) (*domain.User, error) {
return &domain.User{}, nil
return &domain.User{
UserId: 0,
UserBaseId: 0,
Org: nil,
Orgs: nil,
Department: nil,
Role: nil,
UserInfo: nil,
UserType: 0,
Status: 0,
Company: nil,
}, nil
}
... ...