作者 陈志颖

feat:增加分红预算单号生成方法

... ... @@ -444,7 +444,7 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
} else {
dividendsEstimate = &domain.DividendsEstimate{
DividendsEstimateId: 0,
DividendsAccountStatus: 0,
DividendsAccountStatus: 1,
DividendsAmount: dividendsAmount,
DividendsEstimateOrderNumber: "",
DividendsEstimateTime: time.Time{},
... ... @@ -491,9 +491,9 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
Org: nil,
Company: nil,
Operator: nil,
OperateTime: time.Time{},
OperateTime: time.Now(),
IsCanceled: false,
CreatedAt: time.Time{},
CreatedAt: time.Now(),
DeletedAt: time.Time{},
UpdatedAt: time.Time{},
}
... ... @@ -509,7 +509,6 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
dividendsEstimatesSaved = append(dividendsEstimatesSaved, dividendsEstimateSaved)
}
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
... ...
package dao
import (
"fmt"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils"
"time"
)
type DividendsEstimateDao struct {
transactionContext *pgTransaction.TransactionContext
}
// GenerateDividendsEstimateNumber 生成分红预算单号
func (dao *DividendsEstimateDao) GenerateDividendsEstimateNumber() (string, error) {
tx := dao.transactionContext.PgTx
var dividendsEstimateModels []*models.DividendsEstimate
query := tx.Model(&dividendsEstimateModels)
currentTime := time.Now()
todayZeroTime := utils.GetZeroTime(currentTime)
nextDayZeroTime := utils.GetNextDayZeroTime(currentTime)
query.Where("dividends_estimate.created_at >= ?", todayZeroTime)
query.Where("dividends_estimate.created_at < ?", nextDayZeroTime)
if count, err := query.AllWithDeleted().SelectAndCount(); err != nil {
return "", err
} else {
countStr := fmt.Sprintf("%03d", count+1)
timestamp := currentTime.Unix()
timeNow := time.Unix(timestamp, 0)
timeString := timeNow.Format("20060102")
timeString = timeString[2:len(timeString)]
dividendsOrderNumber := "FH" + timeString + "#" + countStr
return dividendsOrderNumber, nil
}
}
// CheckDividendsEstimateOrderNumberAvailable 校验分红预算单号是否唯一
func (dao *DividendsEstimateDao) CheckDividendsEstimateOrderNumberAvailable(queryOptions map[string]interface{}) (bool, error) {
tx := dao.transactionContext.PgTx
var dividendsEstimateModels []*models.DividendsEstimate
query := tx.Model(&dividendsEstimateModels)
if dividendsEstimateOrderNumber, ok := queryOptions["dividendsEstimateOrderNumber"]; ok && dividendsEstimateOrderNumber != "" {
query = query.Where("dividends_estimate_order_number = ?", dividendsEstimateOrderNumber)
}
if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
query = query.Where(`dividends_estimate.company @> '{"companyId":"?"}'`, companyId)
}
if orgId, ok := queryOptions["orgId"]; ok && orgId.(int64) != 0 {
query = query.Where(`dividends_estimate.org @> '{"orgId":"?"}'`, orgId)
}
ok, err := query.Exists()
return !ok, err
}
func NewDividendsEstimateDao(transactionContext *pgTransaction.TransactionContext) (*DividendsEstimateDao, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为空")
} else {
return &DividendsEstimateDao{
transactionContext: transactionContext,
}, nil
}
}
... ...
... ... @@ -60,7 +60,7 @@ func (dao *DividendsOrderDao) CalculateDividendsOrderAmount(queryOptions map[str
func NewDividendsOrderDao(transactionContext *pgTransaction.TransactionContext) (*DividendsOrderDao, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能")
return nil, fmt.Errorf("transactionContext参数不能为空")
} else {
return &DividendsOrderDao{
transactionContext: transactionContext,
... ...