R3 is ready

This commit is contained in:
Michał Zieliński
2024-12-22 13:35:43 +01:00
parent 1fc00ac419
commit a72c1488ba
3 changed files with 30 additions and 9 deletions

View File

@@ -1,10 +1,8 @@
using System.Globalization;
using System.Text.RegularExpressions;
using DiunaBIWebAPI.dataProcessors;
using Google;
using Google.Apis.Sheets.v4;
using Google.Apis.Sheets.v4.Data;
using Microsoft.AspNetCore.Http.HttpResults;
using Microsoft.EntityFrameworkCore;
using WebAPI.Controllers;
using WebAPI.Models;
@@ -14,12 +12,10 @@ namespace WebAPI.dataProcessors;
public class T1R3Processor(
AppDbContext db,
LayersController controller,
LogsController logsController,
SpreadsheetsResource.ValuesResource googleSheetValues)
{
public void Process(Layer processWorker)
{
var year = int.Parse(processWorker.Records?.SingleOrDefault(x => x.Code == "Year")?.Desc1!);
var source = processWorker.Records?.Where(x => x.Code == "Source").First().Desc1;
if (source == null)
@@ -127,7 +123,7 @@ public class T1R3Processor(
{
dataRangeResponse = googleSheetValues.Get(sheetId, $"{sheetName}!A7:A200").Execute();
}
catch (GoogleApiException ex)
catch
{
continue; // Sheet not exist
}
@@ -147,7 +143,7 @@ public class T1R3Processor(
var updateRow = new List<object>();
for (var j = 1; j < 12; j++)
for (var j = 1; j < 16; j++)
{
var codeRecord = r3!.Records!.FirstOrDefault(x => x.Code == $"{code}{i:D2}{j:D2}");
if (codeRecord is { Value1: not null })
@@ -167,6 +163,29 @@ public class T1R3Processor(
var update = googleSheetValues.Update(updateValueRange, sheetId, $"{sheetName}!C7:Q200");
update.ValueInputOption = SpreadsheetsResource.ValuesResource.UpdateRequest.ValueInputOptionEnum.USERENTERED;
update.Execute();
// update time
var timeUtc = new List<object>
{
r3!.ModifiedAt.ToString("dd.MM.yyyy HH:mm:ss", CultureInfo.GetCultureInfo("pl-PL"))
};
var warsawTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Central European Standard Time");
var warsawTime = TimeZoneInfo.ConvertTimeFromUtc(r3.ModifiedAt.ToUniversalTime(), warsawTimeZone);
var timeWarsaw = new List<object>
{
warsawTime.ToString("dd.MM.yyyy HH:mm:ss", CultureInfo.GetCultureInfo("pl-PL"))
};
var valueRangeTime = new ValueRange
{
Values = new List<IList<object>> ()
};
valueRangeTime.Values.Add(timeUtc);
valueRangeTime.Values.Add(timeWarsaw);
var updateTimeUtc = googleSheetValues.Update(valueRangeTime, sheetId, $"{sheetName}!G1:G2");
updateTimeUtc.ValueInputOption =
SpreadsheetsResource.ValuesResource.UpdateRequest.ValueInputOptionEnum.USERENTERED;
updateTimeUtc.Execute();
}
}
}