Compare commits
10 Commits
bbb3f5b2bf
...
e86cbd82a3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e86cbd82a3 | ||
|
|
bb6d208400 | ||
|
|
41acf9f93e | ||
|
|
15ed0075ea | ||
|
|
ed680267a2 | ||
|
|
9ddfbd83a2 | ||
|
|
bf29367b0c | ||
|
|
45c37d8bd3 | ||
|
|
75600a7415 | ||
|
|
53e12e414d |
418
src/Backend/DiunaBI.Core/Database/Migrations/20250725133501_DataInbox.LayerId.Designer.cs
generated
Normal file
418
src/Backend/DiunaBI.Core/Database/Migrations/20250725133501_DataInbox.LayerId.Designer.cs
generated
Normal 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
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
407
src/Backend/DiunaBI.Core/Database/Migrations/20250726091001_Remove DataInbox.LayerId.Designer.cs
generated
Normal file
407
src/Backend/DiunaBI.Core/Database/Migrations/20250726091001_Remove DataInbox.LayerId.Designer.cs
generated
Normal 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
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -95,8 +95,6 @@ namespace DiunaBI.Core.Migrations
|
||||
|
||||
b.HasIndex("ModifiedById");
|
||||
|
||||
b.HasIndex("ParentId");
|
||||
|
||||
b.ToTable("Layers");
|
||||
});
|
||||
|
||||
@@ -355,15 +353,9 @@ namespace DiunaBI.Core.Migrations
|
||||
.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 =>
|
||||
|
||||
@@ -41,6 +41,5 @@ public class Layer
|
||||
public Guid ModifiedById { get; set; }
|
||||
public User? ModifiedBy { get; init; }
|
||||
public Guid? ParentId { get; init; }
|
||||
public Layer? Parent { get; init; }
|
||||
#endregion
|
||||
}
|
||||
@@ -40,6 +40,30 @@ public class BaseCalc
|
||||
Formula.All(c => char.IsDigit(c) || c == '[' || c == ']' || c == '+' || c == '-');
|
||||
}
|
||||
|
||||
public double Calculate(IReadOnlyDictionary<string, double> ingredients)
|
||||
{
|
||||
if (ingredients == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(ingredients));
|
||||
}
|
||||
|
||||
var codes = GetCodes();
|
||||
var missing = codes.Where(x => !ingredients.ContainsKey(x)).ToList();
|
||||
if (missing.Any())
|
||||
{
|
||||
throw new ArgumentException($"Missing ingredients: {string.Join(", ", missing)}");
|
||||
}
|
||||
|
||||
var formula = ingredients.Aggregate(Formula,
|
||||
(current, ingredient) => current.Replace($"[{ingredient.Key}]", ingredient.Value.ToString(CultureInfo.InvariantCulture)));
|
||||
if (formula.Contains('['))
|
||||
{
|
||||
throw new Exception($"Not all placeholders were replaced. Value{1} [{formula}]");
|
||||
}
|
||||
Entity expr = formula;
|
||||
return (double)expr.EvalNumerical();
|
||||
}
|
||||
|
||||
public Record CalculateT3(List<Record> records)
|
||||
{
|
||||
var resultCode = ResultCode;
|
||||
@@ -81,7 +105,6 @@ public class BaseCalc
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public Record CalculateT1(List<Record> records)
|
||||
{
|
||||
var resultCode = ResultCode;
|
||||
@@ -121,8 +144,7 @@ public class BaseCalc
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
private List<string> GetCodes()
|
||||
public List<string> GetCodes()
|
||||
{
|
||||
var codes = new List<string>();
|
||||
var endIndex = -1;
|
||||
@@ -143,4 +165,9 @@ public class BaseCalc
|
||||
|
||||
return codes;
|
||||
}
|
||||
|
||||
public string GetResultCode()
|
||||
{
|
||||
return ResultCode;
|
||||
}
|
||||
}
|
||||
@@ -5,14 +5,18 @@ using Microsoft.Extensions.Logging;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using DiunaBI.Core.Models;
|
||||
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;
|
||||
|
||||
public class MorskaD3Importer : MorskaBaseImporter
|
||||
{
|
||||
public override string ImporterType => "Morska.Import.D3";
|
||||
|
||||
|
||||
private readonly AppDbContext _db;
|
||||
private readonly SpreadsheetsResource.ValuesResource _googleSheetValues;
|
||||
private readonly ILogger<MorskaD3Importer> _logger;
|
||||
|
||||
// Configuration properties
|
||||
@@ -20,15 +24,20 @@ public class MorskaD3Importer : MorskaBaseImporter
|
||||
private string? ImportMonth { get; set; }
|
||||
private string? ImportName { get; set; }
|
||||
private string? ImportType { get; set; }
|
||||
private DateTime? StartDate { get; set; }
|
||||
private DateTime? EndDate { get; set; }
|
||||
private string? SheetId { get; set; }
|
||||
private bool IsEnabled { get; set; }
|
||||
|
||||
// Cached deserialized data
|
||||
private List<Record>? _cachedRecords;
|
||||
private string? _cachedDataInboxId;
|
||||
|
||||
public MorskaD3Importer(
|
||||
AppDbContext db,
|
||||
SpreadsheetsResource.ValuesResource googleSheetValues,
|
||||
ILogger<MorskaD3Importer> logger)
|
||||
{
|
||||
_db = db;
|
||||
_googleSheetValues = googleSheetValues;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
@@ -36,14 +45,21 @@ public class MorskaD3Importer : MorskaBaseImporter
|
||||
{
|
||||
try
|
||||
{
|
||||
_logger.LogInformation("{ImporterType}: Starting import for {ImportWorkerName} ({ImportWorkerId})",
|
||||
_logger.LogInformation("{ImporterType}: Starting import for {ImportWorkerName} ({ImportWorkerId})",
|
||||
ImporterType, importWorker.Name, importWorker.Id);
|
||||
|
||||
// Clear cache at start
|
||||
_cachedRecords = null;
|
||||
_cachedDataInboxId = null;
|
||||
|
||||
LoadConfiguration(importWorker);
|
||||
|
||||
|
||||
// Deserialize data early - right after LoadConfiguration
|
||||
DeserializeDataInboxData();
|
||||
|
||||
if (!ShouldPerformImport(importWorker))
|
||||
{
|
||||
_logger.LogInformation("{ImporterType}: Import not needed for {ImportWorkerName}",
|
||||
_logger.LogInformation("{ImporterType}: Import not needed for {ImportWorkerName}",
|
||||
ImporterType, importWorker.Name);
|
||||
return;
|
||||
}
|
||||
@@ -51,16 +67,25 @@ public class MorskaD3Importer : MorskaBaseImporter
|
||||
ValidateConfiguration();
|
||||
|
||||
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);
|
||||
}
|
||||
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);
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Clear cache after import
|
||||
_cachedRecords = null;
|
||||
_cachedDataInboxId = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadConfiguration(Layer importWorker)
|
||||
@@ -71,56 +96,107 @@ public class MorskaD3Importer : MorskaBaseImporter
|
||||
ImportMonth = GetRecordValue(importWorker.Records, "ImportMonth");
|
||||
ImportName = GetRecordValue(importWorker.Records, "ImportName");
|
||||
ImportType = GetRecordValue(importWorker.Records, "ImportType");
|
||||
SheetId = GetRecordValue(importWorker.Records, "SheetId");
|
||||
IsEnabled = GetRecordValue(importWorker.Records, "IsEnabled") == "True";
|
||||
|
||||
var startDateStr = GetRecordValue(importWorker.Records, "StartDate");
|
||||
if (startDateStr != null && DateTime.TryParseExact(startDateStr, "yyyy.MM.dd", null, DateTimeStyles.None, out var startDate))
|
||||
_logger.LogDebug(
|
||||
"{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");
|
||||
if (endDateStr != null && DateTime.TryParseExact(endDateStr, "yyyy.MM.dd", null, DateTimeStyles.None, out var endDate))
|
||||
_logger.LogDebug("{ImporterType}: Found DataInbox {DataInboxId}, created at {CreatedAt}",
|
||||
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}",
|
||||
ImporterType, importWorker.Name, ImportType);
|
||||
var filteredRecords = _cachedRecords.Where(x => x.Code!.StartsWith($"{ImportYear}{ImportMonth}")).ToList();
|
||||
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)
|
||||
{
|
||||
if (!IsEnabled)
|
||||
{
|
||||
_logger.LogDebug("{ImporterType}: Import disabled for {ImportWorkerName}",
|
||||
_logger.LogDebug("{ImporterType}: Import disabled for {ImportWorkerName}",
|
||||
ImporterType, importWorker.Name);
|
||||
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;
|
||||
if (now >= StartDate.Value.Date && now <= EndDate.Value.Date)
|
||||
{
|
||||
_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);
|
||||
_logger.LogDebug("{ImporterType}: No DataInbox found for type {ImportType}",
|
||||
ImporterType, ImportType);
|
||||
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()
|
||||
@@ -131,6 +207,7 @@ public class MorskaD3Importer : MorskaBaseImporter
|
||||
if (string.IsNullOrEmpty(ImportMonth)) errors.Add("ImportMonth is required");
|
||||
if (string.IsNullOrEmpty(ImportName)) errors.Add("ImportName is required");
|
||||
if (string.IsNullOrEmpty(ImportType)) errors.Add("ImportType is required");
|
||||
if (string.IsNullOrEmpty(SheetId)) errors.Add("SheetId is required");
|
||||
|
||||
if (errors.Any())
|
||||
{
|
||||
@@ -142,116 +219,182 @@ public class MorskaD3Importer : MorskaBaseImporter
|
||||
{
|
||||
var newestLayer = _db.Layers
|
||||
.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)
|
||||
.AsNoTracking()
|
||||
.FirstOrDefault();
|
||||
|
||||
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);
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var dataInbox = _db.DataInbox.OrderByDescending(x => x.CreatedAt).FirstOrDefault(x => x.Name == ImportType);
|
||||
if (dataInbox == null)
|
||||
var currentRecords = GetFilteredRecords();
|
||||
|
||||
// Compare record counts first
|
||||
if (newestLayer.Records?.Count != currentRecords.Count)
|
||||
{
|
||||
_logger.LogWarning("{ImporterType}: No DataInbox found for type {ImportType}",
|
||||
ImporterType, ImportType);
|
||||
return true; // Assume up to date if no data source
|
||||
_logger.LogDebug("{ImporterType}: Record count mismatch - DB: {DbCount}, DataInbox: {DataCount}",
|
||||
ImporterType, newestLayer.Records?.Count ?? 0, currentRecords.Count);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Compare timestamps - if DataInbox is newer than our layer, we need to import
|
||||
var isUpToDate = newestLayer.CreatedAt >= dataInbox.CreatedAt;
|
||||
|
||||
_logger.LogDebug("{ImporterType}: Layer created at {LayerTime}, DataInbox created at {DataTime}, up to date: {IsUpToDate}",
|
||||
ImporterType, newestLayer.CreatedAt, dataInbox.CreatedAt, isUpToDate);
|
||||
// Compare individual records
|
||||
foreach (var currentRecord in currentRecords)
|
||||
{
|
||||
var existingRecord = newestLayer.Records?.FirstOrDefault(x => x.Code == currentRecord.Code);
|
||||
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)
|
||||
{
|
||||
_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);
|
||||
throw;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
var dataInbox = _db.DataInbox.OrderByDescending(x => x.CreatedAt).FirstOrDefault(x => x.Name == ImportType);
|
||||
if (dataInbox == null)
|
||||
{
|
||||
throw new InvalidOperationException($"DataInbox not found for type: {ImportType}");
|
||||
}
|
||||
var filteredRecords = GetFilteredRecords();
|
||||
|
||||
_logger.LogDebug("{ImporterType}: Found DataInbox {DataInboxId}, created at {CreatedAt}",
|
||||
ImporterType, dataInbox.Id, dataInbox.CreatedAt);
|
||||
// Prepare records for saving
|
||||
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
|
||||
{
|
||||
var data = Convert.FromBase64String(dataInbox.Data);
|
||||
var jsonString = Encoding.UTF8.GetString(data);
|
||||
|
||||
_logger.LogDebug("{ImporterType}: Decoded {DataSize} bytes from base64",
|
||||
ImporterType, data.Length);
|
||||
_logger.LogDebug("{ImporterType}: Starting Google Sheets export to {SheetId}",
|
||||
ImporterType, SheetId);
|
||||
|
||||
var records = JsonSerializer.Deserialize<List<Record>>(jsonString);
|
||||
if (records == null)
|
||||
var filteredRecords = GetFilteredRecords();
|
||||
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",
|
||||
ImporterType, records.Count);
|
||||
|
||||
records = records.Where(x => x.Code!.StartsWith($"{ImportYear}{ImportMonth}")).ToList();
|
||||
if (records.Count == 0)
|
||||
if (updateRequests.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);
|
||||
}
|
||||
|
||||
_logger.LogDebug("{ImporterType}: Filtered to {FilteredCount} records for period {Year}{Month}",
|
||||
ImporterType, records.Count, ImportYear, ImportMonth);
|
||||
|
||||
records = records.Select(x =>
|
||||
else
|
||||
{
|
||||
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, records);
|
||||
_db.SaveChanges();
|
||||
|
||||
_logger.LogInformation("{ImporterType}: Successfully imported {RecordCount} records for layer {LayerName} ({LayerId})",
|
||||
ImporterType, records.Count, layer.Name, layer.Id);
|
||||
_logger.LogInformation("{ImporterType}: No changes to export to Google Sheet {SheetId}",
|
||||
ImporterType, SheetId);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.LogError(e, "{ImporterType}: Error processing DataInbox {DataInboxId}",
|
||||
ImporterType, dataInbox.Id);
|
||||
_logger.LogError(e, "{ImporterType}: Failed to export to Google Sheets {SheetId}",
|
||||
ImporterType, SheetId);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
@@ -279,7 +422,7 @@ public class MorskaD3Importer : MorskaBaseImporter
|
||||
_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);
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ using Google.Apis.Sheets.v4.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using DiunaBI.Core.Models;
|
||||
using DiunaBI.Core.Database.Context;
|
||||
using DiunaBI.Core.Services.Calculations;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace DiunaBI.Plugins.Morska.Processors;
|
||||
@@ -22,6 +23,7 @@ public class MorskaD6Processor : MorskaBaseProcessor
|
||||
private int Year { get; set; }
|
||||
private string? CostSource { get; set; }
|
||||
private string? SellSource { get; set; }
|
||||
private List<string> SellCodesConfiguration { get; set; } = new();
|
||||
|
||||
public MorskaD6Processor(
|
||||
AppDbContext db,
|
||||
@@ -59,7 +61,6 @@ public class MorskaD6Processor : MorskaBaseProcessor
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadConfiguration(Layer processWorker)
|
||||
{
|
||||
if (processWorker.Records == null)
|
||||
@@ -86,12 +87,23 @@ public class MorskaD6Processor : MorskaBaseProcessor
|
||||
{
|
||||
throw new InvalidOperationException("SourceLayerCosts record not found");
|
||||
}
|
||||
|
||||
SellCodesConfiguration = processWorker.Records
|
||||
.Where(x => string.Equals(x.Code, "Sell-Code", StringComparison.OrdinalIgnoreCase))
|
||||
.Select(x => x.Desc1!.Trim())
|
||||
.Where(x => !string.IsNullOrWhiteSpace(x))
|
||||
.Distinct(StringComparer.Ordinal)
|
||||
.ToList();
|
||||
|
||||
if (!SellCodesConfiguration.Any())
|
||||
{
|
||||
throw new InvalidOperationException("Sell-Code records not found");
|
||||
}
|
||||
|
||||
_logger.LogDebug(
|
||||
"{ProcessorType}: Configuration loaded - Year: {Year}, SourceCost: {CostSource}, SourceSell: {SellSource}",
|
||||
ProcessorType, Year, CostSource, SellSource);
|
||||
}
|
||||
|
||||
private void ValidateConfiguration()
|
||||
{
|
||||
var errors = new List<string>();
|
||||
@@ -107,7 +119,6 @@ public class MorskaD6Processor : MorskaBaseProcessor
|
||||
|
||||
_logger.LogDebug("{ProcessorType}: Configuration validation passed", ProcessorType);
|
||||
}
|
||||
|
||||
private void PerformProcessing(Layer processWorker)
|
||||
{
|
||||
_logger.LogDebug(
|
||||
@@ -122,11 +133,12 @@ public class MorskaD6Processor : MorskaBaseProcessor
|
||||
|
||||
SaveProcessedLayer(processedLayer, newRecords);
|
||||
|
||||
UpdateGoogleSheetReport(processedLayer.Id);
|
||||
|
||||
_logger.LogInformation(
|
||||
"{ProcessorType}: Successfully processed {RecordCount} records for layer {LayerName} ({LayerId})",
|
||||
ProcessorType, newRecords.Count, processedLayer.Name, processedLayer.Id);
|
||||
}
|
||||
|
||||
private Layer GetOrCreateProcessedLayer(Layer processWorker)
|
||||
{
|
||||
var processedLayer = _db.Layers
|
||||
@@ -163,7 +175,6 @@ public class MorskaD6Processor : MorskaBaseProcessor
|
||||
|
||||
return processedLayer;
|
||||
}
|
||||
|
||||
private List<Layer> GetDataSources()
|
||||
{
|
||||
var costDataSource = _db.Layers
|
||||
@@ -192,14 +203,13 @@ public class MorskaD6Processor : MorskaBaseProcessor
|
||||
|
||||
return [costDataSource, sellDataSource];
|
||||
}
|
||||
|
||||
private List<Record> ProcessRecords(List<Layer> dataSources)
|
||||
{
|
||||
var newRecords = new List<Record>();
|
||||
|
||||
// L8542-D-DEPARTMENTS
|
||||
var dictionary = _db.Layers.Include(x => x.Records).FirstOrDefault(x => x.Number == 8542);
|
||||
|
||||
|
||||
var departmentLookup = new Dictionary<string, string>();
|
||||
if (dictionary?.Records != null)
|
||||
{
|
||||
@@ -220,6 +230,8 @@ public class MorskaD6Processor : MorskaBaseProcessor
|
||||
ProcessorType);
|
||||
}
|
||||
|
||||
// COSTS
|
||||
|
||||
var firstDataSource = dataSources.First();
|
||||
|
||||
if (firstDataSource.Records == null || !firstDataSource.Records.Any())
|
||||
@@ -229,7 +241,7 @@ public class MorskaD6Processor : MorskaBaseProcessor
|
||||
}
|
||||
|
||||
var groupedData = firstDataSource.Records
|
||||
.Where(record => record.Code != null && record.Code.Length >= 8 && record.Value1.HasValue)
|
||||
.Where(record => record is { Code: { Length: >= 8 }, Value1: not null })
|
||||
.Select(record => new
|
||||
{
|
||||
Month = record.Code!.Substring(4, 2),
|
||||
@@ -264,13 +276,28 @@ public class MorskaD6Processor : MorskaBaseProcessor
|
||||
|
||||
foreach (var groupedRecord in groupedData)
|
||||
{
|
||||
// hack for 2206 ([2206]=[2206]+[2203]
|
||||
double value = groupedRecord.TotalValue;
|
||||
if (groupedRecord.FinalCode.StartsWith("2206"))
|
||||
{
|
||||
var month = groupedRecord.FinalCode.Substring(4, 2);
|
||||
var toSumUp = groupedData.FirstOrDefault(x => x.FinalCode == $"2203{month}");
|
||||
if (toSumUp == null)
|
||||
{
|
||||
_logger.LogWarning("{ProcessorType}: 2203{month} not found (to sum up with 2206{month}", ProcessorType, month, month);
|
||||
}
|
||||
else
|
||||
{
|
||||
value+= toSumUp.TotalValue;
|
||||
}
|
||||
}
|
||||
var newRecord = new Record
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
Code = groupedRecord.FinalCode,
|
||||
CreatedAt = DateTime.UtcNow,
|
||||
ModifiedAt = DateTime.UtcNow,
|
||||
Value1 = groupedRecord.TotalValue,
|
||||
Value1 = value,
|
||||
Desc1 = groupedRecord.Department
|
||||
};
|
||||
|
||||
@@ -281,14 +308,135 @@ public class MorskaD6Processor : MorskaBaseProcessor
|
||||
ProcessorType, newRecord.Code, newRecord.Value1, groupedRecord.Department, groupedRecord.DepartmentCode,
|
||||
groupedRecord.Type, groupedRecord.Month);
|
||||
}
|
||||
|
||||
// SELLS
|
||||
|
||||
var secondDataSource = dataSources.Last();
|
||||
|
||||
if (secondDataSource.Records == null || !secondDataSource.Records.Any())
|
||||
{
|
||||
_logger.LogWarning("{ProcessorType}: Second data source has no records to process", ProcessorType);
|
||||
return newRecords;
|
||||
}
|
||||
|
||||
|
||||
foreach (var sellCodeConfig in SellCodesConfiguration)
|
||||
{
|
||||
var calc = new BaseCalc(sellCodeConfig);
|
||||
if (!calc.IsFormulaCorrect())
|
||||
{
|
||||
_logger.LogDebug("{ProcessorType}: Invalid formula: {SellCodeConfig}", ProcessorType, sellCodeConfig);
|
||||
continue;
|
||||
}
|
||||
var codes = calc.GetCodes();
|
||||
var resultCode = calc.GetResultCode();
|
||||
|
||||
for (var i = 1; i <= 12; i++)
|
||||
{
|
||||
var monthRecords = secondDataSource.Records
|
||||
.Where(x => x.Code is { Length: 6 } && x.Code.EndsWith($"{i:D2}") && x.Value1.HasValue)
|
||||
.ToList();
|
||||
if (monthRecords.Count == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
var ingredients = monthRecords.ToDictionary(x => x.Code!.Substring(0, 4), x => x.Value1!.Value);
|
||||
double result = 0;
|
||||
try
|
||||
{
|
||||
result = calc.Calculate(ingredients);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.LogError(e, "{ProcessorType}: Failed to calculate sell code {ResultCode} for month {Month}",
|
||||
ProcessorType, resultCode, i);
|
||||
}
|
||||
|
||||
var newRecord = new Record
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
Code = $"{resultCode}{i:D2}",
|
||||
CreatedAt = DateTime.UtcNow,
|
||||
ModifiedAt = DateTime.UtcNow,
|
||||
Value1 = result
|
||||
};
|
||||
newRecords.Add(newRecord);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
// Process records from secondDataSource
|
||||
foreach (var record in secondDataSource.Records)
|
||||
{
|
||||
if (string.IsNullOrEmpty(record.Code) || record.Code.Length < 6 || !record.Value1.HasValue)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Extract month from last two digits
|
||||
var monthStr = record.Code.Substring(record.Code.Length - 2);
|
||||
if (!int.TryParse(monthStr, out var month) || month < 1 || month > 13)
|
||||
{
|
||||
_logger.LogDebug("{ProcessorType}: Invalid month in code {Code}", ProcessorType, record.Code);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Extract base code (without month)
|
||||
var baseCode = record.Code.Substring(0, record.Code.Length - 2);
|
||||
|
||||
// Check if we have mapping for this code
|
||||
if (mappingDictionary.TryGetValue(baseCode, out var targetCode))
|
||||
{
|
||||
// Create target code with month
|
||||
var targetCodeWithMonth = $"{targetCode}{monthStr}";
|
||||
|
||||
// Add/sum value
|
||||
if (sellResults.ContainsKey(targetCodeWithMonth))
|
||||
{
|
||||
sellResults[targetCodeWithMonth] += record.Value1.Value;
|
||||
_logger.LogDebug("{ProcessorType}: Added to existing record {TargetCode}: {Value} (total: {Total})",
|
||||
ProcessorType, targetCodeWithMonth, record.Value1.Value, sellResults[targetCodeWithMonth]);
|
||||
}
|
||||
else
|
||||
{
|
||||
sellResults[targetCodeWithMonth] = record.Value1.Value;
|
||||
_logger.LogDebug("{ProcessorType}: Created new record {TargetCode}: {Value}",
|
||||
ProcessorType, targetCodeWithMonth, record.Value1.Value);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogDebug("{ProcessorType}: No mapping found for code {BaseCode}", ProcessorType, baseCode);
|
||||
}
|
||||
}
|
||||
|
||||
// Add results to newRecords
|
||||
foreach (var sellResult in sellResults)
|
||||
{
|
||||
var newRecord = new Record
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
Code = sellResult.Key,
|
||||
CreatedAt = DateTime.UtcNow,
|
||||
ModifiedAt = DateTime.UtcNow,
|
||||
Value1 = sellResult.Value
|
||||
};
|
||||
|
||||
newRecords.Add(newRecord);
|
||||
|
||||
_logger.LogDebug("{ProcessorType}: Added sell record {Code} with value {Value}",
|
||||
ProcessorType, newRecord.Code, newRecord.Value1);
|
||||
}
|
||||
|
||||
_logger.LogInformation("{ProcessorType}: Processed {SellRecordCount} sell records from {OriginalSellCount} source records",
|
||||
ProcessorType, sellResults.Count, secondDataSource.Records.Count);
|
||||
|
||||
_logger.LogInformation(
|
||||
"{ProcessorType}: Processed {GroupCount} unique grouped records from {OriginalCount} original records",
|
||||
ProcessorType, newRecords.Count, firstDataSource.Records.Count);
|
||||
|
||||
*/
|
||||
return newRecords;
|
||||
}
|
||||
|
||||
private void SaveProcessedLayer(Layer processedLayer, List<Record> newRecords)
|
||||
{
|
||||
var existsInDb = _db.Layers.Any(x => x.Id == processedLayer.Id);
|
||||
@@ -310,7 +458,6 @@ public class MorskaD6Processor : MorskaBaseProcessor
|
||||
_logger.LogDebug("{ProcessorType}: Saved {RecordCount} records for layer {LayerId}",
|
||||
ProcessorType, newRecords.Count, processedLayer.Id);
|
||||
}
|
||||
|
||||
private void SaveRecords(Guid layerId, ICollection<Record> records)
|
||||
{
|
||||
// Remove existing records for this layer
|
||||
@@ -336,12 +483,10 @@ public class MorskaD6Processor : MorskaBaseProcessor
|
||||
_logger.LogDebug("{ProcessorType}: Added {RecordCount} new records for layer {LayerId}",
|
||||
ProcessorType, records.Count, layerId);
|
||||
}
|
||||
|
||||
private string? GetRecordValue(ICollection<Record> records, string code)
|
||||
{
|
||||
return records.FirstOrDefault(x => x.Code == code)?.Desc1;
|
||||
}
|
||||
|
||||
private string GetDepartmentByType(string type, string originalDepartment)
|
||||
{
|
||||
var typesThatUseDepartment = new[] { "02", "09", "10", "11", "12", "13", "14", "15" };
|
||||
@@ -374,4 +519,238 @@ public class MorskaD6Processor : MorskaBaseProcessor
|
||||
return string.IsNullOrEmpty(originalDepartment) ? "OTHER" : originalDepartment;
|
||||
}
|
||||
}
|
||||
|
||||
// Export to Google
|
||||
|
||||
private void UpdateGoogleSheetReport(Guid sourceId)
|
||||
{
|
||||
const string googleSheetName = "Raport_R6_DRAFT_2025";
|
||||
try
|
||||
{
|
||||
const string sheetId = "19AljwrZRg2Rc5hagkfK3u8LIo3x9_GmFNnZEeOJ5g_g";
|
||||
|
||||
_logger.LogDebug("{ProcessorType}: Updating Google Sheet report {SheetName}",
|
||||
ProcessorType, googleSheetName);
|
||||
|
||||
// Get processed layer data
|
||||
var processedLayer = _db.Layers
|
||||
.Where(x => x.Id == sourceId)
|
||||
.Include(x => x.Records)
|
||||
.AsNoTracking()
|
||||
.FirstOrDefault();
|
||||
|
||||
if (processedLayer == null)
|
||||
{
|
||||
throw new InvalidOperationException($"Processed layer {sourceId} not found");
|
||||
}
|
||||
|
||||
// Get codes from sheet header (row 4, columns C to AA)
|
||||
var codesResponse = _googleSheetValues.Get(sheetId, $"{googleSheetName}!C4:AB4").Execute();
|
||||
var codesRow = codesResponse.Values[0];
|
||||
|
||||
// Update data based on 6-digit codes from processedLayer
|
||||
UpdateMonthlyDataFromCodes(sheetId, codesRow, processedLayer);
|
||||
Thread.Sleep(1000);
|
||||
|
||||
// Update yearly summary data (row 20)
|
||||
UpdateYearlySummaryData(sheetId, codesRow, processedLayer);
|
||||
Thread.Sleep(1000);
|
||||
|
||||
// Update timestamps
|
||||
UpdateTimestamps(sheetId, processedLayer);
|
||||
Thread.Sleep(1000);
|
||||
|
||||
_logger.LogInformation("{ProcessorType}: Successfully updated Google Sheet report {SheetName}",
|
||||
ProcessorType, googleSheetName);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.LogError(e, "{ProcessorType}: Failed to update Google Sheet report {SheetName}",
|
||||
ProcessorType, googleSheetName);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateYearlySummaryData(string sheetId, IList<object> codesRow, Layer processedLayer)
|
||||
{
|
||||
const string googleSheetName = "Raport_R6_DRAFT_2025";
|
||||
|
||||
if (processedLayer.Records == null)
|
||||
{
|
||||
_logger.LogWarning("{ProcessorType}: No records found in processed layer for yearly summary", ProcessorType);
|
||||
return;
|
||||
}
|
||||
|
||||
var summaryValues = new List<object>();
|
||||
|
||||
foreach (string fourDigitCode in codesRow)
|
||||
{
|
||||
// Calculate sum for all months (01-12) for this 4-digit code
|
||||
double yearlySum = 0;
|
||||
|
||||
for (var month = 1; month <= 12; month++)
|
||||
{
|
||||
var sixDigitCode = $"{fourDigitCode}{month:D2}";
|
||||
var record = processedLayer.Records.FirstOrDefault(x => x.Code == sixDigitCode);
|
||||
|
||||
if (record?.Value1.HasValue == true)
|
||||
{
|
||||
yearlySum += record.Value1.Value;
|
||||
}
|
||||
}
|
||||
|
||||
summaryValues.Add(yearlySum.ToString(CultureInfo.GetCultureInfo("pl-PL")));
|
||||
|
||||
_logger.LogDebug("{ProcessorType}: Calculated yearly sum for code {FourDigitCode}: {YearlySum}",
|
||||
ProcessorType, fourDigitCode, yearlySum);
|
||||
}
|
||||
|
||||
// Update row 20 with yearly sums
|
||||
var valueRange = new ValueRange
|
||||
{
|
||||
Values = new List<IList<object>> { summaryValues }
|
||||
};
|
||||
|
||||
var columnStart = "C";
|
||||
var columnEnd = GetColumnLetter(codesRow.Count + 1); // +1 because we start from C (index 2)
|
||||
var range = $"{googleSheetName}!{columnStart}20:{columnEnd}20";
|
||||
|
||||
var update = _googleSheetValues.Update(valueRange, sheetId, range);
|
||||
update.ValueInputOption = SpreadsheetsResource.ValuesResource.UpdateRequest.ValueInputOptionEnum.USERENTERED;
|
||||
update.Execute();
|
||||
|
||||
_logger.LogInformation("{ProcessorType}: Updated yearly summary data in row 20 with {CodeCount} totals",
|
||||
ProcessorType, codesRow.Count);
|
||||
}
|
||||
|
||||
private void UpdateMonthlyDataFromCodes(string sheetId, IList<object> codesRow, Layer processedLayer)
|
||||
{
|
||||
const string googleSheetName = "Raport_R6_DRAFT_2025";
|
||||
|
||||
if (processedLayer.Records == null)
|
||||
{
|
||||
_logger.LogWarning("{ProcessorType}: No records found in processed layer", ProcessorType);
|
||||
return;
|
||||
}
|
||||
|
||||
// Create a dictionary to store updates for each cell
|
||||
var cellUpdates = new Dictionary<string, string>();
|
||||
|
||||
foreach (var record in processedLayer.Records)
|
||||
{
|
||||
if (string.IsNullOrEmpty(record.Code) || record.Code.Length != 6)
|
||||
{
|
||||
_logger.LogWarning("{ProcessorType}: Invalid code format in record {RecordId}: {Code}",
|
||||
ProcessorType, record.Id, record.Code);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Extract 4-digit code and month from 6-digit code
|
||||
var fourDigitCode = record.Code.Substring(0, 4);
|
||||
var monthStr = record.Code.Substring(4, 2);
|
||||
|
||||
if (!int.TryParse(monthStr, out var month) || month < 1 || month > 12)
|
||||
{
|
||||
_logger.LogWarning("{ProcessorType}: Invalid month in code {Code}", ProcessorType, record.Code);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Find column index for the 4-digit code
|
||||
var columnIndex = -1;
|
||||
for (var i = 0; i < codesRow.Count; i++)
|
||||
{
|
||||
if (codesRow[i]?.ToString() == fourDigitCode)
|
||||
{
|
||||
columnIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (columnIndex == -1)
|
||||
{
|
||||
_logger.LogWarning("{ProcessorType}: Code {FourDigitCode} not found in sheet header",
|
||||
ProcessorType, fourDigitCode);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Calculate row (month 01 = row 7, month 02 = row 8, etc.)
|
||||
var targetRow = 6 + month; // row 7 for month 01, row 8 for month 02, etc.
|
||||
|
||||
// Calculate column letter (C = index 0, D = index 1, etc.)
|
||||
var targetColumn = GetColumnLetter(columnIndex + 2); // +2 because C is the first column (index 0)
|
||||
|
||||
var cellAddress = $"{targetColumn}{targetRow}";
|
||||
var value = record.Value1?.ToString(CultureInfo.GetCultureInfo("pl-PL")) ?? "0";
|
||||
|
||||
cellUpdates[cellAddress] = value;
|
||||
|
||||
_logger.LogDebug(
|
||||
"{ProcessorType}: Mapping code {SixDigitCode} (base: {FourDigitCode}, month: {Month}) to cell {CellAddress} with value {Value}",
|
||||
ProcessorType, record.Code, fourDigitCode, month, cellAddress, value);
|
||||
}
|
||||
|
||||
// Batch update all cells
|
||||
if (cellUpdates.Any())
|
||||
{
|
||||
var batchUpdateRequest = new BatchUpdateValuesRequest
|
||||
{
|
||||
ValueInputOption = "USER_ENTERED",
|
||||
Data = cellUpdates.Select(kvp => new ValueRange
|
||||
{
|
||||
Range = $"{googleSheetName}!{kvp.Key}",
|
||||
Values = new List<IList<object>> { new List<object> { kvp.Value } }
|
||||
}).ToList()
|
||||
};
|
||||
|
||||
var batchUpdate = _googleSheetValues.BatchUpdate(batchUpdateRequest, sheetId);
|
||||
batchUpdate.Execute();
|
||||
|
||||
_logger.LogInformation("{ProcessorType}: Updated {CellCount} cells in Google Sheet",
|
||||
ProcessorType, cellUpdates.Count);
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogWarning("{ProcessorType}: No valid data found to update in Google Sheet", ProcessorType);
|
||||
}
|
||||
}
|
||||
|
||||
private string GetColumnLetter(int columnIndex)
|
||||
{
|
||||
var columnLetter = string.Empty;
|
||||
while (columnIndex >= 0)
|
||||
{
|
||||
columnLetter = (char)('A' + (columnIndex % 26)) + columnLetter;
|
||||
columnIndex = columnIndex / 26 - 1;
|
||||
}
|
||||
|
||||
return columnLetter;
|
||||
}
|
||||
|
||||
private void UpdateTimestamps(string sheetId, Layer processedLayer)
|
||||
{
|
||||
const string googleSheetName = "Raport_R6_DRAFT_2025";
|
||||
|
||||
var timeUtc = processedLayer.ModifiedAt.ToString("dd.MM.yyyy HH:mm:ss", CultureInfo.GetCultureInfo("pl-PL"));
|
||||
|
||||
var warsawTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Central European Standard Time");
|
||||
var warsawTime = TimeZoneInfo.ConvertTimeFromUtc(processedLayer.ModifiedAt.ToUniversalTime(), warsawTimeZone);
|
||||
var timeWarsaw = warsawTime.ToString("dd.MM.yyyy HH:mm:ss", CultureInfo.GetCultureInfo("pl-PL"));
|
||||
|
||||
var valueRangeTime = new ValueRange
|
||||
{
|
||||
Values = new List<IList<object>>
|
||||
{
|
||||
new List<object> { timeUtc },
|
||||
new List<object> { timeWarsaw }
|
||||
}
|
||||
};
|
||||
|
||||
var updateTime = _googleSheetValues.Update(valueRangeTime, sheetId, $"{googleSheetName}!G1:G2");
|
||||
updateTime.ValueInputOption =
|
||||
SpreadsheetsResource.ValuesResource.UpdateRequest.ValueInputOptionEnum.USERENTERED;
|
||||
updateTime.Execute();
|
||||
|
||||
_logger.LogDebug("{ProcessorType}: Updated timestamps in Google Sheet - UTC: {TimeUtc}, Warsaw: {TimeWarsaw}",
|
||||
ProcessorType, timeUtc, timeWarsaw);
|
||||
}
|
||||
}
|
||||
@@ -384,7 +384,7 @@ public class MorskaT1R1Processor : MorskaBaseProcessor
|
||||
}
|
||||
|
||||
// Get codes from sheet header
|
||||
var codesResponse = _googleSheetValues.Get(sheetId, $"{GoogleSheetName}!C4:DC4").Execute();
|
||||
var codesResponse = _googleSheetValues.Get(sheetId, $"{GoogleSheetName}!C4:DS4").Execute();
|
||||
var codesRow = codesResponse.Values[0];
|
||||
|
||||
// Update monthly data (months 1-12)
|
||||
@@ -430,7 +430,7 @@ public class MorskaT1R1Processor : MorskaBaseProcessor
|
||||
valueRange.Values.Add(monthValues);
|
||||
}
|
||||
|
||||
var update = _googleSheetValues.Update(valueRange, sheetId, $"{GoogleSheetName}!C7:DC18");
|
||||
var update = _googleSheetValues.Update(valueRange, sheetId, $"{GoogleSheetName}!C7:DS18");
|
||||
update.ValueInputOption = SpreadsheetsResource.ValuesResource.UpdateRequest.ValueInputOptionEnum.USERENTERED;
|
||||
update.Execute();
|
||||
|
||||
@@ -461,7 +461,7 @@ public class MorskaT1R1Processor : MorskaBaseProcessor
|
||||
}
|
||||
valueRange.Values.Add(summaryValues);
|
||||
|
||||
var update = _googleSheetValues.Update(valueRange, sheetId, $"{GoogleSheetName}!C19:DC20");
|
||||
var update = _googleSheetValues.Update(valueRange, sheetId, $"{GoogleSheetName}!C19:DS20");
|
||||
update.ValueInputOption = SpreadsheetsResource.ValuesResource.UpdateRequest.ValueInputOptionEnum.USERENTERED;
|
||||
update.Execute();
|
||||
|
||||
|
||||
@@ -70,7 +70,6 @@ public class LayersController : Controller
|
||||
return BadRequest(e.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("{id:guid}")]
|
||||
public IActionResult Get(Guid id)
|
||||
@@ -91,7 +90,6 @@ public class LayersController : Controller
|
||||
return BadRequest(e.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("getForPowerBI/{apiKey}/{number:int}")]
|
||||
public IActionResult GetByNumber(string apiKey, int number)
|
||||
@@ -140,7 +138,6 @@ public class LayersController : Controller
|
||||
return BadRequest(e.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("getConfiguration/{apiKey}/{number:int}")]
|
||||
public IActionResult GetConfigurationByNumber(string apiKey, int number)
|
||||
@@ -202,7 +199,6 @@ public class LayersController : Controller
|
||||
return BadRequest();
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("exportToGoogleSheet/{id:guid}")]
|
||||
public IActionResult ExportToGoogleSheet(Guid id)
|
||||
@@ -237,7 +233,6 @@ public class LayersController : Controller
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("ProcessQueue/{apiKey}")]
|
||||
[AllowAnonymous]
|
||||
@@ -253,7 +248,6 @@ public class LayersController : Controller
|
||||
// Queue processing implementation would go here
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("AutoImport/{apiKey}/{nameFilter}")]
|
||||
[AllowAnonymous]
|
||||
|
||||
@@ -16,10 +16,11 @@ if (builder.Environment.IsProduction())
|
||||
{
|
||||
builder.Host.UseSerilog((context, configuration) =>
|
||||
{
|
||||
var instanceName = context.Configuration["InstanceName"] ?? "unknown";
|
||||
configuration
|
||||
.ReadFrom.Configuration(context.Configuration)
|
||||
.Enrich.FromLogContext()
|
||||
.Enrich.WithProperty("Application", "DiunaBI")
|
||||
.Enrich.WithProperty("Application", $"DiunaBI-{instanceName}")
|
||||
.Enrich.WithProperty("Version", Assembly.GetExecutingAssembly().GetName().Version?.ToString() ?? "unknown")
|
||||
.Enrich.WithEnvironmentName()
|
||||
.Enrich.WithMachineName();
|
||||
|
||||
@@ -49,6 +49,7 @@
|
||||
"ConnectionStrings": {
|
||||
"SQLDatabase": "#{db-connection-string}#"
|
||||
},
|
||||
"InstanceName": "#{instance-name}#",
|
||||
"GoogleClientId": "#{google-backend-login-client-id}#",
|
||||
"Secret": "#{google-backend-login-secret}#",
|
||||
"apiKey": "#{api-key}#",
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
###
|
||||
GET http://localhost:5400/api/Layers/AutoImport/10763478CB738D4ecb2h76g803478CB738D4e/D1-
|
||||
GET http://localhost:5400/api/Layers/AutoImport/10763478CB738D4ecb2h76g803478CB738D4e/D3-
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
DECLARE @JustForDebug TINYINT = 1;
|
||||
DECLARE @JustForDebug TINYINT = 0;
|
||||
|
||||
-- SETUP VARIABLES
|
||||
DECLARE @Type NVARCHAR(3) = 'D3';
|
||||
DECLARE @Month INT = 3;
|
||||
DECLARE @Month INT = 7;
|
||||
DECLARE @Year INT = 2025;
|
||||
|
||||
IF @Type NOT IN ('D3')
|
||||
@@ -73,4 +73,8 @@ INSERT INTO [diunabi-morska].[dbo].[Records]
|
||||
([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);
|
||||
|
||||
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;
|
||||
@@ -1,10 +1,10 @@
|
||||
DECLARE @JustForDebug TINYINT = 0;
|
||||
|
||||
-- SETUP VARIABLES
|
||||
DECLARE @Type NVARCHAR(3) = 'K5';
|
||||
DECLARE @Month INT = 6;
|
||||
DECLARE @Type NVARCHAR(3) = 'D1';
|
||||
DECLARE @Month INT = 7;
|
||||
DECLARE @Year INT = 2025;
|
||||
DECLARE @MonthName NVARCHAR(20) = 'Czerwiec_2025';
|
||||
DECLARE @MonthName NVARCHAR(20) = 'Lipiec_2025';
|
||||
|
||||
IF @Type NOT IN ('K5', 'PU', 'AK', 'FK', 'D1', 'FK2')
|
||||
BEGIN
|
||||
@@ -15,7 +15,7 @@ END;
|
||||
DECLARE @Range NVARCHAR(20);
|
||||
SET @Range =
|
||||
CASE @Type
|
||||
WHEN 'D1' THEN 'A7:R200'
|
||||
WHEN 'D1' THEN 'A7:S200'
|
||||
WHEN 'FK2' THEN 'A8:J1652'
|
||||
ELSE 'E4:DA5'
|
||||
END;
|
||||
@@ -50,6 +50,22 @@ BEGIN
|
||||
SELECT 'SheetId is NULL' AS Logger;
|
||||
RETURN;
|
||||
END;
|
||||
DECLARE @Plugin NVARCHAR(100);
|
||||
SET @Plugin =
|
||||
CASE @Type
|
||||
WHEN 'K5' THEN 'Morska.Import.Standard'
|
||||
WHEN 'PU' THEN 'Morska.Import.Standard'
|
||||
WHEN 'AK' THEN 'Morska.Import.Standard'
|
||||
WHEN 'FK' THEN 'Morska.Import.Standard'
|
||||
WHEN 'D1' THEN 'Morska.Import.D1'
|
||||
WHEN 'FK2' THEN 'Morska.Import.FK2'
|
||||
ELSE NULL -- If @Type doesn't match, set it to NULL
|
||||
END;
|
||||
IF @SheetId IS NULL
|
||||
BEGIN
|
||||
SELECT 'SheetId is NULL' AS Logger;
|
||||
RETURN;
|
||||
END;
|
||||
DECLARE @LayerId UNIQUEIDENTIFIER = NEWID();
|
||||
|
||||
SELECT @Name AS Name,@Range AS Range, @ImportType AS ImportType, @StartDate AS StartDate, @EndDate AS EndDate;
|
||||
@@ -105,6 +121,10 @@ INSERT INTO [diunabi-morska].[dbo].[Records]
|
||||
([Id], [Code], [Desc1], [CreatedAt], [ModifiedAt], [CreatedById], [ModifiedById], [IsDeleted], [LayerId])
|
||||
VALUES ((SELECT NEWID()), 'Type', 'ImportWorker', 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()), 'Plugin', @Plugin, 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()), 'IsEnabled', 'True', GETDATE(), GETDATE(), '117be4f0-b5d1-41a1-a962-39dc30cce368', '117be4f0-b5d1-41a1-a962-39dc30cce368', 0, @LayerId);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
DECLARE @JustForDebug TINYINT = 0;
|
||||
|
||||
-- SETUP VARIABLES
|
||||
DECLARE @Month INT = 6;
|
||||
DECLARE @Month INT = 9;
|
||||
DECLARE @Year INT = 2025;
|
||||
|
||||
DECLARE @Number INT = (SELECT COUNT(id) + 1 FROM [diunabi-morska].[dbo].[Layers]);
|
||||
@@ -63,4 +63,12 @@ VALUES ((SELECT NEWID()), 'Month', @FormattedMonth, GETDATE(), GETDATE(), '117be
|
||||
|
||||
INSERT INTO [diunabi-morska].[dbo].[Records]
|
||||
([Id], [Code], [Desc1], [CreatedAt], [ModifiedAt], [CreatedById], [ModifiedById], [IsDeleted], [LayerId])
|
||||
VALUES ((SELECT NEWID()), 'DynamicCode-0', '[1001]=[9000]+[9005]-[9006]', GETDATE(), GETDATE(), '117be4f0-b5d1-41a1-a962-39dc30cce368', '117be4f0-b5d1-41a1-a962-39dc30cce368', 0, @LayerId);
|
||||
VALUES ((SELECT NEWID()), 'DynamicCode-0', '[1001]=[9000]+[9005]-[9006]', 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()), 'Plugin', 'Morska.Process.T3.MultiSourceSummary', 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()), 'Priority', '80', GETDATE(), GETDATE(), '117be4f0-b5d1-41a1-a962-39dc30cce368', '117be4f0-b5d1-41a1-a962-39dc30cce368', 0, @LayerId);
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
-- T3-SingleSource
|
||||
|
||||
DECLARE @JustForDebug TINYINT = 1;
|
||||
DECLARE @JustForDebug TINYINT = 0;
|
||||
|
||||
-- SETUP VARIABLES
|
||||
DECLARE @Type NVARCHAR(3) = 'FK';
|
||||
DECLARE @Month INT = 6;
|
||||
DECLARE @Month INT = 9;
|
||||
DECLARE @Year INT = 2025;
|
||||
|
||||
IF @Type NOT IN ('K5', 'PU', 'AK', 'FK')
|
||||
@@ -68,3 +68,11 @@ VALUES ((SELECT NEWID()), 'Year', @Year, GETDATE(), GETDATE(), '117be4f0-b5d1-41
|
||||
INSERT INTO [diunabi-morska].[dbo].[Records]
|
||||
([Id], [Code], [Desc1], [CreatedAt], [ModifiedAt], [CreatedById], [ModifiedById], [IsDeleted], [LayerId])
|
||||
VALUES ((SELECT NEWID()), 'Month', @FormattedMonth, 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()), 'Plugin', 'Morska.Process.T3.SingleSource', 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()), 'Priority', '100', GETDATE(), GETDATE(), '117be4f0-b5d1-41a1-a962-39dc30cce368', '117be4f0-b5d1-41a1-a962-39dc30cce368', 0, @LayerId);
|
||||
|
||||
@@ -4,7 +4,7 @@ DECLARE @JustForDebug TINYINT = 0;
|
||||
|
||||
-- SETUP VARIABLES
|
||||
DECLARE @Type NVARCHAR(3) = 'FK2';
|
||||
DECLARE @Month INT = 6;
|
||||
DECLARE @Month INT = 9;
|
||||
DECLARE @Year INT = 2025;
|
||||
|
||||
DECLARE @Number INT = (SELECT COUNT(id) + 1 FROM [diunabi-morska].[dbo].[Layers]);
|
||||
@@ -62,3 +62,11 @@ VALUES ((SELECT NEWID()), 'Year', @Year, GETDATE(), GETDATE(), '117be4f0-b5d1-41
|
||||
INSERT INTO [diunabi-morska].[dbo].[Records]
|
||||
([Id], [Code], [Desc1], [CreatedAt], [ModifiedAt], [CreatedById], [ModifiedById], [IsDeleted], [LayerId])
|
||||
VALUES ((SELECT NEWID()), 'Month', @FormattedMonth, 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()), 'Plugin', 'Morska.Process.T4.SingleSource', 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()), 'Priority', '100', GETDATE(), GETDATE(), '117be4f0-b5d1-41a1-a962-39dc30cce368', '117be4f0-b5d1-41a1-a962-39dc30cce368', 0, @LayerId);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
-- T5-LastValue
|
||||
-- T5-LastValue41
|
||||
DECLARE @JustForDebug TINYINT = 0;
|
||||
|
||||
-- SETUP VARIABLES
|
||||
DECLARE @Month INT = 4;
|
||||
DECLARE @Month INT = 7;
|
||||
DECLARE @Year INT = 2025;
|
||||
|
||||
DECLARE @Number INT = (SELECT COUNT(id) + 1 FROM [diunabi-morska].[dbo].[Layers]);
|
||||
@@ -50,6 +50,10 @@ INSERT INTO [diunabi-morska].[dbo].[Records]
|
||||
([Id], [Code], [Desc1], [CreatedAt], [ModifiedAt], [CreatedById], [ModifiedById], [IsDeleted], [LayerId])
|
||||
VALUES ((SELECT NEWID()), 'ProcessType', 'T5-LastValues', 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()), 'Plugin', 'Morska.Process.T5.LastValues', 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()), 'IsEnabled', 'True', GETDATE(), GETDATE(), '117be4f0-b5d1-41a1-a962-39dc30cce368', '117be4f0-b5d1-41a1-a962-39dc30cce368', 0, @LayerId);
|
||||
|
||||
@@ -4,7 +4,7 @@ DECLARE @JustForDebug TINYINT = 0;
|
||||
-- SETUP VARIABLES
|
||||
DECLARE @Number INT = (SELECT COUNT(id) + 1 FROM [diunabi-morska].[dbo].[Layers]);
|
||||
DECLARE @Name NVARCHAR(50) = CONCAT(
|
||||
'L', @Number, '-D-DEPARTMENTS'
|
||||
'L', @Number, '-D-D6-SELL-CODES'
|
||||
);
|
||||
DECLARE @LayerId UNIQUEIDENTIFIER = NEWID();
|
||||
|
||||
@@ -27,10 +27,16 @@ DECLARE @Array TABLE (
|
||||
|
||||
INSERT INTO @Array (Code, Desc1)
|
||||
VALUES
|
||||
('0', 'OTHER'),
|
||||
('1','K5'),
|
||||
('2','AK'),
|
||||
('3','PU')
|
||||
('1002', '1102'),
|
||||
('1003','1202'),
|
||||
('1008','1302'),
|
||||
('1009','1302'),
|
||||
('9085','1203'),
|
||||
('1010','1304'),
|
||||
('9086','1005'),
|
||||
('1021','1206'),
|
||||
('9089','1207'),
|
||||
('9091','1208')
|
||||
|
||||
-- Loop through the array and insert into the target table
|
||||
DECLARE @Code NVARCHAR(50);
|
||||
|
||||
@@ -1,5 +1 @@
|
||||
INSERT INTO [diunabi-morska].[dbo].[Records]
|
||||
([Id], [Code], [Desc1], [CreatedAt], [ModifiedAt], [CreatedById], [ModifiedById], [IsDeleted], [LayerId])
|
||||
VALUES ((SELECT NEWID()), 'SourceLayerSell', 'L4187-P-2025-R1-T1',
|
||||
GETDATE(), GETDATE(), '117be4f0-b5d1-41a1-a962-39dc30cce368', '117be4f0-b5d1-41a1-a962-39dc30cce368', 0,
|
||||
'd1e6e8d2-a13b-421f-84cb-a9ccd5b1c6f5');
|
||||
|
||||
|
||||
@@ -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].[Layers] WHERE [Id] = @LayerId;
|
||||
Reference in New Issue
Block a user