|
...
|
...
|
@@ -16,14 +16,11 @@ import ( |
|
|
|
|
|
|
|
type CooperationContractRepository struct {
|
|
|
|
transactionContext *pgTransaction.TransactionContext
|
|
|
|
IdWorker *snowflake.IdWorker
|
|
|
|
}
|
|
|
|
|
|
|
|
func (repository *CooperationContractRepository) nextIdentify() (int64, error) {
|
|
|
|
IdWorker, err := snowflake.NewIdWorker(1)
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
id, err := IdWorker.NextId()
|
|
|
|
id, err := repository.IdWorker.NextId()
|
|
|
|
return id, err
|
|
|
|
}
|
|
|
|
|
|
...
|
...
|
@@ -108,7 +105,16 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai |
|
|
|
// 新增相关人
|
|
|
|
var relevantPeopleModel []*models.CooperationContractRelevant
|
|
|
|
for _, relevant := range cooperationContract.RelevantPeople {
|
|
|
|
if relevant.Identify() == nil {
|
|
|
|
orderGoodId, err := repository.nextIdentify()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
} else {
|
|
|
|
relevant.RelevantId = orderGoodId
|
|
|
|
}
|
|
|
|
}
|
|
|
|
relevantPeopleModel = append(relevantPeopleModel, &models.CooperationContractRelevant{
|
|
|
|
CooperationContractRelevantId: relevant.RelevantId,
|
|
|
|
CooperationContractNumber: cooperationContract.CooperationContractNumber,
|
|
|
|
UserId: relevant.UserId,
|
|
|
|
UserBaseId: relevant.UserBaseId,
|
|
...
|
...
|
@@ -169,7 +175,16 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai |
|
|
|
// 新增分红激励规则
|
|
|
|
var dividendsIncentivesRulesModel []*models.DividendsIncentivesRule
|
|
|
|
for _, rule := range cooperationContract.DividendsIncentivesRules {
|
|
|
|
if rule.Identify() == nil {
|
|
|
|
ruleId, err := repository.nextIdentify()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
} else {
|
|
|
|
rule.DividendsIncentivesRuleId = ruleId
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dividendsIncentivesRulesModel = append(dividendsIncentivesRulesModel, &models.DividendsIncentivesRule{
|
|
|
|
DividendsIncentivesRuleId: rule.DividendsIncentivesRuleId,
|
|
|
|
CooperationContractNumber: cooperationContract.CooperationContractNumber,
|
|
|
|
ReferrerPercentage: rule.ReferrerPercentage,
|
|
|
|
SalesmanPercentage: rule.SalesmanPercentage,
|
|
...
|
...
|
@@ -197,7 +212,16 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai |
|
|
|
// 新增金额激励规则
|
|
|
|
var moneyIncentivesRulesModel []*models.MoneyIncentivesRule
|
|
|
|
for _, rule := range cooperationContract.MoneyIncentivesRules {
|
|
|
|
if rule.Identify() == nil {
|
|
|
|
ruleId, err := repository.nextIdentify()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
} else {
|
|
|
|
rule.MoneyIncentivesRuleId = ruleId
|
|
|
|
}
|
|
|
|
}
|
|
|
|
moneyIncentivesRulesModel = append(moneyIncentivesRulesModel, &models.MoneyIncentivesRule{
|
|
|
|
MoneyIncentivesRuleId: rule.MoneyIncentivesRuleId,
|
|
|
|
CooperationContractNumber: cooperationContract.CooperationContractNumber,
|
|
|
|
MoneyIncentivesAmount: rule.MoneyIncentivesAmount,
|
|
|
|
MoneyIncentivesStage: rule.MoneyIncentivesStage,
|
|
...
|
...
|
@@ -272,7 +296,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
|
|
|
|
}
|
|
|
|
|
|
...
|
...
|
@@ -298,7 +326,16 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai |
|
|
|
// 将待添加的相关人领域模型转换为数据模型
|
|
|
|
var cooperationContractRelevantPeopleToAddModels []*models.CooperationContractRelevant
|
|
|
|
for _, relevantDomain := range cooperationContractRelevantPeopleToAdd {
|
|
|
|
if relevantDomain.Identify() == nil {
|
|
|
|
relevantId, err := repository.nextIdentify()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
} else {
|
|
|
|
relevantDomain.RelevantId = relevantId
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cooperationContractRelevantPeopleToAddModels = append(cooperationContractRelevantPeopleToAddModels, &models.CooperationContractRelevant{
|
|
|
|
CooperationContractRelevantId: relevantDomain.RelevantId,
|
|
|
|
CooperationContractNumber: relevantDomain.CooperationContractNumber,
|
|
|
|
UserId: relevantDomain.UserId,
|
|
|
|
UserBaseId: relevantDomain.UserBaseId,
|
|
...
|
...
|
@@ -368,7 +405,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
|
|
|
|
}
|
|
|
|
|
|
...
|
...
|
@@ -393,7 +434,16 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai |
|
|
|
// 将待添加的相关人领域模型转换为数据模型
|
|
|
|
var cooperationContractUndertakersToAddModels []*models.CooperationContractUndertaker
|
|
|
|
for _, undertakerDomain := range cooperationContractUndertakersToAdd {
|
|
|
|
if undertakerDomain.Identify() == nil {
|
|
|
|
undertakerId, err := repository.nextIdentify()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
} else {
|
|
|
|
undertakerDomain.UndertakerId = undertakerId
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cooperationContractUndertakersToAddModels = append(cooperationContractUndertakersToAddModels, &models.CooperationContractUndertaker{
|
|
|
|
CooperationContractUndertakerId: undertakerDomain.UndertakerId,
|
|
|
|
CooperationContractNumber: undertakerDomain.CooperationContractNumber,
|
|
|
|
UserId: undertakerDomain.UserId,
|
|
|
|
UserBaseId: undertakerDomain.UserBaseId,
|
|
...
|
...
|
@@ -497,7 +547,11 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai |
|
|
|
// 获取分红激励规则列表
|
|
|
|
var dividendsIncentivesRulesFetched []*models.DividendsIncentivesRule
|
|
|
|
dividendsIncentivesRuleQuery := tx.Model(÷ndsIncentivesRulesFetched)
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
...
|
...
|
@@ -522,7 +576,16 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai |
|
|
|
// 将待添加的分红激励规则领域模型转换为数据模型
|
|
|
|
var dividendsIncentivesRulesToAddModels []*models.DividendsIncentivesRule
|
|
|
|
for _, dividendsIncentivesRuleDomain := range dividendsIncentivesRulesToAdd {
|
|
|
|
if dividendsIncentivesRuleDomain.Identify() == nil {
|
|
|
|
ruleId, err := repository.nextIdentify()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
} else {
|
|
|
|
dividendsIncentivesRuleDomain.DividendsIncentivesRuleId = ruleId
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dividendsIncentivesRulesToAddModels = append(dividendsIncentivesRulesToAddModels, &models.DividendsIncentivesRule{
|
|
|
|
DividendsIncentivesRuleId: dividendsIncentivesRuleDomain.DividendsIncentivesRuleId,
|
|
|
|
CooperationContractNumber: dividendsIncentivesRuleDomain.CooperationContractNumber,
|
|
|
|
ReferrerPercentage: dividendsIncentivesRuleDomain.ReferrerPercentage,
|
|
|
|
SalesmanPercentage: dividendsIncentivesRuleDomain.SalesmanPercentage,
|
|
...
|
...
|
@@ -616,7 +679,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
|
|
|
|
}
|
|
|
|
|
|
...
|
...
|
@@ -641,7 +708,16 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai |
|
|
|
// 将待添加的金额激励规则领域模型转换为数据模型
|
|
|
|
var moneyIncentivesRulesToAddModels []*models.MoneyIncentivesRule
|
|
|
|
for _, moneyIncentivesRuleDomain := range moneyIncentivesRulesToAdd {
|
|
|
|
if moneyIncentivesRuleDomain.Identify() == nil {
|
|
|
|
ruleId, err := repository.nextIdentify()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
} else {
|
|
|
|
moneyIncentivesRuleDomain.MoneyIncentivesRuleId = ruleId
|
|
|
|
}
|
|
|
|
}
|
|
|
|
moneyIncentivesRulesToAddModels = append(moneyIncentivesRulesToAddModels, &models.MoneyIncentivesRule{
|
|
|
|
MoneyIncentivesRuleId: moneyIncentivesRuleDomain.MoneyIncentivesRuleId,
|
|
|
|
CooperationContractNumber: moneyIncentivesRuleDomain.CooperationContractNumber,
|
|
|
|
MoneyIncentivesAmount: moneyIncentivesRuleDomain.MoneyIncentivesAmount,
|
|
|
|
MoneyIncentivesStage: moneyIncentivesRuleDomain.MoneyIncentivesStage,
|
|
...
|
...
|
@@ -815,27 +891,43 @@ func (repository *CooperationContractRepository) Remove(cooperationContract *dom |
|
|
|
// 获取分红激励规则列表
|
|
|
|
var dividendsIncentivesRuleModels []*models.DividendsIncentivesRule
|
|
|
|
dividendsIncentivesRuleQuery := tx.Model(÷ndsIncentivesRuleModels)
|
|
|
|
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 len(dividendsIncentivesRuleModels) > 0 {
|
|
|
|
if _, err := tx.Model(÷ndsIncentivesRuleModels).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 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,14 +937,20 @@ 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 len(cooperationContractRelevantModels) > 0 {
|
|
|
|
if _, err := tx.Model(&cooperationContractRelevantModels).WherePK().Delete(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return cooperationContract, nil
|
|
|
|
}
|
|
|
|
|
|
...
|
...
|
@@ -872,8 +970,12 @@ func (repository *CooperationContractRepository) BatchRemove(cooperationContract |
|
|
|
// 获取分红激励规则列表
|
|
|
|
var dividendsIncentivesRuleModels []*models.DividendsIncentivesRule
|
|
|
|
dividendsIncentivesRuleQuery := tx.Model(÷ndsIncentivesRuleModels)
|
|
|
|
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(÷ndsIncentivesRuleModels).WherePK().Delete(); err != nil {
|
|
...
|
...
|
@@ -884,8 +986,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 +1002,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 +1018,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 {
|
|
...
|
...
|
@@ -927,10 +1041,18 @@ func (repository *CooperationContractRepository) FindOne(queryOptions map[string |
|
|
|
cooperationContractModel := new(models.CooperationContract)
|
|
|
|
query := sqlbuilder.BuildQuery(tx.Model(cooperationContractModel), queryOptions)
|
|
|
|
query.SetWhereByQueryOption("cooperation_contract.cooperation_contract_id = ?", "cooperationContractId")
|
|
|
|
query.SetWhereByQueryOption("cooperation_contract.cooperation_contract_number = ?", "cooperationContractNumber")
|
|
|
|
if cooperationContractNumber, ok := queryOptions["cooperationContractNumber"]; ok && cooperationContractNumber != "" {
|
|
|
|
query.Where("cooperation_contract.cooperation_contract_number = ?", cooperationContractNumber)
|
|
|
|
}
|
|
|
|
if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
|
|
|
|
query.Where("company->>'companyId' = '?'", companyId)
|
|
|
|
}
|
|
|
|
if orgId, ok := queryOptions["orgId"]; ok && orgId.(int64) != 0 {
|
|
|
|
query.Where("org->>'orgId' = '?'", orgId)
|
|
|
|
}
|
|
|
|
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
|
|
|
|
}
|
|
...
|
...
|
@@ -939,43 +1061,79 @@ func (repository *CooperationContractRepository) FindOne(queryOptions map[string |
|
|
|
return nil, nil
|
|
|
|
} else {
|
|
|
|
// 获取共创模式
|
|
|
|
cooperationModeModels := new(models.CooperationMode)
|
|
|
|
cooperationModeQuery := tx.Model(cooperationModeModels)
|
|
|
|
if err := cooperationModeQuery.Where("cooperation_mode_number = ?", cooperationContractModel.CooperationModeNumber).First(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
//cooperationModeModels := new(models.CooperationMode)
|
|
|
|
//cooperationModeQuery := tx.Model(cooperationModeModels)
|
|
|
|
//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 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).
|
|
|
|
Limit(1).
|
|
|
|
SelectAndCount(); err != nil {
|
|
|
|
log.Logger.Error("合约关联的共创模式不存在", map[string]interface{}{
|
|
|
|
"cooperationContractModel": cooperationContractModel,
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
if countMode > 0 {
|
|
|
|
// 获取分红激励规则列表
|
|
|
|
var dividendsIncentivesRuleModels []*models.DividendsIncentivesRule
|
|
|
|
dividendsIncentivesRuleQuery := tx.Model(÷ndsIncentivesRuleModels)
|
|
|
|
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,
|
|
|
|
cooperationModeModels,
|
|
|
|
cooperationModeModels[0],
|
|
|
|
dividendsIncentivesRuleModels,
|
|
|
|
moneyIncentivesRuleModels,
|
|
|
|
cooperationContractRelevantModels,
|
|
|
|
cooperationContractUndertakerModels)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil, fmt.Errorf("共创合约不存在")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (repository *CooperationContractRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.CooperationContract, error) {
|
|
...
|
...
|
@@ -998,6 +1156,12 @@ func (repository *CooperationContractRepository) Find(queryOptions map[string]in |
|
|
|
if cooperationContractIds, ok := queryOptions["cooperationContractIds"]; ok && len(cooperationContractIds.([]int64)) != 0 {
|
|
|
|
query.Where("cooperation_contract_id in (?)", pg.In(cooperationContractIds))
|
|
|
|
}
|
|
|
|
if cooperationContractNumbers, ok := queryOptions["cooperationContractNumbers"]; ok && len(cooperationContractNumbers.([]string)) != 0 {
|
|
|
|
query.Where("cooperation_contract_number in (?)", pg.In(cooperationContractNumbers))
|
|
|
|
}
|
|
|
|
if incentivesType, ok := queryOptions["incentivesType"]; ok && incentivesType.(int32) != 0 {
|
|
|
|
query.Where("incentives_type = ?", incentivesType)
|
|
|
|
}
|
|
|
|
if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
|
|
|
|
query.Where("company->>'companyId' = '?'", companyId)
|
|
|
|
}
|
|
...
|
...
|
@@ -1025,15 +1189,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, err
|
|
|
|
}
|
|
|
|
Limit(1).
|
|
|
|
SelectAndCount(); err != nil {
|
|
|
|
log.Logger.Error("合约关联的共创模式不存在", map[string]interface{}{
|
|
|
|
"cooperationContractModel": cooperationContractModel,
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
if countMode > 0 {
|
|
|
|
// 获取分红激励规则列表
|
|
|
|
var dividendsIncentivesRuleModels []*models.DividendsIncentivesRule
|
|
|
|
dividendsIncentivesRuleQuery := tx.Model(÷ndsIncentivesRuleModels)
|
|
...
|
...
|
@@ -1042,7 +1210,7 @@ func (repository *CooperationContractRepository) Find(queryOptions map[string]in |
|
|
|
Where("org->>'orgId' = '?'", cooperationContractModel.Org.OrgId).
|
|
|
|
Where("cooperation_contract_number = ?", cooperationContractModel.CooperationContractNumber).
|
|
|
|
Select(); err != nil {
|
|
|
|
return 0, nil, err
|
|
|
|
return 0, nil, fmt.Errorf("合约关联的分红激励规则列表不存在")
|
|
|
|
}
|
|
|
|
// 获取金额激励规则列表
|
|
|
|
var moneyIncentivesRuleModels []*models.MoneyIncentivesRule
|
|
...
|
...
|
@@ -1052,7 +1220,7 @@ func (repository *CooperationContractRepository) Find(queryOptions map[string]in |
|
|
|
Where("org->>'orgId' = '?'", cooperationContractModel.Org.OrgId).
|
|
|
|
Where("cooperation_contract_number = ?", cooperationContractModel.CooperationContractNumber).
|
|
|
|
Select(); err != nil {
|
|
|
|
return 0, nil, err
|
|
|
|
return 0, nil, fmt.Errorf("合约关联的金额激励规则列表不存在")
|
|
|
|
}
|
|
|
|
// 获取承接人列表
|
|
|
|
var cooperationContractUndertakerModels []*models.CooperationContractUndertaker
|
|
...
|
...
|
@@ -1062,7 +1230,7 @@ func (repository *CooperationContractRepository) Find(queryOptions map[string]in |
|
|
|
Where("org->>'orgId' = '?'", cooperationContractModel.Org.OrgId).
|
|
|
|
Where("cooperation_contract_number = ?", cooperationContractModel.CooperationContractNumber).
|
|
|
|
Select(); err != nil {
|
|
|
|
return 0, nil, err
|
|
|
|
return 0, nil, fmt.Errorf("合约相关的承接人列表不存在")
|
|
|
|
}
|
|
|
|
// 获取相关人列表
|
|
|
|
var cooperationContractRelevantModels []*models.CooperationContractRelevant
|
|
...
|
...
|
@@ -1072,11 +1240,11 @@ func (repository *CooperationContractRepository) Find(queryOptions map[string]in |
|
|
|
Where("org->>'orgId' = '?'", cooperationContractModel.Org.OrgId).
|
|
|
|
Where("cooperation_contract_number = ?", cooperationContractModel.CooperationContractNumber).
|
|
|
|
Select(); err != nil {
|
|
|
|
return 0, nil, err
|
|
|
|
return 0, nil, fmt.Errorf("合约相关的相关人列表不存在")
|
|
|
|
}
|
|
|
|
if cooperationContract, err := transform.TransformToCooperationContractDomainModelFromPgModels(
|
|
|
|
cooperationContractModel,
|
|
|
|
cooperationModeModel,
|
|
|
|
cooperationModeModels[0],
|
|
|
|
dividendsIncentivesRuleModels,
|
|
|
|
moneyIncentivesRuleModels,
|
|
|
|
cooperationContractRelevantModels,
|
|
...
|
...
|
@@ -1087,6 +1255,8 @@ func (repository *CooperationContractRepository) Find(queryOptions map[string]in |
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return int64(count), cooperationContracts, nil
|
|
|
|
}
|
|
|
|
}
|
|
...
|
...
|
@@ -1095,8 +1265,13 @@ func NewCooperationContractRepository(transactionContext *pgTransaction.Transact |
|
|
|
if transactionContext == nil {
|
|
|
|
return nil, fmt.Errorf("transactionContext参数不能为nil")
|
|
|
|
} else {
|
|
|
|
idWorker, err := snowflake.NewIdWorker(1)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &CooperationContractRepository{
|
|
|
|
transactionContext: transactionContext,
|
|
|
|
IdWorker: idWorker,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|