作者 陈志颖

refactor:优化分红预算提示信息

@@ -10,7 +10,7 @@ import ( @@ -10,7 +10,7 @@ import (
10 10
11 type ApplyForCooperationCommand struct { 11 type ApplyForCooperationCommand struct {
12 // 共创申请描述附件 12 // 共创申请描述附件
13 - CooperationApplicationAttachment []*domain.Attachment `cname:"共创申请描述附件" json:"cooperationApplicationAttachment" valid:"Required"` 13 + CooperationApplicationAttachment []*domain.Attachment `cname:"共创申请描述附件" json:"cooperationApplicationAttachment"`
14 // 共创申请描述 14 // 共创申请描述
15 CooperationApplicationDescription string `cname:"共创申请描述" json:"cooperationApplicationDescription,omitempty"` 15 CooperationApplicationDescription string `cname:"共创申请描述" json:"cooperationApplicationDescription,omitempty"`
16 // 申请人ID 16 // 申请人ID
@@ -546,25 +546,25 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent @@ -546,25 +546,25 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
546 operator = data 546 operator = data
547 } 547 }
548 548
549 - // 分红订单仓储初始化  
550 - var dividendsOrderRepository domain.DividendsOrderRepository  
551 - if value, err := factory.CreateDividendsOrderRepository(map[string]interface{}{  
552 - "transactionContext": transactionContext,  
553 - }); err != nil {  
554 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
555 - } else {  
556 - dividendsOrderRepository = value  
557 - } 549 + //// 分红订单仓储初始化
  550 + //var dividendsOrderRepository domain.DividendsOrderRepository
  551 + //if value, err := factory.CreateDividendsOrderRepository(map[string]interface{}{
  552 + // "transactionContext": transactionContext,
  553 + //}); err != nil {
  554 + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  555 + //} else {
  556 + // dividendsOrderRepository = value
  557 + //}
558 558
559 // 分红退货单仓储初始化 559 // 分红退货单仓储初始化
560 - var dividendsReturnedOrderRepository domain.DividendsReturnedOrderRepository  
561 - if value, err := factory.CreateDividendsReturnedOrderRepository(map[string]interface{}{  
562 - "transactionContext": transactionContext,  
563 - }); err != nil {  
564 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
565 - } else {  
566 - dividendsReturnedOrderRepository = value  
567 - } 560 + //var dividendsReturnedOrderRepository domain.DividendsReturnedOrderRepository
  561 + //if value, err := factory.CreateDividendsReturnedOrderRepository(map[string]interface{}{
  562 + // "transactionContext": transactionContext,
  563 + //}); err != nil {
  564 + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  565 + //} else {
  566 + // dividendsReturnedOrderRepository = value
  567 + //}
568 568
569 // 订单产品仓储初始化 569 // 订单产品仓储初始化
570 var orderGoodRepository domain.OrderGoodRepository 570 var orderGoodRepository domain.OrderGoodRepository
@@ -610,10 +610,10 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent @@ -610,10 +610,10 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
610 } 610 }
611 611
612 // 统计成功预算的分红订单 612 // 统计成功预算的分红订单
613 - var estimateSuccessfullyDividendsOrders map[string]int 613 + estimateSuccessfullyDividendsOrders := make(map[string]string)
614 614
615 // 统计预算失败的分红订单 615 // 统计预算失败的分红订单
616 - var estimateFailedDividendsOrders map[string]int 616 + estimateFailedDividendsOrders := make(map[string]string)
617 617
618 // 获取订单产品 618 // 获取订单产品
619 if _, orderGoods, err := orderGoodRepository.Find(map[string]interface{}{ 619 if _, orderGoods, err := orderGoodRepository.Find(map[string]interface{}{
@@ -621,7 +621,7 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent @@ -621,7 +621,7 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
621 }); err != nil { 621 }); err != nil {
622 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 622 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
623 } else { 623 } else {
624 - var dividendsEstimates []*domain.DividendsEstimate 624 + dividendsEstimates := make([]*domain.DividendsEstimate, 0)
625 // 统计当前分红预算单数 625 // 统计当前分红预算单数
626 count, err := dividendsEstimateDao.CountDividendsEstimate(map[string]interface{}{ 626 count, err := dividendsEstimateDao.CountDividendsEstimate(map[string]interface{}{
627 "companyId": confirmDividendsIncentivesEstimateCommand.CompanyId, 627 "companyId": confirmDividendsIncentivesEstimateCommand.CompanyId,
@@ -633,102 +633,116 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent @@ -633,102 +633,116 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
633 for _, orderGood := range orderGoods { 633 for _, orderGood := range orderGoods {
634 dividendsEstimate := &domain.DividendsEstimate{} 634 dividendsEstimate := &domain.DividendsEstimate{}
635 if orderGood.DividendsOrderNumber != "" { // 查询分红订单 635 if orderGood.DividendsOrderNumber != "" { // 查询分红订单
636 - dividendsOrder, err3 := dividendsOrderRepository.FindOne(map[string]interface{}{  
637 - "dividendsOrderNumber": orderGood.DividendsOrderNumber,  
638 - "companyId": orderGood.CompanyId,  
639 - "orgId": orderGood.OrgId,  
640 - })  
641 - if err3 != nil {  
642 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "分红订单不存在")  
643 - }  
644 - if dividendsOrder == nil {  
645 - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("分红订单%s不存在", orderGood.DividendsOrderNumber))  
646 - } 636 + //dividendsOrder, err3 := dividendsOrderRepository.FindOne(map[string]interface{}{
  637 + // "dividendsOrderNumber": orderGood.DividendsOrderNumber,
  638 + // "companyId": orderGood.CompanyId,
  639 + // "orgId": orderGood.OrgId,
  640 + //})
  641 + //if err3 != nil {
  642 + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "分红订单不存在")
  643 + //}
  644 + //if dividendsOrder == nil {
  645 + // return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("分红订单%s不存在", orderGood.DividendsOrderNumber))
  646 + //}
647 // 分红订单产品预算 647 // 分红订单产品预算
648 if dividendsEstimateDetails, err := confirmDividendsIncentivesEstimateService.Confirm(orderGoods); err != nil { 648 if dividendsEstimateDetails, err := confirmDividendsIncentivesEstimateService.Confirm(orderGoods); err != nil {
649 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 649 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
650 } else { 650 } else {
651 for _, dividendsEstimateDetail := range dividendsEstimateDetails { 651 for _, dividendsEstimateDetail := range dividendsEstimateDetails {
652 - // 生成分红预算单号  
653 - dividendsEstimateOrderNumber, err := dividendsEstimateDetail.GenerateSpecificDividendsEstimateNumber(int64(count), countDividendsEstimate)  
654 - if err != nil {  
655 - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())  
656 - }  
657 - countDividendsEstimate = countDividendsEstimate + 1  
658 - dividendsEstimate = &domain.DividendsEstimate{  
659 - DividendsEstimateId: 0,  
660 - DividendsAccountStatus: domain.TO_BE_ACCOUNT,  
661 - DividendsAmount: dividendsEstimateDetail.DividendsAmount,  
662 - DividendsEstimateOrderNumber: dividendsEstimateOrderNumber,  
663 - DividendsEstimateTime: time.Now(),  
664 - DividendsParticipateType: dividendsEstimateDetail.DividendsParticipateType,  
665 - DividendsType: domain.ORDER_DIVIDENDS,  
666 - DividendsTypeName: "订单分红",  
667 - OrderOrReturnedOrderNum: orderGood.DividendsOrderNumber,  
668 - CooperationContractNumber: orderGood.CooperationContractNumber,  
669 - DividendsUser: dividendsEstimateDetail.DividendsUser,  
670 - DividendsStage: dividendsEstimateDetail.DividendsStage,  
671 - Org: organization,  
672 - Company: company,  
673 - Operator: operator,  
674 - OperateTime: time.Time{},  
675 - IsCanceled: false,  
676 - CreatedAt: time.Now(),  
677 - DeletedAt: time.Time{},  
678 - UpdatedAt: time.Time{},  
679 - OrderGoodId: orderGood.OrderGoodId,  
680 - OrderGoodAmount: orderGood.OrderGoodAmount, 652 + if dividendsEstimateDetail.IsSuccessfully {
  653 + // 生成分红预算单号
  654 + dividendsEstimateOrderNumber, err := dividendsEstimateDetail.GenerateSpecificDividendsEstimateNumber(int64(count), countDividendsEstimate)
  655 + if err != nil {
  656 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  657 + }
  658 +
  659 + // 记录成功的订单号
  660 + estimateSuccessfullyDividendsOrders[dividendsEstimateDetail.OrderOrReturnedOrderNumber] = dividendsEstimateDetail.OrderOrReturnedOrderNumber
  661 +
  662 + // 统计分红预算单数目
  663 + countDividendsEstimate = countDividendsEstimate + 1
  664 +
  665 + dividendsEstimate = &domain.DividendsEstimate{
  666 + DividendsEstimateId: 0,
  667 + DividendsAccountStatus: domain.TO_BE_ACCOUNT,
  668 + DividendsAmount: dividendsEstimateDetail.DividendsAmount,
  669 + DividendsEstimateOrderNumber: dividendsEstimateOrderNumber,
  670 + DividendsEstimateTime: time.Now(),
  671 + DividendsParticipateType: dividendsEstimateDetail.DividendsParticipateType,
  672 + DividendsType: domain.ORDER_DIVIDENDS,
  673 + DividendsTypeName: "订单分红",
  674 + OrderOrReturnedOrderNum: orderGood.DividendsOrderNumber,
  675 + CooperationContractNumber: orderGood.CooperationContractNumber,
  676 + DividendsUser: dividendsEstimateDetail.DividendsUser,
  677 + DividendsStage: dividendsEstimateDetail.DividendsStage,
  678 + Org: organization,
  679 + Company: company,
  680 + Operator: operator,
  681 + OperateTime: time.Time{},
  682 + IsCanceled: false,
  683 + CreatedAt: time.Now(),
  684 + DeletedAt: time.Time{},
  685 + UpdatedAt: time.Time{},
  686 + OrderGoodId: orderGood.OrderGoodId,
  687 + OrderGoodAmount: orderGood.OrderGoodAmount,
  688 + }
  689 +
  690 + dividendsEstimates = append(dividendsEstimates, dividendsEstimate)
  691 + } else {
  692 + // 记录失败的订单号和原因s
  693 + estimateFailedDividendsOrders[dividendsEstimateDetail.OrderOrReturnedOrderNumber] = dividendsEstimateDetail.Reason
681 } 694 }
682 - dividendsEstimates = append(dividendsEstimates, dividendsEstimate)  
683 } 695 }
684 } 696 }
685 } else if orderGood.DividendsReturnedOrderNumber != "" { // 查询分红退货单 697 } else if orderGood.DividendsReturnedOrderNumber != "" { // 查询分红退货单
686 - dividendsReturnedOrder, err := dividendsReturnedOrderRepository.FindOne(map[string]interface{}{"dividendsReturnedOrderNumber": orderGood.DividendsReturnedOrderNumber})  
687 - if err != nil {  
688 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
689 - }  
690 - if dividendsReturnedOrder == nil {  
691 - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("分红退货单%s不存在", orderGood.DividendsReturnedOrderNumber))  
692 - }  
693 // 分红退货单产品预算 698 // 分红退货单产品预算
694 if dividendsReturnedEstimateDetails, err := confirmDividendsIncentivesEstimateService.Confirm(orderGoods); err != nil { 699 if dividendsReturnedEstimateDetails, err := confirmDividendsIncentivesEstimateService.Confirm(orderGoods); err != nil {
695 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 700 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
696 } else { 701 } else {
697 for _, dividendsReturnedEstimateDetail := range dividendsReturnedEstimateDetails { 702 for _, dividendsReturnedEstimateDetail := range dividendsReturnedEstimateDetails {
698 - // 生成分红预算单号  
699 - dividendsEstimateOrderNumber, err := dividendsReturnedEstimateDetail.GenerateSpecificDividendsEstimateNumber(int64(count), countDividendsEstimate)  
700 - if err != nil {  
701 - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())  
702 - }  
703 - countDividendsEstimate = countDividendsEstimate + 1  
704 - if err != nil {  
705 - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())  
706 - }  
707 - dividendsEstimate = &domain.DividendsEstimate{  
708 - DividendsEstimateId: 0,  
709 - DividendsAccountStatus: domain.TO_BE_ACCOUNT,  
710 - DividendsAmount: dividendsReturnedEstimateDetail.DividendsAmount,  
711 - DividendsEstimateOrderNumber: dividendsEstimateOrderNumber,  
712 - DividendsEstimateTime: time.Now(),  
713 - DividendsParticipateType: dividendsReturnedEstimateDetail.DividendsParticipateType,  
714 - DividendsType: domain.RETURN_WRITE_OFF,  
715 - DividendsTypeName: "退货冲销",  
716 - OrderOrReturnedOrderNum: orderGood.DividendsReturnedOrderNumber,  
717 - CooperationContractNumber: orderGood.CooperationContractNumber,  
718 - DividendsUser: dividendsReturnedEstimateDetail.DividendsUser,  
719 - DividendsStage: dividendsReturnedEstimateDetail.DividendsStage,  
720 - Org: organization,  
721 - Company: company,  
722 - Operator: operator,  
723 - OperateTime: time.Time{},  
724 - IsCanceled: false,  
725 - CreatedAt: time.Now(),  
726 - DeletedAt: time.Time{},  
727 - UpdatedAt: time.Time{},  
728 - OrderGoodId: orderGood.OrderGoodId,  
729 - OrderGoodAmount: orderGood.OrderGoodAmount, 703 + if dividendsReturnedEstimateDetail.IsSuccessfully {
  704 + // 生成分红预算单号
  705 + dividendsEstimateOrderNumber, err := dividendsReturnedEstimateDetail.GenerateSpecificDividendsEstimateNumber(int64(count), countDividendsEstimate)
  706 + if err != nil {
  707 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  708 + }
  709 +
  710 + // 记录成功的退货单号
  711 + estimateSuccessfullyDividendsOrders[dividendsReturnedEstimateDetail.OrderOrReturnedOrderNumber] = dividendsReturnedEstimateDetail.OrderOrReturnedOrderNumber
  712 +
  713 + // 统计生成的预算单数量
  714 + countDividendsEstimate = countDividendsEstimate + 1
  715 +
  716 + dividendsEstimate = &domain.DividendsEstimate{
  717 + DividendsEstimateId: 0,
  718 + DividendsAccountStatus: domain.TO_BE_ACCOUNT,
  719 + DividendsAmount: dividendsReturnedEstimateDetail.DividendsAmount,
  720 + DividendsEstimateOrderNumber: dividendsEstimateOrderNumber,
  721 + DividendsEstimateTime: time.Now(),
  722 + DividendsParticipateType: dividendsReturnedEstimateDetail.DividendsParticipateType,
  723 + DividendsType: domain.RETURN_WRITE_OFF,
  724 + DividendsTypeName: "退货冲销",
  725 + OrderOrReturnedOrderNum: orderGood.DividendsReturnedOrderNumber,
  726 + CooperationContractNumber: orderGood.CooperationContractNumber,
  727 + DividendsUser: dividendsReturnedEstimateDetail.DividendsUser,
  728 + DividendsStage: dividendsReturnedEstimateDetail.DividendsStage,
  729 + Org: organization,
  730 + Company: company,
  731 + Operator: operator,
  732 + OperateTime: time.Time{},
  733 + IsCanceled: false,
  734 + CreatedAt: time.Now(),
  735 + DeletedAt: time.Time{},
  736 + UpdatedAt: time.Time{},
  737 + OrderGoodId: orderGood.OrderGoodId,
  738 + OrderGoodAmount: orderGood.OrderGoodAmount,
  739 + }
  740 +
  741 + dividendsEstimates = append(dividendsEstimates, dividendsEstimate)
  742 + } else {
  743 + // 记录失败的退货单号和原因
  744 + estimateFailedDividendsOrders[dividendsReturnedEstimateDetail.OrderOrReturnedOrderNumber] = dividendsReturnedEstimateDetail.Reason
730 } 745 }
731 - dividendsEstimates = append(dividendsEstimates, dividendsEstimate)  
732 } 746 }
733 } 747 }
734 } 748 }
@@ -744,8 +758,13 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent @@ -744,8 +758,13 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
744 } 758 }
745 // 分析成功和失败原因 759 // 分析成功和失败原因
746 successfullyCount := len(dividendsEstimatesSaved) 760 successfullyCount := len(dividendsEstimatesSaved)
  761 + // 错误原因收集,返回第一个可能的原因
  762 + var failedReason []string
  763 + for _, v := range estimateFailedDividendsOrders {
  764 + failedReason = append(failedReason, v)
  765 + }
