作者 陈志颖

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,37 +276,41 @@ 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("申请关联的共创项目不存在")
}
// 获取共创模式
cooperationModeModel := new(models.CooperationMode)
cooperationModeQuery := tx.Model(cooperationModeModel)
cooperationModeQuery.AllWithDeleted()
if err := cooperationModeQuery.
Where("company->>'companyId' = '?'", cooperationApplicationModel.Company.CompanyId).
Where("org->>'orgId' = '?'", cooperationApplicationModel.Org.OrgId).
Where("cooperation_mode_number = ?", cooperationProjectModel.CooperationModeNumber).
First(); 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 {
return 0, cooperationApplications, err
} else {
cooperationApplications = append(cooperationApplications, cooperationApplication)
if countProject > 0 {
// 获取共创模式
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 = ?", cooperationProjectModels[0].CooperationModeNumber).
Limit(1).
SelectAndCount(); err != nil {
log.Logger.Error("申请关联的共创模式不存在", map[string]interface{}{
"cooperationApplicationModel": cooperationApplicationModel,
})
} 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)
}
}
}
}
}
}
}
... ...
... ... @@ -1099,65 +1099,71 @@ 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("合约关联的共创模式不存在")
}
// 获取分红激励规则列表
var dividendsIncentivesRuleModels []*models.DividendsIncentivesRule
dividendsIncentivesRuleQuery := tx.Model(&dividendsIncentivesRuleModels)
if err := dividendsIncentivesRuleQuery.
Where("company->>'companyId' = '?'", cooperationContractModel.Company.CompanyId).
Where("org->>'orgId' = '?'", cooperationContractModel.Org.OrgId).
Where("cooperation_contract_number = ?", cooperationContractModel.CooperationContractNumber).
Select(); err != nil {
return 0, nil, fmt.Errorf("合约关联的分红激励规则列表不存在")
}
// 获取金额激励规则列表
var moneyIncentivesRuleModels []*models.MoneyIncentivesRule
moneyIncentivesRuleQuery := tx.Model(&moneyIncentivesRuleModels)
if err := moneyIncentivesRuleQuery.
Where("company->>'companyId' = '?'", cooperationContractModel.Company.CompanyId).
Where("org->>'orgId' = '?'", cooperationContractModel.Org.OrgId).
Where("cooperation_contract_number = ?", cooperationContractModel.CooperationContractNumber).
Select(); err != nil {
return 0, nil, fmt.Errorf("合约关联的金额激励规则列表不存在")
}
// 获取承接人列表
var cooperationContractUndertakerModels []*models.CooperationContractUndertaker
cooperationContractUndertakerQuery := tx.Model(&cooperationContractUndertakerModels)
if err := cooperationContractUndertakerQuery.
Where("company->>'companyId' = '?'", cooperationContractModel.Company.CompanyId).
Where("org->>'orgId' = '?'", cooperationContractModel.Org.OrgId).
Where("cooperation_contract_number = ?", cooperationContractModel.CooperationContractNumber).
Select(); err != nil {
return 0, nil, fmt.Errorf("合约相关的承接人列表不存在")
}
// 获取相关人列表
var cooperationContractRelevantModels []*models.CooperationContractRelevant
cooperationContractRelevantQuery := tx.Model(&cooperationContractRelevantModels)
if err := cooperationContractRelevantQuery.
Where("company->>'companyId' = '?'", cooperationContractModel.Company.CompanyId).
Where("org->>'orgId' = '?'", cooperationContractModel.Org.OrgId).
Where("cooperation_contract_number = ?", cooperationContractModel.CooperationContractNumber).
Select(); err != nil {
return 0, nil, fmt.Errorf("合约相关的相关人列表不存在")
}
if cooperationContract, err := transform.TransformToCooperationContractDomainModelFromPgModels(
cooperationContractModel,
cooperationModeModel,
dividendsIncentivesRuleModels,
moneyIncentivesRuleModels,
cooperationContractRelevantModels,
cooperationContractUndertakerModels); err != nil {
return 0, cooperationContracts, err
Limit(1).
SelectAndCount(); err != nil {
log.Logger.Error("合约关联的共创模式不存在", map[string]interface{}{
"cooperationContractModel": cooperationContractModel,
})
} else {
cooperationContracts = append(cooperationContracts, cooperationContract)
if countMode > 0 {
// 获取分红激励规则列表
var dividendsIncentivesRuleModels []*models.DividendsIncentivesRule
dividendsIncentivesRuleQuery := tx.Model(&dividendsIncentivesRuleModels)
if err := dividendsIncentivesRuleQuery.
Where("company->>'companyId' = '?'", cooperationContractModel.Company.CompanyId).
Where("org->>'orgId' = '?'", cooperationContractModel.Org.OrgId).
Where("cooperation_contract_number = ?", cooperationContractModel.CooperationContractNumber).
Select(); err != nil {
return 0, nil, fmt.Errorf("合约关联的分红激励规则列表不存在")
}
// 获取金额激励规则列表
var moneyIncentivesRuleModels []*models.MoneyIncentivesRule
moneyIncentivesRuleQuery := tx.Model(&moneyIncentivesRuleModels)
if err := moneyIncentivesRuleQuery.
Where("company->>'companyId' = '?'", cooperationContractModel.Company.CompanyId).
Where("org->>'orgId' = '?'", cooperationContractModel.Org.OrgId).
Where("cooperation_contract_number = ?", cooperationContractModel.CooperationContractNumber).
Select(); err != nil {
return 0, nil, fmt.Errorf("合约关联的金额激励规则列表不存在")
}
// 获取承接人列表
var cooperationContractUndertakerModels []*models.CooperationContractUndertaker
cooperationContractUndertakerQuery := tx.Model(&cooperationContractUndertakerModels)
if err := cooperationContractUndertakerQuery.
Where("company->>'companyId' = '?'", cooperationContractModel.Company.CompanyId).
Where("org->>'orgId' = '?'", cooperationContractModel.Org.OrgId).
Where("cooperation_contract_number = ?", cooperationContractModel.CooperationContractNumber).
Select(); err != nil {
return 0, nil, fmt.Errorf("合约相关的承接人列表不存在")
}
// 获取相关人列表
var cooperationContractRelevantModels []*models.CooperationContractRelevant
cooperationContractRelevantQuery := tx.Model(&cooperationContractRelevantModels)
if err := cooperationContractRelevantQuery.
Where("company->>'companyId' = '?'", cooperationContractModel.Company.CompanyId).
Where("org->>'orgId' = '?'", cooperationContractModel.Org.OrgId).
Where("cooperation_contract_number = ?", cooperationContractModel.CooperationContractNumber).
Select(); err != nil {
return 0, nil, fmt.Errorf("合约相关的相关人列表不存在")
}
if cooperationContract, err := transform.TransformToCooperationContractDomainModelFromPgModels(
cooperationContractModel,
cooperationModeModels[0],
dividendsIncentivesRuleModels,
moneyIncentivesRuleModels,
cooperationContractRelevantModels,
cooperationContractUndertakerModels); err != nil {
return 0, cooperationContracts, err
} else {
cooperationContracts = append(cooperationContracts, cooperationContract)
}
}
}
}
}
... ...
... ... @@ -284,22 +284,25 @@ 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 {
return 0, cooperationProjects, err
} else {
cooperationProjects = append(cooperationProjects, cooperationProject)
if countMode > 0 {
if cooperationProject, err := transform.TransformToCooperationProjectDomainModelFromPgModels(cooperationProjectModel, cooperationModeModels[0]); err != nil {
return 0, cooperationProjects, err
} else {
cooperationProjects = append(cooperationProjects, cooperationProject)
}
}
}
}
}
... ...