D3 Importer

This commit is contained in:
Michał Zieliński
2025-07-26 11:11:24 +02:00
parent 9ddfbd83a2
commit ed680267a2
11 changed files with 1164 additions and 123 deletions

View File

@@ -0,0 +1,418 @@
// <auto-generated />
using System;
using DiunaBI.Core.Database.Context;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace DiunaBI.Core.Migrations
{
[DbContext(typeof(AppDbContext))]
[Migration("20250725133501_DataInbox.LayerId")]
partial class DataInboxLayerId
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.0")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("DiunaBI.Core.Models.DataInbox", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<DateTime>("CreatedAt")
.HasColumnType("datetime2");
b.Property<string>("Data")
.IsRequired()
.HasMaxLength(2147483647)
.HasColumnType("nvarchar(max)");
b.Property<Guid?>("LayerId")
.HasColumnType("uniqueidentifier");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("nvarchar(50)");
b.Property<string>("Source")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("nvarchar(50)");
b.HasKey("Id");
b.ToTable("DataInbox");
});
modelBuilder.Entity("DiunaBI.Core.Models.Layer", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<DateTime>("CreatedAt")
.HasColumnType("datetime2");
b.Property<Guid>("CreatedById")
.HasColumnType("uniqueidentifier");
b.Property<bool>("IsCancelled")
.HasColumnType("bit");
b.Property<bool>("IsDeleted")
.HasColumnType("bit");
b.Property<DateTime>("ModifiedAt")
.HasColumnType("datetime2");
b.Property<Guid>("ModifiedById")
.HasColumnType("uniqueidentifier");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("nvarchar(50)");
b.Property<int>("Number")
.HasColumnType("int");
b.Property<Guid?>("ParentId")
.HasColumnType("uniqueidentifier");
b.Property<int>("Type")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("CreatedById");
b.HasIndex("ModifiedById");
b.HasIndex("ParentId");
b.ToTable("Layers");
});
modelBuilder.Entity("DiunaBI.Core.Models.ProcessSource", b =>
{
b.Property<Guid>("LayerId")
.HasColumnType("uniqueidentifier");
b.Property<Guid>("SourceId")
.HasColumnType("uniqueidentifier");
b.HasKey("LayerId", "SourceId");
b.HasIndex("SourceId");
b.ToTable("ProcessSources");
});
modelBuilder.Entity("DiunaBI.Core.Models.QueueJob", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<DateTime?>("CompletedAt")
.HasColumnType("datetime2");
b.Property<DateTime>("CreatedAt")
.HasColumnType("datetime2");
b.Property<DateTime>("CreatedAtUtc")
.HasColumnType("datetime2");
b.Property<Guid>("CreatedById")
.HasColumnType("uniqueidentifier");
b.Property<int>("JobType")
.HasColumnType("int");
b.Property<DateTime?>("LastAttemptAt")
.HasColumnType("datetime2");
b.Property<string>("LastError")
.HasMaxLength(1000)
.HasColumnType("nvarchar(1000)");
b.Property<Guid>("LayerId")
.HasColumnType("uniqueidentifier");
b.Property<string>("LayerName")
.IsRequired()
.HasMaxLength(200)
.HasColumnType("nvarchar(200)");
b.Property<int>("MaxRetries")
.HasColumnType("int");
b.Property<DateTime>("ModifiedAtUtc")
.HasColumnType("datetime2");
b.Property<Guid>("ModifiedById")
.HasColumnType("uniqueidentifier");
b.Property<string>("PluginName")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("nvarchar(100)");
b.Property<int>("Priority")
.HasColumnType("int");
b.Property<int>("RetryCount")
.HasColumnType("int");
b.Property<int>("Status")
.HasColumnType("int");
b.HasKey("Id");
b.ToTable("QueueJobs");
});
modelBuilder.Entity("DiunaBI.Core.Models.Record", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<string>("Code")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("nvarchar(50)");
b.Property<DateTime>("CreatedAt")
.HasColumnType("datetime2");
b.Property<Guid>("CreatedById")
.HasColumnType("uniqueidentifier");
b.Property<string>("Desc1")
.HasMaxLength(10000)
.HasColumnType("nvarchar(max)");
b.Property<bool>("IsDeleted")
.HasColumnType("bit");
b.Property<Guid>("LayerId")
.HasColumnType("uniqueidentifier");
b.Property<DateTime>("ModifiedAt")
.HasColumnType("datetime2");
b.Property<Guid>("ModifiedById")
.HasColumnType("uniqueidentifier");
b.Property<double?>("Value1")
.HasColumnType("float");
b.Property<double?>("Value10")
.HasColumnType("float");
b.Property<double?>("Value11")
.HasColumnType("float");
b.Property<double?>("Value12")
.HasColumnType("float");
b.Property<double?>("Value13")
.HasColumnType("float");
b.Property<double?>("Value14")
.HasColumnType("float");
b.Property<double?>("Value15")
.HasColumnType("float");
b.Property<double?>("Value16")
.HasColumnType("float");
b.Property<double?>("Value17")
.HasColumnType("float");
b.Property<double?>("Value18")
.HasColumnType("float");
b.Property<double?>("Value19")
.HasColumnType("float");
b.Property<double?>("Value2")
.HasColumnType("float");
b.Property<double?>("Value20")
.HasColumnType("float");
b.Property<double?>("Value21")
.HasColumnType("float");
b.Property<double?>("Value22")
.HasColumnType("float");
b.Property<double?>("Value23")
.HasColumnType("float");
b.Property<double?>("Value24")
.HasColumnType("float");
b.Property<double?>("Value25")
.HasColumnType("float");
b.Property<double?>("Value26")
.HasColumnType("float");
b.Property<double?>("Value27")
.HasColumnType("float");
b.Property<double?>("Value28")
.HasColumnType("float");
b.Property<double?>("Value29")
.HasColumnType("float");
b.Property<double?>("Value3")
.HasColumnType("float");
b.Property<double?>("Value30")
.HasColumnType("float");
b.Property<double?>("Value31")
.HasColumnType("float");
b.Property<double?>("Value32")
.HasColumnType("float");
b.Property<double?>("Value4")
.HasColumnType("float");
b.Property<double?>("Value5")
.HasColumnType("float");
b.Property<double?>("Value6")
.HasColumnType("float");
b.Property<double?>("Value7")
.HasColumnType("float");
b.Property<double?>("Value8")
.HasColumnType("float");
b.Property<double?>("Value9")
.HasColumnType("float");
b.HasKey("Id");
b.HasIndex("CreatedById");
b.HasIndex("LayerId");
b.HasIndex("ModifiedById");
b.ToTable("Records");
});
modelBuilder.Entity("DiunaBI.Core.Models.User", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<DateTime>("CreatedAt")
.HasColumnType("datetime2");
b.Property<string>("Email")
.HasMaxLength(50)
.HasColumnType("nvarchar(50)");
b.Property<string>("UserName")
.HasMaxLength(50)
.HasColumnType("nvarchar(50)");
b.HasKey("Id");
b.ToTable("Users");
});
modelBuilder.Entity("DiunaBI.Core.Models.Layer", b =>
{
b.HasOne("DiunaBI.Core.Models.User", "CreatedBy")
.WithMany()
.HasForeignKey("CreatedById")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("DiunaBI.Core.Models.User", "ModifiedBy")
.WithMany()
.HasForeignKey("ModifiedById")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("DiunaBI.Core.Models.Layer", "Parent")
.WithMany()
.HasForeignKey("ParentId");
b.Navigation("CreatedBy");
b.Navigation("ModifiedBy");
b.Navigation("Parent");
});
modelBuilder.Entity("DiunaBI.Core.Models.ProcessSource", b =>
{
b.HasOne("DiunaBI.Core.Models.Layer", "Source")
.WithMany()
.HasForeignKey("SourceId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Source");
});
modelBuilder.Entity("DiunaBI.Core.Models.Record", b =>
{
b.HasOne("DiunaBI.Core.Models.User", "CreatedBy")
.WithMany()
.HasForeignKey("CreatedById")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("DiunaBI.Core.Models.Layer", null)
.WithMany("Records")
.HasForeignKey("LayerId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("DiunaBI.Core.Models.User", "ModifiedBy")
.WithMany()
.HasForeignKey("ModifiedById")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("CreatedBy");
b.Navigation("ModifiedBy");
});
modelBuilder.Entity("DiunaBI.Core.Models.Layer", b =>
{
b.Navigation("Records");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -0,0 +1,29 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace DiunaBI.Core.Migrations
{
/// <inheritdoc />
public partial class DataInboxLayerId : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<Guid>(
name: "LayerId",
table: "DataInbox",
type: "uniqueidentifier",
nullable: true);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "LayerId",
table: "DataInbox");
}
}
}

