|
@@ -25,6 +25,7 @@ func (repository *CooperationContractRepository) nextIdentify() (int64, error) { |
|
@@ -25,6 +25,7 @@ func (repository *CooperationContractRepository) nextIdentify() (int64, error) { |
|
25
|
id, err := IdWorker.NextId()
|
25
|
id, err := IdWorker.NextId()
|
|
26
|
return id, err
|
26
|
return id, err
|
|
27
|
}
|
27
|
}
|
|
|
|
28
|
+
|
|
28
|
func (repository *CooperationContractRepository) Save(cooperationContract *domain.CooperationContract) (*domain.CooperationContract, error) {
|
29
|
func (repository *CooperationContractRepository) Save(cooperationContract *domain.CooperationContract) (*domain.CooperationContract, error) {
|
|
29
|
sqlBuildFields := []string{
|
30
|
sqlBuildFields := []string{
|
|
30
|
"cooperation_contract_id",
|
31
|
"cooperation_contract_id",
|
|
@@ -331,7 +332,6 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai |
|
@@ -331,7 +332,6 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai |
|
331
|
|
332
|
|
|
332
|
// 待更新相关人
|
333
|
// 待更新相关人
|
|
333
|
var cooperationContractUndertakersToUpdate []*domain.Undertaker
|
334
|
var cooperationContractUndertakersToUpdate []*domain.Undertaker
|
|
334
|
-
|
|
|
|
335
|
// 待添加相关人
|
335
|
// 待添加相关人
|
|
336
|
var cooperationContractUndertakersToAdd []*domain.Undertaker
|
336
|
var cooperationContractUndertakersToAdd []*domain.Undertaker
|
|
337
|
for _, undertaker := range cooperationContract.Undertakers {
|
337
|
for _, undertaker := range cooperationContract.Undertakers {
|
|
@@ -410,6 +410,81 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai |
|
@@ -410,6 +410,81 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai |
|
410
|
return nil, err
|
410
|
return nil, err
|
|
411
|
}
|
411
|
}
|
|
412
|
|
412
|
|
|
|
|
413
|
+ // 提取分红激励规则id
|
|
|
|
414
|
+ var dividendsIncentivesRuleIdsFetched []int64
|
|
|
|
415
|
+ for _, dividendsIncentivesRule := range dividendsIncentivesRulesFetched {
|
|
|
|
416
|
+ dividendsIncentivesRuleIdsFetched = append(dividendsIncentivesRuleIdsFetched, dividendsIncentivesRule.DividendsIncentivesRuleId)
|
|
|
|
417
|
+ }
|
|
|
|
418
|
+
|
|
|
|
419
|
+ // 待更新分红激励规则
|
|
|
|
420
|
+ var dividendsIncentivesRulesToUpdate []*domain.DividendsIncentivesRule
|
|
|
|
421
|
+ // 待添加分红激励规则
|
|
|
|
422
|
+ var dividendsIncentivesRulesToAdd []*domain.DividendsIncentivesRule
|
|
|
|
423
|
+ for _, dividendsIncentivesRule := range cooperationContract.DividendsIncentivesRules {
|
|
|
|
424
|
+ if dividendsIncentivesRule.DividendsIncentivesRuleId != 0 {
|
|
|
|
425
|
+ dividendsIncentivesRulesToUpdate = append(dividendsIncentivesRulesToUpdate, dividendsIncentivesRule)
|
|
|
|
426
|
+ } else {
|
|
|
|
427
|
+ dividendsIncentivesRulesToAdd = append(dividendsIncentivesRulesToAdd, dividendsIncentivesRule)
|
|
|
|
428
|
+ }
|
|
|
|
429
|
+ }
|
|
|
|
430
|
+
|
|
|
|
431
|
+ // 将待添加的分红激励规则领域模型转换为数据模型
|
|
|
|
432
|
+ var dividendsIncentivesRulesToAddModels []*models.DividendsIncentivesRule
|
|
|
|
433
|
+ for _, dividendsIncentivesRuleDomain := range dividendsIncentivesRulesToAdd {
|
|
|
|
434
|
+ dividendsIncentivesRulesToAddModels = append(dividendsIncentivesRulesToAddModels, &models.DividendsIncentivesRule{
|
|
|
|
435
|
+ CooperationContractNumber: dividendsIncentivesRuleDomain.CooperationContractNumber,
|
|
|
|
436
|
+ ReferrerPercentage: dividendsIncentivesRuleDomain.ReferrerPercentage,
|
|
|
|
437
|
+ SalesmanPercentage: dividendsIncentivesRuleDomain.SalesmanPercentage,
|
|
|
|
438
|
+ DividendsIncentivesPercentage: dividendsIncentivesRuleDomain.DividendsIncentivesPercentage,
|
|
|
|
439
|
+ DividendsIncentivesStage: dividendsIncentivesRuleDomain.DividendsIncentivesStage,
|
|
|
|
440
|
+ DividendsIncentivesStageEnd: dividendsIncentivesRuleDomain.DividendsIncentivesStageEnd,
|
|
|
|
441
|
+ DividendsIncentivesStageStart: dividendsIncentivesRuleDomain.DividendsIncentivesStageStart,
|
|
|
|
442
|
+ Org: dividendsIncentivesRuleDomain.Org,
|
|
|
|
443
|
+ Company: dividendsIncentivesRuleDomain.Company,
|
|
|
|
444
|
+ UpdatedAt: time.Time{},
|
|
|
|
445
|
+ DeletedAt: time.Time{},
|
|
|
|
446
|
+ CreatedAt: time.Now(),
|
|
|
|
447
|
+ })
|
|
|
|
448
|
+ }
|
|
|
|
449
|
+ // 添加分红激励规则
|
|
|
|
450
|
+ if _, err := tx.Model(÷ndsIncentivesRulesToAddModels).Insert(); err != nil {
|
|
|
|
451
|
+ return nil, err
|
|
|
|
452
|
+ }
|
|
|
|
453
|
+
|
|
|
|
454
|
+ // 待更新或者删除的ids
|
|
|
|
455
|
+ var dividendsIncentivesRulesToUpdateOrDeleteIds []int64
|
|
|
|
456
|
+ for _, dividendsIncentivesRuleToUpdate := range dividendsIncentivesRulesToUpdate {
|
|
|
|
457
|
+ dividendsIncentivesRulesToUpdateOrDeleteIds = append(dividendsIncentivesRulesToUpdateOrDeleteIds, dividendsIncentivesRuleToUpdate.DividendsIncentivesRuleId)
|
|
|
|
458
|
+ }
|
|
|
|
459
|
+
|
|
|
|
460
|
+ // 待更新的分红激励规则id
|
|
|
|
461
|
+ dividendsRuleIdsToUpdate := utils.Intersect(dividendsIncentivesRuleIdsFetched, dividendsIncentivesRulesToUpdateOrDeleteIds)
|
|
|
|
462
|
+ var dividendsRuleModelsToUpdate []*models.DividendsIncentivesRule
|
|
|
|
463
|
+ for _, id := range dividendsRuleIdsToUpdate {
|
|
|
|
464
|
+ for _, dividendsIncentivesRuleModel := range dividendsIncentivesRulesFetched {
|
|
|
|
465
|
+ if dividendsIncentivesRuleModel.DividendsIncentivesRuleId == id {
|
|
|
|
466
|
+ dividendsRuleModelsToUpdate = append(dividendsRuleModelsToUpdate, dividendsIncentivesRuleModel)
|
|
|
|
467
|
+ }
|
|
|
|
468
|
+ }
|
|
|
|
469
|
+ }
|
|
|
|
470
|
+ if _, err := tx.Model(÷ndsRuleModelsToUpdate).WherePK().Update(); err != nil {
|
|
|
|
471
|
+ return nil, err
|
|
|
|
472
|
+ }
|
|
|
|
473
|
+
|
|
|
|
474
|
+ // 待删除的分红激励规则id
|
|
|
|
475
|
+ dividendsIncentivesRuleIdsToDelete := utils.Difference(dividendsIncentivesRuleIdsFetched, dividendsIncentivesRulesToUpdateOrDeleteIds)
|
|
|
|
476
|
+ var dividendsIncentivesRuleModelsToDelete []*models.DividendsIncentivesRule
|
|
|
|
477
|
+ for _, id := range dividendsIncentivesRuleIdsToDelete {
|
|
|
|
478
|
+ for _, dividendsIncentivesRuleModel := range dividendsIncentivesRulesFetched {
|
|
|
|
479
|
+ if dividendsIncentivesRuleModel.DividendsIncentivesRuleId == id {
|
|
|
|
480
|
+ dividendsIncentivesRuleModelsToDelete = append(dividendsIncentivesRuleModelsToDelete, dividendsIncentivesRuleModel)
|
|
|
|
481
|
+ }
|
|
|
|
482
|
+ }
|
|
|
|
483
|
+ }
|
|
|
|
484
|
+ if _, err := tx.Model(÷ndsIncentivesRuleModelsToDelete).WherePK().Delete(); err != nil {
|
|
|
|
485
|
+ return nil, err
|
|
|
|
486
|
+ }
|
|
|
|
487
|
+
|
|
413
|
//TODO /********************** 更新金额激励规则 **************************/
|
488
|
//TODO /********************** 更新金额激励规则 **************************/
|
|
414
|
|
489
|
|
|
415
|
// 获取金额激励规则列表
|
490
|
// 获取金额激励规则列表
|
|
@@ -421,6 +496,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai |
|
@@ -421,6 +496,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai |
|
421
|
}
|
496
|
}
|
|
422
|
return cooperationContract, nil
|
497
|
return cooperationContract, nil
|
|
423
|
}
|
498
|
}
|
|
|
|
499
|
+
|
|
424
|
func (repository *CooperationContractRepository) Remove(cooperationContract *domain.CooperationContract) (*domain.CooperationContract, error) {
|
500
|
func (repository *CooperationContractRepository) Remove(cooperationContract *domain.CooperationContract) (*domain.CooperationContract, error) {
|
|
425
|
tx := repository.transactionContext.PgTx
|
501
|
tx := repository.transactionContext.PgTx
|
|
426
|
cooperationContractModel := new(models.CooperationContract)
|
502
|
cooperationContractModel := new(models.CooperationContract)
|
|
@@ -471,6 +547,7 @@ func (repository *CooperationContractRepository) Remove(cooperationContract *dom |
|
@@ -471,6 +547,7 @@ func (repository *CooperationContractRepository) Remove(cooperationContract *dom |
|
471
|
}
|
547
|
}
|
|
472
|
return cooperationContract, nil
|
548
|
return cooperationContract, nil
|
|
473
|
}
|
549
|
}
|
|
|
|
550
|
+
|
|
474
|
func (repository *CooperationContractRepository) FindOne(queryOptions map[string]interface{}) (*domain.CooperationContract, error) {
|
551
|
func (repository *CooperationContractRepository) FindOne(queryOptions map[string]interface{}) (*domain.CooperationContract, error) {
|
|
475
|
tx := repository.transactionContext.PgTx
|
552
|
tx := repository.transactionContext.PgTx
|
|
476
|
cooperationContractModel := new(models.CooperationContract)
|
553
|
cooperationContractModel := new(models.CooperationContract)
|
|
@@ -525,6 +602,7 @@ func (repository *CooperationContractRepository) FindOne(queryOptions map[string |
|
@@ -525,6 +602,7 @@ func (repository *CooperationContractRepository) FindOne(queryOptions map[string |
|
525
|
cooperationContractUndertakerModels)
|
602
|
cooperationContractUndertakerModels)
|
|
526
|
}
|
603
|
}
|
|
527
|
}
|
604
|
}
|
|
|
|
605
|
+
|
|
528
|
func (repository *CooperationContractRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.CooperationContract, error) {
|
606
|
func (repository *CooperationContractRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.CooperationContract, error) {
|
|
529
|
tx := repository.transactionContext.PgTx
|
607
|
tx := repository.transactionContext.PgTx
|
|
530
|
var cooperationContractModels []*models.CooperationContract
|
608
|
var cooperationContractModels []*models.CooperationContract
|
|
@@ -581,6 +659,7 @@ func (repository *CooperationContractRepository) Find(queryOptions map[string]in |
|
@@ -581,6 +659,7 @@ func (repository *CooperationContractRepository) Find(queryOptions map[string]in |
|
581
|
return int64(count), cooperationContracts, nil
|
659
|
return int64(count), cooperationContracts, nil
|
|
582
|
}
|
660
|
}
|
|
583
|
}
|
661
|
}
|
|
|
|
662
|
+
|
|
584
|
func NewCooperationContractRepository(transactionContext *pgTransaction.TransactionContext) (*CooperationContractRepository, error) {
|
663
|
func NewCooperationContractRepository(transactionContext *pgTransaction.TransactionContext) (*CooperationContractRepository, error) {
|
|
585
|
if transactionContext == nil {
|
664
|
if transactionContext == nil {
|
|
586
|
return nil, fmt.Errorf("transactionContext参数不能为nil")
|
665
|
return nil, fmt.Errorf("transactionContext参数不能为nil")
|