R2 - zero values for future months
This commit is contained in:
@@ -78,50 +78,77 @@ public class T4R2Processor
|
|||||||
sourceCodes = ProcessHelper.ParseCodes(rawSourceCodes);
|
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;
|
if (month <= DateTime.UtcNow.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)
|
|
||||||
{
|
{
|
||||||
var news = dataSource.Records!
|
var monthCopy = month;
|
||||||
.Where(x => sourceCodes.Count <= 0 || sourceCodes.Contains(int.Parse(x.Code!)))
|
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 =>
|
.Select(x =>
|
||||||
{
|
{
|
||||||
var newRecord = new Record
|
var newRecord = new Record
|
||||||
{
|
{
|
||||||
Id = Guid.NewGuid(),
|
Id = Guid.NewGuid(),
|
||||||
Code = x.Code + month.ToString("D2"),
|
Code = x + month.ToString("D2"),
|
||||||
CreatedAt = DateTime.UtcNow,
|
CreatedAt = DateTime.UtcNow,
|
||||||
ModifiedAt = DateTime.UtcNow,
|
ModifiedAt = DateTime.UtcNow,
|
||||||
Value1 = source.Desc1 != "FK2" ? x.Value32 : x.Value1,
|
Value1 = 0,
|
||||||
Desc1 = x.Desc1
|
|
||||||
};
|
};
|
||||||
return newRecord;
|
return newRecord;
|
||||||
}
|
}
|
||||||
).ToList();
|
).ToList();
|
||||||
newRecords.AddRange(news);
|
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 =>
|
var dataSourceSum = _db.Layers.Where(x =>
|
||||||
x.Type == LayerType.Processed &&
|
x.Type == LayerType.Processed &&
|
||||||
!x.IsDeleted &&
|
!x.IsDeleted &&
|
||||||
|
|||||||
Reference in New Issue
Block a user