View File

@@ -0,0 +1,407 @@
// <auto-generated />
using System;
using DiunaBI.Core.Database.Context;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace DiunaBI.Core.Migrations
{
[DbContext(typeof(AppDbContext))]
[Migration("20250726091001_Remove DataInbox.LayerId")]
partial class RemoveDataInboxLayerId
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.0")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("DiunaBI.Core.Models.DataInbox", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<DateTime>("CreatedAt")
.HasColumnType("datetime2");
b.Property<string>("Data")
.IsRequired()
.HasMaxLength(2147483647)
.HasColumnType("nvarchar(max)");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("nvarchar(50)");
b.Property<string>("Source")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("nvarchar(50)");
b.HasKey("Id");
b.ToTable("DataInbox");
});
modelBuilder.Entity("DiunaBI.Core.Models.Layer", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<DateTime>("CreatedAt")
.HasColumnType("datetime2");
b.Property<Guid>("CreatedById")
.HasColumnType("uniqueidentifier");
b.Property<bool>("IsCancelled")
.HasColumnType("bit");
b.Property<bool>("IsDeleted")
.HasColumnType("bit");
b.Property<DateTime>("ModifiedAt")
.HasColumnType("datetime2");
b.Property<Guid>("ModifiedById")
.HasColumnType("uniqueidentifier");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("nvarchar(50)");
b.Property<int>("Number")
.HasColumnType("int");
b.Property<Guid?>("ParentId")
.HasColumnType("uniqueidentifier");
b.Property<int>("Type")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("CreatedById");
b.HasIndex("ModifiedById");
b.ToTable("Layers");
});
modelBuilder.Entity("DiunaBI.Core.Models.ProcessSource", b =>
{
b.Property<Guid>("LayerId")
.HasColumnType("uniqueidentifier");
b.Property<Guid>("SourceId")
.HasColumnType("uniqueidentifier");
b.HasKey("LayerId", "SourceId");
b.HasIndex("SourceId");
b.ToTable("ProcessSources");
});
modelBuilder.Entity("DiunaBI.Core.Models.QueueJob", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<DateTime?>("CompletedAt")
.HasColumnType("datetime2");
b.Property<DateTime>("CreatedAt")
.HasColumnType("datetime2");
b.Property<DateTime>("CreatedAtUtc")
.HasColumnType("datetime2");
b.Property<Guid>("CreatedById")
.HasColumnType("uniqueidentifier");
b.Property<int>("JobType")
.HasColumnType("int");
b.Property<DateTime?>("LastAttemptAt")
.HasColumnType("datetime2");
b.Property<string>("LastError")
.HasMaxLength(1000)
.HasColumnType("nvarchar(1000)");
b.Property<Guid>("LayerId")
.HasColumnType("uniqueidentifier");
b.Property<string>("LayerName")
.IsRequired()
.HasMaxLength(200)
.HasColumnType("nvarchar(200)");
b.Property<int>("MaxRetries")
.HasColumnType("int");
b.Property<DateTime>("ModifiedAtUtc")
.HasColumnType("datetime2");
b.Property<Guid>("ModifiedById")
.HasColumnType("uniqueidentifier");
b.Property<string>("PluginName")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("nvarchar(100)");
b.Property<int>("Priority")
.HasColumnType("int");
b.Property<int>("RetryCount")
.HasColumnType("int");
b.Property<int>("Status")
.HasColumnType("int");
b.HasKey("Id");
b.ToTable("QueueJobs");
});
modelBuilder.Entity("DiunaBI.Core.Models.Record", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<string>("Code")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("nvarchar(50)");
b.Property<DateTime>("CreatedAt")
.HasColumnType("datetime2");
b.Property<Guid>("CreatedById")
.HasColumnType("uniqueidentifier");
b.Property<string>("Desc1")
.HasMaxLength(10000)
.HasColumnType("nvarchar(max)");
b.Property<bool>("IsDeleted")
.HasColumnType("bit");
b.Property<Guid>("LayerId")
.HasColumnType("uniqueidentifier");
b.Property<DateTime>("ModifiedAt")
.HasColumnType("datetime2");
b.Property<Guid>("ModifiedById")
.HasColumnType("uniqueidentifier");
b.Property<double?>("Value1")
.HasColumnType("float");
b.Property<double?>("Value10")
.HasColumnType("float");
b.Property<double?>("Value11")
.HasColumnType("float");
b.Property<double?>("Value12")
.HasColumnType("float");
b.Property<double?>("Value13")
.HasColumnType("float");
b.Property<double?>("Value14")
.HasColumnType("float");
b.Property<double?>("Value15")
.HasColumnType("float");
b.Property<double?>("Value16")
.HasColumnType("float");
b.Property<double?>("Value17")
.HasColumnType("float");
b.Property<double?>("Value18")
.HasColumnType("float");
b.Property<double?>("Value19")
.HasColumnType("float");
b.Property<double?>("Value2")
.HasColumnType("float");
b.Property<double?>("Value20")
.HasColumnType("float");
b.Property<double?>("Value21")
.HasColumnType("float");
b.Property<double?>("Value22")
.HasColumnType("float");
b.Property<double?>("Value23")
.HasColumnType("float");
b.Property<double?>("Value24")
.HasColumnType("float");
b.Property<double?>("Value25")
.HasColumnType("float");
b.Property<double?>("Value26")
.HasColumnType("float");
b.Property<double?>("Value27")
.HasColumnType("float");
b.Property<double?>("Value28")
.HasColumnType("float");
b.Property<double?>("Value29")
.HasColumnType("float");
b.Property<double?>("Value3")
.HasColumnType("float");
b.Property<double?>("Value30")
.HasColumnType("float");
b.Property<double?>("Value31")
.HasColumnType("float");
b.Property<double?>("Value32")
.HasColumnType("float");
b.Property<double?>("Value4")
.HasColumnType("float");
b.Property<double?>("Value5")
.HasColumnType("float");
b.Property<double?>("Value6")
.HasColumnType("float");
b.Property<double?>("Value7")
.HasColumnType("float");
b.Property<double?>("Value8")
.HasColumnType("float");
b.Property<double?>("Value9")
.HasColumnType("float");
b.HasKey("Id");
b.HasIndex("CreatedById");
b.HasIndex("LayerId");
b.HasIndex("ModifiedById");
b.ToTable("Records");
});
modelBuilder.Entity("DiunaBI.Core.Models.User", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<DateTime>("CreatedAt")
.HasColumnType("datetime2");
b.Property<string>("Email")
.HasMaxLength(50)
.HasColumnType("nvarchar(50)");
b.Property<string>("UserName")
.HasMaxLength(50)
.HasColumnType("nvarchar(50)");
b.HasKey("Id");
b.ToTable("Users");
});
modelBuilder.Entity("DiunaBI.Core.Models.Layer", b =>
{
b.HasOne("DiunaBI.Core.Models.User", "CreatedBy")
.WithMany()
.HasForeignKey("CreatedById")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("DiunaBI.Core.Models.User", "ModifiedBy")
.WithMany()
.HasForeignKey("ModifiedById")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("CreatedBy");
b.Navigation("ModifiedBy");
});
modelBuilder.Entity("DiunaBI.Core.Models.ProcessSource", b =>
{
b.HasOne("DiunaBI.Core.Models.Layer", "Source")
.WithMany()
.HasForeignKey("SourceId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Source");
});
modelBuilder.Entity("DiunaBI.Core.Models.Record", b =>
{
b.HasOne("DiunaBI.Core.Models.User", "CreatedBy")
.WithMany()
.HasForeignKey("CreatedById")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("DiunaBI.Core.Models.Layer", null)
.WithMany("Records")
.HasForeignKey("LayerId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("DiunaBI.Core.Models.User", "ModifiedBy")
.WithMany()
.HasForeignKey("ModifiedById")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("CreatedBy");
b.Navigation("ModifiedBy");
});
modelBuilder.Entity("DiunaBI.Core.Models.Layer", b =>
{
b.Navigation("Records");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -0,0 +1,49 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace DiunaBI.Core.Migrations
{
/// <inheritdoc />
public partial class RemoveDataInboxLayerId : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Layers_Layers_ParentId",
table: "Layers");
migrationBuilder.DropIndex(
name: "IX_Layers_ParentId",
table: "Layers");
migrationBuilder.DropColumn(
name: "LayerId",
table: "DataInbox");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<Guid>(
name: "LayerId",
table: "DataInbox",
type: "uniqueidentifier",
nullable: true);
migrationBuilder.CreateIndex(
name: "IX_Layers_ParentId",
table: "Layers",
column: "ParentId");
migrationBuilder.AddForeignKey(
name: "FK_Layers_Layers_ParentId",
table: "Layers",
column: "ParentId",
principalTable: "Layers",
principalColumn: "Id");
}
}
}

