作者 陈志颖

refactor:优化分红预算

@@ -640,6 +640,26 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent @@ -640,6 +640,26 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
640 dividendsReturnedOrderRepository = value 640 dividendsReturnedOrderRepository = value
641 } 641 }
642 642
  643 + // 共创合约仓储初始化
  644 + var cooperationContractRepository domain.CooperationContractRepository
  645 + if value, err := factory.CreateCooperationContractRepository(map[string]interface{}{
  646 + "transactionContext": transactionContext,
  647 + }); err != nil {
  648 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  649 + } else {
  650 + cooperationContractRepository = value
  651 + }
  652 +
  653 + // 共创项目仓储初始化
  654 + var cooperationProjectRepository domain.CooperationProjectRepository
  655 + if value, err := factory.CreateCooperationProjectRepository(map[string]interface{}{
  656 + "transactionContext": transactionContext,
  657 + }); err != nil {
  658 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  659 + } else {
  660 + cooperationProjectRepository = value
  661 + }
  662 +
643 // 初始化确认业绩激励分红预算领域服务 663 // 初始化确认业绩激励分红预算领域服务
644 var confirmDividendsIncentivesEstimateService service.ConfirmDividendsIncentivesEstimateService 664 var confirmDividendsIncentivesEstimateService service.ConfirmDividendsIncentivesEstimateService
645 if value, err := factory.CreateConfirmDividendsIncentivesEstimateService(map[string]interface{}{ 665 if value, err := factory.CreateConfirmDividendsIncentivesEstimateService(map[string]interface{}{
@@ -653,6 +673,38 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent @@ -653,6 +673,38 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
653 }) 673 })
654 } 674 }
655 675
  676 + // 查询共创合约
  677 + cooperationContractsMap := make(map[string]*domain.CooperationContract, 0)
  678 + if count, cooperationContractsFound, err := cooperationContractRepository.Find(map[string]interface{}{
  679 + "companyId": confirmDividendsIncentivesEstimateCommand.CompanyId,
  680 + "orgId": confirmDividendsIncentivesEstimateCommand.OrgId,
  681 + "offsetLimit": false,
  682 + }); err != nil {
  683 + return nil, err
  684 + } else {
  685 + if count > 0 {
  686 + for _, cooperationContractFound := range cooperationContractsFound {
  687 + cooperationContractsMap[cooperationContractFound.CooperationContractNumber] = cooperationContractFound
  688 + }
  689 + }
  690 + }
  691 +
  692 + // 查询共创项目
  693 + cooperationProjectsMap := make(map[string]*domain.CooperationProject, 0)
  694 + if count, cooperationProjectsFound, err := cooperationProjectRepository.Find(map[string]interface{}{
  695 + "companyId": confirmDividendsIncentivesEstimateCommand.CompanyId,
  696 + "orgId": confirmDividendsIncentivesEstimateCommand.OrgId,
  697 + "offsetLimit": false,
  698 + }); err != nil {
  699 + return nil, err
  700 + } else {
  701 + if count > 0 {
  702 + for _, cooperationProjectFound := range cooperationProjectsFound {
  703 + cooperationProjectsMap[cooperationProjectFound.CooperationProjectNumber] = cooperationProjectFound
  704 + }
  705 + }
  706 + }
  707 +
