mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-19 17:24:26 +08:00
code refactor
This commit is contained in:
@@ -9,7 +9,9 @@ type EzBookKeepingCSVFileExporter struct {
|
|||||||
EzBookKeepingPlainFileExporter
|
EzBookKeepingPlainFileExporter
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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, allTagIndexs map[int64][]int64) ([]byte, error) {
|
||||||
return e.toExportedContent(uid, ",", transactions, accountMap, categoryMap, tagMap, allTagIndexs)
|
return e.toExportedContent(uid, csvSeparator, transactions, accountMap, categoryMap, tagMap, allTagIndexs)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,8 +13,11 @@ import (
|
|||||||
type EzBookKeepingPlainFileExporter struct {
|
type EzBookKeepingPlainFileExporter struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
const headerLine = "Time,Timezone,Type,Category,Sub Category,Account,Account Currency,Amount,Account2,Account2 Currency,Account2 Amount,Geographic Location,Tags,Description\n"
|
const lineSeparator = "\n"
|
||||||
const dataLineFormat = "%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s\n"
|
const geoLocationSeparator = " "
|
||||||
|
const transactionTagSeparator = ";"
|
||||||
|
const headerLine = "Time,Timezone,Type,Category,Sub Category,Account,Account Currency,Amount,Account2,Account2 Currency,Account2 Amount,Geographic Location,Tags,Description" + 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, allTagIndexs map[int64][]int64) ([]byte, error) {
|
||||||
@@ -60,7 +63,7 @@ func (e *EzBookKeepingPlainFileExporter) toExportedContent(uid int64, separator
|
|||||||
}
|
}
|
||||||
|
|
||||||
if transaction.GeoLongitude != 0 || transaction.GeoLatitude != 0 {
|
if transaction.GeoLongitude != 0 || transaction.GeoLatitude != 0 {
|
||||||
geoLocation = fmt.Sprintf("%f %f", transaction.GeoLongitude, 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, allTagIndexs, tagMap), separator)
|
||||||
@@ -167,7 +170,7 @@ func (e *EzBookKeepingPlainFileExporter) getTags(transactionId int64, allTagInde
|
|||||||
|
|
||||||
for i := 0; i < len(tagIndexs); i++ {
|
for i := 0; i < len(tagIndexs); i++ {
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
ret.WriteString(";")
|
ret.WriteString(transactionTagSeparator)
|
||||||
}
|
}
|
||||||
|
|
||||||
tagIndex := tagIndexs[i]
|
tagIndex := tagIndexs[i]
|
||||||
|
|||||||
@@ -9,7 +9,9 @@ type EzBookKeepingTSVFileExporter struct {
|
|||||||
EzBookKeepingPlainFileExporter
|
EzBookKeepingPlainFileExporter
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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, allTagIndexs map[int64][]int64) ([]byte, error) {
|
||||||
return e.toExportedContent(uid, "\t", transactions, accountMap, categoryMap, tagMap, allTagIndexs)
|
return e.toExportedContent(uid, tsvSeparator, transactions, accountMap, categoryMap, tagMap, allTagIndexs)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user