View File

@@ -95,8 +95,6 @@ namespace DiunaBI.Core.Migrations
b.HasIndex("ModifiedById"); b.HasIndex("ModifiedById");
b.HasIndex("ParentId");
b.ToTable("Layers"); b.ToTable("Layers");
}); });
@@ -355,15 +353,9 @@ namespace DiunaBI.Core.Migrations
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
b.HasOne("DiunaBI.Core.Models.Layer", "Parent")
.WithMany()
.HasForeignKey("ParentId");
b.Navigation("CreatedBy"); b.Navigation("CreatedBy");
b.Navigation("ModifiedBy"); b.Navigation("ModifiedBy");
b.Navigation("Parent");
}); });
modelBuilder.Entity("DiunaBI.Core.Models.ProcessSource", b => modelBuilder.Entity("DiunaBI.Core.Models.ProcessSource", b =>

View File

@@ -41,6 +41,5 @@ public class Layer
public Guid ModifiedById { get; set; } public Guid ModifiedById { get; set; }
public User? ModifiedBy { get; init; } public User? ModifiedBy { get; init; }
public Guid? ParentId { get; init; } public Guid? ParentId { get; init; }
public Layer? Parent { get; init; }
#endregion #endregion
} }

View File

@@ -5,14 +5,18 @@ using Microsoft.Extensions.Logging;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using DiunaBI.Core.Models; using DiunaBI.Core.Models;
using DiunaBI.Core.Database.Context; using DiunaBI.Core.Database.Context;
using DiunaBI.Core.Services;
using Google.Apis.Sheets.v4;
using Google.Apis.Sheets.v4.Data;
namespace DiunaBI.Plugins.Morska.Importers; namespace DiunaBI.Plugins.Morska.Importers;
public class MorskaD3Importer : MorskaBaseImporter public class MorskaD3Importer : MorskaBaseImporter
{ {
public override string ImporterType => "Morska.Import.D3"; public override string ImporterType => "Morska.Import.D3";
private readonly AppDbContext _db; private readonly AppDbContext _db;
private readonly SpreadsheetsResource.ValuesResource _googleSheetValues;
private readonly ILogger<MorskaD3Importer> _logger; private readonly ILogger<MorskaD3Importer> _logger;
// Configuration properties // Configuration properties
@@ -20,15 +24,20 @@ public class MorskaD3Importer : MorskaBaseImporter
private string? ImportMonth { get; set; } private string? ImportMonth { get; set; }
private string? ImportName { get; set; } private string? ImportName { get; set; }
private string? ImportType { get; set; } private string? ImportType { get; set; }
private DateTime? StartDate { get; set; } private string? SheetId { get; set; }
private DateTime? EndDate { get; set; }
private bool IsEnabled { get; set; } private bool IsEnabled { get; set; }
// Cached deserialized data
private List<Record>? _cachedRecords;
private string? _cachedDataInboxId;
public MorskaD3Importer( public MorskaD3Importer(
AppDbContext db, AppDbContext db,
SpreadsheetsResource.ValuesResource googleSheetValues,
ILogger<MorskaD3Importer> logger) ILogger<MorskaD3Importer> logger)
{ {
_db = db; _db = db;
_googleSheetValues = googleSheetValues;
_logger = logger; _logger = logger;
} }
@@ -36,14 +45,21 @@ public class MorskaD3Importer : MorskaBaseImporter
{ {
try try
{ {
_logger.LogInformation("{ImporterType}: Starting import for {ImportWorkerName} ({ImportWorkerId})", _logger.LogInformation("{ImporterType}: Starting import for {ImportWorkerName} ({ImportWorkerId})",
ImporterType, importWorker.Name, importWorker.Id); ImporterType, importWorker.Name, importWorker.Id);
// Clear cache at start
_cachedRecords = null;
_cachedDataInboxId = null;
LoadConfiguration(importWorker); LoadConfiguration(importWorker);
// Deserialize data early - right after LoadConfiguration
DeserializeDataInboxData();
if (!ShouldPerformImport(importWorker)) if (!ShouldPerformImport(importWorker))
{ {
_logger.LogInformation("{ImporterType}: Import not needed for {ImportWorkerName}", _logger.LogInformation("{ImporterType}: Import not needed for {ImportWorkerName}",
ImporterType, importWorker.Name); ImporterType, importWorker.Name);
return; return;
} }
@@ -51,16 +67,25 @@ public class MorskaD3Importer : MorskaBaseImporter
ValidateConfiguration(); ValidateConfiguration();
PerformImport(importWorker); PerformImport(importWorker);
_logger.LogInformation("{ImporterType}: Successfully completed import for {ImportWorkerName}", // Export to Google Sheets after successful import
ExportToGoogleSheets();
_logger.LogInformation("{ImporterType}: Successfully completed import for {ImportWorkerName}",
ImporterType, importWorker.Name); ImporterType, importWorker.Name);
} }
catch (Exception e) catch (Exception e)
{ {
_logger.LogError(e, "{ImporterType}: Failed to import {ImportWorkerName} ({ImportWorkerId})", _logger.LogError(e, "{ImporterType}: Failed to import {ImportWorkerName} ({ImportWorkerId})",
ImporterType, importWorker.Name, importWorker.Id); ImporterType, importWorker.Name, importWorker.Id);
throw; throw;
} }
finally
{
// Clear cache after import
_cachedRecords = null;
_cachedDataInboxId = null;
}
} }
private void LoadConfiguration(Layer importWorker) private void LoadConfiguration(Layer importWorker)
@@ -71,56 +96,107 @@ public class MorskaD3Importer : MorskaBaseImporter
ImportMonth = GetRecordValue(importWorker.Records, "ImportMonth"); ImportMonth = GetRecordValue(importWorker.Records, "ImportMonth");
ImportName = GetRecordValue(importWorker.Records, "ImportName"); ImportName = GetRecordValue(importWorker.Records, "ImportName");
ImportType = GetRecordValue(importWorker.Records, "ImportType"); ImportType = GetRecordValue(importWorker.Records, "ImportType");
SheetId = GetRecordValue(importWorker.Records, "SheetId");
IsEnabled = GetRecordValue(importWorker.Records, "IsEnabled") == "True"; IsEnabled = GetRecordValue(importWorker.Records, "IsEnabled") == "True";
var startDateStr = GetRecordValue(importWorker.Records, "StartDate"); _logger.LogDebug(
if (startDateStr != null && DateTime.TryParseExact(startDateStr, "yyyy.MM.dd", null, DateTimeStyles.None, out var startDate)) "{ImporterType}: Configuration loaded for {ImportWorkerName} - Type: {ImportType}, SheetId: {SheetId}",
ImporterType, importWorker.Name, ImportType, SheetId);
}
private void DeserializeDataInboxData()
{
var dataInbox = _db.DataInbox.OrderByDescending(x => x.CreatedAt).FirstOrDefault(x => x.Name == ImportType);
if (dataInbox == null)
{ {
StartDate = startDate; throw new InvalidOperationException($"DataInbox not found for type: {ImportType}");
} }
var endDateStr = GetRecordValue(importWorker.Records, "EndDate"); _logger.LogDebug("{ImporterType}: Found DataInbox {DataInboxId}, created at {CreatedAt}",
if (endDateStr != null && DateTime.TryParseExact(endDateStr, "yyyy.MM.dd", null, DateTimeStyles.None, out var endDate)) ImporterType, dataInbox.Id, dataInbox.CreatedAt);
try
{ {
EndDate = endDate; var data = Convert.FromBase64String(dataInbox.Data);
var jsonString = Encoding.UTF8.GetString(data);
_logger.LogDebug("{ImporterType}: Decoded {DataSize} bytes from base64",
ImporterType, data.Length);
var records = JsonSerializer.Deserialize<List<Record>>(jsonString);
if (records == null)
{
throw new InvalidOperationException($"DataInbox.Data is empty for: {dataInbox.Name}");
}
_logger.LogDebug("{ImporterType}: Deserialized {RecordCount} records from JSON",
ImporterType, records.Count);
// Cache the deserialized data
_cachedRecords = records;
_cachedDataInboxId = dataInbox.Id.ToString();
}
catch (FormatException e)
{
_logger.LogError(e, "{ImporterType}: Invalid base64 data in DataInbox {DataInboxName}",
ImporterType, ImportType);
throw new InvalidOperationException($"Invalid base64 data in DataInbox: {ImportType}", e);
}
catch (JsonException e)
{
_logger.LogError(e, "{ImporterType}: Invalid JSON data in DataInbox {DataInboxName}",
ImporterType, ImportType);
throw new InvalidOperationException($"Invalid JSON data in DataInbox: {ImportType}", e);
}
}
private List<Record> GetFilteredRecords()
{
if (_cachedRecords == null)
{
throw new InvalidOperationException("Data has not been deserialized yet");
} }
_logger.LogDebug("{ImporterType}: Configuration loaded for {ImportWorkerName} - Type: {ImportType}", var filteredRecords = _cachedRecords.Where(x => x.Code!.StartsWith($"{ImportYear}{ImportMonth}")).ToList();
ImporterType, importWorker.Name, ImportType); if (filteredRecords.Count == 0)
{
throw new InvalidOperationException($"No records found for period: {ImportYear}{ImportMonth}");
}
_logger.LogDebug("{ImporterType}: Filtered to {FilteredCount} records for period {Year}{Month}",
ImporterType, filteredRecords.Count, ImportYear, ImportMonth);
return filteredRecords;
} }
private bool ShouldPerformImport(Layer importWorker) private bool ShouldPerformImport(Layer importWorker)
{ {
if (!IsEnabled) if (!IsEnabled)
{ {
_logger.LogDebug("{ImporterType}: Import disabled for {ImportWorkerName}", _logger.LogDebug("{ImporterType}: Import disabled for {ImportWorkerName}",
ImporterType, importWorker.Name); ImporterType, importWorker.Name);
return false; return false;
} }
if (StartDate.HasValue && EndDate.HasValue) var dataInbox = _db.DataInbox.OrderByDescending(x => x.CreatedAt).FirstOrDefault(x => x.Name == ImportType);
if (dataInbox == null)
{ {
var now = DateTime.UtcNow.Date; _logger.LogDebug("{ImporterType}: No DataInbox found for type {ImportType}",
if (now >= StartDate.Value.Date && now <= EndDate.Value.Date) ImporterType, ImportType);
{
_logger.LogDebug("{ImporterType}: Within date range, import needed for {ImportWorkerName}",
ImporterType, importWorker.Name);
return true;
}
if (!IsImportedLayerUpToDate(importWorker))
{
_logger.LogDebug("{ImporterType}: Outside date range but layer is out of date, import needed for {ImportWorkerName}",
ImporterType, importWorker.Name);
return true;
}
_logger.LogDebug("{ImporterType}: Outside date range and layer is up to date for {ImportWorkerName}",
ImporterType, importWorker.Name);
return false; return false;
} }
// Check if imported layer is up to date
if (!IsImportedLayerUpToDate(importWorker))
{
_logger.LogDebug("{ImporterType}: Layer is out of date, import needed for {ImportWorkerName}",
ImporterType, importWorker.Name);
return true;
}
return true; _logger.LogDebug("{ImporterType}: Layer is up to date for {ImportWorkerName}",
ImporterType, importWorker.Name);
return false;
} }
private void ValidateConfiguration() private void ValidateConfiguration()
@@ -131,6 +207,7 @@ public class MorskaD3Importer : MorskaBaseImporter
if (string.IsNullOrEmpty(ImportMonth)) errors.Add("ImportMonth is required"); if (string.IsNullOrEmpty(ImportMonth)) errors.Add("ImportMonth is required");
if (string.IsNullOrEmpty(ImportName)) errors.Add("ImportName is required"); if (string.IsNullOrEmpty(ImportName)) errors.Add("ImportName is required");
if (string.IsNullOrEmpty(ImportType)) errors.Add("ImportType is required"); if (string.IsNullOrEmpty(ImportType)) errors.Add("ImportType is required");
if (string.IsNullOrEmpty(SheetId)) errors.Add("SheetId is required");
if (errors.Any()) if (errors.Any())
{ {
@@ -142,116 +219,182 @@ public class MorskaD3Importer : MorskaBaseImporter
{ {
var newestLayer = _db.Layers var newestLayer = _db.Layers
.Include(x => x.Records) .Include(x => x.Records)
.Where(x => x.ParentId == importWorker.Id) .Where(x =>
x.ParentId == importWorker.Id
&& x.Name!.Contains($"I-{ImportName}-{ImportYear}/{ImportMonth}"))
.OrderByDescending(x => x.CreatedAt) .OrderByDescending(x => x.CreatedAt)
.AsNoTracking() .AsNoTracking()
.FirstOrDefault(); .FirstOrDefault();
if (newestLayer == null) if (newestLayer == null)
{ {
_logger.LogDebug("{ImporterType}: No child layers found for {ImportWorkerName}, treating as up to date", _logger.LogDebug("{ImporterType}: No child layers found for {ImportWorkerName}, import needed",
ImporterType, importWorker.Name); ImporterType, importWorker.Name);
return true; return false;
} }
try try
{ {
var dataInbox = _db.DataInbox.OrderByDescending(x => x.CreatedAt).FirstOrDefault(x => x.Name == ImportType); var currentRecords = GetFilteredRecords();
if (dataInbox == null)
// Compare record counts first
if (newestLayer.Records?.Count != currentRecords.Count)
{ {
_logger.LogWarning("{ImporterType}: No DataInbox found for type {ImportType}", _logger.LogDebug("{ImporterType}: Record count mismatch - DB: {DbCount}, DataInbox: {DataCount}",
ImporterType, ImportType); ImporterType, newestLayer.Records?.Count ?? 0, currentRecords.Count);
return true; // Assume up to date if no data source return false;
} }
// Compare timestamps - if DataInbox is newer than our layer, we need to import // Compare individual records
var isUpToDate = newestLayer.CreatedAt >= dataInbox.CreatedAt; foreach (var currentRecord in currentRecords)
{
_logger.LogDebug("{ImporterType}: Layer created at {LayerTime}, DataInbox created at {DataTime}, up to date: {IsUpToDate}", var existingRecord = newestLayer.Records?.FirstOrDefault(x => x.Code == currentRecord.Code);
ImporterType, newestLayer.CreatedAt, dataInbox.CreatedAt, isUpToDate); if (existingRecord == null)
{
_logger.LogDebug("{ImporterType}: Record with code {Code} not found in existing layer",
ImporterType, currentRecord.Code);
return false;
}
return isUpToDate; // Compare all relevant fields
if (Math.Abs((existingRecord.Value1 ?? 0) - (currentRecord.Value1 ?? 0)) > 0.001 ||
existingRecord.Desc1 != currentRecord.Desc1)
{
_logger.LogDebug("{ImporterType}: Data difference found for code {Code}",
ImporterType, currentRecord.Code);
return false;
}
}
_logger.LogDebug("{ImporterType}: All records match, layer is up to date for {ImportWorkerName}",
ImporterType, importWorker.Name);
return true;
} }
catch (Exception e) catch (Exception e)
{ {
_logger.LogError(e, "{ImporterType}: Error checking if layer {ImportWorkerName} is up to date", _logger.LogError(e, "{ImporterType}: Error checking if layer {ImportWorkerName} is up to date",
ImporterType, importWorker.Name); ImporterType, importWorker.Name);
throw; return false;
} }
} }
private void PerformImport(Layer importWorker) private void PerformImport(Layer importWorker)
{ {
_logger.LogDebug("{ImporterType}: Looking for DataInbox with type {ImportType}", _logger.LogDebug("{ImporterType}: Starting import for DataInbox type {ImportType}",
ImporterType, ImportType); ImporterType, ImportType);
var dataInbox = _db.DataInbox.OrderByDescending(x => x.CreatedAt).FirstOrDefault(x => x.Name == ImportType); var filteredRecords = GetFilteredRecords();
if (dataInbox == null)
{
throw new InvalidOperationException($"DataInbox not found for type: {ImportType}");
}
_logger.LogDebug("{ImporterType}: Found DataInbox {DataInboxId}, created at {CreatedAt}", // Prepare records for saving
ImporterType, dataInbox.Id, dataInbox.CreatedAt); var recordsToSave = filteredRecords.Select(x =>
{
x.Id = Guid.NewGuid();
x.CreatedAt = DateTime.UtcNow;
x.ModifiedAt = DateTime.UtcNow;
return x;
}).ToList();
var layer = new Layer
{
Id = Guid.NewGuid(),
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-{ImportName}-{ImportYear}/{ImportMonth}-{DateTime.Now:yyyyMMddHHmm}";
_db.Layers.Add(layer);
SaveRecords(layer.Id, recordsToSave);
_db.SaveChanges();
_logger.LogInformation(
"{ImporterType}: Successfully imported {RecordCount} records for layer {LayerName} ({LayerId})",
ImporterType, recordsToSave.Count, layer.Name, layer.Id);
}
private void ExportToGoogleSheets()
{
if (string.IsNullOrEmpty(SheetId))
{
_logger.LogWarning("{ImporterType}: SheetId not configured, skipping Google Sheets export",
ImporterType);
return;
}
try try
{ {
var data = Convert.FromBase64String(dataInbox.Data); _logger.LogDebug("{ImporterType}: Starting Google Sheets export to {SheetId}",
var jsonString = Encoding.UTF8.GetString(data); ImporterType, SheetId);
_logger.LogDebug("{ImporterType}: Decoded {DataSize} bytes from base64",
ImporterType, data.Length);
var records = JsonSerializer.Deserialize<List<Record>>(jsonString); var filteredRecords = GetFilteredRecords();
if (records == null) var sheetTabName = ProcessHelper.GetSheetName(int.Parse(ImportMonth!), int.Parse(ImportYear!));
_logger.LogDebug("{ImporterType}: Using sheet tab name: {SheetTabName}",
ImporterType, sheetTabName);
// Get current sheet data
var currentSheetData = _googleSheetValues.Get(SheetId!, $"{sheetTabName}!C7:D200").Execute();
var updateRequests = new List<ValueRange>();
for (var rowIndex = 0; rowIndex < 194; rowIndex++)
{ {
throw new InvalidOperationException($"DataInbox.Data is empty for: {dataInbox.Name}"); if (currentSheetData.Values == null || rowIndex >= currentSheetData.Values.Count)
continue;
var existingRow = currentSheetData.Values[rowIndex];
if (existingRow.Count == 0 || string.IsNullOrEmpty(existingRow[0]?.ToString()))
continue;
var accountCode = existingRow[0].ToString()!;
var matchingRecord = filteredRecords.FirstOrDefault(x => x.Desc1 == accountCode);
if (matchingRecord == null)
continue;
var newValue = matchingRecord.Value1?.ToString(CultureInfo.GetCultureInfo("pl-PL")) ?? "0";
var existingValue = (existingRow.Count > 1 ? existingRow[1] : "")?.ToString();
if (existingValue != newValue)
{
var range = $"{sheetTabName}!D{rowIndex + 7}";
updateRequests.Add(new ValueRange
{
Range = range,
Values = new List<IList<object>> { new List<object> { newValue } }
});
_logger.LogDebug("{ImporterType}: Scheduled update for {AccountCode} at {Range} with value {Value}",
ImporterType, accountCode, range, newValue);
}
} }
_logger.LogDebug("{ImporterType}: Deserialized {RecordCount} records from JSON", if (updateRequests.Count > 0)
ImporterType, records.Count);
records = records.Where(x => x.Code!.StartsWith($"{ImportYear}{ImportMonth}")).ToList();
if (records.Count == 0)
{ {
throw new InvalidOperationException($"No records found for period: {ImportYear}{ImportMonth}"); var batchUpdate = new BatchUpdateValuesRequest
{
Data = updateRequests,
ValueInputOption = "USER_ENTERED"
};
_googleSheetValues.BatchUpdate(batchUpdate, SheetId!).Execute();
_logger.LogInformation("{ImporterType}: Updated {Count} cells in Google Sheet {SheetId}",
ImporterType, updateRequests.Count, SheetId);
} }
else
_logger.LogDebug("{ImporterType}: Filtered to {FilteredCount} records for period {Year}{Month}",
ImporterType, records.Count, ImportYear, ImportMonth);
records = records.Select(x =>
{ {
x.Id = Guid.NewGuid(); _logger.LogInformation("{ImporterType}: No changes to export to Google Sheet {SheetId}",
x.CreatedAt = DateTime.UtcNow; ImporterType, SheetId);
x.ModifiedAt = DateTime.UtcNow; }
return x;
}).ToList();
var layer = new Layer
{
Id = Guid.NewGuid(),
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-{ImportName}-{ImportYear}/{ImportMonth}-{DateTime.Now:yyyyMMddHHmm}";
_db.Layers.Add(layer);
SaveRecords(layer.Id, records);
_db.SaveChanges();
_logger.LogInformation("{ImporterType}: Successfully imported {RecordCount} records for layer {LayerName} ({LayerId})",
ImporterType, records.Count, layer.Name, layer.Id);
} }
catch (Exception e) catch (Exception e)
{ {
_logger.LogError(e, "{ImporterType}: Error processing DataInbox {DataInboxId}", _logger.LogError(e, "{ImporterType}: Failed to export to Google Sheets {SheetId}",
ImporterType, dataInbox.Id); ImporterType, SheetId);
throw; throw;
} }
} }
@@ -279,7 +422,7 @@ public class MorskaD3Importer : MorskaBaseImporter
_db.Records.Add(record); _db.Records.Add(record);
} }
_logger.LogDebug("{ImporterType}: Saved {RecordCount} records for layer {LayerId}", _logger.LogDebug("{ImporterType}: Saved {RecordCount} records for layer {LayerId}",
ImporterType, records.Count, layerId); ImporterType, records.Count, layerId);
} }
} }

