modify variable name
This commit is contained in:
@@ -190,7 +190,7 @@ func (a *DataManagementsApi) getExportedFileContent(c *core.Context, fileType st
|
|||||||
return nil, "", errs.ErrOperationFailed
|
return nil, "", errs.ErrOperationFailed
|
||||||
}
|
}
|
||||||
|
|
||||||
tagIndexs, err := a.tags.GetAllTagIdsMapOfAllTransactions(c, uid)
|
tagIndexes, err := a.tags.GetAllTagIdsMapOfAllTransactions(c, uid)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.ErrorfWithRequestId(c, "[data_managements.ExportDataHandler] failed to get tag index for user \"uid:%d\", because %s", uid, err.Error())
|
log.ErrorfWithRequestId(c, "[data_managements.ExportDataHandler] failed to get tag index for user \"uid:%d\", because %s", uid, err.Error())
|
||||||
@@ -216,7 +216,7 @@ func (a *DataManagementsApi) getExportedFileContent(c *core.Context, fileType st
|
|||||||
dataExporter = a.ezBookKeepingCsvExporter
|
dataExporter = a.ezBookKeepingCsvExporter
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err := dataExporter.ToExportedContent(uid, allTransactions, accountMap, categoryMap, tagMap, tagIndexs)
|
result, err := dataExporter.ToExportedContent(uid, allTransactions, accountMap, categoryMap, tagMap, tagIndexes)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.ErrorfWithRequestId(c, "[data_managements.ExportDataHandler] failed to get csv format exported data for \"uid:%d\", because %s", uid, err.Error())
|
log.ErrorfWithRequestId(c, "[data_managements.ExportDataHandler] failed to get csv format exported data for \"uid:%d\", because %s", uid, err.Error())
|
||||||
|
|||||||
+23
-23
@@ -432,7 +432,7 @@ func (l *UserDataCli) CheckTransactionAndAccount(c *cli.Context, username string
|
|||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
accountMap, categoryMap, tagMap, tagIndexs, tagIndexsMap, err := l.getUserEssentialData(uid, username)
|
accountMap, categoryMap, tagMap, tagIndexes, tagIndexesMap, 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, tagIndexsMap, tagMap)
|
err = l.checkTransactionTag(c, transaction.TransactionId, tagIndexesMap, tagMap)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
@@ -535,8 +535,8 @@ func (l *UserDataCli) CheckTransactionAndAccount(c *cli.Context, username string
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < len(tagIndexs); i++ {
|
for i := 0; i < len(tagIndexes); i++ {
|
||||||
tagIndex := tagIndexs[i]
|
tagIndex := tagIndexes[i]
|
||||||
|
|
||||||
if tagIndex.TransactionTime < 1 {
|
if tagIndex.TransactionTime < 1 {
|
||||||
log.BootErrorf("[user_data.CheckTransactionAndAccount] transaction tag index \"id:%d\" does not have transaction time", tagIndex.TagIndexId)
|
log.BootErrorf("[user_data.CheckTransactionAndAccount] transaction tag index \"id:%d\" does not have transaction time", tagIndex.TagIndexId)
|
||||||
@@ -561,24 +561,24 @@ func (l *UserDataCli) FixTransactionTagIndexWithTransactionTime(c *cli.Context,
|
|||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
tagIndexs, err := l.tags.GetAllTagIdsOfAllTransactions(nil, uid)
|
tagIndexes, err := l.tags.GetAllTagIdsOfAllTransactions(nil, uid)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.BootErrorf("[user_data.FixTransactionTagIndexWithTransactionTime] failed to get tag index for user \"%s\", because %s", username, err.Error())
|
log.BootErrorf("[user_data.FixTransactionTagIndexWithTransactionTime] failed to get tag index for user \"%s\", because %s", username, err.Error())
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
invalidTagIndexs := make([]*models.TransactionTagIndex, 0, len(tagIndexs))
|
invalidTagIndexes := make([]*models.TransactionTagIndex, 0, len(tagIndexes))
|
||||||
|
|
||||||
for i := 0; i < len(tagIndexs); i++ {
|
for i := 0; i < len(tagIndexes); i++ {
|
||||||
tagIndex := tagIndexs[i]
|
tagIndex := tagIndexes[i]
|
||||||
|
|
||||||
if tagIndex.TransactionTime < 1 {
|
if tagIndex.TransactionTime < 1 {
|
||||||
invalidTagIndexs = append(invalidTagIndexs, tagIndex)
|
invalidTagIndexes = append(invalidTagIndexes, tagIndex)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(invalidTagIndexs) < 1 {
|
if len(invalidTagIndexes) < 1 {
|
||||||
log.BootErrorf("[user_data.FixTransactionTagIndexWithTransactionTime] all user transaction tag index data has been checked, there is no problem with user data")
|
log.BootErrorf("[user_data.FixTransactionTagIndexWithTransactionTime] all user transaction tag index data has been checked, there is no problem with user data")
|
||||||
return false, errs.ErrOperationFailed
|
return false, errs.ErrOperationFailed
|
||||||
}
|
}
|
||||||
@@ -592,8 +592,8 @@ func (l *UserDataCli) FixTransactionTagIndexWithTransactionTime(c *cli.Context,
|
|||||||
|
|
||||||
transactionMap := l.transactions.GetTransactionMapByList(allTransactions)
|
transactionMap := l.transactions.GetTransactionMapByList(allTransactions)
|
||||||
|
|
||||||
for i := 0; i < len(invalidTagIndexs); i++ {
|
for i := 0; i < len(invalidTagIndexes); i++ {
|
||||||
tagIndex := invalidTagIndexs[i]
|
tagIndex := invalidTagIndexes[i]
|
||||||
transaction, exists := transactionMap[tagIndex.TransactionId]
|
transaction, exists := transactionMap[tagIndex.TransactionId]
|
||||||
|
|
||||||
if !exists {
|
if !exists {
|
||||||
@@ -603,7 +603,7 @@ func (l *UserDataCli) FixTransactionTagIndexWithTransactionTime(c *cli.Context,
|
|||||||
tagIndex.TransactionTime = transaction.TransactionTime
|
tagIndex.TransactionTime = transaction.TransactionTime
|
||||||
}
|
}
|
||||||
|
|
||||||
err = l.tags.ModifyTagIndexTransactionTime(nil, uid, invalidTagIndexs)
|
err = l.tags.ModifyTagIndexTransactionTime(nil, uid, invalidTagIndexes)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.BootErrorf("[user_data.FixTransactionTagIndexWithTransactionTime] failed to update transaction tag index for user \"%s\", because %s", username, err.Error())
|
log.BootErrorf("[user_data.FixTransactionTagIndexWithTransactionTime] failed to update transaction tag index for user \"%s\", because %s", username, err.Error())
|
||||||
@@ -627,7 +627,7 @@ func (l *UserDataCli) ExportTransaction(c *cli.Context, username string, fileTyp
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
accountMap, categoryMap, tagMap, _, tagIndexsMap, err := l.getUserEssentialData(uid, username)
|
accountMap, categoryMap, tagMap, _, tagIndexesMap, 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())
|
||||||
@@ -649,7 +649,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, tagIndexsMap)
|
result, err := dataExporter.ToExportedContent(uid, allTransactions, accountMap, categoryMap, tagMap, tagIndexesMap)
|
||||||
|
|
||||||
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())
|
||||||
@@ -670,7 +670,7 @@ 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 []*models.TransactionTagIndex, tagIndexsMap 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, tagIndexes []*models.TransactionTagIndex, tagIndexesMap 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, nil, errs.ErrUserIdInvalid
|
return nil, nil, nil, nil, nil, errs.ErrUserIdInvalid
|
||||||
@@ -703,16 +703,16 @@ func (l *UserDataCli) getUserEssentialData(uid int64, username string) (accountM
|
|||||||
|
|
||||||
tagMap = l.tags.GetTagMapByList(tags)
|
tagMap = l.tags.GetTagMapByList(tags)
|
||||||
|
|
||||||
tagIndexs, err = l.tags.GetAllTagIdsOfAllTransactions(nil, uid)
|
tagIndexes, 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, nil, err
|
return nil, nil, nil, nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
tagIndexsMap = l.tags.GetGroupedTransactionTagIds(tagIndexs)
|
tagIndexesMap = l.tags.GetGroupedTransactionTagIds(tagIndexes)
|
||||||
|
|
||||||
return accountMap, categoryMap, tagMap, tagIndexs, tagIndexsMap, nil
|
return accountMap, categoryMap, tagMap, tagIndexes, tagIndexesMap, 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 {
|
||||||
@@ -770,15 +770,15 @@ func (l *UserDataCli) checkTransactionCategory(c *cli.Context, transaction *mode
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *UserDataCli) checkTransactionTag(c *cli.Context, transactionId int64, allTagIndexsMap map[int64][]int64, tagMap map[int64]*models.TransactionTag) error {
|
func (l *UserDataCli) checkTransactionTag(c *cli.Context, transactionId int64, allTagIndexesMap map[int64][]int64, tagMap map[int64]*models.TransactionTag) error {
|
||||||
tagIndexs, exists := allTagIndexsMap[transactionId]
|
tagIndexes, exists := allTagIndexesMap[transactionId]
|
||||||
|
|
||||||
if !exists {
|
if !exists {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < len(tagIndexs); i++ {
|
for i := 0; i < len(tagIndexes); i++ {
|
||||||
tagIndex := tagIndexs[i]
|
tagIndex := tagIndexes[i]
|
||||||
tag, exists := tagMap[tagIndex]
|
tag, exists := tagMap[tagIndex]
|
||||||
|
|
||||||
if !exists {
|
if !exists {
|
||||||
|
|||||||
@@ -7,5 +7,5 @@ import (
|
|||||||
// DataConverter defines the structure of data exporter
|
// DataConverter defines the structure of data exporter
|
||||||
type DataConverter interface {
|
type DataConverter interface {
|
||||||
// ToExportedContent returns the exported data
|
// ToExportedContent returns the exported data
|
||||||
ToExportedContent(uid int64, transactions []*models.Transaction, accountMap map[int64]*models.Account, categoryMap map[int64]*models.TransactionCategory, tagMap map[int64]*models.TransactionTag, allTagIndexs map[int64][]int64) ([]byte, error)
|
ToExportedContent(uid int64, transactions []*models.Transaction, accountMap map[int64]*models.Account, categoryMap map[int64]*models.TransactionCategory, tagMap map[int64]*models.TransactionTag, allTagIndexes map[int64][]int64) ([]byte, error)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,6 @@ type EzBookKeepingCSVFileExporter struct {
|
|||||||
const csvSeparator = ","
|
const csvSeparator = ","
|
||||||
|
|
||||||
// ToExportedContent returns the exported CSV data
|
// ToExportedContent returns the exported CSV data
|
||||||
func (e *EzBookKeepingCSVFileExporter) ToExportedContent(uid int64, transactions []*models.Transaction, accountMap map[int64]*models.Account, categoryMap map[int64]*models.TransactionCategory, tagMap map[int64]*models.TransactionTag, allTagIndexs map[int64][]int64) ([]byte, error) {
|
func (e *EzBookKeepingCSVFileExporter) ToExportedContent(uid int64, transactions []*models.Transaction, accountMap map[int64]*models.Account, categoryMap map[int64]*models.TransactionCategory, tagMap map[int64]*models.TransactionTag, allTagIndexes map[int64][]int64) ([]byte, error) {
|
||||||
return e.toExportedContent(uid, csvSeparator, transactions, accountMap, categoryMap, tagMap, allTagIndexs)
|
return e.toExportedContent(uid, csvSeparator, transactions, accountMap, categoryMap, tagMap, allTagIndexes)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ const headerLine = "Time,Timezone,Type,Category,Sub Category,Account,Account Cur
|
|||||||
const dataLineFormat = "%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s" + lineSeparator
|
const dataLineFormat = "%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s" + lineSeparator
|
||||||
|
|
||||||
// toExportedContent returns the exported plain data
|
// toExportedContent returns the exported plain data
|
||||||
func (e *EzBookKeepingPlainFileExporter) toExportedContent(uid int64, separator string, transactions []*models.Transaction, accountMap map[int64]*models.Account, categoryMap map[int64]*models.TransactionCategory, tagMap map[int64]*models.TransactionTag, allTagIndexs map[int64][]int64) ([]byte, error) {
|
func (e *EzBookKeepingPlainFileExporter) toExportedContent(uid int64, separator string, transactions []*models.Transaction, accountMap map[int64]*models.Account, categoryMap map[int64]*models.TransactionCategory, tagMap map[int64]*models.TransactionTag, allTagIndexes map[int64][]int64) ([]byte, error) {
|
||||||
var ret strings.Builder
|
var ret strings.Builder
|
||||||
|
|
||||||
ret.Grow(len(transactions) * 100)
|
ret.Grow(len(transactions) * 100)
|
||||||
@@ -66,7 +66,7 @@ func (e *EzBookKeepingPlainFileExporter) toExportedContent(uid int64, separator
|
|||||||
geoLocation = fmt.Sprintf("%f%s%f", transaction.GeoLongitude, geoLocationSeparator, transaction.GeoLatitude)
|
geoLocation = fmt.Sprintf("%f%s%f", transaction.GeoLongitude, geoLocationSeparator, transaction.GeoLatitude)
|
||||||
}
|
}
|
||||||
|
|
||||||
tags := e.replaceDelimiters(e.getTags(transaction.TransactionId, allTagIndexs, tagMap), separator)
|
tags := e.replaceDelimiters(e.getTags(transaction.TransactionId, allTagIndexes, tagMap), separator)
|
||||||
comment := e.replaceDelimiters(transaction.Comment, separator)
|
comment := e.replaceDelimiters(transaction.Comment, separator)
|
||||||
|
|
||||||
ret.WriteString(fmt.Sprintf(actualDataLineFormat, transactionTime, transactionTimezone, transactionType, category, subCategory, account, accountCurrency, amount, account2, account2Currency, account2Amount, geoLocation, tags, comment))
|
ret.WriteString(fmt.Sprintf(actualDataLineFormat, transactionTime, transactionTimezone, transactionType, category, subCategory, account, accountCurrency, amount, account2, account2Currency, account2Amount, geoLocation, tags, comment))
|
||||||
@@ -159,8 +159,8 @@ func (e *EzBookKeepingPlainFileExporter) getDisplayAmount(amount int64) string {
|
|||||||
return integer + "." + decimals
|
return integer + "." + decimals
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *EzBookKeepingPlainFileExporter) getTags(transactionId int64, allTagIndexs map[int64][]int64, tagMap map[int64]*models.TransactionTag) string {
|
func (e *EzBookKeepingPlainFileExporter) getTags(transactionId int64, allTagIndexes map[int64][]int64, tagMap map[int64]*models.TransactionTag) string {
|
||||||
tagIndexs, exists := allTagIndexs[transactionId]
|
tagIndexes, exists := allTagIndexes[transactionId]
|
||||||
|
|
||||||
if !exists {
|
if !exists {
|
||||||
return ""
|
return ""
|
||||||
@@ -168,12 +168,12 @@ func (e *EzBookKeepingPlainFileExporter) getTags(transactionId int64, allTagInde
|
|||||||
|
|
||||||
var ret strings.Builder
|
var ret strings.Builder
|
||||||
|
|
||||||
for i := 0; i < len(tagIndexs); i++ {
|
for i := 0; i < len(tagIndexes); i++ {
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
ret.WriteString(transactionTagSeparator)
|
ret.WriteString(transactionTagSeparator)
|
||||||
}
|
}
|
||||||
|
|
||||||
tagIndex := tagIndexs[i]
|
tagIndex := tagIndexes[i]
|
||||||
tag, exists := tagMap[tagIndex]
|
tag, exists := tagMap[tagIndex]
|
||||||
|
|
||||||
if !exists {
|
if !exists {
|
||||||
|
|||||||
@@ -12,6 +12,6 @@ type EzBookKeepingTSVFileExporter struct {
|
|||||||
const tsvSeparator = "\t"
|
const tsvSeparator = "\t"
|
||||||
|
|
||||||
// ToExportedContent returns the exported TSV data
|
// ToExportedContent returns the exported TSV data
|
||||||
func (e *EzBookKeepingTSVFileExporter) ToExportedContent(uid int64, transactions []*models.Transaction, accountMap map[int64]*models.Account, categoryMap map[int64]*models.TransactionCategory, tagMap map[int64]*models.TransactionTag, allTagIndexs map[int64][]int64) ([]byte, error) {
|
func (e *EzBookKeepingTSVFileExporter) ToExportedContent(uid int64, transactions []*models.Transaction, accountMap map[int64]*models.Account, categoryMap map[int64]*models.TransactionCategory, tagMap map[int64]*models.TransactionTag, allTagIndexes map[int64][]int64) ([]byte, error) {
|
||||||
return e.toExportedContent(uid, tsvSeparator, transactions, accountMap, categoryMap, tagMap, allTagIndexs)
|
return e.toExportedContent(uid, tsvSeparator, transactions, accountMap, categoryMap, tagMap, allTagIndexes)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -122,10 +122,10 @@ func (s *TransactionTagService) GetAllTagIdsOfAllTransactions(c *core.Context, u
|
|||||||
return nil, errs.ErrUserIdInvalid
|
return nil, errs.ErrUserIdInvalid
|
||||||
}
|
}
|
||||||
|
|
||||||
var tagIndexs []*models.TransactionTagIndex
|
var tagIndexes []*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(&tagIndexes)
|
||||||
|
|
||||||
return tagIndexs, err
|
return tagIndexes, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAllTagIdsMapOfAllTransactions returns all transaction tag ids map grouped by transaction id
|
// GetAllTagIdsMapOfAllTransactions returns all transaction tag ids map grouped by transaction id
|
||||||
@@ -134,10 +134,10 @@ func (s *TransactionTagService) GetAllTagIdsMapOfAllTransactions(c *core.Context
|
|||||||
return nil, errs.ErrUserIdInvalid
|
return nil, errs.ErrUserIdInvalid
|
||||||
}
|
}
|
||||||
|
|
||||||
var tagIndexs []*models.TransactionTagIndex
|
var tagIndexes []*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(&tagIndexes)
|
||||||
|
|
||||||
allTransactionTagIds := s.GetGroupedTransactionTagIds(tagIndexs)
|
allTransactionTagIds := s.GetGroupedTransactionTagIds(tagIndexes)
|
||||||
|
|
||||||
return allTransactionTagIds, err
|
return allTransactionTagIds, err
|
||||||
}
|
}
|
||||||
@@ -148,10 +148,10 @@ func (s *TransactionTagService) GetAllTagIdsOfTransactions(c *core.Context, uid
|
|||||||
return nil, errs.ErrUserIdInvalid
|
return nil, errs.ErrUserIdInvalid
|
||||||
}
|
}
|
||||||
|
|
||||||
var tagIndexs []*models.TransactionTagIndex
|
var tagIndexes []*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(&tagIndexes)
|
||||||
|
|
||||||
allTransactionTagIds := s.GetGroupedTransactionTagIds(tagIndexs)
|
allTransactionTagIds := s.GetGroupedTransactionTagIds(tagIndexes)
|
||||||
|
|
||||||
return allTransactionTagIds, err
|
return allTransactionTagIds, err
|
||||||
}
|
}
|
||||||
@@ -343,18 +343,18 @@ func (s *TransactionTagService) ExistsTagName(c *core.Context, uid int64, name s
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ModifyTagIndexTransactionTime updates transaction time of given transaction tag indexes
|
// ModifyTagIndexTransactionTime updates transaction time of given transaction tag indexes
|
||||||
func (s *TransactionTagService) ModifyTagIndexTransactionTime(c *core.Context, uid int64, tagIndexs []*models.TransactionTagIndex) error {
|
func (s *TransactionTagService) ModifyTagIndexTransactionTime(c *core.Context, uid int64, tagIndexes []*models.TransactionTagIndex) error {
|
||||||
if uid <= 0 {
|
if uid <= 0 {
|
||||||
return errs.ErrUserIdInvalid
|
return errs.ErrUserIdInvalid
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < len(tagIndexs); i++ {
|
for i := 0; i < len(tagIndexes); i++ {
|
||||||
tagIndexs[i].UpdatedUnixTime = time.Now().Unix()
|
tagIndexes[i].UpdatedUnixTime = time.Now().Unix()
|
||||||
}
|
}
|
||||||
|
|
||||||
return s.UserDataDB(uid).DoTransaction(c, func(sess *xorm.Session) error {
|
return s.UserDataDB(uid).DoTransaction(c, func(sess *xorm.Session) error {
|
||||||
for i := 0; i < len(tagIndexs); i++ {
|
for i := 0; i < len(tagIndexes); i++ {
|
||||||
tagIndex := tagIndexs[i]
|
tagIndex := tagIndexes[i]
|
||||||
updatedRows, err := sess.ID(tagIndex.TagIndexId).Cols("transaction_time", "updated_unix_time").Where("uid=? AND deleted=?", uid, false).Update(tagIndex)
|
updatedRows, err := sess.ID(tagIndex.TagIndexId).Cols("transaction_time", "updated_unix_time").Where("uid=? AND deleted=?", uid, false).Update(tagIndex)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -379,11 +379,11 @@ 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(tagIndexes []*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(tagIndexes); i++ {
|
||||||
tagIndex := tagIndexs[i]
|
tagIndex := tagIndexes[i]
|
||||||
|
|
||||||
var transactionTagIds []int64
|
var transactionTagIds []int64
|
||||||
|
|
||||||
|
|||||||
@@ -235,7 +235,7 @@ func (s *TransactionService) CreateTransaction(c *core.Context, transaction *mod
|
|||||||
transaction.UpdatedUnixTime = now
|
transaction.UpdatedUnixTime = now
|
||||||
|
|
||||||
tagIds = utils.ToUniqueInt64Slice(tagIds)
|
tagIds = utils.ToUniqueInt64Slice(tagIds)
|
||||||
transactionTagIndexs := make([]*models.TransactionTagIndex, len(tagIds))
|
transactionTagIndexes := make([]*models.TransactionTagIndex, len(tagIds))
|
||||||
|
|
||||||
for i := 0; i < len(tagIds); i++ {
|
for i := 0; i < len(tagIds); i++ {
|
||||||
tagIndexId := s.GenerateUuid(uuid.UUID_TYPE_TAG_INDEX)
|
tagIndexId := s.GenerateUuid(uuid.UUID_TYPE_TAG_INDEX)
|
||||||
@@ -244,7 +244,7 @@ func (s *TransactionService) CreateTransaction(c *core.Context, transaction *mod
|
|||||||
return errs.ErrSystemIsBusy
|
return errs.ErrSystemIsBusy
|
||||||
}
|
}
|
||||||
|
|
||||||
transactionTagIndexs[i] = &models.TransactionTagIndex{
|
transactionTagIndexes[i] = &models.TransactionTagIndex{
|
||||||
TagIndexId: tagIndexId,
|
TagIndexId: tagIndexId,
|
||||||
Uid: transaction.Uid,
|
Uid: transaction.Uid,
|
||||||
Deleted: false,
|
Deleted: false,
|
||||||
@@ -280,7 +280,7 @@ func (s *TransactionService) CreateTransaction(c *core.Context, transaction *mod
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get and verify tags
|
// Get and verify tags
|
||||||
err = s.isTagsValid(sess, transaction, transactionTagIndexs, tagIds)
|
err = s.isTagsValid(sess, transaction, transactionTagIndexes, tagIds)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -353,9 +353,9 @@ func (s *TransactionService) CreateTransaction(c *core.Context, transaction *mod
|
|||||||
err = nil
|
err = nil
|
||||||
|
|
||||||
// Insert transaction tag index
|
// Insert transaction tag index
|
||||||
if len(transactionTagIndexs) > 0 {
|
if len(transactionTagIndexes) > 0 {
|
||||||
for i := 0; i < len(transactionTagIndexs); i++ {
|
for i := 0; i < len(transactionTagIndexes); i++ {
|
||||||
transactionTagIndex := transactionTagIndexs[i]
|
transactionTagIndex := transactionTagIndexes[i]
|
||||||
transactionTagIndex.TransactionTime = transaction.TransactionTime
|
transactionTagIndex.TransactionTime = transaction.TransactionTime
|
||||||
|
|
||||||
_, err := sess.Insert(transactionTagIndex)
|
_, err := sess.Insert(transactionTagIndex)
|
||||||
@@ -437,7 +437,7 @@ func (s *TransactionService) ModifyTransaction(c *core.Context, transaction *mod
|
|||||||
addTagIds = utils.ToUniqueInt64Slice(addTagIds)
|
addTagIds = utils.ToUniqueInt64Slice(addTagIds)
|
||||||
removeTagIds = utils.ToUniqueInt64Slice(removeTagIds)
|
removeTagIds = utils.ToUniqueInt64Slice(removeTagIds)
|
||||||
|
|
||||||
transactionTagIndexs := make([]*models.TransactionTagIndex, len(addTagIds))
|
transactionTagIndexes := make([]*models.TransactionTagIndex, len(addTagIds))
|
||||||
|
|
||||||
for i := 0; i < len(addTagIds); i++ {
|
for i := 0; i < len(addTagIds); i++ {
|
||||||
tagIndexId := s.GenerateUuid(uuid.UUID_TYPE_TAG_INDEX)
|
tagIndexId := s.GenerateUuid(uuid.UUID_TYPE_TAG_INDEX)
|
||||||
@@ -446,7 +446,7 @@ func (s *TransactionService) ModifyTransaction(c *core.Context, transaction *mod
|
|||||||
return errs.ErrSystemIsBusy
|
return errs.ErrSystemIsBusy
|
||||||
}
|
}
|
||||||
|
|
||||||
transactionTagIndexs[i] = &models.TransactionTagIndex{
|
transactionTagIndexes[i] = &models.TransactionTagIndex{
|
||||||
TagIndexId: tagIndexId,
|
TagIndexId: tagIndexId,
|
||||||
Uid: transaction.Uid,
|
Uid: transaction.Uid,
|
||||||
Deleted: false,
|
Deleted: false,
|
||||||
@@ -587,7 +587,7 @@ func (s *TransactionService) ModifyTransaction(c *core.Context, transaction *mod
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get and verify tags
|
// Get and verify tags
|
||||||
err = s.isTagsValid(sess, transaction, transactionTagIndexs, addTagIds)
|
err = s.isTagsValid(sess, transaction, transactionTagIndexes, addTagIds)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -635,9 +635,9 @@ func (s *TransactionService) ModifyTransaction(c *core.Context, transaction *mod
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(transactionTagIndexs) > 0 {
|
if len(transactionTagIndexes) > 0 {
|
||||||
for i := 0; i < len(transactionTagIndexs); i++ {
|
for i := 0; i < len(transactionTagIndexes); i++ {
|
||||||
transactionTagIndex := transactionTagIndexs[i]
|
transactionTagIndex := transactionTagIndexes[i]
|
||||||
transactionTagIndex.TransactionTime = transaction.TransactionTime
|
transactionTagIndex.TransactionTime = transaction.TransactionTime
|
||||||
|
|
||||||
_, err := sess.Insert(transactionTagIndex)
|
_, err := sess.Insert(transactionTagIndex)
|
||||||
@@ -646,7 +646,7 @@ func (s *TransactionService) ModifyTransaction(c *core.Context, transaction *mod
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if len(transactionTagIndexs) == 0 && currentTagIdsCount > 0 && modifyTransactionTime {
|
} else if len(transactionTagIndexes) == 0 && currentTagIdsCount > 0 && modifyTransactionTime {
|
||||||
tagIndexUpdateModel := &models.TransactionTagIndex{
|
tagIndexUpdateModel := &models.TransactionTagIndex{
|
||||||
TransactionTime: transaction.TransactionTime,
|
TransactionTime: transaction.TransactionTime,
|
||||||
}
|
}
|
||||||
@@ -1649,8 +1649,8 @@ func (s *TransactionService) isCategoryValid(sess *xorm.Session, transaction *mo
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *TransactionService) isTagsValid(sess *xorm.Session, transaction *models.Transaction, transactionTagIndexs []*models.TransactionTagIndex, tagIds []int64) error {
|
func (s *TransactionService) isTagsValid(sess *xorm.Session, transaction *models.Transaction, transactionTagIndexes []*models.TransactionTagIndex, tagIds []int64) error {
|
||||||
if len(transactionTagIndexs) > 0 {
|
if len(transactionTagIndexes) > 0 {
|
||||||
var tags []*models.TransactionTag
|
var tags []*models.TransactionTag
|
||||||
err := sess.Where("uid=? AND deleted=?", transaction.Uid, false).In("tag_id", tagIds).Find(&tags)
|
err := sess.Where("uid=? AND deleted=?", transaction.Uid, false).In("tag_id", tagIds).Find(&tags)
|
||||||
|
|
||||||
@@ -1664,8 +1664,8 @@ func (s *TransactionService) isTagsValid(sess *xorm.Session, transaction *models
|
|||||||
tagMap[tags[i].TagId] = tags[i]
|
tagMap[tags[i].TagId] = tags[i]
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < len(transactionTagIndexs); i++ {
|
for i := 0; i < len(transactionTagIndexes); i++ {
|
||||||
if _, exists := tagMap[transactionTagIndexs[i].TagId]; !exists {
|
if _, exists := tagMap[transactionTagIndexes[i].TagId]; !exists {
|
||||||
return errs.ErrTransactionTagNotFound
|
return errs.ErrTransactionTagNotFound
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user