作者 陈志颖

refactor:共创合约仓储优化

... ... @@ -195,7 +195,7 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC
UserId: undertakerDomain.UserId,
CooperationContractNumber: contractNumber,
UserBaseId: undertakerDomain.UserBaseId,
Org: undertakerDomain.Org,
Org: organization,
Orgs: undertakerDomain.Orgs,
Department: undertakerDomain.Department,
Roles: undertakerDomain.Roles,
... ... @@ -227,14 +227,14 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC
CooperationContractNumber: contractNumber,
UserId: relevantDomain.UserId,
UserBaseId: relevantDomain.UserBaseId,
Org: relevantDomain.Org,
Org: organization,
Orgs: relevantDomain.Orgs,
Department: relevantDomain.Department,
Roles: relevantDomain.Roles,
UserInfo: relevantDomain.UserInfo,
UserType: relevantDomain.UserType,
Status: relevantDomain.Status,
Company: relevantDomain.Company,
Company: company,
})
}
... ...
... ... @@ -276,40 +276,44 @@ func (repository *CooperationApplicationRepository) Find(queryOptions map[string
if count > 0 {
for _, cooperationApplicationModel := range cooperationApplicationModels {
// 获取共创项目
cooperationProjectModel := new(models.CooperationProject)
cooperationProjectQuery := tx.Model(cooperationProjectModel)
cooperationProjectQuery.AllWithDeleted()
if err := cooperationProjectQuery.
var cooperationProjectModels []*models.CooperationProject
cooperationProjectQuery := tx.Model(&cooperationProjectModels)
if countProject, err := cooperationProjectQuery.
Where("company->>'companyId' = '?'", cooperationApplicationModel.Company.CompanyId).
Where("org->>'orgId' = '?'", cooperationApplicationModel.Org.OrgId).
Where("cooperation_project_number = ?", cooperationApplicationModel.CooperationProjectNumber).
First(); err != nil {
Limit(1).
SelectAndCount(); err != nil {
log.Logger.Error("申请关联的共创项目不存在", map[string]interface{}{
"cooperationApplicationModel": cooperationApplicationModel,
})
return 0, nil, fmt.Errorf("申请关联的共创项目不存在")
}
} else {
if countProject > 0 {
// 获取共创模式
cooperationModeModel := new(models.CooperationMode)
cooperationModeQuery := tx.Model(cooperationModeModel)
cooperationModeQuery.AllWithDeleted()
if err := cooperationModeQuery.
var cooperationModeModels []*models.CooperationMode
cooperationModeQuery := tx.Model(&cooperationModeModels)
if countMode, err := cooperationModeQuery.
Where("company->>'companyId' = '?'", cooperationApplicationModel.Company.CompanyId).
Where("org->>'orgId' = '?'", cooperationApplicationModel.Org.OrgId).
Where("cooperation_mode_number = ?", cooperationProjectModel.CooperationModeNumber).
First(); err != nil {
Where("cooperation_mode_number = ?", cooperationProjectModels[0].CooperationModeNumber).
Limit(1).
SelectAndCount(); err != nil {
log.Logger.Error("申请关联的共创模式不存在", map[string]interface{}{
"cooperationApplicationModel": cooperationApplicationModel,
})
return 0, nil, fmt.Errorf("申请关联的共创模式不存在")
}
if cooperationApplication, err := transform.TransformToCooperationApplicationDomainModelFromPgModels(cooperationApplicationModel, cooperationProjectModel, cooperationModeModel); err != nil {
} else {
if countMode > 0 {
if cooperationApplication, err := transform.TransformToCooperationApplicationDomainModelFromPgModels(cooperationApplicationModel, cooperationProjectModels[0], cooperationModeModels[0]); err != nil {
return 0, cooperationApplications, err
} else {
cooperationApplications = append(cooperationApplications, cooperationApplication)
}
}
}
}
}
}
}
return int64(count), cooperationApplications, nil
}
}
... ...
... ... @@ -1099,15 +1099,19 @@ func (repository *CooperationContractRepository) Find(queryOptions map[string]in
if count > 0 {
for _, cooperationContractModel := range cooperationContractModels {
// 获取共创模式
cooperationModeModel := new(models.CooperationMode)
cooperationModeQuery := tx.Model(cooperationModeModel)
if err := cooperationModeQuery.
var cooperationModeModels []*models.CooperationMode
cooperationModeQuery := tx.Model(&cooperationModeModels)
if countMode, err := cooperationModeQuery.
Where("company->>'companyId' = '?'", cooperationContractModel.Company.CompanyId).
Where("org->>'orgId' = '?'", cooperationContractModel.Org.OrgId).
Where("cooperation_mode_number = ?", cooperationContractModel.CooperationModeNumber).
First(); err != nil {
return 0, nil, fmt.Errorf("合约关联的共创模式不存在")
}
Limit(1).
SelectAndCount(); err != nil {
log.Logger.Error("合约关联的共创模式不存在", map[string]interface{}{
"cooperationContractModel": cooperationContractModel,
})
} else {
if countMode > 0 {
// 获取分红激励规则列表
var dividendsIncentivesRuleModels []*models.DividendsIncentivesRule
dividendsIncentivesRuleQuery := tx.Model(&dividendsIncentivesRuleModels)
... ... @@ -1150,7 +1154,7 @@ func (repository *CooperationContractRepository) Find(queryOptions map[string]in
}
if cooperationContract, err := transform.TransformToCooperationContractDomainModelFromPgModels(
cooperationContractModel,
cooperationModeModel,
cooperationModeModels[0],
dividendsIncentivesRuleModels,
moneyIncentivesRuleModels,
cooperationContractRelevantModels,
... ... @@ -1161,6 +1165,8 @@ func (repository *CooperationContractRepository) Find(queryOptions map[string]in
}
}
}
}
}
return int64(count), cooperationContracts, nil
}
}
... ...
... ... @@ -284,25 +284,28 @@ func (repository *CooperationProjectRepository) Find(queryOptions map[string]int
if count > 0 {
for _, cooperationProjectModel := range cooperationProjectModels {
// 获取共创模式
cooperationModeModel := new(models.CooperationMode)
cooperationModeQuery := tx.Model(cooperationModeModel)
if err := cooperationModeQuery.
var cooperationModeModels []*models.CooperationMode
cooperationModeQuery := tx.Model(&cooperationModeModels)
if countMode, err := cooperationModeQuery.
Where("company->>'companyId' = '?'", cooperationProjectModel.Company.CompanyId).
Where("org->>'orgId' = '?'", cooperationProjectModel.Org.OrgId).
Where("cooperation_mode_number = ?", cooperationProjectModel.CooperationModeNumber).
First(); err != nil {
Limit(1).
SelectAndCount(); err != nil {
log.Logger.Error("共创项目关联的共创模式不存在", map[string]interface{}{
"cooperationProjectModel": cooperationProjectModel,
})
return 0, nil, fmt.Errorf("共创项目关联的共创模式不存在")
}
if cooperationProject, err := transform.TransformToCooperationProjectDomainModelFromPgModels(cooperationProjectModel, cooperationModeModel); err != nil {
} else {
if countMode > 0 {
if cooperationProject, err := transform.TransformToCooperationProjectDomainModelFromPgModels(cooperationProjectModel, cooperationModeModels[0]); err != nil {
return 0, cooperationProjects, err
} else {
cooperationProjects = append(cooperationProjects, cooperationProject)
}
}
}
}
}
return int64(count), cooperationProjects, nil
}
}
... ...