View File

@@ -1,3 +1,3 @@
### ###
GET http://localhost:5400/api/Layers/AutoImport/10763478CB738D4ecb2h76g803478CB738D4e/K5- GET http://localhost:5400/api/Layers/AutoImport/10763478CB738D4ecb2h76g803478CB738D4e/D3-

View File

@@ -1,8 +1,8 @@
DECLARE @JustForDebug TINYINT = 1; DECLARE @JustForDebug TINYINT = 0;
-- SETUP VARIABLES -- SETUP VARIABLES
DECLARE @Type NVARCHAR(3) = 'D3'; DECLARE @Type NVARCHAR(3) = 'D3';
DECLARE @Month INT = 3; DECLARE @Month INT = 7;
DECLARE @Year INT = 2025; DECLARE @Year INT = 2025;
IF @Type NOT IN ('D3') IF @Type NOT IN ('D3')
@@ -73,4 +73,8 @@ INSERT INTO [diunabi-morska].[dbo].[Records]
([Id], [Code], [Desc1], [CreatedAt], [ModifiedAt], [CreatedById], [ModifiedById], [IsDeleted], [LayerId]) ([Id], [Code], [Desc1], [CreatedAt], [ModifiedAt], [CreatedById], [ModifiedById], [IsDeleted], [LayerId])
VALUES ((SELECT NEWID()), 'ImportType', @ImportType, GETDATE(), GETDATE(), '117be4f0-b5d1-41a1-a962-39dc30cce368', '117be4f0-b5d1-41a1-a962-39dc30cce368', 0, @LayerId); VALUES ((SELECT NEWID()), 'ImportType', @ImportType, GETDATE(), GETDATE(), '117be4f0-b5d1-41a1-a962-39dc30cce368', '117be4f0-b5d1-41a1-a962-39dc30cce368', 0, @LayerId);
INSERT INTO [diunabi-morska].[dbo].[Records]
([Id], [Code], [Desc1], [CreatedAt], [ModifiedAt], [CreatedById], [ModifiedById], [IsDeleted], [LayerId])
VALUES ((SELECT NEWID()), 'SheetId', '1wplF3CRHweDE8A3Dk9dYbhWAatj1kp0UBM7MiFE26hE', GETDATE(), GETDATE(), '117be4f0-b5d1-41a1-a962-39dc30cce368', '117be4f0-b5d1-41a1-a962-39dc30cce368', 0, @LayerId);
SELECT 'ImportWorker created' AS Logger; SELECT 'ImportWorker created' AS Logger;

