Add initial DTO classes and parser skeleton
This commit is contained in:
11
PriorBankParser/Constants.cs
Normal file
11
PriorBankParser/Constants.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
namespace PriorBankParser
|
||||
{
|
||||
public static class Constants
|
||||
{
|
||||
public static class SectionNames
|
||||
{
|
||||
internal const string LockedSectionPrefix = "Заблокированные суммы по ........";
|
||||
internal const string OperationSectionPrefix = "Операции по ........";
|
||||
}
|
||||
}
|
||||
}
|
||||
83
PriorBankParser/Parser.cs
Normal file
83
PriorBankParser/Parser.cs
Normal file
@@ -0,0 +1,83 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using CsvHelper;
|
||||
using CsvHelper.Configuration;
|
||||
|
||||
namespace PriorBankParser
|
||||
{
|
||||
public class SectionParser
|
||||
{
|
||||
public enum SectionType
|
||||
{
|
||||
AccountInfo,
|
||||
StatementDetails,
|
||||
ContractOperations,
|
||||
ContractLocked,
|
||||
ContractTotal,
|
||||
StatementTotal
|
||||
}
|
||||
|
||||
public SectionParseResultDto Parse(string filePath)
|
||||
{
|
||||
var result = new SectionParseResultDto();
|
||||
var transactions = new List<TransactionInfoDto>();
|
||||
result.Transactions = transactions;
|
||||
|
||||
using var reader = new StreamReader(filePath);
|
||||
using var csv = new CsvReader(reader, CultureInfo.InvariantCulture);
|
||||
csv.Configuration.HasHeaderRecord = false;
|
||||
csv.Configuration.RegisterClassMap<TransactionInfoDtoMap>();
|
||||
//csv.Configuration.
|
||||
|
||||
var currentSection = SectionType.AccountInfo;
|
||||
var contractName = string.Empty;
|
||||
|
||||
while (csv.Read())
|
||||
{
|
||||
var field = csv.GetField(0);
|
||||
if (field.Equals(Constants.SectionNames.OperationSectionPrefix))
|
||||
{
|
||||
currentSection = SectionType.StatementTotal;
|
||||
contractName = field.Replace(Constants.SectionNames.OperationSectionPrefix, string.Empty);
|
||||
continue;
|
||||
}
|
||||
|
||||
//switch (currentSection)
|
||||
//{
|
||||
// case "FooId":
|
||||
// fooRecords.Add(csv.GetRecord<Foo>());
|
||||
// break;
|
||||
// case "BarId":
|
||||
// barRecords.Add(csv.GetRecord<Bar>());
|
||||
// break;
|
||||
// default:
|
||||
// throw new InvalidOperationException("Unknown record type.");
|
||||
//}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public sealed class TransactionInfoDtoMap : ClassMap<TransactionInfoDto>
|
||||
{
|
||||
public TransactionInfoDtoMap()
|
||||
{
|
||||
Map(m => m.TransactionDate).Name("Дата транзакции");
|
||||
Map(m => m.OperationName).Name("Операция");
|
||||
Map(m => m.Amount).Name("Сумма");
|
||||
Map(m => m.Currency).Name("Валюта");
|
||||
Map(m => m.OperationDate).Name("Дата операции по счету");
|
||||
Map(m => m.Commission).Name("Комиссия/Money-back");
|
||||
Map(m => m.AccountTurnover).Name("Обороты по счету");
|
||||
Map(m => m.DigitalCard).Name("Цифровая карта");
|
||||
Map(m => m.OperationCategory).Name("Категория операции");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
11
PriorBankParser/SectionParseResult.cs
Normal file
11
PriorBankParser/SectionParseResult.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace PriorBankParser
|
||||
{
|
||||
public class SectionParseResultDto
|
||||
{
|
||||
public string ContractNo { get; set; }
|
||||
|
||||
public IReadOnlyCollection<TransactionInfoDto> Transactions { get; set; }
|
||||
}
|
||||
}
|
||||
42
PriorBankParser/StatementDto.cs
Normal file
42
PriorBankParser/StatementDto.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace PriorBankParser
|
||||
{
|
||||
public class StatementDto
|
||||
{
|
||||
public ICollection<KeyValuePair<string, string>> AccountInfos { get; set; }
|
||||
|
||||
public ICollection<OperationalSectionDto> ContractsInfo { get; set; }
|
||||
|
||||
public ICollection<LockedSection> LockedInfo { get; set; }
|
||||
|
||||
public TotalDto StatementTotal { get; set; }
|
||||
}
|
||||
|
||||
public class LockedSection
|
||||
{
|
||||
public string SectionName { get; set; }
|
||||
|
||||
public IReadOnlyCollection<TransactionInfoDto> Items { get; set; }
|
||||
}
|
||||
|
||||
public class OperationalSectionDto
|
||||
{
|
||||
public string SectionName { get; set; }
|
||||
|
||||
public IReadOnlyCollection<TransactionInfoDto> Items { get; set; }
|
||||
|
||||
public TotalDto Total { get; set; }
|
||||
}
|
||||
|
||||
public class TotalDto
|
||||
{
|
||||
public decimal IncomeAmount { get; set; }
|
||||
|
||||
public decimal OutcomeAmount { get; set; }
|
||||
|
||||
public decimal Commission { get; set; }
|
||||
|
||||
public decimal FinalAmount { get; set; }
|
||||
}
|
||||
}
|
||||
25
PriorBankParser/TransactionInfoDto.cs
Normal file
25
PriorBankParser/TransactionInfoDto.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
|
||||
namespace PriorBankParser
|
||||
{
|
||||
public class TransactionInfoDto
|
||||
{
|
||||
public DateTime TransactionDate { get; set; }
|
||||
|
||||
public string OperationName { get; set; }
|
||||
|
||||
public decimal Amount { get; set; }
|
||||
|
||||
public string Currency { get; set; }
|
||||
|
||||
public DateTime OperationDate { get; set; }
|
||||
|
||||
public decimal Commission { get; set; }
|
||||
|
||||
public decimal AccountTurnover { get; set; }
|
||||
|
||||
public string DigitalCard { get; set; }
|
||||
|
||||
public string OperationCategory { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user