作者 陈志颖

feat:REST客户端设计

正在显示 24 个修改的文件 包含 280 行增加20 行删除
  1 +package service
  2 +
  3 +type ApplyForCooperationService interface {
  4 + ApplyFor()
  5 +}
  1 +package service
  2 +
  3 +import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
  4 +
  5 +type CompanyService interface {
  6 + CompanyFrom(companyId int64) (*domain.Company, error)
  7 +}
  1 +package service
  2 +
  3 +import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
  4 +
  5 +type DepartmentService interface {
  6 + DepartmentFrom(companyId int64, departmentId int64) (*domain.Department, error)
  7 +}
  1 +package service
  2 +
  3 +import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
  4 +
  5 +type OrgService interface {
  6 + OrgFrom(companyId int64, orgId int64) (*domain.Org, error)
  7 +}
  1 +package service
  2 +
  3 +import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
  4 +
  5 +type UserService interface {
  6 + ReferrerFrom(companyId int64, orgId int64, userId int64) (*domain.Referrer, error)
  7 + UndertakerFrom(companyId int64, orgId int64, userId int64) (*domain.Undertaker, error)
  8 + RelevantFrom(companyId int64, orgId int64, userId int64) (*domain.Relevant, error)
  9 + SalesmanFrom(companyId int64, orgId int64, userId int64) (*domain.Salesman, error)
  10 + OperatorFrom(companyId int64, orgId int64, userId int64) (*domain.User, error)
  11 + UserInMenu(companyId int64, orgId int64, userId int64, code string) (bool, error)
  12 + UserInOrganization(companyId int64, orgId int64, userId int64) (bool, error)
  13 +}
@@ -23,10 +23,3 @@ type User struct { @@ -23,10 +23,3 @@ type User struct {
23 // 用户关联公司信息 23 // 用户关联公司信息
24 Company *Company `json:"company"` 24 Company *Company `json:"company"`
25 } 25 }
26 -  
27 -type UserService interface {  
28 - ReferrerFrom(user *User) (*Referrer, error)  
29 - UndertakerFrom(user *User) (*Undertaker, error)  
30 - RelevantFrom(user *User) (*Relevant, error)  
31 - SalesmanFrom(user *User) (*Salesman, error)  
32 -}  
  1 +package domain_service
  2 +
  3 +import (
  4 + "fmt"
  5 + coreDomain "github.com/linmadan/egglib-go/core/domain"
  6 + pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
  7 +)
  8 +
  9 +type ApplyForApplicationService struct {
  10 + coreDomain.BaseEventPublisher
  11 + transactionContext *pgTransaction.TransactionContext
  12 +}
  13 +
  14 +func NewApplyForApplicationService(transactionContext *pgTransaction.TransactionContext) (*ApplyForApplicationService, error) {
  15 + if transactionContext == nil {
  16 + return nil, fmt.Errorf("transactionContext参数不能为nil")
  17 + } else {
  18 + return &ApplyForApplicationService{
  19 + transactionContext: transactionContext,
  20 + }, nil
  21 + }
  22 +}
  1 +package domain_service
  2 +
  3 +import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
  4 +
  5 +type CompanyService struct {
  6 +}
  7 +
  8 +func (service *CompanyService) CompanyFrom(companyId int64) (*domain.Company, error) {
  9 + return nil, nil
  10 +}
  11 +
  12 +func NewCompanyService() (*CompanyService, error) {
  13 + return &CompanyService{}, nil
  14 +}
  1 +package domain_service
  2 +
  3 +import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
  4 +
  5 +type DepartmentService struct {
  6 +}
  7 +
  8 +func (service *DepartmentService) DepartmentFrom(companyId int64, departmentId int64) (*domain.Department, error) {
  9 + return nil, nil
  10 +}
  11 +
  12 +func NewDepartmentService() (*DepartmentService, error) {
  13 + return &DepartmentService{}, nil
  14 +}
  1 +package domain_service
  2 +
  3 +import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
  4 +
  5 +type OrganizationService struct {
  6 +}
  7 +
  8 +func (service *OrganizationService) OrgFrom(companyId int64, orgId int64) (*domain.Org, error) {
  9 + return nil, nil
  10 +}
  11 +
  12 +func NewOrganizationService() (*OrganizationService, error) {
  13 + return &OrganizationService{}, nil
  14 +}
  1 +package domain_service
  2 +
  3 +import (
  4 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
  5 +)
  6 +
  7 +type UserService struct {
  8 +}
  9 +
  10 +func (service *UserService) ReferrerFrom(companyId int64, orgId int64, userId int64) (*domain.Referrer, error) {
  11 + return nil, nil
  12 +}
  13 +
  14 +func (service *UserService) UndertakerFrom(companyId int64, orgId int64, userId int64) (*domain.Undertaker, error) {
  15 + return nil, nil
  16 +}
  17 +
  18 +func (service *UserService) RelevantFrom(companyId int64, orgId int64, userId int64) (*domain.Relevant, error) {
  19 + return nil, nil
  20 +}
  21 +
  22 +func (service *UserService) SalesmanFrom(companyId int64, orgId int64, userId int64) (*domain.Salesman, error) {
  23 + return nil, nil
  24 +}
  25 +
  26 +func (service *UserService) OperatorFrom(companyId int64, orgId int64, userId int64) (*domain.User, error) {
  27 + return nil, nil
  28 +}
  29 +
  30 +func (service *UserService) UserInMenu(companyId int64, orgId int64, userId int64, code string) (bool, error) {
  31 + return false, nil
  32 +}
  33 +
  34 +func (service *UserService) UserInOrganization(companyId int64, orgId int64, userId int64) (bool, error) {
  35 + return false, nil
  36 +}
  37 +
  38 +func NewUserService() (*UserService, error) {
  39 + return &UserService{}, nil
  40 +}
