作者 陈志颖

feat:REST客户端设计

正在显示 24 个修改的文件 包含 280 行增加20 行删除
package service
type ApplyForCooperationService interface {
ApplyFor()
}
... ...
package service
import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
type CompanyService interface {
CompanyFrom(companyId int64) (*domain.Company, error)
}
... ...
package service
import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
type DepartmentService interface {
DepartmentFrom(companyId int64, departmentId int64) (*domain.Department, error)
}
... ...
package service
import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
type OrgService interface {
OrgFrom(companyId int64, orgId int64) (*domain.Org, error)
}
... ...
package service
import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
type UserService interface {
ReferrerFrom(companyId int64, orgId int64, userId int64) (*domain.Referrer, error)
UndertakerFrom(companyId int64, orgId int64, userId int64) (*domain.Undertaker, error)
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)
}
... ...
... ... @@ -23,10 +23,3 @@ type User struct {
// 用户关联公司信息
Company *Company `json:"company"`
}
type UserService interface {
ReferrerFrom(user *User) (*Referrer, error)
UndertakerFrom(user *User) (*Undertaker, error)
RelevantFrom(user *User) (*Relevant, error)
SalesmanFrom(user *User) (*Salesman, error)
}
... ...
package domain_service
import (
"fmt"
coreDomain "github.com/linmadan/egglib-go/core/domain"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
)
type ApplyForApplicationService struct {
coreDomain.BaseEventPublisher
transactionContext *pgTransaction.TransactionContext
}
func NewApplyForApplicationService(transactionContext *pgTransaction.TransactionContext) (*ApplyForApplicationService, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &ApplyForApplicationService{
transactionContext: transactionContext,
}, nil
}
}
... ...
package domain_service
import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
type CompanyService struct {
}
func (service *CompanyService) CompanyFrom(companyId int64) (*domain.Company, error) {
return nil, nil
}
func NewCompanyService() (*CompanyService, error) {
return &CompanyService{}, nil
}
... ...
package domain_service
import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
type DepartmentService struct {
}
func (service *DepartmentService) DepartmentFrom(companyId int64, departmentId int64) (*domain.Department, error) {
return nil, nil
}
func NewDepartmentService() (*DepartmentService, error) {
return &DepartmentService{}, nil
}
... ...
package domain_service
import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
type OrganizationService struct {
}
func (service *OrganizationService) OrgFrom(companyId int64, orgId int64) (*domain.Org, error) {
return nil, nil
}
func NewOrganizationService() (*OrganizationService, error) {
return &OrganizationService{}, nil
}
... ...
package domain_service
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
)
type UserService struct {
}
func (service *UserService) ReferrerFrom(companyId int64, orgId int64, userId int64) (*domain.Referrer, error) {
return nil, nil
}
func (service *UserService) UndertakerFrom(companyId int64, orgId int64, userId int64) (*domain.Undertaker, error) {
return nil, nil
}
func (service *UserService) RelevantFrom(companyId int64, orgId int64, userId int64) (*domain.Relevant, error) {
return nil, nil
}
func (service *UserService) SalesmanFrom(companyId int64, orgId int64, userId int64) (*domain.Salesman, error) {
return nil, nil
}
func (service *UserService) OperatorFrom(companyId int64, orgId int64, userId int64) (*domain.User, error) {
return nil, 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
}
... ...
... ... @@ -216,13 +216,13 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
); err != nil {
return cooperationContract, err
} else {
//TODO 更新相关人
// 获取相关人列表
var cooperationContractRelevantModels []*models.CooperationContractRelevant
cooperationContractRelevantQuery := tx.Model(&cooperationContractRelevantModels)
if err := cooperationContractRelevantQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil {
return nil, err
}
var cooperationContractRelevantModelsUpdate []*models.CooperationContractRelevant // 待更新的相关人
var cooperationContractRelevantModelsDelete []*models.CooperationContractRelevant // 待删除的相关人
var cooperationContractRelevantModelsCreate []*models.CooperationContractRelevant // 待增加的相关人
... ... @@ -233,6 +233,12 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
}
}
// 更新的相关人
// 删除的相关人
// 新增的相关人
//TODO 更新承接人
// 获取承接人列表
var cooperationContractUndertakerModels []*models.CooperationContractUndertaker
... ...
package adaptor
type UserInMenuAdaptor struct {
type CompanyAdaptor struct {
}
func (adaptor *CompanyAdaptor) ToCompany() {
}
... ...
package adaptor
type UserInOrganizationAdaptor struct {
type DepartmentAdaptor struct {
}
func (adaptor *DepartmentAdaptor) ToDepartment() {
}
... ...
package adaptor
type OrganizationAdaptor struct {
}
func (adaptor *OrganizationAdaptor) ToOrganization() {
}
... ...
... ... @@ -2,3 +2,31 @@ package adaptor
type UserAdaptor struct {
}
func (adaptor *UserAdaptor) ToRelevant() {
}
func (adaptor *UserAdaptor) ToReferrer() {
}
func (adaptor *UserAdaptor) ToSalesman() {
}
func (adaptor *UserAdaptor) ToUndertaker() {
}
func (adaptor *UserAdaptor) ToOperator() {
}
func (adaptor *UserAdaptor) UserInMenu() {
}
func (adaptor *UserAdaptor) UserInOrganization() {
}
... ...
... ... @@ -2,6 +2,7 @@ package service_gateway
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/constant"
"strconv"
"strings"
"time"
)
... ... @@ -11,8 +12,9 @@ type HttplibUserServiceGateway struct {
}
// GetUser 获取用户
func (serviceGateway *HttplibUserServiceGateway) GetUser(uid int64) (map[string]interface{}, error) {
url := strings.Join([]string{serviceGateway.baseURL, "users/get-user"}, "/")
func (serviceGateway *HttplibUserServiceGateway) GetUser(companyId 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")
options := make(map[string]interface{})
options["uid"] = uid
... ... @@ -25,7 +27,8 @@ func (serviceGateway *HttplibUserServiceGateway) GetUser(uid int64) (map[string]
// GetCompany 获取公司
func (serviceGateway *HttplibUserServiceGateway) GetCompany(companyId int64) (map[string]interface{}, error) {
url := strings.Join([]string{serviceGateway.baseURL, "companies/ge-company"}, "/")
companyIdStr := strconv.FormatInt(companyId, 10)
url := strings.Join([]string{serviceGateway.baseURL, "companies/" + companyIdStr}, "/")
request := serviceGateway.createRequest(url, "get")
options := make(map[string]interface{})
options["companyId"] = companyId
... ... @@ -37,8 +40,10 @@ func (serviceGateway *HttplibUserServiceGateway) GetCompany(companyId int64) (ma
}
// GetOrganization 获取组织信息
func (serviceGateway *HttplibUserServiceGateway) GetOrganization(organizationId int64) (map[string]interface{}, error) {
url := strings.Join([]string{serviceGateway.baseURL, "orgs/get-org"}, "/")
func (serviceGateway *HttplibUserServiceGateway) GetOrganization(companyId int64, organizationId int64) (map[string]interface{}, error) {
companyIdStr := strconv.FormatInt(companyId, 10)
organizationIdStr := strconv.FormatInt(organizationId, 10)
url := strings.Join([]string{serviceGateway.baseURL, "companies/" + companyIdStr + "/orgs/" + organizationIdStr}, "/")
request := serviceGateway.createRequest(url, "get")
options := make(map[string]interface{})
options["orgId"] = organizationId
... ... @@ -49,8 +54,8 @@ func (serviceGateway *HttplibUserServiceGateway) GetOrganization(organizationId
return data, err
}
// UserInMenu 获取用户菜单模块权限
func (serviceGateway *HttplibUserServiceGateway) UserInMenu(menuCode string) (map[string]interface{}, error) {
// UserInMenu 判断用户是否具有模块权限
func (serviceGateway *HttplibUserServiceGateway) UserInMenu(companyId int64, userId int64, menuCode string) (map[string]interface{}, error) {
url := strings.Join([]string{serviceGateway.baseURL, "users/menu"}, "/")
request := serviceGateway.createRequest(url, "get")
options := make(map[string]interface{})
... ... @@ -62,6 +67,19 @@ func (serviceGateway *HttplibUserServiceGateway) UserInMenu(menuCode string) (ma
return data, err
}
// UserInOrganization 判断用户是否存在组织内
func (serviceGateway *HttplibUserServiceGateway) UserInOrganization(companyId int64, orgId int64, userId int64) (map[string]interface{}, error) {
url := strings.Join([]string{serviceGateway.baseURL, "users/menu"}, "/")
request := serviceGateway.createRequest(url, "get")
options := make(map[string]interface{})
options["orgId"] = orgId
request.JSONBody(options)
response := make(map[string]interface{})
request.ToJSON(&response)
data, err := serviceGateway.responseHandle(response)
return data, err
}
func NewHttplibUserServiceGateway() *HttplibUserServiceGateway {
return &HttplibUserServiceGateway{
httplibBaseServiceGateway: httplibBaseServiceGateway{
... ...
package service_gateway
type UserServiceGateway interface {
GetUser(uid int64) (map[string]interface{}, error)
GetUser(companyId 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)
}
... ...
package translator
import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
type CompanyTranslator struct {
}
func (translator *CompanyTranslator) ToCompanyFromRepresentation(data map[string]interface{}) (*domain.Company, error) {
return &domain.Company{}, nil
}
... ...
package translator
import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
type DepartmentTranslator struct {
}
func (translator *DepartmentTranslator) ToDepartmentFromRepresentation(data map[string]interface{}) (*domain.Department, error) {
return &domain.Department{}, nil
}
... ...
package translator
import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
type OrganizationTranslator struct {
}
func (translator *OrganizationTranslator) ToOrganizationFromRepresentation(data map[string]interface{}) (*domain.Org, error) {
return &domain.Org{}, nil
}
... ...
package translator
import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
type UserTranslator struct {
}
func (translator *UserTranslator) ToRelevantFromRepresentation(data map[string]interface{}) (*domain.Relevant, error) {
return &domain.Relevant{}, nil
}
func (translator *UserTranslator) ToReferrerFromRepresentation(data map[string]interface{}) (*domain.Referrer, error) {
return &domain.Referrer{}, nil
}
func (translator *UserTranslator) ToUndertakerFromRepresentation(data map[string]interface{}) (*domain.Undertaker, error) {
return &domain.Undertaker{}, nil
}
func (translator *UserTranslator) ToSalesmanFromRepresentation(data map[string]interface{}) (*domain.Salesman, error) {
return &domain.Salesman{}, nil
}
func (translator *UserTranslator) ToOperatorFromRepresentation(data map[string]interface{}) (*domain.User, error) {
return &domain.User{}, nil
}
... ...