mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-17 00:12:11 +08:00
show process when importing a lot of transactions
This commit is contained in:
@@ -2,6 +2,7 @@ package services
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -260,8 +261,11 @@ func (s *TransactionService) CreateTransaction(c core.Context, transaction *mode
|
||||
}
|
||||
|
||||
// BatchCreateTransactions saves new transactions to database
|
||||
func (s *TransactionService) BatchCreateTransactions(c core.Context, uid int64, transactions []*models.Transaction, allTagIds map[int][]int64) error {
|
||||
func (s *TransactionService) BatchCreateTransactions(c core.Context, uid int64, transactions []*models.Transaction, allTagIds map[int][]int64, processHandler core.TaskProcessUpdateHandler) error {
|
||||
now := time.Now().Unix()
|
||||
currentProcess := float64(0)
|
||||
processUpdateStep := int(math.Max(100.0, float64(len(transactions)/100.0)))
|
||||
|
||||
needTransactionUuidCount := uint16(0)
|
||||
needTagIndexUuidCount := uint16(0)
|
||||
|
||||
@@ -366,6 +370,12 @@ func (s *TransactionService) BatchCreateTransactions(c core.Context, uid int64,
|
||||
transactionTagIds := allTransactionTagIds[transaction.TransactionId]
|
||||
err := s.doCreateTransaction(c, userDataDb, sess, transaction, transactionTagIndexes, transactionTagIds, nil, nil)
|
||||
|
||||
currentProcess = float64(i) / float64(len(transactions)) * 100
|
||||
|
||||
if processHandler != nil && i%processUpdateStep == 0 {
|
||||
processHandler(currentProcess)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
transactionUnixTime := utils.GetUnixTimeFromTransactionTime(transaction.TransactionTime)
|
||||
transactionTimeZone := time.FixedZone("Transaction Timezone", int(transaction.TimezoneUtcOffset)*60)
|
||||
|
||||
Reference in New Issue
Block a user