@@ -216,13 +216,13 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai @@ -216,13 +216,13 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
216 ); err != nil { 216 ); err != nil {
217 return cooperationContract, err 217 return cooperationContract, err
218 } else { 218 } else {
219 - //TODO 更新相关人  
220 // 获取相关人列表 219 // 获取相关人列表
221 var cooperationContractRelevantModels []*models.CooperationContractRelevant 220 var cooperationContractRelevantModels []*models.CooperationContractRelevant
222 cooperationContractRelevantQuery := tx.Model(&cooperationContractRelevantModels) 221 cooperationContractRelevantQuery := tx.Model(&cooperationContractRelevantModels)
223 if err := cooperationContractRelevantQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil { 222 if err := cooperationContractRelevantQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil {
224 return nil, err 223 return nil, err
225 } 224 }
  225 +
226 var cooperationContractRelevantModelsUpdate []*models.CooperationContractRelevant // 待更新的相关人 226 var cooperationContractRelevantModelsUpdate []*models.CooperationContractRelevant // 待更新的相关人
227 var cooperationContractRelevantModelsDelete []*models.CooperationContractRelevant // 待删除的相关人 227 var cooperationContractRelevantModelsDelete []*models.CooperationContractRelevant // 待删除的相关人
228 var cooperationContractRelevantModelsCreate []*models.CooperationContractRelevant // 待增加的相关人 228 var cooperationContractRelevantModelsCreate []*models.CooperationContractRelevant // 待增加的相关人
@@ -233,6 +233,12 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai @@ -233,6 +233,12 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
233 } 233 }
234 } 234 }
235 235
  236 + // 更新的相关人
  237 +
  238 + // 删除的相关人
  239 +
  240 + // 新增的相关人
  241 +
236 //TODO 更新承接人 242 //TODO 更新承接人
237 // 获取承接人列表 243 // 获取承接人列表
238 var cooperationContractUndertakerModels []*models.CooperationContractUndertaker 244 var cooperationContractUndertakerModels []*models.CooperationContractUndertaker
1 package adaptor 1 package adaptor
2 2
3 -type UserInMenuAdaptor struct { 3 +type CompanyAdaptor struct {
  4 +}
  5 +
  6 +func (adaptor *CompanyAdaptor) ToCompany() {
  7 +
4 } 8 }
1 package adaptor 1 package adaptor
2 2
3 -type UserInOrganizationAdaptor struct { 3 +type DepartmentAdaptor struct {
  4 +}
  5 +
  6 +func (adaptor *DepartmentAdaptor) ToDepartment() {
  7 +
4 } 8 }
  1 +package adaptor
  2 +
  3 +type OrganizationAdaptor struct {
  4 +}
  5 +
  6 +func (adaptor *OrganizationAdaptor) ToOrganization() {
  7 +
  8 +}
