...
|
...
|
@@ -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,
|
...
|
...
|
@@ -302,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,
|
...
|
...
|
@@ -401,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,
|
...
|
...
|
@@ -534,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,
|
...
|
...
|
@@ -657,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,
|
...
|
...
|
@@ -1175,8 +1235,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
|
|
|
}
|
|
|
} |
...
|
...
|
|