|
@@ -521,6 +521,7 @@ func (dividendsEstimateService *DividendsEstimateService) CreateDividendsEstimat |
|
@@ -521,6 +521,7 @@ func (dividendsEstimateService *DividendsEstimateService) CreateDividendsEstimat |
521
|
|
521
|
|
522
|
// ConfirmDividendsIncentivesEstimate 确定业绩激励分红预算
|
522
|
// ConfirmDividendsIncentivesEstimate 确定业绩激励分红预算
|
523
|
func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncentivesEstimate(confirmDividendsIncentivesEstimateCommand *command.ConfirmDividendsIncentivesEstimateCommand) (interface{}, error) {
|
523
|
func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncentivesEstimate(confirmDividendsIncentivesEstimateCommand *command.ConfirmDividendsIncentivesEstimateCommand) (interface{}, error) {
|
|
|
524
|
+ start := time.Now()
|
524
|
if err := confirmDividendsIncentivesEstimateCommand.ValidateCommand(); err != nil {
|
525
|
if err := confirmDividendsIncentivesEstimateCommand.ValidateCommand(); err != nil {
|
525
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
526
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
526
|
}
|
527
|
}
|
|
@@ -550,12 +551,14 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
@@ -550,12 +551,14 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
550
|
}
|
551
|
}
|
551
|
|
552
|
|
552
|
// 获取公司信息
|
553
|
// 获取公司信息
|
|
|
554
|
+ startGetCompany := time.Now()
|
553
|
var company *domain.Company
|
555
|
var company *domain.Company
|
554
|
if data, err := companyService.CompanyFrom(confirmDividendsIncentivesEstimateCommand.CompanyId); err != nil {
|
556
|
if data, err := companyService.CompanyFrom(confirmDividendsIncentivesEstimateCommand.CompanyId); err != nil {
|
555
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
557
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
556
|
} else {
|
558
|
} else {
|
557
|
company = data
|
559
|
company = data
|
558
|
}
|
560
|
}
|
|
|
561
|
+ fmt.Println("获取公司信息耗时:", time.Since(startGetCompany))
|
559
|
|
562
|
|
560
|
// 组织机构REST服务初始化
|
563
|
// 组织机构REST服务初始化
|
561
|
var organizationService service.OrgService
|
564
|
var organizationService service.OrgService
|
|
@@ -566,12 +569,14 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
@@ -566,12 +569,14 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
566
|
}
|
569
|
}
|
567
|
|
570
|
|
568
|
// 获取组织机构信息
|
571
|
// 获取组织机构信息
|
|
|
572
|
+ startGetOrg := time.Now()
|
569
|
var organization *domain.Org
|
573
|
var organization *domain.Org
|
570
|
if data, err := organizationService.OrgFrom(confirmDividendsIncentivesEstimateCommand.CompanyId, confirmDividendsIncentivesEstimateCommand.OrgId); err != nil {
|
574
|
if data, err := organizationService.OrgFrom(confirmDividendsIncentivesEstimateCommand.CompanyId, confirmDividendsIncentivesEstimateCommand.OrgId); err != nil {
|
571
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
575
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
572
|
} else {
|
576
|
} else {
|
573
|
organization = data
|
577
|
organization = data
|
574
|
}
|
578
|
}
|
|
|
579
|
+ fmt.Println("获取组织机构数据耗时:", time.Since(startGetOrg))
|
575
|
|
580
|
|
576
|
// 用户REST服务初始化
|
581
|
// 用户REST服务初始化
|
577
|
var userService service.UserService
|
582
|
var userService service.UserService
|
|
@@ -582,12 +587,14 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
@@ -582,12 +587,14 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
582
|
}
|
587
|
}
|
583
|
|
588
|
|
584
|
// 获取操作人
|
589
|
// 获取操作人
|
|
|
590
|
+ startGetOperator := time.Now()
|
585
|
var operator *domain.User
|
591
|
var operator *domain.User
|
586
|
if data, err := userService.OperatorFrom(confirmDividendsIncentivesEstimateCommand.CompanyId, confirmDividendsIncentivesEstimateCommand.OrgId, confirmDividendsIncentivesEstimateCommand.UserId); err != nil {
|
592
|
if data, err := userService.OperatorFrom(confirmDividendsIncentivesEstimateCommand.CompanyId, confirmDividendsIncentivesEstimateCommand.OrgId, confirmDividendsIncentivesEstimateCommand.UserId); err != nil {
|
587
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
593
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
588
|
} else {
|
594
|
} else {
|
589
|
operator = data
|
595
|
operator = data
|
590
|
}
|
596
|
}
|
|
|
597
|
+ fmt.Println("获取操作人耗时:", time.Since(startGetOperator))
|
591
|
|
598
|
|
592
|
// 订单产品仓储初始化
|
599
|
// 订单产品仓储初始化
|
593
|
var orderGoodRepository domain.OrderGoodRepository
|
600
|
var orderGoodRepository domain.OrderGoodRepository
|
|
@@ -649,16 +656,6 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
@@ -649,16 +656,6 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
649
|
cooperationContractRepository = value
|
656
|
cooperationContractRepository = value
|
650
|
}
|
657
|
}
|
651
|
|
658
|
|
652
|
- // 共创项目仓储初始化
|
|
|
653
|
- //var cooperationProjectRepository domain.CooperationProjectRepository
|
|
|
654
|
- //if value, err := factory.CreateCooperationProjectRepository(map[string]interface{}{
|
|
|
655
|
- // "transactionContext": transactionContext,
|
|
|
656
|
- //}); err != nil {
|
|
|
657
|
- // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
658
|
- //} else {
|
|
|
659
|
- // cooperationProjectRepository = value
|
|
|
660
|
- //}
|
|
|
661
|
-
|
|
|
662
|
// 初始化确认业绩激励分红预算领域服务
|
659
|
// 初始化确认业绩激励分红预算领域服务
|
663
|
var confirmDividendsIncentivesEstimateService service.ConfirmDividendsIncentivesEstimateService
|
660
|
var confirmDividendsIncentivesEstimateService service.ConfirmDividendsIncentivesEstimateService
|
664
|
if value, err := factory.CreateConfirmDividendsIncentivesEstimateService(map[string]interface{}{
|
661
|
if value, err := factory.CreateConfirmDividendsIncentivesEstimateService(map[string]interface{}{
|
|
@@ -672,26 +669,6 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
@@ -672,26 +669,6 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
672
|
})
|
669
|
})
|
673
|
}
|
670
|
}
|
674
|
|
671
|
|
675
|
- // 查询共创项目
|
|
|
676
|
- //cooperationProjectsMap := make(map[string]*domain.CooperationProject, 0)
|
|
|
677
|
- //if count, cooperationProjectsFound, err := cooperationProjectRepository.Find(map[string]interface{}{
|
|
|
678
|
- // "companyId": confirmDividendsIncentivesEstimateCommand.CompanyId,
|
|
|
679
|
- // "orgId": confirmDividendsIncentivesEstimateCommand.OrgId,
|
|
|
680
|
- // "offsetLimit": false,
|
|
|
681
|
- //}); err != nil {
|
|
|
682
|
- // return nil, err
|
|
|
683
|
- //} else {
|
|
|
684
|
- // if count > 0 {
|
|
|
685
|
- // for _, cooperationProjectFound := range cooperationProjectsFound {
|
|
|
686
|
- // cooperationProjectsMap[cooperationProjectFound.CooperationProjectNumber] = cooperationProjectFound
|
|
|
687
|
- // }
|
|
|
688
|
- // }
|
|
|
689
|
- //}
|
|
|
690
|
- //
|
|
|
691
|
- //log.Logger.Info("查询共创项目", map[string]interface{}{
|
|
|
692
|
- // "cooperationProjectsMap": cooperationProjectsMap,
|
|
|
693
|
- //})
|
|
|
694
|
-
|
|
|
695
|
// 统计成功预算的分红订单
|
672
|
// 统计成功预算的分红订单
|
696
|
estimateSuccessfullyDividendsOrders := make(map[string]string)
|
673
|
estimateSuccessfullyDividendsOrders := make(map[string]string)
|
697
|
|
674
|
|
|
@@ -699,12 +676,15 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
@@ -699,12 +676,15 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
699
|
estimateFailedDividendsOrders := make(map[string]string)
|
676
|
estimateFailedDividendsOrders := make(map[string]string)
|
700
|
|
677
|
|
701
|
// 获取订单产品
|
678
|
// 获取订单产品
|
|
|
679
|
+ startGetOrderGoods := time.Now()
|
702
|
if _, orderGoods, err := orderGoodRepository.Find(map[string]interface{}{
|
680
|
if _, orderGoods, err := orderGoodRepository.Find(map[string]interface{}{
|
703
|
"orderGoodIds": orderGoodIds,
|
681
|
"orderGoodIds": orderGoodIds,
|
704
|
"offsetLimit": false,
|
682
|
"offsetLimit": false,
|
705
|
}); err != nil {
|
683
|
}); err != nil {
|
706
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
684
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
707
|
} else {
|
685
|
} else {
|
|
|
686
|
+ fmt.Println("获取订单产品耗时:", time.Since(startGetOrderGoods))
|
|
|
687
|
+
|
708
|
dividendsEstimates := make([]*domain.DividendsEstimate, 0)
|
688
|
dividendsEstimates := make([]*domain.DividendsEstimate, 0)
|
709
|
|
689
|
|
710
|
var cooperationContractNumbers []string
|
690
|
var cooperationContractNumbers []string
|
|
@@ -716,26 +696,31 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
@@ -716,26 +696,31 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
716
|
|
696
|
|
717
|
newCooperationContractNumbers := utils.RemoveDuplicationString(cooperationContractNumbers)
|
697
|
newCooperationContractNumbers := utils.RemoveDuplicationString(cooperationContractNumbers)
|
718
|
|
698
|
|
719
|
- // 查询共创合约
|
|
|
720
|
cooperationContractsMap := make(map[string]*domain.CooperationContract, 0)
|
699
|
cooperationContractsMap := make(map[string]*domain.CooperationContract, 0)
|
721
|
- if count, cooperationContractsFound, err := cooperationContractRepository.Find(map[string]interface{}{
|
|
|
722
|
- "cooperationContractNumbers": newCooperationContractNumbers,
|
|
|
723
|
- "companyId": confirmDividendsIncentivesEstimateCommand.CompanyId,
|
|
|
724
|
- "orgId": confirmDividendsIncentivesEstimateCommand.OrgId,
|
|
|
725
|
- "offsetLimit": false,
|
|
|
726
|
- }); err != nil {
|
|
|
727
|
- return nil, err
|
|
|
728
|
- } else {
|
|
|
729
|
- if count > 0 {
|
|
|
730
|
- for _, cooperationContractFound := range cooperationContractsFound {
|
|
|
731
|
- cooperationContractsMap[cooperationContractFound.CooperationContractNumber] = cooperationContractFound
|
700
|
+
|
|
|
701
|
+ // 查询共创合约
|
|
|
702
|
+ startQueryContracts := time.Now()
|
|
|
703
|
+ if len(newCooperationContractNumbers) > 0 {
|
|
|
704
|
+ if count, cooperationContractsFound, err := cooperationContractRepository.Find(map[string]interface{}{
|
|
|
705
|
+ "cooperationContractNumbers": newCooperationContractNumbers,
|
|
|
706
|
+ "companyId": confirmDividendsIncentivesEstimateCommand.CompanyId,
|
|
|
707
|
+ "orgId": confirmDividendsIncentivesEstimateCommand.OrgId,
|
|
|
708
|
+ "offsetLimit": false,
|
|
|
709
|
+ }); err != nil {
|
|
|
710
|
+ return nil, err
|
|
|
711
|
+ } else {
|
|
|
712
|
+ if count > 0 {
|
|
|
713
|
+ for _, cooperationContractFound := range cooperationContractsFound {
|
|
|
714
|
+ cooperationContractsMap[cooperationContractFound.CooperationContractNumber] = cooperationContractFound
|
|
|
715
|
+ }
|
732
|
}
|
716
|
}
|
733
|
}
|
717
|
}
|
|
|
718
|
+ } else {
|
|
|
719
|
+ return map[string]interface{}{
|
|
|
720
|
+ "report": fmt.Sprintf("已完成0单订单分红预算,生成0单分红预算,失败原因:产品未关联合约"),
|
|
|
721
|
+ }, nil
|
734
|
}
|
722
|
}
|
735
|
-
|
|
|
736
|
- log.Logger.Info("查询共创合约", map[string]interface{}{
|
|
|
737
|
- "cooperationContractsMap": cooperationContractsMap,
|
|
|
738
|
- })
|
723
|
+ fmt.Println("查询共创合约耗时:", time.Since(startQueryContracts))
|
739
|
|
724
|
|
740
|
// 统计当前企业分红预算单数
|
725
|
// 统计当前企业分红预算单数
|
741
|
count, err := dividendsEstimateDao.CountDividendsEstimate(map[string]interface{}{
|
726
|
count, err := dividendsEstimateDao.CountDividendsEstimate(map[string]interface{}{
|
|
@@ -747,130 +732,132 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
@@ -747,130 +732,132 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
747
|
|
732
|
|
748
|
var countDividendsEstimate int64
|
733
|
var countDividendsEstimate int64
|
749
|
|
734
|
|
|
|
735
|
+ orderGoodsToConfirm := make([]*domain.OrderGood, 0)
|
|
|
736
|
+ returnedOrderGoodsToConfirm := make([]*domain.OrderGood, 0)
|
|
|
737
|
+
|
750
|
for _, orderGood := range orderGoods {
|
738
|
for _, orderGood := range orderGoods {
|
751
|
- dividendsEstimate := &domain.DividendsEstimate{}
|
|
|
752
|
- if orderGood.DividendsOrderNumber != "" { // 查询分红订单
|
|
|
753
|
- orderGoodsToConfirm := make([]*domain.OrderGood, 0)
|
739
|
+ if orderGood.DividendsOrderNumber != "" {
|
754
|
orderGoodsToConfirm = append(orderGoodsToConfirm, orderGood)
|
740
|
orderGoodsToConfirm = append(orderGoodsToConfirm, orderGood)
|
755
|
- // 分红订单产品预算
|
|
|
756
|
- if dividendsEstimateDetails, err := confirmDividendsIncentivesEstimateService.Confirm(orderGoodsToConfirm, confirmDividendsIncentivesEstimateCommand.CompanyId, confirmDividendsIncentivesEstimateCommand.OrgId, cooperationContractsMap); err != nil {
|
|
|
757
|
- return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
758
|
- } else {
|
|
|
759
|
- for _, dividendsEstimateDetail := range dividendsEstimateDetails {
|
|
|
760
|
- if dividendsEstimateDetail.IsSuccessfully {
|
|
|
761
|
- // 生成分红预算单号
|
|
|
762
|
- dividendsEstimateOrderNumber, err := dividendsEstimateDetail.GenerateSpecificDividendsEstimateNumber(int64(count), countDividendsEstimate)
|
|
|
763
|
- if err != nil {
|
|
|
764
|
- return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
765
|
- }
|
741
|
+ } else if orderGood.DividendsReturnedOrderNumber != "" {
|
|
|
742
|
+ returnedOrderGoodsToConfirm = append(returnedOrderGoodsToConfirm, orderGood)
|
|
|
743
|
+ }
|
|
|
744
|
+ }
|
766
|
|
745
|
|
767
|
- // 记录成功的订单号
|
|
|
768
|
- estimateSuccessfullyDividendsOrders[dividendsEstimateDetail.OrderOrReturnedOrderNumber] = dividendsEstimateDetail.OrderOrReturnedOrderNumber
|
|
|
769
|
-
|
|
|
770
|
- // 统计分红预算单数目
|
|
|
771
|
- countDividendsEstimate = countDividendsEstimate + 1
|
|
|
772
|
-
|
|
|
773
|
- dividendsEstimate = &domain.DividendsEstimate{
|
|
|
774
|
- DividendsEstimateId: 0,
|
|
|
775
|
- DividendsAccountStatus: domain.TO_BE_ACCOUNT,
|
|
|
776
|
- DividendsAmount: dividendsEstimateDetail.DividendsAmount,
|
|
|
777
|
- DividendsEstimateOrderNumber: dividendsEstimateOrderNumber,
|
|
|
778
|
- DividendsEstimateTime: time.Now(),
|
|
|
779
|
- DividendsParticipateType: dividendsEstimateDetail.DividendsParticipateType,
|
|
|
780
|
- DividendsType: domain.ORDER_DIVIDENDS,
|
|
|
781
|
- DividendsTypeName: "订单分红",
|
|
|
782
|
- OrderOrReturnedOrderNum: orderGood.DividendsOrderNumber,
|
|
|
783
|
- CooperationContractNumber: orderGood.CooperationContractNumber,
|
|
|
784
|
- DividendsUser: dividendsEstimateDetail.DividendsUser,
|
|
|
785
|
- DividendsPercentage: dividendsEstimateDetail.DividendsPercentage,
|
|
|
786
|
- DividendsStage: dividendsEstimateDetail.DividendsStage,
|
|
|
787
|
- Org: organization,
|
|
|
788
|
- Company: company,
|
|
|
789
|
- Operator: operator,
|
|
|
790
|
- OperateTime: time.Time{},
|
|
|
791
|
- IsCanceled: false,
|
|
|
792
|
- CreatedAt: time.Now(),
|
|
|
793
|
- DeletedAt: time.Time{},
|
|
|
794
|
- UpdatedAt: time.Time{},
|
|
|
795
|
- OrderGoodId: orderGood.OrderGoodId,
|
|
|
796
|
- OrderGoodAmount: orderGood.OrderGoodAmount,
|
|
|
797
|
- PaymentStatus: int32(1),
|
|
|
798
|
- CooperationContractUndertakerId: dividendsEstimateDetail.CooperationContractUndertakerId,
|
|
|
799
|
- }
|
746
|
+ startConfirm := time.Now()
|
|
|
747
|
+ if len(orderGoodsToConfirm) > 0 { // 分红订单产品预算
|
|
|
748
|
+ if dividendsEstimateDetails, err := confirmDividendsIncentivesEstimateService.Confirm(orderGoodsToConfirm, confirmDividendsIncentivesEstimateCommand.CompanyId, confirmDividendsIncentivesEstimateCommand.OrgId, cooperationContractsMap); err != nil {
|
|
|
749
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
750
|
+ } else {
|
|
|
751
|
+ for _, dividendsEstimateDetail := range dividendsEstimateDetails {
|
|
|
752
|
+ if dividendsEstimateDetail.IsSuccessfully {
|
|
|
753
|
+ // 生成分红预算单号
|
|
|
754
|
+ dividendsEstimateOrderNumber, err := dividendsEstimateDetail.GenerateSpecificDividendsEstimateNumber(int64(count), countDividendsEstimate)
|
|
|
755
|
+ if err != nil {
|
|
|
756
|
+ return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
757
|
+ }
|
800
|
|
758
|
|
801
|
- dividendsEstimates = append(dividendsEstimates, dividendsEstimate)
|
|
|
802
|
- } else {
|
|
|
803
|
- // 记录失败的订单号和原因
|
|
|
804
|
- estimateFailedDividendsOrders[dividendsEstimateDetail.OrderOrReturnedOrderNumber] = dividendsEstimateDetail.Reason
|
759
|
+ // 记录成功的订单号
|
|
|
760
|
+ estimateSuccessfullyDividendsOrders[dividendsEstimateDetail.OrderOrReturnedOrderNumber] = dividendsEstimateDetail.OrderOrReturnedOrderNumber
|
|
|
761
|
+
|
|
|
762
|
+ // 统计分红预算单数目
|
|
|
763
|
+ countDividendsEstimate = countDividendsEstimate + 1
|
|
|
764
|
+
|
|
|
765
|
+ dividendsEstimate := &domain.DividendsEstimate{
|
|
|
766
|
+ DividendsEstimateId: 0,
|
|
|
767
|
+ DividendsAccountStatus: domain.TO_BE_ACCOUNT,
|
|
|
768
|
+ DividendsAmount: dividendsEstimateDetail.DividendsAmount,
|
|
|
769
|
+ DividendsEstimateOrderNumber: dividendsEstimateOrderNumber,
|
|
|
770
|
+ DividendsEstimateTime: time.Now(),
|
|
|
771
|
+ DividendsParticipateType: dividendsEstimateDetail.DividendsParticipateType,
|
|
|
772
|
+ DividendsType: domain.ORDER_DIVIDENDS,
|
|
|
773
|
+ DividendsTypeName: "订单分红",
|
|
|
774
|
+ OrderOrReturnedOrderNum: dividendsEstimateDetail.OrderOrReturnedOrderNumber,
|
|
|
775
|
+ CooperationContractNumber: dividendsEstimateDetail.CooperationContractNumber,
|
|
|
776
|
+ DividendsUser: dividendsEstimateDetail.DividendsUser,
|
|
|
777
|
+ DividendsPercentage: dividendsEstimateDetail.DividendsPercentage,
|
|
|
778
|
+ DividendsStage: dividendsEstimateDetail.DividendsStage,
|
|
|
779
|
+ Org: organization,
|
|
|
780
|
+ Company: company,
|
|
|
781
|
+ Operator: operator,
|
|
|
782
|
+ OperateTime: time.Time{},
|
|
|
783
|
+ IsCanceled: false,
|
|
|
784
|
+ CreatedAt: time.Now(),
|
|
|
785
|
+ DeletedAt: time.Time{},
|
|
|
786
|
+ UpdatedAt: time.Time{},
|
|
|
787
|
+ OrderGoodId: dividendsEstimateDetail.OrderGoodId,
|
|
|
788
|
+ OrderGoodAmount: dividendsEstimateDetail.OrderGoodAmount,
|
|
|
789
|
+ PaymentStatus: int32(1),
|
|
|
790
|
+ CooperationContractUndertakerId: dividendsEstimateDetail.CooperationContractUndertakerId,
|
805
|
}
|
791
|
}
|
|
|
792
|
+
|
|
|
793
|
+ dividendsEstimates = append(dividendsEstimates, dividendsEstimate)
|
|
|
794
|
+ } else {
|
|
|
795
|
+ // 记录失败的订单号和原因
|
|
|
796
|
+ estimateFailedDividendsOrders[dividendsEstimateDetail.OrderOrReturnedOrderNumber] = dividendsEstimateDetail.Reason
|
806
|
}
|
797
|
}
|
807
|
}
|
798
|
}
|
808
|
- } else if orderGood.DividendsReturnedOrderNumber != "" { // 查询分红退货单
|
|
|
809
|
- orderGoodsToConfirm := make([]*domain.OrderGood, 0)
|
|
|
810
|
- orderGoodsToConfirm = append(orderGoodsToConfirm, orderGood)
|
|
|
811
|
- // 分红退货单产品预算
|
|
|
812
|
- if dividendsReturnedEstimateDetails, err := confirmDividendsIncentivesEstimateService.Confirm(orderGoodsToConfirm, confirmDividendsIncentivesEstimateCommand.CompanyId, confirmDividendsIncentivesEstimateCommand.OrgId, cooperationContractsMap); err != nil {
|
|
|
813
|
- return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
814
|
- } else {
|
|
|
815
|
- for _, dividendsReturnedEstimateDetail := range dividendsReturnedEstimateDetails {
|
|
|
816
|
- if dividendsReturnedEstimateDetail.IsSuccessfully {
|
|
|
817
|
- // 生成分红预算单号
|
|
|
818
|
- dividendsEstimateOrderNumber, err := dividendsReturnedEstimateDetail.GenerateSpecificDividendsEstimateNumber(int64(count), countDividendsEstimate)
|
|
|
819
|
- if err != nil {
|
|
|
820
|
- return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
821
|
- }
|
|
|
822
|
-
|
|
|
823
|
- // 记录成功的退货单号
|
|
|
824
|
- estimateSuccessfullyDividendsOrders[dividendsReturnedEstimateDetail.OrderOrReturnedOrderNumber] = dividendsReturnedEstimateDetail.OrderOrReturnedOrderNumber
|
|
|
825
|
-
|
|
|
826
|
- // 统计生成的预算单数量
|
|
|
827
|
- countDividendsEstimate = countDividendsEstimate + 1
|
|
|
828
|
-
|
|
|
829
|
- dividendsEstimate = &domain.DividendsEstimate{
|
|
|
830
|
- DividendsEstimateId: 0,
|
|
|
831
|
- DividendsAccountStatus: domain.TO_BE_ACCOUNT,
|
|
|
832
|
- DividendsAmount: dividendsReturnedEstimateDetail.DividendsAmount,
|
|
|
833
|
- DividendsEstimateOrderNumber: dividendsEstimateOrderNumber,
|
|
|
834
|
- DividendsEstimateTime: time.Now(),
|
|
|
835
|
- DividendsParticipateType: dividendsReturnedEstimateDetail.DividendsParticipateType,
|
|
|
836
|
- DividendsType: domain.RETURN_WRITE_OFF,
|
|
|
837
|
- DividendsTypeName: "退货冲销",
|
|
|
838
|
- OrderOrReturnedOrderNum: orderGood.DividendsReturnedOrderNumber,
|
|
|
839
|
- CooperationContractNumber: orderGood.CooperationContractNumber,
|
|
|
840
|
- DividendsUser: dividendsReturnedEstimateDetail.DividendsUser,
|
|
|
841
|
- DividendsPercentage: dividendsReturnedEstimateDetail.DividendsPercentage,
|
|
|
842
|
- DividendsStage: dividendsReturnedEstimateDetail.DividendsStage,
|
|
|
843
|
- Org: organization,
|
|
|
844
|
- Company: company,
|
|
|
845
|
- Operator: operator,
|
|
|
846
|
- OperateTime: time.Time{},
|
|
|
847
|
- IsCanceled: false,
|
|
|
848
|
- CreatedAt: time.Now(),
|
|
|
849
|
- DeletedAt: time.Time{},
|
|
|
850
|
- UpdatedAt: time.Time{},
|
|
|
851
|
- OrderGoodId: orderGood.OrderGoodId,
|
|
|
852
|
- OrderGoodAmount: orderGood.OrderGoodAmount,
|
|
|
853
|
- PaymentStatus: int32(1),
|
|
|
854
|
- CooperationContractUndertakerId: dividendsReturnedEstimateDetail.CooperationContractUndertakerId,
|
|
|
855
|
- }
|
799
|
+ }
|
|
|
800
|
+ } else if len(returnedOrderGoodsToConfirm) > 0 { // 退货单产品预算
|
|
|
801
|
+ if dividendsReturnedEstimateDetails, err := confirmDividendsIncentivesEstimateService.Confirm(returnedOrderGoodsToConfirm, confirmDividendsIncentivesEstimateCommand.CompanyId, confirmDividendsIncentivesEstimateCommand.OrgId, cooperationContractsMap); err != nil {
|
|
|
802
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
803
|
+ } else {
|
|
|
804
|
+ for _, dividendsReturnedEstimateDetail := range dividendsReturnedEstimateDetails {
|
|
|
805
|
+ if dividendsReturnedEstimateDetail.IsSuccessfully {
|
|
|
806
|
+ // 生成分红预算单号
|
|
|
807
|
+ dividendsEstimateOrderNumber, err := dividendsReturnedEstimateDetail.GenerateSpecificDividendsEstimateNumber(int64(count), countDividendsEstimate)
|
|
|
808
|
+ if err != nil {
|
|
|
809
|
+ return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
810
|
+ }
|
856
|
|
811
|
|
857
|
- dividendsEstimates = append(dividendsEstimates, dividendsEstimate)
|
|
|
858
|
- } else {
|
|
|
859
|
- // 记录失败的退货单号和原因
|
|
|
860
|
- estimateFailedDividendsOrders[dividendsReturnedEstimateDetail.OrderOrReturnedOrderNumber] = dividendsReturnedEstimateDetail.Reason
|
812
|
+ // 记录成功的退货单号
|
|
|
813
|
+ estimateSuccessfullyDividendsOrders[dividendsReturnedEstimateDetail.OrderOrReturnedOrderNumber] = dividendsReturnedEstimateDetail.OrderOrReturnedOrderNumber
|
|
|
814
|
+
|
|
|
815
|
+ // 统计生成的预算单数量
|
|
|
816
|
+ countDividendsEstimate = countDividendsEstimate + 1
|
|
|
817
|
+
|
|
|
818
|
+ dividendsEstimate := &domain.DividendsEstimate{
|
|
|
819
|
+ DividendsEstimateId: 0,
|
|
|
820
|
+ DividendsAccountStatus: domain.TO_BE_ACCOUNT,
|
|
|
821
|
+ DividendsAmount: dividendsReturnedEstimateDetail.DividendsAmount,
|
|
|
822
|
+ DividendsEstimateOrderNumber: dividendsEstimateOrderNumber,
|
|
|
823
|
+ DividendsEstimateTime: time.Now(),
|
|
|
824
|
+ DividendsParticipateType: dividendsReturnedEstimateDetail.DividendsParticipateType,
|
|
|
825
|
+ DividendsType: domain.RETURN_WRITE_OFF,
|
|
|
826
|
+ DividendsTypeName: "退货冲销",
|
|
|
827
|
+ OrderOrReturnedOrderNum: dividendsReturnedEstimateDetail.OrderOrReturnedOrderNumber,
|
|
|
828
|
+ CooperationContractNumber: dividendsReturnedEstimateDetail.CooperationContractNumber,
|
|
|
829
|
+ DividendsUser: dividendsReturnedEstimateDetail.DividendsUser,
|
|
|
830
|
+ DividendsPercentage: dividendsReturnedEstimateDetail.DividendsPercentage,
|
|
|
831
|
+ DividendsStage: dividendsReturnedEstimateDetail.DividendsStage,
|
|
|
832
|
+ Org: organization,
|
|
|
833
|
+ Company: company,
|
|
|
834
|
+ Operator: operator,
|
|
|
835
|
+ OperateTime: time.Time{},
|
|
|
836
|
+ IsCanceled: false,
|
|
|
837
|
+ CreatedAt: time.Now(),
|
|
|
838
|
+ DeletedAt: time.Time{},
|
|
|
839
|
+ UpdatedAt: time.Time{},
|
|
|
840
|
+ OrderGoodId: dividendsReturnedEstimateDetail.OrderGoodId,
|
|
|
841
|
+ OrderGoodAmount: dividendsReturnedEstimateDetail.OrderGoodAmount,
|
|
|
842
|
+ PaymentStatus: int32(1),
|
|
|
843
|
+ CooperationContractUndertakerId: dividendsReturnedEstimateDetail.CooperationContractUndertakerId,
|
861
|
}
|
844
|
}
|
|
|
845
|
+
|
|
|
846
|
+ dividendsEstimates = append(dividendsEstimates, dividendsEstimate)
|
|
|
847
|
+ } else {
|
|
|
848
|
+ // 记录失败的退货单号和原因
|
|
|
849
|
+ estimateFailedDividendsOrders[dividendsReturnedEstimateDetail.OrderOrReturnedOrderNumber] = dividendsReturnedEstimateDetail.Reason
|
862
|
}
|
850
|
}
|
863
|
}
|
851
|
}
|
864
|
}
|
852
|
}
|
865
|
}
|
853
|
}
|
|
|
854
|
+ fmt.Println("订单分红耗时:", time.Since(startConfirm))
|
866
|
|
855
|
|
867
|
- log.Logger.Info("新增的分红预算单", map[string]interface{}{
|
|
|
868
|
- "dividendsEstimates": dividendsEstimates,
|
|
|
869
|
- })
|
|
|
870
|
-
|
856
|
+ startInsert := time.Now()
|
871
|
if dividendsEstimatesSaved, err := dividendsEstimateRepository.SaveMany(dividendsEstimates); err != nil {
|
857
|
if dividendsEstimatesSaved, err := dividendsEstimateRepository.SaveMany(dividendsEstimates); err != nil {
|
872
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
858
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
873
|
} else {
|
859
|
} else {
|
|
|
860
|
+ fmt.Println("插入预算单耗时:", time.Since(startInsert))
|
874
|
// 获取产品ID
|
861
|
// 获取产品ID
|
875
|
orderGoodSavedIds := make([]int64, 0)
|
862
|
orderGoodSavedIds := make([]int64, 0)
|
876
|
for _, dividendsEstimate := range dividendsEstimates {
|
863
|
for _, dividendsEstimate := range dividendsEstimates {
|
|
@@ -878,6 +865,7 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
@@ -878,6 +865,7 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
878
|
}
|
865
|
}
|
879
|
|
866
|
|
880
|
// 更新订单产品分红状态
|
867
|
// 更新订单产品分红状态
|
|
|
868
|
+ startUpdateGoodStatus := time.Now()
|
881
|
var orderGoodsSaved []*domain.OrderGood
|
869
|
var orderGoodsSaved []*domain.OrderGood
|
882
|
if len(orderGoodSavedIds) > 0 {
|
870
|
if len(orderGoodSavedIds) > 0 {
|
883
|
// 订单产品ID去重
|
871
|
// 订单产品ID去重
|
|
@@ -899,6 +887,7 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
@@ -899,6 +887,7 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
899
|
}
|
887
|
}
|
900
|
}
|
888
|
}
|
901
|
}
|
889
|
}
|
|
|
890
|
+ fmt.Println("更新订单产品分红状态耗时:", time.Since(startUpdateGoodStatus))
|
902
|
|
891
|
|
903
|
// 分离分红订单和退货单
|
892
|
// 分离分红订单和退货单
|
904
|
dividendsOrderNumbers := make([]string, 0)
|
893
|
dividendsOrderNumbers := make([]string, 0)
|
|
@@ -915,15 +904,8 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
@@ -915,15 +904,8 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
915
|
}
|
904
|
}
|
916
|
}
|
905
|
}
|
917
|
|
906
|
|
918
|
- log.Logger.Info("分红订单", map[string]interface{}{
|
|
|
919
|
- "dividendsOrderNumbers": dividendsOrderNumbers,
|
|
|
920
|
- })
|
|
|
921
|
-
|
|
|
922
|
- log.Logger.Info("分红退货单", map[string]interface{}{
|
|
|
923
|
- "dividendsReturnedOrderNumbers": dividendsReturnedOrderNumbers,
|
|
|
924
|
- })
|
|
|
925
|
-
|
|
|
926
|
// 查找分红订单
|
907
|
// 查找分红订单
|
|
|
908
|
+ startUpdateOrder := time.Now()
|
927
|
if len(dividendsOrderNumbers) > 0 {
|
909
|
if len(dividendsOrderNumbers) > 0 {
|
928
|
if countDividendsOrdersFound, dividendsOrdersFound, err := dividendsOrderRepository.Find(map[string]interface{}{
|
910
|
if countDividendsOrdersFound, dividendsOrdersFound, err := dividendsOrderRepository.Find(map[string]interface{}{
|
929
|
"dividendsOrderNumbers": dividendsOrderNumbers,
|
911
|
"dividendsOrderNumbers": dividendsOrderNumbers,
|
|
@@ -966,8 +948,10 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
@@ -966,8 +948,10 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
966
|
}
|
948
|
}
|
967
|
}
|
949
|
}
|
968
|
}
|
950
|
}
|
|
|
951
|
+ fmt.Println("更新订单耗时:", time.Since(startUpdateOrder))
|
969
|
|
952
|
|
970
|
// 查找分红退货单
|
953
|
// 查找分红退货单
|
|
|
954
|
+ startUpdateReturnedOrder := time.Now()
|
971
|
if len(dividendsReturnedOrderNumbers) > 0 {
|
955
|
if len(dividendsReturnedOrderNumbers) > 0 {
|
972
|
if countDividendsReturnedOrdersFound, dividendsReturnedOrdersFound, err := dividendsReturnedOrderRepository.Find(map[string]interface{}{
|
956
|
if countDividendsReturnedOrdersFound, dividendsReturnedOrdersFound, err := dividendsReturnedOrderRepository.Find(map[string]interface{}{
|
973
|
"dividendsReturnedOrderNumbers": dividendsReturnedOrderNumbers,
|
957
|
"dividendsReturnedOrderNumbers": dividendsReturnedOrderNumbers,
|
|
@@ -1010,9 +994,13 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
@@ -1010,9 +994,13 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
1010
|
}
|
994
|
}
|
1011
|
}
|
995
|
}
|
1012
|
|
996
|
|
|
|
997
|
+ fmt.Println("更新退货单耗时:", time.Since(startUpdateReturnedOrder))
|
|
|
998
|
+
|
|
|
999
|
+ startCommit := time.Now()
|
1013
|
if err := transactionContext.CommitTransaction(); err != nil {
|
1000
|
if err := transactionContext.CommitTransaction(); err != nil {
|
1014
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
1001
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
1015
|
}
|
1002
|
}
|
|
|
1003
|
+ fmt.Println("提交事务耗时:", time.Since(startCommit))
|
1016
|
|
1004
|
|
1017
|
// 统计成功的分红预算
|
1005
|
// 统计成功的分红预算
|
1018
|
successfullyCount := len(dividendsEstimatesSaved)
|
1006
|
successfullyCount := len(dividendsEstimatesSaved)
|
|
@@ -1029,6 +1017,8 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
@@ -1029,6 +1017,8 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
1029
|
failedReasonStr = "无"
|
1017
|
failedReasonStr = "无"
|
1030
|
}
|
1018
|
}
|
1031
|
|
1019
|
|
|
|
1020
|
+ fmt.Println("函数执行完毕:", time.Since(start))
|
|
|
1021
|
+
|
1032
|
return map[string]interface{}{
|
1022
|
return map[string]interface{}{
|
1033
|
"report": fmt.Sprintf("已完成%d单订单分红预算,生成%d单分红预算,%d笔订单分红预算失败,失败原因:%s", len(estimateSuccessfullyDividendsOrders), successfullyCount, len(estimateFailedDividendsOrders), failedReasonStr),
|
1023
|
"report": fmt.Sprintf("已完成%d单订单分红预算,生成%d单分红预算,%d笔订单分红预算失败,失败原因:%s", len(estimateSuccessfullyDividendsOrders), successfullyCount, len(estimateFailedDividendsOrders), failedReasonStr),
|
1034
|
}, nil
|
1024
|
}, nil
|