作者 陈志颖

Merge branch 'dev-chenzhiying' into dev

... ... @@ -86,7 +86,7 @@ type CreateCooperationContractCommand struct {
// 共创合约名称
CooperationContractName string `cname:"共创合约名称" json:"cooperationContractName" valid:"Required"`
// 共创模式编码
CooperationModeNumber string `cname:"共创模式编码" json:"cooperationModeNumber,omitempty"`
CooperationModeNumber string `cname:"共创模式编码" json:"cooperationModeNumber" valid:"Required"`
// 共创合约发起人uid
SponsorUid string `cname:"共创合约发起人uid" json:"sponsorUid,omitempty"`
// 业绩分红激励规则列表
... ... @@ -108,7 +108,14 @@ type CreateCooperationContractCommand struct {
}
func (createCooperationContractCommand *CreateCooperationContractCommand) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
// 激励规则自定义校验
if len(createCooperationContractCommand.DividendsIncentivesRules) == 0 && len(createCooperationContractCommand.MoneyIncentivesRules) == 0 {
validation.Error("激励规则不能为空")
}
// 承接人列表校验
if len(createCooperationContractCommand.Undertakers) == 0 {
validation.Error("承接人不能为空")
}
}
func (createCooperationContractCommand *CreateCooperationContractCommand) ValidateCommand() error {
... ...
... ... @@ -42,7 +42,31 @@ type UpdateCooperationContractCommand struct {
}
func (updateCooperationContractCommand *UpdateCooperationContractCommand) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
// 激励规则自定义校验
if len(updateCooperationContractCommand.DividendsIncentivesRules) <= 0 && len(updateCooperationContractCommand.MoneyIncentivesRules) <= 0 {
validation.Error("激励规则不能为空")
} else {
for i, _ := range updateCooperationContractCommand.DividendsIncentivesRules {
if updateCooperationContractCommand.DividendsIncentivesRules[i].DividendsIncentivesRuleId == "" {
updateCooperationContractCommand.DividendsIncentivesRules[i].DividendsIncentivesRuleId = "0"
}
}
for j, _ := range updateCooperationContractCommand.MoneyIncentivesRules {
if updateCooperationContractCommand.MoneyIncentivesRules[j].MoneyIncentivesRuleId == "" {
updateCooperationContractCommand.MoneyIncentivesRules[j].MoneyIncentivesRuleId = "0"
}
}
}
// 承接人列表校验
if len(updateCooperationContractCommand.Undertakers) <= 0 {
validation.Error("承接人不能为空")
} else {
for i, _ := range updateCooperationContractCommand.Undertakers {
if updateCooperationContractCommand.Undertakers[i].UndertakerId == "" {
updateCooperationContractCommand.Undertakers[i].UndertakerId = "0"
}
}
}
}
func (updateCooperationContractCommand *UpdateCooperationContractCommand) ValidateCommand() error {
... ...
... ... @@ -166,7 +166,6 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC
referrerDomain = data
}
}
// 获取业务员
var salesmanDomain *domain.Salesman
salesmanUid, _ := strconv.ParseInt(undertaker.SalesmanId, 10, 64)
... ... @@ -179,6 +178,17 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC
}
}
// 解析附件
var attachments []*domain.Attachment
for _, attachment := range undertaker.ContractAttachment {
attachments = append(attachments, &domain.Attachment{
FileType: attachment.FileType,
Name: attachment.Name,
Url: attachment.Url,
FileSize: attachment.FileSize,
})
}
undertakers = append(undertakers, &domain.Undertaker{
UndertakerId: 0,
UserId: undertakerDomain.UserId,
... ... @@ -192,9 +202,9 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC
UserType: undertakerDomain.UserType,
Referrer: referrerDomain,
Salesman: salesmanDomain,
Status: 0,
Status: undertakerDomain.Status,
Company: company,
ContractAttachment: nil,
ContractAttachment: attachments,
})
}
... ... @@ -282,6 +292,12 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC
if cooperationMode == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", createCooperationContractCommand.CooperationModeNumber))
} else {
incentivesType := 0
if len(dividendsIncentivesRules) > 0 {
incentivesType = domain.TYPE_DIVIDNEDS_INCENTIVES
} else if len(moneyIncentivesRules) > 0 {
incentivesType = domain.TYPE_MONEY_INCENTIVES
}
newCooperationContract := &domain.CooperationContract{
CooperationContractDescription: createCooperationContractCommand.CooperationContractDescription,
CooperationContractName: createCooperationContractCommand.CooperationContractName,
... ... @@ -297,6 +313,7 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC
Operator: operator,
DividendsIncentivesRules: dividendsIncentivesRules,
MoneyIncentivesRules: moneyIncentivesRules,
IncentivesType: int32(incentivesType),
Undertakers: undertakers,
RelevantPeople: relevantPeople,
OperateTime: time.Now(),
... ... @@ -314,7 +331,7 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC
} else {
cooperationContractRepository = value
}
// 保存共创合约
if cooperationContract, err := cooperationContractRepository.Save(newCooperationContract); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
... ... @@ -795,6 +812,7 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
Company: relevantDomain.Company,
})
}
// 更新合约相关人
cooperationContract.RelevantPeople = relevantPeople
... ...
... ... @@ -4,6 +4,11 @@ import (
"time"
)
const (
TYPE_DIVIDNEDS_INCENTIVES = iota + 1
TYPE_MONEY_INCENTIVES
)
// CooperationContract 共创项目合约实体
type CooperationContract struct {
// 共创合约ID
... ...
... ... @@ -8,7 +8,7 @@ import (
type CooperationContractRelevant struct {
tableName string `comment:"共创合约相关人" pg:"cooperation_contract_relevants,alias:cooperation_contract_relevant"`
// 共创合约相关人id
CooperationContractRelevantId int64 `comment:"共创合约相关人id" pg:"pk:cooperation_contract_relevant_id"`
CooperationContractRelevantId int64 `comment:"共创合约相关人id" pg:",pk:cooperation_contract_relevant_id"`
// 共创合约编号
CooperationContractNumber string `comment:"共创合约编号"`
// 合约人userId
... ...
... ... @@ -8,7 +8,7 @@ import (
type CooperationContractUndertaker struct {
tableName string `comment:"共创合约承接人" pg:"cooperation_contract_undertakers,alias:cooperation_contract_undertaker"`
// 共创合约承接人id
CooperationContractUndertakerId int64 `comment:"共创合约承接人id" pg:"pk:cooperation_contract_undertaker_id"`
CooperationContractUndertakerId int64 `comment:"共创合约承接人id" pg:",pk:cooperation_contract_undertaker_id"`
// 共创合约编号
CooperationContractNumber string `comment:"共创合约编号"`
// 共创合约承接人uid
... ...
... ... @@ -10,6 +10,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/transform"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/log"
"time"
)
... ... @@ -159,6 +160,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
var dividendsIncentivesRulesModel []*models.DividendsIncentivesRule
for _, rule := range cooperationContract.DividendsIncentivesRules {
dividendsIncentivesRulesModel = append(dividendsIncentivesRulesModel, &models.DividendsIncentivesRule{
DividendsIncentivesRuleId: 0,
CooperationContractNumber: cooperationContract.CooperationContractNumber,
ReferrerPercentage: rule.ReferrerPercentage,
SalesmanPercentage: rule.SalesmanPercentage,
... ... @@ -183,6 +185,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
var moneyIncentivesRulesModel []*models.MoneyIncentivesRule
for _, rule := range cooperationContract.MoneyIncentivesRules {
moneyIncentivesRulesModel = append(moneyIncentivesRulesModel, &models.MoneyIncentivesRule{
MoneyIncentivesRuleId: 0,
CooperationContractNumber: cooperationContract.CooperationContractNumber,
MoneyIncentivesAmount: rule.MoneyIncentivesAmount,
MoneyIncentivesStage: rule.MoneyIncentivesStage,
... ... @@ -278,6 +281,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
var cooperationContractRelevantPeopleToAddModels []*models.CooperationContractRelevant
for _, relevantDomain := range cooperationContractRelevantPeopleToAdd {
cooperationContractRelevantPeopleToAddModels = append(cooperationContractRelevantPeopleToAddModels, &models.CooperationContractRelevant{
CooperationContractRelevantId: 0,
CooperationContractNumber: relevantDomain.CooperationContractNumber,
UserId: relevantDomain.UserId,
UserBaseId: relevantDomain.UserBaseId,
... ... @@ -333,9 +337,14 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
}
}
}
log.Logger.Info("待删除的相关人", map[string]interface{}{
"待删除的相关人": relevantModelsToDelete,
})
if len(relevantModelsToDelete) > 0 {
if _, err := tx.Model(&relevantModelsToDelete).Delete(); err != nil {
return nil, err
}
}
/************************* 更新承接人 ****************************/
// 获取承接人列表
... ... @@ -383,6 +392,9 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
CreatedAt: time.Now(),
})
}
log.Logger.Info("待添加的承接人", map[string]interface{}{
"待添加的承接人": cooperationContractUndertakersToAddModels,
})
// 添加承接人
if len(cooperationContractUndertakersToAddModels) > 0 {
if _, err := tx.Model(&cooperationContractUndertakersToAddModels).Insert(); err != nil {
... ... @@ -406,6 +418,9 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
}
}
}
log.Logger.Info("待更新的承接人", map[string]interface{}{
"待更新的承接人": undertakerModelsToUpdate,
})
if len(undertakerModelsToUpdate) > 0 {
if _, err := tx.Model(&undertakerModelsToUpdate).WherePK().Update(); err != nil {
return nil, err
... ... @@ -422,9 +437,14 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
}
}
}
log.Logger.Info("待删除的承接人", map[string]interface{}{
"待删除的承接人": undertakerModelsToDelete,
})
if len(undertakerModelsToDelete) > 0 {
if _, err := tx.Model(&undertakerModelsToDelete).Delete(); err != nil {
return nil, err
}
}
/************************ 更新分红激励规则 **************************/
// 获取分红激励规则列表
... ... @@ -471,6 +491,9 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
})
}
// 添加分红激励规则
log.Logger.Info("待添加的分红激励规则", map[string]interface{}{
"dividendsIncentivesRulesToAddModels": dividendsIncentivesRulesToAddModels,
})
if len(dividendsIncentivesRulesToAddModels) > 0 {
if _, err := tx.Model(&dividendsIncentivesRulesToAddModels).Insert(); err != nil {
return nil, err
... ... @@ -493,6 +516,9 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
}
}
}
log.Logger.Info("待更新的分红激励规则", map[string]interface{}{
"dividendsRuleModelsToUpdate": dividendsRuleModelsToUpdate,
})
if len(dividendsRuleModelsToUpdate) > 0 {
if _, err := tx.Model(&dividendsRuleModelsToUpdate).WherePK().Update(); err != nil {
return nil, err
... ... @@ -509,9 +535,12 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
}
}
}
if _, err := tx.Model(&dividendsIncentivesRuleModelsToDelete).Delete(); err != nil {
log.Logger.Info("待删除的分红激励规则", map[string]interface{}{})
if len(dividendsIncentivesRuleModelsToDelete) > 0 {
if _, err := tx.Model(&dividendsIncentivesRuleModelsToDelete).WherePK().Delete(); err != nil {
return nil, err
}
}
/********************** 更新金额激励规则 **************************/
var moneyIncentivesRulesFetched []*models.MoneyIncentivesRule
... ... @@ -558,6 +587,9 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
})
}
// 添加金额激励规则
log.Logger.Info("待添加的金额激励规则", map[string]interface{}{
"moneyIncentivesRulesToAddModels": moneyIncentivesRulesToAddModels,
})
if len(moneyIncentivesRulesToAddModels) > 0 {
if _, err := tx.Model(&moneyIncentivesRulesToAddModels).Insert(); err != nil {
return nil, err
... ... @@ -580,6 +612,9 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
}
}
}
log.Logger.Info("待更新的金额激励规则", map[string]interface{}{
"moneyRuleModelsToUpdate": moneyRuleModelsToUpdate,
})
if len(moneyRuleModelsToUpdate) > 0 {
if _, err := tx.Model(&moneyRuleModelsToUpdate).WherePK().Update(); err != nil {
return nil, err
... ... @@ -596,10 +631,14 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
}
}
}
if _, err := tx.Model(&moneyIncentivesRuleModelsToDelete).Delete(); err != nil {
log.Logger.Info("待删除的金额激励规则", map[string]interface{}{
"moneyIncentivesRuleModelsToDelete": moneyIncentivesRuleModelsToDelete,
})
if len(moneyIncentivesRuleModelsToDelete) > 0 {
if _, err := tx.Model(&moneyIncentivesRuleModelsToDelete).WherePK().Delete(); err != nil {
return nil, err
}
}
}
return cooperationContract, nil
}
... ... @@ -693,7 +732,7 @@ func (repository *CooperationContractRepository) Remove(cooperationContract *dom
if err := cooperationContractUndertakerQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil {
return nil, err
} else {
if _, err := tx.Model(&cooperationContractUndertakerModels).Delete(); err != nil {
if _, err := tx.Model(&cooperationContractUndertakerModels).WherePK().Delete(); err != nil {
return nil, err
}
}
... ... @@ -703,7 +742,7 @@ func (repository *CooperationContractRepository) Remove(cooperationContract *dom
if err := cooperationContractRelevantQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil {
return nil, err
} else {
if _, err := tx.Model(&cooperationContractRelevantModels).Delete(); err != nil {
if _, err := tx.Model(&cooperationContractRelevantModels).WherePK().Delete(); err != nil {
return nil, err
}
}
... ... @@ -730,42 +769,50 @@ func (repository *CooperationContractRepository) BatchRemove(cooperationContract
if err := dividendsIncentivesRuleQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil {
return nil, err
} else {
if len(dividendsIncentivesRuleModels) > 0 {
if _, err := tx.Model(&dividendsIncentivesRuleModels).WherePK().Delete(); err != nil {
return nil, err
}
}
}
// 获取金额激励规则列表
var moneyIncentivesRuleModels []*models.MoneyIncentivesRule
moneyIncentivesRuleQuery := tx.Model(&moneyIncentivesRuleModels)
if err := moneyIncentivesRuleQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil {
return nil, err
} else {
if len(moneyIncentivesRuleModels) > 0 {
if _, err := tx.Model(&moneyIncentivesRuleModels).WherePK().Delete(); err != nil {
return nil, err
}
}
}
// 获取承接人列表
var cooperationContractUndertakerModels []*models.CooperationContractUndertaker
cooperationContractUndertakerQuery := tx.Model(&cooperationContractUndertakerModels)
if err := cooperationContractUndertakerQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil {
return nil, err
} else {
if _, err := tx.Model(&cooperationContractUndertakerModels).Delete(); err != nil {
if len(cooperationContractUndertakerModels) > 0 {
if _, err := tx.Model(&cooperationContractUndertakerModels).WherePK().Delete(); err != nil {
return nil, err
}
}
}
// 获取相关人列表
var cooperationContractRelevantModels []*models.CooperationContractRelevant
cooperationContractRelevantQuery := tx.Model(&cooperationContractRelevantModels)
if err := cooperationContractRelevantQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil {
return nil, err
} else {
if _, err := tx.Model(&cooperationContractRelevantModels).Delete(); err != nil {
if len(cooperationContractRelevantModels) > 0 {
if _, err := tx.Model(&cooperationContractRelevantModels).WherePK().Delete(); err != nil {
return nil, err
}
}
}
}
}
return cooperationContracts, nil
}
... ...
... ... @@ -118,94 +118,266 @@ func (translator *UserTranslator) ToRelevantFromRepresentation(user *UserDetail)
}
func (translator *UserTranslator) ToReferrerFromRepresentation(user *UserDetail) (*domain.Referrer, 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.Referrer{
UserId: user.UserId,
UserBaseId: user.UserBaseId,
Roles: nil,
Orgs: nil,
Org: nil,
Department: nil,
Roles: roles,
Orgs: orgs,
Org: &domain.Org{
OrgId: user.Org.OrgId,
OrgName: user.Org.OrgName,
Company: nil,
},
Department: &domain.Department{
DepartmentId: user.Department.DepartmentId,
DepartmentName: user.Department.DepartmentName,
DepartmentNumber: "",
IsOrganization: false,
},
Company: &domain.Company{
CompanyId: user.Company.CompanyId,
CompanyLogo: "",
CompanyName: user.Company.CompanyName,
},
UserInfo: nil,
UserType: 0,
UserType: user.UserType,
UserName: user.UserInfo.UserName,
UserPhone: user.UserInfo.Phone,
}, nil
}
func (translator *UserTranslator) ToUndertakerFromRepresentation(user *UserDetail) (*domain.Undertaker, 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.Undertaker{
UserId: user.UserId,
UserBaseId: user.UserBaseId,
Org: nil,
Orgs: nil,
Department: nil,
Roles: nil,
UserInfo: nil,
UserType: 0,
Org: &domain.Org{
OrgId: user.Org.OrgId,
OrgName: user.Org.OrgName,
Company: nil,
},
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,
Status: 0,
Company: nil,
UserAccount: "",
},
UserType: user.UserType,
UserName: user.UserInfo.UserName,
UserPhone: user.UserInfo.Phone,
Status: user.EnableStatus,
Company: &domain.Company{
CompanyId: user.Company.CompanyId,
CompanyLogo: "",
CompanyName: user.Company.CompanyName,
},
ContractAttachment: nil,
}, nil
}
func (translator *UserTranslator) ToSalesmanFromRepresentation(user *UserDetail) (*domain.Salesman, 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.Salesman{
UserId: user.UserId,
UserBaseId: user.UserBaseId,
Roles: nil,
Orgs: nil,
Org: nil,
Department: nil,
Roles: roles,
Orgs: orgs,
Org: &domain.Org{
OrgId: user.Org.OrgId,
OrgName: user.Org.OrgName,
Company: nil,
UserInfo: nil,
UserType: 0,
},
Department: &domain.Department{
DepartmentId: user.Department.DepartmentId,
DepartmentName: user.Department.DepartmentName,
DepartmentNumber: "",
IsOrganization: false,
},
Company: &domain.Company{
CompanyId: user.Company.CompanyId,
CompanyLogo: "",
CompanyName: user.Company.CompanyName,
},
UserInfo: &domain.UserInfo{
UserAvatar: user.UserInfo.Avatar,
UserEmail: user.UserInfo.Email,
UserName: user.UserInfo.UserName,
UserPhone: user.UserInfo.Phone,
UserAccount: "",
},
UserType: user.UserType,
UserName: user.UserInfo.UserName,
UserPhone: user.UserInfo.Phone,
}, nil
}
func (translator *UserTranslator) ToOperatorFromRepresentation(user *UserDetail) (*domain.User, 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.User{
UserId: user.UserId,
UserBaseId: user.UserBaseId,
Org: nil,
Orgs: nil,
Department: nil,
Roles: nil,
Org: &domain.Org{
OrgId: user.Org.OrgId,
OrgName: user.Org.OrgName,
Company: nil,
},
Orgs: orgs,
Department: &domain.Department{
DepartmentId: user.Department.DepartmentId,
DepartmentName: user.Department.DepartmentName,
DepartmentNumber: "",
IsOrganization: false,
},
Roles: roles,
UserInfo: &domain.UserInfo{
UserName: user.UserInfo.UserName,
UserPhone: user.UserInfo.Phone,
UserAvatar: user.UserInfo.Avatar,
},
UserType: 0,
UserType: user.UserType,
UserName: user.UserInfo.UserName,
UserPhone: user.UserInfo.Phone,
Status: 0,
Company: nil,
Status: user.EnableStatus,
Company: &domain.Company{
CompanyId: user.Company.CompanyId,
CompanyLogo: "",
CompanyName: user.Company.CompanyName,
},
}, nil
}
func (translator *UserTranslator) ToUserFromRepresentation(user *UserDetail) (*domain.User, 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.User{
UserId: user.UserId,
UserBaseId: user.UserBaseId,
Org: nil,
Orgs: nil,
Department: nil,
Roles: nil,
Org: &domain.Org{
OrgId: user.Org.OrgId,
OrgName: user.Org.OrgName,
Company: nil,
},
Orgs: orgs,
Department: &domain.Department{
DepartmentId: user.Department.DepartmentId,
DepartmentName: user.Department.DepartmentName,
DepartmentNumber: "",
IsOrganization: false,
},
Roles: roles,
UserInfo: &domain.UserInfo{
UserName: user.UserInfo.UserName,
UserPhone: user.UserInfo.Phone,
UserAvatar: user.UserInfo.Avatar,
},
UserType: 0,
UserType: user.UserType,
UserName: user.UserInfo.UserName,
UserPhone: user.UserInfo.Phone,
Status: 0,
Company: nil,
Status: user.EnableStatus,
Company: &domain.Company{
CompanyId: user.Company.CompanyId,
CompanyLogo: "",
CompanyName: user.Company.CompanyName,
},
}, nil
}
... ...