CopyProcessor: update existing layer
This commit is contained in:
@@ -252,18 +252,14 @@ namespace WebAPI.Controllers
|
||||
switch (processType)
|
||||
{
|
||||
case "Copy":
|
||||
CopyProcessor cp = new CopyProcessor(db, googleSheetValues);
|
||||
processedLayer = cp.process(sourceLayer, processWorker?.Id);
|
||||
CopyProcessor cp = new CopyProcessor(db, googleSheetValues, this);
|
||||
cp.process(sourceLayer, processWorker?.Id);
|
||||
break;
|
||||
case "Deaggregation":
|
||||
DeaggregationProcessor dp = new DeaggregationProcessor(db, googleSheetValues);
|
||||
processedLayer = dp.process(sourceLayer, processWorker?.Id);
|
||||
break;
|
||||
}
|
||||
if (processedLayer != null)
|
||||
{
|
||||
AddLayer(processedLayer, Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -394,7 +390,7 @@ namespace WebAPI.Controllers
|
||||
});
|
||||
|
||||
}
|
||||
private Layer AddLayer(Layer input, Guid currentUserId)
|
||||
public Layer AddLayer(Layer input, Guid currentUserId)
|
||||
{
|
||||
input.CreatedById = currentUserId;
|
||||
input.ModifiedById = currentUserId;
|
||||
@@ -406,7 +402,7 @@ namespace WebAPI.Controllers
|
||||
return input;
|
||||
}
|
||||
|
||||
private void SaveRecords(Guid id, ICollection<Record> records, Guid currentUserId)
|
||||
public void SaveRecords(Guid id, ICollection<Record> records, Guid currentUserId)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -432,7 +428,7 @@ namespace WebAPI.Controllers
|
||||
foreach (ProcessSource processSource in sources)
|
||||
{
|
||||
Console.WriteLine($"{processSource.LayerId} {processSource.SourceId}");
|
||||
// db.ProcessSources.Add(processSource);
|
||||
db.ProcessSources.Add(processSource);
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
using Google.Apis.Sheets.v4;
|
||||
using Azure;
|
||||
using Google.Apis.Sheets.v4;
|
||||
using Google.Apis.Sheets.v4.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Globalization;
|
||||
using WebAPI.Controllers;
|
||||
using WebAPI.Models;
|
||||
|
||||
namespace WebAPI.dataProcessors
|
||||
@@ -11,16 +13,19 @@ namespace WebAPI.dataProcessors
|
||||
{
|
||||
private AppDbContext db;
|
||||
private SpreadsheetsResource.ValuesResource googleSheetValues;
|
||||
private LayersController controller;
|
||||
|
||||
public CopyProcessor(
|
||||
AppDbContext _db,
|
||||
SpreadsheetsResource.ValuesResource _googleSheetValues)
|
||||
SpreadsheetsResource.ValuesResource _googleSheetValues,
|
||||
LayersController _controller)
|
||||
{
|
||||
db = _db;
|
||||
googleSheetValues = _googleSheetValues;
|
||||
controller = _controller;
|
||||
}
|
||||
|
||||
public Layer process(Layer sourceImportWorker, Guid? parentId)
|
||||
public void process(Layer sourceImportWorker, Guid? parentId)
|
||||
{
|
||||
string? sheetId = sourceImportWorker.Records!.Where(x => x.Code == "SheetId").FirstOrDefault()?.Desc1;
|
||||
if (sheetId == null)
|
||||
@@ -65,29 +70,48 @@ namespace WebAPI.dataProcessors
|
||||
{
|
||||
throw new Exception($"ImportMonth cell is empty, {sourceImportWorker.Name}");
|
||||
}
|
||||
|
||||
Layer? processedLayer = db.Layers
|
||||
.Where(x => x.ParentId == parentId)
|
||||
.OrderByDescending(x => x.CreatedAt)
|
||||
.FirstOrDefault();
|
||||
|
||||
if (processedLayer == null)
|
||||
{
|
||||
processedLayer = new Layer
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
Source = "",
|
||||
Type = LayerType.processed,
|
||||
ParentId = parentId,
|
||||
Number = db.Layers.Count() + 1,
|
||||
};
|
||||
processedLayer.Name = $"L{processedLayer.Number}-P-{name}-{year}/{month}-{DateTime.Now.ToString("yyyyMMddHHmm")}";
|
||||
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;
|
||||
db.Layers.Add(processedLayer);
|
||||
}
|
||||
|
||||
processedLayer.Records = new List<Record>();
|
||||
processedLayer.Sources = new List<ProcessSource>();
|
||||
processedLayer.ModifiedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D");
|
||||
processedLayer.ModifiedAt = DateTime.UtcNow;
|
||||
|
||||
Layer response = new Layer
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
Source = "",
|
||||
Type = LayerType.processed,
|
||||
ParentId = parentId,
|
||||
Number = db.Layers.Count() + 1,
|
||||
Records = new List<Record>(),
|
||||
Sources = new List<ProcessSource>()
|
||||
};
|
||||
|
||||
Layer dataSource = db.Layers
|
||||
.Include(x => x.Records)
|
||||
.Where(x => x.ParentId == sourceImportWorker.Id && !x.IsDeleted)
|
||||
.OrderByDescending(x => x.CreatedAt)
|
||||
.First();
|
||||
response.Sources.Add(new ProcessSource
|
||||
/*
|
||||
processedLayer.Sources.Add(new ProcessSource
|
||||
{
|
||||
LayerId = response.Id,
|
||||
LayerId = processedLayer.Id,
|
||||
SourceId = dataSource.Id
|
||||
});
|
||||
response.Name = $"L{response.Number}-P-{name}-{year}/{month}-{DateTime.Now.ToString("yyyyMMddHHmm")}";
|
||||
*/
|
||||
|
||||
foreach (Record source in dataSource.Records!)
|
||||
{
|
||||
@@ -99,9 +123,11 @@ namespace WebAPI.dataProcessors
|
||||
CreatedAt = DateTime.UtcNow,
|
||||
ModifiedAt = DateTime.UtcNow
|
||||
};
|
||||
response.Records.Add(record);
|
||||
processedLayer.Records.Add(record);
|
||||
}
|
||||
return response;
|
||||
controller.SaveRecords(processedLayer.Id, processedLayer.Records, Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"));
|
||||
db.Layers.Update(processedLayer);
|
||||
db.SaveChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user