code refactor
This commit is contained in:
@@ -59,7 +59,8 @@ func (r *iifDataReader) read(ctx core.Context) ([]*iifAccountDataset, []*iifTran
|
||||
return nil, nil, errs.ErrInvalidIIFFile
|
||||
}
|
||||
|
||||
if items[0][0] == '!' { // sample line
|
||||
// read sample line
|
||||
if items[0][0] == '!' {
|
||||
if lastLineSign != "" {
|
||||
log.Errorf(ctx, "[iif_data_reader.read] iif missing transaction end line")
|
||||
return nil, nil, errs.ErrInvalidIIFFile
|
||||
@@ -82,19 +83,29 @@ func (r *iifDataReader) read(ctx core.Context) ([]*iifAccountDataset, []*iifTran
|
||||
currentDatasetType = items[0]
|
||||
lastLineSign = ""
|
||||
}
|
||||
}
|
||||
|
||||
if currentDatasetType == "" {
|
||||
log.Errorf(ctx, "[iif_data_reader.read] cannot read data line before sample line")
|
||||
return nil, nil, errs.ErrInvalidIIFFile
|
||||
} else if currentDatasetType == iifAccountSampleLineSignColumnName {
|
||||
if currentAccountDataset == nil {
|
||||
if currentDatasetType == iifAccountSampleLineSignColumnName {
|
||||
currentAccountDataset, err = r.readAccountSampleLine(ctx, items)
|
||||
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
} else {
|
||||
} else if currentDatasetType == iifTransactionSampleLineSignColumnName {
|
||||
currentTransactionDataset, err = r.readTransactionSampleLines(ctx, items)
|
||||
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
}
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
// read data lines
|
||||
if currentDatasetType == "" {
|
||||
log.Errorf(ctx, "[iif_data_reader.read] cannot read data line before sample line")
|
||||
return nil, nil, errs.ErrInvalidIIFFile
|
||||
} else if currentDatasetType == iifAccountSampleLineSignColumnName && currentAccountDataset != nil {
|
||||
if items[0] == iifAccountLineSignColumnName {
|
||||
accountData := &iifAccountData{
|
||||
dataItems: items,
|
||||
@@ -104,15 +115,7 @@ func (r *iifDataReader) read(ctx core.Context) ([]*iifAccountDataset, []*iifTran
|
||||
log.Errorf(ctx, "[iif_data_reader.read] iif line expected reading account sign, but actual is \"%s\"", items[0])
|
||||
return nil, nil, errs.ErrInvalidIIFFile
|
||||
}
|
||||
}
|
||||
} else if currentDatasetType == iifTransactionSampleLineSignColumnName {
|
||||
if currentTransactionDataset == nil {
|
||||
currentTransactionDataset, err = r.readTransactionSampleLines(ctx, items)
|
||||
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
} else {
|
||||
} else if currentDatasetType == iifTransactionSampleLineSignColumnName && currentTransactionDataset != nil {
|
||||
if lastLineSign == "" {
|
||||
if items[0] == iifTransactionLineSignColumnName {
|
||||
currentTransactionData = &iifTransactionData{
|
||||
@@ -143,7 +146,6 @@ func (r *iifDataReader) read(ctx core.Context) ([]*iifAccountDataset, []*iifTran
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if lastLineSign != "" {
|
||||
log.Errorf(ctx, "[iif_data_reader.read] iif missing transaction end line")
|
||||
|
||||
Reference in New Issue
Block a user