diff --git a/pkg/services/accounts.go b/pkg/services/accounts.go index de8c5407..2c6fd445 100644 --- a/pkg/services/accounts.go +++ b/pkg/services/accounts.go @@ -201,28 +201,25 @@ func (s *AccountService) CreateAccounts(c core.Context, mainAccount *models.Acco return errs.ErrUserIdInvalid } + needAccountUuidCount := uint16(len(childrenAccounts) + 1) + accountUuids := s.GenerateUuids(uuid.UUID_TYPE_ACCOUNT, needAccountUuidCount) + + if len(accountUuids) < int(needAccountUuidCount) { + return errs.ErrSystemIsBusy + } + now := time.Now().Unix() allAccounts := make([]*models.Account, len(childrenAccounts)+1) var allInitTransactions []*models.Transaction - mainAccount.AccountId = s.GenerateUuid(uuid.UUID_TYPE_ACCOUNT) - - if mainAccount.AccountId < 1 { - return errs.ErrSystemIsBusy - } - + mainAccount.AccountId = accountUuids[0] allAccounts[0] = mainAccount if mainAccount.Type == models.ACCOUNT_TYPE_MULTI_SUB_ACCOUNTS { for i := 0; i < len(childrenAccounts); i++ { childAccount := childrenAccounts[i] - childAccount.AccountId = s.GenerateUuid(uuid.UUID_TYPE_ACCOUNT) - - if childAccount.AccountId < 1 { - return errs.ErrSystemIsBusy - } - + childAccount.AccountId = accountUuids[i+1] childAccount.ParentAccountId = mainAccount.AccountId childAccount.Uid = mainAccount.Uid childAccount.Type = models.ACCOUNT_TYPE_SINGLE_ACCOUNT diff --git a/pkg/services/transaction_categories.go b/pkg/services/transaction_categories.go index 1aedab3a..0af6f4b3 100644 --- a/pkg/services/transaction_categories.go +++ b/pkg/services/transaction_categories.go @@ -229,14 +229,16 @@ func (s *TransactionCategoryService) CreateCategories(c core.Context, uid int64, var allCategories []*models.TransactionCategory primaryCategories := categories[nil] + needPrimaryCategoryUuidCount := uint16(len(primaryCategories)) + primaryCategoryUuids := s.GenerateUuids(uuid.UUID_TYPE_CATEGORY, needPrimaryCategoryUuidCount) + + if len(primaryCategoryUuids) < int(needPrimaryCategoryUuidCount) { + return nil, errs.ErrSystemIsBusy + } + for i := 0; i < len(primaryCategories); i++ { primaryCategory := primaryCategories[i] - primaryCategory.CategoryId = s.GenerateUuid(uuid.UUID_TYPE_CATEGORY) - - if primaryCategory.CategoryId < 1 { - return nil, errs.ErrSystemIsBusy - } - + primaryCategory.CategoryId = primaryCategoryUuids[i] primaryCategory.Deleted = false primaryCategory.CreatedUnixTime = time.Now().Unix() primaryCategory.UpdatedUnixTime = time.Now().Unix() @@ -245,16 +247,17 @@ func (s *TransactionCategoryService) CreateCategories(c core.Context, uid int64, secondaryCategories := categories[primaryCategory] + needSecondaryCategoryUuidCount := uint16(len(secondaryCategories)) + secondaryCategoryUuids := s.GenerateUuids(uuid.UUID_TYPE_CATEGORY, needSecondaryCategoryUuidCount) + + if len(secondaryCategoryUuids) < int(needSecondaryCategoryUuidCount) { + return nil, errs.ErrSystemIsBusy + } + for j := 0; j < len(secondaryCategories); j++ { secondaryCategory := secondaryCategories[j] - secondaryCategory.CategoryId = s.GenerateUuid(uuid.UUID_TYPE_CATEGORY) - - if secondaryCategory.CategoryId < 1 { - return nil, errs.ErrSystemIsBusy - } - + secondaryCategory.CategoryId = secondaryCategoryUuids[j] secondaryCategory.ParentCategoryId = primaryCategory.CategoryId - secondaryCategory.Deleted = false secondaryCategory.CreatedUnixTime = time.Now().Unix() secondaryCategory.UpdatedUnixTime = time.Now().Unix() diff --git a/pkg/services/transactions.go b/pkg/services/transactions.go index bd7ed310..6016eb44 100644 --- a/pkg/services/transactions.go +++ b/pkg/services/transactions.go @@ -525,6 +525,13 @@ func (s *TransactionService) ModifyTransaction(c core.Context, transaction *mode return errs.ErrUserIdInvalid } + needTagIndexUuidCount := uint16(len(addTagIds)) + tagIndexUuids := s.GenerateUuids(uuid.UUID_TYPE_TAG_INDEX, needTagIndexUuidCount) + + if len(tagIndexUuids) < int(needTagIndexUuidCount) { + return errs.ErrSystemIsBusy + } + updateCols := make([]string, 0, 16) now := time.Now().Unix() @@ -539,14 +546,8 @@ func (s *TransactionService) ModifyTransaction(c core.Context, transaction *mode transactionTagIndexes := make([]*models.TransactionTagIndex, len(addTagIds)) for i := 0; i < len(addTagIds); i++ { - tagIndexId := s.GenerateUuid(uuid.UUID_TYPE_TAG_INDEX) - - if tagIndexId < 1 { - return errs.ErrSystemIsBusy - } - transactionTagIndexes[i] = &models.TransactionTagIndex{ - TagIndexId: tagIndexId, + TagIndexId: tagIndexUuids[i], Uid: transaction.Uid, Deleted: false, TagId: addTagIds[i],