feat(dal): Добавлена таблица WorkGroups и AppInWorkGroups

This commit is contained in:
Mikhail Kuznetsov
2024-06-03 15:17:14 +10:00
parent faab4a6664
commit 90948108c1
11 changed files with 2985 additions and 0 deletions

View File

@@ -10,6 +10,8 @@ namespace PARR.DAL.Context
public DataContext(DbContextOptions<DataContext> options) : base(options) { }
public DbSet<Host> Hosts { get; set; }
public DbSet<WorkGroup> WorkGroups { get; set; }
public DbSet<AppInWorkInWorkGroup> AppInWorkInWorkGroups { get; set; }
public DbSet<EkStatus> EkStatuses { get; set; }
public DbSet<ResponseArea> ResponseAreas { get; set; }
public DbSet<Application> Applications { get; set; }

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,97 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace PARR.DAL.Migrations
{
/// <inheritdoc />
public partial class TblAddWorkGroup : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<Guid>(
name: "WorkGroupId",
table: "Hosts",
type: "uuid",
nullable: true);
migrationBuilder.CreateTable(
name: "WorkGroups",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
DateCreated = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
Name = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_WorkGroups", x => x.Id);
});
migrationBuilder.CreateTable(
name: "AppInWorkInWorkGroups",
columns: table => new
{
ApplicationsInWorkId = table.Column<Guid>(type: "uuid", nullable: false),
WorkGroupId = table.Column<Guid>(type: "uuid", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_AppInWorkInWorkGroups", x => new { x.ApplicationsInWorkId, x.WorkGroupId });
table.ForeignKey(
name: "FK_AppInWorkInWorkGroups_ApplicationsInWorks_ApplicationsInWor~",
column: x => x.ApplicationsInWorkId,
principalTable: "ApplicationsInWorks",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_AppInWorkInWorkGroups_WorkGroups_WorkGroupId",
column: x => x.WorkGroupId,
principalTable: "WorkGroups",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_Hosts_WorkGroupId",
table: "Hosts",
column: "WorkGroupId");
migrationBuilder.CreateIndex(
name: "IX_AppInWorkInWorkGroups_WorkGroupId",
table: "AppInWorkInWorkGroups",
column: "WorkGroupId");
migrationBuilder.AddForeignKey(
name: "FK_Hosts_WorkGroups_WorkGroupId",
table: "Hosts",
column: "WorkGroupId",
principalTable: "WorkGroups",
principalColumn: "Id");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Hosts_WorkGroups_WorkGroupId",
table: "Hosts");
migrationBuilder.DropTable(
name: "AppInWorkInWorkGroups");
migrationBuilder.DropTable(
name: "WorkGroups");
migrationBuilder.DropIndex(
name: "IX_Hosts_WorkGroupId",
table: "Hosts");
migrationBuilder.DropColumn(
name: "WorkGroupId",
table: "Hosts");
}
}
}

View File

@@ -89,6 +89,21 @@ namespace PARR.DAL.Migrations
});
});
modelBuilder.Entity("PARR.DAL.Models.AppInWorkInWorkGroup", b =>
{
b.Property<Guid>("ApplicationsInWorkId")
.HasColumnType("uuid");
b.Property<Guid>("WorkGroupId")
.HasColumnType("uuid");
b.HasKey("ApplicationsInWorkId", "WorkGroupId");
b.HasIndex("WorkGroupId");
b.ToTable("AppInWorkInWorkGroups");
});
modelBuilder.Entity("PARR.DAL.Models.Application", b =>
{
b.Property<Guid>("Id")
@@ -1402,12 +1417,17 @@ namespace PARR.DAL.Migrations
b.Property<string>("WorkGroup")
.HasColumnType("text");
b.Property<Guid?>("WorkGroupId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("EkStatusCode");
b.HasIndex("ResponseAreaCode");
b.HasIndex("WorkGroupId");
b.HasIndex("Ek", "IP");
b.ToTable("Hosts");
@@ -2201,6 +2221,24 @@ namespace PARR.DAL.Migrations
b.ToTable("Works");
});
modelBuilder.Entity("PARR.DAL.Models.WorkGroup", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTimeOffset>("DateCreated")
.HasColumnType("timestamp with time zone");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("WorkGroups");
});
modelBuilder.Entity("PARR.DAL.Models.AgentHistory", b =>
{
b.HasOne("PARR.DAL.Models.AgentHistoryLevel", "AgentHistoryLevel")
@@ -2226,6 +2264,25 @@ namespace PARR.DAL.Migrations
b.Navigation("Template");
});
modelBuilder.Entity("PARR.DAL.Models.AppInWorkInWorkGroup", b =>
{
b.HasOne("PARR.DAL.Models.ApplicationsInWork", "ApplicationsInWork")
.WithMany("WorkGroups")
.HasForeignKey("ApplicationsInWorkId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("PARR.DAL.Models.WorkGroup", "WorkGroup")
.WithMany("AppInWorks")
.HasForeignKey("WorkGroupId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("ApplicationsInWork");
b.Navigation("WorkGroup");
});
modelBuilder.Entity("PARR.DAL.Models.Application", b =>
{
b.HasOne("PARR.DAL.Models.ApplicationType", "ApplicationType")
@@ -2346,9 +2403,15 @@ namespace PARR.DAL.Migrations
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("PARR.DAL.Models.WorkGroup", "WorkGroupItem")
.WithMany("Hosts")
.HasForeignKey("WorkGroupId");
b.Navigation("EkStatus");
b.Navigation("ResponseArea");
b.Navigation("WorkGroupItem");
});
modelBuilder.Entity("PARR.DAL.Models.Order", b =>
@@ -2529,6 +2592,8 @@ namespace PARR.DAL.Migrations
b.Navigation("EsppSchValues");
b.Navigation("Templates");
b.Navigation("WorkGroups");
});
modelBuilder.Entity("PARR.DAL.Models.EkStatus", b =>
@@ -2647,6 +2712,13 @@ namespace PARR.DAL.Migrations
{
b.Navigation("ApplicationsInWorks");
});
modelBuilder.Entity("PARR.DAL.Models.WorkGroup", b =>
{
b.Navigation("AppInWorks");
b.Navigation("Hosts");
});
#pragma warning restore 612, 618
}
}

