作者 陈志颖

Merge branch 'dev-chenzhiying' into dev

... ... @@ -272,7 +272,11 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
// 查找相关人列表
var cooperationContractRelevantModelsFetched []*models.CooperationContractRelevant
cooperationContractRelevantQuery := tx.Model(&cooperationContractRelevantModelsFetched)
if err := cooperationContractRelevantQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil {
if err := cooperationContractRelevantQuery.
Where("company->>'companyId' = '?'", cooperationContract.Company.CompanyId).
Where("org->>'orgId' = '?'", cooperationContract.Org.OrgId).
Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).
Select(); err != nil {
return nil, err
}
... ... @@ -368,7 +372,11 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
// 获取承接人列表
var cooperationContractUndertakersModelsFetched []*models.CooperationContractUndertaker
cooperationContractUndertakerQuery := tx.Model(&cooperationContractUndertakersModelsFetched)
if err := cooperationContractUndertakerQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil {
if err := cooperationContractUndertakerQuery.
Where("company->>'companyId' = '?'", cooperationContract.Company.CompanyId).
Where("org->>'orgId' = '?'", cooperationContract.Org.OrgId).
Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).
Select(); err != nil {
return nil, err
}
... ... @@ -497,7 +505,11 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
// 获取分红激励规则列表
var dividendsIncentivesRulesFetched []*models.DividendsIncentivesRule
dividendsIncentivesRuleQuery := tx.Model(&dividendsIncentivesRulesFetched)
if err := dividendsIncentivesRuleQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil {
if err := dividendsIncentivesRuleQuery.
Where("company->>'companyId' = '?'", cooperationContract.Company.CompanyId).
Where("org->>'orgId' = '?'", cooperationContract.Org.OrgId).
Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).
Select(); err != nil {
return nil, err
}
... ... @@ -616,7 +628,11 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
/********************** 更新金额激励规则 **************************/
var moneyIncentivesRulesFetched []*models.MoneyIncentivesRule
moneyIncentivesRuleQuery := tx.Model(&moneyIncentivesRulesFetched)
if err := moneyIncentivesRuleQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil {
if err := moneyIncentivesRuleQuery.
Where("company->>'companyId' = '?'", cooperationContract.Company.CompanyId).
Where("org->>'orgId' = '?'", cooperationContract.Org.OrgId).
Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).
Select(); err != nil {
return nil, err
}
... ... @@ -815,27 +831,43 @@ func (repository *CooperationContractRepository) Remove(cooperationContract *dom
// 获取分红激励规则列表
var dividendsIncentivesRuleModels []*models.DividendsIncentivesRule
dividendsIncentivesRuleQuery := tx.Model(&dividendsIncentivesRuleModels)
if err := dividendsIncentivesRuleQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil {
if err := dividendsIncentivesRuleQuery.
Where("company->>'companyId' = '?'", cooperationContract.Company.CompanyId).
Where("org->>'orgId' = '?'", cooperationContract.Org.OrgId).
Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).
Select(); err != nil {
return nil, err
} else {
if _, err := tx.Model(&dividendsIncentivesRuleModels).WherePK().Delete(); err != nil {
return nil, err
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 {
if err := moneyIncentivesRuleQuery.
Where("company->>'companyId' = '?'", cooperationContract.Company.CompanyId).
Where("org->>'orgId' = '?'", cooperationContract.Org.OrgId).
Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).
Select(); err != nil {
return nil, err
} else {
if _, err := tx.Model(&moneyIncentivesRuleModels).WherePK().Delete(); err != nil {
return nil, err
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 {
if err := cooperationContractUndertakerQuery.
Where("company->>'companyId' = '?'", cooperationContract.Company.CompanyId).
Where("org->>'orgId' = '?'", cooperationContract.Org.OrgId).
Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).
Select(); err != nil {
return nil, err
} else {
if _, err := tx.Model(&cooperationContractUndertakerModels).WherePK().Delete(); err != nil {
... ... @@ -845,11 +877,17 @@ func (repository *CooperationContractRepository) Remove(cooperationContract *dom
// 获取相关人列表
var cooperationContractRelevantModels []*models.CooperationContractRelevant
cooperationContractRelevantQuery := tx.Model(&cooperationContractRelevantModels)
if err := cooperationContractRelevantQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil {
if err := cooperationContractRelevantQuery.
Where("company->>'companyId' = '?'", cooperationContract.Company.CompanyId).
Where("org->>'orgId' = '?'", cooperationContract.Org.OrgId).
Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).
Select(); err != nil {
return nil, err
} else {
if _, err := tx.Model(&cooperationContractRelevantModels).WherePK().Delete(); err != nil {
return nil, err
if len(cooperationContractRelevantModels) > 0 {
if _, err := tx.Model(&cooperationContractRelevantModels).WherePK().Delete(); err != nil {
return nil, err
}
}
}
}
... ... @@ -872,8 +910,12 @@ func (repository *CooperationContractRepository) BatchRemove(cooperationContract
// 获取分红激励规则列表
var dividendsIncentivesRuleModels []*models.DividendsIncentivesRule
dividendsIncentivesRuleQuery := tx.Model(&dividendsIncentivesRuleModels)
if err := dividendsIncentivesRuleQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil {
return nil, err
if err := dividendsIncentivesRuleQuery.
Where("company->>'companyId' = '?'", cooperationContract.Company.CompanyId).
Where("org->>'orgId' = '?'", cooperationContract.Org.OrgId).
Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).
Select(); err != nil {
return nil, fmt.Errorf("分红激励规则不存在:" + err.Error())
} else {
if len(dividendsIncentivesRuleModels) > 0 {
if _, err := tx.Model(&dividendsIncentivesRuleModels).WherePK().Delete(); err != nil {
... ... @@ -884,8 +926,12 @@ func (repository *CooperationContractRepository) BatchRemove(cooperationContract
// 获取金额激励规则列表
var moneyIncentivesRuleModels []*models.MoneyIncentivesRule
moneyIncentivesRuleQuery := tx.Model(&moneyIncentivesRuleModels)
if err := moneyIncentivesRuleQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil {
return nil, err
if err := moneyIncentivesRuleQuery.
Where("company->>'companyId' = '?'", cooperationContract.Company.CompanyId).
Where("org->>'orgId' = '?'", cooperationContract.Org.OrgId).
Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).
Select(); err != nil {
return nil, fmt.Errorf("金额激励规则列表不存在:" + err.Error())
} else {
if len(moneyIncentivesRuleModels) > 0 {
if _, err := tx.Model(&moneyIncentivesRuleModels).WherePK().Delete(); err != nil {
... ... @@ -896,8 +942,12 @@ func (repository *CooperationContractRepository) BatchRemove(cooperationContract
// 获取承接人列表
var cooperationContractUndertakerModels []*models.CooperationContractUndertaker
cooperationContractUndertakerQuery := tx.Model(&cooperationContractUndertakerModels)
if err := cooperationContractUndertakerQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil {
return nil, err
if err := cooperationContractUndertakerQuery.
Where("company->>'companyId' = '?'", cooperationContract.Company.CompanyId).
Where("org->>'orgId' = '?'", cooperationContract.Org.OrgId).
Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).
Select(); err != nil {
return nil, fmt.Errorf("合约承接人不存在:" + err.Error())
} else {
if len(cooperationContractUndertakerModels) > 0 {
if _, err := tx.Model(&cooperationContractUndertakerModels).WherePK().Delete(); err != nil {
... ... @@ -908,8 +958,12 @@ func (repository *CooperationContractRepository) BatchRemove(cooperationContract
// 获取相关人列表
var cooperationContractRelevantModels []*models.CooperationContractRelevant
cooperationContractRelevantQuery := tx.Model(&cooperationContractRelevantModels)
if err := cooperationContractRelevantQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil {
return nil, err
if err := cooperationContractRelevantQuery.
Where("company->>'companyId' = '?'", cooperationContract.Company.CompanyId).
Where("org->>'orgId' = '?'", cooperationContract.Org.OrgId).
Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).
Select(); err != nil {
return nil, fmt.Errorf("合约相关人存在:" + err.Error())
} else {
if len(cooperationContractRelevantModels) > 0 {
if _, err := tx.Model(&cooperationContractRelevantModels).WherePK().Delete(); err != nil {
... ... @@ -930,7 +984,7 @@ func (repository *CooperationContractRepository) FindOne(queryOptions map[string
query.SetWhereByQueryOption("cooperation_contract.cooperation_contract_number = ?", "cooperationContractNumber")
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("没有此资源")
return nil, fmt.Errorf("共创合约不存在")
} else {
return nil, err
}
... ... @@ -941,32 +995,52 @@ func (repository *CooperationContractRepository) FindOne(queryOptions map[string
// 获取共创模式
cooperationModeModels := new(models.CooperationMode)
cooperationModeQuery := tx.Model(cooperationModeModels)
if err := cooperationModeQuery.Where("cooperation_mode_number = ?", cooperationContractModel.CooperationModeNumber).First(); err != nil {
return nil, err
if err := cooperationModeQuery.
Where("company->>'companyId' = '?'", cooperationContractModel.Company.CompanyId).
Where("org->>'orgId' = '?'", cooperationContractModel.Org.OrgId).
Where("cooperation_mode_number = ?", cooperationContractModel.CooperationModeNumber).
First(); err != nil {
return nil, fmt.Errorf("共创合约关联的共创模式不存在")
}
// 获取分红激励规则列表
var dividendsIncentivesRuleModels []*models.DividendsIncentivesRule
dividendsIncentivesRuleQuery := tx.Model(&dividendsIncentivesRuleModels)
if err := dividendsIncentivesRuleQuery.Where("cooperation_contract_number = ?", cooperationContractModel.CooperationContractNumber).Select(); err != nil {
return nil, err
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 nil, fmt.Errorf("共创合约关联的分红激励规则不存在")
}
// 获取金额激励规则列表
var moneyIncentivesRuleModels []*models.MoneyIncentivesRule
moneyIncentivesRuleQuery := tx.Model(&moneyIncentivesRuleModels)
if err := moneyIncentivesRuleQuery.Where("cooperation_contract_number = ?", cooperationContractModel.CooperationContractNumber).Select(); err != nil {
return nil, err
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 nil, fmt.Errorf("共创合约关联的金额激励规则不存在")
}
// 获取承接人列表
var cooperationContractUndertakerModels []*models.CooperationContractUndertaker
cooperationContractUndertakerQuery := tx.Model(&cooperationContractUndertakerModels)
if err := cooperationContractUndertakerQuery.Where("cooperation_contract_number = ?", cooperationContractModel.CooperationContractNumber).Select(); err != nil {
return nil, err
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 nil, fmt.Errorf("合约承接人不存在")
}
// 获取相关人列表
var cooperationContractRelevantModels []*models.CooperationContractRelevant
cooperationContractRelevantQuery := tx.Model(&cooperationContractRelevantModels)
if err := cooperationContractRelevantQuery.Where("cooperation_contract_number = ?", cooperationContractModel.CooperationContractNumber).Select(); err != nil {
return nil, err
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 nil, fmt.Errorf("合约相关人不存在")
}
return transform.TransformToCooperationContractDomainModelFromPgModels(
cooperationContractModel,
... ...