2023-11-09 15:17:22 +01:00
|
|
|
using DiunaBIWebAPI.dataImporters;
|
2023-11-29 22:14:37 +01:00
|
|
|
using Google.Apis.Sheets.v4;
|
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
using WebAPI.dataProcessors;
|
|
|
|
|
using WebAPI.Exports;
|
|
|
|
|
using WebAPI.Models;
|
|
|
|
|
|
|
|
|
|
namespace WebAPI.Controllers
|
|
|
|
|
{
|
|
|
|
|
[ApiController]
|
|
|
|
|
[Route("api/[controller]")]
|
|
|
|
|
|
|
|
|
|
public class LayersController : Controller
|
|
|
|
|
{
|
|
|
|
|
private readonly AppDbContext db;
|
|
|
|
|
private SpreadsheetsResource.ValuesResource? googleSheetValues;
|
|
|
|
|
private GoogleDriveHelper googleDriveHelper;
|
|
|
|
|
private GoogleSheetsHelper googleSheetsHelper;
|
|
|
|
|
private readonly IConfiguration configuration;
|
|
|
|
|
private readonly LogsController logsController;
|
|
|
|
|
public LayersController(
|
|
|
|
|
AppDbContext _db,
|
|
|
|
|
GoogleSheetsHelper _googleSheetsHelper,
|
|
|
|
|
GoogleDriveHelper _googleDriveHelper,
|
|
|
|
|
IConfiguration _configuration)
|
|
|
|
|
{
|
|
|
|
|
db = _db;
|
2024-03-06 16:48:11 +01:00
|
|
|
if (_googleSheetsHelper.Service is not null)
|
|
|
|
|
{
|
2023-11-29 22:14:37 +01:00
|
|
|
googleSheetValues = _googleSheetsHelper.Service.Spreadsheets.Values;
|
|
|
|
|
}
|
|
|
|
|
googleSheetsHelper = _googleSheetsHelper;
|
|
|
|
|
googleDriveHelper = _googleDriveHelper;
|
|
|
|
|
configuration = _configuration;
|
|
|
|
|
logsController = new LogsController(googleSheetsHelper, googleDriveHelper, configuration);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult GetAll(int start, int limit, string? name, LayerType? type)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
IQueryable<Layer> response = db.Layers.Where(x => !x.IsDeleted);
|
|
|
|
|
if (name != null)
|
|
|
|
|
{
|
2024-03-06 16:48:11 +01:00
|
|
|
response = response.Where(x => x.Name != null && x.Name.Contains(name));
|
2023-11-29 22:14:37 +01:00
|
|
|
}
|
|
|
|
|
if (type != null)
|
|
|
|
|
{
|
|
|
|
|
response = response.Where(x => x.Type == type);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Ok(response
|
|
|
|
|
.OrderByDescending(x => x.Number)
|
|
|
|
|
.Skip(start).Take(limit).ToList());
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
return BadRequest(e.ToString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public IActionResult Save(Layer input)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
//Request.Headers.TryGetValue("userId", out var value);
|
|
|
|
|
//Guid currentUserId = new Guid(value!);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return Ok();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
return BadRequest(e.ToString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
[HttpGet]
|
2024-03-06 16:48:11 +01:00
|
|
|
[Route("{id}")]
|
|
|
|
|
public IActionResult Get(Guid id)
|
2023-11-29 22:14:37 +01:00
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return Ok(db.Layers
|
|
|
|
|
.Include(x => x.CreatedBy)
|
|
|
|
|
.Include(x => x.Records)
|
|
|
|
|
.Where(x => x.Id == id && !x.IsDeleted).First());
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
return BadRequest(e.ToString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
[HttpGet]
|
2023-12-26 11:42:51 +01:00
|
|
|
[Route("getByNumber/{apiKey}/{number}")]
|
|
|
|
|
public IActionResult GetByNumber(string apiKey, int number)
|
|
|
|
|
{
|
|
|
|
|
if (apiKey != configuration["apiKey"])
|
|
|
|
|
{
|
|
|
|
|
return Unauthorized();
|
|
|
|
|
}
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return Ok(db.Layers
|
|
|
|
|
.Include(x => x.CreatedBy)
|
|
|
|
|
.Include(x => x.Records)
|
|
|
|
|
.Where(x => x.Number == number && !x.IsDeleted).First());
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
return BadRequest(e.ToString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
[HttpGet]
|
2023-11-29 22:14:37 +01:00
|
|
|
[Route("exportToGoogleSheet/{id}")]
|
|
|
|
|
public IActionResult ExportToGoogleSheet(Guid id)
|
|
|
|
|
{
|
2024-03-06 16:48:11 +01:00
|
|
|
if (googleSheetValues is null)
|
|
|
|
|
{
|
2023-11-29 22:14:37 +01:00
|
|
|
throw new Exception("Google Sheets API not initialized");
|
|
|
|
|
}
|
|
|
|
|
Layer layer = db.Layers
|
|
|
|
|
.Include(x => x.Records!.OrderByDescending(x => x.Code))
|
|
|
|
|
.Where(x => x.Id == id && !x.IsDeleted).First();
|
|
|
|
|
|
|
|
|
|
var export = new googleSheetExport(googleDriveHelper, googleSheetValues, configuration);
|
|
|
|
|
export.export(layer);
|
|
|
|
|
return Ok(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
[Route("AutoImport/{apiKey}")]
|
|
|
|
|
[AllowAnonymous]
|
|
|
|
|
public IActionResult AutoImport(string apiKey)
|
|
|
|
|
{
|
|
|
|
|
if (Request.Host.Value != configuration["apiLocalUrl"] || apiKey != configuration["apiKey"])
|
|
|
|
|
{
|
|
|
|
|
return Unauthorized();
|
|
|
|
|
}
|
2024-03-06 16:48:11 +01:00
|
|
|
if (googleSheetValues is null)
|
|
|
|
|
{
|
2023-11-29 22:14:37 +01:00
|
|
|
throw new Exception("Google Sheets API not initialized");
|
|
|
|
|
}
|
2023-11-09 15:17:22 +01:00
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
List<Layer> importWorkerLayers;
|
|
|
|
|
importWorkerLayers = db.Layers
|
|
|
|
|
.Include(x => x.Records)
|
|
|
|
|
.Where(x =>
|
|
|
|
|
x.Records!.Any(x => x.Code == "Type" && x.Desc1 == "ImportWorker") &&
|
2024-03-06 16:48:11 +01:00
|
|
|
x.Records!.Any(x => x.Code == "IsEnabled" && x.Desc1 == "True")
|
2023-11-09 15:17:22 +01:00
|
|
|
)
|
|
|
|
|
.OrderBy(x => x.CreatedAt)
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
if (importWorkerLayers.Count() == 0)
|
|
|
|
|
{
|
|
|
|
|
logsController.AddEntry(new LogEntry
|
|
|
|
|
{
|
|
|
|
|
Title = "No Layers to import.",
|
|
|
|
|
Type = LogEntryType.info,
|
|
|
|
|
LogType = LogType.import,
|
|
|
|
|
CreatedAt = DateTime.UtcNow,
|
2023-11-29 22:14:37 +01:00
|
|
|
});
|
2023-11-09 15:17:22 +01:00
|
|
|
return Ok();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (Layer importWorker in importWorkerLayers)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
string? startDate = importWorker.Records!.FirstOrDefault(x => x.Code == "StartDate")?.Desc1;
|
|
|
|
|
if (startDate == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Year record nod found");
|
|
|
|
|
}
|
|
|
|
|
string? endDate = importWorker.Records!.Where(x => x.Code == "EndDate").First().Desc1;
|
|
|
|
|
if (endDate == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Year record nod found");
|
|
|
|
|
}
|
|
|
|
|
var startDateParsed = DateTime.ParseExact(startDate!, "yyyy.MM.dd", null);
|
|
|
|
|
var endDateParsed = DateTime.ParseExact(endDate!, "yyyy.MM.dd", null);
|
2024-03-08 15:56:35 +01:00
|
|
|
if (startDateParsed.Date <= DateTime.UtcNow.Date && endDateParsed.Date >= DateTime.UtcNow.Date || true)
|
2023-11-09 15:17:22 +01:00
|
|
|
{
|
|
|
|
|
MorskaImporter importer = new MorskaImporter(db, googleSheetValues, this);
|
|
|
|
|
importer.import(importWorker);
|
|
|
|
|
|
|
|
|
|
logsController.AddEntry(new LogEntry
|
|
|
|
|
{
|
|
|
|
|
Title = $"{importWorker!.Name}, {importWorker.Id}",
|
|
|
|
|
Type = LogEntryType.info,
|
|
|
|
|
LogType = LogType.import,
|
|
|
|
|
Message = "Success",
|
|
|
|
|
CreatedAt = DateTime.UtcNow
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
logsController.AddEntry(new LogEntry
|
|
|
|
|
{
|
|
|
|
|
Title = $"{importWorker!.Name}, {importWorker.Id}",
|
|
|
|
|
Type = LogEntryType.warning,
|
|
|
|
|
LogType = LogType.import,
|
|
|
|
|
Message = "importLayer is out of date. Should be disabled. Not processed.",
|
|
|
|
|
CreatedAt = DateTime.UtcNow
|
|
|
|
|
});
|
|
|
|
|
}
|
2024-03-06 16:48:11 +01:00
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
2023-11-09 15:17:22 +01:00
|
|
|
{
|
|
|
|
|
logsController.AddEntry(new LogEntry
|
|
|
|
|
{
|
|
|
|
|
Title = $"{importWorker!.Name}, {importWorker.Id}",
|
|
|
|
|
Type = LogEntryType.error,
|
|
|
|
|
LogType = LogType.import,
|
|
|
|
|
Message = e.ToString(),
|
|
|
|
|
CreatedAt = DateTime.UtcNow
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return Ok();
|
2024-03-06 16:48:11 +01:00
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
2023-11-09 15:17:22 +01:00
|
|
|
{
|
2023-11-29 22:14:37 +01:00
|
|
|
logsController.AddEntry(new LogEntry
|
|
|
|
|
{
|
|
|
|
|
Title = "Process error",
|
|
|
|
|
Type = LogEntryType.error,
|
|
|
|
|
LogType = LogType.import,
|
|
|
|
|
Message = e.ToString(),
|
|
|
|
|
CreatedAt = DateTime.UtcNow
|
|
|
|
|
});
|
2023-11-09 15:17:22 +01:00
|
|
|
return BadRequest(e.ToString());
|
2023-11-29 22:14:37 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
[HttpGet]
|
|
|
|
|
[Route("AutoProcess/{apiKey}/{type}")]
|
|
|
|
|
[AllowAnonymous]
|
|
|
|
|
public IActionResult AutoProcess(string apiKey, string type)
|
|
|
|
|
{
|
|
|
|
|
if (Request.Host.Value != configuration["apiLocalUrl"] || apiKey != configuration["apiKey"])
|
|
|
|
|
{
|
|
|
|
|
return Unauthorized();
|
|
|
|
|
}
|
2024-03-06 16:48:11 +01:00
|
|
|
if (googleSheetValues is null)
|
|
|
|
|
{
|
2023-11-29 22:14:37 +01:00
|
|
|
throw new Exception("Google Sheets API not initialized");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
List<Layer> processWorkerLayers = db.Layers
|
|
|
|
|
.Include(x => x.Records)
|
|
|
|
|
.Where(x =>
|
|
|
|
|
x.Records!.Any(x => x.Code == "Type" && x.Desc1 == "ProcessWorker") &&
|
|
|
|
|
x.Records!.Any(x => x.Code == "IsEnabled" && x.Desc1 == "True") &&
|
|
|
|
|
x.Records!.Any(x => x.Code == "ProcessType" && x.Desc1 == type)
|
2024-03-08 15:56:35 +01:00
|
|
|
&& x.Number == 800
|
2023-11-29 22:14:37 +01:00
|
|
|
)
|
|
|
|
|
.OrderBy(x => x.CreatedAt)
|
|
|
|
|
.ToList();
|
|
|
|
|
|
2023-11-06 22:52:07 +01:00
|
|
|
if (processWorkerLayers.Count() == 0)
|
|
|
|
|
{
|
|
|
|
|
logsController.AddEntry(new LogEntry
|
|
|
|
|
{
|
|
|
|
|
Title = "No Layers to process.",
|
|
|
|
|
Type = LogEntryType.info,
|
|
|
|
|
LogType = LogType.process,
|
|
|
|
|
CreatedAt = DateTime.UtcNow,
|
2023-11-29 22:14:37 +01:00
|
|
|
});
|
2023-11-06 22:52:07 +01:00
|
|
|
return Ok();
|
2023-11-29 22:14:37 +01:00
|
|
|
}
|
|
|
|
|
|
2023-11-06 22:52:07 +01:00
|
|
|
foreach (Layer processWorker in processWorkerLayers)
|
2023-11-29 22:14:37 +01:00
|
|
|
{
|
2023-11-06 22:52:07 +01:00
|
|
|
try
|
2023-11-29 22:14:37 +01:00
|
|
|
{
|
2024-03-08 15:56:35 +01:00
|
|
|
ProcessLayer(processWorker, true);
|
2024-03-06 16:48:11 +01:00
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
2023-11-06 22:52:07 +01:00
|
|
|
{
|
|
|
|
|
logsController.AddEntry(new LogEntry
|
|
|
|
|
{
|
|
|
|
|
Title = $"{processWorker!.Name}, {processWorker.Id}",
|
|
|
|
|
Type = LogEntryType.error,
|
|
|
|
|
LogType = LogType.process,
|
|
|
|
|
Message = e.ToString(),
|
|
|
|
|
CreatedAt = DateTime.UtcNow
|
|
|
|
|
});
|
2024-03-06 16:48:11 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return Ok();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
logsController.AddEntry(new LogEntry
|
|
|
|
|
{
|
|
|
|
|
Title = "Process error",
|
|
|
|
|
Type = LogEntryType.error,
|
|
|
|
|
LogType = LogType.process,
|
|
|
|
|
Message = e.ToString(),
|
|
|
|
|
CreatedAt = DateTime.UtcNow
|
|
|
|
|
});
|
|
|
|
|
return BadRequest(e.ToString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
[Route("ProcessLayer/{id}")]
|
|
|
|
|
public IActionResult ProcessLayer(Guid id)
|
|
|
|
|
{
|
|
|
|
|
if (googleSheetValues is null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Google Sheets API not initialized");
|
|
|
|
|
}
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Layer layer = db.Layers
|
|
|
|
|
.Include(x => x.Records)
|
|
|
|
|
.Where(x => x.Id == id && !x.IsDeleted).First();
|
|
|
|
|
if (layer == null)
|
|
|
|
|
{
|
|
|
|
|
logsController.AddEntry(new LogEntry
|
|
|
|
|
{
|
|
|
|
|
Title = "Process error",
|
|
|
|
|
Type = LogEntryType.error,
|
|
|
|
|
LogType = LogType.process,
|
|
|
|
|
Message = "Layer not found",
|
|
|
|
|
CreatedAt = DateTime.UtcNow
|
|
|
|
|
});
|
|
|
|
|
return BadRequest("Layer not found");
|
2023-11-29 22:14:37 +01:00
|
|
|
}
|
2024-03-06 16:48:11 +01:00
|
|
|
Layer processWorker = db.Layers
|
|
|
|
|
.Include(x => x.Records)
|
|
|
|
|
.Where(x => x.Id == layer.ParentId && !x.IsDeleted).First();
|
|
|
|
|
|
|
|
|
|
if (processWorker == null)
|
|
|
|
|
{
|
|
|
|
|
logsController.AddEntry(new LogEntry
|
|
|
|
|
{
|
|
|
|
|
Title = "Process error",
|
|
|
|
|
Type = LogEntryType.error,
|
|
|
|
|
LogType = LogType.process,
|
|
|
|
|
Message = "ProcessWorker not found",
|
|
|
|
|
CreatedAt = DateTime.UtcNow
|
|
|
|
|
});
|
|
|
|
|
return BadRequest("ProcessWorker not found");
|
|
|
|
|
}
|
|
|
|
|
ProcessLayer(processWorker, true);
|
2023-11-29 22:14:37 +01:00
|
|
|
return Ok();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
logsController.AddEntry(new LogEntry
|
|
|
|
|
{
|
|
|
|
|
Title = "Process error",
|
|
|
|
|
Type = LogEntryType.error,
|
|
|
|
|
LogType = LogType.process,
|
|
|
|
|
Message = e.ToString(),
|
|
|
|
|
CreatedAt = DateTime.UtcNow
|
|
|
|
|
});
|
|
|
|
|
return BadRequest(e.ToString());
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-03-06 16:48:11 +01:00
|
|
|
internal void ProcessLayer(Layer processWorker, bool alwaysProcess = false)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
string? name = processWorker.Name;
|
|
|
|
|
string? year = processWorker?.Records?.SingleOrDefault(x => x.Code == "Year")?.Desc1;
|
|
|
|
|
if (year == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Year record nod found");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!alwaysProcess && int.Parse(year!) < DateTime.UtcNow.Year)
|
|
|
|
|
{
|
|
|
|
|
logsController.AddEntry(new LogEntry
|
|
|
|
|
{
|
|
|
|
|
Title = $"{processWorker!.Name}, {processWorker.Id}",
|
|
|
|
|
Type = LogEntryType.warning,
|
|
|
|
|
LogType = LogType.process,
|
|
|
|
|
Message = "processLayer is out of date. Should be disabled. Not processed.",
|
|
|
|
|
CreatedAt = DateTime.UtcNow
|
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string? processType = processWorker?.Records?.SingleOrDefault(x => x.Code == "ProcessType")?.Desc1;
|
|
|
|
|
if (processType == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("ProcessType record not found");
|
|
|
|
|
}
|
|
|
|
|
if (processType == "T3-SourceYearSummary")
|
|
|
|
|
{
|
|
|
|
|
if (!alwaysProcess && int.Parse(year!) < DateTime.UtcNow.Year)
|
|
|
|
|
{
|
|
|
|
|
logsController.AddEntry(new LogEntry
|
|
|
|
|
{
|
|
|
|
|
Title = $"{processWorker!.Name}, {processWorker.Id}",
|
|
|
|
|
Type = LogEntryType.warning,
|
|
|
|
|
LogType = LogType.process,
|
|
|
|
|
Message = "processLayer is out of date. Should be disabled. Not processed",
|
|
|
|
|
CreatedAt = DateTime.UtcNow
|
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
T3SourceYearSummaryProcessor processor = new T3SourceYearSummaryProcessor(db, googleSheetValues, this);
|
|
|
|
|
processor.process(processWorker!);
|
|
|
|
|
|
|
|
|
|
logsController.AddEntry(new LogEntry
|
|
|
|
|
{
|
|
|
|
|
Title = $"{processWorker!.Name}, {processWorker.Id}",
|
|
|
|
|
Type = LogEntryType.info,
|
|
|
|
|
LogType = LogType.process,
|
|
|
|
|
Message = "Success",
|
|
|
|
|
CreatedAt = DateTime.UtcNow
|
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (processType == "T3-MultiSourceYearSummary")
|
|
|
|
|
{
|
|
|
|
|
if (!alwaysProcess && int.Parse(year!) < DateTime.UtcNow.Year)
|
|
|
|
|
{
|
|
|
|
|
logsController.AddEntry(new LogEntry
|
|
|
|
|
{
|
|
|
|
|
Title = $"{processWorker!.Name}, {processWorker.Id}",
|
|
|
|
|
Type = LogEntryType.warning,
|
|
|
|
|
LogType = LogType.process,
|
|
|
|
|
Message = "processLayer is out of date. Should be disabled. Not processed",
|
|
|
|
|
CreatedAt = DateTime.UtcNow
|
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
T3MultiSourceYearSummaryProcessor processor = new T3MultiSourceYearSummaryProcessor(db, googleSheetValues, this);
|
|
|
|
|
processor.process(processWorker!);
|
|
|
|
|
|
|
|
|
|
logsController.AddEntry(new LogEntry
|
|
|
|
|
{
|
|
|
|
|
Title = $"{processWorker!.Name}, {processWorker.Id}",
|
|
|
|
|
Type = LogEntryType.info,
|
|
|
|
|
LogType = LogType.process,
|
|
|
|
|
Message = "Success",
|
|
|
|
|
CreatedAt = DateTime.UtcNow
|
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
string? month = processWorker?.Records?.SingleOrDefault(x => x.Code == "Month")?.Desc1;
|
|
|
|
|
if (month == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Month record not found");
|
|
|
|
|
}
|
|
|
|
|
if (!alwaysProcess && int.Parse(month!) < DateTime.UtcNow.Month)
|
|
|
|
|
{
|
|
|
|
|
logsController.AddEntry(new LogEntry
|
|
|
|
|
{
|
|
|
|
|
Title = $"{processWorker!.Name}, {processWorker.Id}",
|
|
|
|
|
Type = LogEntryType.warning,
|
|
|
|
|
LogType = LogType.process,
|
|
|
|
|
Message = "processLayer is out of date. Should be disabled. Not processed",
|
|
|
|
|
CreatedAt = DateTime.UtcNow
|
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
switch (processType!)
|
|
|
|
|
{
|
|
|
|
|
case "T3-SingleSource":
|
|
|
|
|
{
|
|
|
|
|
T3SingleSourceProcessor processor = new T3SingleSourceProcessor(db, googleSheetValues, this);
|
|
|
|
|
processor.process(processWorker!);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case "T3-MultiSourceSummary":
|
|
|
|
|
{
|
|
|
|
|
T3MultiSourceSummaryProcessor processor = new T3MultiSourceSummaryProcessor(db, googleSheetValues, this);
|
|
|
|
|
processor.process(processWorker!);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case "T3-MultiSourceCopySelectedCodes":
|
|
|
|
|
{
|
|
|
|
|
T3MultiSourceCopySelectedCodesProcessor processor = new T3MultiSourceCopySelectedCodesProcessor(db, googleSheetValues, this);
|
|
|
|
|
processor.process(processWorker!);
|
|
|
|
|
processor.updateReport();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
logsController.AddEntry(new LogEntry
|
|
|
|
|
{
|
|
|
|
|
Title = $"{processWorker!.Name}, {processWorker.Id}",
|
|
|
|
|
Type = LogEntryType.info,
|
|
|
|
|
LogType = LogType.process,
|
|
|
|
|
Message = "Success",
|
|
|
|
|
CreatedAt = DateTime.UtcNow
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-29 22:14:37 +01:00
|
|
|
internal void SaveRecords(Guid id, ICollection<Record> records, Guid currentUserId)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
List<Record> toDelete = db.Records.Where(x => x.LayerId == id).ToList();
|
|
|
|
|
if (toDelete.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
db.Records.RemoveRange(toDelete);
|
|
|
|
|
}
|
|
|
|
|
foreach (Record record in records)
|
|
|
|
|
{
|
|
|
|
|
record.CreatedById = currentUserId;
|
|
|
|
|
record.CreatedAt = DateTime.UtcNow;
|
|
|
|
|
record.ModifiedById = currentUserId;
|
|
|
|
|
record.ModifiedAt = DateTime.UtcNow;
|
|
|
|
|
record.LayerId = id;
|
|
|
|
|
db.Records.Add(record);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-12-11 23:40:16 +01:00
|
|
|
}
|