t2.SingleSource - check if need to update
This commit is contained in:
@@ -7,7 +7,8 @@ namespace WebAPI.dataProcessors;
|
||||
|
||||
public class T3SingleSourceProcessor(
|
||||
AppDbContext db,
|
||||
LayersController controller)
|
||||
LayersController controller,
|
||||
LogsController logsController)
|
||||
{
|
||||
public void Process(Layer processWorker)
|
||||
{
|
||||
@@ -23,7 +24,7 @@ public class T3SingleSourceProcessor(
|
||||
{
|
||||
throw new Exception("SourceImportWorkerL layer not found");
|
||||
}
|
||||
var source= processWorker.Records?.SingleOrDefault(x => x.Code == "Source")?.Desc1;
|
||||
var source = processWorker.Records?.SingleOrDefault(x => x.Code == "Source")?.Desc1;
|
||||
if (sourceLayer == null)
|
||||
{
|
||||
throw new Exception("Source record not found");
|
||||
@@ -70,6 +71,18 @@ public class T3SingleSourceProcessor(
|
||||
throw new Exception($"DataSources are empty, {sourceImportWorker.Name}");
|
||||
}
|
||||
|
||||
if (!dataSources.Any(x => x.CreatedAt > processedLayer.ModifiedAt))
|
||||
{
|
||||
logsController.AddEntry(new LogEntry
|
||||
{
|
||||
Title = $"{processWorker.Name}, {processWorker.Id}",
|
||||
Type = LogEntryType.Info,
|
||||
LogType = LogType.Process,
|
||||
Message = $"Layer is up to date",
|
||||
CreatedAt = DateTime.UtcNow
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
var allRecords = dataSources.SelectMany(x => x.Records!).ToList();
|
||||
|
||||
@@ -92,14 +105,15 @@ public class T3SingleSourceProcessor(
|
||||
ProcessHelper.SetValue(processedRecord, 1, firstVal);
|
||||
var previousValue = firstVal;
|
||||
//days 2-29/30
|
||||
for (var i=2; i<lastDayInMonth; i++)
|
||||
for (var i = 2; i < lastDayInMonth; i++)
|
||||
{
|
||||
var dayVal = codeRecords
|
||||
.Where(x => x.CreatedAt.Day == i && x.CreatedAt.Month == month).MaxBy(x => x.CreatedAt)?.Value1;
|
||||
if (dayVal == null)
|
||||
{
|
||||
ProcessHelper.SetValue(processedRecord, i, 0);
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
var processedVal = dayVal - previousValue;
|
||||
ProcessHelper.SetValue(processedRecord, i, processedVal);
|
||||
@@ -113,7 +127,8 @@ public class T3SingleSourceProcessor(
|
||||
if (lastVal == null)
|
||||
{
|
||||
ProcessHelper.SetValue(processedRecord, lastDayInMonth, 0);
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
ProcessHelper.SetValue(processedRecord, lastDayInMonth, (double)lastVal - previousValue);
|
||||
}
|
||||
@@ -128,7 +143,8 @@ public class T3SingleSourceProcessor(
|
||||
if (isNew)
|
||||
{
|
||||
db.Layers.Add(processedLayer);
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
db.Layers.Update(processedLayer);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user