From d4bc74c2927d15dccd7f397eeb0325b747d0c5e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Zieliski?= Date: Wed, 3 Jul 2024 13:43:57 +0200 Subject: [PATCH] R2 - zero values for future months --- WebAPI/dataProcessors/t4.r2.processor.cs | 83 ++++++++++++++++-------- 1 file changed, 55 insertions(+), 28 deletions(-) diff --git a/WebAPI/dataProcessors/t4.r2.processor.cs b/WebAPI/dataProcessors/t4.r2.processor.cs index 2a8d791..1a3a0aa 100644 --- a/WebAPI/dataProcessors/t4.r2.processor.cs +++ b/WebAPI/dataProcessors/t4.r2.processor.cs @@ -78,50 +78,77 @@ public class T4R2Processor sourceCodes = ProcessHelper.ParseCodes(rawSourceCodes); } - for (var month = 1; month <= DateTime.UtcNow.Month; month++) + List lastSourceCodes = new List(); + + for (var month = 1; month <= 12; month++) { - var monthCopy = month; - var dataSource = _db.Layers.Where(x => - x.Type == LayerType.Processed && - !x.IsDeleted && - x.Name != null && x.Name.Contains($"{year}/{monthCopy}-{source.Desc1}-T") - ) - .Include(x => x.Records) - .FirstOrDefault(); - if (dataSource != null) + if (month <= DateTime.UtcNow.Month) { - var news = dataSource.Records! - .Where(x => sourceCodes.Count <= 0 || sourceCodes.Contains(int.Parse(x.Code!))) + var monthCopy = month; + var dataSource = _db.Layers.Where(x => + x.Type == LayerType.Processed && + !x.IsDeleted && + x.Name != null && x.Name.Contains($"{year}/{monthCopy}-{source.Desc1}-T") + ) + .Include(x => x.Records) + .FirstOrDefault(); + if (dataSource != null) + { + lastSourceCodes = dataSource.Records!.Select(x => x.Code!).ToList(); + var news = dataSource.Records! + .Where(x => sourceCodes.Count <= 0 || sourceCodes.Contains(int.Parse(x.Code!))) + .Select(x => + { + var newRecord = new Record + { + Id = Guid.NewGuid(), + Code = x.Code + month.ToString("D2"), + CreatedAt = DateTime.UtcNow, + ModifiedAt = DateTime.UtcNow, + Value1 = source.Desc1 != "FK2" ? x.Value32 : x.Value1, + Desc1 = x.Desc1 + }; + return newRecord; + } + ).ToList(); + newRecords.AddRange(news); + } + else + { + _logsController.AddEntry(new LogEntry + { + Title = $"{processWorker.Name}, {processWorker.Id}", + Type = LogEntryType.Warning, + LogType = LogType.Process, + Message = $"Data source {year}/{month}-{source.Desc1}-T3 not found", + CreatedAt = DateTime.UtcNow + }); + } + } + else + { + //0 values for future months + if (source.Desc1 == "FK2" || lastSourceCodes.Count <= 0) continue; + var news = lastSourceCodes + .Where(x => sourceCodes.Contains(int.Parse(x))) .Select(x => { var newRecord = new Record { Id = Guid.NewGuid(), - Code = x.Code + month.ToString("D2"), + Code = x + month.ToString("D2"), CreatedAt = DateTime.UtcNow, ModifiedAt = DateTime.UtcNow, - Value1 = source.Desc1 != "FK2" ? x.Value32 : x.Value1, - Desc1 = x.Desc1 + Value1 = 0, }; - return newRecord; + return newRecord; } ).ToList(); newRecords.AddRange(news); } - else - { - _logsController.AddEntry(new LogEntry - { - Title = $"{processWorker.Name}, {processWorker.Id}", - Type = LogEntryType.Warning, - LogType = LogType.Process, - Message = $"Data source {year}/{month}-{source.Desc1}-T3 not found", - CreatedAt = DateTime.UtcNow - }); - } } - // year summery + // year summary var dataSourceSum = _db.Layers.Where(x => x.Type == LayerType.Processed && !x.IsDeleted &&