作者 陈志颖

fix:去除结算单支付必填项校验

@@ -16,9 +16,9 @@ type PayCreditAccountCommand struct { @@ -16,9 +16,9 @@ type PayCreditAccountCommand struct {
16 // 账期结算实付金额 16 // 账期结算实付金额
17 ActuallyPaidAmount float64 `cname:"账期结算实付金额" json:"actuallyPaidAmount" valid:"Required"` 17 ActuallyPaidAmount float64 `cname:"账期结算实付金额" json:"actuallyPaidAmount" valid:"Required"`
18 // 备注 18 // 备注
19 - Remarks string `cname:"备注" json:"remarks" valid:"Required"` 19 + Remarks string `cname:"备注" json:"remarks"`
20 // 支付凭证附件 20 // 支付凭证附件
21 - PaymentDocumentAttachments []*domain.Attachment `cname:"支付凭证附件" json:"paymentDocumentAttachment" valid:"Required"` 21 + PaymentDocumentAttachments []*domain.Attachment `cname:"支付凭证附件" json:"paymentDocumentAttachment"`
22 // 公司ID,通过集成REST上下文获取 22 // 公司ID,通过集成REST上下文获取
23 CompanyId int64 `cname:"公司ID" json:"companyId" valid:"Required"` 23 CompanyId int64 `cname:"公司ID" json:"companyId" valid:"Required"`
24 // 组织机构ID 24 // 组织机构ID
@@ -609,6 +609,9 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent @@ -609,6 +609,9 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
609 }) 609 })
610 } 610 }
611 611
  612 + // 统计分红订单
  613 + var countDividendsOrders int32
  614 +
612 // 获取订单产品 615 // 获取订单产品
613 if _, orderGoods, err := orderGoodRepository.Find(map[string]interface{}{ 616 if _, orderGoods, err := orderGoodRepository.Find(map[string]interface{}{
614 "orderGoodIds": orderGoodIds, 617 "orderGoodIds": orderGoodIds,
@@ -634,9 +637,15 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent @@ -634,9 +637,15 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
634 if dividendsEstimateDetails, err := confirmDividendsIncentivesEstimateService.Confirm(orderGoods); err != nil { 637 if dividendsEstimateDetails, err := confirmDividendsIncentivesEstimateService.Confirm(orderGoods); err != nil {
635 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 638 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
636 } else { 639 } else {
637 - for _, dividendsEstimateDetail := range dividendsEstimateDetails { 640 + // 统计当前分红预算单数
  641 + count, err := dividendsEstimateDao.CountDividendsEstimate(map[string]interface{}{})
  642 + if err != nil {
  643 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  644 + }
  645 +
  646 + for i, dividendsEstimateDetail := range dividendsEstimateDetails {
638 // 生成分红预算单号 647 // 生成分红预算单号
639 - dividendsEstimateOrderNumber, err := dividendsEstimateDao.GenerateDividendsEstimateNumber() 648 + dividendsEstimateOrderNumber, err := dividendsEstimateDetail.GenerateSpecificDividendsEstimateNumber(int64(count), int64(i))
640 if err != nil { 649 if err != nil {
641 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 650 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
642 } 651 }
@@ -718,25 +727,16 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent @@ -718,25 +727,16 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
718 "dividendsEstimates": dividendsEstimates, 727 "dividendsEstimates": dividendsEstimates,
719 }) 728 })
720 729
721 - // 创建成功的分红预算单  
722 - var dividendsEstimatesSavedSuccessfully []*domain.DividendsEstimate  
723 - // 创建失败的分红预算单  
724 - var dividendsEstimateSaveFailed []*domain.DividendsEstimate  
725 - for _, dividendsEstimate := range dividendsEstimates {  
726 - if dividendsEstimateSaved, err := dividendsEstimateRepository.Save(dividendsEstimate); err != nil {  
727 - dividendsEstimateSaveFailed = append(dividendsEstimateSaveFailed, dividendsEstimate) 730 + if dividendsEstimatesSaved, err := dividendsEstimateRepository.SaveMany(dividendsEstimates); err != nil {
728 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 731 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
729 - } else if dividendsEstimateSaved != nil {  
730 - dividendsEstimatesSavedSuccessfully = append(dividendsEstimatesSavedSuccessfully, dividendsEstimate)  
731 - }  
732 - }  
733 - 732 + } else {
734 if err := transactionContext.CommitTransaction(); err != nil { 733 if err := transactionContext.CommitTransaction(); err != nil {
735 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 734 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
736 } 735 }
737 // TODO 分析成功和失败原因 736 // TODO 分析成功和失败原因
738 -  
739 - return dividendsEstimatesSavedSuccessfully, nil 737 + successfullyCount := len(dividendsEstimatesSaved)
  738 + return fmt.Sprintf("已完成%d单订单分红预算,生成%d单分红预算,%d订单分红预算失败,失败原因:%s", countDividendsOrders, successfullyCount, 0, ""), nil
  739 + }
740 } 740 }
741 } 741 }
742 742
@@ -643,6 +643,9 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD @@ -643,6 +643,9 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
643 643
644 // 统计当前分红订单数 644 // 统计当前分红订单数
645 count, err := dividendsOrderDao.CountDividendsOrder(map[string]interface{}{}) 645 count, err := dividendsOrderDao.CountDividendsOrder(map[string]interface{}{})
  646 + if err != nil {
  647 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  648 + }
