Rename R1/R1_V2
This commit is contained in:
@@ -352,9 +352,9 @@ public class LayersController : Controller
|
|||||||
"T3-MultiSourceSummary", // AA
|
"T3-MultiSourceSummary", // AA
|
||||||
"T3-MultiSourceYearSummary", // AA/13
|
"T3-MultiSourceYearSummary", // AA/13
|
||||||
"T4-SingleSource",
|
"T4-SingleSource",
|
||||||
|
"T1-R1_OLD",
|
||||||
"T1-R1",
|
"T1-R1",
|
||||||
"T4-R2",
|
"T4-R2",
|
||||||
"T1-R1_V2"
|
|
||||||
];
|
];
|
||||||
|
|
||||||
foreach (var type in processTypes)
|
foreach (var type in processTypes)
|
||||||
@@ -491,9 +491,9 @@ public class LayersController : Controller
|
|||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
case "T1-R1":
|
case "T1-R1_OLD":
|
||||||
{
|
{
|
||||||
var processor = new T1R1Processor(_db, _googleSheetValues, this, _logsController);
|
var processor = new T1R1OldProcessor(_db, _googleSheetValues, this, _logsController);
|
||||||
processor.Process(processWorker);
|
processor.Process(processWorker);
|
||||||
|
|
||||||
_logsController.AddEntry(new LogEntry
|
_logsController.AddEntry(new LogEntry
|
||||||
@@ -506,9 +506,9 @@ public class LayersController : Controller
|
|||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
case "T1-R1_V2":
|
case "T1-R1":
|
||||||
{
|
{
|
||||||
var processor = new T1R1V2Processor(_db, _googleSheetValues, this, _logsController);
|
var processor = new T1R1Processor(_db, _googleSheetValues, this, _logsController);
|
||||||
processor.Process(processWorker);
|
processor.Process(processWorker);
|
||||||
|
|
||||||
_logsController.AddEntry(new LogEntry
|
_logsController.AddEntry(new LogEntry
|
||||||
|
|||||||
261
WebAPI/dataProcessors/t1.r1.old.processor.cs
Normal file
261
WebAPI/dataProcessors/t1.r1.old.processor.cs
Normal file
@@ -0,0 +1,261 @@
|
|||||||
|
using System.Globalization;
|
||||||
|
using DiunaBIWebAPI.dataProcessors;
|
||||||
|
using Google.Apis.Sheets.v4;
|
||||||
|
using Google.Apis.Sheets.v4.Data;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using WebAPI.Controllers;
|
||||||
|
using WebAPI.Models;
|
||||||
|
|
||||||
|
namespace WebAPI.dataProcessors;
|
||||||
|
|
||||||
|
public class T1R1OldProcessor(
|
||||||
|
AppDbContext db,
|
||||||
|
SpreadsheetsResource.ValuesResource googleSheetValues,
|
||||||
|
LayersController 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!.Count == 0)
|
||||||
|
{
|
||||||
|
throw new Exception("Source record not found");
|
||||||
|
}
|
||||||
|
var codes = processWorker.Records?.SingleOrDefault(x => x.Code == "Codes")?.Desc1;
|
||||||
|
if (codes == null)
|
||||||
|
{
|
||||||
|
throw new Exception("Codes record not found");
|
||||||
|
}
|
||||||
|
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(),
|
||||||
|
Type = LayerType.Processed,
|
||||||
|
ParentId = processWorker.Id,
|
||||||
|
Number = db.Layers.Count() + 1
|
||||||
|
};
|
||||||
|
processedLayer.Name = $"L{processedLayer.Number}-P-{year}-R1-T1";
|
||||||
|
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 = new List<Layer>();
|
||||||
|
|
||||||
|
foreach (var source in sources)
|
||||||
|
{
|
||||||
|
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}-T3")
|
||||||
|
)
|
||||||
|
.Include(x => x.Records)
|
||||||
|
.FirstOrDefault();
|
||||||
|
if (dataSource != null)
|
||||||
|
{
|
||||||
|
dataSources.Add(dataSource);
|
||||||
|
}
|
||||||
|
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 summary
|
||||||
|
var dataSourceSum = 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 (dataSourceSum != null)
|
||||||
|
{
|
||||||
|
dataSources.Add(dataSourceSum);
|
||||||
|
}
|
||||||
|
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 (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 layer = dataSources.SingleOrDefault(y => y.Id == x.LayerId);
|
||||||
|
var postFix = layer!.Name!.Split("/")[1].Split("-")[0];
|
||||||
|
if (postFix.Length == 1)
|
||||||
|
{
|
||||||
|
postFix = "0" + postFix;
|
||||||
|
}
|
||||||
|
|
||||||
|
var newRecord = new Record
|
||||||
|
{
|
||||||
|
Id = Guid.NewGuid(),
|
||||||
|
Code = x.Code + postFix,
|
||||||
|
CreatedAt = DateTime.UtcNow,
|
||||||
|
ModifiedAt = DateTime.UtcNow,
|
||||||
|
Value1 = x.Value32
|
||||||
|
};
|
||||||
|
|
||||||
|
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();
|
||||||
|
|
||||||
|
UpdateReport();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateReport()
|
||||||
|
{
|
||||||
|
const string sheetId = "1pph-XowjlK5CIaCEV_A5buK4ceJ0Z0YoUlDI4VMkhhA";
|
||||||
|
const string sheetName = "OLD_Raport_R1_Eksport";
|
||||||
|
var request = googleSheetValues.Get(sheetId, "C4:EX4");
|
||||||
|
var response = request.Execute();
|
||||||
|
|
||||||
|
var r1 = db.Layers
|
||||||
|
.Where(x => x.Number == 1205)
|
||||||
|
.Include(x => x.Records)
|
||||||
|
.FirstOrDefault();
|
||||||
|
|
||||||
|
const int startRow = 6;
|
||||||
|
|
||||||
|
var codesRow = response.Values[0];
|
||||||
|
for (var i = 1; i <= DateTime.UtcNow.Month; i++)
|
||||||
|
{
|
||||||
|
var values = new List<object>();
|
||||||
|
var month = i < 10 ? $"0{i}" : i.ToString();
|
||||||
|
var row = (startRow + i).ToString();
|
||||||
|
foreach (string code in codesRow)
|
||||||
|
{
|
||||||
|
var record = r1!.Records?.SingleOrDefault(x => x.Code == $"{code}{month}");
|
||||||
|
if (record != null)
|
||||||
|
{
|
||||||
|
values.Add(record.Value1!.Value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
values.Add("0");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var valueRange = new ValueRange
|
||||||
|
{
|
||||||
|
Values = new List<IList<object>> { values }
|
||||||
|
};
|
||||||
|
var update = googleSheetValues.Update(valueRange, sheetId, $"{sheetName}!C{row}:XZ{row}");
|
||||||
|
update.ValueInputOption = SpreadsheetsResource.ValuesResource.UpdateRequest.ValueInputOptionEnum.USERENTERED;
|
||||||
|
update.Execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
// sum
|
||||||
|
var valuesSum = new List<object>();
|
||||||
|
var emptyRow = new List<object>();
|
||||||
|
var rowEmpty = (startRow + DateTime.UtcNow.Month + 1).ToString();
|
||||||
|
var rowSum = (startRow + DateTime.UtcNow.Month + 2).ToString();
|
||||||
|
foreach (string code in codesRow)
|
||||||
|
{
|
||||||
|
var record = r1!.Records?.SingleOrDefault(x => x.Code == $"{code}13");
|
||||||
|
emptyRow.Add("");
|
||||||
|
if (record != null)
|
||||||
|
{
|
||||||
|
valuesSum.Add(record.Value1!.Value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
valuesSum.Add("0");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// insert empty row before sum
|
||||||
|
var valueRangeEmpty = new ValueRange
|
||||||
|
{
|
||||||
|
Values = new List<IList<object>> { emptyRow }
|
||||||
|
};
|
||||||
|
var updateEmpty = googleSheetValues.Update(valueRangeEmpty, sheetId, $"{sheetName}!C{rowEmpty}:XZ{rowEmpty}");
|
||||||
|
updateEmpty.ValueInputOption = SpreadsheetsResource.ValuesResource.UpdateRequest.ValueInputOptionEnum.USERENTERED;
|
||||||
|
updateEmpty.Execute();
|
||||||
|
|
||||||
|
var valueRangeSum = new ValueRange
|
||||||
|
{
|
||||||
|
Values = new List<IList<object>> { valuesSum }
|
||||||
|
};
|
||||||
|
var updateSum = googleSheetValues.Update(valueRangeSum, sheetId, $"{sheetName}!C{rowSum}:XZ{rowSum}");
|
||||||
|
updateSum.ValueInputOption = SpreadsheetsResource.ValuesResource.UpdateRequest.ValueInputOptionEnum.USERENTERED;
|
||||||
|
updateSum.Execute();
|
||||||
|
|
||||||
|
// update time
|
||||||
|
var timeUtc = new List<object>
|
||||||
|
{
|
||||||
|
r1!.ModifiedAt.ToString("dd.MM.yyyy HH:mm:ss", CultureInfo.GetCultureInfo("pl-PL"))
|
||||||
|
};
|
||||||
|
var valueRangeUtcTime = new ValueRange
|
||||||
|
{
|
||||||
|
Values = new List<IList<object>> { timeUtc }
|
||||||
|
};
|
||||||
|
var updateTimeUtc = googleSheetValues.Update(valueRangeUtcTime, sheetId, $"{sheetName}!G1");
|
||||||
|
updateTimeUtc.ValueInputOption = SpreadsheetsResource.ValuesResource.UpdateRequest.ValueInputOptionEnum.USERENTERED;
|
||||||
|
updateTimeUtc.Execute();
|
||||||
|
|
||||||
|
var warsawTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Central European Standard Time");
|
||||||
|
var warsawTime = TimeZoneInfo.ConvertTimeFromUtc(r1.ModifiedAt.ToUniversalTime(), warsawTimeZone);
|
||||||
|
var timeWarsaw = new List<object>
|
||||||
|
{
|
||||||
|
warsawTime.ToString("dd.MM.yyyy HH:mm:ss", CultureInfo.GetCultureInfo("pl-PL"))
|
||||||
|
};
|
||||||
|
var valueRangeWarsawTime = new ValueRange
|
||||||
|
{
|
||||||
|
Values = new List<IList<object>> { timeWarsaw }
|
||||||
|
};
|
||||||
|
var updateTimeWarsaw = googleSheetValues.Update(valueRangeWarsawTime, sheetId, $"{sheetName}!G2");
|
||||||
|
updateTimeWarsaw.ValueInputOption = SpreadsheetsResource.ValuesResource.UpdateRequest.ValueInputOptionEnum.USERENTERED;
|
||||||
|
updateTimeWarsaw.Execute();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,30 +3,18 @@ using DiunaBIWebAPI.dataProcessors;
|
|||||||
using Google.Apis.Sheets.v4;
|
using Google.Apis.Sheets.v4;
|
||||||
using Google.Apis.Sheets.v4.Data;
|
using Google.Apis.Sheets.v4.Data;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using WebAPI.Calculator;
|
||||||
using WebAPI.Controllers;
|
using WebAPI.Controllers;
|
||||||
using WebAPI.Models;
|
using WebAPI.Models;
|
||||||
|
|
||||||
namespace WebAPI.dataProcessors;
|
namespace WebAPI.dataProcessors;
|
||||||
|
|
||||||
public class T1R1Processor
|
public class T1R1Processor(
|
||||||
{
|
|
||||||
private readonly AppDbContext _db;
|
|
||||||
private readonly SpreadsheetsResource.ValuesResource _googleSheetValues;
|
|
||||||
private readonly LayersController _controller;
|
|
||||||
private readonly LogsController _logsController;
|
|
||||||
|
|
||||||
public T1R1Processor(
|
|
||||||
AppDbContext db,
|
AppDbContext db,
|
||||||
SpreadsheetsResource.ValuesResource googleSheetValues,
|
SpreadsheetsResource.ValuesResource googleSheetValues,
|
||||||
LayersController controller,
|
LayersController controller,
|
||||||
LogsController logsController)
|
LogsController logsController)
|
||||||
{
|
{
|
||||||
_db = db;
|
|
||||||
_googleSheetValues = googleSheetValues;
|
|
||||||
_controller = controller;
|
|
||||||
_logsController = logsController;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Process(Layer processWorker)
|
public void Process(Layer processWorker)
|
||||||
{
|
{
|
||||||
var year = int.Parse(processWorker.Records?.SingleOrDefault(x => x.Code == "Year")?.Desc1!);
|
var year = int.Parse(processWorker.Records?.SingleOrDefault(x => x.Code == "Year")?.Desc1!);
|
||||||
@@ -35,14 +23,8 @@ public class T1R1Processor
|
|||||||
{
|
{
|
||||||
throw new Exception("Source record not found");
|
throw new Exception("Source record not found");
|
||||||
}
|
}
|
||||||
var codes = processWorker.Records?.SingleOrDefault(x => x.Code == "Codes")?.Desc1;
|
|
||||||
if (codes == null)
|
|
||||||
{
|
|
||||||
throw new Exception("Codes record not found");
|
|
||||||
}
|
|
||||||
var codesList = ProcessHelper.ParseCodes(codes);
|
|
||||||
|
|
||||||
var processedLayer = _db.Layers
|
var processedLayer = db.Layers
|
||||||
.Where(x => x.ParentId == processWorker.Id
|
.Where(x => x.ParentId == processWorker.Id
|
||||||
&& !x.IsDeleted)
|
&& !x.IsDeleted)
|
||||||
.OrderByDescending(x => x.CreatedAt)
|
.OrderByDescending(x => x.CreatedAt)
|
||||||
@@ -57,9 +39,9 @@ public class T1R1Processor
|
|||||||
Id = Guid.NewGuid(),
|
Id = Guid.NewGuid(),
|
||||||
Type = LayerType.Processed,
|
Type = LayerType.Processed,
|
||||||
ParentId = processWorker.Id,
|
ParentId = processWorker.Id,
|
||||||
Number = _db.Layers.Count() + 1
|
Number = db.Layers.Count() + 1
|
||||||
};
|
};
|
||||||
processedLayer.Name = $"L{processedLayer.Number}-P-{year}-R1-T1";
|
processedLayer.Name = $"L{processedLayer.Number}-P-{year}-R1_V2-T1";
|
||||||
processedLayer.CreatedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D");
|
processedLayer.CreatedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D");
|
||||||
processedLayer.ModifiedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D");
|
processedLayer.ModifiedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D");
|
||||||
processedLayer.CreatedAt = DateTime.UtcNow;
|
processedLayer.CreatedAt = DateTime.UtcNow;
|
||||||
@@ -69,101 +51,133 @@ public class T1R1Processor
|
|||||||
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;
|
||||||
|
|
||||||
var dataSources = new List<Layer>();
|
var dynamicCodes = processWorker.Records?.Where(x => x.Code!.Contains("DynamicCode-"))
|
||||||
|
.OrderBy(x => int.Parse(x.Code!.Split('-')[1]))
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
var newRecords = new List<Record>();
|
||||||
|
|
||||||
|
for (var month = 1; month <= 14; month++)
|
||||||
|
{
|
||||||
|
if (month > DateTime.UtcNow.Month && month != 13)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
var records = new List<Record>();
|
||||||
foreach (var source in sources)
|
foreach (var source in sources)
|
||||||
{
|
|
||||||
for (var month = 1; month <= DateTime.UtcNow.Month; month++)
|
|
||||||
{
|
{
|
||||||
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")
|
||||||
)
|
).Include(x => x.Records)
|
||||||
.Include(x => x.Records)
|
|
||||||
.FirstOrDefault();
|
.FirstOrDefault();
|
||||||
if (dataSource != null)
|
|
||||||
|
if (dataSource == null)
|
||||||
{
|
{
|
||||||
dataSources.Add(dataSource);
|
throw new Exception($"Source layer {year}/{monthCopy}-{source.Desc1}-T3 not found.");
|
||||||
|
}
|
||||||
|
|
||||||
|
var codesRecord = processWorker.Records?.Where(x => x.Code == $"Codes-{source.Desc1}").FirstOrDefault();
|
||||||
|
if (codesRecord != null)
|
||||||
|
{
|
||||||
|
var codes = ProcessHelper.ParseCodes(codesRecord.Desc1!);
|
||||||
|
records.AddRange(dataSource.Records!.Where(x => codes.Contains(int.Parse(x.Code!))));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_logsController.AddEntry(new LogEntry
|
records.AddRange(dataSource.Records!);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dynamicCodes != null)
|
||||||
|
{
|
||||||
|
foreach (var dynamicCode in dynamicCodes)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (dynamicCode.Desc1 == null)
|
||||||
|
{
|
||||||
|
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 = $"Formula in Record {dynamicCode.Id} is missing.",
|
||||||
CreatedAt = DateTime.UtcNow
|
CreatedAt = DateTime.UtcNow
|
||||||
});
|
});
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// year summary
|
var calc = new BaseCalc(dynamicCode.Desc1);
|
||||||
var dataSourceSum = _db.Layers.Where(x =>
|
if (!calc.IsFormulaCorrect())
|
||||||
x.Type == LayerType.Processed &&
|
|
||||||
!x.IsDeleted &&
|
|
||||||
x.Name != null && x.Name.Contains($"{year}/13-{source.Desc1}-T3")
|
|
||||||
)
|
|
||||||
.Include(x => x.Records)
|
|
||||||
.FirstOrDefault();
|
|
||||||
if (dataSourceSum != null)
|
|
||||||
{
|
{
|
||||||
dataSources.Add(dataSourceSum);
|
logsController.AddEntry(new LogEntry
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_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 = $"Formula {calc.Expression} in Record {dynamicCode.Id} is not correct",
|
||||||
|
CreatedAt = DateTime.UtcNow
|
||||||
|
});
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
records.Add(calc.CalculateT1(records));
|
||||||
|
}
|
||||||
|
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
|
CreatedAt = DateTime.UtcNow
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
|
||||||
if (dataSources.Count == 0)
|
|
||||||
{
|
{
|
||||||
throw new Exception("DataSources are empty");
|
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
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var newRecords = dataSources
|
newRecords.AddRange(records.Select(x => new Record
|
||||||
.SelectMany(x => x.Records!)
|
|
||||||
.Where(x => codesList.Contains(int.Parse(x.Code!)))
|
|
||||||
.Select(x =>
|
|
||||||
{
|
|
||||||
var layer = dataSources.SingleOrDefault(y => y.Id == x.LayerId);
|
|
||||||
var postFix = layer!.Name!.Split("/")[1].Split("-")[0];
|
|
||||||
if (postFix.Length == 1)
|
|
||||||
{
|
|
||||||
postFix = "0" + postFix;
|
|
||||||
}
|
|
||||||
|
|
||||||
var newRecord = new Record
|
|
||||||
{
|
{
|
||||||
Id = Guid.NewGuid(),
|
Id = Guid.NewGuid(),
|
||||||
Code = x.Code + postFix,
|
Code = x.Code + month.ToString("D2"),
|
||||||
CreatedAt = DateTime.UtcNow,
|
CreatedAt = DateTime.UtcNow,
|
||||||
ModifiedAt = DateTime.UtcNow,
|
ModifiedAt = DateTime.UtcNow,
|
||||||
Value1 = x.Value32
|
Value1 = x.Value32
|
||||||
};
|
}
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
return newRecord;
|
|
||||||
})
|
|
||||||
.ToList();
|
|
||||||
if (isNew)
|
if (isNew)
|
||||||
{
|
{
|
||||||
_db.Layers.Add(processedLayer);
|
db.Layers.Add(processedLayer);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_db.Layers.Update(processedLayer);
|
db.Layers.Update(processedLayer);
|
||||||
}
|
}
|
||||||
_controller.SaveRecords(processedLayer.Id, newRecords, Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"));
|
|
||||||
_db.SaveChanges();
|
controller.SaveRecords(processedLayer.Id, newRecords, Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"));
|
||||||
|
db.SaveChanges();
|
||||||
|
|
||||||
UpdateReport();
|
UpdateReport();
|
||||||
}
|
}
|
||||||
@@ -172,18 +186,24 @@ public class T1R1Processor
|
|||||||
{
|
{
|
||||||
const string sheetId = "1pph-XowjlK5CIaCEV_A5buK4ceJ0Z0YoUlDI4VMkhhA";
|
const string sheetId = "1pph-XowjlK5CIaCEV_A5buK4ceJ0Z0YoUlDI4VMkhhA";
|
||||||
const string sheetName = "Raport_R1_Eksport";
|
const string sheetName = "Raport_R1_Eksport";
|
||||||
var request = _googleSheetValues.Get(sheetId, "C4:EX4");
|
var request = googleSheetValues.Get(sheetId, $"{sheetName}!C4:CM4");
|
||||||
var response = request.Execute();
|
var response = request.Execute();
|
||||||
|
|
||||||
var r1 = _db.Layers
|
var r1 = db.Layers
|
||||||
.Where(x => x.Number == 1205)
|
.Where(x => x.Number == 2286)
|
||||||
.Include(x => x.Records)
|
.Include(x => x.Records)
|
||||||
.FirstOrDefault();
|
.FirstOrDefault();
|
||||||
|
|
||||||
const int startRow = 6;
|
const int startRow = 6;
|
||||||
|
|
||||||
var codesRow = response.Values[0];
|
var codesRow = response.Values[0];
|
||||||
for (var i = 1; i <= DateTime.UtcNow.Month; i++)
|
|
||||||
|
var valueRange = new ValueRange
|
||||||
|
{
|
||||||
|
Values = new List<IList<object>>()
|
||||||
|
};
|
||||||
|
|
||||||
|
for (var i = 1; i <= 12; i++)
|
||||||
{
|
{
|
||||||
var values = new List<object>();
|
var values = new List<object>();
|
||||||
var month = i < 10 ? $"0{i}" : i.ToString();
|
var month = i < 10 ? $"0{i}" : i.ToString();
|
||||||
@@ -200,20 +220,14 @@ public class T1R1Processor
|
|||||||
values.Add("0");
|
values.Add("0");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var valueRange = new ValueRange
|
valueRange.Values.Add(values);
|
||||||
{
|
|
||||||
Values = new List<IList<object>> { values }
|
|
||||||
};
|
|
||||||
var update = _googleSheetValues.Update(valueRange, sheetId, $"{sheetName}!C{row}:XZ{row}");
|
|
||||||
update.ValueInputOption = SpreadsheetsResource.ValuesResource.UpdateRequest.ValueInputOptionEnum.USERENTERED;
|
|
||||||
update.Execute();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// sum
|
// sum
|
||||||
var valuesSum = new List<object>();
|
var valuesSum = new List<object>();
|
||||||
var emptyRow = new List<object>();
|
var emptyRow = new List<object>();
|
||||||
var rowEmpty = (startRow + DateTime.UtcNow.Month + 1).ToString();
|
var rowEmpty = (startRow + 13).ToString();
|
||||||
var rowSum = (startRow + DateTime.UtcNow.Month + 2).ToString();
|
var rowSum = (startRow + 14).ToString();
|
||||||
foreach (string code in codesRow)
|
foreach (string code in codesRow)
|
||||||
{
|
{
|
||||||
var record = r1!.Records?.SingleOrDefault(x => x.Code == $"{code}13");
|
var record = r1!.Records?.SingleOrDefault(x => x.Code == $"{code}13");
|
||||||
@@ -227,48 +241,36 @@ public class T1R1Processor
|
|||||||
valuesSum.Add("0");
|
valuesSum.Add("0");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// insert empty row before sum
|
|
||||||
var valueRangeEmpty = new ValueRange
|
|
||||||
{
|
|
||||||
Values = new List<IList<object>> { emptyRow }
|
|
||||||
};
|
|
||||||
var updateEmpty = _googleSheetValues.Update(valueRangeEmpty, sheetId, $"{sheetName}!C{rowEmpty}:XZ{rowEmpty}");
|
|
||||||
updateEmpty.ValueInputOption = SpreadsheetsResource.ValuesResource.UpdateRequest.ValueInputOptionEnum.USERENTERED;
|
|
||||||
updateEmpty.Execute();
|
|
||||||
|
|
||||||
var valueRangeSum = new ValueRange
|
valueRange.Values.Add(emptyRow);
|
||||||
{
|
valueRange.Values.Add(valuesSum);
|
||||||
Values = new List<IList<object>> { valuesSum }
|
|
||||||
};
|
var update = googleSheetValues.Update(valueRange, sheetId, $"{sheetName}!C7:CM20");
|
||||||
var updateSum = _googleSheetValues.Update(valueRangeSum, sheetId, $"{sheetName}!C{rowSum}:XZ{rowSum}");
|
update.ValueInputOption =
|
||||||
updateSum.ValueInputOption = SpreadsheetsResource.ValuesResource.UpdateRequest.ValueInputOptionEnum.USERENTERED;
|
SpreadsheetsResource.ValuesResource.UpdateRequest.ValueInputOptionEnum.USERENTERED;
|
||||||
updateSum.Execute();
|
update.Execute();
|
||||||
|
|
||||||
// update time
|
// update time
|
||||||
var timeUtc = new List<object>
|
var timeUtc = new List<object>
|
||||||
{
|
{
|
||||||
r1!.ModifiedAt.ToString("dd.MM.yyyy HH:mm:ss", CultureInfo.GetCultureInfo("pl-PL"))
|
r1!.ModifiedAt.ToString("dd.MM.yyyy HH:mm:ss", CultureInfo.GetCultureInfo("pl-PL"))
|
||||||
};
|
};
|
||||||
var valueRangeUtcTime = new ValueRange
|
|
||||||
{
|
|
||||||
Values = new List<IList<object>> { timeUtc }
|
|
||||||
};
|
|
||||||
var updateTimeUtc = _googleSheetValues.Update(valueRangeUtcTime, sheetId, $"{sheetName}!G1");
|
|
||||||
updateTimeUtc.ValueInputOption = SpreadsheetsResource.ValuesResource.UpdateRequest.ValueInputOptionEnum.USERENTERED;
|
|
||||||
updateTimeUtc.Execute();
|
|
||||||
|
|
||||||
var warsawTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Central European Standard Time");
|
var warsawTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Central European Standard Time");
|
||||||
var warsawTime = TimeZoneInfo.ConvertTimeFromUtc(r1.ModifiedAt.ToUniversalTime(), warsawTimeZone);
|
var warsawTime = TimeZoneInfo.ConvertTimeFromUtc(r1.ModifiedAt.ToUniversalTime(), warsawTimeZone);
|
||||||
var timeWarsaw = new List<object>
|
var timeWarsaw = new List<object>
|
||||||
{
|
{
|
||||||
warsawTime.ToString("dd.MM.yyyy HH:mm:ss", CultureInfo.GetCultureInfo("pl-PL"))
|
warsawTime.ToString("dd.MM.yyyy HH:mm:ss", CultureInfo.GetCultureInfo("pl-PL"))
|
||||||
};
|
};
|
||||||
var valueRangeWarsawTime = new ValueRange
|
var valueRangeTime = new ValueRange
|
||||||
{
|
{
|
||||||
Values = new List<IList<object>> { timeWarsaw }
|
Values = new List<IList<object>> ()
|
||||||
};
|
};
|
||||||
var updateTimeWarsaw = _googleSheetValues.Update(valueRangeWarsawTime, sheetId, $"{sheetName}!G2");
|
valueRangeTime.Values.Add(timeUtc);
|
||||||
updateTimeWarsaw.ValueInputOption = SpreadsheetsResource.ValuesResource.UpdateRequest.ValueInputOptionEnum.USERENTERED;
|
valueRangeTime.Values.Add(timeWarsaw);
|
||||||
updateTimeWarsaw.Execute();
|
|
||||||
|
var updateTimeUtc = googleSheetValues.Update(valueRangeTime, sheetId, $"{sheetName}!G1:G2");
|
||||||
|
updateTimeUtc.ValueInputOption =
|
||||||
|
SpreadsheetsResource.ValuesResource.UpdateRequest.ValueInputOptionEnum.USERENTERED;
|
||||||
|
updateTimeUtc.Execute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,276 +0,0 @@
|
|||||||
using System.Globalization;
|
|
||||||
using DiunaBIWebAPI.dataProcessors;
|
|
||||||
using Google.Apis.Sheets.v4;
|
|
||||||
using Google.Apis.Sheets.v4.Data;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using WebAPI.Calculator;
|
|
||||||
using WebAPI.Controllers;
|
|
||||||
using WebAPI.Models;
|
|
||||||
|
|
||||||
namespace WebAPI.dataProcessors;
|
|
||||||
|
|
||||||
public class T1R1V2Processor(
|
|
||||||
AppDbContext db,
|
|
||||||
SpreadsheetsResource.ValuesResource googleSheetValues,
|
|
||||||
LayersController 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!.Count == 0)
|
|
||||||
{
|
|
||||||
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}-R1_V2-T1";
|
|
||||||
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 dynamicCodes = processWorker.Records?.Where(x => x.Code!.Contains("DynamicCode-"))
|
|
||||||
.OrderBy(x => int.Parse(x.Code!.Split('-')[1]))
|
|
||||||
.ToList();
|
|
||||||
|
|
||||||
var newRecords = new List<Record>();
|
|
||||||
|
|
||||||
for (var month = 1; month <= 14; month++)
|
|
||||||
{
|
|
||||||
if (month > DateTime.UtcNow.Month && month != 13)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
var records = new List<Record>();
|
|
||||||
foreach (var source in sources)
|
|
||||||
{
|
|
||||||
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}-T3")
|
|
||||||
).Include(x => x.Records)
|
|
||||||
.FirstOrDefault();
|
|
||||||
|
|
||||||
if (dataSource == null)
|
|
||||||
{
|
|
||||||
throw new Exception($"Source layer {year}/{monthCopy}-{source.Desc1}-T3 not found.");
|
|
||||||
}
|
|
||||||
|
|
||||||
var codesRecord = processWorker.Records?.Where(x => x.Code == $"Codes-{source.Desc1}").FirstOrDefault();
|
|
||||||
if (codesRecord != null)
|
|
||||||
{
|
|
||||||
var codes = ProcessHelper.ParseCodes(codesRecord.Desc1!);
|
|
||||||
records.AddRange(dataSource.Records!.Where(x => codes.Contains(int.Parse(x.Code!))));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
records.AddRange(dataSource.Records!);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dynamicCodes != null)
|
|
||||||
{
|
|
||||||
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
|
|
||||||
{
|
|
||||||
records.Add(calc.CalculateT1(records));
|
|
||||||
}
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
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
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
newRecords.AddRange(records.Select(x => new Record
|
|
||||||
{
|
|
||||||
Id = Guid.NewGuid(),
|
|
||||||
Code = x.Code + month.ToString("D2"),
|
|
||||||
CreatedAt = DateTime.UtcNow,
|
|
||||||
ModifiedAt = DateTime.UtcNow,
|
|
||||||
Value1 = x.Value32
|
|
||||||
}
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
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();
|
|
||||||
|
|
||||||
UpdateReport();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void UpdateReport()
|
|
||||||
{
|
|
||||||
const string sheetId = "1pph-XowjlK5CIaCEV_A5buK4ceJ0Z0YoUlDI4VMkhhA";
|
|
||||||
const string sheetName = "Raport_R1_V2_Eksport";
|
|
||||||
var request = googleSheetValues.Get(sheetId, $"{sheetName}!C4:CM4");
|
|
||||||
var response = request.Execute();
|
|
||||||
|
|
||||||
var r1 = db.Layers
|
|
||||||
.Where(x => x.Number == 2286)
|
|
||||||
.Include(x => x.Records)
|
|
||||||
.FirstOrDefault();
|
|
||||||
|
|
||||||
const int startRow = 6;
|
|
||||||
|
|
||||||
var codesRow = response.Values[0];
|
|
||||||
|
|
||||||
var valueRange = new ValueRange
|
|
||||||
{
|
|
||||||
Values = new List<IList<object>>()
|
|
||||||
};
|
|
||||||
|
|
||||||
for (var i = 1; i <= 12; i++)
|
|
||||||
{
|
|
||||||
var values = new List<object>();
|
|
||||||
var month = i < 10 ? $"0{i}" : i.ToString();
|
|
||||||
var row = (startRow + i).ToString();
|
|
||||||
foreach (string code in codesRow)
|
|
||||||
{
|
|
||||||
var record = r1!.Records?.SingleOrDefault(x => x.Code == $"{code}{month}");
|
|
||||||
if (record != null)
|
|
||||||
{
|
|
||||||
values.Add(record.Value1!.Value);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
values.Add("0");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
valueRange.Values.Add(values);
|
|
||||||
}
|
|
||||||
|
|
||||||
// sum
|
|
||||||
var valuesSum = new List<object>();
|
|
||||||
var emptyRow = new List<object>();
|
|
||||||
var rowEmpty = (startRow + 13).ToString();
|
|
||||||
var rowSum = (startRow + 14).ToString();
|
|
||||||
foreach (string code in codesRow)
|
|
||||||
{
|
|
||||||
var record = r1!.Records?.SingleOrDefault(x => x.Code == $"{code}13");
|
|
||||||
emptyRow.Add("");
|
|
||||||
if (record != null)
|
|
||||||
{
|
|
||||||
valuesSum.Add(record.Value1!.Value);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
valuesSum.Add("0");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
valueRange.Values.Add(emptyRow);
|
|
||||||
valueRange.Values.Add(valuesSum);
|
|
||||||
|
|
||||||
var update = googleSheetValues.Update(valueRange, sheetId, $"{sheetName}!C7:CM20");
|
|
||||||
update.ValueInputOption =
|
|
||||||
SpreadsheetsResource.ValuesResource.UpdateRequest.ValueInputOptionEnum.USERENTERED;
|
|
||||||
update.Execute();
|
|
||||||
|
|
||||||
// update time
|
|
||||||
var timeUtc = new List<object>
|
|
||||||
{
|
|
||||||
r1!.ModifiedAt.ToString("dd.MM.yyyy HH:mm:ss", CultureInfo.GetCultureInfo("pl-PL"))
|
|
||||||
};
|
|
||||||
var warsawTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Central European Standard Time");
|
|
||||||
var warsawTime = TimeZoneInfo.ConvertTimeFromUtc(r1.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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user