747 return map[string]interface{}{ 766 return map[string]interface{}{
748 - "report": fmt.Sprintf("已完成%d笔单订单分红预算,生成%d笔单分红预算,%d笔订单分红预算失败,失败原因:%s", len(estimateSuccessfullyDividendsOrders), successfullyCount, len(estimateFailedDividendsOrders), ""), 767 + "report": fmt.Sprintf("已完成%d笔单订单分红预算,生成%d笔单分红预算,%d笔订单分红预算失败,失败原因:%s", len(estimateSuccessfullyDividendsOrders), successfullyCount, len(estimateFailedDividendsOrders), failedReason[0]),
749 }, nil 768 }, nil
750 } 769 }
751 } 770 }
@@ -842,11 +861,20 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmMoneyIncentives @@ -842,11 +861,20 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmMoneyIncentives
842 dividendsEstimateRepository = value 861 dividendsEstimateRepository = value
843 } 862 }
844 863
845 - cooperationContractId, _ := strconv.ParseInt(confirmMoneyIncentivesEstimateCommand.CooperationContractId, 10, 64)  
846 - undertakerUIDs, _ := utils.SliceAtoi(confirmMoneyIncentivesEstimateCommand.UndertakerUids) 864 + cooperationContractId, err := strconv.ParseInt(confirmMoneyIncentivesEstimateCommand.CooperationContractId, 10, 64)
  865 + if err != nil {
  866 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "合约编号类型错误:"+err.Error())
  867 + }
  868 +
  869 + undertakerUIDs, err := utils.SliceAtoi(confirmMoneyIncentivesEstimateCommand.UndertakerUids)
  870 + if err != nil {
  871 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "承接人UID类型错误:"+err.Error())
  872 + }
