Add - operator into basecalc
This commit is contained in:
77
WebAPI/dataImporters/morska.d3.importer.cs
Normal file
77
WebAPI/dataImporters/morska.d3.importer.cs
Normal file
@@ -0,0 +1,77 @@
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using Google.Apis.Sheets.v4;
|
||||
using WebAPI;
|
||||
using WebAPI.Controllers;
|
||||
using WebAPI.Models;
|
||||
|
||||
namespace DiunaBIWebAPI.dataImporters;
|
||||
|
||||
public class MorskaD3Importer(
|
||||
AppDbContext db,
|
||||
LayersController controller)
|
||||
{
|
||||
public void Import(Layer importWorker)
|
||||
{
|
||||
var year = importWorker.Records!.FirstOrDefault(x => x.Code == "ImportYear")?.Desc1;
|
||||
if (year == null)
|
||||
{
|
||||
throw new Exception($"ImportYear not found, {importWorker.Name}");
|
||||
}
|
||||
var month = importWorker.Records!.FirstOrDefault(x => x.Code == "ImportMonth")?.Desc1;
|
||||
if (month == null)
|
||||
{
|
||||
throw new Exception($"ImportMonth not found, {importWorker.Name}");
|
||||
}
|
||||
var name = importWorker.Records!.FirstOrDefault(x => x.Code == "ImportName")?.Desc1;
|
||||
if (name == null)
|
||||
{
|
||||
throw new Exception($"ImportName not found, {importWorker.Name}");
|
||||
}
|
||||
var type = importWorker.Records!.FirstOrDefault(x => x.Code == "ImportType")?.Desc1;
|
||||
if (name == null)
|
||||
{
|
||||
throw new Exception($"ImportType not found, {importWorker.Name}");
|
||||
}
|
||||
var dataInbox = db.DataInbox.OrderByDescending(x => x.CreatedAt).FirstOrDefault(x => x.Name == type);
|
||||
if (dataInbox == null)
|
||||
{
|
||||
throw new Exception($"DataInbox not found, {type}");
|
||||
}
|
||||
var data = Convert.FromBase64String(dataInbox.Data);
|
||||
var records = JsonSerializer.Deserialize<List<Record>>(Encoding.UTF8.GetString(data));
|
||||
if (records == null)
|
||||
{
|
||||
throw new Exception($"DataInbox.Data is empty, {dataInbox.Name}");
|
||||
}
|
||||
year = "2024";
|
||||
records = records.Where(x => x.Code!.EndsWith($"{year}{month}")).ToList();
|
||||
if (records.Count == 0)
|
||||
{
|
||||
throw new Exception($"No records found for {year}{month}");
|
||||
}
|
||||
records = records.Select(x =>
|
||||
{
|
||||
x.Id = Guid.NewGuid();
|
||||
x.CreatedAt = DateTime.UtcNow;
|
||||
x.ModifiedAt = DateTime.UtcNow;
|
||||
return x;
|
||||
}).ToList();
|
||||
var layer = new Layer
|
||||
{
|
||||
Number = db.Layers.Count() + 1,
|
||||
ParentId = importWorker.Id,
|
||||
Type = LayerType.Import,
|
||||
CreatedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"),
|
||||
ModifiedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"),
|
||||
CreatedAt = DateTime.UtcNow,
|
||||
ModifiedAt = DateTime.UtcNow
|
||||
};
|
||||
layer.Name = $"L{layer.Number}-I-{name}-{year}/{month}-{DateTime.Now.ToString("yyyyMMddHHmm", CultureInfo.InvariantCulture)}";
|
||||
|
||||
db.Layers.Add(layer);
|
||||
controller.SaveRecords(layer.Id, records, Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"));
|
||||
//db.SaveChanges();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user