mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-14 15:07:33 +08:00
code refactor
This commit is contained in:
@@ -55,8 +55,8 @@ type DataTableTransactionDataImporter struct {
|
||||
// DataTableTransactionDataImporterPostProcessFunc represents item post process function of DataTableTransactionDataImporter
|
||||
type DataTableTransactionDataImporterPostProcessFunc func(core.Context, *models.ImportTransaction) error
|
||||
|
||||
// CreateNewDataTableTransactionDataExporter returns a new data table transaction data exporter according to the specified arguments
|
||||
func CreateNewDataTableTransactionDataExporter(dataColumnMapping map[DataTableColumn]string, transactionTypeMapping map[models.TransactionType]string, geoLocationSeparator string, transactionTagSeparator string) *DataTableTransactionDataExporter {
|
||||
// CreateNewExporter returns a new data table transaction data exporter according to the specified arguments
|
||||
func CreateNewExporter(dataColumnMapping map[DataTableColumn]string, transactionTypeMapping map[models.TransactionType]string, geoLocationSeparator string, transactionTagSeparator string) *DataTableTransactionDataExporter {
|
||||
return &DataTableTransactionDataExporter{
|
||||
dataColumnMapping: dataColumnMapping,
|
||||
transactionTypeMapping: transactionTypeMapping,
|
||||
@@ -65,8 +65,8 @@ func CreateNewDataTableTransactionDataExporter(dataColumnMapping map[DataTableCo
|
||||
}
|
||||
}
|
||||
|
||||
// CreateNewDataTableTransactionDataImporter returns a new data table transaction data importer according to the specified arguments
|
||||
func CreateNewDataTableTransactionDataImporter(dataColumnMapping map[DataTableColumn]string, transactionTypeMapping map[models.TransactionType]string, geoLocationSeparator string, transactionTagSeparator string) *DataTableTransactionDataImporter {
|
||||
// CreateNewImporter returns a new data table transaction data importer according to the specified arguments
|
||||
func CreateNewImporter(dataColumnMapping map[DataTableColumn]string, transactionTypeMapping map[models.TransactionType]string, geoLocationSeparator string, transactionTagSeparator string) *DataTableTransactionDataImporter {
|
||||
return &DataTableTransactionDataImporter{
|
||||
dataColumnMapping: dataColumnMapping,
|
||||
transactionTypeMapping: transactionTypeMapping,
|
||||
@@ -75,8 +75,8 @@ func CreateNewDataTableTransactionDataImporter(dataColumnMapping map[DataTableCo
|
||||
}
|
||||
}
|
||||
|
||||
// CreateNewSimpleDataTableTransactionDataImporterWithPostProcessFunc returns a new data table transaction data importer according to the specified arguments
|
||||
func CreateNewSimpleDataTableTransactionDataImporterWithPostProcessFunc(dataColumnMapping map[DataTableColumn]string, transactionTypeMapping map[models.TransactionType]string, postProcessFunc DataTableTransactionDataImporterPostProcessFunc) *DataTableTransactionDataImporter {
|
||||
// CreateNewSimpleImporterWithPostProcessFunc returns a new data table transaction data importer according to the specified arguments
|
||||
func CreateNewSimpleImporterWithPostProcessFunc(dataColumnMapping map[DataTableColumn]string, transactionTypeMapping map[models.TransactionType]string, postProcessFunc DataTableTransactionDataImporterPostProcessFunc) *DataTableTransactionDataImporter {
|
||||
return &DataTableTransactionDataImporter{
|
||||
dataColumnMapping: dataColumnMapping,
|
||||
transactionTypeMapping: transactionTypeMapping,
|
||||
@@ -84,6 +84,16 @@ func CreateNewSimpleDataTableTransactionDataImporterWithPostProcessFunc(dataColu
|
||||
}
|
||||
}
|
||||
|
||||
// CreateNewSimpleImporterFromWritableDataTableWithPostProcessFunc returns a new data table transaction data importer according to the specified arguments
|
||||
func CreateNewSimpleImporterFromWritableDataTableWithPostProcessFunc(writableDataTable *WritableDataTable, transactionTypeMapping map[models.TransactionType]string, postProcessFunc DataTableTransactionDataImporterPostProcessFunc) *DataTableTransactionDataImporter {
|
||||
return &DataTableTransactionDataImporter{
|
||||
dataColumnMapping: writableDataTable.GetDataColumnMapping(),
|
||||
transactionTypeMapping: transactionTypeMapping,
|
||||
postProcessFunc: postProcessFunc,
|
||||
}
|
||||
}
|
||||
|
||||
// BuildExportedContent writes the exported transaction data to the data table builder
|
||||
func (c *DataTableTransactionDataExporter) BuildExportedContent(ctx core.Context, dataTableBuilder DataTableBuilder, uid int64, transactions []*models.Transaction, accountMap map[int64]*models.Account, categoryMap map[int64]*models.TransactionCategory, tagMap map[int64]*models.TransactionTag, allTagIndexes map[int64][]int64) error {
|
||||
for i := 0; i < len(transactions); i++ {
|
||||
transaction := transactions[i]
|
||||
@@ -221,6 +231,7 @@ func (c *DataTableTransactionDataExporter) getExportedTags(dataTableBuilder Data
|
||||
return dataTableBuilder.ReplaceDelimiters(ret.String())
|
||||
}
|
||||
|
||||
// ParseImportedData returns the imported transaction data
|
||||
func (c *DataTableTransactionDataImporter) ParseImportedData(ctx core.Context, user *models.User, dataTable ImportedDataTable, defaultTimezoneOffset int16, accountMap map[string]*models.Account, categoryMap map[string]*models.TransactionCategory, tagMap map[string]*models.TransactionTag) (models.ImportedTransactionSlice, []*models.Account, []*models.TransactionCategory, []*models.TransactionTag, error) {
|
||||
if dataTable.DataRowCount() < 1 {
|
||||
log.Errorf(ctx, "[data_table_transaction_data_converter.parseImportedData] cannot parse import data for user \"uid:%d\", because data table row count is less 1", user.Uid)
|
||||
|
||||
@@ -66,7 +66,7 @@ func (c *ezBookKeepingTransactionDataPlainTextConverter) ToExportedContent(ctx c
|
||||
ezbookkeepingLineSeparator,
|
||||
)
|
||||
|
||||
dataTableExporter := datatable.CreateNewDataTableTransactionDataExporter(
|
||||
dataTableExporter := datatable.CreateNewExporter(
|
||||
ezbookkeepingDataColumnNameMapping,
|
||||
ezbookkeepingTransactionTypeNameMapping,
|
||||
ezbookkeepingGeoLocationSeparator,
|
||||
@@ -94,7 +94,7 @@ func (c *ezBookKeepingTransactionDataPlainTextConverter) ParseImportedData(ctx c
|
||||
return nil, nil, nil, nil, err
|
||||
}
|
||||
|
||||
dataTableImporter := datatable.CreateNewDataTableTransactionDataImporter(
|
||||
dataTableImporter := datatable.CreateNewImporter(
|
||||
ezbookkeepingDataColumnNameMapping,
|
||||
ezbookkeepingTransactionTypeNameMapping,
|
||||
ezbookkeepingGeoLocationSeparator,
|
||||
|
||||
@@ -181,8 +181,8 @@ func (c *feideeMymoneyTransactionDataCsvImporter) ParseImportedData(ctx core.Con
|
||||
return nil, nil, nil, nil, errs.ErrFoundRecordNotHasRelatedRecord
|
||||
}
|
||||
|
||||
dataTableImporter := datatable.CreateNewSimpleDataTableTransactionDataImporterWithPostProcessFunc(
|
||||
dataTable.GetDataColumnMapping(),
|
||||
dataTableImporter := datatable.CreateNewSimpleImporterFromWritableDataTableWithPostProcessFunc(
|
||||
dataTable,
|
||||
feideeMymoneyTransactionTypeNameMapping,
|
||||
feideeMymoneyTransactionDataImporterPostProcess,
|
||||
)
|
||||
@@ -204,7 +204,7 @@ func (c *feideeMymoneyTransactionDataCsvImporter) parseAllLinesFromCsvData(ctx c
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
log.Errorf(ctx, "[feidee_mymoney_transaction_data_csv_file_importer.parseCsvData] cannot parse feidee mymoney csv data, because %s", err.Error())
|
||||
log.Errorf(ctx, "[feidee_mymoney_transaction_data_csv_file_importer.parseAllLinesFromCsvData] cannot parse feidee mymoney csv data, because %s", err.Error())
|
||||
return nil, errs.ErrInvalidCSVFile
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ func (c *feideeMymoneyTransactionDataXlsImporter) ParseImportedData(ctx core.Con
|
||||
return nil, nil, nil, nil, err
|
||||
}
|
||||
|
||||
dataTableImporter := datatable.CreateNewSimpleDataTableTransactionDataImporterWithPostProcessFunc(
|
||||
dataTableImporter := datatable.CreateNewSimpleImporterWithPostProcessFunc(
|
||||
feideeMymoneyDataColumnNameMapping,
|
||||
feideeMymoneyTransactionTypeNameMapping,
|
||||
feideeMymoneyTransactionDataImporterPostProcess,
|
||||
|
||||
Reference in New Issue
Block a user