...
|
...
|
@@ -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(÷ndsIncentivesRuleModels)
|
|
|
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(÷ndsIncentivesRuleModels)
|
|
|
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)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
...
|
...
|
|