作者 陈志颖

feat:添加公司和部门适配器

... ... @@ -8,3 +8,15 @@ import (
func CreateUserService(options map[string]interface{}) (service.UserService, error) {
return domain_service.NewUserService()
}
func CreateCompanyService(options map[string]interface{}) (service.CompanyService, error) {
return domain_service.NewCompanyService()
}
func CreateDepartmentService(options map[string]interface{}) (service.DepartmentService, error) {
return domain_service.NewDepartmentService()
}
func CreateOrganization(options map[string]interface{}) (service.OrgService, error) {
return domain_service.NewOrganizationService()
}
... ...
... ... @@ -8,6 +8,4 @@ type UserService interface {
RelevantFrom(companyId int64, orgId int64, userId int64) (*domain.Relevant, error)
SalesmanFrom(companyId int64, orgId int64, userId int64) (*domain.Salesman, error)
OperatorFrom(companyId int64, orgId int64, userId int64) (*domain.User, error)
UserInMenu(companyId int64, orgId int64, userId int64, code string) (bool, error)
UserInOrganization(companyId int64, orgId int64, userId int64) (bool, error)
}
... ...
... ... @@ -18,9 +18,11 @@ func (service *UserService) ReferrerFrom(companyId int64, orgId int64, userId in
if referrer, err := userAdaptor.ToParticipator(companyId, orgId, userId, "Referrer"); err != nil {
return nil, err
} else {
err := json.Unmarshal(referrer.([]byte), returnData)
if err != nil {
return nil, err
if referrer != nil {
err := json.Unmarshal(referrer.([]byte), returnData)
if err != nil {
return nil, err
}
}
return returnData, nil
}
... ... @@ -33,12 +35,14 @@ func (service *UserService) UndertakerFrom(companyId int64, orgId int64, userId
if userAdaptor, err := adaptor.NewUserAdaptor(); err != nil {
return nil, err
} else {
if referrer, err := userAdaptor.ToParticipator(companyId, orgId, userId, "Undertaker"); err != nil {
if undertaker, err := userAdaptor.ToParticipator(companyId, orgId, userId, "Undertaker"); err != nil {
return nil, err
} else {
err := json.Unmarshal(referrer.([]byte), returnData)
if err != nil {
return nil, err
if undertaker != nil {
err := json.Unmarshal(undertaker.([]byte), returnData)
if err != nil {
return nil, err
}
}
return returnData, nil
}
... ... @@ -51,12 +55,14 @@ func (service *UserService) RelevantFrom(companyId int64, orgId int64, userId in
if userAdaptor, err := adaptor.NewUserAdaptor(); err != nil {
return nil, err
} else {
if referrer, err := userAdaptor.ToParticipator(companyId, orgId, userId, "Relevant"); err != nil {
if relevant, err := userAdaptor.ToParticipator(companyId, orgId, userId, "Relevant"); err != nil {
return nil, err
} else {
err := json.Unmarshal(referrer.([]byte), returnData)
if err != nil {
return nil, err
if relevant != nil {
err := json.Unmarshal(relevant.([]byte), returnData)
if err != nil {
return nil, err
}
}
return returnData, nil
}
... ... @@ -69,12 +75,14 @@ func (service *UserService) SalesmanFrom(companyId int64, orgId int64, userId in
if userAdaptor, err := adaptor.NewUserAdaptor(); err != nil {
return nil, err
} else {
if referrer, err := userAdaptor.ToParticipator(companyId, orgId, userId, "Salesman"); err != nil {
if salesman, err := userAdaptor.ToParticipator(companyId, orgId, userId, "Salesman"); err != nil {
return nil, err
} else {
err := json.Unmarshal(referrer.([]byte), returnData)
if err != nil {
return nil, err
if salesman != nil {
err := json.Unmarshal(salesman.([]byte), returnData)
if err != nil {
return nil, err
}
}
return returnData, nil
}
... ... @@ -87,26 +95,20 @@ func (service *UserService) OperatorFrom(companyId int64, orgId int64, userId in
if userAdaptor, err := adaptor.NewUserAdaptor(); err != nil {
return nil, err
} else {
if referrer, err := userAdaptor.ToParticipator(companyId, orgId, userId, "Operator"); err != nil {
if operator, err := userAdaptor.ToParticipator(companyId, orgId, userId, "Operator"); err != nil {
return nil, err
} else {
err := json.Unmarshal(referrer.([]byte), returnData)
if err != nil {
return nil, err
if operator != nil {
err := json.Unmarshal(operator.([]byte), returnData)
if err != nil {
return nil, err
}
}
return returnData, nil
}
}
}
func (service *UserService) UserInMenu(companyId int64, orgId int64, userId int64, code string) (bool, error) {
return false, nil
}
func (service *UserService) UserInOrganization(companyId int64, orgId int64, userId int64) (bool, error) {
return false, nil
}
func NewUserService() (*UserService, error) {
return &UserService{}, nil
}
... ...
package adaptor
import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
"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 CompanyAdaptor struct {
}
func (adaptor *CompanyAdaptor) ToCompany(companyId int64) (*domain.Company, error) {
return nil, nil
companyServiceGateway := service_gateway.NewHttplibUserServiceGateway()
response, err := companyServiceGateway.GetCompany(companyId)
if err != nil {
return nil, err
}
if companyTranslator, err := translator.NewCompanyTranslator(); err != nil {
return nil, err
} else {
company, err := companyTranslator.ToCompanyFromRepresentation(response)
if err != nil {
return nil, err
}
return company, nil
}
}
func NewCompanyAdaptor() (*CompanyAdaptor, error) {
return &CompanyAdaptor{}, nil
}
... ...
package adaptor
import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
"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 DepartmentAdaptor struct {
}
func (adaptor *DepartmentAdaptor) ToDepartment(companyId int64, departmentId int64) (*domain.Department, error) {
return nil, nil
departmentServiceGateway := service_gateway.NewHttplibUserServiceGateway()
response, err := departmentServiceGateway.GetDepartment(companyId, departmentId)
if err != nil {
return nil, err
}
if departmentTranslator, err := translator.NewDepartmentTranslator(); err != nil {
return nil, err
} else {
department, err := departmentTranslator.ToDepartmentFromRepresentation(response)
if err != nil {
return nil, err
}
return department, nil
}
}
func NewDepartmentAdaptor() (*DepartmentAdaptor, error) {
return &DepartmentAdaptor{}, nil
}
... ...
package adaptor
import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
"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 OrganizationAdaptor struct {
}
func (adaptor *OrganizationAdaptor) ToOrganization(companyId int64, orgId int64) (*domain.Org, error) {
return nil, nil
organizationServiceGateway := service_gateway.NewHttplibUserServiceGateway()
response, err := organizationServiceGateway.GetOrganization(companyId, orgId)
if err != nil {
return nil, err
}
if organizationTranslator, err := translator.NewOrganizationTranslator(); err != nil {
return nil, err
} else {
organization, err := organizationTranslator.ToOrganizationFromRepresentation(response)
if err != nil {
return nil, err
}
return organization, nil
}
}
func NewOrganizationAdaptor() (*OrganizationAdaptor, error) {
return &OrganizationAdaptor{}, nil
}
... ...
... ... @@ -28,39 +28,31 @@ func (adaptor *UserAdaptor) ToParticipator(companyId int64, orgId int64, userId
case "Referrer":
referrer, err := userTranslator.ToReferrerFromRepresentation(response)
if err != nil {
return struct{}{}, err
return map[string]interface{}{}, err
}
return referrer, nil
case "Salesman":
salesman, err := userTranslator.ToSalesmanFromRepresentation(response)
if err != nil {
return struct{}{}, nil
return map[string]interface{}{}, nil
}
return salesman, nil
case "Undertaker":
undertaker, err := userTranslator.ToUndertakerFromRepresentation(response)
if err != nil {
return struct{}{}, nil
return map[string]interface{}{}, nil
}
return undertaker, nil
case "Operator":
operator, err := userTranslator.ToOperatorFromRepresentation(response)
if err != nil {
return struct{}{}, nil
return map[string]interface{}{}, nil
}
return operator, nil
}
}
}
return struct{}{}, nil
}
func (adaptor *UserAdaptor) UserInMenu() {
}
func (adaptor *UserAdaptor) UserInOrganization() {
return map[string]interface{}{}, nil
}
func NewUserAdaptor() (*UserAdaptor, error) {
... ...
... ... @@ -31,7 +31,7 @@ func (serviceGateway *HttplibUserServiceGateway) GetUser(companyId int64, orgId
return data, err
}
// GetCompany 获取公司
// GetCompany 获取公司信息
func (serviceGateway *HttplibUserServiceGateway) GetCompany(companyId int64) (map[string]interface{}, error) {
companyIdStr := strconv.FormatInt(companyId, 10)
url := strings.Join([]string{serviceGateway.baseURL, "companies/" + companyIdStr}, "/")
... ... @@ -51,6 +51,26 @@ func (serviceGateway *HttplibUserServiceGateway) GetCompany(companyId int64) (ma
return data, err
}
// GetDepartment 获取部门信息
func (serviceGateway *HttplibUserServiceGateway) GetDepartment(companyId int64, departmentId int64) (map[string]interface{}, error) {
companyIdStr := strconv.FormatInt(companyId, 10)
url := strings.Join([]string{serviceGateway.baseURL, "companies/" + companyIdStr}, "/")
request := serviceGateway.createRequest(url, "get")
options := make(map[string]interface{})
options["departmentId"] = departmentId
_, err1 := request.JSONBody(options)
if err1 != nil {
return nil, err1
}
response := make(map[string]interface{})
err2 := request.ToJSON(&response)
if err2 != nil {
return nil, err2
}
data, err := serviceGateway.responseHandle(response)
return data, err
}
// GetOrganization 获取组织信息
func (serviceGateway *HttplibUserServiceGateway) GetOrganization(companyId int64, organizationId int64) (map[string]interface{}, error) {
companyIdStr := strconv.FormatInt(companyId, 10)
... ... @@ -73,41 +93,47 @@ func (serviceGateway *HttplibUserServiceGateway) GetOrganization(companyId int64
}
// UserInMenu 判断用户是否具有模块权限
func (serviceGateway *HttplibUserServiceGateway) UserInMenu(companyId int64, userId int64, menuCode string) (map[string]interface{}, error) {
func (serviceGateway *HttplibUserServiceGateway) UserInMenu(companyId int64, userId int64, menuCode string) (bool, error) {
url := strings.Join([]string{serviceGateway.baseURL, "users/menu"}, "/")
request := serviceGateway.createRequest(url, "get")
options := make(map[string]interface{})
options["code"] = menuCode
_, err1 := request.JSONBody(options)
if err1 != nil {
return nil, err1
return false, err1
}
response := make(map[string]interface{})
err2 := request.ToJSON(&response)
if err2 != nil {
return nil, err2
return false, err2
}
data, err := serviceGateway.responseHandle(response)
return data, err
if data["code"] == 200 {
return true, nil
}
return false, err
}
// UserInOrganization 判断用户是否存在组织内
func (serviceGateway *HttplibUserServiceGateway) UserInOrganization(companyId int64, orgId int64, userId int64) (map[string]interface{}, error) {
func (serviceGateway *HttplibUserServiceGateway) UserInOrganization(companyId int64, orgId int64, userId int64) (bool, error) {
url := strings.Join([]string{serviceGateway.baseURL, "users/menu"}, "/")
request := serviceGateway.createRequest(url, "get")
options := make(map[string]interface{})
options["orgId"] = orgId
_, err1 := request.JSONBody(options)
if err1 != nil {
return nil, err1
return false, err1
}
response := make(map[string]interface{})
err2 := request.ToJSON(&response)
if err2 != nil {
return nil, err2
return false, err2
}
data, err := serviceGateway.responseHandle(response)
return data, err
if data["code"] == 200 {
return true, nil
}
return false, err
}
func NewHttplibUserServiceGateway() *HttplibUserServiceGateway {
... ...
... ... @@ -4,6 +4,6 @@ type UserServiceGateway interface {
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)
UserInOrganization(companyId int64, orgId int64, userId int64) (map[string]interface{}, error)
UserInMenu(companyId int64, userId int64, menuCode string) (bool, error)
UserInOrganization(companyId int64, orgId int64, userId int64) (bool, error)
}
... ...
... ... @@ -11,3 +11,7 @@ func (translator *CompanyTranslator) ToCompanyFromRepresentation(data map[string
CompanyName: "",
}, nil
}
func NewCompanyTranslator() (*CompanyTranslator, error) {
return &CompanyTranslator{}, nil
}
... ...
... ... @@ -13,3 +13,7 @@ func (translator *DepartmentTranslator) ToDepartmentFromRepresentation(data map[
IsOrganization: false,
}, nil
}
func NewDepartmentTranslator() (*DepartmentTranslator, error) {
return &DepartmentTranslator{}, nil
}
... ...
... ... @@ -12,3 +12,7 @@ func (translator *OrganizationTranslator) ToOrganizationFromRepresentation(data
Company: nil,
}, nil
}
func NewOrganizationTranslator() (*OrganizationTranslator, error) {
return &OrganizationTranslator{}, nil
}
... ...