Config all processors for using two digits month number.
This commit is contained in:
@@ -6,22 +6,11 @@ using WebAPI.Models;
|
||||
|
||||
namespace WebAPI.dataProcessors;
|
||||
|
||||
public class T3MultiSourceSummaryProcessor
|
||||
public class T3MultiSourceSummaryProcessor(
|
||||
AppDbContext db,
|
||||
LayersController controller,
|
||||
LogsController logsController)
|
||||
{
|
||||
private readonly AppDbContext _db;
|
||||
private readonly LayersController _controller;
|
||||
private readonly LogsController _logsController;
|
||||
|
||||
public T3MultiSourceSummaryProcessor(
|
||||
AppDbContext db,
|
||||
LayersController controller,
|
||||
LogsController logsController)
|
||||
{
|
||||
_db = db;
|
||||
_controller = controller;
|
||||
_logsController = logsController;
|
||||
}
|
||||
|
||||
public void Process(Layer processWorker)
|
||||
{
|
||||
var year = int.Parse(processWorker.Records?.SingleOrDefault(x => x.Code == "Year")?.Desc1!);
|
||||
@@ -32,7 +21,7 @@ public class T3MultiSourceSummaryProcessor
|
||||
throw new Exception("Source record not found");
|
||||
}
|
||||
|
||||
var processedLayer = _db.Layers
|
||||
var processedLayer = db.Layers
|
||||
.Where(x => x.ParentId == processWorker.Id
|
||||
&& !x.IsDeleted)
|
||||
.OrderByDescending(x => x.CreatedAt)
|
||||
@@ -47,9 +36,9 @@ public class T3MultiSourceSummaryProcessor
|
||||
Id = Guid.NewGuid(),
|
||||
Type = LayerType.Processed,
|
||||
ParentId = processWorker.Id,
|
||||
Number = _db.Layers.Count() + 1
|
||||
Number = db.Layers.Count() + 1
|
||||
};
|
||||
processedLayer.Name = $"L{processedLayer.Number}-P-{year}/{month}-AA-T3";
|
||||
processedLayer.Name = $"L{processedLayer.Number}-P-{year}/{month:D2}-AA-T3";
|
||||
processedLayer.CreatedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D");
|
||||
processedLayer.ModifiedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D");
|
||||
processedLayer.CreatedAt = DateTime.UtcNow;
|
||||
@@ -61,7 +50,7 @@ public class T3MultiSourceSummaryProcessor
|
||||
|
||||
var newRecords = new List<Record>();
|
||||
|
||||
var dataSources = sources.Select(source => _db.Layers.Where(x => x.Type == LayerType.Processed && !x.IsDeleted && x.Name != null && x.Name.Contains($"{year}/{month}-{source.Desc1}-T3"))
|
||||
var dataSources = sources.Select(source => db.Layers.Where(x => x.Type == LayerType.Processed && !x.IsDeleted && x.Name != null && x.Name.Contains($"{year}/{month:D2}-{source.Desc1}-T3"))
|
||||
.Include(x => x.Records)
|
||||
.FirstOrDefault())
|
||||
.OfType<Layer>()
|
||||
@@ -108,7 +97,7 @@ public class T3MultiSourceSummaryProcessor
|
||||
{
|
||||
if (dynamicCode.Desc1 == null)
|
||||
{
|
||||
_logsController.AddEntry(new LogEntry
|
||||
logsController.AddEntry(new LogEntry
|
||||
{
|
||||
Title = $"{processWorker.Name}, {processWorker.Id}",
|
||||
Type = LogEntryType.Warning,
|
||||
@@ -121,7 +110,7 @@ public class T3MultiSourceSummaryProcessor
|
||||
var calc = new BaseCalc(dynamicCode.Desc1);
|
||||
if (!calc.IsFormulaCorrect())
|
||||
{
|
||||
_logsController.AddEntry(new LogEntry
|
||||
logsController.AddEntry(new LogEntry
|
||||
{
|
||||
Title = $"{processWorker.Name}, {processWorker.Id}",
|
||||
Type = LogEntryType.Warning,
|
||||
@@ -138,7 +127,7 @@ public class T3MultiSourceSummaryProcessor
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logsController.AddEntry(new LogEntry
|
||||
logsController.AddEntry(new LogEntry
|
||||
{
|
||||
Title = $"{processWorker.Name}, {processWorker.Id}",
|
||||
Type = LogEntryType.Warning,
|
||||
@@ -150,7 +139,7 @@ public class T3MultiSourceSummaryProcessor
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logsController.AddEntry(new LogEntry
|
||||
logsController.AddEntry(new LogEntry
|
||||
{
|
||||
Title = $"{processWorker.Name}, {processWorker.Id}",
|
||||
Type = LogEntryType.Warning,
|
||||
@@ -165,13 +154,13 @@ public class T3MultiSourceSummaryProcessor
|
||||
|
||||
if (isNew)
|
||||
{
|
||||
_db.Layers.Add(processedLayer);
|
||||
db.Layers.Add(processedLayer);
|
||||
}
|
||||
else
|
||||
{
|
||||
_db.Layers.Update(processedLayer);
|
||||
db.Layers.Update(processedLayer);
|
||||
}
|
||||
_controller.SaveRecords(processedLayer.Id, newRecords, Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"));
|
||||
_db.SaveChanges();
|
||||
controller.SaveRecords(processedLayer.Id, newRecords, Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"));
|
||||
db.SaveChanges();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user