作者 陈志颖

feat:添加用户rest服务

package factory
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain/service"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/domain_service"
)
func CreateUserService(options map[string]interface{}) (service.UserService, error) {
return domain_service.NewUserService()
}
... ...
package domain_service
import (
"encoding/json"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/service_gateway/adaptor"
)
type UserService struct {
}
// ReferrerFrom 获取推荐人
func (service *UserService) ReferrerFrom(companyId int64, orgId int64, userId int64) (*domain.Referrer, error) {
return nil, nil
var returnData *domain.Referrer
if userAdaptor, err := adaptor.NewUserAdaptor(); err != nil {
return nil, err
} else {
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
}
return returnData, nil
}
}
}
// UndertakerFrom 获取承接人
func (service *UserService) UndertakerFrom(companyId int64, orgId int64, userId int64) (*domain.Undertaker, error) {
return nil, nil
var returnData *domain.Undertaker
if userAdaptor, err := adaptor.NewUserAdaptor(); err != nil {
return nil, err
} else {
if referrer, 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
}
return returnData, nil
}
}
}
// RelevantFrom 获取相关人
func (service *UserService) RelevantFrom(companyId int64, orgId int64, userId int64) (*domain.Relevant, error) {
return nil, nil
var returnData *domain.Relevant
if userAdaptor, err := adaptor.NewUserAdaptor(); err != nil {
return nil, err
} else {
if referrer, 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
}
return returnData, nil
}
}
}
// SalesmanFrom 获取业务员
func (service *UserService) SalesmanFrom(companyId int64, orgId int64, userId int64) (*domain.Salesman, error) {
return nil, nil
var returnData *domain.Salesman
if userAdaptor, err := adaptor.NewUserAdaptor(); err != nil {
return nil, err
} else {
if referrer, 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
}
return returnData, nil
}
}
}
// OperatorFrom 获取操作人
func (service *UserService) OperatorFrom(companyId int64, orgId int64, userId int64) (*domain.User, error) {
return nil, nil
var returnData *domain.User
if userAdaptor, err := adaptor.NewUserAdaptor(); err != nil {
return nil, err
} else {
if referrer, 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
}
return returnData, nil
}
}
}
func (service *UserService) UserInMenu(companyId int64, orgId int64, userId int64, code string) (bool, error) {
... ...
... ... @@ -11,42 +11,45 @@ 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)
userTranslator := &translator.UserTranslator{}
if err != nil {
return struct{}{}, err
return map[string]interface{}{}, err
}
if response["code"] == 200 {
switch aRoleName {
case "Relevant":
relevant, err := userTranslator.ToRelevantFromRepresentation(response)
if err != nil {
return struct{}{}, err
if userTranslator, err := translator.NewUserTranslator(); err != nil {
return map[string]interface{}{}, err
} else {
if response["code"] == 200 {
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 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 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
... ... @@ -59,3 +62,7 @@ func (adaptor *UserAdaptor) UserInMenu() {
func (adaptor *UserAdaptor) UserInOrganization() {
}
func NewUserAdaptor() (*UserAdaptor, error) {
return &UserAdaptor{}, nil
}
... ...
... ... @@ -18,9 +18,15 @@ func (serviceGateway *HttplibUserServiceGateway) GetUser(companyId int64, orgId
request := serviceGateway.createRequest(url, "get")
options := make(map[string]interface{})
options["uid"] = uid
request.JSONBody(options)
_, err1 := request.JSONBody(options)
if err1 != nil {
return nil, err1
}
response := make(map[string]interface{})
request.ToJSON(&response)
err2 := request.ToJSON(&response)
if err2 != nil {
return nil, err2
}
data, err := serviceGateway.responseHandle(response)
return data, err
}
... ... @@ -32,9 +38,15 @@ func (serviceGateway *HttplibUserServiceGateway) GetCompany(companyId int64) (ma
request := serviceGateway.createRequest(url, "get")
options := make(map[string]interface{})
options["companyId"] = companyId
request.JSONBody(options)
_, err1 := request.JSONBody(options)
if err1 != nil {
return nil, err1
}
response := make(map[string]interface{})
request.ToJSON(&response)
err2 := request.ToJSON(&response)
if err2 != nil {
return nil, err2
}
data, err := serviceGateway.responseHandle(response)
return data, err
}
... ... @@ -47,9 +59,15 @@ func (serviceGateway *HttplibUserServiceGateway) GetOrganization(companyId int64
request := serviceGateway.createRequest(url, "get")
options := make(map[string]interface{})
options["orgId"] = organizationId
request.JSONBody(options)
_, err1 := request.JSONBody(options)
if err1 != nil {
return nil, err1
}
response := make(map[string]interface{})
request.ToJSON(&response)
err2 := request.ToJSON(&response)
if err2 != nil {
return nil, err2
}
data, err := serviceGateway.responseHandle(response)
return data, err
}
... ... @@ -60,9 +78,15 @@ func (serviceGateway *HttplibUserServiceGateway) UserInMenu(companyId int64, use
request := serviceGateway.createRequest(url, "get")
options := make(map[string]interface{})
options["code"] = menuCode
request.JSONBody(options)
_, err1 := request.JSONBody(options)
if err1 != nil {
return nil, err1
}
response := make(map[string]interface{})
request.ToJSON(&response)
err2 := request.ToJSON(&response)
if err2 != nil {
return nil, err2
}
data, err := serviceGateway.responseHandle(response)
return data, err
}
... ... @@ -73,9 +97,15 @@ func (serviceGateway *HttplibUserServiceGateway) UserInOrganization(companyId in
request := serviceGateway.createRequest(url, "get")
options := make(map[string]interface{})
options["orgId"] = orgId
request.JSONBody(options)
_, err1 := request.JSONBody(options)
if err1 != nil {
return nil, err1
}
response := make(map[string]interface{})
request.ToJSON(&response)
err2 := request.ToJSON(&response)
if err2 != nil {
return nil, err2
}
data, err := serviceGateway.responseHandle(response)
return data, err
}
... ...
... ... @@ -78,3 +78,7 @@ func (translator *UserTranslator) ToOperatorFromRepresentation(data map[string]i
Company: nil,
}, nil
}
func NewUserTranslator() (*UserTranslator, error) {
return &UserTranslator{}, nil
}
... ...