diff --git a/WebAPI/dataProcessors/t3.SingleSource.processor.cs b/WebAPI/dataProcessors/t3.SingleSource.processor.cs index 77bba86..2b93338 100644 --- a/WebAPI/dataProcessors/t3.SingleSource.processor.cs +++ b/WebAPI/dataProcessors/t3.SingleSource.processor.cs @@ -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"); @@ -55,7 +56,7 @@ public class T3SingleSourceProcessor( processedLayer.ModifiedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"); processedLayer.ModifiedAt = DateTime.UtcNow; - + var newRecords = new List(); var dataSources = db.Layers @@ -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 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); } @@ -124,16 +139,17 @@ public class T3SingleSourceProcessor( newRecords.Add(processedRecord); } - + if (isNew) { db.Layers.Add(processedLayer); - } else + } + else { db.Layers.Update(processedLayer); } controller.SaveRecords(processedLayer.Id, newRecords, Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D")); db.SaveChanges(); } - + } \ No newline at end of file