...
|
...
|
@@ -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,21 +105,30 @@ 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{
|
|
|
CooperationContractNumber: cooperationContract.CooperationContractNumber,
|
|
|
UserId: relevant.UserId,
|
|
|
UserBaseId: relevant.UserBaseId,
|
|
|
Org: relevant.Org,
|
|
|
Orgs: relevant.Orgs,
|
|
|
Department: relevant.Department,
|
|
|
Roles: relevant.Roles,
|
|
|
UserInfo: relevant.UserInfo,
|
|
|
UserType: relevant.UserType,
|
|
|
Status: relevant.Status,
|
|
|
Company: relevant.Company,
|
|
|
UpdatedAt: time.Time{},
|
|
|
DeletedAt: time.Time{},
|
|
|
CreatedAt: time.Now(),
|
|
|
CooperationContractRelevantId: relevant.RelevantId,
|
|
|
CooperationContractNumber: cooperationContract.CooperationContractNumber,
|
|
|
UserId: relevant.UserId,
|
|
|
UserBaseId: relevant.UserBaseId,
|
|
|
Org: relevant.Org,
|
|
|
Orgs: relevant.Orgs,
|
|
|
Department: relevant.Department,
|
|
|
Roles: relevant.Roles,
|
|
|
UserInfo: relevant.UserInfo,
|
|
|
UserType: relevant.UserType,
|
|
|
Status: relevant.Status,
|
|
|
Company: relevant.Company,
|
|
|
UpdatedAt: time.Time{},
|
|
|
DeletedAt: time.Time{},
|
|
|
CreatedAt: time.Now(),
|
|
|
})
|
|
|
}
|
|
|
if len(relevantPeopleModel) > 0 {
|
...
|
...
|
@@ -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,21 +326,30 @@ 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{
|
|
|
CooperationContractNumber: relevantDomain.CooperationContractNumber,
|
|
|
UserId: relevantDomain.UserId,
|
|
|
UserBaseId: relevantDomain.UserBaseId,
|
|
|
Org: relevantDomain.Org,
|
|
|
Orgs: relevantDomain.Orgs,
|
|
|
Department: relevantDomain.Department,
|
|
|
Roles: relevantDomain.Roles,
|
|
|
UserInfo: relevantDomain.UserInfo,
|
|
|
UserType: relevantDomain.UserType,
|
|
|
Status: relevantDomain.Status,
|
|
|
Company: relevantDomain.Company,
|
|
|
UpdatedAt: time.Time{},
|
|
|
DeletedAt: time.Time{},
|
|
|
CreatedAt: time.Now(),
|
|
|
CooperationContractRelevantId: relevantDomain.RelevantId,
|
|
|
CooperationContractNumber: relevantDomain.CooperationContractNumber,
|
|
|
UserId: relevantDomain.UserId,
|
|
|
UserBaseId: relevantDomain.UserBaseId,
|
|
|
Org: relevantDomain.Org,
|
|
|
Orgs: relevantDomain.Orgs,
|
|
|
Department: relevantDomain.Department,
|
|
|
Roles: relevantDomain.Roles,
|
|
|
UserInfo: relevantDomain.UserInfo,
|
|
|
UserType: relevantDomain.UserType,
|
|
|
Status: relevantDomain.Status,
|
|
|
Company: relevantDomain.Company,
|
|
|
UpdatedAt: time.Time{},
|
|
|
DeletedAt: time.Time{},
|
|
|
CreatedAt: time.Now(),
|
|
|
})
|
|
|
}
|
|
|
|
...
|
...
|
@@ -401,24 +434,33 @@ 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{
|
|
|
CooperationContractNumber: undertakerDomain.CooperationContractNumber,
|
|
|
UserId: undertakerDomain.UserId,
|
|
|
UserBaseId: undertakerDomain.UserBaseId,
|
|
|
Org: undertakerDomain.Org,
|
|
|
Orgs: undertakerDomain.Orgs,
|
|
|
Department: undertakerDomain.Department,
|
|
|
Roles: undertakerDomain.Roles,
|
|
|
UserInfo: undertakerDomain.UserInfo,
|
|
|
UserType: undertakerDomain.UserType,
|
|
|
Referrer: undertakerDomain.Referrer,
|
|
|
Salesman: undertakerDomain.Salesman,
|
|
|
Status: undertakerDomain.Status,
|
|
|
Company: undertakerDomain.Company,
|
|
|
ContractAttachment: undertakerDomain.ContractAttachment,
|
|
|
UpdatedAt: time.Time{},
|
|
|
DeletedAt: time.Time{},
|
|
|
CreatedAt: time.Now(),
|
|
|
CooperationContractUndertakerId: undertakerDomain.UndertakerId,
|
|
|
CooperationContractNumber: undertakerDomain.CooperationContractNumber,
|
|
|
UserId: undertakerDomain.UserId,
|
|
|
UserBaseId: undertakerDomain.UserBaseId,
|
|
|
Org: undertakerDomain.Org,
|
|
|
Orgs: undertakerDomain.Orgs,
|
|
|
Department: undertakerDomain.Department,
|
|
|
Roles: undertakerDomain.Roles,
|
|
|
UserInfo: undertakerDomain.UserInfo,
|
|
|
UserType: undertakerDomain.UserType,
|
|
|
Referrer: undertakerDomain.Referrer,
|
|
|
Salesman: undertakerDomain.Salesman,
|
|
|
Status: undertakerDomain.Status,
|
|
|
Company: undertakerDomain.Company,
|
|
|
ContractAttachment: undertakerDomain.ContractAttachment,
|
|
|
UpdatedAt: time.Time{},
|
|
|
DeletedAt: time.Time{},
|
|
|
CreatedAt: time.Now(),
|
|
|
})
|
|
|
}
|
|
|
log.Logger.Info("待添加的承接人", map[string]interface{}{
|
...
|
...
|
@@ -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
|
|
|
}
|
|
|
} |
...
|
...
|
|