847 873
848 // 获取共创合约 874 // 获取共创合约
849 - cooperationContract, err := cooperationContractRepository.FindOne(map[string]interface{}{"cooperationContractId": cooperationContractId}) 875 + cooperationContract, err := cooperationContractRepository.FindOne(map[string]interface{}{
  876 + "cooperationContractId": cooperationContractId,
  877 + })
850 if err != nil { 878 if err != nil {
851 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 879 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
852 } 880 }
@@ -860,7 +888,10 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmMoneyIncentives @@ -860,7 +888,10 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmMoneyIncentives
860 count, err := dividendsEstimateDao.CountDividendsEstimate(map[string]interface{}{ 888 count, err := dividendsEstimateDao.CountDividendsEstimate(map[string]interface{}{
861 "companyId": confirmMoneyIncentivesEstimateCommand.CompanyId, 889 "companyId": confirmMoneyIncentivesEstimateCommand.CompanyId,
862 }) 890 })
  891 +
  892 + // 分红预算单统计
863 var countDividendsEstimate int64 893 var countDividendsEstimate int64
  894 +
864 // 共创合约预算 895 // 共创合约预算
865 if dividendsEstimateDetails, err2 := confirmMoneyIncentivesEstimateService.Confirm(cooperationContract, confirmMoneyIncentivesEstimateCommand.DividendsIncentivesStage, undertakerUIDs); err2 != nil { 896 if dividendsEstimateDetails, err2 := confirmMoneyIncentivesEstimateService.Confirm(cooperationContract, confirmMoneyIncentivesEstimateCommand.DividendsIncentivesStage, undertakerUIDs); err2 != nil {
866 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err2.Error()) 897 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err2.Error())
@@ -871,7 +902,10 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmMoneyIncentives @@ -871,7 +902,10 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmMoneyIncentives
871 if err != nil { 902 if err != nil {
872 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 903 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
873 } 904 }
  905 +
  906 + // 统计生成的预算单数目
