AutoProcess Refactor. Logging improvement. MultiSourceSummaryProcessor
This commit is contained in:
@@ -7,29 +7,32 @@ namespace WebAPI.dataProcessors
|
||||
{
|
||||
public class T3SourceYearSummaryProcessor
|
||||
{
|
||||
private AppDbContext db;
|
||||
private SpreadsheetsResource.ValuesResource googleSheetValues;
|
||||
private LayersController controller;
|
||||
private readonly AppDbContext db;
|
||||
private readonly SpreadsheetsResource.ValuesResource googleSheetValues;
|
||||
private readonly LayersController controller;
|
||||
private readonly LogsController logsController;
|
||||
|
||||
public T3SourceYearSummaryProcessor(
|
||||
AppDbContext _db,
|
||||
SpreadsheetsResource.ValuesResource _googleSheetValues,
|
||||
LayersController _controller)
|
||||
LayersController _controller,
|
||||
LogsController _logsController
|
||||
)
|
||||
{
|
||||
db = _db;
|
||||
googleSheetValues = _googleSheetValues;
|
||||
controller = _controller;
|
||||
logsController = _logsController;
|
||||
}
|
||||
|
||||
public void process(Layer processWorker)
|
||||
{
|
||||
string? sourceName = processWorker?.Records?.Single(x => x.Code == "Source")?.Desc1;
|
||||
int year = int.Parse(processWorker?.Records?.Single(x => x.Code == "Year")?.Desc1 ?? "0");
|
||||
if (year == 0)
|
||||
string? year = processWorker?.Records?.SingleOrDefault(x => x.Code == "Year")?.Desc1;
|
||||
string? source = processWorker?.Records?.SingleOrDefault(x => x.Code == "Source")?.Desc1;
|
||||
if (source == null)
|
||||
{
|
||||
throw new Exception($"Year is empty, {processWorker!.Name}");
|
||||
throw new Exception("Source record not found");
|
||||
}
|
||||
|
||||
Layer? processedLayer = db.Layers
|
||||
.Where(x => x.ParentId == processWorker!.Id
|
||||
&& !x.IsDeleted)
|
||||
@@ -48,7 +51,7 @@ namespace WebAPI.dataProcessors
|
||||
ParentId = processWorker!.Id,
|
||||
Number = db.Layers.Count() + 1,
|
||||
};
|
||||
processedLayer.Name = $"L{processedLayer.Number}-P-{year}/13-{sourceName}-T3";
|
||||
processedLayer.Name = $"L{processedLayer.Number}-P-{year}/13-{source}-T3";
|
||||
processedLayer.CreatedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D");
|
||||
processedLayer.ModifiedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D");
|
||||
processedLayer.CreatedAt = DateTime.UtcNow;
|
||||
@@ -60,29 +63,29 @@ namespace WebAPI.dataProcessors
|
||||
|
||||
List<Record> newRecords = new List<Record>();
|
||||
|
||||
List<Layer> sources = new List<Layer>();
|
||||
List<Layer> dataSources = new List<Layer>();
|
||||
for (int i=1; i<13; i++)
|
||||
{
|
||||
Layer? source = db.Layers.Where(x =>
|
||||
Layer? dataSource = db.Layers.Where(x =>
|
||||
x.Type == LayerType.processed
|
||||
&& !x.IsDeleted
|
||||
&& x.Name.Contains($"{year}/{i}-{sourceName}-T3"))
|
||||
&& x.Name.Contains($"{year}/{i}-{source}-T3"))
|
||||
.Include(x => x.Records)
|
||||
.FirstOrDefault();
|
||||
if (source != null)
|
||||
if (dataSource != null)
|
||||
{
|
||||
sources.Add(source);
|
||||
dataSources.Add(dataSource!);
|
||||
}
|
||||
}
|
||||
|
||||
if (sources.Count == 0)
|
||||
if (dataSources.Count == 0)
|
||||
{
|
||||
throw new Exception($"DataSources are empty, {processWorker!.Name}");
|
||||
throw new Exception("DataSources are empty");
|
||||
}
|
||||
|
||||
List<Record> allRecords = sources.SelectMany(x => x.Records!).ToList();
|
||||
List<Record> allRecords = dataSources.SelectMany(x => x.Records!).ToList();
|
||||
|
||||
foreach (Record baseRecord in sources.Last()?.Records!)
|
||||
foreach (Record baseRecord in dataSources.Last()?.Records!)
|
||||
{
|
||||
List<Record> codeRecords = allRecords.Where(x => x.Code == baseRecord.Code).ToList();
|
||||
Record processedRecord = new Record
|
||||
|
||||
Reference in New Issue
Block a user