作者 陈志颖

feat:用户REST接口调整

正在显示 36 个修改的文件 包含 282 行增加74 行删除
... ... @@ -26,7 +26,7 @@ type ListContractUndertakerFeedbackQuery struct {
}
func (listContractUndertakerFeedbackQuery *ListContractUndertakerFeedbackQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (listContractUndertakerFeedbackQuery *ListContractUndertakerFeedbackQuery) ValidateQuery() error {
... ...
... ... @@ -26,7 +26,7 @@ type AgreeCooperationApplicationCommand struct {
}
func (agreeCooperationApplicationCommand *AgreeCooperationApplicationCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (agreeCooperationApplicationCommand *AgreeCooperationApplicationCommand) ValidateCommand() error {
... ...
... ... @@ -66,7 +66,7 @@ type ApplyForCooperationCommand struct {
}
func (applyForCooperationCommand *ApplyForCooperationCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (applyForCooperationCommand *ApplyForCooperationCommand) ValidateCommand() error {
... ...
... ... @@ -27,7 +27,7 @@ type BatchApprovalCooperationApplicationCommand struct {
}
func (batchApprovalCooperationApplicationCommand *BatchApprovalCooperationApplicationCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (batchApprovalCooperationApplicationCommand *BatchApprovalCooperationApplicationCommand) ValidateCommand() error {
... ...
... ... @@ -29,7 +29,7 @@ type CreateCooperationApplicationCommand struct {
}
func (createCooperationApplicationCommand *CreateCooperationApplicationCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (createCooperationApplicationCommand *CreateCooperationApplicationCommand) ValidateCommand() error {
... ...
... ... @@ -26,7 +26,7 @@ type RejectCooperationApplicationCommand struct {
}
func (rejectCooperationApplicationCommand *RejectCooperationApplicationCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (rejectCooperationApplicationCommand *RejectCooperationApplicationCommand) ValidateCommand() error {
... ...
... ... @@ -22,7 +22,7 @@ type RemoveCooperationApplicationCommand struct {
}
func (removeCooperationApplicationCommand *RemoveCooperationApplicationCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (removeCooperationApplicationCommand *RemoveCooperationApplicationCommand) ValidateCommand() error {
... ...
... ... @@ -31,7 +31,7 @@ type UpdateCooperationApplicationCommand struct {
}
func (updateCooperationApplicationCommand *UpdateCooperationApplicationCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (updateCooperationApplicationCommand *UpdateCooperationApplicationCommand) ValidateCommand() error {
... ...
... ... @@ -22,7 +22,7 @@ type GetCooperationApplicationQuery struct {
}
func (getCooperationApplicationQuery *GetCooperationApplicationQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (getCooperationApplicationQuery *GetCooperationApplicationQuery) ValidateQuery() error {
... ...
... ... @@ -28,7 +28,7 @@ type ListCooperationApplicationQuery struct {
}
func (listCooperationApplicationQuery *ListCooperationApplicationQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (listCooperationApplicationQuery *ListCooperationApplicationQuery) ValidateQuery() error {
... ...
... ... @@ -30,7 +30,7 @@ type SearchCooperationApplicationQuery struct {
}
func (searchCooperationApplicationQuery *SearchCooperationApplicationQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (searchCooperationApplicationQuery *SearchCooperationApplicationQuery) ValidateQuery() error {
... ...
... ... @@ -39,7 +39,7 @@ type UpdateDividendsOrderCommand struct {
}
func (updateDividendsOrderCommand *UpdateDividendsOrderCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (updateDividendsOrderCommand *UpdateDividendsOrderCommand) ValidateCommand() error {
... ...
... ... @@ -22,7 +22,7 @@ type GetDividendsOrderQuery struct {
}
func (getDividendsOrderQuery *GetDividendsOrderQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (getDividendsOrderQuery *GetDividendsOrderQuery) ValidateQuery() error {
... ...
... ... @@ -24,7 +24,7 @@ type ListDividendsOrdersQuery struct {
}
func (listDividendsOrdersQuery *ListDividendsOrdersQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (listDividendsOrdersQuery *ListDividendsOrdersQuery) ValidateQuery() error {
... ...
... ... @@ -28,7 +28,7 @@ type SearchDividendsOrderQuery struct {
}
func (searchDividendsOrderQuery *SearchDividendsOrderQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (searchDividendsOrderQuery *SearchDividendsOrderQuery) ValidateQuery() error {
... ...
... ... @@ -26,7 +26,7 @@ type SearchDividendsOrderNumberQuery struct {
}
func (searchDividendsOrderNumberQuery *SearchDividendsOrderNumberQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (searchDividendsOrderNumberQuery *SearchDividendsOrderNumberQuery) ValidateQuery() error {
... ...
... ... @@ -22,7 +22,7 @@ type RemoveDividendsReturnedOrderCommand struct {
}
func (removeDividendsReturnedOrderCommand *RemoveDividendsReturnedOrderCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (removeDividendsReturnedOrderCommand *RemoveDividendsReturnedOrderCommand) ValidateCommand() error {
... ...
... ... @@ -37,7 +37,7 @@ type UpdateDividendsReturnedOrderCommand struct {
}
func (updateDividendsReturnedOrderCommand *UpdateDividendsReturnedOrderCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (updateDividendsReturnedOrderCommand *UpdateDividendsReturnedOrderCommand) ValidateCommand() error {
... ...
... ... @@ -24,7 +24,7 @@ type ListDividendsReturnedOrderQuery struct {
}
func (listDividendsReturnedOrderQuery *ListDividendsReturnedOrderQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (listDividendsReturnedOrderQuery *ListDividendsReturnedOrderQuery) ValidateQuery() error {
... ...
... ... @@ -28,7 +28,7 @@ type SearchDividendsReturnedOrderQuery struct {
}
func (searchDividendsReturnedOrderQuery *SearchDividendsReturnedOrderQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (searchDividendsReturnedOrderQuery *SearchDividendsReturnedOrderQuery) ValidateQuery() error {
... ...
... ... @@ -61,10 +61,10 @@ func (cooperationContractRelevant *CooperationContractRelevant) Update(data map[
cooperationContractRelevant.Relevant.Org.Company.CompanyName = companyName.(string)
}
if roleId, ok := data["roleId"]; ok {
cooperationContractRelevant.Relevant.Role.RoleId = roleId.(int64)
cooperationContractRelevant.Relevant.Roles.RoleId = roleId.(int64)
}
if roleName, ok := data["roleName"]; ok {
cooperationContractRelevant.Relevant.Role.RoleName = roleName.(string)
cooperationContractRelevant.Relevant.Roles.RoleName = roleName.(string)
}
if userAvatar, ok := data["userAvatar"]; ok {
cooperationContractRelevant.Relevant.UserInfo.UserAvatar = userAvatar.(string)
... ...
... ... @@ -17,7 +17,7 @@ type Relevant struct {
// 用户所属的部门
Department *Department `json:"department"`
// 用户角色
Role *Role `json:"role"`
Roles []*Role `json:"roles"`
// 冗余字段,jsonb格式,不限制存放内容
UserInfo *UserInfo `json:"userInfo"`
// 用户类型,1员工,2共创用户,3公开
... ...
package domain_service
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/adaptor"
)
type CompanyService struct {
}
func (service *CompanyService) CompanyFrom(companyId int64) (*domain.Company, error) {
return nil, nil
if companyAdaptor, err := adaptor.NewCompanyAdaptor(); err != nil {
return nil, err
} else {
if company, err := companyAdaptor.ToCompany(companyId); err != nil {
return nil, err
} else {
return company, nil
}
}
}
func NewCompanyService() (*CompanyService, error) {
... ...
package domain_service
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/adaptor"
)
type OrganizationService struct {
}
func (service *OrganizationService) OrgFrom(companyId int64, orgId int64) (*domain.Org, error) {
return nil, nil
if organizationAdaptor, err := adaptor.NewOrganizationAdaptor(); err != nil {
return nil, err
} else {
if organization, err := organizationAdaptor.ToOrganization(companyId, orgId); err != nil {
return nil, err
} else {
return organization, nil
}
}
}
func NewOrganizationService() (*OrganizationService, error) {
... ...
... ... @@ -60,7 +60,7 @@ func TransformToCooperationContractDomainModelFromPgModels(
Org: relevant.Org,
Orgs: relevant.Orgs,
Department: relevant.Department,
Role: relevant.Role,
Roles: relevant.Role,
UserInfo: relevant.UserInfo,
UserType: relevant.UserType,
Status: relevant.Status,
... ...
... ... @@ -17,7 +17,7 @@ func TransformToCooperationContractRelevantDomainModelFromPgModels(cooperationCo
Org: cooperationContractRelevantModel.Org,
Orgs: cooperationContractRelevantModel.Orgs,
Department: cooperationContractRelevantModel.Department,
Role: cooperationContractRelevantModel.Role,
Roles: cooperationContractRelevantModel.Role,
UserInfo: cooperationContractRelevantModel.UserInfo,
UserType: cooperationContractRelevantModel.UserType,
Status: cooperationContractRelevantModel.Status,
... ...
... ... @@ -64,7 +64,7 @@ func (repository *CooperationContractRelevantRepository) Save(cooperationContrac
&cooperationContractRelevant.Relevant.Org,
&cooperationContractRelevant.Relevant.Orgs,
&cooperationContractRelevant.Relevant.Department,
&cooperationContractRelevant.Relevant.Role,
&cooperationContractRelevant.Relevant.Roles,
&cooperationContractRelevant.Relevant.UserInfo,
&cooperationContractRelevant.Relevant.UserType,
&cooperationContractRelevant.Relevant.Status,
... ... @@ -81,7 +81,7 @@ func (repository *CooperationContractRelevantRepository) Save(cooperationContrac
&cooperationContractRelevant.Relevant.Org,
&cooperationContractRelevant.Relevant.Orgs,
&cooperationContractRelevant.Relevant.Department,
&cooperationContractRelevant.Relevant.Role,
&cooperationContractRelevant.Relevant.Roles,
&cooperationContractRelevant.Relevant.UserInfo,
&cooperationContractRelevant.Relevant.UserType,
&cooperationContractRelevant.Relevant.Status,
... ... @@ -102,7 +102,7 @@ func (repository *CooperationContractRelevantRepository) Save(cooperationContrac
&cooperationContractRelevant.Relevant.Org,
&cooperationContractRelevant.Relevant.Orgs,
&cooperationContractRelevant.Relevant.Department,
&cooperationContractRelevant.Relevant.Role,
&cooperationContractRelevant.Relevant.Roles,
&cooperationContractRelevant.Relevant.UserInfo,
&cooperationContractRelevant.Relevant.UserType,
&cooperationContractRelevant.Relevant.Status,
... ... @@ -119,7 +119,7 @@ func (repository *CooperationContractRelevantRepository) Save(cooperationContrac
cooperationContractRelevant.Relevant.Org,
cooperationContractRelevant.Relevant.Orgs,
cooperationContractRelevant.Relevant.Department,
cooperationContractRelevant.Relevant.Role,
cooperationContractRelevant.Relevant.Roles,
cooperationContractRelevant.Relevant.UserInfo,
cooperationContractRelevant.Relevant.UserType,
cooperationContractRelevant.Relevant.Status,
... ...
... ... @@ -106,7 +106,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
Org: relevant.Org,
Orgs: relevant.Orgs,
Department: relevant.Department,
Role: relevant.Role,
Role: relevant.Roles,
UserInfo: relevant.UserInfo,
UserType: relevant.UserType,
Status: relevant.Status,
... ... @@ -267,7 +267,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
Org: relevantDomain.Org,
Orgs: relevantDomain.Orgs,
Department: relevantDomain.Department,
Role: relevantDomain.Role,
Role: relevantDomain.Roles,
UserInfo: relevantDomain.UserInfo,
UserType: relevantDomain.UserType,
Status: relevantDomain.Status,
... ...
... ... @@ -24,6 +24,7 @@ func (repository *CooperationProjectRepository) nextIdentify() (int64, error) {
id, err := IdWorker.NextId()
return id, err
}
func (repository *CooperationProjectRepository) Save(cooperationProject *domain.CooperationProject) (*domain.CooperationProject, error) {
sqlBuildFields := []string{
"cooperation_project_id",
... ... @@ -144,6 +145,7 @@ func (repository *CooperationProjectRepository) Save(cooperationProject *domain.
}
return cooperationProject, nil
}
func (repository *CooperationProjectRepository) Remove(cooperationProject *domain.CooperationProject) (*domain.CooperationProject, error) {
tx := repository.transactionContext.PgTx
cooperationProjectModel := new(models.CooperationProject)
... ... @@ -153,6 +155,7 @@ func (repository *CooperationProjectRepository) Remove(cooperationProject *domai
}
return cooperationProject, nil
}
func (repository *CooperationProjectRepository) FindOne(queryOptions map[string]interface{}) (*domain.CooperationProject, error) {
tx := repository.transactionContext.PgTx
cooperationProjectModel := new(models.CooperationProject)
... ... @@ -171,6 +174,7 @@ func (repository *CooperationProjectRepository) FindOne(queryOptions map[string]
return transform.TransformToCooperationProjectDomainModelFromPgModels(cooperationProjectModel)
}
}
func (repository *CooperationProjectRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.CooperationProject, error) {
tx := repository.transactionContext.PgTx
var cooperationProjectModels []*models.CooperationProject
... ... @@ -191,6 +195,7 @@ func (repository *CooperationProjectRepository) Find(queryOptions map[string]int
return int64(count), cooperationProjects, nil
}
}
func NewCooperationProjectRepository(transactionContext *pgTransaction.TransactionContext) (*CooperationProjectRepository, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
... ...
... ... @@ -17,7 +17,6 @@ func (adaptor *UserAdaptor) ToParticipator(companyId int64, orgId int64, userId
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)
... ... @@ -57,7 +56,6 @@ func (adaptor *UserAdaptor) ToParticipator(companyId int64, orgId int64, userId
return user, nil
}
}
}
return map[string]interface{}{}, nil
}
... ...
... ... @@ -9,6 +9,18 @@ import (
"time"
)
// MessageCode 消息码
type MessageCode struct {
Code int `json:"code"`
Msg string `json:"msg"`
}
// GatewayResponse 统一消息返回格式
type GatewayResponse struct {
MessageCode
Data json.RawMessage `json:"data"`
}
type httplibBaseServiceGateway struct {
baseURL string
connectTimeout time.Duration
... ... @@ -59,3 +71,14 @@ func (serviceGateway *httplibBaseServiceGateway) responseHandle(response map[str
}
return data, err
}
func (serviceGateway *httplibBaseServiceGateway) getResponseData(result GatewayResponse, data interface{}) error {
if result.Code != 0 {
return fmt.Errorf(result.Msg)
}
err := json.Unmarshal(result.Data, data)
if err != nil {
return err
}
return nil
}
... ...
package service_gateway
import (
"encoding/json"
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/constant"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/service_gateway/translator"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/log"
"strconv"
"strings"
"time"
... ... @@ -12,29 +16,43 @@ type HttplibUserServiceGateway struct {
}
// GetUser 获取用户
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"}, "/")
func (serviceGateway *HttplibUserServiceGateway) GetUser(companyId int64, orgId int64, uid int64) (*translator.UserDetail, error) {
uidStr := strconv.FormatInt(uid, 10)
url := serviceGateway.baseURL + "/user/" + uidStr
request := serviceGateway.createRequest(url, "get")
options := make(map[string]interface{})
options["uid"] = uid
_, 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
//response := make(map[string]interface{})
//err2 := request.ToJSON(&response)
//if err2 != nil {
// return nil, err2
//}
//data, err := serviceGateway.responseHandle(response)
//return data, err
byteResult, err := request.Bytes()
if err != nil {
return nil, fmt.Errorf("获取获取用户失败:%w", err)
}
log.Logger.Debug("获取用户模块请求数据:获取用户。", map[string]interface{}{
"result": string(byteResult),
})
var result GatewayResponse
err = json.Unmarshal(byteResult, &result)
if err != nil {
return nil, fmt.Errorf("解析获取用户:%w", err)
}
var data translator.UserDetail
err = serviceGateway.getResponseData(result, &data)
return &data, err
}
// GetUsers 获取用户
func (serviceGateway *HttplibUserServiceGateway) GetUsers(companyId int64, orgId int64, uids []int64) (map[string]interface{}, error) {
companyIdStr := strconv.FormatInt(companyId, 10)
url := strings.Join([]string{serviceGateway.baseURL, "companies/" + companyIdStr + "/users/get-user"}, "/")
url := strings.Join([]string{serviceGateway.baseURL, "user/" + companyIdStr + "/users/get-user"}, "/")
request := serviceGateway.createRequest(url, "get")
options := make(map[string]interface{})
options["uids"] = uids
... ... @@ -54,19 +72,25 @@ func (serviceGateway *HttplibUserServiceGateway) GetUsers(companyId int64, orgId
// GetCompany 获取公司信息
func (serviceGateway *HttplibUserServiceGateway) GetCompany(companyId int64) (map[string]interface{}, error) {
companyIdStr := strconv.FormatInt(companyId, 10)
url := strings.Join([]string{serviceGateway.baseURL, "companies/" + companyIdStr}, "/")
url := serviceGateway.baseURL + "/company/" + companyIdStr
request := serviceGateway.createRequest(url, "get")
options := make(map[string]interface{})
options["companyId"] = companyId
_, err1 := request.JSONBody(options)
if err1 != nil {
return nil, err1
} else {
log.Logger.Debug("向用户模块请求数据:返回企业。", map[string]interface{}{
"api": "get:" + url,
"param": options,
})
}
response := make(map[string]interface{})
err2 := request.ToJSON(&response)
if err2 != nil {
return nil, err2
}
data, err := serviceGateway.responseHandle(response)
return data, err
}
... ... @@ -93,9 +117,8 @@ func (serviceGateway *HttplibUserServiceGateway) GetDepartment(companyId int64,
// GetOrganization 获取组织信息
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}, "/")
url := serviceGateway.baseURL + "/org/" + organizationIdStr
request := serviceGateway.createRequest(url, "get")
options := make(map[string]interface{})
options["orgId"] = organizationId
... ...
... ... @@ -5,6 +5,7 @@ type UserServiceGateway interface {
GetUsers(companyId int64, orgId int64, uids []int64) (map[string]interface{}, error)
GetCompany(companyId int64) (map[string]interface{}, error)
GetOrganization(companyId int64, organizationId int64) (map[string]interface{}, error)
GetDepartment(companyId int64, departmentId int64) (map[string]interface{}, error)
UserInMenu(companyId int64, userId int64, menuCode string) (bool, error)
UserInOrganization(companyId int64, orgId int64, userId int64) (bool, error)
}
... ...
package translator
import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
"time"
)
type CompanyTranslator struct {
}
func (translator *CompanyTranslator) ToCompanyFromRepresentation(data map[string]interface{}) (*domain.Company, error) {
type CompanyDetail struct {
CompanyId int64 `json:"companyId"`
CompanyConfig struct {
SystemName string `json:"systemName"`
Theme string `json:"theme"`
} `json:"companyConfig"`
CompanyInfo struct {
CompanyName string `json:"companyName"`
Scale string `json:"scale"`
IndustryCategory string `json:"industryCategory"`
RegisteredTime time.Time `json:"registeredTime"`
} `json:"companyInfo"`
Status int `json:"status"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
func (translator *CompanyTranslator) ToCompanyFromRepresentation(company *CompanyDetail) (*domain.Company, error) {
return &domain.Company{
CompanyId: 0,
CompanyName: "",
CompanyId: company.CompanyId,
CompanyName: company.CompanyInfo.CompanyName,
}, nil
}
... ...
package translator
import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
"time"
)
type OrganizationTranslator struct {
}
func (translator *OrganizationTranslator) ToOrganizationFromRepresentation(data map[string]interface{}) (*domain.Org, error) {
type OrganizationDetail struct {
OrgId int64 `json:"orgId"`
CompanyId int64 `json:"companyId"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
DeletedAt time.Time `json:"deletedAt"`
OrgCode string `json:"orgCode"`
OrgName string `json:"orgName"`
Ext struct {
} `json:"ext"`
IsOrg bool `json:"isOrg"`
OrgStatus int `json:"orgStatus"`
}
func (translator *OrganizationTranslator) ToOrganizationFromRepresentation(organization *OrganizationDetail) (*domain.Org, error) {
return &domain.Org{
OrgId: 0,
OrgName: "",
Company: nil,
OrgId: organization.OrgId,
OrgName: organization.OrgName,
Company: &domain.Company{
CompanyId: organization.CompanyId,
CompanyLogo: "",
CompanyName: "",
},
}, nil
}
... ...
package translator
import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
"time"
)
type UserTranslator struct {
}
func (translator *UserTranslator) ToRelevantFromRepresentation(data map[string]interface{}) (*domain.Relevant, error) {
type UserDetail struct {
UserId int64 `json:"userId"`
UserBaseId int64 `json:"userBaseId"`
UserType int32 `json:"userType"`
UserCode string `json:"userCode"`
EnableStatus int32 `json:"enableStatus"`
CooperationInfo struct {
CooperationCompany string `json:"cooperationCompany"`
CooperationDeadline time.Time `json:"cooperationDeadline"`
} `json:"cooperationInfo,omitempty"`
UserInfo struct {
Phone string `json:"phone"`
UserCode string `json:"userCode"`
Email string `json:"email"`
UserName string `json:"userName"`
Avatar string `json:"avatar"`
} `json:"userInfo,omitempty"`
Company *struct {
CompanyId int64 `json:"companyId"`
CompanyName string `json:"companyName"`
Scale string `json:"scale"`
IndustryCategory string `json:"industryCategory"`
RegisteredTime time.Time `json:"registeredTime"`
Status int64 `json:"status"`
} `json:"company,omitempty"`
Org *struct {
OrgId int64 `json:"orgId"`
OrgCode string `json:"orgCode"`
OrgName string `json:"orgName"`
} `json:"org,omitempty"`
Department *struct {
DepartmentId int64 `json:"departmentId"`
DepartmentName string `json:"departmentName"`
} `json:"department,omitempty"`
UserRole []struct {
RoleID int64 `json:"roleId"`
RoleName string `json:"roleName"`
Ext struct {
OrgName string `json:"orgName"`
} `json:"ext,omitempty"`
} `json:"userRole"`
UserOrg []struct {
OrgID int64 `json:"orgId"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
DeletedAt time.Time `json:"deletedAt"`
OrgName string `json:"orgName"`
} `json:"userOrg"`
}
func (translator *UserTranslator) ToRelevantFromRepresentation(user *UserDetail) (*domain.Relevant, error) {
var orgs []*domain.Org
for _, org := range user.UserOrg {
orgs = append(orgs, &domain.Org{
OrgId: org.OrgID,
OrgName: org.OrgName,
Company: &domain.Company{
CompanyId: user.Company.CompanyId,
CompanyLogo: "",
CompanyName: user.Company.CompanyName,
},
})
}
var roles []*domain.Role
for _, role := range user.UserRole {
roles = append(roles, &domain.Role{
RoleId: int64(role.RoleID),
RoleName: role.RoleName,
})
}
return &domain.Relevant{
UserId: data["userId"].(int64),
UserBaseId: data["userBaseId"].(int64),
Org: nil,
Orgs: nil,
Department: nil,
Role: nil,
UserInfo: nil,
UserType: 0,
Status: 0,
Company: nil,
UserId: user.UserId,
UserBaseId: user.UserBaseId,
Org: &domain.Org{
OrgId: user.Org.OrgId,
OrgName: user.Org.OrgName,
Company: &domain.Company{
CompanyId: user.Company.CompanyId,
CompanyLogo: "",
CompanyName: user.Company.CompanyName,
},
},
Orgs: orgs,
Department: &domain.Department{
DepartmentId: user.Department.DepartmentId,
DepartmentName: user.Department.DepartmentName,
DepartmentNumber: "",
IsOrganization: false,
},
Roles: roles,
UserInfo: &domain.UserInfo{
UserAvatar: user.UserInfo.Avatar,
UserEmail: user.UserInfo.Email,
UserName: user.UserInfo.UserName,
UserPhone: user.UserInfo.Phone,
UserAccount: "",
},
UserType: user.UserType,
Status: user.EnableStatus,
Company: &domain.Company{
CompanyId: user.Company.CompanyId,
CompanyLogo: "",
CompanyName: user.Company.CompanyName,
},
}, nil
}
... ...