874 countDividendsEstimate = countDividendsEstimate + 1 907 countDividendsEstimate = countDividendsEstimate + 1
  908 +
875 dividendsEstimate := &domain.DividendsEstimate{ 909 dividendsEstimate := &domain.DividendsEstimate{
876 DividendsEstimateId: 0, 910 DividendsEstimateId: 0,
877 DividendsAccountStatus: domain.TO_BE_ACCOUNT, 911 DividendsAccountStatus: domain.TO_BE_ACCOUNT,
@@ -894,6 +928,7 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmMoneyIncentives @@ -894,6 +928,7 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmMoneyIncentives
894 DeletedAt: time.Time{}, 928 DeletedAt: time.Time{},
895 UpdatedAt: time.Time{}, 929 UpdatedAt: time.Time{},
896 } 930 }
  931 +
897 dividendsEstimates = append(dividendsEstimates, dividendsEstimate) 932 dividendsEstimates = append(dividendsEstimates, dividendsEstimate)
898 } 933 }
899 dividendsEstimatesSaved, err := dividendsEstimateRepository.SaveMany(dividendsEstimates) 934 dividendsEstimatesSaved, err := dividendsEstimateRepository.SaveMany(dividendsEstimates)
@@ -8,10 +8,13 @@ import ( @@ -8,10 +8,13 @@ import (
8 ) 8 )
9 9
10 type DividendsEstimateDetail struct { 10 type DividendsEstimateDetail struct {
11 - DividendsUser *domain.User `json:"dividendsUser"` // 共创参与(分红用户)  
12 - DividendsParticipateType int32 `json:"dividendsParticipateType"` // 参与类型  
13 - DividendsStage int32 `json:"dividendsStage"` // 分红阶段  
14 - DividendsAmount float64 `json:"dividendsAmount"` // 分红金额 11 + DividendsUser *domain.User `json:"dividendsUser"` // 共创参与(分红用户)
  12 + DividendsParticipateType int32 `json:"dividendsParticipateType"` // 参与类型
  13 + DividendsStage int32 `json:"dividendsStage"` // 分红阶段
  14 + DividendsAmount float64 `json:"dividendsAmount"` // 分红金额
  15 + OrderOrReturnedOrderNumber string `json:"orderOrReturnedOrderNumber"` // 分红订单号或退货单号
  16 + IsSuccessfully bool `json:"isSuccessfully"` // 是否预算成功
  17 + Reason string `json:"reason"` // 错误原因
15 } 18 }
16 19
17 // GenerateSpecificDividendsEstimateNumber 批量生成自定义分红预算单号 20 // GenerateSpecificDividendsEstimateNumber 批量生成自定义分红预算单号
@@ -2,7 +2,6 @@ package domain_service @@ -2,7 +2,6 @@ package domain_service
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
5 - "github.com/linmadan/egglib-go/core/application"  
6 coreDomain "github.com/linmadan/egglib-go/core/domain" 5 coreDomain "github.com/linmadan/egglib-go/core/domain"
7 pgTransaction "github.com/linmadan/egglib-go/transaction/pg" 6 pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
8 "github.com/shopspring/decimal" 7 "github.com/shopspring/decimal"
@@ -57,29 +56,84 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo @@ -57,29 +56,84 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
57 // 获取合约 56 // 获取合约
58 cooperationContract, err := cooperationContractRepository.FindOne(map[string]interface{}{ 57 cooperationContract, err := cooperationContractRepository.FindOne(map[string]interface{}{
59 "cooperationContractNumber": orderGood.CooperationContractNumber, 58 "cooperationContractNumber": orderGood.CooperationContractNumber,
  59 + "companyId": orderGood.CompanyId,
  60 + "orgId": orderGood.OrgId,
60 }) 61 })
61 if err != nil { 62 if err != nil {
62 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 63 + dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
  64 + DividendsUser: nil,
  65 + DividendsParticipateType: 0,
  66 + DividendsStage: 0,
  67 + DividendsAmount: 0,
  68 + OrderOrReturnedOrderNumber: orderGood.DividendsOrderNumber,
  69 + IsSuccessfully: false,
  70 + Reason: "共创合约错误",
  71 + })
  72 + continue
  73 + //return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