656 // 统计成功预算的分红订单 708 // 统计成功预算的分红订单
657 estimateSuccessfullyDividendsOrders := make(map[string]string) 709 estimateSuccessfullyDividendsOrders := make(map[string]string)
658 710
@@ -684,7 +736,7 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent @@ -684,7 +736,7 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
684 orderGoodsToConfirm := make([]*domain.OrderGood, 0) 736 orderGoodsToConfirm := make([]*domain.OrderGood, 0)
685 orderGoodsToConfirm = append(orderGoodsToConfirm, orderGood) 737 orderGoodsToConfirm = append(orderGoodsToConfirm, orderGood)
686 // 分红订单产品预算 738 // 分红订单产品预算
687 - if dividendsEstimateDetails, err := confirmDividendsIncentivesEstimateService.Confirm(orderGoodsToConfirm, confirmDividendsIncentivesEstimateCommand.CompanyId, confirmDividendsIncentivesEstimateCommand.OrgId); err != nil { 739 + if dividendsEstimateDetails, err := confirmDividendsIncentivesEstimateService.Confirm(orderGoodsToConfirm, confirmDividendsIncentivesEstimateCommand.CompanyId, confirmDividendsIncentivesEstimateCommand.OrgId, cooperationContractsMap, cooperationProjectsMap); err != nil {
688 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 740 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
689 } else { 741 } else {
690 for _, dividendsEstimateDetail := range dividendsEstimateDetails { 742 for _, dividendsEstimateDetail := range dividendsEstimateDetails {
@@ -740,7 +792,7 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent @@ -740,7 +792,7 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
740 orderGoodsToConfirm := make([]*domain.OrderGood, 0) 792 orderGoodsToConfirm := make([]*domain.OrderGood, 0)
741 orderGoodsToConfirm = append(orderGoodsToConfirm, orderGood) 793 orderGoodsToConfirm = append(orderGoodsToConfirm, orderGood)
742 // 分红退货单产品预算 794 // 分红退货单产品预算
743 - if dividendsReturnedEstimateDetails, err := confirmDividendsIncentivesEstimateService.Confirm(orderGoodsToConfirm, confirmDividendsIncentivesEstimateCommand.CompanyId, confirmDividendsIncentivesEstimateCommand.OrgId); err != nil { 795 + if dividendsReturnedEstimateDetails, err := confirmDividendsIncentivesEstimateService.Confirm(orderGoodsToConfirm, confirmDividendsIncentivesEstimateCommand.CompanyId, confirmDividendsIncentivesEstimateCommand.OrgId, cooperationContractsMap, cooperationProjectsMap); err != nil {
744 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 796 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
745 } else { 797 } else {
746 for _, dividendsReturnedEstimateDetail := range dividendsReturnedEstimateDetails { 798 for _, dividendsReturnedEstimateDetail := range dividendsReturnedEstimateDetails {
@@ -43,5 +43,5 @@ func (DividendsEstimateDetail *DividendsEstimateDetail) GenerateSpecificDividend @@ -43,5 +43,5 @@ func (DividendsEstimateDetail *DividendsEstimateDetail) GenerateSpecificDividend
43 43
44 type ConfirmDividendsIncentivesEstimateService interface { 44 type ConfirmDividendsIncentivesEstimateService interface {
45 coreDomain.DomainEventPublisher 45 coreDomain.DomainEventPublisher
46 - Confirm(orderGoods []*domain.OrderGood, companyId int64, orgId int64) ([]*DividendsEstimateDetail, error) 46 + Confirm(orderGoods []*domain.OrderGood, companyId int64, orgId int64, cooperationContractsMap map[string]*domain.CooperationContract, cooperationProjectsMap map[string]*domain.CooperationProject) ([]*DividendsEstimateDetail, error)
47 } 47 }
@@ -17,25 +17,25 @@ type ConfirmDividendsIncentivesEstimateService struct { @@ -17,25 +17,25 @@ type ConfirmDividendsIncentivesEstimateService struct {
17 } 17 }
18 18
19 // Confirm 确认业绩分红预算 19 // Confirm 确认业绩分红预算
20 -func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoods []*domain.OrderGood, companyId int64, orgId int64) ([]*service.DividendsEstimateDetail, error) {  
21 - var cooperationContractRepository domain.CooperationContractRepository // 共创合约仓储  
22 - var cooperationProjectRepository domain.CooperationProjectRepository // 共创项目仓储 20 +func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoods []*domain.OrderGood, companyId int64, orgId int64, cooperationContractsMap map[string]*domain.CooperationContract, cooperationProjectsMap map[string]*domain.CooperationProject) ([]*service.DividendsEstimateDetail, error) {
  21 + //var cooperationContractRepository domain.CooperationContractRepository // 共创合约仓储
  22 + //var cooperationProjectRepository domain.CooperationProjectRepository // 共创项目仓储
23 var dividendsOrderRepository domain.DividendsOrderRepository // 分红订单仓储 23 var dividendsOrderRepository domain.DividendsOrderRepository // 分红订单仓储
24 var dividendsReturnedOrderRepository domain.DividendsReturnedOrderRepository // 分红退货单仓储 24 var dividendsReturnedOrderRepository domain.DividendsReturnedOrderRepository // 分红退货单仓储
25 25
26 // 共创合约仓储初始化 26 // 共创合约仓储初始化
27 - if repo, err := repository.NewCooperationContractRepository(domainService.transactionContext); err != nil {  
28 - return nil, err  
29 - } else {  
30 - cooperationContractRepository = repo  
31 - } 27 + //if repo, err := repository.NewCooperationContractRepository(domainService.transactionContext); err != nil {
  28 + // return nil, err
  29 + //} else {
  30 + // cooperationContractRepository = repo
  31 + //}
32 32
33 // 共创项目仓储初始化 33 // 共创项目仓储初始化
34 - if repo, err := repository.NewCooperationProjectRepository(domainService.transactionContext); err != nil {  
35 - return nil, err  
36 - } else {  
37 - cooperationProjectRepository = repo  
38 - } 34 + //if repo, err := repository.NewCooperationProjectRepository(domainService.transactionContext); err != nil {
  35 + // return nil, err
  36 + //} else {
  37 + // cooperationProjectRepository = repo
  38 + //}
39 39
40 // 分红订单仓储初始化 40 // 分红订单仓储初始化
41 if repo, err := repository.NewDividendsOrderRepository(domainService.transactionContext); err != nil { 41 if repo, err := repository.NewDividendsOrderRepository(domainService.transactionContext); err != nil {
@@ -52,36 +52,36 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo @@ -52,36 +52,36 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
52 } 52 }
53 53
54 // 查询共创合约 54 // 查询共创合约
55 - cooperationContractsMap := make(map[string]*domain.CooperationContract, 0)  
56 - if count, cooperationContractsFound, err := cooperationContractRepository.Find(map[string]interface{}{  
57 - "companyId": companyId,  
58 - "orgId": orgId,  
59 - "offsetLimit": false,  
60 - }); err != nil {  
61 - return nil, err  
62 - } else {  
63 - if count > 0 {  
64 - for _, cooperationContractFound := range cooperationContractsFound {  
65 - cooperationContractsMap[cooperationContractFound.CooperationContractNumber] = cooperationContractFound  
66 - }  
67 - }  
68 - } 55 + //cooperationContractsMap := make(map[string]*domain.CooperationContract, 0)
  56 + //if count, cooperationContractsFound, err := cooperationContractRepository.Find(map[string]interface{}{
  57 + // "companyId": companyId,
  58 + // "orgId": orgId,
  59 + // "offsetLimit": false,
  60 + //}); err != nil {
  61 + // return nil, err
  62 + //} else {
  63 + // if count > 0 {
  64 + // for _, cooperationContractFound := range cooperationContractsFound {
  65 + // cooperationContractsMap[cooperationContractFound.CooperationContractNumber] = cooperationContractFound
  66 + // }
  67 + // }
  68 + //}
69 69
70 // 查询共创项目 70 // 查询共创项目
71 - cooperationProjectsMap := make(map[string]*domain.CooperationProject, 0)  
72 - if count, cooperationProjectsFound, err := cooperationProjectRepository.Find(map[string]interface{}{  
73 - "companyId": companyId,  
74 - "orgId": orgId,  
75 - "offsetLimit": false,  
76 - }); err != nil {  
77 - return nil, err  
78 - } else {  
79 - if count > 0 {  
80 - for _, cooperationProjectFound := range cooperationProjectsFound {  
81 - cooperationProjectsMap[cooperationProjectFound.CooperationProjectNumber] = cooperationProjectFound  
82 - }  
83 - }  
84 - } 71 + //cooperationProjectsMap := make(map[string]*domain.CooperationProject, 0)
  72 + //if count, cooperationProjectsFound, err := cooperationProjectRepository.Find(map[string]interface{}{
  73 + // "companyId": companyId,
  74 + // "orgId": orgId,
  75 + // "offsetLimit": false,
  76 + //}); err != nil {
  77 + // return nil, err
  78 + //} else {
  79 + // if count > 0 {
  80 + // for _, cooperationProjectFound := range cooperationProjectsFound {
  81 + // cooperationProjectsMap[cooperationProjectFound.CooperationProjectNumber] = cooperationProjectFound
  82 + // }
  83 + // }
  84 + //}
85 85
86 // 确认业绩分红预算 86 // 确认业绩分红预算
87 var dividendsEstimateDetails []*service.DividendsEstimateDetail 87 var dividendsEstimateDetails []*service.DividendsEstimateDetail