This commit is contained in:
MaysWind
2024-09-10 00:23:31 +08:00
parent 698c0a62a2
commit 70beb45c4e
4 changed files with 40 additions and 3 deletions
+7 -3
View File
@@ -1,6 +1,7 @@
package cli
import (
"strings"
"time"
"github.com/mayswind/ezbookkeeping/pkg/converters"
@@ -706,17 +707,20 @@ func (l *UserDataCli) ImportTransaction(c *core.CliContext, username string, fil
}
if len(newAccounts) > 0 {
log.BootErrorf(c, "[user_data.ImportTransaction] there are %d accounts need to be created, please create them manually", len(newAccounts))
accountNames := l.accounts.GetAccountNames(newAccounts)
log.BootErrorf(c, "[user_data.ImportTransaction] there are %d accounts (%s) need to be created, please create them manually", len(newAccounts), strings.Join(accountNames, ","))
return errs.ErrOperationFailed
}
if len(newCategories) > 0 {
log.BootErrorf(c, "[user_data.ImportTransaction] there are %d transaction categories need to be created, please create them manually", len(newCategories))
categoryNames := l.categories.GetCategoryNames(newCategories)
log.BootErrorf(c, "[user_data.ImportTransaction] there are %d transaction categories (%s) need to be created, please create them manually", len(newCategories), strings.Join(categoryNames, ","))
return errs.ErrOperationFailed
}
if len(newTags) > 0 {
log.BootErrorf(c, "[user_data.ImportTransaction] there are %d transaction tags need to be created, please create them manually", len(newTags))
tagNames := l.tags.GetTagNames(newTags)
log.BootErrorf(c, "[user_data.ImportTransaction] there are %d transaction tags (%s) need to be created, please create them manually", len(newTags), strings.Join(tagNames, ","))
return errs.ErrOperationFailed
}
+11
View File
@@ -474,3 +474,14 @@ func (s *AccountService) GetAccountNameMapByList(accounts []*models.Account) map
}
return accountMap
}
// GetAccountNames returns a list with account names from account models list
func (s *AccountService) GetAccountNames(accounts []*models.Account) []string {
accountNames := make([]string, len(accounts))
for i := 0; i < len(accounts); i++ {
accountNames[i] = accounts[i].Name
}
return accountNames
}
+11
View File
@@ -458,3 +458,14 @@ func (s *TransactionCategoryService) GetCategoryNameMapByList(categories []*mode
}
return categoryMap
}
// GetCategoryNames returns a list with transaction category names from transaction category models list
func (s *TransactionCategoryService) GetCategoryNames(categories []*models.TransactionCategory) []string {
categoryNames := make([]string, len(categories))
for i := 0; i < len(categories); i++ {
categoryNames[i] = categories[i].Name
}
return categoryNames
}
+11
View File
@@ -426,6 +426,17 @@ func (s *TransactionTagService) GetTagNameMapByList(tags []*models.TransactionTa
return tagMap
}
// GetTagNames returns a list with tag names from tag models list
func (s *TransactionTagService) GetTagNames(tags []*models.TransactionTag) []string {
tagNames := make([]string, len(tags))
for i := 0; i < len(tags); i++ {
tagNames[i] = tags[i].Name
}
return tagNames
}
func (s *TransactionTagService) GetGroupedTransactionTagIds(tagIndexes []*models.TransactionTagIndex) map[int64][]int64 {
allTransactionTagIds := make(map[int64][]int64)