63 } 74 }
64 if cooperationContract == nil { 75 if cooperationContract == nil {
65 - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("共创合约%s不存在", orderGood.CooperationContractNumber)) 76 + dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
  77 + DividendsUser: nil,
  78 + DividendsParticipateType: 0,
  79 + DividendsStage: 0,
  80 + DividendsAmount: 0,
  81 + OrderOrReturnedOrderNumber: orderGood.DividendsOrderNumber,
  82 + IsSuccessfully: false,
  83 + Reason: "共创合约" + orderGood.CooperationContractNumber + "不存在",
  84 + })
  85 + continue
  86 + //return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("共创合约%s不存在", orderGood.CooperationContractNumber))
66 } 87 }
67 88
68 // 获取共创项目 89 // 获取共创项目
69 cooperationProject, err := cooperationProjectRepository.FindOne(map[string]interface{}{ 90 cooperationProject, err := cooperationProjectRepository.FindOne(map[string]interface{}{
70 "cooperationProjectNumber": cooperationContract.CooperationProjectNumber, 91 "cooperationProjectNumber": cooperationContract.CooperationProjectNumber,
  92 + "companyId": cooperationContract.Company.CompanyId,
  93 + "orgId": cooperationContract.Org.OrgId,
  94 + "notPause": true,
71 }) 95 })
72 if err != nil { 96 if err != nil {
73 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 97 + dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
  98 + DividendsUser: nil,
  99 + DividendsParticipateType: 0,
  100 + DividendsStage: 0,
  101 + DividendsAmount: 0,
  102 + OrderOrReturnedOrderNumber: orderGood.DividendsOrderNumber,
  103 + IsSuccessfully: false,
  104 + Reason: "共创项目" + orderGood.CooperationContractNumber + "查询错误",
  105 + })
  106 + continue
  107 + //return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
