command transaction-check supports checking whether transaction tag index has transaction time
This commit is contained in:
+25
-14
@@ -432,7 +432,7 @@ func (l *UserDataCli) CheckTransactionAndAccount(c *cli.Context, username string
|
|||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
accountMap, categoryMap, tagMap, tagIndexs, err := l.getUserEssentialData(uid, username)
|
accountMap, categoryMap, tagMap, tagIndexs, tagIndexsMap, err := l.getUserEssentialData(uid, username)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.BootErrorf("[user_data.CheckTransactionAndAccount] failed to get essential data for user \"%s\", because %s", username, err.Error())
|
log.BootErrorf("[user_data.CheckTransactionAndAccount] failed to get essential data for user \"%s\", because %s", username, err.Error())
|
||||||
@@ -472,7 +472,7 @@ func (l *UserDataCli) CheckTransactionAndAccount(c *cli.Context, username string
|
|||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = l.checkTransactionTag(c, transaction.TransactionId, tagIndexs, tagMap)
|
err = l.checkTransactionTag(c, transaction.TransactionId, tagIndexsMap, tagMap)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
@@ -535,6 +535,15 @@ func (l *UserDataCli) CheckTransactionAndAccount(c *cli.Context, username string
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for i := 0; i < len(tagIndexs); i++ {
|
||||||
|
tagIndex := tagIndexs[i]
|
||||||
|
|
||||||
|
if tagIndex.TransactionTime < 1 {
|
||||||
|
log.BootErrorf("[user_data.CheckTransactionAndAccount] transaction tag index \"id:%d\" does not have transaction time", tagIndex.TagIndexId)
|
||||||
|
return false, errs.ErrOperationFailed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -552,7 +561,7 @@ func (l *UserDataCli) ExportTransaction(c *cli.Context, username string, fileTyp
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
accountMap, categoryMap, tagMap, tagIndexs, err := l.getUserEssentialData(uid, username)
|
accountMap, categoryMap, tagMap, _, tagIndexsMap, err := l.getUserEssentialData(uid, username)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.BootErrorf("[user_data.ExportTransaction] failed to get essential data for user \"%s\", because %s", username, err.Error())
|
log.BootErrorf("[user_data.ExportTransaction] failed to get essential data for user \"%s\", because %s", username, err.Error())
|
||||||
@@ -574,7 +583,7 @@ func (l *UserDataCli) ExportTransaction(c *cli.Context, username string, fileTyp
|
|||||||
dataExporter = l.ezBookKeepingCsvExporter
|
dataExporter = l.ezBookKeepingCsvExporter
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err := dataExporter.ToExportedContent(uid, allTransactions, accountMap, categoryMap, tagMap, tagIndexs)
|
result, err := dataExporter.ToExportedContent(uid, allTransactions, accountMap, categoryMap, tagMap, tagIndexsMap)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.BootErrorf("[user_data.ExportTransaction] failed to get csv format exported data for \"%s\", because %s", username, err.Error())
|
log.BootErrorf("[user_data.ExportTransaction] failed to get csv format exported data for \"%s\", because %s", username, err.Error())
|
||||||
@@ -595,17 +604,17 @@ func (l *UserDataCli) getUserIdByUsername(c *cli.Context, username string) (int6
|
|||||||
return user.Uid, nil
|
return user.Uid, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *UserDataCli) getUserEssentialData(uid int64, username string) (accountMap map[int64]*models.Account, categoryMap map[int64]*models.TransactionCategory, tagMap map[int64]*models.TransactionTag, tagIndexs map[int64][]int64, err error) {
|
func (l *UserDataCli) getUserEssentialData(uid int64, username string) (accountMap map[int64]*models.Account, categoryMap map[int64]*models.TransactionCategory, tagMap map[int64]*models.TransactionTag, tagIndexs []*models.TransactionTagIndex, tagIndexsMap map[int64][]int64, err error) {
|
||||||
if uid <= 0 {
|
if uid <= 0 {
|
||||||
log.BootErrorf("[user_data.getUserEssentialData] user uid \"%d\" is invalid", uid)
|
log.BootErrorf("[user_data.getUserEssentialData] user uid \"%d\" is invalid", uid)
|
||||||
return nil, nil, nil, nil, errs.ErrUserIdInvalid
|
return nil, nil, nil, nil, nil, errs.ErrUserIdInvalid
|
||||||
}
|
}
|
||||||
|
|
||||||
accounts, err := l.accounts.GetAllAccountsByUid(nil, uid)
|
accounts, err := l.accounts.GetAllAccountsByUid(nil, uid)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.BootErrorf("[user_data.getUserEssentialData] failed to get accounts for user \"%s\", because %s", username, err.Error())
|
log.BootErrorf("[user_data.getUserEssentialData] failed to get accounts for user \"%s\", because %s", username, err.Error())
|
||||||
return nil, nil, nil, nil, err
|
return nil, nil, nil, nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
accountMap = l.accounts.GetAccountMapByList(accounts)
|
accountMap = l.accounts.GetAccountMapByList(accounts)
|
||||||
@@ -614,7 +623,7 @@ func (l *UserDataCli) getUserEssentialData(uid int64, username string) (accountM
|
|||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.BootErrorf("[user_data.getUserEssentialData] failed to get categories for user \"%s\", because %s", username, err.Error())
|
log.BootErrorf("[user_data.getUserEssentialData] failed to get categories for user \"%s\", because %s", username, err.Error())
|
||||||
return nil, nil, nil, nil, err
|
return nil, nil, nil, nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
categoryMap = l.categories.GetCategoryMapByList(categories)
|
categoryMap = l.categories.GetCategoryMapByList(categories)
|
||||||
@@ -623,19 +632,21 @@ func (l *UserDataCli) getUserEssentialData(uid int64, username string) (accountM
|
|||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.BootErrorf("[user_data.getUserEssentialData] failed to get tags for user \"%s\", because %s", username, err.Error())
|
log.BootErrorf("[user_data.getUserEssentialData] failed to get tags for user \"%s\", because %s", username, err.Error())
|
||||||
return nil, nil, nil, nil, err
|
return nil, nil, nil, nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
tagMap = l.tags.GetTagMapByList(tags)
|
tagMap = l.tags.GetTagMapByList(tags)
|
||||||
|
|
||||||
tagIndexs, err = l.tags.GetAllTagIdsMapOfAllTransactions(nil, uid)
|
tagIndexs, err = l.tags.GetAllTagIdsOfAllTransactions(nil, uid)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.BootErrorf("[user_data.getUserEssentialData] failed to get tag index for user \"%s\", because %s", username, err.Error())
|
log.BootErrorf("[user_data.getUserEssentialData] failed to get tag index for user \"%s\", because %s", username, err.Error())
|
||||||
return nil, nil, nil, nil, err
|
return nil, nil, nil, nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return accountMap, categoryMap, tagMap, tagIndexs, nil
|
tagIndexsMap = l.tags.GetGroupedTransactionTagIds(tagIndexs)
|
||||||
|
|
||||||
|
return accountMap, categoryMap, tagMap, tagIndexs, tagIndexsMap, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *UserDataCli) checkTransactionAccount(c *cli.Context, transaction *models.Transaction, accountMap map[int64]*models.Account, accountHasChild map[int64]bool) error {
|
func (l *UserDataCli) checkTransactionAccount(c *cli.Context, transaction *models.Transaction, accountMap map[int64]*models.Account, accountHasChild map[int64]bool) error {
|
||||||
@@ -693,8 +704,8 @@ func (l *UserDataCli) checkTransactionCategory(c *cli.Context, transaction *mode
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *UserDataCli) checkTransactionTag(c *cli.Context, transactionId int64, allTagIndexs map[int64][]int64, tagMap map[int64]*models.TransactionTag) error {
|
func (l *UserDataCli) checkTransactionTag(c *cli.Context, transactionId int64, allTagIndexsMap map[int64][]int64, tagMap map[int64]*models.TransactionTag) error {
|
||||||
tagIndexs, exists := allTagIndexs[transactionId]
|
tagIndexs, exists := allTagIndexsMap[transactionId]
|
||||||
|
|
||||||
if !exists {
|
if !exists {
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -116,7 +116,19 @@ func (s *TransactionTagService) GetMaxDisplayOrder(c *core.Context, uid int64) (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAllTagIdsMapOfAllTransactions returns all transaction tag ids map
|
// GetAllTagIdsOfAllTransactions returns all transaction tag ids
|
||||||
|
func (s *TransactionTagService) GetAllTagIdsOfAllTransactions(c *core.Context, uid int64) ([]*models.TransactionTagIndex, error) {
|
||||||
|
if uid <= 0 {
|
||||||
|
return nil, errs.ErrUserIdInvalid
|
||||||
|
}
|
||||||
|
|
||||||
|
var tagIndexs []*models.TransactionTagIndex
|
||||||
|
err := s.UserDataDB(uid).NewSession(c).Where("uid=? AND deleted=?", uid, false).Find(&tagIndexs)
|
||||||
|
|
||||||
|
return tagIndexs, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetAllTagIdsMapOfAllTransactions returns all transaction tag ids map grouped by transaction id
|
||||||
func (s *TransactionTagService) GetAllTagIdsMapOfAllTransactions(c *core.Context, uid int64) (map[int64][]int64, error) {
|
func (s *TransactionTagService) GetAllTagIdsMapOfAllTransactions(c *core.Context, uid int64) (map[int64][]int64, error) {
|
||||||
if uid <= 0 {
|
if uid <= 0 {
|
||||||
return nil, errs.ErrUserIdInvalid
|
return nil, errs.ErrUserIdInvalid
|
||||||
@@ -125,7 +137,7 @@ func (s *TransactionTagService) GetAllTagIdsMapOfAllTransactions(c *core.Context
|
|||||||
var tagIndexs []*models.TransactionTagIndex
|
var tagIndexs []*models.TransactionTagIndex
|
||||||
err := s.UserDataDB(uid).NewSession(c).Where("uid=? AND deleted=?", uid, false).Find(&tagIndexs)
|
err := s.UserDataDB(uid).NewSession(c).Where("uid=? AND deleted=?", uid, false).Find(&tagIndexs)
|
||||||
|
|
||||||
allTransactionTagIds := s.getGroupedTransactionTagIds(tagIndexs)
|
allTransactionTagIds := s.GetGroupedTransactionTagIds(tagIndexs)
|
||||||
|
|
||||||
return allTransactionTagIds, err
|
return allTransactionTagIds, err
|
||||||
}
|
}
|
||||||
@@ -139,7 +151,7 @@ func (s *TransactionTagService) GetAllTagIdsOfTransactions(c *core.Context, uid
|
|||||||
var tagIndexs []*models.TransactionTagIndex
|
var tagIndexs []*models.TransactionTagIndex
|
||||||
err := s.UserDataDB(uid).NewSession(c).Where("uid=? AND deleted=?", uid, false).In("transaction_id", transactionIds).Find(&tagIndexs)
|
err := s.UserDataDB(uid).NewSession(c).Where("uid=? AND deleted=?", uid, false).In("transaction_id", transactionIds).Find(&tagIndexs)
|
||||||
|
|
||||||
allTransactionTagIds := s.getGroupedTransactionTagIds(tagIndexs)
|
allTransactionTagIds := s.GetGroupedTransactionTagIds(tagIndexs)
|
||||||
|
|
||||||
return allTransactionTagIds, err
|
return allTransactionTagIds, err
|
||||||
}
|
}
|
||||||
@@ -341,7 +353,7 @@ func (s *TransactionTagService) GetTagMapByList(tags []*models.TransactionTag) m
|
|||||||
return tagMap
|
return tagMap
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *TransactionTagService) getGroupedTransactionTagIds(tagIndexs []*models.TransactionTagIndex) map[int64][]int64 {
|
func (s *TransactionTagService) GetGroupedTransactionTagIds(tagIndexs []*models.TransactionTagIndex) map[int64][]int64 {
|
||||||
allTransactionTagIds := make(map[int64][]int64)
|
allTransactionTagIds := make(map[int64][]int64)
|
||||||
|
|
||||||
for i := 0; i < len(tagIndexs); i++ {
|
for i := 0; i < len(tagIndexs); i++ {
|
||||||
|
|||||||
Reference in New Issue
Block a user