feat(dal): Созданы таблицы JobGroupTypes+UnitsInTemplates, обновлен ключ уникального индекса шаблонов

This commit is contained in:
Mikhail Kuznetsov
2025-11-14 14:48:56 +10:00
parent 334595e81c
commit 48c8741395
19 changed files with 12199 additions and 16 deletions

View File

@@ -249,9 +249,9 @@ namespace PARR.API.Controllers.V1
changed = true;
}
if (orig.isParentRelationships != request.isParentRelationships)
if (orig.IsParentRelationships != request.isParentRelationships)
{
orig.isParentRelationships = request.isParentRelationships;
orig.IsParentRelationships = request.isParentRelationships;
changed = true;
}

View File

@@ -83,6 +83,8 @@ namespace PARR.DAL.Context
public DbSet<UnitInUnit> UnitInUnits { get; set; }
public DbSet<UnitsInTemplate> UnitsInTemplates { get; set; }
#endregion
#region Job
@@ -95,6 +97,8 @@ namespace PARR.DAL.Context
public DbSet<JobGroup> JobGroups { get; set; }
public DbSet<JobGroupType> JobGroupTypes { get; set; }
public DbSet<JobRelationshipFilter> JobRelationshipFilters { get; set; }
@@ -119,6 +123,22 @@ namespace PARR.DAL.Context
});
#endregion
#region UnitsInTemplate
modelBuilder.Entity<UnitsInTemplate>()
.HasKey(t => new { t.TemplateId, t.UnitId });
#endregion
#region JobGroupType
modelBuilder.Entity<JobGroupType>(f =>
{
f.HasData(
new() { Id = new Guid("4FA62E79-86BB-47C2-BE1A-72A716A170FA"), DateCreated = dateCreated, DateModified = null, Name = JobGroupTypesEnum.Simple.ToString(), Code = JobGroupTypesEnum.Simple },
new() { Id = new Guid("6EC58B1A-5C40-47B9-B036-4FA490E8D503"), DateCreated = dateCreated, DateModified = null, Name = JobGroupTypesEnum.Umbrella.ToString(), Code = JobGroupTypesEnum.Umbrella },
new() { Id = new Guid("318625E5-F833-436A-99DF-2A382A1E71C7"), DateCreated = dateCreated, DateModified = null, Name = JobGroupTypesEnum.Group.ToString(), Code = JobGroupTypesEnum.Group }
);
});
#endregion
#region ApplicationType
modelBuilder.Entity<ApplicationType>(f =>
{

View File

@@ -0,0 +1,20 @@
namespace PARR.DAL.Contracts
{
public enum JobGroupTypesEnum
{
/// <summary>
/// Обычный тип без особенностей
/// </summary>
Simple = 0,
/// <summary>
/// Тип зонтик, когда отслеживается количество дочерних или родительских связей
/// </summary>
Umbrella = 1,
/// <summary>
/// Тип группа, когда шаблоны группируются по полю Field
/// </summary>
Group = 2
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,103 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional
namespace PARR.DAL.Migrations
{
/// <inheritdoc />
public partial class tblJobGroupTypeCreate : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.RenameColumn(
name: "isParentRelationships",
schema: "job",
table: "Jobs",
newName: "IsParentRelationships");
migrationBuilder.AddColumn<Guid>(
name: "GroupTypeId",
schema: "job",
table: "Groups",
type: "uuid",
nullable: false,
defaultValue: new Guid("4FA62E79-86BB-47C2-BE1A-72A716A170FA"));
migrationBuilder.CreateTable(
name: "GroupTypes",
schema: "job",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
DateCreated = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
Code = table.Column<int>(type: "integer", nullable: false),
Name = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_GroupTypes", x => x.Id);
},
comment: "Таблица типов групп работ");
migrationBuilder.InsertData(
schema: "job",
table: "GroupTypes",
columns: new[] { "Id", "Code", "DateCreated", "Name" },
values: new object[,]
{
{ new Guid("318625e5-f833-436a-99df-2a382a1e71c7"), 2, new DateTimeOffset(new DateTime(2023, 5, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0)), "Group" },
{ new Guid("4fa62e79-86bb-47c2-be1a-72a716a170fa"), 0, new DateTimeOffset(new DateTime(2023, 5, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0)), "Simple" },
{ new Guid("6ec58b1a-5c40-47b9-b036-4fa490e8d503"), 1, new DateTimeOffset(new DateTime(2023, 5, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0)), "Umbrella" }
});
migrationBuilder.CreateIndex(
name: "IX_Groups_GroupTypeId",
schema: "job",
table: "Groups",
column: "GroupTypeId");
migrationBuilder.AddForeignKey(
name: "FK_Groups_GroupTypes_GroupTypeId",
schema: "job",
table: "Groups",
column: "GroupTypeId",
principalSchema: "job",
principalTable: "GroupTypes",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Groups_GroupTypes_GroupTypeId",
schema: "job",
table: "Groups");
migrationBuilder.DropTable(
name: "GroupTypes",
schema: "job");
migrationBuilder.DropIndex(
name: "IX_Groups_GroupTypeId",
schema: "job",
table: "Groups");
migrationBuilder.DropColumn(
name: "GroupTypeId",
schema: "job",
table: "Groups");
migrationBuilder.RenameColumn(
name: "IsParentRelationships",
schema: "job",
table: "Jobs",
newName: "isParentRelationships");
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,98 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace PARR.DAL.Migrations
{
/// <inheritdoc />
public partial class tblUnitsInTemplates : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropIndex(
name: "IX_Templates_Name",
table: "Templates");
migrationBuilder.AddColumn<int>(
name: "Index",
table: "Templates",
type: "integer",
nullable: true);
migrationBuilder.AddColumn<bool>(
name: "IsUnused",
table: "Templates",
type: "boolean",
nullable: false,
defaultValue: false);
migrationBuilder.CreateTable(
name: "UnitsInTemplates",
schema: "job",
columns: table => new
{
TemplateId = table.Column<Guid>(type: "uuid", nullable: false),
UnitId = table.Column<Guid>(type: "uuid", nullable: false),
DateCreated = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_UnitsInTemplates", x => new { x.TemplateId, x.UnitId });
table.ForeignKey(
name: "FK_UnitsInTemplates_Templates_TemplateId",
column: x => x.TemplateId,
principalTable: "Templates",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_UnitsInTemplates_Units_UnitId",
column: x => x.UnitId,
principalSchema: "unit",
principalTable: "Units",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
},
comment: "Таблица связи ЭК в шаблонах");
migrationBuilder.CreateIndex(
name: "IX_Templates_Name_Index",
table: "Templates",
columns: new[] { "Name", "Index" },
unique: true);
migrationBuilder.CreateIndex(
name: "IX_UnitsInTemplates_UnitId",
schema: "job",
table: "UnitsInTemplates",
column: "UnitId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "UnitsInTemplates",
schema: "job");
migrationBuilder.DropIndex(
name: "IX_Templates_Name_Index",
table: "Templates");
migrationBuilder.DropColumn(
name: "Index",
table: "Templates");
migrationBuilder.DropColumn(
name: "IsUnused",
table: "Templates");
migrationBuilder.CreateIndex(
name: "IX_Templates_Name",
table: "Templates",
column: "Name",
unique: true);
}
}
}

View File

@@ -1557,6 +1557,9 @@ namespace PARR.DAL.Migrations
b.Property<Guid>("GroupId")
.HasColumnType("uuid");
b.Property<bool?>("IsParentRelationships")
.HasColumnType("boolean");
b.Property<int?>("MaxValueRelationships")
.HasColumnType("integer");
@@ -1582,9 +1585,6 @@ namespace PARR.DAL.Migrations
.IsRequired()
.HasColumnType("text");
b.Property<bool?>("isParentRelationships")
.HasColumnType("boolean");
b.HasKey("Id");
b.HasIndex("GroupId");
@@ -1660,6 +1660,9 @@ namespace PARR.DAL.Migrations
.IsRequired()
.HasColumnType("text");
b.Property<Guid>("GroupTypeId")
.HasColumnType("uuid");
b.Property<bool>("IsAgent")
.HasColumnType("boolean");
@@ -1686,12 +1689,61 @@ namespace PARR.DAL.Migrations
b.HasKey("Id");
b.HasIndex("GroupTypeId");
b.ToTable("Groups", "job", t =>
{
t.HasComment("Таблица описания групп работ, для реализации зонтиков");
});
});
modelBuilder.Entity("PARR.DAL.Models.Job.JobGroupType", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Code")
.HasColumnType("integer");
b.Property<DateTimeOffset>("DateCreated")
.HasColumnType("timestamp with time zone");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("GroupTypes", "job", t =>
{
t.HasComment("Таблица типов групп работ");
});
b.HasData(
new
{
Id = new Guid("4fa62e79-86bb-47c2-be1a-72a716a170fa"),
Code = 0,
DateCreated = new DateTimeOffset(new DateTime(2023, 5, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0)),
Name = "Simple"
},
new
{
Id = new Guid("6ec58b1a-5c40-47b9-b036-4fa490e8d503"),
Code = 1,
DateCreated = new DateTimeOffset(new DateTime(2023, 5, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0)),
Name = "Umbrella"
},
new
{
Id = new Guid("318625e5-f833-436a-99df-2a382a1e71c7"),
Code = 2,
DateCreated = new DateTimeOffset(new DateTime(2023, 5, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0)),
Name = "Group"
});
});
modelBuilder.Entity("PARR.DAL.Models.Job.JobRelationshipFilter", b =>
{
b.Property<Guid>("UnitFilterId")
@@ -2619,6 +2671,9 @@ namespace PARR.DAL.Migrations
b.Property<DateTimeOffset?>("DateModified")
.HasColumnType("timestamp with time zone");
b.Property<int?>("Index")
.HasColumnType("integer");
b.Property<string>("InitiatorComment")
.HasColumnType("text");
@@ -2634,6 +2689,9 @@ namespace PARR.DAL.Migrations
b.Property<bool>("IsActiveTemplate")
.HasColumnType("boolean");
b.Property<bool>("IsUnused")
.HasColumnType("boolean");
b.Property<Guid>("JobId")
.HasColumnType("uuid");
@@ -2657,11 +2715,11 @@ namespace PARR.DAL.Migrations
b.HasIndex("JobId");
b.HasIndex("Name")
.IsUnique();
b.HasIndex("UnitId");
b.HasIndex("Name", "Index")
.IsUnique();
b.ToTable("Templates");
});
@@ -2925,6 +2983,27 @@ namespace PARR.DAL.Migrations
});
});
modelBuilder.Entity("PARR.DAL.Models.UnitsInTemplate", b =>
{
b.Property<Guid>("TemplateId")
.HasColumnType("uuid");
b.Property<Guid>("UnitId")
.HasColumnType("uuid");
b.Property<DateTimeOffset>("DateCreated")
.HasColumnType("timestamp with time zone");
b.HasKey("TemplateId", "UnitId");
b.HasIndex("UnitId");
b.ToTable("UnitsInTemplates", "job", t =>
{
t.HasComment("Таблица связи ЭК в шаблонах");
});
});
modelBuilder.Entity("PARR.DAL.Models.User", b =>
{
b.Property<Guid>("Id")
@@ -3280,6 +3359,17 @@ namespace PARR.DAL.Migrations
b.Navigation("UnitFilter");
});
modelBuilder.Entity("PARR.DAL.Models.Job.JobGroup", b =>
{
b.HasOne("PARR.DAL.Models.Job.JobGroupType", "GroupType")
.WithMany("JobGroups")
.HasForeignKey("GroupTypeId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("GroupType");
});
modelBuilder.Entity("PARR.DAL.Models.Job.JobRelationshipFilter", b =>
{
b.HasOne("PARR.DAL.Models.Unit.UnitField", "UnitField")
@@ -3572,6 +3662,25 @@ namespace PARR.DAL.Migrations
b.Navigation("Value");
});
modelBuilder.Entity("PARR.DAL.Models.UnitsInTemplate", b =>
{
b.HasOne("PARR.DAL.Models.Template", "Template")
.WithMany("UnitsInTemplate")
.HasForeignKey("TemplateId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("PARR.DAL.Models.Unit.Unit", "Unit")
.WithMany("TemplatesInUnit")
.HasForeignKey("UnitId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Template");
b.Navigation("Unit");
});
modelBuilder.Entity("PARR.DAL.Models.UsersInRole", b =>
{
b.HasOne("PARR.DAL.Models.Role", "Role")
@@ -3695,6 +3804,11 @@ namespace PARR.DAL.Migrations
b.Navigation("Jobs");
});
modelBuilder.Entity("PARR.DAL.Models.Job.JobGroupType", b =>
{
b.Navigation("JobGroups");
});
modelBuilder.Entity("PARR.DAL.Models.Job.JobUnitFilter", b =>
{
b.Navigation("FieldFilters");
@@ -3779,6 +3893,8 @@ namespace PARR.DAL.Migrations
b.Navigation("RobotConfigurations");
b.Navigation("TemplateHistories");
b.Navigation("UnitsInTemplate");
});
modelBuilder.Entity("PARR.DAL.Models.Tnk", b =>
@@ -3794,6 +3910,8 @@ namespace PARR.DAL.Migrations
b.Navigation("Templates");
b.Navigation("TemplatesInUnit");
b.Navigation("UnitFields");
b.Navigation("UnitValues");

View File

@@ -44,7 +44,7 @@ namespace PARR.DAL.Models.Job
/// true - диапазон связей относится к родительским связям<br/>
/// false, null - диапазон относится к дочерним связям
/// </value>
public bool? isParentRelationships { get; set; }
public bool? IsParentRelationships { get; set; }
/// <summary>
/// Маска для динамического формирования имени шаблона

View File

@@ -27,7 +27,7 @@ namespace PARR.DAL.Models.Job
/// Связана ли работа с групповыми ЭК(зонтами)
/// </summary>
public bool? IsUmbrella { get; set; }
/// <summary>
/// Поле Короткое описания шаблона АСУ ЕСПП
/// </summary>
@@ -114,6 +114,11 @@ namespace PARR.DAL.Models.Job
/// </summary>
public string? AgentScript { get; set; }
public Guid GroupTypeId { get; set; }
[ForeignKey(nameof(GroupTypeId))]
public JobGroupType? GroupType { get; set; }
public ICollection<Job> Jobs { get; set; } = new HashSet<Job>();
public ICollection<EsppSchValue> EsppSchValues { get; set; } = new HashSet<EsppSchValue>();

View File

@@ -0,0 +1,28 @@
using Microsoft.EntityFrameworkCore;
using PARR.DAL.Context;
using PARR.DAL.Contracts;
using PARR.DAL.Models.Base;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace PARR.DAL.Models.Job
{
[Table("GroupTypes", Schema = DataContextSettings.Job)]
[Comment("Таблица типов групп работ")]
public class JobGroupType : IBase
{
[Key]
public Guid Id { get; set; }
public DateTimeOffset DateCreated { get; set; }
[NotMapped]
public DateTimeOffset? DateModified { get; set; }
public required JobGroupTypesEnum Code { get; set; }
public required string Name { get; set; }
public ICollection<JobGroup> JobGroups { get; set; } = new HashSet<JobGroup>();
}
}

View File

@@ -46,9 +46,5 @@ namespace PARR.DAL.Models.Job
[ForeignKey(nameof(FieldId))]
public UnitField? UnitField { get; set; }
}
}

View File

@@ -11,7 +11,7 @@ using System.ComponentModel.DataAnnotations.Schema;
namespace PARR.DAL.Models
{
[Table("Templates")]
[Index(nameof(Name), IsUnique = true)]
[Index(nameof(Name), nameof(Index), IsUnique = true)]
public class Template : IBase, ITemplateGeneralProps, IHistoryInitiator, IMyHistory<TemplateHistory>
{
[Key]
@@ -23,10 +23,20 @@ namespace PARR.DAL.Models
public required string Name { get; set; }
/// <summary>
/// Индекс, используется в групповых шаблонах
/// </summary>
public int? Index { get; set; }
public bool IsActiveTemplate { get; set; }
public bool IsActiveSchedule { get; set; }
/// <summary>
/// Шаблон не используется : перестал подходить условиям Job'а
/// </summary>
public bool IsUnused { get; set; } = false;
/// <summary>
/// Номер расписания еспп
/// </summary>
@@ -76,7 +86,7 @@ namespace PARR.DAL.Models
[ForeignKey(nameof(UnitId))]
public Unit.Unit? Unit { get; set; }
public ICollection<RobotConfiguration> RobotConfigurations { get; set; } = new HashSet<RobotConfiguration>();
public ICollection<AgentHistory> AgentHistories { get; set; } = new HashSet<AgentHistory>();
@@ -84,5 +94,7 @@ namespace PARR.DAL.Models
public ICollection<Order> Orders { get; set; } = new HashSet<Order>();
public ICollection<TemplateHistory> TemplateHistories { get; set; } = new HashSet<TemplateHistory>();
public ICollection<UnitsInTemplate> UnitsInTemplate { get; set; } = new HashSet<UnitsInTemplate>();
}
}

View File

@@ -67,7 +67,16 @@ namespace PARR.DAL.Models.Unit
[InverseProperty(nameof(UnitInUnit.ParentUnit))]
public ICollection<UnitInUnit> ChildUnits { get; set; } = new HashSet<UnitInUnit>();
/// <summary>
/// Связь с шаблонами. Один ко многим
/// </summary>
public ICollection<Template> Templates { get; set; } = new HashSet<Template>();
/// <summary>
/// К одному шаблону привязано несколько ЭК(Груповой тип работы). Многие ко многим
/// </summary>
public ICollection<UnitsInTemplate> TemplatesInUnit { get; set; } = new HashSet<UnitsInTemplate>();
}