74 } 108 }
75 if cooperationProject == nil { 109 if cooperationProject == nil {
76 - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("共创项目%s不存在", cooperationContract.CooperationProjectNumber)) 110 + dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
  111 + DividendsUser: nil,
  112 + DividendsParticipateType: 0,
  113 + DividendsStage: 0,
  114 + DividendsAmount: 0,
  115 + OrderOrReturnedOrderNumber: orderGood.DividendsOrderNumber,
  116 + IsSuccessfully: false,
  117 + Reason: "共创项目" + orderGood.CooperationContractNumber + "已结束或不存在",
  118 + })
  119 + continue
  120 + //return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("共创项目%s不存在", cooperationContract.CooperationProjectNumber))
77 } 121 }
78 122
79 // 校验合约关联的项目是否已结束 123 // 校验合约关联的项目是否已结束
80 - if cooperationProject.Status == 2 {  
81 - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("共创项目%s已结束", cooperationContract.CooperationProjectNumber))  
82 - } 124 + //if cooperationProject.Status == 2 {
  125 + // dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
  126 + // DividendsUser: nil,
  127 + // DividendsParticipateType: 0,
  128 + // DividendsStage: 0,
  129 + // DividendsAmount: 0,
  130 + // OrderOrReturnedOrderNumber: orderGood.DividendsOrderNumber,
  131 + // IsSuccessfully: false,
  132 + // Reason: "共创项目" + orderGood.CooperationContractNumber + "已结束",
  133 + // })
  134 + // continue
  135 + // //return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("共创项目%s已结束", cooperationContract.CooperationProjectNumber))
  136 + //}
83 137
84 if orderGood.DividendsOrderNumber != "" { // 获取分红订单 138 if orderGood.DividendsOrderNumber != "" { // 获取分红订单
85 // 获取分红订单 139 // 获取分红订单
@@ -89,10 +143,30 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo @@ -89,10 +143,30 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
89 "orgId": orderGood.OrgId, 143 "orgId": orderGood.OrgId,
90 }) 144 })
91 if err2 != nil { 145 if err2 != nil {
92 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "分红订单不存在") 146 + dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
  147 + DividendsUser: nil,
  148 + DividendsParticipateType: 0,
  149 + DividendsStage: 0,
  150 + DividendsAmount: 0,
  151 + OrderOrReturnedOrderNumber: orderGood.DividendsOrderNumber,
  152 + IsSuccessfully: false,
  153 + Reason: "分红订单" + orderGood.DividendsOrderNumber + "查询错误",
  154 + })
  155 + continue
  156 + //return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "分红订单不存在")
93 } 157 }
94 if dividendsOrder == nil { 158 if dividendsOrder == nil {
95 - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("分红订单%s不存在", orderGood.DividendsOrderNumber)) 159 + dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
  160 + DividendsUser: nil,
  161 + DividendsParticipateType: 0,
  162 + DividendsStage: 0,
  163 + DividendsAmount: 0,
  164 + OrderOrReturnedOrderNumber: orderGood.DividendsOrderNumber,
  165 + IsSuccessfully: false,
  166 + Reason: "分红订单" + orderGood.DividendsOrderNumber + "不存在",
  167 + })
  168 + continue
  169 + //return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("分红订单%s不存在", orderGood.DividendsOrderNumber))
96 } 170 }
97 171
98 // 匹配分红规则 172 // 匹配分红规则
@@ -104,7 +178,17 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo @@ -104,7 +178,17 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
104 } 178 }
105 } 179 }
106 if dividendsIncentivesRuleMatched == nil { 180 if dividendsIncentivesRuleMatched == nil {
107 - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, "未匹配到分红规则") 181 + dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
  182 + DividendsUser: nil,
  183 + DividendsParticipateType: 0,
  184 + DividendsStage: 0,
  185 + DividendsAmount: 0,
  186 + OrderOrReturnedOrderNumber: orderGood.DividendsOrderNumber,
  187 + IsSuccessfully: false,
  188 + Reason: "未匹配到分红规则",
  189 + })
  190 + continue
  191 + //return nil, application.ThrowError(application.RES_NO_FIND_ERROR, "未匹配到分红规则")
108 } 192 }
109 193
110 // 计算分红 194 // 计算分红
@@ -127,9 +211,11 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo @@ -127,9 +211,11 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
127 Status: undertaker.Status, 211 Status: undertaker.Status,
128 Company: undertaker.Company, 212 Company: undertaker.Company,
129 }, 213 },
130 - DividendsParticipateType: domain.UNDERTAKER,  
131 - DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage,  
132 - DividendsAmount: undertakerDividendsAmount, 214 + DividendsParticipateType: domain.UNDERTAKER,
  215 + DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage,
  216 + DividendsAmount: undertakerDividendsAmount,
  217 + OrderOrReturnedOrderNumber: dividendsOrder.DividendsOrderNumber,
  218 + IsSuccessfully: true,
133 }) 219 })
134 // 添加推荐人分红预算信息详情 220 // 添加推荐人分红预算信息详情
135 if undertaker.Referrer != nil { 221 if undertaker.Referrer != nil {
@@ -148,9 +234,11 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo @@ -148,9 +234,11 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
148 UserPhone: undertaker.Referrer.UserPhone, 234 UserPhone: undertaker.Referrer.UserPhone,
149 Company: undertaker.Referrer.Company, 235 Company: undertaker.Referrer.Company,
150 }, 236 },
151 - DividendsParticipateType: domain.REFERRER,  
152 - DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage,  
153 - DividendsAmount: referrerDividendsAmount, 237 + DividendsParticipateType: domain.REFERRER,
  238 + DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage,
  239 + DividendsAmount: referrerDividendsAmount,
  240 + OrderOrReturnedOrderNumber: dividendsOrder.DividendsOrderNumber,
  241 + IsSuccessfully: true,
