Code refactor finished
This commit is contained in:
@@ -85,8 +85,8 @@ public class AdminController : Controller
|
|||||||
_logsController.AddEntry(new LogEntry
|
_logsController.AddEntry(new LogEntry
|
||||||
{
|
{
|
||||||
Title = "Backup success",
|
Title = "Backup success",
|
||||||
Type = LogEntryType.info,
|
Type = LogEntryType.Info,
|
||||||
LogType = LogType.backup,
|
LogType = LogType.Backup,
|
||||||
CreatedAt = DateTime.UtcNow
|
CreatedAt = DateTime.UtcNow
|
||||||
});
|
});
|
||||||
return Ok();
|
return Ok();
|
||||||
@@ -96,8 +96,8 @@ public class AdminController : Controller
|
|||||||
_logsController.AddEntry(new LogEntry
|
_logsController.AddEntry(new LogEntry
|
||||||
{
|
{
|
||||||
Title = "Backup error",
|
Title = "Backup error",
|
||||||
Type = LogEntryType.error,
|
Type = LogEntryType.Error,
|
||||||
LogType = LogType.backup,
|
LogType = LogType.Backup,
|
||||||
Message = e.ToString(),
|
Message = e.ToString(),
|
||||||
CreatedAt = DateTime.UtcNow
|
CreatedAt = DateTime.UtcNow
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -90,8 +90,8 @@ public class LayersController : Controller
|
|||||||
_logsController.AddEntry(new LogEntry
|
_logsController.AddEntry(new LogEntry
|
||||||
{
|
{
|
||||||
Title = $"Unauthorized request - wrong apiKey ({number})",
|
Title = $"Unauthorized request - wrong apiKey ({number})",
|
||||||
Type = LogEntryType.warning,
|
Type = LogEntryType.Warning,
|
||||||
LogType = LogType.powerBI,
|
LogType = LogType.PowerBi,
|
||||||
CreatedAt = DateTime.UtcNow
|
CreatedAt = DateTime.UtcNow
|
||||||
});
|
});
|
||||||
return Unauthorized();
|
return Unauthorized();
|
||||||
@@ -105,8 +105,8 @@ public class LayersController : Controller
|
|||||||
_logsController.AddEntry(new LogEntry
|
_logsController.AddEntry(new LogEntry
|
||||||
{
|
{
|
||||||
Title = $"Unauthorized request - no authorization header ({number})",
|
Title = $"Unauthorized request - no authorization header ({number})",
|
||||||
Type = LogEntryType.warning,
|
Type = LogEntryType.Warning,
|
||||||
LogType = LogType.powerBI,
|
LogType = LogType.PowerBi,
|
||||||
CreatedAt = DateTime.UtcNow
|
CreatedAt = DateTime.UtcNow
|
||||||
});
|
});
|
||||||
return Unauthorized();
|
return Unauthorized();
|
||||||
@@ -118,8 +118,8 @@ public class LayersController : Controller
|
|||||||
_logsController.AddEntry(new LogEntry
|
_logsController.AddEntry(new LogEntry
|
||||||
{
|
{
|
||||||
Title = $"Unauthorized request - wrong auth header format ({number})",
|
Title = $"Unauthorized request - wrong auth header format ({number})",
|
||||||
Type = LogEntryType.warning,
|
Type = LogEntryType.Warning,
|
||||||
LogType = LogType.powerBI,
|
LogType = LogType.PowerBi,
|
||||||
CreatedAt = DateTime.UtcNow
|
CreatedAt = DateTime.UtcNow
|
||||||
});
|
});
|
||||||
return Unauthorized();
|
return Unauthorized();
|
||||||
@@ -133,8 +133,8 @@ public class LayersController : Controller
|
|||||||
_logsController.AddEntry(new LogEntry
|
_logsController.AddEntry(new LogEntry
|
||||||
{
|
{
|
||||||
Title = $"Unauthorized request - bad credentials ({number})",
|
Title = $"Unauthorized request - bad credentials ({number})",
|
||||||
Type = LogEntryType.warning,
|
Type = LogEntryType.Warning,
|
||||||
LogType = LogType.powerBI,
|
LogType = LogType.PowerBi,
|
||||||
CreatedAt = DateTime.UtcNow
|
CreatedAt = DateTime.UtcNow
|
||||||
});
|
});
|
||||||
return Unauthorized();
|
return Unauthorized();
|
||||||
@@ -143,8 +143,8 @@ public class LayersController : Controller
|
|||||||
_logsController.AddEntry(new LogEntry
|
_logsController.AddEntry(new LogEntry
|
||||||
{
|
{
|
||||||
Title = $"Sending data for layer {number}",
|
Title = $"Sending data for layer {number}",
|
||||||
Type = LogEntryType.info,
|
Type = LogEntryType.Info,
|
||||||
LogType = LogType.powerBI,
|
LogType = LogType.PowerBi,
|
||||||
CreatedAt = DateTime.UtcNow
|
CreatedAt = DateTime.UtcNow
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -157,8 +157,8 @@ public class LayersController : Controller
|
|||||||
_logsController.AddEntry(new LogEntry
|
_logsController.AddEntry(new LogEntry
|
||||||
{
|
{
|
||||||
Title = e.ToString(),
|
Title = e.ToString(),
|
||||||
Type = LogEntryType.error,
|
Type = LogEntryType.Error,
|
||||||
LogType = LogType.powerBI,
|
LogType = LogType.PowerBi,
|
||||||
CreatedAt = DateTime.UtcNow
|
CreatedAt = DateTime.UtcNow
|
||||||
});
|
});
|
||||||
return BadRequest(e.ToString());
|
return BadRequest(e.ToString());
|
||||||
@@ -213,8 +213,8 @@ public class LayersController : Controller
|
|||||||
_logsController.AddEntry(new LogEntry
|
_logsController.AddEntry(new LogEntry
|
||||||
{
|
{
|
||||||
Title = "No Layers to import.",
|
Title = "No Layers to import.",
|
||||||
Type = LogEntryType.info,
|
Type = LogEntryType.Info,
|
||||||
LogType = LogType.import,
|
LogType = LogType.Import,
|
||||||
CreatedAt = DateTime.UtcNow
|
CreatedAt = DateTime.UtcNow
|
||||||
});
|
});
|
||||||
return Ok();
|
return Ok();
|
||||||
@@ -235,8 +235,8 @@ public class LayersController : Controller
|
|||||||
_logsController.AddEntry(new LogEntry
|
_logsController.AddEntry(new LogEntry
|
||||||
{
|
{
|
||||||
Title = $"{importWorker.Name}, {importWorker.Id}",
|
Title = $"{importWorker.Name}, {importWorker.Id}",
|
||||||
Type = LogEntryType.info,
|
Type = LogEntryType.Info,
|
||||||
LogType = LogType.import,
|
LogType = LogType.Import,
|
||||||
Message = "Success",
|
Message = "Success",
|
||||||
CreatedAt = DateTime.UtcNow
|
CreatedAt = DateTime.UtcNow
|
||||||
});
|
});
|
||||||
@@ -267,8 +267,8 @@ public class LayersController : Controller
|
|||||||
_logsController.AddEntry(new LogEntry
|
_logsController.AddEntry(new LogEntry
|
||||||
{
|
{
|
||||||
Title = $"{importWorker.Name}, {importWorker.Id}",
|
Title = $"{importWorker.Name}, {importWorker.Id}",
|
||||||
Type = LogEntryType.info,
|
Type = LogEntryType.Info,
|
||||||
LogType = LogType.import,
|
LogType = LogType.Import,
|
||||||
Message = "Success",
|
Message = "Success",
|
||||||
CreatedAt = DateTime.UtcNow
|
CreatedAt = DateTime.UtcNow
|
||||||
});
|
});
|
||||||
@@ -282,8 +282,8 @@ public class LayersController : Controller
|
|||||||
_logsController.AddEntry(new LogEntry
|
_logsController.AddEntry(new LogEntry
|
||||||
{
|
{
|
||||||
Title = $"{importWorker.Name}, {importWorker.Id}",
|
Title = $"{importWorker.Name}, {importWorker.Id}",
|
||||||
Type = LogEntryType.warning,
|
Type = LogEntryType.Warning,
|
||||||
LogType = LogType.import,
|
LogType = LogType.Import,
|
||||||
Message = "Success (reimported)",
|
Message = "Success (reimported)",
|
||||||
CreatedAt = DateTime.UtcNow
|
CreatedAt = DateTime.UtcNow
|
||||||
});
|
});
|
||||||
@@ -293,8 +293,8 @@ public class LayersController : Controller
|
|||||||
_logsController.AddEntry(new LogEntry
|
_logsController.AddEntry(new LogEntry
|
||||||
{
|
{
|
||||||
Title = $"{importWorker.Name}, {importWorker.Id}",
|
Title = $"{importWorker.Name}, {importWorker.Id}",
|
||||||
Type = LogEntryType.warning,
|
Type = LogEntryType.Warning,
|
||||||
LogType = LogType.import,
|
LogType = LogType.Import,
|
||||||
Message = "importLayer records are up of date. Not processed.",
|
Message = "importLayer records are up of date. Not processed.",
|
||||||
CreatedAt = DateTime.UtcNow
|
CreatedAt = DateTime.UtcNow
|
||||||
});
|
});
|
||||||
@@ -306,8 +306,8 @@ public class LayersController : Controller
|
|||||||
_logsController.AddEntry(new LogEntry
|
_logsController.AddEntry(new LogEntry
|
||||||
{
|
{
|
||||||
Title = $"{importWorker.Name}, {importWorker.Id}",
|
Title = $"{importWorker.Name}, {importWorker.Id}",
|
||||||
Type = LogEntryType.error,
|
Type = LogEntryType.Error,
|
||||||
LogType = LogType.import,
|
LogType = LogType.Import,
|
||||||
Message = e.ToString(),
|
Message = e.ToString(),
|
||||||
CreatedAt = DateTime.UtcNow
|
CreatedAt = DateTime.UtcNow
|
||||||
});
|
});
|
||||||
@@ -321,8 +321,8 @@ public class LayersController : Controller
|
|||||||
_logsController.AddEntry(new LogEntry
|
_logsController.AddEntry(new LogEntry
|
||||||
{
|
{
|
||||||
Title = "Process error",
|
Title = "Process error",
|
||||||
Type = LogEntryType.error,
|
Type = LogEntryType.Error,
|
||||||
LogType = LogType.import,
|
LogType = LogType.Import,
|
||||||
Message = e.ToString(),
|
Message = e.ToString(),
|
||||||
CreatedAt = DateTime.UtcNow
|
CreatedAt = DateTime.UtcNow
|
||||||
});
|
});
|
||||||
@@ -363,8 +363,8 @@ public class LayersController : Controller
|
|||||||
_logsController.AddEntry(new LogEntry
|
_logsController.AddEntry(new LogEntry
|
||||||
{
|
{
|
||||||
Title = $"Processing: {type}",
|
Title = $"Processing: {type}",
|
||||||
Type = LogEntryType.info,
|
Type = LogEntryType.Info,
|
||||||
LogType = LogType.process,
|
LogType = LogType.Process,
|
||||||
CreatedAt = DateTime.UtcNow
|
CreatedAt = DateTime.UtcNow
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -383,8 +383,8 @@ public class LayersController : Controller
|
|||||||
_logsController.AddEntry(new LogEntry
|
_logsController.AddEntry(new LogEntry
|
||||||
{
|
{
|
||||||
Title = "No Layers to process.",
|
Title = "No Layers to process.",
|
||||||
Type = LogEntryType.info,
|
Type = LogEntryType.Info,
|
||||||
LogType = LogType.process,
|
LogType = LogType.Process,
|
||||||
CreatedAt = DateTime.UtcNow
|
CreatedAt = DateTime.UtcNow
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -400,8 +400,8 @@ public class LayersController : Controller
|
|||||||
_logsController.AddEntry(new LogEntry
|
_logsController.AddEntry(new LogEntry
|
||||||
{
|
{
|
||||||
Title = $"{processWorker.Name}, {processWorker.Id}",
|
Title = $"{processWorker.Name}, {processWorker.Id}",
|
||||||
Type = LogEntryType.error,
|
Type = LogEntryType.Error,
|
||||||
LogType = LogType.process,
|
LogType = LogType.Process,
|
||||||
Message = e.ToString(),
|
Message = e.ToString(),
|
||||||
CreatedAt = DateTime.UtcNow
|
CreatedAt = DateTime.UtcNow
|
||||||
});
|
});
|
||||||
@@ -413,8 +413,8 @@ public class LayersController : Controller
|
|||||||
_logsController.AddEntry(new LogEntry
|
_logsController.AddEntry(new LogEntry
|
||||||
{
|
{
|
||||||
Title = "Process error",
|
Title = "Process error",
|
||||||
Type = LogEntryType.error,
|
Type = LogEntryType.Error,
|
||||||
LogType = LogType.process,
|
LogType = LogType.Process,
|
||||||
Message = e.ToString(),
|
Message = e.ToString(),
|
||||||
CreatedAt = DateTime.UtcNow
|
CreatedAt = DateTime.UtcNow
|
||||||
});
|
});
|
||||||
@@ -445,14 +445,14 @@ public class LayersController : Controller
|
|||||||
case "T3-SourceYearSummary":
|
case "T3-SourceYearSummary":
|
||||||
{
|
{
|
||||||
var processor =
|
var processor =
|
||||||
new T3SourceYearSummaryProcessor(_db, _googleSheetValues, this);
|
new T3SourceYearSummaryProcessor(_db, this);
|
||||||
processor.process(processWorker);
|
processor.Process(processWorker);
|
||||||
|
|
||||||
_logsController.AddEntry(new LogEntry
|
_logsController.AddEntry(new LogEntry
|
||||||
{
|
{
|
||||||
Title = $"{processWorker.Name}, {processWorker.Id}",
|
Title = $"{processWorker.Name}, {processWorker.Id}",
|
||||||
Type = LogEntryType.info,
|
Type = LogEntryType.Info,
|
||||||
LogType = LogType.process,
|
LogType = LogType.Process,
|
||||||
Message = "Success",
|
Message = "Success",
|
||||||
CreatedAt = DateTime.UtcNow
|
CreatedAt = DateTime.UtcNow
|
||||||
});
|
});
|
||||||
@@ -461,14 +461,14 @@ public class LayersController : Controller
|
|||||||
case "T3-MultiSourceYearSummary":
|
case "T3-MultiSourceYearSummary":
|
||||||
{
|
{
|
||||||
var processor =
|
var processor =
|
||||||
new T3MultiSourceYearSummaryProcessor(_db, _googleSheetValues, this, _logsController);
|
new T3MultiSourceYearSummaryProcessor(_db, this, _logsController);
|
||||||
processor.process(processWorker);
|
processor.Process(processWorker);
|
||||||
|
|
||||||
_logsController.AddEntry(new LogEntry
|
_logsController.AddEntry(new LogEntry
|
||||||
{
|
{
|
||||||
Title = $"{processWorker.Name}, {processWorker.Id}",
|
Title = $"{processWorker.Name}, {processWorker.Id}",
|
||||||
Type = LogEntryType.info,
|
Type = LogEntryType.Info,
|
||||||
LogType = LogType.process,
|
LogType = LogType.Process,
|
||||||
Message = "Success",
|
Message = "Success",
|
||||||
CreatedAt = DateTime.UtcNow
|
CreatedAt = DateTime.UtcNow
|
||||||
});
|
});
|
||||||
@@ -477,14 +477,14 @@ public class LayersController : Controller
|
|||||||
case "T3-MultiSourceCopySelectedCodesYearSummary":
|
case "T3-MultiSourceCopySelectedCodesYearSummary":
|
||||||
{
|
{
|
||||||
var processor =
|
var processor =
|
||||||
new T3MultiSourceCopySelectedCodesYearSummaryProcessor(_db, _googleSheetValues, this);
|
new T3MultiSourceCopySelectedCodesYearSummaryProcessor(_db, this);
|
||||||
processor.process(processWorker);
|
processor.Process(processWorker);
|
||||||
|
|
||||||
_logsController.AddEntry(new LogEntry
|
_logsController.AddEntry(new LogEntry
|
||||||
{
|
{
|
||||||
Title = $"{processWorker.Name}, {processWorker.Id}",
|
Title = $"{processWorker.Name}, {processWorker.Id}",
|
||||||
Type = LogEntryType.info,
|
Type = LogEntryType.Info,
|
||||||
LogType = LogType.process,
|
LogType = LogType.Process,
|
||||||
Message = "Success",
|
Message = "Success",
|
||||||
CreatedAt = DateTime.UtcNow
|
CreatedAt = DateTime.UtcNow
|
||||||
});
|
});
|
||||||
@@ -498,8 +498,8 @@ public class LayersController : Controller
|
|||||||
_logsController.AddEntry(new LogEntry
|
_logsController.AddEntry(new LogEntry
|
||||||
{
|
{
|
||||||
Title = $"{processWorker.Name}, {processWorker.Id}",
|
Title = $"{processWorker.Name}, {processWorker.Id}",
|
||||||
Type = LogEntryType.info,
|
Type = LogEntryType.Info,
|
||||||
LogType = LogType.process,
|
LogType = LogType.Process,
|
||||||
Message = "Success",
|
Message = "Success",
|
||||||
CreatedAt = DateTime.UtcNow
|
CreatedAt = DateTime.UtcNow
|
||||||
});
|
});
|
||||||
@@ -507,14 +507,14 @@ public class LayersController : Controller
|
|||||||
}
|
}
|
||||||
case "T4-R2":
|
case "T4-R2":
|
||||||
{
|
{
|
||||||
var processor = new T4R2Processor(_db, _googleSheetValues, this, _logsController);
|
var processor = new T4R2Processor(_db, this, _logsController);
|
||||||
processor.Process(processWorker);
|
processor.Process(processWorker);
|
||||||
|
|
||||||
_logsController.AddEntry(new LogEntry
|
_logsController.AddEntry(new LogEntry
|
||||||
{
|
{
|
||||||
Title = $"{processWorker.Name}, {processWorker.Id}",
|
Title = $"{processWorker.Name}, {processWorker.Id}",
|
||||||
Type = LogEntryType.info,
|
Type = LogEntryType.Info,
|
||||||
LogType = LogType.process,
|
LogType = LogType.Process,
|
||||||
Message = "Success",
|
Message = "Success",
|
||||||
CreatedAt = DateTime.UtcNow
|
CreatedAt = DateTime.UtcNow
|
||||||
});
|
});
|
||||||
@@ -531,28 +531,28 @@ public class LayersController : Controller
|
|||||||
switch (processType!)
|
switch (processType!)
|
||||||
{
|
{
|
||||||
case "T3-SingleSource":
|
case "T3-SingleSource":
|
||||||
var t3SingleSource = new T3SingleSourceProcessor(_db, _googleSheetValues, this);
|
var t3SingleSource = new T3SingleSourceProcessor(_db, this);
|
||||||
{
|
{
|
||||||
t3SingleSource.process(processWorker);
|
t3SingleSource.Process(processWorker);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "T4-SingleSource":
|
case "T4-SingleSource":
|
||||||
{
|
{
|
||||||
var t4SingleSource = new T4SingleSourceProcessor(_db, _googleSheetValues, this);
|
var t4SingleSource = new T4SingleSourceProcessor(_db, this);
|
||||||
t4SingleSource.process(processWorker);
|
t4SingleSource.Process(processWorker);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "T3-MultiSourceSummary":
|
case "T3-MultiSourceSummary":
|
||||||
{
|
{
|
||||||
var t3MultiSourceSummary =
|
var t3MultiSourceSummary =
|
||||||
new T3MultiSourceSummaryProcessor(_db, _googleSheetValues, this, _logsController);
|
new T3MultiSourceSummaryProcessor(_db, this, _logsController);
|
||||||
t3MultiSourceSummary.process(processWorker);
|
t3MultiSourceSummary.Process(processWorker);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "T3-MultiSourceCopySelectedCodes":
|
case "T3-MultiSourceCopySelectedCodes":
|
||||||
{
|
{
|
||||||
var t3MultiSourceCopySelectedCode =
|
var t3MultiSourceCopySelectedCode =
|
||||||
new T3MultiSourceCopySelectedCodesProcessor(_db, _googleSheetValues, this);
|
new T3MultiSourceCopySelectedCodesProcessor(_db, this);
|
||||||
t3MultiSourceCopySelectedCode.Process(processWorker);
|
t3MultiSourceCopySelectedCode.Process(processWorker);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -561,8 +561,8 @@ public class LayersController : Controller
|
|||||||
_logsController.AddEntry(new LogEntry
|
_logsController.AddEntry(new LogEntry
|
||||||
{
|
{
|
||||||
Title = $"{processWorker.Name}, {processWorker.Id}",
|
Title = $"{processWorker.Name}, {processWorker.Id}",
|
||||||
Type = LogEntryType.info,
|
Type = LogEntryType.Info,
|
||||||
LogType = LogType.process,
|
LogType = LogType.Process,
|
||||||
Message = "Success",
|
Message = "Success",
|
||||||
CreatedAt = DateTime.UtcNow
|
CreatedAt = DateTime.UtcNow
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -28,10 +28,10 @@ public class LogsController : Controller
|
|||||||
|
|
||||||
var type = entry.LogType switch
|
var type = entry.LogType switch
|
||||||
{
|
{
|
||||||
LogType.import => "Import",
|
LogType.Import => "Import",
|
||||||
LogType.backup => "Backup",
|
LogType.Backup => "Backup",
|
||||||
LogType.process => "Process",
|
LogType.Process => "Process",
|
||||||
LogType.powerBI => "PowerBIAccess",
|
LogType.PowerBi => "PowerBIAccess",
|
||||||
_ => "Other"
|
_ => "Other"
|
||||||
};
|
};
|
||||||
var response = _googleSheetValues.Get(_configuration["appLogsFile"], $"{type}!A:A").Execute();
|
var response = _googleSheetValues.Get(_configuration["appLogsFile"], $"{type}!A:A").Execute();
|
||||||
|
|||||||
@@ -32,19 +32,19 @@ public class GoogleSheetExport
|
|||||||
|
|
||||||
switch (layer.Type)
|
switch (layer.Type)
|
||||||
{
|
{
|
||||||
case LayerType.import:
|
case LayerType.Import:
|
||||||
{
|
{
|
||||||
data.Add(new List<object> { "Code", "Value1" });
|
data.Add(new List<object> { "Code", "Value1" });
|
||||||
data.AddRange(layer.Records!.Select(record => new List<object> { record.Code!, record.Value1! }));
|
data.AddRange(layer.Records!.Select(record => new List<object> { record.Code!, record.Value1! }));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case LayerType.administration:
|
case LayerType.Administration:
|
||||||
{
|
{
|
||||||
data.Add(new List<object> { "Code", "Desc1"});
|
data.Add(new List<object> { "Code", "Desc1"});
|
||||||
data.AddRange(layer.Records!.Select(record => new List<object> { record.Code!, record.Desc1! }));
|
data.AddRange(layer.Records!.Select(record => new List<object> { record.Code!, record.Desc1! }));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case LayerType.processed:
|
case LayerType.Processed:
|
||||||
{
|
{
|
||||||
data.Add(new List<object> { "Code", "Value1", "Value2", "Value3", "Value3",
|
data.Add(new List<object> { "Code", "Value1", "Value2", "Value3", "Value3",
|
||||||
"Value5", "Value6", "Value7", "Value8", "Value9", "Value10",
|
"Value5", "Value6", "Value7", "Value8", "Value9", "Value10",
|
||||||
|
|||||||
@@ -1,44 +1,42 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
namespace WebAPI.Models
|
namespace WebAPI.Models;
|
||||||
|
|
||||||
|
public enum LayerType
|
||||||
{
|
{
|
||||||
public enum LayerType
|
Import,
|
||||||
{
|
Processed,
|
||||||
import,
|
Administration
|
||||||
processed,
|
|
||||||
administration,
|
|
||||||
}
|
|
||||||
public class Layer
|
|
||||||
{
|
|
||||||
#region Properties
|
|
||||||
[Key]
|
|
||||||
public Guid Id { get; set; }
|
|
||||||
[Required]
|
|
||||||
public int Number { get; set; }
|
|
||||||
[Required]
|
|
||||||
public string? Source { get; set; }
|
|
||||||
[Required]
|
|
||||||
public string? Name { get; set; }
|
|
||||||
[Required]
|
|
||||||
public LayerType Type { get; set; }
|
|
||||||
[Required]
|
|
||||||
public DateTime CreatedAt { get; set; }
|
|
||||||
[Required]
|
|
||||||
public DateTime ModifiedAt { get; set; }
|
|
||||||
[Required]
|
|
||||||
public bool IsDeleted { get; set; }
|
|
||||||
#endregion
|
|
||||||
#region Relations
|
|
||||||
public ICollection<Record>? Records { get; set; }
|
|
||||||
public ICollection<ProcessSource>? Sources { get; set; }
|
|
||||||
[Required]
|
|
||||||
public Guid CreatedById { get; set; }
|
|
||||||
public User? CreatedBy { get; set; }
|
|
||||||
[Required]
|
|
||||||
public Guid ModifiedById { get; set; }
|
|
||||||
public User? ModifiedBy { get; set; }
|
|
||||||
public Guid? ParentId { get; set; }
|
|
||||||
public Layer? Parent { get; set; }
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
public class Layer
|
||||||
|
{
|
||||||
|
#region Properties
|
||||||
|
[Key]
|
||||||
|
public Guid Id { get; init; }
|
||||||
|
[Required]
|
||||||
|
public int Number { get; init; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
[MaxLength(50)]
|
||||||
|
public string? Name { get; set; }
|
||||||
|
[Required]
|
||||||
|
public LayerType Type { get; init; }
|
||||||
|
[Required]
|
||||||
|
public DateTime CreatedAt { get; set; }
|
||||||
|
[Required]
|
||||||
|
public DateTime ModifiedAt { get; set; }
|
||||||
|
[Required]
|
||||||
|
public bool IsDeleted { get; init; }
|
||||||
|
#endregion
|
||||||
|
#region Relations
|
||||||
|
public ICollection<Record>? Records { get; init; }
|
||||||
|
[Required]
|
||||||
|
public Guid CreatedById { get; set; }
|
||||||
|
public User? CreatedBy { get; init; }
|
||||||
|
[Required]
|
||||||
|
public Guid ModifiedById { get; set; }
|
||||||
|
public User? ModifiedBy { get; init; }
|
||||||
|
public Guid? ParentId { get; init; }
|
||||||
|
public Layer? Parent { get; init; }
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
@@ -1,25 +1,22 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
namespace WebAPI.Models;
|
||||||
|
|
||||||
namespace WebAPI.Models
|
public enum LogEntryType
|
||||||
{
|
{
|
||||||
public enum LogEntryType
|
Info,
|
||||||
{
|
Warning,
|
||||||
info,
|
Error
|
||||||
warning,
|
|
||||||
error,
|
|
||||||
}
|
|
||||||
public enum LogType {
|
|
||||||
import,
|
|
||||||
backup,
|
|
||||||
process,
|
|
||||||
powerBI
|
|
||||||
}
|
|
||||||
public class LogEntry
|
|
||||||
{
|
|
||||||
public LogType LogType { get; set; }
|
|
||||||
public LogEntryType Type { get; set; }
|
|
||||||
public string? Message { get; set; }
|
|
||||||
public string? Title {get; set;}
|
|
||||||
public DateTime CreatedAt { get; set; }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
public enum LogType {
|
||||||
|
Import,
|
||||||
|
Backup,
|
||||||
|
Process,
|
||||||
|
PowerBi
|
||||||
|
}
|
||||||
|
public class LogEntry
|
||||||
|
{
|
||||||
|
public LogType LogType { get; init; }
|
||||||
|
public LogEntryType Type { get; init; }
|
||||||
|
public string? Message { get; init; }
|
||||||
|
public string? Title {get; init;}
|
||||||
|
public DateTime CreatedAt { get; init; }
|
||||||
|
}
|
||||||
@@ -1,15 +1,14 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
namespace WebAPI.Models
|
namespace WebAPI.Models;
|
||||||
|
|
||||||
|
public class ProcessSource
|
||||||
{
|
{
|
||||||
public class ProcessSource
|
#region Relations
|
||||||
{
|
[Required]
|
||||||
#region Relations
|
public Guid LayerId { get; init; }
|
||||||
[Required]
|
[Required]
|
||||||
public Guid LayerId { get; set; }
|
public Guid SourceId { get; init; }
|
||||||
[Required]
|
public Layer? Source { get; init; }
|
||||||
public Guid SourceId { get; set; }
|
#endregion
|
||||||
public Layer? Source { get; set; }
|
}
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -6,10 +6,10 @@ public class Record
|
|||||||
{
|
{
|
||||||
#region Properties
|
#region Properties
|
||||||
[Key]
|
[Key]
|
||||||
public Guid Id { get; set; }
|
public Guid Id { get; init; }
|
||||||
[Required]
|
[Required]
|
||||||
[StringLength(50)]
|
[StringLength(50)]
|
||||||
public string? Code { get; set; }
|
public string? Code { get; init; }
|
||||||
public double? Value1 { get; set; }
|
public double? Value1 { get; set; }
|
||||||
public double? Value2 { get; set; }
|
public double? Value2 { get; set; }
|
||||||
public double? Value3 { get; set; }
|
public double? Value3 { get; set; }
|
||||||
@@ -44,15 +44,15 @@ public class Record
|
|||||||
public double? Value32 { get; set; }
|
public double? Value32 { get; set; }
|
||||||
//Description fields
|
//Description fields
|
||||||
[StringLength(50)]
|
[StringLength(50)]
|
||||||
public string? Desc1 { get; set; }
|
public string? Desc1 { get; init; }
|
||||||
[StringLength(50)]
|
[StringLength(50)]
|
||||||
public string? Desc2 { get; set; }
|
public string? Desc2 { get; init; }
|
||||||
[StringLength(50)]
|
[StringLength(50)]
|
||||||
public string? Desc3 { get; set; }
|
public string? Desc3 { get; init; }
|
||||||
[StringLength(50)]
|
[StringLength(50)]
|
||||||
public string? Desc4 { get; set; }
|
public string? Desc4 { get; init; }
|
||||||
[StringLength(50)]
|
[StringLength(50)]
|
||||||
public string? Desc5 { get; set; }
|
public string? Desc5 { get; init; }
|
||||||
[StringLength(50)]
|
[StringLength(50)]
|
||||||
public DateTime CreatedAt { get; set; }
|
public DateTime CreatedAt { get; set; }
|
||||||
public DateTime ModifiedAt { get; set; }
|
public DateTime ModifiedAt { get; set; }
|
||||||
|
|||||||
@@ -80,10 +80,9 @@ public class MorskaFk2Importer
|
|||||||
}
|
}
|
||||||
var layer = new Layer
|
var layer = new Layer
|
||||||
{
|
{
|
||||||
Source = "GoogleSheet",
|
|
||||||
Number = _db.Layers.Count() + 1,
|
Number = _db.Layers.Count() + 1,
|
||||||
ParentId = importWorker.Id,
|
ParentId = importWorker.Id,
|
||||||
Type = LayerType.import,
|
Type = LayerType.Import,
|
||||||
CreatedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"),
|
CreatedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"),
|
||||||
ModifiedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"),
|
ModifiedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"),
|
||||||
CreatedAt = DateTime.UtcNow,
|
CreatedAt = DateTime.UtcNow,
|
||||||
|
|||||||
@@ -80,10 +80,9 @@ public class MorskaImporter
|
|||||||
}
|
}
|
||||||
var layer = new Layer
|
var layer = new Layer
|
||||||
{
|
{
|
||||||
Source = "GoogleSheet",
|
|
||||||
Number = _db.Layers.Count() + 1,
|
Number = _db.Layers.Count() + 1,
|
||||||
ParentId = importWorker.Id,
|
ParentId = importWorker.Id,
|
||||||
Type = LayerType.import,
|
Type = LayerType.Import,
|
||||||
CreatedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"),
|
CreatedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"),
|
||||||
ModifiedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"),
|
ModifiedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"),
|
||||||
CreatedAt = DateTime.UtcNow,
|
CreatedAt = DateTime.UtcNow,
|
||||||
|
|||||||
@@ -55,8 +55,7 @@ public class T1R1Processor
|
|||||||
processedLayer = new Layer
|
processedLayer = new Layer
|
||||||
{
|
{
|
||||||
Id = Guid.NewGuid(),
|
Id = Guid.NewGuid(),
|
||||||
Source = "",
|
Type = LayerType.Processed,
|
||||||
Type = LayerType.processed,
|
|
||||||
ParentId = processWorker.Id,
|
ParentId = processWorker.Id,
|
||||||
Number = _db.Layers.Count() + 1
|
Number = _db.Layers.Count() + 1
|
||||||
};
|
};
|
||||||
@@ -66,7 +65,7 @@ public class T1R1Processor
|
|||||||
processedLayer.CreatedAt = DateTime.UtcNow;
|
processedLayer.CreatedAt = DateTime.UtcNow;
|
||||||
processedLayer.ModifiedAt = DateTime.UtcNow;
|
processedLayer.ModifiedAt = DateTime.UtcNow;
|
||||||
}
|
}
|
||||||
processedLayer.Sources = new List<ProcessSource>();
|
|
||||||
processedLayer.ModifiedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D");
|
processedLayer.ModifiedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D");
|
||||||
processedLayer.ModifiedAt = DateTime.UtcNow;
|
processedLayer.ModifiedAt = DateTime.UtcNow;
|
||||||
|
|
||||||
@@ -78,7 +77,7 @@ public class T1R1Processor
|
|||||||
{
|
{
|
||||||
var monthCopy = month;
|
var monthCopy = month;
|
||||||
var dataSource = _db.Layers.Where(x =>
|
var dataSource = _db.Layers.Where(x =>
|
||||||
x.Type == LayerType.processed &&
|
x.Type == LayerType.Processed &&
|
||||||
!x.IsDeleted &&
|
!x.IsDeleted &&
|
||||||
x.Name != null && x.Name.Contains($"{year}/{monthCopy}-{source.Desc1}-T3")
|
x.Name != null && x.Name.Contains($"{year}/{monthCopy}-{source.Desc1}-T3")
|
||||||
)
|
)
|
||||||
@@ -93,8 +92,8 @@ public class T1R1Processor
|
|||||||
_logsController.AddEntry(new LogEntry
|
_logsController.AddEntry(new LogEntry
|
||||||
{
|
{
|
||||||
Title = $"{processWorker.Name}, {processWorker.Id}",
|
Title = $"{processWorker.Name}, {processWorker.Id}",
|
||||||
Type = LogEntryType.warning,
|
Type = LogEntryType.Warning,
|
||||||
LogType = LogType.process,
|
LogType = LogType.Process,
|
||||||
Message = $"Data source {year}/{month}-{source.Desc1}-T3 not found",
|
Message = $"Data source {year}/{month}-{source.Desc1}-T3 not found",
|
||||||
CreatedAt = DateTime.UtcNow
|
CreatedAt = DateTime.UtcNow
|
||||||
});
|
});
|
||||||
@@ -102,7 +101,7 @@ public class T1R1Processor
|
|||||||
}
|
}
|
||||||
// year summary
|
// 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 &&
|
||||||
x.Name != null && x.Name.Contains($"{year}/13-{source.Desc1}-T3")
|
x.Name != null && x.Name.Contains($"{year}/13-{source.Desc1}-T3")
|
||||||
)
|
)
|
||||||
@@ -117,8 +116,8 @@ public class T1R1Processor
|
|||||||
_logsController.AddEntry(new LogEntry
|
_logsController.AddEntry(new LogEntry
|
||||||
{
|
{
|
||||||
Title = $"{processWorker.Name}, {processWorker.Id}",
|
Title = $"{processWorker.Name}, {processWorker.Id}",
|
||||||
Type = LogEntryType.warning,
|
Type = LogEntryType.Warning,
|
||||||
LogType = LogType.process,
|
LogType = LogType.Process,
|
||||||
Message = $"Data source {year}/13-{source.Desc1}-T3 not found",
|
Message = $"Data source {year}/13-{source.Desc1}-T3 not found",
|
||||||
CreatedAt = DateTime.UtcNow
|
CreatedAt = DateTime.UtcNow
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,113 +1,106 @@
|
|||||||
using DiunaBIWebAPI.dataProcessors;
|
using DiunaBIWebAPI.dataProcessors;
|
||||||
using Google.Apis.Sheets.v4;
|
|
||||||
using Google.Apis.Sheets.v4.Data;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using WebAPI.Controllers;
|
using WebAPI.Controllers;
|
||||||
using WebAPI.Models;
|
using WebAPI.Models;
|
||||||
|
|
||||||
namespace WebAPI.dataProcessors
|
namespace WebAPI.dataProcessors;
|
||||||
{
|
|
||||||
public class T3MultiSourceCopySelectedCodesProcessor
|
|
||||||
{
|
|
||||||
private readonly AppDbContext db;
|
|
||||||
private readonly SpreadsheetsResource.ValuesResource googleSheetValues;
|
|
||||||
private readonly LayersController controller;
|
|
||||||
|
|
||||||
public T3MultiSourceCopySelectedCodesProcessor(
|
public class T3MultiSourceCopySelectedCodesProcessor
|
||||||
AppDbContext _db,
|
{
|
||||||
SpreadsheetsResource.ValuesResource _googleSheetValues,
|
private readonly AppDbContext _db;
|
||||||
LayersController _controller)
|
private readonly LayersController _controller;
|
||||||
|
|
||||||
|
public T3MultiSourceCopySelectedCodesProcessor(
|
||||||
|
AppDbContext db,
|
||||||
|
LayersController controller)
|
||||||
|
{
|
||||||
|
_db = db;
|
||||||
|
_controller = controller;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Process(Layer processWorker)
|
||||||
|
{
|
||||||
|
var year = int.Parse(processWorker.Records?.SingleOrDefault(x => x.Code == "Year")?.Desc1!);
|
||||||
|
var month = int.Parse(processWorker.Records?.SingleOrDefault(x => x.Code == "Month")?.Desc1!);
|
||||||
|
var sources = processWorker.Records?.Where(x => x.Code == "Source").ToList();
|
||||||
|
if (!sources!.Any())
|
||||||
{
|
{
|
||||||
db = _db;
|
throw new Exception("Source record not found");
|
||||||
googleSheetValues = _googleSheetValues;
|
}
|
||||||
controller = _controller;
|
var codes = processWorker.Records?.SingleOrDefault(x => x.Code == "Codes")?.Desc1;
|
||||||
|
if (codes == null)
|
||||||
|
{
|
||||||
|
throw new Exception("Codes record not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Process(Layer processWorker)
|
var codesList = ProcessHelper.ParseCodes(codes);
|
||||||
|
|
||||||
|
var processedLayer = _db.Layers
|
||||||
|
.Where(x => x.ParentId == processWorker.Id
|
||||||
|
&& !x.IsDeleted)
|
||||||
|
.OrderByDescending(x => x.CreatedAt)
|
||||||
|
.FirstOrDefault();
|
||||||
|
|
||||||
|
var isNew = false;
|
||||||
|
if (processedLayer == null)
|
||||||
{
|
{
|
||||||
var year = int.Parse(processWorker!.Records?.SingleOrDefault(x => x.Code == "Year")?.Desc1!);
|
isNew = true;
|
||||||
var month = int.Parse(processWorker!.Records?.SingleOrDefault(x => x.Code == "Month")?.Desc1!);
|
processedLayer = new Layer
|
||||||
var sources = processWorker.Records?.Where(x => x.Code == "Source").ToList();
|
|
||||||
if (!sources!.Any())
|
|
||||||
{
|
{
|
||||||
throw new Exception("Source record not found");
|
Id = Guid.NewGuid(),
|
||||||
}
|
Type = LayerType.Processed,
|
||||||
var codes = processWorker.Records?.SingleOrDefault(x => x.Code == "Codes")?.Desc1;
|
ParentId = processWorker.Id,
|
||||||
if (codes == null)
|
Number = _db.Layers.Count() + 1
|
||||||
|
};
|
||||||
|
processedLayer.Name = $"L{processedLayer.Number}-P-{year}/{month}-AB-T3";
|
||||||
|
processedLayer.CreatedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D");
|
||||||
|
processedLayer.ModifiedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D");
|
||||||
|
processedLayer.CreatedAt = DateTime.UtcNow;
|
||||||
|
processedLayer.ModifiedAt = DateTime.UtcNow;
|
||||||
|
}
|
||||||
|
|
||||||
|
processedLayer.ModifiedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D");
|
||||||
|
processedLayer.ModifiedAt = DateTime.UtcNow;
|
||||||
|
|
||||||
|
var dataSources = sources!.Select(source => _db.Layers.Where(x => x.Type == LayerType.Processed && !x.IsDeleted && x.Name != null && x.Name.Contains($"{year}/{month}-{source.Desc1}-T3"))
|
||||||
|
.Include(x => x.Records)
|
||||||
|
.FirstOrDefault())
|
||||||
|
.OfType<Layer>()
|
||||||
|
.ToList();
|
||||||
|
if (dataSources.Count == 0)
|
||||||
|
{
|
||||||
|
throw new Exception("DataSources are empty");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
var newRecords = dataSources
|
||||||
|
.SelectMany(x => x.Records!)
|
||||||
|
.Where(x => codesList.Contains(int.Parse(x.Code!)))
|
||||||
|
.Select(x =>
|
||||||
{
|
{
|
||||||
throw new Exception("Codes record not found");
|
var newRecord = new Record
|
||||||
}
|
|
||||||
|
|
||||||
var codesList = ProcessHelper.ParseCodes(codes);
|
|
||||||
|
|
||||||
var processedLayer = db.Layers
|
|
||||||
.Where(x => x.ParentId == processWorker!.Id
|
|
||||||
&& !x.IsDeleted)
|
|
||||||
.OrderByDescending(x => x.CreatedAt)
|
|
||||||
.FirstOrDefault();
|
|
||||||
|
|
||||||
var isNew = false;
|
|
||||||
if (processedLayer == null)
|
|
||||||
{
|
|
||||||
isNew = true;
|
|
||||||
processedLayer = new Layer
|
|
||||||
{
|
{
|
||||||
Id = Guid.NewGuid(),
|
Id = Guid.NewGuid(),
|
||||||
Source = "",
|
Code = x.Code,
|
||||||
Type = LayerType.processed,
|
CreatedAt = DateTime.UtcNow,
|
||||||
ParentId = processWorker!.Id,
|
ModifiedAt = DateTime.UtcNow
|
||||||
Number = db.Layers.Count() + 1
|
|
||||||
};
|
};
|
||||||
processedLayer.Name = $"L{processedLayer.Number}-P-{year}/{month}-AB-T3";
|
for (var i = 1; i < 33; i++)
|
||||||
processedLayer.CreatedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D");
|
|
||||||
processedLayer.ModifiedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D");
|
|
||||||
processedLayer.CreatedAt = DateTime.UtcNow;
|
|
||||||
processedLayer.ModifiedAt = DateTime.UtcNow;
|
|
||||||
}
|
|
||||||
processedLayer.Sources = new List<ProcessSource>();
|
|
||||||
processedLayer.ModifiedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D");
|
|
||||||
processedLayer.ModifiedAt = DateTime.UtcNow;
|
|
||||||
|
|
||||||
var dataSources = sources!.Select(source => db.Layers.Where(x => x.Type == LayerType.processed && !x.IsDeleted && x.Name != null && x.Name.Contains($"{year}/{month}-{source.Desc1}-T3"))
|
|
||||||
.Include(x => x.Records)
|
|
||||||
.FirstOrDefault())
|
|
||||||
.OfType<Layer>()
|
|
||||||
.ToList();
|
|
||||||
if (dataSources.Count == 0)
|
|
||||||
{
|
|
||||||
throw new Exception($"DataSources are empty");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
var newRecords = dataSources
|
|
||||||
.SelectMany(x => x.Records!)
|
|
||||||
.Where(x => codesList.Contains(int.Parse(x.Code!)))
|
|
||||||
.Select(x =>
|
|
||||||
{
|
{
|
||||||
var newRecord = new Record
|
ProcessHelper.SetValue(newRecord, i, ProcessHelper.GetValue(x, i));
|
||||||
{
|
}
|
||||||
Id = Guid.NewGuid(),
|
return newRecord;
|
||||||
Code = x.Code,
|
})
|
||||||
CreatedAt = DateTime.UtcNow,
|
.ToList();
|
||||||
ModifiedAt = DateTime.UtcNow
|
if (isNew)
|
||||||
};
|
{
|
||||||
for (var i = 1; i < 33; i++)
|
_db.Layers.Add(processedLayer);
|
||||||
{
|
|
||||||
ProcessHelper.SetValue(newRecord, i, ProcessHelper.GetValue(x, i));
|
|
||||||
}
|
|
||||||
return newRecord;
|
|
||||||
})
|
|
||||||
.ToList();
|
|
||||||
if (isNew)
|
|
||||||
{
|
|
||||||
db.Layers.Add(processedLayer);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
db.Layers.Update(processedLayer);
|
|
||||||
}
|
|
||||||
controller.SaveRecords(processedLayer.Id, newRecords, Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"));
|
|
||||||
db.SaveChanges();
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_db.Layers.Update(processedLayer);
|
||||||
|
}
|
||||||
|
_controller.SaveRecords(processedLayer.Id, newRecords, Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"));
|
||||||
|
_db.SaveChanges();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,116 +1,109 @@
|
|||||||
using DiunaBIWebAPI.dataProcessors;
|
using DiunaBIWebAPI.dataProcessors;
|
||||||
using Google.Apis.Sheets.v4;
|
|
||||||
using Google.Apis.Sheets.v4.Data;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using WebAPI.Controllers;
|
using WebAPI.Controllers;
|
||||||
using WebAPI.Models;
|
using WebAPI.Models;
|
||||||
|
|
||||||
namespace WebAPI.dataProcessors
|
namespace WebAPI.dataProcessors;
|
||||||
|
|
||||||
|
public class T3MultiSourceCopySelectedCodesYearSummaryProcessor
|
||||||
{
|
{
|
||||||
public class T3MultiSourceCopySelectedCodesYearSummaryProcessor
|
private readonly AppDbContext _db;
|
||||||
|
private readonly LayersController _controller;
|
||||||
|
|
||||||
|
public T3MultiSourceCopySelectedCodesYearSummaryProcessor(
|
||||||
|
AppDbContext db,
|
||||||
|
LayersController controller)
|
||||||
{
|
{
|
||||||
private readonly AppDbContext db;
|
_db = db;
|
||||||
private readonly SpreadsheetsResource.ValuesResource googleSheetValues;
|
_controller = controller;
|
||||||
private readonly LayersController controller;
|
|
||||||
|
|
||||||
public T3MultiSourceCopySelectedCodesYearSummaryProcessor(
|
|
||||||
AppDbContext _db,
|
|
||||||
SpreadsheetsResource.ValuesResource _googleSheetValues,
|
|
||||||
LayersController _controller)
|
|
||||||
{
|
|
||||||
db = _db;
|
|
||||||
googleSheetValues = _googleSheetValues;
|
|
||||||
controller = _controller;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void process(Layer processWorker)
|
|
||||||
{
|
|
||||||
int year = int.Parse(processWorker!.Records?.SingleOrDefault(x => x.Code == "Year")?.Desc1!);
|
|
||||||
|
|
||||||
Layer? processedLayer = db.Layers
|
|
||||||
.Where(x => x.ParentId == processWorker!.Id
|
|
||||||
&& !x.IsDeleted)
|
|
||||||
.OrderByDescending(x => x.CreatedAt)
|
|
||||||
.FirstOrDefault();
|
|
||||||
|
|
||||||
bool isNew = false;
|
|
||||||
if (processedLayer == null)
|
|
||||||
{
|
|
||||||
isNew = true;
|
|
||||||
processedLayer = new Layer
|
|
||||||
{
|
|
||||||
Id = Guid.NewGuid(),
|
|
||||||
Source = "",
|
|
||||||
Type = LayerType.processed,
|
|
||||||
ParentId = processWorker!.Id,
|
|
||||||
Number = db.Layers.Count() + 1,
|
|
||||||
};
|
|
||||||
processedLayer.Name = $"L{processedLayer.Number}-P-{year}/13-AB-T3";
|
|
||||||
processedLayer.CreatedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D");
|
|
||||||
processedLayer.ModifiedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D");
|
|
||||||
processedLayer.CreatedAt = DateTime.UtcNow;
|
|
||||||
processedLayer.ModifiedAt = DateTime.UtcNow;
|
|
||||||
}
|
|
||||||
|
|
||||||
processedLayer.Sources = new List<ProcessSource>();
|
|
||||||
processedLayer.ModifiedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D");
|
|
||||||
processedLayer.ModifiedAt = DateTime.UtcNow;
|
|
||||||
|
|
||||||
List<Record> newRecords = new List<Record>();
|
|
||||||
|
|
||||||
List<Layer> dataSources = new List<Layer>();
|
|
||||||
|
|
||||||
for (int i = 1; i < 13; i++)
|
|
||||||
{
|
|
||||||
Layer? dataSource = db.Layers.Where(x =>
|
|
||||||
x.Type == LayerType.processed
|
|
||||||
&& !x.IsDeleted
|
|
||||||
&& x.Name != null && x.Name.Contains($"{year}/{i}-AB-T3"))
|
|
||||||
.Include(x => x.Records)
|
|
||||||
.FirstOrDefault();
|
|
||||||
if (dataSource != null)
|
|
||||||
{
|
|
||||||
dataSources.Add(dataSource!);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dataSources.Count == 0)
|
|
||||||
{
|
|
||||||
throw new Exception("DataSources are empty");
|
|
||||||
}
|
|
||||||
|
|
||||||
List<Record> allRecords = dataSources.SelectMany(x => x.Records!).ToList();
|
|
||||||
|
|
||||||
foreach (Record baseRecord in dataSources.Last()?.Records!)
|
|
||||||
{
|
|
||||||
List<Record> codeRecords = allRecords.Where(x => x.Code == baseRecord.Code).ToList();
|
|
||||||
Record processedRecord = new Record
|
|
||||||
{
|
|
||||||
Id = Guid.NewGuid(),
|
|
||||||
Code = baseRecord.Code,
|
|
||||||
CreatedAt = DateTime.UtcNow,
|
|
||||||
ModifiedAt = DateTime.UtcNow
|
|
||||||
};
|
|
||||||
for (var i = 1; i < 33; i++)
|
|
||||||
{
|
|
||||||
ProcessHelper.SetValue(processedRecord, i,
|
|
||||||
codeRecords.Sum(x => ProcessHelper.GetValue(x, i)));
|
|
||||||
}
|
|
||||||
|
|
||||||
newRecords.Add(processedRecord);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isNew)
|
|
||||||
{
|
|
||||||
db.Layers.Add(processedLayer);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
db.Layers.Update(processedLayer);
|
|
||||||
}
|
|
||||||
|
|
||||||
controller.SaveRecords(processedLayer.Id, newRecords, Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"));
|
|
||||||
db.SaveChanges();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
public void Process(Layer processWorker)
|
||||||
|
{
|
||||||
|
var year = int.Parse(processWorker.Records?.SingleOrDefault(x => x.Code == "Year")?.Desc1!);
|
||||||
|
|
||||||
|
var processedLayer = _db.Layers
|
||||||
|
.Where(x => x.ParentId == processWorker.Id
|
||||||
|
&& !x.IsDeleted)
|
||||||
|
.OrderByDescending(x => x.CreatedAt)
|
||||||
|
.FirstOrDefault();
|
||||||
|
|
||||||
|
var isNew = false;
|
||||||
|
if (processedLayer == null)
|
||||||
|
{
|
||||||
|
isNew = true;
|
||||||
|
processedLayer = new Layer
|
||||||
|
{
|
||||||
|
Id = Guid.NewGuid(),
|
||||||
|
Type = LayerType.Processed,
|
||||||
|
ParentId = processWorker.Id,
|
||||||
|
Number = _db.Layers.Count() + 1
|
||||||
|
};
|
||||||
|
processedLayer.Name = $"L{processedLayer.Number}-P-{year}/13-AB-T3";
|
||||||
|
processedLayer.CreatedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D");
|
||||||
|
processedLayer.ModifiedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D");
|
||||||
|
processedLayer.CreatedAt = DateTime.UtcNow;
|
||||||
|
processedLayer.ModifiedAt = DateTime.UtcNow;
|
||||||
|
}
|
||||||
|
|
||||||
|
processedLayer.ModifiedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D");
|
||||||
|
processedLayer.ModifiedAt = DateTime.UtcNow;
|
||||||
|
|
||||||
|
var newRecords = new List<Record>();
|
||||||
|
|
||||||
|
var dataSources = new List<Layer>();
|
||||||
|
|
||||||
|
for (var i = 1; i < 13; i++)
|
||||||
|
{
|
||||||
|
var i1 = i;
|
||||||
|
var dataSource = _db.Layers.Where(x =>
|
||||||
|
x.Type == LayerType.Processed
|
||||||
|
&& !x.IsDeleted
|
||||||
|
&& x.Name != null && x.Name.Contains($"{year}/{i1}-AB-T3"))
|
||||||
|
.Include(x => x.Records)
|
||||||
|
.FirstOrDefault();
|
||||||
|
if (dataSource != null)
|
||||||
|
{
|
||||||
|
dataSources.Add(dataSource);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dataSources.Count == 0)
|
||||||
|
{
|
||||||
|
throw new Exception("DataSources are empty");
|
||||||
|
}
|
||||||
|
|
||||||
|
var allRecords = dataSources.SelectMany(x => x.Records!).ToList();
|
||||||
|
|
||||||
|
foreach (var baseRecord in dataSources.Last().Records!)
|
||||||
|
{
|
||||||
|
var codeRecords = allRecords.Where(x => x.Code == baseRecord.Code).ToList();
|
||||||
|
var processedRecord = new Record
|
||||||
|
{
|
||||||
|
Id = Guid.NewGuid(),
|
||||||
|
Code = baseRecord.Code,
|
||||||
|
CreatedAt = DateTime.UtcNow,
|
||||||
|
ModifiedAt = DateTime.UtcNow
|
||||||
|
};
|
||||||
|
for (var i = 1; i < 33; i++)
|
||||||
|
{
|
||||||
|
ProcessHelper.SetValue(processedRecord, i,
|
||||||
|
codeRecords.Sum(x => ProcessHelper.GetValue(x, i)));
|
||||||
|
}
|
||||||
|
|
||||||
|
newRecords.Add(processedRecord);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isNew)
|
||||||
|
{
|
||||||
|
_db.Layers.Add(processedLayer);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_db.Layers.Update(processedLayer);
|
||||||
|
}
|
||||||
|
|
||||||
|
_controller.SaveRecords(processedLayer.Id, newRecords, Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"));
|
||||||
|
_db.SaveChanges();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,192 +1,175 @@
|
|||||||
using DiunaBIWebAPI.dataProcessors;
|
using DiunaBIWebAPI.dataProcessors;
|
||||||
using Google.Apis.Sheets.v4;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using WebAPI.Calculator;
|
using WebAPI.Calculator;
|
||||||
using WebAPI.Controllers;
|
using WebAPI.Controllers;
|
||||||
using WebAPI.Models;
|
using WebAPI.Models;
|
||||||
|
|
||||||
namespace WebAPI.dataProcessors
|
namespace WebAPI.dataProcessors;
|
||||||
{
|
|
||||||
public class T3MultiSourceSummaryProcessor
|
|
||||||
{
|
|
||||||
private readonly AppDbContext db;
|
|
||||||
private readonly SpreadsheetsResource.ValuesResource googleSheetValues;
|
|
||||||
private readonly LayersController controller;
|
|
||||||
private readonly LogsController logsController;
|
|
||||||
|
|
||||||
public T3MultiSourceSummaryProcessor(
|
public class T3MultiSourceSummaryProcessor
|
||||||
AppDbContext _db,
|
{
|
||||||
SpreadsheetsResource.ValuesResource _googleSheetValues,
|
private readonly AppDbContext _db;
|
||||||
LayersController _controller,
|
private readonly LayersController _controller;
|
||||||
LogsController _logsController)
|
private readonly LogsController _logsController;
|
||||||
|
|
||||||
|
public T3MultiSourceSummaryProcessor(
|
||||||
|
AppDbContext db,
|
||||||
|
LayersController controller,
|
||||||
|
LogsController logsController)
|
||||||
|
{
|
||||||
|
_db = db;
|
||||||
|
_controller = controller;
|
||||||
|
_logsController = logsController;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Process(Layer processWorker)
|
||||||
|
{
|
||||||
|
var year = int.Parse(processWorker.Records?.SingleOrDefault(x => x.Code == "Year")?.Desc1!);
|
||||||
|
var month = int.Parse(processWorker.Records?.SingleOrDefault(x => x.Code == "Month")?.Desc1!);
|
||||||
|
var sources = processWorker.Records?.Where(x => x.Code == "Source").ToList();
|
||||||
|
if (!sources!.Any())
|
||||||
{
|
{
|
||||||
db = _db;
|
throw new Exception("Source record not found");
|
||||||
googleSheetValues = _googleSheetValues;
|
|
||||||
controller = _controller;
|
|
||||||
logsController = _logsController;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void process(Layer processWorker)
|
var processedLayer = _db.Layers
|
||||||
|
.Where(x => x.ParentId == processWorker.Id
|
||||||
|
&& !x.IsDeleted)
|
||||||
|
.OrderByDescending(x => x.CreatedAt)
|
||||||
|
.FirstOrDefault();
|
||||||
|
|
||||||
|
var isNew = false;
|
||||||
|
if (processedLayer == null)
|
||||||
{
|
{
|
||||||
int year = int.Parse(processWorker!.Records?.SingleOrDefault(x => x.Code == "Year")?.Desc1!);
|
isNew = true;
|
||||||
int month = int.Parse(processWorker!.Records?.SingleOrDefault(x => x.Code == "Month")?.Desc1!);
|
processedLayer = new Layer
|
||||||
List<Record>? sources = processWorker.Records?.Where(x => x.Code == "Source").ToList();
|
|
||||||
if (sources!.Count() == 0)
|
|
||||||
{
|
{
|
||||||
throw new Exception("Source record not found");
|
Id = Guid.NewGuid(),
|
||||||
}
|
Type = LayerType.Processed,
|
||||||
|
ParentId = processWorker.Id,
|
||||||
Layer? processedLayer = db.Layers
|
Number = _db.Layers.Count() + 1
|
||||||
.Where(x => x.ParentId == processWorker!.Id
|
};
|
||||||
&& !x.IsDeleted)
|
processedLayer.Name = $"L{processedLayer.Number}-P-{year}/{month}-AA-T3";
|
||||||
.OrderByDescending(x => x.CreatedAt)
|
processedLayer.CreatedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D");
|
||||||
.FirstOrDefault();
|
|
||||||
|
|
||||||
bool isNew = false;
|
|
||||||
if (processedLayer == null)
|
|
||||||
{
|
|
||||||
isNew = true;
|
|
||||||
processedLayer = new Layer
|
|
||||||
{
|
|
||||||
Id = Guid.NewGuid(),
|
|
||||||
Source = "",
|
|
||||||
Type = LayerType.processed,
|
|
||||||
ParentId = processWorker!.Id,
|
|
||||||
Number = db.Layers.Count() + 1,
|
|
||||||
};
|
|
||||||
processedLayer.Name = $"L{processedLayer.Number}-P-{year}/{month}-AA-T3";
|
|
||||||
processedLayer.CreatedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D");
|
|
||||||
processedLayer.ModifiedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D");
|
|
||||||
processedLayer.CreatedAt = DateTime.UtcNow;
|
|
||||||
processedLayer.ModifiedAt = DateTime.UtcNow;
|
|
||||||
}
|
|
||||||
processedLayer.Sources = new List<ProcessSource>();
|
|
||||||
processedLayer.ModifiedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D");
|
processedLayer.ModifiedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D");
|
||||||
|
processedLayer.CreatedAt = DateTime.UtcNow;
|
||||||
processedLayer.ModifiedAt = DateTime.UtcNow;
|
processedLayer.ModifiedAt = DateTime.UtcNow;
|
||||||
|
}
|
||||||
|
|
||||||
List<Record> newRecords = new List<Record>();
|
processedLayer.ModifiedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D");
|
||||||
|
processedLayer.ModifiedAt = DateTime.UtcNow;
|
||||||
|
|
||||||
List<Layer> dataSources = new List<Layer>();
|
var newRecords = new List<Record>();
|
||||||
|
|
||||||
foreach (Record source in sources!)
|
var dataSources = sources!.Select(source => _db.Layers.Where(x => x.Type == LayerType.Processed && !x.IsDeleted && x.Name != null && x.Name.Contains($"{year}/{month}-{source.Desc1}-T3"))
|
||||||
{
|
.Include(x => x.Records)
|
||||||
Layer? dataSource = db.Layers.Where(x =>
|
.FirstOrDefault())
|
||||||
x.Type == LayerType.processed &&
|
.OfType<Layer>()
|
||||||
!x.IsDeleted &&
|
.ToList();
|
||||||
x.Name!=null && x.Name.Contains($"{year}/{month}-{source.Desc1}-T3")
|
|
||||||
)
|
|
||||||
.Include(x => x.Records)
|
|
||||||
.FirstOrDefault();
|
|
||||||
if (dataSource != null)
|
|
||||||
{
|
|
||||||
dataSources.Add(dataSource);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dataSources.Count == 0)
|
if (dataSources.Count == 0)
|
||||||
{
|
{
|
||||||
throw new Exception($"DataSources are empty");
|
throw new Exception("DataSources are empty");
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Record> allRecords = dataSources.SelectMany(x => x.Records!).ToList();
|
var allRecords = dataSources.SelectMany(x => x.Records!).ToList();
|
||||||
List<string> baseCodess = allRecords.Select(x => x.Code!.Remove(0, 1)).Distinct().ToList();
|
var baseCodes = allRecords.Select(x => x.Code!.Remove(0, 1)).Distinct().ToList();
|
||||||
|
|
||||||
foreach (string baseCode in baseCodess)
|
foreach (var baseCode in baseCodes)
|
||||||
{
|
{
|
||||||
|
|
||||||
List<Record> codeRecords = allRecords.Where(x =>
|
var codeRecords = allRecords.Where(x =>
|
||||||
x.Code!.Substring(1) == baseCode)
|
x.Code![1..] == baseCode)
|
||||||
.ToList();
|
.ToList();
|
||||||
Record processedRecord = new Record
|
var processedRecord = new Record
|
||||||
{
|
|
||||||
Id = Guid.NewGuid(),
|
|
||||||
Code = $"9{baseCode}",
|
|
||||||
CreatedAt = DateTime.UtcNow,
|
|
||||||
ModifiedAt = DateTime.UtcNow
|
|
||||||
};
|
|
||||||
for (var i = 1; i<33; i++)
|
|
||||||
{
|
|
||||||
ProcessHelper.SetValue(processedRecord, i,
|
|
||||||
codeRecords.Sum(x => ProcessHelper.GetValue(x, i)));
|
|
||||||
}
|
|
||||||
newRecords.Add(processedRecord);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Dynamic Codes
|
|
||||||
List<Record>? dynamicCodes = processWorker.Records?.Where(x => x.Code == "DynamicCode").ToList();
|
|
||||||
if (dynamicCodes != null && dynamicCodes.Any())
|
|
||||||
{
|
{
|
||||||
foreach (Record dynamicCode in dynamicCodes)
|
Id = Guid.NewGuid(),
|
||||||
|
Code = $"9{baseCode}",
|
||||||
|
CreatedAt = DateTime.UtcNow,
|
||||||
|
ModifiedAt = DateTime.UtcNow
|
||||||
|
};
|
||||||
|
for (var i = 1; i<33; i++)
|
||||||
|
{
|
||||||
|
ProcessHelper.SetValue(processedRecord, i,
|
||||||
|
codeRecords.Sum(x => ProcessHelper.GetValue(x, i)));
|
||||||
|
}
|
||||||
|
newRecords.Add(processedRecord);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dynamic Codes
|
||||||
|
var dynamicCodes = processWorker.Records?.Where(x => x.Code == "DynamicCode").ToList();
|
||||||
|
if (dynamicCodes != null && dynamicCodes.Any())
|
||||||
|
{
|
||||||
|
foreach (var dynamicCode in dynamicCodes)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
|
if (dynamicCode.Desc1 == null)
|
||||||
|
{
|
||||||
|
_logsController.AddEntry(new LogEntry
|
||||||
|
{
|
||||||
|
Title = $"{processWorker.Name}, {processWorker.Id}",
|
||||||
|
Type = LogEntryType.Warning,
|
||||||
|
LogType = LogType.Process,
|
||||||
|
Message = $"Formula in Record {dynamicCode.Id} is missing.",
|
||||||
|
CreatedAt = DateTime.UtcNow
|
||||||
|
});
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
var calc = new BaseCalc(dynamicCode.Desc1);
|
||||||
|
if (!calc.IsFormulaCorrect())
|
||||||
|
{
|
||||||
|
_logsController.AddEntry(new LogEntry
|
||||||
|
{
|
||||||
|
Title = $"{processWorker.Name}, {processWorker.Id}",
|
||||||
|
Type = LogEntryType.Warning,
|
||||||
|
LogType = LogType.Process,
|
||||||
|
Message = $"Formula {calc.Expression} in Record {dynamicCode.Id} is not correct",
|
||||||
|
CreatedAt = DateTime.UtcNow
|
||||||
|
});
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (dynamicCode.Desc1 == null)
|
newRecords.Add(calc.CalculateT3(newRecords));
|
||||||
{
|
|
||||||
logsController.AddEntry(new LogEntry
|
|
||||||
{
|
|
||||||
Title = $"{processWorker!.Name}, {processWorker.Id}",
|
|
||||||
Type = LogEntryType.warning,
|
|
||||||
LogType = LogType.process,
|
|
||||||
Message = $"Formula in Record {dynamicCode.Id} is missing.",
|
|
||||||
CreatedAt = DateTime.UtcNow
|
|
||||||
});
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
BaseCalc calc = new BaseCalc(dynamicCode.Desc1);
|
|
||||||
if (!calc.IsFormulaCorrect())
|
|
||||||
{
|
|
||||||
logsController.AddEntry(new LogEntry
|
|
||||||
{
|
|
||||||
Title = $"{processWorker!.Name}, {processWorker.Id}",
|
|
||||||
Type = LogEntryType.warning,
|
|
||||||
LogType = LogType.process,
|
|
||||||
Message = $"Formula {calc.Expression} in Record {dynamicCode.Id} is not correct",
|
|
||||||
CreatedAt = DateTime.UtcNow
|
|
||||||
});
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
newRecords.Add(calc.CalculateT3(newRecords));
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
logsController.AddEntry(new LogEntry
|
|
||||||
{
|
|
||||||
Title = $"{processWorker!.Name}, {processWorker.Id}",
|
|
||||||
Type = LogEntryType.warning,
|
|
||||||
LogType = LogType.process,
|
|
||||||
Message = $"Formula {calc.Expression} in Record {dynamicCode.Id} error: {e.Message}",
|
|
||||||
CreatedAt = DateTime.UtcNow
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
logsController.AddEntry(new LogEntry
|
_logsController.AddEntry(new LogEntry
|
||||||
{
|
{
|
||||||
Title = $"{processWorker!.Name}, {processWorker.Id}",
|
Title = $"{processWorker.Name}, {processWorker.Id}",
|
||||||
Type = LogEntryType.warning,
|
Type = LogEntryType.Warning,
|
||||||
LogType = LogType.process,
|
LogType = LogType.Process,
|
||||||
Message = $"Calculation error {dynamicCode.Id}: {e.Message} ",
|
Message = $"Formula {calc.Expression} in Record {dynamicCode.Id} error: {e.Message}",
|
||||||
CreatedAt = DateTime.UtcNow
|
CreatedAt = DateTime.UtcNow
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_logsController.AddEntry(new LogEntry
|
||||||
|
{
|
||||||
|
Title = $"{processWorker.Name}, {processWorker.Id}",
|
||||||
|
Type = LogEntryType.Warning,
|
||||||
|
LogType = LogType.Process,
|
||||||
|
Message = $"Calculation error {dynamicCode.Id}: {e.Message} ",
|
||||||
|
CreatedAt = DateTime.UtcNow
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (isNew)
|
|
||||||
{
|
|
||||||
db.Layers.Add(processedLayer);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
db.Layers.Update(processedLayer);
|
|
||||||
}
|
|
||||||
controller.SaveRecords(processedLayer.Id, newRecords, Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"));
|
|
||||||
db.SaveChanges();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (isNew)
|
||||||
|
{
|
||||||
|
_db.Layers.Add(processedLayer);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_db.Layers.Update(processedLayer);
|
||||||
|
}
|
||||||
|
_controller.SaveRecords(processedLayer.Id, newRecords, Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"));
|
||||||
|
_db.SaveChanges();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,226 +1,195 @@
|
|||||||
using DiunaBIWebAPI.dataProcessors;
|
using DiunaBIWebAPI.dataProcessors;
|
||||||
using Google.Apis.Sheets.v4;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using WebAPI.Calculator;
|
using WebAPI.Calculator;
|
||||||
using WebAPI.Controllers;
|
using WebAPI.Controllers;
|
||||||
using WebAPI.Models;
|
using WebAPI.Models;
|
||||||
|
|
||||||
namespace WebAPI.dataProcessors
|
namespace WebAPI.dataProcessors;
|
||||||
{
|
|
||||||
public class T3MultiSourceYearSummaryProcessor
|
|
||||||
{
|
|
||||||
private readonly AppDbContext db;
|
|
||||||
private readonly SpreadsheetsResource.ValuesResource googleSheetValues;
|
|
||||||
private readonly LayersController controller;
|
|
||||||
private readonly LogsController logsController;
|
|
||||||
|
|
||||||
public T3MultiSourceYearSummaryProcessor(
|
public class T3MultiSourceYearSummaryProcessor
|
||||||
AppDbContext _db,
|
{
|
||||||
SpreadsheetsResource.ValuesResource _googleSheetValues,
|
private readonly AppDbContext _db;
|
||||||
LayersController _controller,
|
private readonly LayersController _controller;
|
||||||
LogsController _logsController)
|
private readonly LogsController _logsController;
|
||||||
|
|
||||||
|
public T3MultiSourceYearSummaryProcessor(
|
||||||
|
AppDbContext db,
|
||||||
|
LayersController controller,
|
||||||
|
LogsController logsController)
|
||||||
|
{
|
||||||
|
_db = db;
|
||||||
|
_controller = controller;
|
||||||
|
_logsController = logsController;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Process(Layer processWorker)
|
||||||
|
{
|
||||||
|
var year = int.Parse(processWorker.Records?.SingleOrDefault(x => x.Code == "Year")?.Desc1!);
|
||||||
|
var sources = processWorker.Records?.Where(x => x.Code == "Source").ToList();
|
||||||
|
if (!sources!.Any())
|
||||||
{
|
{
|
||||||
db = _db;
|
throw new Exception("Source record not found");
|
||||||
googleSheetValues = _googleSheetValues;
|
|
||||||
controller = _controller;
|
|
||||||
logsController = _logsController;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void process(Layer processWorker)
|
var processedLayer = _db.Layers
|
||||||
|
.Where(x => x.ParentId == processWorker.Id
|
||||||
|
&& !x.IsDeleted)
|
||||||
|
.OrderByDescending(x => x.CreatedAt)
|
||||||
|
.FirstOrDefault();
|
||||||
|
|
||||||
|
var isNew = false;
|
||||||
|
if (processedLayer == null)
|
||||||
{
|
{
|
||||||
int year = int.Parse(processWorker!.Records?.SingleOrDefault(x => x.Code == "Year")?.Desc1!);
|
isNew = true;
|
||||||
List<Record>? sources = processWorker.Records?.Where(x => x.Code == "Source").ToList();
|
processedLayer = new Layer
|
||||||
if (sources!.Count() == 0)
|
|
||||||
{
|
{
|
||||||
throw new Exception("Source record not found");
|
Id = Guid.NewGuid(),
|
||||||
}
|
Type = LayerType.Processed,
|
||||||
|
ParentId = processWorker.Id,
|
||||||
Layer? processedLayer = db.Layers
|
Number = _db.Layers.Count() + 1
|
||||||
.Where(x => x.ParentId == processWorker!.Id
|
};
|
||||||
&& !x.IsDeleted)
|
processedLayer.Name = $"L{processedLayer.Number}-P-{year}/13-AA-T3";
|
||||||
.OrderByDescending(x => x.CreatedAt)
|
processedLayer.CreatedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D");
|
||||||
.FirstOrDefault();
|
|
||||||
|
|
||||||
bool isNew = false;
|
|
||||||
if (processedLayer == null)
|
|
||||||
{
|
|
||||||
isNew = true;
|
|
||||||
processedLayer = new Layer
|
|
||||||
{
|
|
||||||
Id = Guid.NewGuid(),
|
|
||||||
Source = "",
|
|
||||||
Type = LayerType.processed,
|
|
||||||
ParentId = processWorker!.Id,
|
|
||||||
Number = db.Layers.Count() + 1,
|
|
||||||
};
|
|
||||||
processedLayer.Name = $"L{processedLayer.Number}-P-{year}/13-AA-T3";
|
|
||||||
processedLayer.CreatedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D");
|
|
||||||
processedLayer.ModifiedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D");
|
|
||||||
processedLayer.CreatedAt = DateTime.UtcNow;
|
|
||||||
processedLayer.ModifiedAt = DateTime.UtcNow;
|
|
||||||
}
|
|
||||||
processedLayer.Sources = new List<ProcessSource>();
|
|
||||||
processedLayer.ModifiedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D");
|
processedLayer.ModifiedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D");
|
||||||
|
processedLayer.CreatedAt = DateTime.UtcNow;
|
||||||
processedLayer.ModifiedAt = DateTime.UtcNow;
|
processedLayer.ModifiedAt = DateTime.UtcNow;
|
||||||
|
}
|
||||||
|
|
||||||
List<Record> newRecords = new List<Record>();
|
processedLayer.ModifiedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D");
|
||||||
|
processedLayer.ModifiedAt = DateTime.UtcNow;
|
||||||
|
|
||||||
List<Layer> dataSources = new List<Layer>();
|
var newRecords = new List<Record>();
|
||||||
foreach (Record source in sources!)
|
|
||||||
{
|
|
||||||
Layer? dataSource = db.Layers.Where(x =>
|
|
||||||
x.Type == LayerType.processed &&
|
|
||||||
!x.IsDeleted &&
|
|
||||||
x.Name != null && x.Name.Contains($"{year}/13-{source.Desc1}-T3")
|
|
||||||
)
|
|
||||||
.Include(x => x.Records)
|
|
||||||
.FirstOrDefault();
|
|
||||||
if (dataSource != null)
|
|
||||||
{
|
|
||||||
dataSources.Add(dataSource);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (dataSources.Count == 0)
|
|
||||||
{
|
|
||||||
throw new Exception($"DataSources are empty");
|
|
||||||
}
|
|
||||||
|
|
||||||
List<Layer> dataSourcesValidation = new List<Layer>();
|
var dataSources = sources!.Select(source => _db.Layers.Where(x => x.Type == LayerType.Processed && !x.IsDeleted && x.Name != null && x.Name.Contains($"{year}/13-{source.Desc1}-T3"))
|
||||||
for (int i = 1; i < 13; i++)
|
.Include(x => x.Records)
|
||||||
{
|
.FirstOrDefault())
|
||||||
Layer? dataSource = db.Layers.Where(x =>
|
.OfType<Layer>()
|
||||||
x.Type == LayerType.processed
|
.ToList();
|
||||||
&& !x.IsDeleted
|
if (dataSources.Count == 0)
|
||||||
&& x.Name!=null && x.Name.Contains($"{year}/{i}-AA-T3"))
|
{
|
||||||
.Include(x => x.Records)
|
throw new Exception("DataSources are empty");
|
||||||
.FirstOrDefault();
|
}
|
||||||
if (dataSource != null)
|
|
||||||
{
|
if (dataSources.Count == 0)
|
||||||
dataSourcesValidation.Add(dataSource!);
|
{
|
||||||
}
|
throw new Exception("DataSourcesValidation are empty");
|
||||||
}
|
}
|
||||||
if (dataSources.Count == 0)
|
|
||||||
{
|
var allRecords = dataSources
|
||||||
throw new Exception($"DataSourcesValidation are empty");
|
.SelectMany(x => x.Records!).ToList();
|
||||||
}
|
var baseCodes = allRecords.Select(x => x.Code!.Remove(0, 1)).Distinct().ToList();
|
||||||
|
|
||||||
|
|
||||||
List<Record> allRecords = dataSources
|
|
||||||
.SelectMany(x => x.Records!).ToList();
|
|
||||||
List<string> baseCodess = allRecords.Select(x => x.Code!.Remove(0, 1)).Distinct().ToList();
|
|
||||||
|
|
||||||
foreach (string baseCode in baseCodess)
|
foreach (var baseCode in baseCodes)
|
||||||
|
{
|
||||||
|
|
||||||
|
var codeRecords = allRecords.Where(x =>
|
||||||
|
x.Code![1..] == baseCode)
|
||||||
|
.ToList();
|
||||||
|
var codeRecordsValidation = allRecords.Where(x =>
|
||||||
|
x.Code![1..] == baseCode)
|
||||||
|
.ToList();
|
||||||
|
var processedRecord = new Record
|
||||||
{
|
{
|
||||||
|
Id = Guid.NewGuid(),
|
||||||
|
Code = $"9{baseCode}",
|
||||||
|
CreatedAt = DateTime.UtcNow,
|
||||||
|
ModifiedAt = DateTime.UtcNow
|
||||||
|
};
|
||||||
|
var validationRecord = new Record();
|
||||||
|
for (var i = 1; i < 33; i++)
|
||||||
|
{
|
||||||
|
ProcessHelper.SetValue(processedRecord, i,
|
||||||
|
codeRecords.Sum(x => ProcessHelper.GetValue(x, i)));
|
||||||
|
|
||||||
List<Record> codeRecords = allRecords.Where(x =>
|
ProcessHelper.SetValue(validationRecord, i,
|
||||||
x.Code!.Substring(1) == baseCode)
|
codeRecordsValidation.Sum(x => ProcessHelper.GetValue(x, i)));
|
||||||
.ToList();
|
|
||||||
List<Record> codeRecordsValidation = allRecords.Where(x =>
|
if (
|
||||||
x.Code!.Substring(1) == baseCode)
|
double.Abs((double)(ProcessHelper.GetValue(processedRecord,i) -
|
||||||
.ToList();
|
ProcessHelper.GetValue(validationRecord, i))!) > 0.01)
|
||||||
Record processedRecord = new Record
|
|
||||||
{
|
{
|
||||||
Id = Guid.NewGuid(),
|
throw new Exception($"ValidationError: Code {baseCode}, " +
|
||||||
Code = $"9{baseCode}",
|
$"Value{i} ({ProcessHelper.GetValue(processedRecord, i)} | " +
|
||||||
CreatedAt = DateTime.UtcNow,
|
$"{ProcessHelper.GetValue(validationRecord, i)})");
|
||||||
ModifiedAt = DateTime.UtcNow
|
}
|
||||||
};
|
}
|
||||||
Record validationRecord = new Record();
|
newRecords.Add(processedRecord);
|
||||||
for (var i = 1; i < 33; i++)
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Dynamic Codes
|
||||||
|
var dynamicCodes = processWorker.Records?.Where(x => x.Code == "DynamicCode").ToList();
|
||||||
|
if (dynamicCodes != null && dynamicCodes.Any())
|
||||||
|
{
|
||||||
|
foreach (var dynamicCode in dynamicCodes)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
ProcessHelper.SetValue(processedRecord, i,
|
if (dynamicCode.Desc1 == null)
|
||||||
codeRecords.Sum(x => ProcessHelper.GetValue(x, i)));
|
|
||||||
|
|
||||||
ProcessHelper.SetValue(validationRecord, i,
|
|
||||||
codeRecordsValidation.Sum(x => ProcessHelper.GetValue(x, i)));
|
|
||||||
|
|
||||||
if (
|
|
||||||
ProcessHelper.GetValue(processedRecord,i) !=
|
|
||||||
ProcessHelper.GetValue(validationRecord, i))
|
|
||||||
{
|
{
|
||||||
throw new Exception($"ValidationError: Code {baseCode!}, " +
|
_logsController.AddEntry(new LogEntry
|
||||||
$"Value{i} ({ProcessHelper.GetValue(processedRecord, i)} | " +
|
{
|
||||||
$"{ProcessHelper.GetValue(validationRecord, i)})");
|
Title = $"{processWorker.Name}, {processWorker.Id}",
|
||||||
|
Type = LogEntryType.Warning,
|
||||||
|
LogType = LogType.Process,
|
||||||
|
Message = $"Formula in Record {dynamicCode.Id} is missing.",
|
||||||
|
CreatedAt = DateTime.UtcNow
|
||||||
|
});
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
}
|
var calc = new BaseCalc(dynamicCode.Desc1);
|
||||||
newRecords.Add(processedRecord);
|
if (!calc.IsFormulaCorrect())
|
||||||
}
|
{
|
||||||
|
_logsController.AddEntry(new LogEntry
|
||||||
|
{
|
||||||
|
Title = $"{processWorker.Name}, {processWorker.Id}",
|
||||||
// Dynamic Codes
|
Type = LogEntryType.Warning,
|
||||||
List<Record>? dynamicCodes = processWorker.Records?.Where(x => x.Code == "DynamicCode").ToList();
|
LogType = LogType.Process,
|
||||||
if (dynamicCodes != null && dynamicCodes.Any())
|
Message = $"Formula {calc.Expression} in Record {dynamicCode.Id} is not correct",
|
||||||
{
|
CreatedAt = DateTime.UtcNow
|
||||||
foreach (Record dynamicCode in dynamicCodes)
|
});
|
||||||
{
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (dynamicCode.Desc1 == null)
|
newRecords.Add(calc.CalculateT3(newRecords));
|
||||||
{
|
|
||||||
logsController.AddEntry(new LogEntry
|
|
||||||
{
|
|
||||||
Title = $"{processWorker!.Name}, {processWorker.Id}",
|
|
||||||
Type = LogEntryType.warning,
|
|
||||||
LogType = LogType.process,
|
|
||||||
Message = $"Formula in Record {dynamicCode.Id} is missing.",
|
|
||||||
CreatedAt = DateTime.UtcNow
|
|
||||||
});
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
BaseCalc calc = new BaseCalc(dynamicCode.Desc1);
|
|
||||||
if (!calc.IsFormulaCorrect())
|
|
||||||
{
|
|
||||||
logsController.AddEntry(new LogEntry
|
|
||||||
{
|
|
||||||
Title = $"{processWorker!.Name}, {processWorker.Id}",
|
|
||||||
Type = LogEntryType.warning,
|
|
||||||
LogType = LogType.process,
|
|
||||||
Message = $"Formula {calc.Expression} in Record {dynamicCode.Id} is not correct",
|
|
||||||
CreatedAt = DateTime.UtcNow
|
|
||||||
});
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
newRecords.Add(calc.CalculateT3(newRecords));
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
logsController.AddEntry(new LogEntry
|
|
||||||
{
|
|
||||||
Title = $"{processWorker!.Name}, {processWorker.Id}",
|
|
||||||
Type = LogEntryType.warning,
|
|
||||||
LogType = LogType.process,
|
|
||||||
Message = $"Formula {calc.Expression} in Record {dynamicCode.Id} error: {e.Message}",
|
|
||||||
CreatedAt = DateTime.UtcNow
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
logsController.AddEntry(new LogEntry
|
_logsController.AddEntry(new LogEntry
|
||||||
{
|
{
|
||||||
Title = $"{processWorker!.Name}, {processWorker.Id}",
|
Title = $"{processWorker.Name}, {processWorker.Id}",
|
||||||
Type = LogEntryType.warning,
|
Type = LogEntryType.Warning,
|
||||||
LogType = LogType.process,
|
LogType = LogType.Process,
|
||||||
Message = $"Calculation error {dynamicCode.Id}: {e.Message} ",
|
Message = $"Formula {calc.Expression} in Record {dynamicCode.Id} error: {e.Message}",
|
||||||
CreatedAt = DateTime.UtcNow
|
CreatedAt = DateTime.UtcNow
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_logsController.AddEntry(new LogEntry
|
||||||
|
{
|
||||||
|
Title = $"{processWorker.Name}, {processWorker.Id}",
|
||||||
|
Type = LogEntryType.Warning,
|
||||||
|
LogType = LogType.Process,
|
||||||
|
Message = $"Calculation error {dynamicCode.Id}: {e.Message} ",
|
||||||
|
CreatedAt = DateTime.UtcNow
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (isNew)
|
|
||||||
{
|
|
||||||
db.Layers.Add(processedLayer);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
db.Layers.Update(processedLayer);
|
|
||||||
}
|
|
||||||
controller.SaveRecords(processedLayer.Id, newRecords, Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"));
|
|
||||||
db.SaveChanges();
|
|
||||||
}
|
}
|
||||||
|
if (isNew)
|
||||||
|
{
|
||||||
|
_db.Layers.Add(processedLayer);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_db.Layers.Update(processedLayer);
|
||||||
|
}
|
||||||
|
_controller.SaveRecords(processedLayer.Id, newRecords, Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"));
|
||||||
|
_db.SaveChanges();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,166 +1,147 @@
|
|||||||
using DiunaBIWebAPI.dataProcessors;
|
using DiunaBIWebAPI.dataProcessors;
|
||||||
using Google.Apis.Sheets.v4;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using System;
|
|
||||||
using System.Globalization;
|
|
||||||
using WebAPI.Controllers;
|
using WebAPI.Controllers;
|
||||||
using WebAPI.Models;
|
using WebAPI.Models;
|
||||||
|
|
||||||
namespace WebAPI.dataProcessors
|
namespace WebAPI.dataProcessors;
|
||||||
{
|
|
||||||
public class T3SingleSourceProcessor
|
|
||||||
{
|
|
||||||
private readonly AppDbContext db;
|
|
||||||
private readonly SpreadsheetsResource.ValuesResource googleSheetValues;
|
|
||||||
private readonly LayersController controller;
|
|
||||||
|
|
||||||
public T3SingleSourceProcessor(
|
public class T3SingleSourceProcessor
|
||||||
AppDbContext _db,
|
{
|
||||||
SpreadsheetsResource.ValuesResource _googleSheetValues,
|
private readonly AppDbContext _db;
|
||||||
LayersController _controller)
|
private readonly LayersController _controller;
|
||||||
|
|
||||||
|
public T3SingleSourceProcessor(
|
||||||
|
AppDbContext db,
|
||||||
|
LayersController controller)
|
||||||
|
{
|
||||||
|
_db = db;
|
||||||
|
_controller = controller;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Process(Layer processWorker)
|
||||||
|
{
|
||||||
|
var year = int.Parse(processWorker.Records?.SingleOrDefault(x => x.Code == "Year")?.Desc1!);
|
||||||
|
var month = int.Parse(processWorker.Records?.SingleOrDefault(x => x.Code == "Month")?.Desc1!);
|
||||||
|
var sourceLayer = processWorker.Records?.SingleOrDefault(x => x.Code == "SourceLayer")?.Desc1;
|
||||||
|
if (sourceLayer == null)
|
||||||
{
|
{
|
||||||
db = _db;
|
throw new Exception("SourceLayer record not found");
|
||||||
googleSheetValues = _googleSheetValues;
|
}
|
||||||
controller = _controller;
|
var sourceImportWorker = _db.Layers.SingleOrDefault(x => x.Name == sourceLayer);
|
||||||
|
if (sourceImportWorker == null)
|
||||||
|
{
|
||||||
|
throw new Exception("SourceImportWorkerL layer not found");
|
||||||
|
}
|
||||||
|
var source= processWorker.Records?.SingleOrDefault(x => x.Code == "Source")?.Desc1;
|
||||||
|
if (sourceLayer == null)
|
||||||
|
{
|
||||||
|
throw new Exception("Source record not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void process(Layer processWorker)
|
var processedLayer = _db.Layers
|
||||||
|
.Where(x => x.ParentId == processWorker.Id)
|
||||||
|
.OrderByDescending(x => x.CreatedAt)
|
||||||
|
.FirstOrDefault();
|
||||||
|
|
||||||
|
var isNew = false;
|
||||||
|
if (processedLayer == null)
|
||||||
{
|
{
|
||||||
int year = int.Parse(processWorker?.Records?.SingleOrDefault(x => x.Code == "Year")?.Desc1!);
|
isNew = true;
|
||||||
int month = int.Parse(processWorker?.Records?.SingleOrDefault(x => x.Code == "Month")?.Desc1!);
|
processedLayer = new Layer
|
||||||
string? sourceLayer = processWorker?.Records?.SingleOrDefault(x => x.Code == "SourceLayer")?.Desc1;
|
|
||||||
if (sourceLayer == null)
|
|
||||||
{
|
{
|
||||||
throw new Exception("SourceLayer record not found");
|
Id = Guid.NewGuid(),
|
||||||
}
|
Type = LayerType.Processed,
|
||||||
Layer? sourceImportWorker = db.Layers.SingleOrDefault(x => x.Name == sourceLayer);
|
ParentId = processWorker.Id,
|
||||||
if (sourceImportWorker == null)
|
Number = _db.Layers.Count() + 1
|
||||||
{
|
};
|
||||||
throw new Exception("SourceImportWorkerL layer not found");
|
processedLayer.Name = $"L{processedLayer.Number}-P-{year}/{month}-{source}-T3";
|
||||||
}
|
processedLayer.CreatedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D");
|
||||||
string? source= processWorker?.Records?.SingleOrDefault(x => x.Code == "Source")?.Desc1;
|
|
||||||
if (sourceLayer == null)
|
|
||||||
{
|
|
||||||
throw new Exception("Source record not found");
|
|
||||||
}
|
|
||||||
|
|
||||||
Layer? processedLayer = db.Layers
|
|
||||||
.Where(x => x.ParentId == processWorker!.Id)
|
|
||||||
.OrderByDescending(x => x.CreatedAt)
|
|
||||||
.FirstOrDefault();
|
|
||||||
|
|
||||||
bool isNew = false;
|
|
||||||
if (processedLayer == null)
|
|
||||||
{
|
|
||||||
isNew = true;
|
|
||||||
processedLayer = new Layer
|
|
||||||
{
|
|
||||||
Id = Guid.NewGuid(),
|
|
||||||
Source = "",
|
|
||||||
Type = LayerType.processed,
|
|
||||||
ParentId = processWorker!.Id,
|
|
||||||
Number = db.Layers.Count() + 1,
|
|
||||||
};
|
|
||||||
processedLayer.Name = $"L{processedLayer.Number}-P-{year}/{month}-{source}-T3";
|
|
||||||
processedLayer.CreatedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D");
|
|
||||||
processedLayer.ModifiedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D");
|
|
||||||
processedLayer.CreatedAt = DateTime.UtcNow;
|
|
||||||
processedLayer.ModifiedAt = DateTime.UtcNow;
|
|
||||||
}
|
|
||||||
processedLayer.Sources = new List<ProcessSource>();
|
|
||||||
processedLayer.ModifiedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D");
|
processedLayer.ModifiedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D");
|
||||||
|
processedLayer.CreatedAt = DateTime.UtcNow;
|
||||||
processedLayer.ModifiedAt = DateTime.UtcNow;
|
processedLayer.ModifiedAt = DateTime.UtcNow;
|
||||||
|
}
|
||||||
|
|
||||||
|
processedLayer.ModifiedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D");
|
||||||
|
processedLayer.ModifiedAt = DateTime.UtcNow;
|
||||||
|
|
||||||
|
|
||||||
List<Record> newRecords = new List<Record>();
|
var newRecords = new List<Record>();
|
||||||
|
|
||||||
List<Layer> dataSources = db.Layers
|
var dataSources = _db.Layers
|
||||||
.Include(x => x.Records)
|
.Include(x => x.Records)
|
||||||
.Where(x => x.ParentId == sourceImportWorker.Id
|
.Where(x => x.ParentId == sourceImportWorker.Id
|
||||||
&& !x.IsDeleted)
|
&& !x.IsDeleted)
|
||||||
.OrderBy(x => x.CreatedAt)
|
.OrderBy(x => x.CreatedAt)
|
||||||
.ToList();
|
.ToList();
|
||||||
if (dataSources.Count == 0)
|
if (dataSources.Count == 0)
|
||||||
|
{
|
||||||
|
throw new Exception($"DataSources are empty, {sourceImportWorker.Name}");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
var allRecords = dataSources.SelectMany(x => x.Records!).ToList();
|
||||||
|
|
||||||
|
foreach (var baseRecord in dataSources.Last().Records!)
|
||||||
|
{
|
||||||
|
var codeRecords = allRecords.Where(x => x.Code == baseRecord.Code).ToList();
|
||||||
|
|
||||||
|
var processedRecord = new Record
|
||||||
{
|
{
|
||||||
throw new Exception($"DataSources are empty, {sourceImportWorker.Name}");
|
Id = Guid.NewGuid(),
|
||||||
}
|
Code = baseRecord.Code,
|
||||||
|
CreatedAt = DateTime.UtcNow,
|
||||||
|
ModifiedAt = DateTime.UtcNow
|
||||||
|
};
|
||||||
|
|
||||||
|
var lastDayInMonth = DateTime.DaysInMonth(year, month);
|
||||||
List<Record> allRecords = dataSources.SelectMany(x => x.Records!).ToList();
|
//day 1
|
||||||
|
var firstVal = codeRecords
|
||||||
foreach (Record baseRecord in dataSources.Last()?.Records!)
|
.Where(x => x.CreatedAt.Date <= new DateTime(year, month, 1)).MaxBy(x => x.CreatedAt)?.Value1 ?? 0;
|
||||||
|
ProcessHelper.SetValue(processedRecord, 1, firstVal);
|
||||||
|
var previousValue = firstVal;
|
||||||
|
//days 2-29/30
|
||||||
|
for (var i=2; i<lastDayInMonth; i++)
|
||||||
{
|
{
|
||||||
List<Record> codeRecords = allRecords.Where(x => x.Code == baseRecord.Code).ToList();
|
var dayVal = codeRecords
|
||||||
|
.Where(x => x.CreatedAt.Day == i && x.CreatedAt.Month == month).MaxBy(x => x.CreatedAt)?.Value1;
|
||||||
Record processedRecord = new Record
|
if (dayVal == null)
|
||||||
{
|
{
|
||||||
Id = Guid.NewGuid(),
|
ProcessHelper.SetValue(processedRecord, i, 0);
|
||||||
Code = baseRecord.Code,
|
|
||||||
CreatedAt = DateTime.UtcNow,
|
|
||||||
ModifiedAt = DateTime.UtcNow
|
|
||||||
};
|
|
||||||
|
|
||||||
int lastDayInMonth = DateTime.DaysInMonth(year, month);
|
|
||||||
double previousValue = 0;
|
|
||||||
//day 1
|
|
||||||
double firstVal = codeRecords
|
|
||||||
.Where(x => x.CreatedAt.Date <= new DateTime(year, month, 1))
|
|
||||||
.OrderByDescending(x => x.CreatedAt)
|
|
||||||
.FirstOrDefault()?.Value1 ?? 0;
|
|
||||||
ProcessHelper.SetValue(processedRecord, 1, firstVal);
|
|
||||||
previousValue = firstVal;
|
|
||||||
//days 2-29/30
|
|
||||||
for (int i=2; i<lastDayInMonth; i++)
|
|
||||||
{
|
|
||||||
double? dayVal = codeRecords
|
|
||||||
.Where(x => x.CreatedAt.Day == i && x.CreatedAt.Month == month)
|
|
||||||
.OrderByDescending(x => x.CreatedAt)
|
|
||||||
.FirstOrDefault()?.Value1;
|
|
||||||
if (dayVal == null)
|
|
||||||
{
|
|
||||||
//TODO: missing day value? Should I log it?
|
|
||||||
ProcessHelper.SetValue(processedRecord, i, 0);
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
double processedVal = (dayVal ?? 0) - previousValue;
|
|
||||||
ProcessHelper.SetValue(processedRecord, i, processedVal);
|
|
||||||
previousValue = dayVal ?? 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//last day
|
|
||||||
double? lastVal = codeRecords
|
|
||||||
.Where(x => x.CreatedAt.Date >= new DateTime(year, month, lastDayInMonth))
|
|
||||||
.OrderByDescending(x => x.CreatedAt)
|
|
||||||
.FirstOrDefault()?.Value1;
|
|
||||||
|
|
||||||
if (lastVal == null)
|
|
||||||
{
|
|
||||||
ProcessHelper.SetValue(processedRecord, lastDayInMonth, 0);
|
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
ProcessHelper.SetValue(processedRecord, lastDayInMonth, (lastVal ?? 0) - previousValue);
|
var processedVal = dayVal - previousValue;
|
||||||
|
ProcessHelper.SetValue(processedRecord, i, processedVal);
|
||||||
|
previousValue = (double)dayVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
// copy last value
|
|
||||||
double? valueToCopy = codeRecords
|
|
||||||
.OrderByDescending(x => x.CreatedAt)
|
|
||||||
.FirstOrDefault()?.Value1;
|
|
||||||
ProcessHelper.SetValue(processedRecord, 32, valueToCopy);
|
|
||||||
|
|
||||||
newRecords.Add(processedRecord);
|
|
||||||
}
|
}
|
||||||
|
//last day
|
||||||
if (isNew)
|
var lastVal = codeRecords
|
||||||
|
.Where(x => x.CreatedAt.Date >= new DateTime(year, month, lastDayInMonth)).MaxBy(x => x.CreatedAt)?.Value1;
|
||||||
|
|
||||||
|
if (lastVal == null)
|
||||||
{
|
{
|
||||||
db.Layers.Add(processedLayer);
|
ProcessHelper.SetValue(processedRecord, lastDayInMonth, 0);
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
db.Layers.Update(processedLayer);
|
ProcessHelper.SetValue(processedRecord, lastDayInMonth, (double)lastVal - previousValue);
|
||||||
}
|
}
|
||||||
controller.SaveRecords(processedLayer.Id, newRecords, Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"));
|
|
||||||
db.SaveChanges();
|
// copy last value
|
||||||
|
var valueToCopy = codeRecords.MaxBy(x => x.CreatedAt)?.Value1;
|
||||||
|
ProcessHelper.SetValue(processedRecord, 32, valueToCopy);
|
||||||
|
|
||||||
|
newRecords.Add(processedRecord);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isNew)
|
||||||
|
{
|
||||||
|
_db.Layers.Add(processedLayer);
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
_db.Layers.Update(processedLayer);
|
||||||
|
}
|
||||||
|
_controller.SaveRecords(processedLayer.Id, newRecords, Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"));
|
||||||
|
_db.SaveChanges();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
}
|
||||||
@@ -1,115 +1,110 @@
|
|||||||
using DiunaBIWebAPI.dataProcessors;
|
using DiunaBIWebAPI.dataProcessors;
|
||||||
using Google.Apis.Sheets.v4;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using WebAPI.Controllers;
|
using WebAPI.Controllers;
|
||||||
using WebAPI.Models;
|
using WebAPI.Models;
|
||||||
|
|
||||||
namespace WebAPI.dataProcessors
|
namespace WebAPI.dataProcessors;
|
||||||
|
|
||||||
|
public class T3SourceYearSummaryProcessor
|
||||||
{
|
{
|
||||||
public class T3SourceYearSummaryProcessor
|
private readonly AppDbContext _db;
|
||||||
|
private readonly LayersController _controller;
|
||||||
|
|
||||||
|
public T3SourceYearSummaryProcessor(
|
||||||
|
AppDbContext db,
|
||||||
|
LayersController controller
|
||||||
|
)
|
||||||
{
|
{
|
||||||
private readonly AppDbContext db;
|
_db = db;
|
||||||
private readonly SpreadsheetsResource.ValuesResource googleSheetValues;
|
_controller = controller;
|
||||||
private readonly LayersController controller;
|
|
||||||
|
|
||||||
public T3SourceYearSummaryProcessor(
|
|
||||||
AppDbContext _db,
|
|
||||||
SpreadsheetsResource.ValuesResource _googleSheetValues,
|
|
||||||
LayersController _controller
|
|
||||||
)
|
|
||||||
{
|
|
||||||
db = _db;
|
|
||||||
googleSheetValues = _googleSheetValues;
|
|
||||||
controller = _controller;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void process(Layer processWorker)
|
|
||||||
{
|
|
||||||
string? year = processWorker?.Records?.SingleOrDefault(x => x.Code == "Year")?.Desc1;
|
|
||||||
string? source = processWorker?.Records?.SingleOrDefault(x => x.Code == "Source")?.Desc1;
|
|
||||||
if (source == null)
|
|
||||||
{
|
|
||||||
throw new Exception("Source record not found");
|
|
||||||
}
|
|
||||||
Layer? processedLayer = db.Layers
|
|
||||||
.Where(x => x.ParentId == processWorker!.Id
|
|
||||||
&& !x.IsDeleted)
|
|
||||||
.OrderByDescending(x => x.CreatedAt)
|
|
||||||
.FirstOrDefault();
|
|
||||||
|
|
||||||
bool isNew = false;
|
|
||||||
if (processedLayer == null)
|
|
||||||
{
|
|
||||||
isNew = true;
|
|
||||||
processedLayer = new Layer
|
|
||||||
{
|
|
||||||
Id = Guid.NewGuid(),
|
|
||||||
Source = "",
|
|
||||||
Type = LayerType.processed,
|
|
||||||
ParentId = processWorker!.Id,
|
|
||||||
Number = db.Layers.Count() + 1,
|
|
||||||
};
|
|
||||||
processedLayer.Name = $"L{processedLayer.Number}-P-{year}/13-{source}-T3";
|
|
||||||
processedLayer.CreatedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D");
|
|
||||||
processedLayer.ModifiedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D");
|
|
||||||
processedLayer.CreatedAt = DateTime.UtcNow;
|
|
||||||
processedLayer.ModifiedAt = DateTime.UtcNow;
|
|
||||||
}
|
|
||||||
processedLayer.Sources = new List<ProcessSource>();
|
|
||||||
processedLayer.ModifiedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D");
|
|
||||||
processedLayer.ModifiedAt = DateTime.UtcNow;
|
|
||||||
|
|
||||||
List<Record> newRecords = new List<Record>();
|
|
||||||
|
|
||||||
List<Layer> dataSources = new List<Layer>();
|
|
||||||
for (int i=1; i<13; i++)
|
|
||||||
{
|
|
||||||
Layer? dataSource = db.Layers.Where(x =>
|
|
||||||
x.Type == LayerType.processed
|
|
||||||
&& !x.IsDeleted
|
|
||||||
&& x.Name!=null && x.Name.Contains($"{year}/{i}-{source}-T3"))
|
|
||||||
.Include(x => x.Records)
|
|
||||||
.FirstOrDefault();
|
|
||||||
if (dataSource != null)
|
|
||||||
{
|
|
||||||
dataSources.Add(dataSource!);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dataSources.Count == 0)
|
|
||||||
{
|
|
||||||
throw new Exception("DataSources are empty");
|
|
||||||
}
|
|
||||||
|
|
||||||
List<Record> allRecords = dataSources.SelectMany(x => x.Records!).ToList();
|
|
||||||
|
|
||||||
foreach (Record baseRecord in dataSources.Last()?.Records!)
|
|
||||||
{
|
|
||||||
List<Record> codeRecords = allRecords.Where(x => x.Code == baseRecord.Code).ToList();
|
|
||||||
Record processedRecord = new Record
|
|
||||||
{
|
|
||||||
Id = Guid.NewGuid(),
|
|
||||||
Code = baseRecord.Code,
|
|
||||||
CreatedAt = DateTime.UtcNow,
|
|
||||||
ModifiedAt = DateTime.UtcNow
|
|
||||||
};
|
|
||||||
for (var i = 1; i < 33; i++)
|
|
||||||
{
|
|
||||||
ProcessHelper.SetValue(processedRecord, i,
|
|
||||||
codeRecords.Sum(x => ProcessHelper.GetValue(x, i)));
|
|
||||||
}
|
|
||||||
newRecords.Add(processedRecord);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isNew)
|
|
||||||
{
|
|
||||||
db.Layers.Add(processedLayer);
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
db.Layers.Update(processedLayer);
|
|
||||||
}
|
|
||||||
controller.SaveRecords(processedLayer.Id, newRecords, Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"));
|
|
||||||
db.SaveChanges();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
public void Process(Layer processWorker)
|
||||||
|
{
|
||||||
|
var year = processWorker.Records?.SingleOrDefault(x => x.Code == "Year")?.Desc1;
|
||||||
|
var source = processWorker.Records?.SingleOrDefault(x => x.Code == "Source")?.Desc1;
|
||||||
|
if (source == null)
|
||||||
|
{
|
||||||
|
throw new Exception("Source record not found");
|
||||||
|
}
|
||||||
|
var processedLayer = _db.Layers
|
||||||
|
.Where(x => x.ParentId == processWorker.Id
|
||||||
|
&& !x.IsDeleted)
|
||||||
|
.OrderByDescending(x => x.CreatedAt)
|
||||||
|
.FirstOrDefault();
|
||||||
|
|
||||||
|
var isNew = false;
|
||||||
|
if (processedLayer == null)
|
||||||
|
{
|
||||||
|
isNew = true;
|
||||||
|
processedLayer = new Layer
|
||||||
|
{
|
||||||
|
Id = Guid.NewGuid(),
|
||||||
|
Type = LayerType.Processed,
|
||||||
|
ParentId = processWorker.Id,
|
||||||
|
Number = _db.Layers.Count() + 1
|
||||||
|
};
|
||||||
|
processedLayer.Name = $"L{processedLayer.Number}-P-{year}/13-{source}-T3";
|
||||||
|
processedLayer.CreatedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D");
|
||||||
|
processedLayer.ModifiedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D");
|
||||||
|
processedLayer.CreatedAt = DateTime.UtcNow;
|
||||||
|
processedLayer.ModifiedAt = DateTime.UtcNow;
|
||||||
|
}
|
||||||
|
|
||||||
|
processedLayer.ModifiedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D");
|
||||||
|
processedLayer.ModifiedAt = DateTime.UtcNow;
|
||||||
|
|
||||||
|
var newRecords = new List<Record>();
|
||||||
|
|
||||||
|
var dataSources = new List<Layer>();
|
||||||
|
for (var i=1; i<13; i++)
|
||||||
|
{
|
||||||
|
var i1 = i;
|
||||||
|
var dataSource = _db.Layers.Where(x =>
|
||||||
|
x.Type == LayerType.Processed
|
||||||
|
&& !x.IsDeleted
|
||||||
|
&& x.Name!=null && x.Name.Contains($"{year}/{i1}-{source}-T3"))
|
||||||
|
.Include(x => x.Records)
|
||||||
|
.FirstOrDefault();
|
||||||
|
if (dataSource != null)
|
||||||
|
{
|
||||||
|
dataSources.Add(dataSource);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dataSources.Count == 0)
|
||||||
|
{
|
||||||
|
throw new Exception("DataSources are empty");
|
||||||
|
}
|
||||||
|
|
||||||
|
var allRecords = dataSources.SelectMany(x => x.Records!).ToList();
|
||||||
|
|
||||||
|
foreach (var baseRecord in dataSources.Last().Records!)
|
||||||
|
{
|
||||||
|
var codeRecords = allRecords.Where(x => x.Code == baseRecord.Code).ToList();
|
||||||
|
var processedRecord = new Record
|
||||||
|
{
|
||||||
|
Id = Guid.NewGuid(),
|
||||||
|
Code = baseRecord.Code,
|
||||||
|
CreatedAt = DateTime.UtcNow,
|
||||||
|
ModifiedAt = DateTime.UtcNow
|
||||||
|
};
|
||||||
|
for (var i = 1; i < 33; i++)
|
||||||
|
{
|
||||||
|
ProcessHelper.SetValue(processedRecord, i,
|
||||||
|
codeRecords.Sum(x => ProcessHelper.GetValue(x, i)));
|
||||||
|
}
|
||||||
|
newRecords.Add(processedRecord);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isNew)
|
||||||
|
{
|
||||||
|
_db.Layers.Add(processedLayer);
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
_db.Layers.Update(processedLayer);
|
||||||
|
}
|
||||||
|
_controller.SaveRecords(processedLayer.Id, newRecords, Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"));
|
||||||
|
_db.SaveChanges();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,116 +1,101 @@
|
|||||||
using DiunaBIWebAPI.dataProcessors;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Google.Apis.Sheets.v4;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using System;
|
|
||||||
using System.Globalization;
|
|
||||||
using WebAPI.Controllers;
|
using WebAPI.Controllers;
|
||||||
using WebAPI.Models;
|
using WebAPI.Models;
|
||||||
|
|
||||||
namespace WebAPI.dataProcessors
|
namespace WebAPI.dataProcessors;
|
||||||
|
|
||||||
|
public class T4SingleSourceProcessor
|
||||||
{
|
{
|
||||||
public class T4SingleSourceProcessor
|
private readonly AppDbContext _db;
|
||||||
|
private readonly LayersController _controller;
|
||||||
|
|
||||||
|
public T4SingleSourceProcessor(
|
||||||
|
AppDbContext db,
|
||||||
|
LayersController controller)
|
||||||
{
|
{
|
||||||
private readonly AppDbContext db;
|
_db = db;
|
||||||
private readonly SpreadsheetsResource.ValuesResource googleSheetValues;
|
_controller = controller;
|
||||||
private readonly LayersController controller;
|
|
||||||
|
|
||||||
public T4SingleSourceProcessor(
|
|
||||||
AppDbContext _db,
|
|
||||||
SpreadsheetsResource.ValuesResource _googleSheetValues,
|
|
||||||
LayersController _controller)
|
|
||||||
{
|
|
||||||
db = _db;
|
|
||||||
googleSheetValues = _googleSheetValues;
|
|
||||||
controller = _controller;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void process(Layer processWorker)
|
|
||||||
{
|
|
||||||
int year = int.Parse(processWorker?.Records?.SingleOrDefault(x => x.Code == "Year")?.Desc1!);
|
|
||||||
int month = int.Parse(processWorker?.Records?.SingleOrDefault(x => x.Code == "Month")?.Desc1!);
|
|
||||||
string? sourceLayer = processWorker?.Records?.SingleOrDefault(x => x.Code == "SourceLayer")?.Desc1;
|
|
||||||
if (sourceLayer == null)
|
|
||||||
{
|
|
||||||
throw new Exception("SourceLayer record not found");
|
|
||||||
}
|
|
||||||
Layer? sourceImportWorker = db.Layers.SingleOrDefault(x => x.Name == sourceLayer);
|
|
||||||
if (sourceImportWorker == null)
|
|
||||||
{
|
|
||||||
throw new Exception("SourceImportWorkerL layer not found");
|
|
||||||
}
|
|
||||||
string? source= processWorker?.Records?.SingleOrDefault(x => x.Code == "Source")?.Desc1;
|
|
||||||
if (sourceLayer == null)
|
|
||||||
{
|
|
||||||
throw new Exception("Source record not found");
|
|
||||||
}
|
|
||||||
|
|
||||||
Layer? processedLayer = db.Layers
|
|
||||||
.Where(x => x.ParentId == processWorker!.Id)
|
|
||||||
.OrderByDescending(x => x.CreatedAt)
|
|
||||||
.FirstOrDefault();
|
|
||||||
|
|
||||||
bool isNew = false;
|
|
||||||
if (processedLayer == null)
|
|
||||||
{
|
|
||||||
isNew = true;
|
|
||||||
processedLayer = new Layer
|
|
||||||
{
|
|
||||||
Id = Guid.NewGuid(),
|
|
||||||
Source = "",
|
|
||||||
Type = LayerType.processed,
|
|
||||||
ParentId = processWorker!.Id,
|
|
||||||
Number = db.Layers.Count() + 1,
|
|
||||||
};
|
|
||||||
processedLayer.Name = $"L{processedLayer.Number}-P-{year}/{month}-{source}-T4";
|
|
||||||
processedLayer.CreatedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D");
|
|
||||||
processedLayer.ModifiedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D");
|
|
||||||
processedLayer.CreatedAt = DateTime.UtcNow;
|
|
||||||
processedLayer.ModifiedAt = DateTime.UtcNow;
|
|
||||||
}
|
|
||||||
processedLayer.Sources = new List<ProcessSource>();
|
|
||||||
processedLayer.ModifiedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D");
|
|
||||||
processedLayer.ModifiedAt = DateTime.UtcNow;
|
|
||||||
|
|
||||||
|
|
||||||
List<Record> newRecords = new List<Record>();
|
|
||||||
|
|
||||||
Layer? dataSource = db.Layers
|
|
||||||
.Include(x => x.Records)
|
|
||||||
.Where(x => x.ParentId == sourceImportWorker.Id
|
|
||||||
&& !x.IsDeleted)
|
|
||||||
.OrderByDescending(x => x.CreatedAt)
|
|
||||||
.FirstOrDefault();
|
|
||||||
|
|
||||||
if (dataSource == null)
|
|
||||||
{
|
|
||||||
throw new Exception($"DataSource not found, {sourceImportWorker.Name}");
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (Record record in dataSource.Records!)
|
|
||||||
{
|
|
||||||
Record processedRecord = new Record
|
|
||||||
{
|
|
||||||
Id = Guid.NewGuid(),
|
|
||||||
Code = record.Code,
|
|
||||||
Desc1 = record.Desc1,
|
|
||||||
Value1 = record.Value1,
|
|
||||||
CreatedAt = DateTime.UtcNow,
|
|
||||||
ModifiedAt = DateTime.UtcNow
|
|
||||||
};
|
|
||||||
newRecords.Add(processedRecord);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isNew)
|
|
||||||
{
|
|
||||||
db.Layers.Add(processedLayer);
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
db.Layers.Update(processedLayer);
|
|
||||||
}
|
|
||||||
controller.SaveRecords(processedLayer.Id, newRecords, Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"));
|
|
||||||
db.SaveChanges();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
public void Process(Layer processWorker)
|
||||||
|
{
|
||||||
|
var year = int.Parse(processWorker.Records?.SingleOrDefault(x => x.Code == "Year")?.Desc1!);
|
||||||
|
var month = int.Parse(processWorker.Records?.SingleOrDefault(x => x.Code == "Month")?.Desc1!);
|
||||||
|
var sourceLayer = processWorker.Records?.SingleOrDefault(x => x.Code == "SourceLayer")?.Desc1;
|
||||||
|
if (sourceLayer == null)
|
||||||
|
{
|
||||||
|
throw new Exception("SourceLayer record not found");
|
||||||
|
}
|
||||||
|
var sourceImportWorker = _db.Layers.SingleOrDefault(x => x.Name == sourceLayer);
|
||||||
|
if (sourceImportWorker == null)
|
||||||
|
{
|
||||||
|
throw new Exception("SourceImportWorkerL layer not found");
|
||||||
|
}
|
||||||
|
var source= processWorker.Records?.SingleOrDefault(x => x.Code == "Source")?.Desc1;
|
||||||
|
if (sourceLayer == null)
|
||||||
|
{
|
||||||
|
throw new Exception("Source record not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
var processedLayer = _db.Layers
|
||||||
|
.Where(x => x.ParentId == processWorker.Id)
|
||||||
|
.OrderByDescending(x => x.CreatedAt)
|
||||||
|
.FirstOrDefault();
|
||||||
|
|
||||||
|
var isNew = false;
|
||||||
|
if (processedLayer == null)
|
||||||
|
{
|
||||||
|
isNew = true;
|
||||||
|
processedLayer = new Layer
|
||||||
|
{
|
||||||
|
Id = Guid.NewGuid(),
|
||||||
|
Type = LayerType.Processed,
|
||||||
|
ParentId = processWorker.Id,
|
||||||
|
Number = _db.Layers.Count() + 1
|
||||||
|
};
|
||||||
|
processedLayer.Name = $"L{processedLayer.Number}-P-{year}/{month}-{source}-T4";
|
||||||
|
processedLayer.CreatedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D");
|
||||||
|
processedLayer.ModifiedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D");
|
||||||
|
processedLayer.CreatedAt = DateTime.UtcNow;
|
||||||
|
processedLayer.ModifiedAt = DateTime.UtcNow;
|
||||||
|
}
|
||||||
|
|
||||||
|
processedLayer.ModifiedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D");
|
||||||
|
processedLayer.ModifiedAt = DateTime.UtcNow;
|
||||||
|
|
||||||
|
|
||||||
|
var dataSource = _db.Layers
|
||||||
|
.Include(x => x.Records)
|
||||||
|
.Where(x => x.ParentId == sourceImportWorker.Id
|
||||||
|
&& !x.IsDeleted)
|
||||||
|
.OrderByDescending(x => x.CreatedAt)
|
||||||
|
.FirstOrDefault();
|
||||||
|
|
||||||
|
if (dataSource == null)
|
||||||
|
{
|
||||||
|
throw new Exception($"DataSource not found, {sourceImportWorker.Name}");
|
||||||
|
}
|
||||||
|
|
||||||
|
var newRecords = dataSource.Records!.Select(record => new Record
|
||||||
|
{
|
||||||
|
Id = Guid.NewGuid(),
|
||||||
|
Code = record.Code,
|
||||||
|
Desc1 = record.Desc1,
|
||||||
|
Value1 = record.Value1,
|
||||||
|
CreatedAt = DateTime.UtcNow,
|
||||||
|
ModifiedAt = DateTime.UtcNow
|
||||||
|
})
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
if (isNew)
|
||||||
|
{
|
||||||
|
_db.Layers.Add(processedLayer);
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
_db.Layers.Update(processedLayer);
|
||||||
|
}
|
||||||
|
_controller.SaveRecords(processedLayer.Id, newRecords, Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"));
|
||||||
|
_db.SaveChanges();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,189 +1,176 @@
|
|||||||
using DiunaBIWebAPI.dataProcessors;
|
using DiunaBIWebAPI.dataProcessors;
|
||||||
using Google.Apis.Sheets.v4;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using WebAPI.Controllers;
|
using WebAPI.Controllers;
|
||||||
using WebAPI.Models;
|
using WebAPI.Models;
|
||||||
|
|
||||||
|
|
||||||
namespace WebAPI.dataProcessors
|
namespace WebAPI.dataProcessors;
|
||||||
{
|
|
||||||
public class T4R2Processor
|
|
||||||
{
|
|
||||||
private readonly AppDbContext _db;
|
|
||||||
private readonly LayersController _controller;
|
|
||||||
private readonly LogsController _logsController;
|
|
||||||
|
|
||||||
public T4R2Processor(
|
public class T4R2Processor
|
||||||
AppDbContext db,
|
{
|
||||||
SpreadsheetsResource.ValuesResource googleSheetValues,
|
private readonly AppDbContext _db;
|
||||||
LayersController controller,
|
private readonly LayersController _controller;
|
||||||
LogsController logsController)
|
private readonly LogsController _logsController;
|
||||||
|
|
||||||
|
public T4R2Processor(
|
||||||
|
AppDbContext db,
|
||||||
|
LayersController controller,
|
||||||
|
LogsController logsController)
|
||||||
|
{
|
||||||
|
_db = db;
|
||||||
|
_controller = controller;
|
||||||
|
_logsController = logsController;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Process(Layer processWorker)
|
||||||
|
{
|
||||||
|
var year = int.Parse(processWorker.Records?.SingleOrDefault(x => x.Code == "Year")?.Desc1!);
|
||||||
|
var sources = processWorker.Records?.Where(x => x.Code == "Source").ToList();
|
||||||
|
if (!sources!.Any())
|
||||||
{
|
{
|
||||||
_db = db;
|
throw new Exception("Source record not found");
|
||||||
_controller = controller;
|
|
||||||
_logsController = logsController;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Process(Layer processWorker)
|
var layerName = processWorker.Records?.SingleOrDefault(x => x.Code == "LayerName")?.Desc1;
|
||||||
|
if (layerName == null)
|
||||||
{
|
{
|
||||||
var year = int.Parse(processWorker.Records?.SingleOrDefault(x => x.Code == "Year")?.Desc1!);
|
throw new Exception("LayerName record not found");
|
||||||
var sources = processWorker.Records?.Where(x => x.Code == "Source").ToList();
|
}
|
||||||
if (!sources!.Any())
|
|
||||||
|
|
||||||
|
var processedLayer = _db.Layers
|
||||||
|
.Where(x => x.ParentId == processWorker.Id
|
||||||
|
&& !x.IsDeleted)
|
||||||
|
.OrderByDescending(x => x.CreatedAt)
|
||||||
|
.FirstOrDefault();
|
||||||
|
|
||||||
|
var isNew = false;
|
||||||
|
if (processedLayer == null)
|
||||||
|
{
|
||||||
|
isNew = true;
|
||||||
|
processedLayer = new Layer
|
||||||
{
|
{
|
||||||
throw new Exception("Source record not found");
|
Id = Guid.NewGuid(),
|
||||||
}
|
Type = LayerType.Processed,
|
||||||
|
ParentId = processWorker.Id,
|
||||||
var layerName = processWorker.Records?.SingleOrDefault(x => x.Code == "LayerName")?.Desc1;
|
Number = _db.Layers.Count() + 1
|
||||||
if (layerName == null)
|
};
|
||||||
{
|
processedLayer.Name = $"L{processedLayer.Number}-{layerName}";
|
||||||
throw new Exception("LayerName record not found");
|
processedLayer.CreatedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D");
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
var processedLayer = _db.Layers
|
|
||||||
.Where(x => x.ParentId == processWorker.Id
|
|
||||||
&& !x.IsDeleted)
|
|
||||||
.OrderByDescending(x => x.CreatedAt)
|
|
||||||
.FirstOrDefault();
|
|
||||||
|
|
||||||
var isNew = false;
|
|
||||||
if (processedLayer == null)
|
|
||||||
{
|
|
||||||
isNew = true;
|
|
||||||
processedLayer = new Layer
|
|
||||||
{
|
|
||||||
Id = Guid.NewGuid(),
|
|
||||||
Source = "",
|
|
||||||
Type = LayerType.processed,
|
|
||||||
ParentId = processWorker.Id,
|
|
||||||
Number = _db.Layers.Count() + 1
|
|
||||||
};
|
|
||||||
processedLayer.Name = $"L{processedLayer.Number}-{layerName}";
|
|
||||||
processedLayer.CreatedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D");
|
|
||||||
processedLayer.ModifiedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D");
|
|
||||||
processedLayer.CreatedAt = DateTime.UtcNow;
|
|
||||||
processedLayer.ModifiedAt = DateTime.UtcNow;
|
|
||||||
}
|
|
||||||
|
|
||||||
processedLayer.Sources = new List<ProcessSource>();
|
|
||||||
processedLayer.ModifiedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D");
|
processedLayer.ModifiedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D");
|
||||||
|
processedLayer.CreatedAt = DateTime.UtcNow;
|
||||||
processedLayer.ModifiedAt = DateTime.UtcNow;
|
processedLayer.ModifiedAt = DateTime.UtcNow;
|
||||||
|
}
|
||||||
|
|
||||||
|
processedLayer.ModifiedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D");
|
||||||
|
processedLayer.ModifiedAt = DateTime.UtcNow;
|
||||||
|
|
||||||
|
|
||||||
var newRecords = new List<Record>();
|
var newRecords = new List<Record>();
|
||||||
|
|
||||||
foreach (var source in sources!)
|
foreach (var source in sources!)
|
||||||
|
{
|
||||||
|
var rawSourceCodes = processWorker.Records?.SingleOrDefault(x => x.Code == $"Codes-{source.Desc1}")
|
||||||
|
?.Desc1;
|
||||||
|
var sourceCodes = new List<int>();
|
||||||
|
if (rawSourceCodes != null)
|
||||||
{
|
{
|
||||||
var rawSourceCodes = processWorker.Records?.SingleOrDefault(x => x.Code == $"Codes-{source.Desc1}")
|
sourceCodes = ProcessHelper.ParseCodes(rawSourceCodes);
|
||||||
?.Desc1;
|
|
||||||
var sourceCodes = new List<int>();
|
|
||||||
if (rawSourceCodes != null)
|
|
||||||
{
|
|
||||||
sourceCodes = ProcessHelper.ParseCodes(rawSourceCodes);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var month = 1; month <= DateTime.UtcNow.Month; 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)
|
|
||||||
{
|
|
||||||
List<Record> 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
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// year summery
|
|
||||||
var dataSourceSum = _db.Layers.Where(x =>
|
|
||||||
x.Type == LayerType.processed &&
|
|
||||||
!x.IsDeleted &&
|
|
||||||
x.Name != null && x.Name.Contains($"{year}/13-{source.Desc1}-T")
|
|
||||||
)
|
|
||||||
.Include(x => x.Records)
|
|
||||||
.FirstOrDefault();
|
|
||||||
if (dataSourceSum != null)
|
|
||||||
{
|
|
||||||
var news = dataSourceSum.Records!
|
|
||||||
.Where(x =>
|
|
||||||
{
|
|
||||||
if (sourceCodes.Count > 0)
|
|
||||||
{
|
|
||||||
return sourceCodes.Contains(int.Parse(x.Code!));
|
|
||||||
}
|
|
||||||
|
|
||||||
return true; // get all
|
|
||||||
})
|
|
||||||
.Select(x =>
|
|
||||||
{
|
|
||||||
Record newRecord = new Record
|
|
||||||
{
|
|
||||||
Id = Guid.NewGuid(),
|
|
||||||
Code = x.Code + "13",
|
|
||||||
CreatedAt = DateTime.UtcNow,
|
|
||||||
ModifiedAt = DateTime.UtcNow,
|
|
||||||
Value1 = x.Value32
|
|
||||||
};
|
|
||||||
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}/13-{source.Desc1}-T3 not found",
|
|
||||||
CreatedAt = DateTime.UtcNow
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isNew)
|
for (var month = 1; month <= DateTime.UtcNow.Month; month++)
|
||||||
{
|
{
|
||||||
_db.Layers.Add(processedLayer);
|
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)
|
||||||
|
{
|
||||||
|
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
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// year summery
|
||||||
|
var dataSourceSum = _db.Layers.Where(x =>
|
||||||
|
x.Type == LayerType.Processed &&
|
||||||
|
!x.IsDeleted &&
|
||||||
|
x.Name != null && x.Name.Contains($"{year}/13-{source.Desc1}-T")
|
||||||
|
)
|
||||||
|
.Include(x => x.Records)
|
||||||
|
.FirstOrDefault();
|
||||||
|
if (dataSourceSum != null)
|
||||||
|
{
|
||||||
|
var news = dataSourceSum.Records!
|
||||||
|
.Where(x => sourceCodes.Count <= 0 || sourceCodes.Contains(int.Parse(x.Code!)))
|
||||||
|
.Select(x =>
|
||||||
|
{
|
||||||
|
var newRecord = new Record
|
||||||
|
{
|
||||||
|
Id = Guid.NewGuid(),
|
||||||
|
Code = x.Code + "13",
|
||||||
|
CreatedAt = DateTime.UtcNow,
|
||||||
|
ModifiedAt = DateTime.UtcNow,
|
||||||
|
Value1 = x.Value32
|
||||||
|
};
|
||||||
|
return newRecord;
|
||||||
|
}
|
||||||
|
).ToList();
|
||||||
|
newRecords.AddRange(news);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_db.Layers.Update(processedLayer);
|
_logsController.AddEntry(new LogEntry
|
||||||
|
{
|
||||||
|
Title = $"{processWorker.Name}, {processWorker.Id}",
|
||||||
|
Type = LogEntryType.Warning,
|
||||||
|
LogType = LogType.Process,
|
||||||
|
Message = $"Data source {year}/13-{source.Desc1}-T3 not found",
|
||||||
|
CreatedAt = DateTime.UtcNow
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
_controller.SaveRecords(processedLayer.Id, newRecords, Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"));
|
|
||||||
_db.SaveChanges();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isNew)
|
||||||
|
{
|
||||||
|
_db.Layers.Add(processedLayer);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_db.Layers.Update(processedLayer);
|
||||||
|
}
|
||||||
|
|
||||||
|
_controller.SaveRecords(processedLayer.Id, newRecords, Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"));
|
||||||
|
_db.SaveChanges();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user