View File

@@ -1,5 +1,5 @@
INSERT INTO [diunabi-morska].[dbo].[Records] INSERT INTO [diunabi-morska].[dbo].[Records]
([Id], [Code], [Desc1], [CreatedAt], [ModifiedAt], [CreatedById], [ModifiedById], [IsDeleted], [LayerId]) ([Id], [Code], [Desc1], [CreatedAt], [ModifiedAt], [CreatedById], [ModifiedById], [IsDeleted], [LayerId])
VALUES ((SELECT NEWID()), 'Sell-Code-9091', '1208/', VALUES ((SELECT NEWID()), 'SheetId', '1wplF3CRHweDE8A3Dk9dYbhWAatj1kp0UBM7MiFE26hE',
GETDATE(), GETDATE(), '117be4f0-b5d1-41a1-a962-39dc30cce368', '117be4f0-b5d1-41a1-a962-39dc30cce368', 0, GETDATE(), GETDATE(), '117be4f0-b5d1-41a1-a962-39dc30cce368', '117be4f0-b5d1-41a1-a962-39dc30cce368', 0,
'd1e6e8d2-a13b-421f-84cb-a9ccd5b1c6f5'); 'ef188ff5-c9d2-4bac-9a7a-c2d878d2fbd4');

View File

@@ -1,3 +1,3 @@
DECLARE @LayerId UNIQUEIDENTIFIER = '986e8a71-8cad-4e57-8fce-243a9270b9dc'; DECLARE @LayerId UNIQUEIDENTIFIER = 'e5336f20-82aa-438a-bfa5-003f1e55dc09';
DELETE FROM [diunabi-morska].[dbo].[Records] WHERE [LayerId] = @LayerId; DELETE FROM [diunabi-morska].[dbo].[Records] WHERE [LayerId] = @LayerId;
DELETE FROM [diunabi-morska].[dbo].[Layers] WHERE [Id] = @LayerId; DELETE FROM [diunabi-morska].[dbo].[Layers] WHERE [Id] = @LayerId;