154 }) 242 })
155 } 243 }
156 // 添加关联业务员分红预算信息详情 244 // 添加关联业务员分红预算信息详情
@@ -170,22 +258,46 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo @@ -170,22 +258,46 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
170 UserPhone: undertaker.Salesman.UserPhone, 258 UserPhone: undertaker.Salesman.UserPhone,
171 Company: undertaker.Salesman.Company, 259 Company: undertaker.Salesman.Company,
172 }, 260 },
173 - DividendsParticipateType: domain.SALESMAN,  
174 - DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage,  
175 - DividendsAmount: salesmanDividendsAmount, 261 + DividendsParticipateType: domain.SALESMAN,
  262 + DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage,
  263 + DividendsAmount: salesmanDividendsAmount,
  264 + OrderOrReturnedOrderNumber: dividendsOrder.DividendsOrderNumber,
  265 + IsSuccessfully: true,
176 }) 266 })
177 } 267 }
178 } 268 }
179 } 269 }
180 - } else if orderGood.DividendsReturnedOrderNumber != "" { // 获取分红退货单 270 + } else if orderGood.DividendsReturnedOrderNumber != "" { // 获取退货单
181 dividendsReturnedOrder, err3 := dividendsReturnedOrderRepository.FindOne(map[string]interface{}{ 271 dividendsReturnedOrder, err3 := dividendsReturnedOrderRepository.FindOne(map[string]interface{}{
182 "dividendsReturnedOrderNumber": orderGood.DividendsReturnedOrderNumber, 272 "dividendsReturnedOrderNumber": orderGood.DividendsReturnedOrderNumber,
  273 + "companyId": orderGood.CompanyId,
  274 + "orgId": orderGood.OrgId,
183 }) 275 })
184 if err3 != nil { 276 if err3 != nil {
185 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "分红退货单不存在") 277 + dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
  278 + DividendsUser: nil,
  279 + DividendsParticipateType: 0,
  280 + DividendsStage: 0,
  281 + DividendsAmount: 0,
  282 + OrderOrReturnedOrderNumber: orderGood.DividendsReturnedOrderNumber,
  283 + IsSuccessfully: false,
  284 + Reason: "退货单" + orderGood.DividendsReturnedOrderNumber + "不存在",
  285 + })
  286 + continue
  287 + //return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "分红退货单不存在")
186 } 288 }
187 if dividendsReturnedOrder == nil { 289 if dividendsReturnedOrder == nil {
188 - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", orderGood.DividendsReturnedOrderNumber)) 290 + dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
  291 + DividendsUser: nil,
  292 + DividendsParticipateType: 0,
  293 + DividendsStage: 0,
  294 + DividendsAmount: 0,
  295 + OrderOrReturnedOrderNumber: orderGood.DividendsReturnedOrderNumber,
  296 + IsSuccessfully: false,
  297 + Reason: "退货单" + orderGood.DividendsReturnedOrderNumber + "不存在",
  298 + })
  299 + continue
  300 + //return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", orderGood.DividendsReturnedOrderNumber))
189 } 301 }
190 // 匹配分红规则 302 // 匹配分红规则
191 var dividendsIncentivesRuleMatched *domain.DividendsIncentivesRule 303 var dividendsIncentivesRuleMatched *domain.DividendsIncentivesRule
@@ -214,9 +326,11 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo @@ -214,9 +326,11 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
214 Status: undertaker.Status, 326 Status: undertaker.Status,
215 Company: undertaker.Company, 327 Company: undertaker.Company,
216 }, 328 },
217 - DividendsParticipateType: domain.UNDERTAKER,  
218 - DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage,  
219 - DividendsAmount: -undertakerDividendsAmount, 329 + DividendsParticipateType: domain.UNDERTAKER,
  330 + DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage,
  331 + DividendsAmount: -undertakerDividendsAmount,
  332 + OrderOrReturnedOrderNumber: dividendsReturnedOrder.DividendsOrderNumber,
  333 + IsSuccessfully: true,
220 }) 334 })
221 // 添加推荐人分红退货预算信息详情 335 // 添加推荐人分红退货预算信息详情
222 if undertaker.Referrer != nil { 336 if undertaker.Referrer != nil {
@@ -235,9 +349,11 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo @@ -235,9 +349,11 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
235 UserPhone: undertaker.Referrer.UserPhone, 349 UserPhone: undertaker.Referrer.UserPhone,
236 Company: undertaker.Referrer.Company, 350 Company: undertaker.Referrer.Company,
237 }, 351 },
238 - DividendsParticipateType: domain.REFERRER,  
239 - DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage,  
240 - DividendsAmount: -referrerDividendsAmount, 352 + DividendsParticipateType: domain.REFERRER,
  353 + DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage,
  354 + DividendsAmount: -referrerDividendsAmount,
  355 + OrderOrReturnedOrderNumber: dividendsReturnedOrder.DividendsOrderNumber,
  356 + IsSuccessfully: true,