View File

@@ -0,0 +1,17 @@
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations.Schema;
namespace PARR.DAL.Models
{
[Table("AppInWorkInWorkGroups")]
[PrimaryKey(nameof(ApplicationsInWorkId), nameof(WorkGroupId))]
public class AppInWorkInWorkGroup
{
public Guid ApplicationsInWorkId { get; set; }
public Guid WorkGroupId { get; set; }
public ApplicationsInWork? ApplicationsInWork { get; set; }
public WorkGroup? WorkGroup { get; set; }
}
}

View File

@@ -108,5 +108,7 @@ namespace PARR.DAL.Models
public ICollection<Template> Templates { get; set; } = new HashSet<Template>();
public ICollection<EsppSchValue> EsppSchValues { get; set; } = new HashSet<EsppSchValue>();
public ICollection<AppInWorkInWorkGroup> WorkGroups { get; set; } = new HashSet<AppInWorkInWorkGroup>();
}
}

View File

@@ -30,6 +30,8 @@ namespace PARR.DAL.Models
public string? WorkGroup { get; set; }
public Guid? WorkGroupId { get; set; }
//TODO: удалить поле ResponseAreaStr
//public string? ResponseAreaStr { get; set; }
@@ -48,5 +50,8 @@ namespace PARR.DAL.Models
[ForeignKey(nameof(ResponseAreaCode))]
public ResponseArea? ResponseArea { get; set; }
[ForeignKey(nameof(WorkGroupId))]
public WorkGroup? WorkGroupItem { get; set; }
}
}

View File

@@ -0,0 +1,23 @@
using PARR.DAL.Models.Base;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace PARR.DAL.Models
{
[Table("WorkGroups")]
public class WorkGroup : IBase
{
[Key]
public Guid Id { get; set; }
public DateTimeOffset DateCreated { get; set; }
[NotMapped]
public DateTimeOffset? DateModified { get; set; }
public required string Name { get; set; }
public ICollection<Host> Hosts { get; set; } = new HashSet<Host>();
public ICollection<AppInWorkInWorkGroup> AppInWorks { get; set; } = new HashSet<AppInWorkInWorkGroup>();
}
}

View File

@@ -54,6 +54,7 @@ namespace PARR.DAL
// Entity services
services.AddTransient<IHostService, HostService>();
services.AddTransient<IWorkGroupService, WorkGroupService>();
services.AddTransient<IApplicationService, ApplicationService>();
services.AddTransient<IApplicationTypeService, ApplicationTypeService>();
services.AddTransient<IApplicationInHostService, ApplicationInHostService>();

View File

@@ -0,0 +1,28 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using PARR.DAL.Context;
using PARR.DAL.Models;
using PARR.DAL.Services.Abstracts;
using PARR.DAL.Services.Interfaces;
namespace PARR.DAL.Services.Implementations
{
internal class WorkGroupService : BaseService<WorkGroup>, IWorkGroupService
{
private readonly DataContext dataContext;
private readonly ILogger<WorkGroupService> logger;
protected override DbSet<WorkGroup> EntitySet => dataContext.WorkGroups;
protected override DataContext EntitiContext => dataContext;
public WorkGroupService(DataContext dataContext, ILogger<WorkGroupService> logger) : base(logger)
{
this.dataContext = dataContext;
this.logger = logger;
}
public async Task<WorkGroup?> GetByNameAsync(string name)
{
return await Get().FirstOrDefaultAsync(t => t.Name == name);
}
}
}

View File

@@ -0,0 +1,10 @@
using PARR.DAL.Models;
using PARR.DAL.Services.Interfaces.Base;
namespace PARR.DAL.Services.Interfaces
{
public interface IWorkGroupService : IBaseService<WorkGroup>
{
Task<WorkGroup?> GetByNameAsync(string name);
}
}