作者 陈志颖

Merge branch 'dev-chenzhiying' into dev

... ... @@ -16,9 +16,9 @@ type PayCreditAccountCommand struct {
// 账期结算实付金额
ActuallyPaidAmount float64 `cname:"账期结算实付金额" json:"actuallyPaidAmount" valid:"Required"`
// 备注
Remarks string `cname:"备注" json:"remarks" valid:"Required"`
Remarks string `cname:"备注" json:"remarks"`
// 支付凭证附件
PaymentDocumentAttachments []*domain.Attachment `cname:"支付凭证附件" json:"paymentDocumentAttachment" valid:"Required"`
PaymentDocumentAttachments []*domain.Attachment `cname:"支付凭证附件" json:"paymentDocumentAttachment"`
// 公司ID,通过集成REST上下文获取
CompanyId int64 `cname:"公司ID" json:"companyId" valid:"Required"`
// 组织机构ID
... ...
... ... @@ -609,6 +609,9 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
})
}
// 统计分红订单
var countDividendsOrders int32
// 获取订单产品
if _, orderGoods, err := orderGoodRepository.Find(map[string]interface{}{
"orderGoodIds": orderGoodIds,
... ... @@ -634,9 +637,15 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
if dividendsEstimateDetails, err := confirmDividendsIncentivesEstimateService.Confirm(orderGoods); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
for _, dividendsEstimateDetail := range dividendsEstimateDetails {
// 统计当前分红预算单数
count, err := dividendsEstimateDao.CountDividendsEstimate(map[string]interface{}{})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
for i, dividendsEstimateDetail := range dividendsEstimateDetails {
// 生成分红预算单号
dividendsEstimateOrderNumber, err := dividendsEstimateDao.GenerateDividendsEstimateNumber()
dividendsEstimateOrderNumber, err := dividendsEstimateDetail.GenerateSpecificDividendsEstimateNumber(int64(count), int64(i))
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
... ... @@ -718,25 +727,16 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
"dividendsEstimates": dividendsEstimates,
})
// 创建成功的分红预算单
var dividendsEstimatesSavedSuccessfully []*domain.DividendsEstimate
// 创建失败的分红预算单
var dividendsEstimateSaveFailed []*domain.DividendsEstimate
for _, dividendsEstimate := range dividendsEstimates {
if dividendsEstimateSaved, err := dividendsEstimateRepository.Save(dividendsEstimate); err != nil {
dividendsEstimateSaveFailed = append(dividendsEstimateSaveFailed, dividendsEstimate)
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else if dividendsEstimateSaved != nil {
dividendsEstimatesSavedSuccessfully = append(dividendsEstimatesSavedSuccessfully, dividendsEstimate)
if dividendsEstimatesSaved, err := dividendsEstimateRepository.SaveMany(dividendsEstimates); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
// TODO 分析成功和失败原因
successfullyCount := len(dividendsEstimatesSaved)
return fmt.Sprintf("已完成%d单订单分红预算,生成%d单分红预算,%d订单分红预算失败,失败原因:%s", countDividendsOrders, successfullyCount, 0, ""), nil
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
// TODO 分析成功和失败原因
return dividendsEstimatesSavedSuccessfully, nil
}
}
... ...
... ... @@ -643,6 +643,9 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
// 统计当前分红订单数
count, err := dividendsOrderDao.CountDividendsOrder(map[string]interface{}{})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
// 批量创建分红订单
for i, dividendsOrder := range createDividendsOrderCommands {
... ...
package service
import (
"fmt"
coreDomain "github.com/linmadan/egglib-go/core/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
"time"
)
type DividendsEstimateDetail struct {
... ... @@ -12,6 +14,28 @@ type DividendsEstimateDetail struct {
DividendsAmount float64 `json:"dividendsAmount"` // 分红金额
}
// GenerateSpecificDividendsEstimateNumber 批量生成自定义分红预算单号
func (DividendsEstimateDetail *DividendsEstimateDetail) GenerateSpecificDividendsEstimateNumber(count int64, index int64) (string, error) {
currentTime := time.Now()
if count+index < 1000 {
countStr := fmt.Sprintf("%03d", count+index+1)
timestamp := currentTime.Unix()
timeNow := time.Unix(timestamp, 0)
timeString := timeNow.Format("20060102")
timeString = timeString[2:len(timeString)]
dividendsEstimateNumber := "FH" + timeString + "#" + countStr
return dividendsEstimateNumber, nil
} else {
countStr := fmt.Sprintf("%d", count+index+1)
timestamp := currentTime.Unix()
timeNow := time.Unix(timestamp, 0)
timeString := timeNow.Format("20060102")
timeString = timeString[2:len(timeString)]
dividendsEstimateNumber := "FH" + timeString + "#" + countStr
return dividendsEstimateNumber, nil
}
}
type ConfirmDividendsIncentivesEstimateService interface {
coreDomain.DomainEventPublisher
Confirm(orderGoods []*domain.OrderGood) ([]*DividendsEstimateDetail, error)
... ...
... ... @@ -75,6 +75,18 @@ func (dao *DividendsEstimateDao) UserEstimated(queryOptions map[string]interface
return ok, err
}
// CountDividendsEstimate 统计当前分红预算单总数
func (dao *DividendsEstimateDao) CountDividendsEstimate(queryOptions map[string]interface{}) (int, error) {
tx := dao.transactionContext.PgTx
var dividendsEstimateModels []*models.DividendsEstimate
query := tx.Model(&dividendsEstimateModels)
if count, err := query.AllWithDeleted().SelectAndCount(); err != nil {
return 0, err
} else {
return count, nil
}
}
func NewDividendsEstimateDao(transactionContext *pgTransaction.TransactionContext) (*DividendsEstimateDao, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为空")
... ...
... ... @@ -164,7 +164,16 @@ func (repository *DividendsEstimateRepository) SaveMany(dividendsEstimates []*do
tx := repository.transactionContext.PgTx
var dividendsEstimateModels []*models.DividendsEstimate
for _, dividendsEstimate := range dividendsEstimates {
if dividendsEstimate.Identify() == nil {
dividendsEstimateId, err := repository.nextIdentify()
if err != nil {
return nil, err
} else {
dividendsEstimate.DividendsEstimateId = dividendsEstimateId
}
}
dividendsEstimateModels = append(dividendsEstimateModels, &models.DividendsEstimate{
DividendsEstimateId: dividendsEstimate.DividendsEstimateId,
DividendsAccountStatus: dividendsEstimate.DividendsAccountStatus,
DividendsAmount: dividendsEstimate.DividendsAmount,
DividendsEstimateOrderNumber: dividendsEstimate.DividendsEstimateOrderNumber,
... ...