241 }) 357 })
242 } 358 }
243 // 添加关联业务员分红退货预算信息详情 359 // 添加关联业务员分红退货预算信息详情
@@ -257,9 +373,11 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo @@ -257,9 +373,11 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
257 UserPhone: undertaker.Salesman.UserPhone, 373 UserPhone: undertaker.Salesman.UserPhone,
258 Company: undertaker.Salesman.Company, 374 Company: undertaker.Salesman.Company,
259 }, 375 },
260 - DividendsParticipateType: domain.SALESMAN,  
261 - DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage,  
262 - DividendsAmount: -salesmanDividendsAmount, 376 + DividendsParticipateType: domain.SALESMAN,
  377 + DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage,
  378 + DividendsAmount: -salesmanDividendsAmount,
  379 + OrderOrReturnedOrderNumber: dividendsReturnedOrder.DividendsOrderNumber,
  380 + IsSuccessfully: true,
263 }) 381 })
264 } 382 }
265 } 383 }
@@ -17,16 +17,8 @@ type ConfirmMoneyIncentivesEstimateService struct { @@ -17,16 +17,8 @@ type ConfirmMoneyIncentivesEstimateService struct {
17 } 17 }
18 18
19 func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *domain.CooperationContract, stage int32, undertakerUIDs []int64) ([]*service.DividendsEstimateDetail, error) { 19 func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *domain.CooperationContract, stage int32, undertakerUIDs []int64) ([]*service.DividendsEstimateDetail, error) {
20 - //var dividendsEstimateRepository domain.DividendsEstimateRepository // 分红预算单仓储  
21 var dividendsEstimateDao *dao.DividendsEstimateDao // 分红预算DAO 20 var dividendsEstimateDao *dao.DividendsEstimateDao // 分红预算DAO
22 21
23 - // 分红预算单仓储初始化  
24 - //if repo, err := repository.NewDividendsEstimateRepository(domainService.transactionContext); err != nil {  
25 - // return nil, err  
26 - //} else {  
27 - // dividendsEstimateRepository = repo  
28 - //}  
29 -  
30 // 分红预算DAO初始化 22 // 分红预算DAO初始化
31 if estimateDao, err := dao.NewDividendsEstimateDao(domainService.transactionContext); err != nil { 23 if estimateDao, err := dao.NewDividendsEstimateDao(domainService.transactionContext); err != nil {
32 return nil, err 24 return nil, err
@@ -220,6 +220,9 @@ func (repository *CooperationProjectRepository) FindOne(queryOptions map[string] @@ -220,6 +220,9 @@ func (repository *CooperationProjectRepository) FindOne(queryOptions map[string]
220 if cooperationProjectId, ok := queryOptions["cooperationProjectId"]; ok && cooperationProjectId.(int64) != 0 { 220 if cooperationProjectId, ok := queryOptions["cooperationProjectId"]; ok && cooperationProjectId.(int64) != 0 {
221 query.Where("cooperation_project.cooperation_project_id = ?", cooperationProjectId) 221 query.Where("cooperation_project.cooperation_project_id = ?", cooperationProjectId)
222 } 222 }
  223 + if notPause, ok := queryOptions["notPause"]; ok && notPause.(bool) != false {
  224 + query.Where("status <> ?", 2)
  225 + }
223 if err := query.First(); err != nil { 226 if err := query.First(); err != nil {
224 if err.Error() == "pg: no rows in result set" { 227 if err.Error() == "pg: no rows in result set" {
225 return nil, fmt.Errorf("共创项目不存在") 228 return nil, fmt.Errorf("共创项目不存在")
@@ -195,18 +195,21 @@ func (repository *DividendsEstimateRepository) SaveMany(dividendsEstimates []*do @@ -195,18 +195,21 @@ func (repository *DividendsEstimateRepository) SaveMany(dividendsEstimates []*do
195 UpdatedAt: dividendsEstimate.UpdatedAt, 195 UpdatedAt: dividendsEstimate.UpdatedAt,
196 }) 196 })
197 } 197 }
198 - if _, err := tx.Model(&dividendsEstimateModels).Insert(); err != nil {  
199 - return nil, err  
200 - }  
201 - var dividendsEstimatesSaved []*domain.DividendsEstimate  
202 - for _, dividendsEstimateModel := range dividendsEstimateModels {  
203 - if dividendsEstimate, err := transform.TransformToDividendsEstimateDomainModelFromPgModels(dividendsEstimateModel); err != nil {  
204 - return dividendsEstimates, err  
205 - } else {  
206 - dividendsEstimatesSaved = append(dividendsEstimatesSaved, dividendsEstimate) 198 + if len(dividendsEstimateModels) > 0 {
  199 + if _, err := tx.Model(&dividendsEstimateModels).Insert(); err != nil {
  200 + return nil, err
  201 + }
  202 + var dividendsEstimatesSaved []*domain.DividendsEstimate
  203 + for _, dividendsEstimateModel := range dividendsEstimateModels {
  204 + if dividendsEstimate, err := transform.TransformToDividendsEstimateDomainModelFromPgModels(dividendsEstimateModel); err != nil {
  205 + return dividendsEstimates, err
  206 + } else {
  207 + dividendsEstimatesSaved = append(dividendsEstimatesSaved, dividendsEstimate)
  208 + }
207 } 209 }
  210 + return dividendsEstimatesSaved, nil
208 } 211 }
209 - return dividendsEstimatesSaved, nil 212 + return nil, nil
210 } 213 }
211 214
212 func (repository *DividendsEstimateRepository) UpdateMany(dividendsEstimates []*domain.DividendsEstimate) ([]*domain.DividendsEstimate, error) { 215 func (repository *DividendsEstimateRepository) UpdateMany(dividendsEstimates []*domain.DividendsEstimate) ([]*domain.DividendsEstimate, error) {