|
...
|
...
|
@@ -25,6 +25,7 @@ func (repository *CooperationContractRepository) nextIdentify() (int64, error) { |
|
|
|
id, err := IdWorker.NextId()
|
|
|
|
return id, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (repository *CooperationContractRepository) Save(cooperationContract *domain.CooperationContract) (*domain.CooperationContract, error) {
|
|
|
|
sqlBuildFields := []string{
|
|
|
|
"cooperation_contract_id",
|
|
...
|
...
|
@@ -331,7 +332,6 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai |
|
|
|
|
|
|
|
// 待更新相关人
|
|
|
|
var cooperationContractUndertakersToUpdate []*domain.Undertaker
|
|
|
|
|
|
|
|
// 待添加相关人
|
|
|
|
var cooperationContractUndertakersToAdd []*domain.Undertaker
|
|
|
|
for _, undertaker := range cooperationContract.Undertakers {
|
|
...
|
...
|
@@ -410,6 +410,81 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai |
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// 提取分红激励规则id
|
|
|
|
var dividendsIncentivesRuleIdsFetched []int64
|
|
|
|
for _, dividendsIncentivesRule := range dividendsIncentivesRulesFetched {
|
|
|
|
dividendsIncentivesRuleIdsFetched = append(dividendsIncentivesRuleIdsFetched, dividendsIncentivesRule.DividendsIncentivesRuleId)
|
|
|
|
}
|
|
|
|
|
|
|
|
// 待更新分红激励规则
|
|
|
|
var dividendsIncentivesRulesToUpdate []*domain.DividendsIncentivesRule
|
|
|
|
// 待添加分红激励规则
|
|
|
|
var dividendsIncentivesRulesToAdd []*domain.DividendsIncentivesRule
|
|
|
|
for _, dividendsIncentivesRule := range cooperationContract.DividendsIncentivesRules {
|
|
|
|
if dividendsIncentivesRule.DividendsIncentivesRuleId != 0 {
|
|
|
|
dividendsIncentivesRulesToUpdate = append(dividendsIncentivesRulesToUpdate, dividendsIncentivesRule)
|
|
|
|
} else {
|
|
|
|
dividendsIncentivesRulesToAdd = append(dividendsIncentivesRulesToAdd, dividendsIncentivesRule)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 将待添加的分红激励规则领域模型转换为数据模型
|
|
|
|
var dividendsIncentivesRulesToAddModels []*models.DividendsIncentivesRule
|
|
|
|
for _, dividendsIncentivesRuleDomain := range dividendsIncentivesRulesToAdd {
|
|
|
|
dividendsIncentivesRulesToAddModels = append(dividendsIncentivesRulesToAddModels, &models.DividendsIncentivesRule{
|
|
|
|
CooperationContractNumber: dividendsIncentivesRuleDomain.CooperationContractNumber,
|
|
|
|
ReferrerPercentage: dividendsIncentivesRuleDomain.ReferrerPercentage,
|
|
|
|
SalesmanPercentage: dividendsIncentivesRuleDomain.SalesmanPercentage,
|
|
|
|
DividendsIncentivesPercentage: dividendsIncentivesRuleDomain.DividendsIncentivesPercentage,
|
|
|
|
DividendsIncentivesStage: dividendsIncentivesRuleDomain.DividendsIncentivesStage,
|
|
|
|
DividendsIncentivesStageEnd: dividendsIncentivesRuleDomain.DividendsIncentivesStageEnd,
|
|
|
|
DividendsIncentivesStageStart: dividendsIncentivesRuleDomain.DividendsIncentivesStageStart,
|
|
|
|
Org: dividendsIncentivesRuleDomain.Org,
|
|
|
|
Company: dividendsIncentivesRuleDomain.Company,
|
|
|
|
UpdatedAt: time.Time{},
|
|
|
|
DeletedAt: time.Time{},
|
|
|
|
CreatedAt: time.Now(),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
// 添加分红激励规则
|
|
|
|
if _, err := tx.Model(÷ndsIncentivesRulesToAddModels).Insert(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// 待更新或者删除的ids
|
|
|
|
var dividendsIncentivesRulesToUpdateOrDeleteIds []int64
|
|
|
|
for _, dividendsIncentivesRuleToUpdate := range dividendsIncentivesRulesToUpdate {
|
|
|
|
dividendsIncentivesRulesToUpdateOrDeleteIds = append(dividendsIncentivesRulesToUpdateOrDeleteIds, dividendsIncentivesRuleToUpdate.DividendsIncentivesRuleId)
|
|
|
|
}
|
|
|
|
|
|
|
|
// 待更新的分红激励规则id
|
|
|
|
dividendsRuleIdsToUpdate := utils.Intersect(dividendsIncentivesRuleIdsFetched, dividendsIncentivesRulesToUpdateOrDeleteIds)
|
|
|
|
var dividendsRuleModelsToUpdate []*models.DividendsIncentivesRule
|
|
|
|
for _, id := range dividendsRuleIdsToUpdate {
|
|
|
|
for _, dividendsIncentivesRuleModel := range dividendsIncentivesRulesFetched {
|
|
|
|
if dividendsIncentivesRuleModel.DividendsIncentivesRuleId == id {
|
|
|
|
dividendsRuleModelsToUpdate = append(dividendsRuleModelsToUpdate, dividendsIncentivesRuleModel)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if _, err := tx.Model(÷ndsRuleModelsToUpdate).WherePK().Update(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// 待删除的分红激励规则id
|
|
|
|
dividendsIncentivesRuleIdsToDelete := utils.Difference(dividendsIncentivesRuleIdsFetched, dividendsIncentivesRulesToUpdateOrDeleteIds)
|
|
|
|
var dividendsIncentivesRuleModelsToDelete []*models.DividendsIncentivesRule
|
|
|
|
for _, id := range dividendsIncentivesRuleIdsToDelete {
|
|
|
|
for _, dividendsIncentivesRuleModel := range dividendsIncentivesRulesFetched {
|
|
|
|
if dividendsIncentivesRuleModel.DividendsIncentivesRuleId == id {
|
|
|
|
dividendsIncentivesRuleModelsToDelete = append(dividendsIncentivesRuleModelsToDelete, dividendsIncentivesRuleModel)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if _, err := tx.Model(÷ndsIncentivesRuleModelsToDelete).WherePK().Delete(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
//TODO /********************** 更新金额激励规则 **************************/
|
|
|
|
|
|
|
|
// 获取金额激励规则列表
|
|
...
|
...
|
@@ -421,6 +496,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai |
|
|
|
}
|
|
|
|
return cooperationContract, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (repository *CooperationContractRepository) Remove(cooperationContract *domain.CooperationContract) (*domain.CooperationContract, error) {
|
|
|
|
tx := repository.transactionContext.PgTx
|
|
|
|
cooperationContractModel := new(models.CooperationContract)
|
|
...
|
...
|
@@ -471,6 +547,7 @@ func (repository *CooperationContractRepository) Remove(cooperationContract *dom |
|
|
|
}
|
|
|
|
return cooperationContract, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (repository *CooperationContractRepository) FindOne(queryOptions map[string]interface{}) (*domain.CooperationContract, error) {
|
|
|
|
tx := repository.transactionContext.PgTx
|
|
|
|
cooperationContractModel := new(models.CooperationContract)
|
|
...
|
...
|
@@ -525,6 +602,7 @@ func (repository *CooperationContractRepository) FindOne(queryOptions map[string |
|
|
|
cooperationContractUndertakerModels)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (repository *CooperationContractRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.CooperationContract, error) {
|
|
|
|
tx := repository.transactionContext.PgTx
|
|
|
|
var cooperationContractModels []*models.CooperationContract
|
|
...
|
...
|
@@ -581,6 +659,7 @@ func (repository *CooperationContractRepository) Find(queryOptions map[string]in |
|
|
|
return int64(count), cooperationContracts, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewCooperationContractRepository(transactionContext *pgTransaction.TransactionContext) (*CooperationContractRepository, error) {
|
|
|
|
if transactionContext == nil {
|
|
|
|
return nil, fmt.Errorf("transactionContext参数不能为nil")
|
...
|
...
|
|