@@ -2,3 +2,31 @@ package adaptor @@ -2,3 +2,31 @@ package adaptor
2 2
3 type UserAdaptor struct { 3 type UserAdaptor struct {
4 } 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() {
  19 +
  20 +}
  21 +
  22 +func (adaptor *UserAdaptor) ToOperator() {
  23 +
  24 +}
  25 +
  26 +func (adaptor *UserAdaptor) UserInMenu() {
  27 +
  28 +}
  29 +
  30 +func (adaptor *UserAdaptor) UserInOrganization() {
  31 +
  32 +}
@@ -2,6 +2,7 @@ package service_gateway @@ -2,6 +2,7 @@ package service_gateway
2 2
3 import ( 3 import (
4 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/constant" 4 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/constant"
  5 + "strconv"
5 "strings" 6 "strings"
6 "time" 7 "time"
7 ) 8 )
@@ -11,8 +12,9 @@ type HttplibUserServiceGateway struct { @@ -11,8 +12,9 @@ type HttplibUserServiceGateway struct {
11 } 12 }
12 13
13 // GetUser 获取用户 14 // GetUser 获取用户
14 -func (serviceGateway *HttplibUserServiceGateway) GetUser(uid int64) (map[string]interface{}, error) {  
15 - url := strings.Join([]string{serviceGateway.baseURL, "users/get-user"}, "/") 15 +func (serviceGateway *HttplibUserServiceGateway) GetUser(companyId int64, uid int64) (map[string]interface{}, error) {
  16 + companyIdStr := strconv.FormatInt(companyId, 10)
  17 + url := strings.Join([]string{serviceGateway.baseURL, "companies/" + companyIdStr + "/users/get-user"}, "/")
16 request := serviceGateway.createRequest(url, "get") 18 request := serviceGateway.createRequest(url, "get")
17 options := make(map[string]interface{}) 19 options := make(map[string]interface{})
18 options["uid"] = uid 20 options["uid"] = uid
@@ -25,7 +27,8 @@ func (serviceGateway *HttplibUserServiceGateway) GetUser(uid int64) (map[string] @@ -25,7 +27,8 @@ func (serviceGateway *HttplibUserServiceGateway) GetUser(uid int64) (map[string]
25 27
26 // GetCompany 获取公司 28 // GetCompany 获取公司
27 func (serviceGateway *HttplibUserServiceGateway) GetCompany(companyId int64) (map[string]interface{}, error) { 29 func (serviceGateway *HttplibUserServiceGateway) GetCompany(companyId int64) (map[string]interface{}, error) {
28 - url := strings.Join([]string{serviceGateway.baseURL, "companies/ge-company"}, "/") 30 + companyIdStr := strconv.FormatInt(companyId, 10)
  31 + url := strings.Join([]string{serviceGateway.baseURL, "companies/" + companyIdStr}, "/")
29 request := serviceGateway.createRequest(url, "get") 32 request := serviceGateway.createRequest(url, "get")
30 options := make(map[string]interface{}) 33 options := make(map[string]interface{})
31 options["companyId"] = companyId 34 options["companyId"] = companyId
@@ -37,8 +40,10 @@ func (serviceGateway *HttplibUserServiceGateway) GetCompany(companyId int64) (ma @@ -37,8 +40,10 @@ func (serviceGateway *HttplibUserServiceGateway) GetCompany(companyId int64) (ma
37 } 40 }
38 41
39 // GetOrganization 获取组织信息 42 // GetOrganization 获取组织信息
40 -func (serviceGateway *HttplibUserServiceGateway) GetOrganization(organizationId int64) (map[string]interface{}, error) {  
41 - url := strings.Join([]string{serviceGateway.baseURL, "orgs/get-org"}, "/") 43 +func (serviceGateway *HttplibUserServiceGateway) GetOrganization(companyId int64, organizationId int64) (map[string]interface{}, error) {
  44 + companyIdStr := strconv.FormatInt(companyId, 10)
  45 + organizationIdStr := strconv.FormatInt(organizationId, 10)
  46 + url := strings.Join([]string{serviceGateway.baseURL, "companies/" + companyIdStr + "/orgs/" + organizationIdStr}, "/")
42 request := serviceGateway.createRequest(url, "get") 47 request := serviceGateway.createRequest(url, "get")
43 options := make(map[string]interface{}) 48 options := make(map[string]interface{})
44 options["orgId"] = organizationId 49 options["orgId"] = organizationId
@@ -49,8 +54,8 @@ func (serviceGateway *HttplibUserServiceGateway) GetOrganization(organizationId @@ -49,8 +54,8 @@ func (serviceGateway *HttplibUserServiceGateway) GetOrganization(organizationId
49 return data, err 54 return data, err
50 } 55 }
51 56
52 -// UserInMenu 获取用户菜单模块权限  
53 -func (serviceGateway *HttplibUserServiceGateway) UserInMenu(menuCode string) (map[string]interface{}, error) { 57 +// UserInMenu 判断用户是否具有模块权限
  58 +func (serviceGateway *HttplibUserServiceGateway) UserInMenu(companyId int64, userId int64, menuCode string) (map[string]interface{}, error) {
54 url := strings.Join([]string{serviceGateway.baseURL, "users/menu"}, "/") 59 url := strings.Join([]string{serviceGateway.baseURL, "users/menu"}, "/")
55 request := serviceGateway.createRequest(url, "get") 60 request := serviceGateway.createRequest(url, "get")
56 options := make(map[string]interface{}) 61 options := make(map[string]interface{})
@@ -62,6 +67,19 @@ func (serviceGateway *HttplibUserServiceGateway) UserInMenu(menuCode string) (ma @@ -62,6 +67,19 @@ func (serviceGateway *HttplibUserServiceGateway) UserInMenu(menuCode string) (ma
62 return data, err 67 return data, err
63 } 68 }
64 69
  70 +// UserInOrganization 判断用户是否存在组织内
  71 +func (serviceGateway *HttplibUserServiceGateway) UserInOrganization(companyId int64, orgId int64, userId int64) (map[string]interface{}, error) {
  72 + url := strings.Join([]string{serviceGateway.baseURL, "users/menu"}, "/")
  73 + request := serviceGateway.createRequest(url, "get")
  74 + options := make(map[string]interface{})
  75 + options["orgId"] = orgId
  76 + request.JSONBody(options)
  77 + response := make(map[string]interface{})
  78 + request.ToJSON(&response)
  79 + data, err := serviceGateway.responseHandle(response)
  80 + return data, err
  81 +}
  82 +
65 func NewHttplibUserServiceGateway() *HttplibUserServiceGateway { 83 func NewHttplibUserServiceGateway() *HttplibUserServiceGateway {
66 return &HttplibUserServiceGateway{ 84 return &HttplibUserServiceGateway{
67 httplibBaseServiceGateway: httplibBaseServiceGateway{ 85 httplibBaseServiceGateway: httplibBaseServiceGateway{
1 package service_gateway 1 package service_gateway
2 2
3 type UserServiceGateway interface { 3 type UserServiceGateway interface {
4 - GetUser(uid int64) (map[string]interface{}, error) 4 + GetUser(companyId 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)
  7 + UserInMenu(companyId int64, userId int64, menuCode string) (map[string]interface{}, error)
  8 + UserInOrganization(companyId int64, orgId int64, userId int64) (map[string]interface{}, error)
6 } 9 }
  1 +package translator
  2 +
  3 +import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
  4 +
  5 +type CompanyTranslator struct {
  6 +}
  7 +
  8 +func (translator *CompanyTranslator) ToCompanyFromRepresentation(data map[string]interface{}) (*domain.Company, error) {
  9 + return &domain.Company{}, nil
  10 +}
  1 +package translator
  2 +
  3 +import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
  4 +
  5 +type DepartmentTranslator struct {
  6 +}
  7 +
  8 +func (translator *DepartmentTranslator) ToDepartmentFromRepresentation(data map[string]interface{}) (*domain.Department, error) {
  9 + return &domain.Department{}, nil
  10 +}
  1 +package translator
  2 +
  3 +import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
  4 +
  5 +type OrganizationTranslator struct {
  6 +}
  7 +
  8 +func (translator *OrganizationTranslator) ToOrganizationFromRepresentation(data map[string]interface{}) (*domain.Org, error) {
  9 + return &domain.Org{}, nil
  10 +}
1 package translator 1 package translator
  2 +
  3 +import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
  4 +
  5 +type UserTranslator struct {
  6 +}
  7 +
  8 +func (translator *UserTranslator) ToRelevantFromRepresentation(data map[string]interface{}) (*domain.Relevant, error) {
  9 + return &domain.Relevant{}, nil
  10 +}
  11 +
  12 +func (translator *UserTranslator) ToReferrerFromRepresentation(data map[string]interface{}) (*domain.Referrer, error) {
  13 + return &domain.Referrer{}, nil
  14 +}
  15 +
  16 +func (translator *UserTranslator) ToUndertakerFromRepresentation(data map[string]interface{}) (*domain.Undertaker, error) {
  17 + return &domain.Undertaker{}, nil
  18 +}
  19 +
  20 +func (translator *UserTranslator) ToSalesmanFromRepresentation(data map[string]interface{}) (*domain.Salesman, error) {
  21 + return &domain.Salesman{}, nil
  22 +}
  23 +
  24 +func (translator *UserTranslator) ToOperatorFromRepresentation(data map[string]interface{}) (*domain.User, error) {
  25 + return &domain.User{}, nil
  26 +}