View File

@@ -0,0 +1,25 @@
using Microsoft.EntityFrameworkCore;
using PARR.DAL.Context;
using System.ComponentModel.DataAnnotations.Schema;
using System.Xml.Linq;
namespace PARR.DAL.Models
{
[Table("UnitsInTemplates", Schema = DataContextSettings.Job)]
[Comment("Таблица связи ЭК в шаблонах")]
public class UnitsInTemplate
{
public Guid TemplateId { get; set; }
public Guid UnitId { get; set; }
public DateTimeOffset DateCreated { get; set; }
[ForeignKey(nameof(TemplateId))]
public Template? Template { get; set; }
[ForeignKey(nameof(UnitId))]
public Unit.Unit? Unit { get; set; }
}
}

View File

@@ -107,6 +107,7 @@ namespace PARR.DAL
services.AddTransient<IJobService, JobService>();
services.AddTransient<IJobGroupService, JobGroupService>();
services.AddTransient<IJobGroupTypeService, JobGroupTypeService>();
services.AddTransient<IJobUnitFilterService, JobUnitFilterService>();
services.AddTransient<IFieldFilterService, FieldFilterService>();
services.AddTransient<IJobUnitFilterService, JobUnitFilterService>();

View File

@@ -0,0 +1,27 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using PARR.DAL.Context;
using PARR.DAL.Models.Job;
using PARR.DAL.Services.Abstracts;
using PARR.DAL.Services.Interfaces.Job;
namespace PARR.DAL.Services.Implementations.Job
{
internal class JobGroupTypeService : BaseService<JobGroupType>, IJobGroupTypeService
{
private readonly DataContext dataContext;
private readonly ILogger<JobGroupTypeService> logger;
protected override DbSet<JobGroupType> EntitySet => dataContext.JobGroupTypes;
protected override DataContext EntitiContext => dataContext;
public JobGroupTypeService(
DataContext dataContext,
ILogger<JobGroupTypeService> logger
) : base(logger)
{
this.dataContext = dataContext;
this.logger = logger;
}
}
}

View File

@@ -0,0 +1,9 @@
using PARR.DAL.Models.Job;
using PARR.DAL.Services.Interfaces.Base;
namespace PARR.DAL.Services.Interfaces.Job
{
public interface IJobGroupTypeService : IBaseService<JobGroupType>
{
}
}