R2 - zero values for future months
This commit is contained in:
@@ -78,50 +78,77 @@ public class T4R2Processor
|
||||
sourceCodes = ProcessHelper.ParseCodes(rawSourceCodes);
|
||||
}
|
||||
|
||||
for (var month = 1; month <= DateTime.UtcNow.Month; month++)
|
||||
List<string> lastSourceCodes = new List<string>();
|
||||
|
||||
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 &&
|
||||
|
||||
Reference in New Issue
Block a user