646 649
647 // 批量创建分红订单 650 // 批量创建分红订单
648 for i, dividendsOrder := range createDividendsOrderCommands { 651 for i, dividendsOrder := range createDividendsOrderCommands {
1 package service 1 package service
2 2
3 import ( 3 import (
  4 + "fmt"
4 coreDomain "github.com/linmadan/egglib-go/core/domain" 5 coreDomain "github.com/linmadan/egglib-go/core/domain"
5 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain" 6 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
  7 + "time"
6 ) 8 )
7 9
8 type DividendsEstimateDetail struct { 10 type DividendsEstimateDetail struct {
@@ -12,6 +14,28 @@ type DividendsEstimateDetail struct { @@ -12,6 +14,28 @@ type DividendsEstimateDetail struct {
12 DividendsAmount float64 `json:"dividendsAmount"` // 分红金额 14 DividendsAmount float64 `json:"dividendsAmount"` // 分红金额
13 } 15 }
14 16
  17 +// GenerateSpecificDividendsEstimateNumber 批量生成自定义分红预算单号
  18 +func (DividendsEstimateDetail *DividendsEstimateDetail) GenerateSpecificDividendsEstimateNumber(count int64, index int64) (string, error) {
  19 + currentTime := time.Now()
  20 + if count+index < 1000 {
  21 + countStr := fmt.Sprintf("%03d", count+index+1)
  22 + timestamp := currentTime.Unix()
  23 + timeNow := time.Unix(timestamp, 0)
  24 + timeString := timeNow.Format("20060102")
  25 + timeString = timeString[2:len(timeString)]
  26 + dividendsEstimateNumber := "FH" + timeString + "#" + countStr
  27 + return dividendsEstimateNumber, nil
  28 + } else {
  29 + countStr := fmt.Sprintf("%d", count+index+1)
  30 + timestamp := currentTime.Unix()
  31 + timeNow := time.Unix(timestamp, 0)
  32 + timeString := timeNow.Format("20060102")
  33 + timeString = timeString[2:len(timeString)]
  34 + dividendsEstimateNumber := "FH" + timeString + "#" + countStr
  35 + return dividendsEstimateNumber, nil
  36 + }
  37 +}
  38 +
15 type ConfirmDividendsIncentivesEstimateService interface { 39 type ConfirmDividendsIncentivesEstimateService interface {
16 coreDomain.DomainEventPublisher 40 coreDomain.DomainEventPublisher
17 Confirm(orderGoods []*domain.OrderGood) ([]*DividendsEstimateDetail, error) 41 Confirm(orderGoods []*domain.OrderGood) ([]*DividendsEstimateDetail, error)
@@ -75,6 +75,18 @@ func (dao *DividendsEstimateDao) UserEstimated(queryOptions map[string]interface @@ -75,6 +75,18 @@ func (dao *DividendsEstimateDao) UserEstimated(queryOptions map[string]interface
75 return ok, err 75 return ok, err
76 } 76 }
77 77
  78 +// CountDividendsEstimate 统计当前分红预算单总数
  79 +func (dao *DividendsEstimateDao) CountDividendsEstimate(queryOptions map[string]interface{}) (int, error) {
  80 + tx := dao.transactionContext.PgTx
  81 + var dividendsEstimateModels []*models.DividendsEstimate
  82 + query := tx.Model(&dividendsEstimateModels)
  83 + if count, err := query.AllWithDeleted().SelectAndCount(); err != nil {
  84 + return 0, err
  85 + } else {
  86 + return count, nil
  87 + }
  88 +}
  89 +
78 func NewDividendsEstimateDao(transactionContext *pgTransaction.TransactionContext) (*DividendsEstimateDao, error) { 90 func NewDividendsEstimateDao(transactionContext *pgTransaction.TransactionContext) (*DividendsEstimateDao, error) {
79 if transactionContext == nil { 91 if transactionContext == nil {
80 return nil, fmt.Errorf("transactionContext参数不能为空") 92 return nil, fmt.Errorf("transactionContext参数不能为空")
@@ -164,7 +164,16 @@ func (repository *DividendsEstimateRepository) SaveMany(dividendsEstimates []*do @@ -164,7 +164,16 @@ func (repository *DividendsEstimateRepository) SaveMany(dividendsEstimates []*do
164 tx := repository.transactionContext.PgTx 164 tx := repository.transactionContext.PgTx
165 var dividendsEstimateModels []*models.DividendsEstimate 165 var dividendsEstimateModels []*models.DividendsEstimate
166 for _, dividendsEstimate := range dividendsEstimates { 166 for _, dividendsEstimate := range dividendsEstimates {
  167 + if dividendsEstimate.Identify() == nil {
  168 + dividendsEstimateId, err := repository.nextIdentify()
  169 + if err != nil {
  170 + return nil, err
  171 + } else {
  172 + dividendsEstimate.DividendsEstimateId = dividendsEstimateId
  173 + }
  174 + }
167 dividendsEstimateModels = append(dividendsEstimateModels, &models.DividendsEstimate{ 175 dividendsEstimateModels = append(dividendsEstimateModels, &models.DividendsEstimate{
  176 + DividendsEstimateId: dividendsEstimate.DividendsEstimateId,
168 DividendsAccountStatus: dividendsEstimate.DividendsAccountStatus, 177 DividendsAccountStatus: dividendsEstimate.DividendsAccountStatus,
169 DividendsAmount: dividendsEstimate.DividendsAmount, 178 DividendsAmount: dividendsEstimate.DividendsAmount,
170 DividendsEstimateOrderNumber: dividendsEstimate.DividendsEstimateOrderNumber, 179 DividendsEstimateOrderNumber: dividendsEstimate.DividendsEstimateOrderNumber,