This commit is contained in:
Mikhail Kuznetsov
2023-06-16 15:00:11 +10:00
parent 73a824057b
commit 57fe9eff09
37 changed files with 1151 additions and 504 deletions

View File

@@ -27,6 +27,20 @@
public const string Metrics = Base + "/metrics";
}
public static class Scheduler
{
public const string GetAll = Base + "/schedulers/";
public const string GetByIp = Base + "/schedulers/ip/";
//public const string Get = Base + "/schedulers/" + getParam;
//public const string GetAreas = Base + "/schedulers/" + getParam + "/areas";
//public const string GetPlaces = Base + "/schedulers/" + getParam + "/places";
//public const string GetTemplates = Base + "/schedulers/" + getParam + "/templates";
public const string getParam = "{id}";
}
//public static class Layer
//{
// public const string GetAll = Base + "/layers/";
@@ -37,6 +51,7 @@
// public const string GetTemplates = Base + "/layers/" + getParam + "/templates";
// public const string getParam = "{id}";
//}
//
}
}
}

View File

@@ -0,0 +1,57 @@
namespace PARR.API.Contracts.V1.Requests.Queries
{
public class PaginationQuery
{
private int pageSizeMax = 100;
private int pageSizeDefault = 10;
private int pageNumberMin = 1;
public PaginationQuery()
{
PageNumber = pageNumberMin;
PageSize = pageSizeDefault;
}
public PaginationQuery(int pageNumber, int pageSize)
{
PageNumber = pageNumber;
PageSize = pageSize;
}
private int _pageNumber;
public int PageNumber
{
get
{
return _pageNumber;
}
set
{
if (value < pageNumberMin)
_pageNumber = pageNumberMin;
else
_pageNumber = value;
}
}
private int _pageSize;
public int PageSize
{
get
{
return _pageSize;
}
set
{
if (value > pageSizeMax)
_pageSize = pageSizeMax;
else
_pageSize = value;
if (_pageSize < 1)
_pageSize = pageSizeDefault;
}
}
}
}

View File

@@ -0,0 +1,15 @@
namespace PARR.API.Contracts.V1.Requests.Queries
{
public class SchedulerGetAllQuery
{
/// <summary>
/// true - вкл задания, false - выкл задания, null - все задания
/// </summary>
public bool? IsEnabled { get; set; }
/// <summary>
/// Список запланированных заданий на указанную дату
/// </summary>
public DateTimeOffset? StartDatePlanned { get; set; }
}
}

View File

@@ -0,0 +1,7 @@
namespace PARR.API.Contracts.V1.Requests.Queries
{
public class SchedulerGetByIpQuery
{
public string? Ip { get; set; }
}
}

View File

@@ -0,0 +1,6 @@
namespace PARR.API.Contracts.V1.Responses
{
public class ApiHealthResponse
{
}
}

View File

@@ -0,0 +1,9 @@
namespace PARR.API.Contracts.V1.Responses
{
public class ApiVersionResponse
{
public string? Version { get; set; }
public string? Environment { get; set; }
}
}

View File

@@ -0,0 +1,29 @@
namespace PARR.API.Contracts.V1.Responses.Base
{
public class BaseResponse
{
public BaseResponse() { }
public BaseResponse(bool isSuccess)
{
IsSuccess = isSuccess;
}
public BaseResponse(bool isSuccess, List<ErrorModel> errors)
{
IsSuccess = isSuccess;
Errors = errors;
}
public BaseResponse(bool isSuccess, List<ErrorModel> errors, string message)
{
IsSuccess = isSuccess;
Errors = errors;
Message = message;
}
public List<ErrorModel> Errors { get; set; } = new List<ErrorModel>();
public bool IsSuccess { get; private set; }
public string? Message { get; private set; }
}
}

View File

@@ -0,0 +1,9 @@
namespace PARR.API.Contracts.V1.Responses.Base
{
public class ErrorModel
{
public string? FieldName { get; set; }
public string? Message { get; set; }
}
}

View File

@@ -0,0 +1,29 @@
namespace PARR.API.Contracts.V1.Responses.Base
{
public class PagedResponse<T> : BaseResponse
{
public PagedResponse(bool isSuccess) : base(isSuccess) { }
public PagedResponse(bool isSuccess, List<ErrorModel> errors) : base(isSuccess, errors) { }
public PagedResponse(bool isSuccess, List<ErrorModel> errors, string message) : base(isSuccess, errors, message) { }
public PagedResponse(IEnumerable<T> data, bool isSuccess) : base(isSuccess) { Data = data; }
public PagedResponse(IEnumerable<T> data, bool isSuccess, List<ErrorModel> errors) : base(isSuccess, errors) { Data = data; }
public PagedResponse(IEnumerable<T> data, bool isSuccess, List<ErrorModel> errors, string message) : base(isSuccess, errors, message) { Data = data; }
public IEnumerable<T>? Data { get; set; }
public int? PageNumber { get; set; }
public int? PageSize { get; set; }
public int? TotalPage { get; set; }
public int? TotalItems { get; set; }
}
}

View File

@@ -0,0 +1,57 @@
using FluentValidation.Results;
namespace PARR.API.Contracts.V1.Responses.Base
{
public class Response<T> : BaseResponse
{
public Response(T response, bool isSuccess) : base(isSuccess)
{
Data = response;
}
public Response(T response, bool isSuccess, List<ErrorModel> errors) : base(isSuccess, errors)
{
Data = response;
}
public Response(T response, bool isSuccess, List<ErrorModel> errors, string message) : base(isSuccess, errors, message)
{
Data = response;
}
public T? Data { get; private set; }
}
public class Response : Response<object?>
{
/// <summary>
/// Респонс для валидации от FluentValidator
/// </summary>
/// <param name="validationErrors">ResultValidate.Errors</param>
public Response(List<ValidationFailure> validationErrors) : base(null, false)
{
var errors = new List<ErrorModel>();
foreach (var error in validationErrors)
{
errors.Add(new ErrorModel
{
FieldName = error.PropertyName,
Message = error.ErrorMessage
});
}
Errors = errors;
}
/// <summary>
/// Респонс когда не нужно передавать объект
/// </summary>
/// <param name="isSuccess"></param>
/// <param name="errors"></param>
public Response(bool isSuccess, List<ErrorModel> errors) : base(null, isSuccess, errors)
{
}
}
}

View File

@@ -0,0 +1,21 @@
namespace PARR.API.Contracts.V1.Responses
{
public class SchedulerBaseResponse
{
public required string Name { get; set; }
public DateTimeOffset StartAt { get; set; }
public int FrequencyMinute { get; set; }
}
public class SchedulerGetAllResponse: SchedulerBaseResponse
{
public Guid Id { get; set; }
public bool IsEnabled { get; set; }
}
public class SchedulerResponse
{
}
}

View File

@@ -1,9 +1,49 @@
using PARR.API.Controllers.V1.Base;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using PARR.API.Contracts.V1;
using PARR.API.Contracts.V1.Responses;
using PARR.API.Contracts.V1.Responses.Base;
using PARR.API.Controllers.V1.Base;
using System.Reflection;
namespace PARR.API.Controllers.V1
{
public class ApiStatusController : BaseApiController
{
//TODO:
/// <summary>
/// Получить версию и окружение
/// </summary>
/// <returns></returns>
[AllowAnonymous]
[HttpGet(ApiRoutes.ApiStatus.Version)]
public IActionResult GetVersion()
{
var version = Assembly.GetEntryAssembly()?.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion;
var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
var response = new ApiVersionResponse
{
Environment = environment,
Version = version
};
return Ok(new Response<ApiVersionResponse>(response, true));
}
/// <summary>
/// Проверка доступности системы
/// </summary>
/// <returns></returns>
[AllowAnonymous]
[HttpGet(ApiRoutes.ApiStatus.Health)]
public IActionResult GetHealth()
{
//Так же можно реализовать проверку связи с БД
//Проверка доступности хранилищ
var response = new ApiHealthResponse { };
return Ok(new Response<ApiHealthResponse>(response, true));
}
}
}

View File

@@ -1,26 +0,0 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using PARR.DAL.Services.Interfaces;
namespace PARR.API.Controllers.V1
{
public class HomeController : Controller
{
private readonly IHostService hostService;
public HomeController(IHostService hostService)
{
this.hostService = hostService;
}
[HttpGet("test")]
public async Task<IActionResult> Index()
{
var hosts = await hostService.Get().ToListAsync();
//foreach (var host in hosts) { logger.LogInformation($"{host.HostName}"); }
//return View();
return Ok(hosts.Select(t => new { t.HostName, t.IP, t.Id }));
}
}
}

View File

@@ -0,0 +1,78 @@
using Microsoft.AspNetCore.Mvc;
using PARR.API.Contracts.V1.Requests.Queries;
using PARR.API.Contracts.V1;
using PARR.API.Controllers.V1.Base;
using AutoMapper;
using PARR.DAL.DomainModels;
using PARR.DAL.Models;
using PARR.DAL.Services.Interfaces;
using Microsoft.EntityFrameworkCore;
using PARR.API.Contracts.V1.Responses;
using PARR.API.Contracts.V1.Responses.Base;
using PARR.API.Extensions;
using System.Runtime.CompilerServices;
using PARR.API.Services.Interfaces;
namespace PARR.API.Controllers.V1
{
public class ShchedullerController : BaseApiController
{
private readonly IMapper mapper;
private readonly ISchedulerService schedulerService;
private readonly IClientService clientService;
public ShchedullerController(
IMapper mapper,
ISchedulerService schedulerService,
IClientService clientService
)
{
this.mapper = mapper;
this.schedulerService = schedulerService;
this.clientService = clientService;
}
/// <summary>
/// Список всех планировщиков постранично в соотвествии с фильтрами
/// </summary>
/// <param name="paginationQuery"></param>
/// <returns></returns>
[HttpGet(ApiRoutes.Scheduler.GetAll)]
public async Task<IActionResult> GetAll([FromQuery] PaginationQuery paginationQuery, [FromQuery] SchedulerGetAllQuery filter)
{
var paginationFilter = mapper.Map<PaginationFilter>(paginationQuery);
IQueryable<Scheduler> query = schedulerService.Get().OrderBy(s => s.StartAt);
if (filter.IsEnabled.HasValue)
query = query.Where(t => t.IsEnabled == filter.IsEnabled);
if (filter.StartDatePlanned.HasValue)
query = query.Where(t => t.StartAt.DateTime.Date <= filter.StartDatePlanned.Value.DateTime.Date); ;
var schedulers = await schedulerService.GetPage(query, paginationFilter).ToListAsync();
if (!schedulers.Any())
return NoContent();
var schedulerResponse = mapper.Map<List<SchedulerGetAllResponse>>(schedulers);
var paginationResponse = new PagedResponse<SchedulerGetAllResponse>(schedulerResponse, true).GetPaginatedProps(paginationFilter, query);
return Ok(paginationResponse);
}
[HttpGet(ApiRoutes.Scheduler.GetByIp)]
public async Task<IActionResult> GetByClientIP([FromQuery] SchedulerGetByIpQuery requestQuery)
{
var ip = requestQuery.Ip ?? clientService.GetClientIp()?.ToString();
if (string.IsNullOrEmpty(ip))
return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { Message = "Client IP address is null." } }));
// TODO;
return Ok();
}
}
}

View File

@@ -0,0 +1,59 @@
using PARR.API.Contracts.V1.Responses.Base;
using PARR.DAL.DomainModels;
namespace PARR.API.Extensions
{
public static class PaginationExtensions
{
/// <summary>
/// Заполняет TotalItems, PageNumber, PageSize, TotalPage
/// </summary>
/// <typeparam name="TypeResponse"></typeparam>
/// <typeparam name="Query"></typeparam>
/// <param name="pagedResponse"></param>
/// <param name="paginationFilter"></param>
/// <param name="quaryAllItemsApplyFilters"></param>
/// <returns></returns>
public static PagedResponse<TypeResponse> GetPaginatedProps<TypeResponse, Query>(
this PagedResponse<TypeResponse> pagedResponse,
PaginationFilter paginationFilter,
IQueryable<Query> quaryAllItemsApplyFilters
)
{
// TODO: CountAsync - подумать и затолкать в Task
int totalItems = quaryAllItemsApplyFilters.Count();//.CountAsync().GetAwaiter().GetResult();
return CreatePaginatedResponse(totalItems, paginationFilter, pagedResponse);
}
/// <summary>
/// Заполняет TotalItems, PageNumber, PageSize, TotalPage
/// </summary>
/// <typeparam name="TypeResponse"></typeparam>
/// <param name="pagedResponse"></param>
/// <param name="paginationFilter"></param>
/// <param name="totalItems"></param>
/// <returns></returns>
public static PagedResponse<TypeResponse> GetPaginatedProps<TypeResponse>(
this PagedResponse<TypeResponse> pagedResponse,
PaginationFilter paginationFilter,
int totalItems
)
{
return CreatePaginatedResponse(totalItems, paginationFilter, pagedResponse);
}
private static PagedResponse<T> CreatePaginatedResponse<T>(int totalItems, PaginationFilter paginationFilter, PagedResponse<T> pagedResponse)
{
pagedResponse.TotalItems = totalItems;
pagedResponse.PageNumber = paginationFilter.PageNumber >= 1 ? paginationFilter.PageNumber : (int?)null;
pagedResponse.PageSize = paginationFilter.PageSize >= 1 ? paginationFilter.PageSize : (int?)null;
pagedResponse.TotalPage =
(pagedResponse.TotalItems.HasValue && pagedResponse.PageSize.HasValue)
? (int)Math.Ceiling(pagedResponse.TotalItems.Value / (double)pagedResponse.PageSize.Value)
: (int?)null;
return pagedResponse;
}
}
}

View File

@@ -19,7 +19,7 @@ namespace PARR.API.Installers
return new UriService(absoluteUri);
});
services.AddTransient<IClientService, ClientService>();
//services.AddTransient<IFileService, FileService>();

View File

@@ -19,9 +19,9 @@ namespace PARR.API.Installers
"v1",
new OpenApiInfo
{
Title = "GEO API",
Title = "PARR API",
Version = $"v{version}",
Description = "API for the project \"GEO DVGD\"",
Description = "API for the project \"PARR DVGD\"",
Contact = new OpenApiContact { Email = "IVC_TrubnikovME@dvgd.rzd;IVC_KuznetsovMV@dvgd.rzd", Name = "Trubnikov M.E., Kuznetsov M.V." },
License = new OpenApiLicense { Name = "© PTK-DVGD Software LLC" }
});

View File

@@ -1,4 +1,6 @@
using AutoMapper;
using PARR.API.Contracts.V1.Responses;
using PARR.DAL.Models;
namespace PARR.API.MappingProfiles
{
@@ -6,7 +8,11 @@ namespace PARR.API.MappingProfiles
{
public DomainToResponseProfile()
{
// из проекта наружу
// --- Scheduler ---
CreateMap<Scheduler, SchedulerBaseResponse>()
.Include<Scheduler, SchedulerGetAllResponse>()
.ForMember(d => d.FrequencyMinute, o => o.MapFrom(s => s.Frequency));
CreateMap<Scheduler, SchedulerGetAllResponse>();
}
}
}

View File

@@ -1,4 +1,6 @@
using AutoMapper;
using PARR.API.Contracts.V1.Requests.Queries;
using PARR.DAL.DomainModels;
namespace PARR.API.MappingProfiles
{
@@ -6,7 +8,7 @@ namespace PARR.API.MappingProfiles
{
public RequestToDomainProfile()
{
// снаружи в проект
CreateMap<PaginationQuery, PaginationFilter>();
}
}
}

View File

@@ -34,8 +34,6 @@
</ItemGroup>
<ItemGroup>
<Folder Include="Contracts\V1\Requests\Queries\" />
<Folder Include="Contracts\V1\Responses\" />
<Folder Include="MappingProfiles\Resolvers\" />
<Folder Include="Validators\" />
</ItemGroup>

View File

@@ -0,0 +1,19 @@
using PARR.API.Services.Interfaces;
using System.Net;
namespace PARR.API.Services.Implementations
{
public class ClientService : IClientService
{
private readonly IHttpContextAccessor httpContextAccessor;
public ClientService(IHttpContextAccessor httpContextAccessor)
{
this.httpContextAccessor = httpContextAccessor;
}
public IPAddress? GetClientIp()
{
return httpContextAccessor.HttpContext?.Connection.RemoteIpAddress;
}
}
}

View File

@@ -0,0 +1,9 @@
using System.Net;
namespace PARR.API.Services.Interfaces
{
public interface IClientService
{
IPAddress? GetClientIp();
}
}

View File

@@ -1,4 +1,5 @@
using Microsoft.EntityFrameworkCore;
using PARR.DAL.Contracts;
using PARR.DAL.Models;
namespace PARR.DAL.Context
@@ -19,5 +20,35 @@ namespace PARR.DAL.Context
public DbSet<ApplicationInHost> ApplicationsInHosts { get; set; }
public DbSet<Scheduler> Schedulers { get; set; }
//todo init application type+check migrations
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
var dateCreated = new DateTimeOffset(2023, 05, 01, 0, 0, 0, new TimeSpan(0));
modelBuilder.Entity<JobMode>(f =>
{
f.HasData(
new() { Id = new Guid("FBA4202C-5BAD-49C4-B076-D1CA6E1FB158"), DateCreated = dateCreated, DateModified = null, Name = "auto" },
new() { Id = new Guid("7516B952-510D-4AAA-971C-A14B184FC1D5"), DateCreated = dateCreated, DateModified = null, Name = "manual" }
);
});
modelBuilder.Entity<ApplicationType>(f =>
{
f.HasData(
new() { Id = new Guid("32c28386-6f13-4f7b-8508-be165b7fabdb"), DateCreated = dateCreated, DateModified = null, Name = ApplicationTypesEnum.APP.ToString(), Description = "Поле СП xml АИХ ИТ" },
new() { Id = new Guid("7848a96c-cdee-48c1-a786-de9cb889723a"), DateCreated = dateCreated, DateModified = null, Name = ApplicationTypesEnum.OS.ToString(), Description = "Поле ОС xml АИХ ИТ" },
new() { Id = new Guid("aae2636f-b93a-42dc-873e-0764a90a0a40"), DateCreated = dateCreated, DateModified = null, Name = ApplicationTypesEnum.DB.ToString(), Description = "Поле СУБД xml АИХ ИТ" }
);
});
}
}
}

View File

@@ -0,0 +1,8 @@
namespace PARR.DAL.DomainModels
{
public class PaginationFilter
{
public int PageNumber { get; set; }
public int PageSize { get; set; }
}
}

View File

@@ -1,315 +0,0 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
using PARR.DAL.Context;
#nullable disable
namespace PARR.DAL.Migrations
{
[DbContext(typeof(DataContext))]
[Migration("20230519051342_AllTbls")]
partial class AllTbls
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.5")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("PARR.DAL.Models.Host", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTimeOffset>("DateCreated")
.HasColumnType("timestamp with time zone");
b.Property<DateTimeOffset?>("DateModified")
.HasColumnType("timestamp with time zone");
b.Property<string>("EK")
.HasColumnType("text");
b.Property<string>("HostName")
.IsRequired()
.HasColumnType("text");
b.Property<string>("IP")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Hosts");
});
modelBuilder.Entity("PARR.DAL.Models.Job", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTimeOffset>("DateCreated")
.HasColumnType("timestamp with time zone");
b.Property<DateTimeOffset?>("DateModified")
.HasColumnType("timestamp with time zone");
b.Property<Guid>("JobCategoryId")
.HasColumnType("uuid");
b.Property<Guid>("JobModeId")
.HasColumnType("uuid");
b.Property<Guid>("JobTypeId")
.HasColumnType("uuid");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("JobCategoryId");
b.HasIndex("JobModeId");
b.HasIndex("JobTypeId");
b.ToTable("Jobs");
});
modelBuilder.Entity("PARR.DAL.Models.JobCategory", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTimeOffset>("DateCreated")
.HasColumnType("timestamp with time zone");
b.Property<DateTimeOffset?>("DateModified")
.HasColumnType("timestamp with time zone");
b.Property<string>("Description")
.HasColumnType("text");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("JobCategories");
});
modelBuilder.Entity("PARR.DAL.Models.JobJournal", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTimeOffset>("DateCreated")
.HasColumnType("timestamp with time zone");
b.Property<DateTimeOffset?>("DateModified")
.HasColumnType("timestamp with time zone");
b.Property<string>("DateOper")
.HasColumnType("text");
b.Property<Guid>("HostId")
.HasColumnType("uuid");
b.Property<string>("Info")
.HasColumnType("text");
b.Property<Guid>("JobId")
.HasColumnType("uuid");
b.Property<Guid>("JobStatusId")
.HasColumnType("uuid");
b.Property<string>("Other")
.HasColumnType("text");
b.Property<int?>("TimeOut")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("HostId");
b.HasIndex("JobId");
b.HasIndex("JobStatusId");
b.ToTable("JobJournals");
});
modelBuilder.Entity("PARR.DAL.Models.JobModeService", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTimeOffset>("DateCreated")
.HasColumnType("timestamp with time zone");
b.Property<DateTimeOffset?>("DateModified")
.HasColumnType("timestamp with time zone");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("JobModes");
});
modelBuilder.Entity("PARR.DAL.Models.JobStatus", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTimeOffset>("DateCreated")
.HasColumnType("timestamp with time zone");
b.Property<DateTimeOffset?>("DateModified")
.HasColumnType("timestamp with time zone");
b.Property<string>("Description")
.HasColumnType("text");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("JobStatuses");
});
modelBuilder.Entity("PARR.DAL.Models.JobType", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTimeOffset>("DateCreated")
.HasColumnType("timestamp with time zone");
b.Property<DateTimeOffset?>("DateModified")
.HasColumnType("timestamp with time zone");
b.Property<string>("Description")
.HasColumnType("text");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("JobTypes");
});
modelBuilder.Entity("PARR.DAL.Models.Job", b =>
{
b.HasOne("PARR.DAL.Models.JobCategory", "JobCategorye")
.WithMany("Jobs")
.HasForeignKey("JobCategoryId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("PARR.DAL.Models.JobModeService", "JobModeService")
.WithMany("Jobs")
.HasForeignKey("JobModeId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("PARR.DAL.Models.JobType", "JobType")
.WithMany("Jobs")
.HasForeignKey("JobTypeId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("JobCategorye");
b.Navigation("JobModeService");
b.Navigation("JobType");
});
modelBuilder.Entity("PARR.DAL.Models.JobJournal", b =>
{
b.HasOne("PARR.DAL.Models.Host", "Host")
.WithMany("JobJournals")
.HasForeignKey("HostId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("PARR.DAL.Models.Job", "Job")
.WithMany("Journals")
.HasForeignKey("JobId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("PARR.DAL.Models.JobStatus", "Status")
.WithMany("Journals")
.HasForeignKey("JobStatusId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Host");
b.Navigation("Job");
b.Navigation("Status");
});
modelBuilder.Entity("PARR.DAL.Models.Host", b =>
{
b.Navigation("JobJournals");
});
modelBuilder.Entity("PARR.DAL.Models.Job", b =>
{
b.Navigation("Journals");
});
modelBuilder.Entity("PARR.DAL.Models.JobCategory", b =>
{
b.Navigation("Jobs");
});
modelBuilder.Entity("PARR.DAL.Models.JobModeService", b =>
{
b.Navigation("Jobs");
});
modelBuilder.Entity("PARR.DAL.Models.JobStatus", b =>
{
b.Navigation("Journals");
});
modelBuilder.Entity("PARR.DAL.Models.JobType", b =>
{
b.Navigation("Jobs");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -1,98 +0,0 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace PARR.DAL.Migrations
{
/// <inheritdoc />
public partial class UpdTblHosts : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.RenameColumn(
name: "EK",
table: "Hosts",
newName: "WorkGroup");
migrationBuilder.AddColumn<string>(
name: "APP",
table: "Hosts",
type: "text",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "DB",
table: "Hosts",
type: "text",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "LinkEK",
table: "Hosts",
type: "text",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "OS",
table: "Hosts",
type: "text",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "RegionalEK",
table: "Hosts",
type: "text",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "Responsible",
table: "Hosts",
type: "text",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "Status",
table: "Hosts",
type: "text",
nullable: true);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "APP",
table: "Hosts");
migrationBuilder.DropColumn(
name: "DB",
table: "Hosts");
migrationBuilder.DropColumn(
name: "LinkEK",
table: "Hosts");
migrationBuilder.DropColumn(
name: "OS",
table: "Hosts");
migrationBuilder.DropColumn(
name: "RegionalEK",
table: "Hosts");
migrationBuilder.DropColumn(
name: "Responsible",
table: "Hosts");
migrationBuilder.DropColumn(
name: "Status",
table: "Hosts");
migrationBuilder.RenameColumn(
name: "WorkGroup",
table: "Hosts",
newName: "EK");
}
}
}

View File

@@ -12,8 +12,8 @@ using PARR.DAL.Context;
namespace PARR.DAL.Migrations
{
[DbContext(typeof(DataContext))]
[Migration("20230601014714_UpdTblHosts")]
partial class UpdTblHosts
[Migration("20230616045916_DbV2")]
partial class DbV2
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
@@ -25,18 +25,117 @@ namespace PARR.DAL.Migrations
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("PARR.DAL.Models.Host", b =>
modelBuilder.Entity("PARR.DAL.Models.Application", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("APP")
b.Property<Guid?>("ApplicationId")
.HasColumnType("uuid");
b.Property<Guid>("ApplicationTypeId")
.HasColumnType("uuid");
b.Property<DateTimeOffset>("DateCreated")
.HasColumnType("timestamp with time zone");
b.Property<DateTimeOffset?>("DateModified")
.HasColumnType("timestamp with time zone");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<string>("DB")
b.HasKey("Id");
b.HasIndex("ApplicationId");
b.HasIndex("ApplicationTypeId");
b.ToTable("Applications");
});
modelBuilder.Entity("PARR.DAL.Models.ApplicationInHost", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<Guid>("ApplicationId")
.HasColumnType("uuid");
b.Property<DateTimeOffset>("DateCreated")
.HasColumnType("timestamp with time zone");
b.Property<DateTimeOffset?>("DateModified")
.HasColumnType("timestamp with time zone");
b.Property<Guid>("HostId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ApplicationId");
b.HasIndex("HostId");
b.ToTable("ApplicationsInHosts");
});
modelBuilder.Entity("PARR.DAL.Models.ApplicationType", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTimeOffset>("DateCreated")
.HasColumnType("timestamp with time zone");
b.Property<DateTimeOffset?>("DateModified")
.HasColumnType("timestamp with time zone");
b.Property<string>("Description")
.HasColumnType("text");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("ApplicationTypes");
b.HasData(
new
{
Id = new Guid("32c28386-6f13-4f7b-8508-be165b7fabdb"),
DateCreated = new DateTimeOffset(new DateTime(2023, 5, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0)),
Description = "Поле СП xml АИХ ИТ",
Name = "APP"
},
new
{
Id = new Guid("7848a96c-cdee-48c1-a786-de9cb889723a"),
DateCreated = new DateTimeOffset(new DateTime(2023, 5, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0)),
Description = "Поле ОС xml АИХ ИТ",
Name = "OS"
},
new
{
Id = new Guid("aae2636f-b93a-42dc-873e-0764a90a0a40"),
DateCreated = new DateTimeOffset(new DateTime(2023, 5, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0)),
Description = "Поле СУБД xml АИХ ИТ",
Name = "DB"
});
});
modelBuilder.Entity("PARR.DAL.Models.Host", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTimeOffset>("DateCreated")
.HasColumnType("timestamp with time zone");
@@ -44,7 +143,6 @@ namespace PARR.DAL.Migrations
.HasColumnType("timestamp with time zone");
b.Property<string>("HostName")
.IsRequired()
.HasColumnType("text");
b.Property<string>("IP")
@@ -54,9 +152,6 @@ namespace PARR.DAL.Migrations
b.Property<string>("LinkEK")
.HasColumnType("text");
b.Property<string>("OS")
.HasColumnType("text");
b.Property<string>("RegionalEK")
.HasColumnType("text");
@@ -80,13 +175,16 @@ namespace PARR.DAL.Migrations
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<Guid>("ApplicationId")
.HasColumnType("uuid");
b.Property<DateTimeOffset>("DateCreated")
.HasColumnType("timestamp with time zone");
b.Property<DateTimeOffset?>("DateModified")
.HasColumnType("timestamp with time zone");
b.Property<Guid>("JobCategoryId")
b.Property<Guid?>("JobCategoryId")
.HasColumnType("uuid");
b.Property<Guid>("JobModeId")
@@ -99,8 +197,14 @@ namespace PARR.DAL.Migrations
.IsRequired()
.HasColumnType("text");
b.Property<string>("ScriptName")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("ApplicationId");
b.HasIndex("JobCategoryId");
b.HasIndex("JobModeId");
@@ -178,7 +282,7 @@ namespace PARR.DAL.Migrations
b.ToTable("JobJournals");
});
modelBuilder.Entity("PARR.DAL.Models.JobModeService", b =>
modelBuilder.Entity("PARR.DAL.Models.JobMode", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
@@ -197,6 +301,20 @@ namespace PARR.DAL.Migrations
b.HasKey("Id");
b.ToTable("JobModes");
b.HasData(
new
{
Id = new Guid("fba4202c-5bad-49c4-b076-d1ca6e1fb158"),
DateCreated = new DateTimeOffset(new DateTime(2023, 5, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0)),
Name = "auto"
},
new
{
Id = new Guid("7516b952-510d-4aaa-971c-a14b184fc1d5"),
DateCreated = new DateTimeOffset(new DateTime(2023, 5, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0)),
Name = "manual"
});
});
modelBuilder.Entity("PARR.DAL.Models.JobStatus", b =>
@@ -247,15 +365,82 @@ namespace PARR.DAL.Migrations
b.ToTable("JobTypes");
});
modelBuilder.Entity("PARR.DAL.Models.Job", b =>
modelBuilder.Entity("PARR.DAL.Models.Scheduler", b =>
{
b.HasOne("PARR.DAL.Models.JobCategory", "JobCategorye")
.WithMany("Jobs")
.HasForeignKey("JobCategoryId")
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTimeOffset>("DateCreated")
.HasColumnType("timestamp with time zone");
b.Property<DateTimeOffset?>("DateModified")
.HasColumnType("timestamp with time zone");
b.Property<int>("Frequency")
.HasColumnType("integer");
b.Property<bool>("IsEnabled")
.HasColumnType("boolean");
b.Property<string>("Name")
.HasColumnType("text");
b.Property<DateTimeOffset>("StartAt")
.HasColumnType("timestamp with time zone");
b.HasKey("Id");
b.ToTable("Schedulers");
});
modelBuilder.Entity("PARR.DAL.Models.Application", b =>
{
b.HasOne("PARR.DAL.Models.Application", null)
.WithMany("Applications")
.HasForeignKey("ApplicationId");
b.HasOne("PARR.DAL.Models.ApplicationType", "ApplicationType")
.WithMany()
.HasForeignKey("ApplicationTypeId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("PARR.DAL.Models.JobModeService", "JobModeService")
b.Navigation("ApplicationType");
});
modelBuilder.Entity("PARR.DAL.Models.ApplicationInHost", b =>
{
b.HasOne("PARR.DAL.Models.Application", "Application")
.WithMany("ApplicationsInHosts")
.HasForeignKey("ApplicationId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("PARR.DAL.Models.Host", "Host")
.WithMany("ApplicationsInHosts")
.HasForeignKey("HostId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Application");
b.Navigation("Host");
});
modelBuilder.Entity("PARR.DAL.Models.Job", b =>
{
b.HasOne("PARR.DAL.Models.Application", "Application")
.WithMany()
.HasForeignKey("ApplicationId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("PARR.DAL.Models.JobCategory", "JobCategorye")
.WithMany("Jobs")
.HasForeignKey("JobCategoryId");
b.HasOne("PARR.DAL.Models.JobMode", "JobMode")
.WithMany("Jobs")
.HasForeignKey("JobModeId")
.OnDelete(DeleteBehavior.Cascade)
@@ -267,9 +452,11 @@ namespace PARR.DAL.Migrations
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Application");
b.Navigation("JobCategorye");
b.Navigation("JobModeService");
b.Navigation("JobMode");
b.Navigation("JobType");
});
@@ -301,8 +488,17 @@ namespace PARR.DAL.Migrations
b.Navigation("Status");
});
modelBuilder.Entity("PARR.DAL.Models.Application", b =>
{
b.Navigation("Applications");
b.Navigation("ApplicationsInHosts");
});
modelBuilder.Entity("PARR.DAL.Models.Host", b =>
{
b.Navigation("ApplicationsInHosts");
b.Navigation("JobJournals");
});
@@ -316,7 +512,7 @@ namespace PARR.DAL.Migrations
b.Navigation("Jobs");
});
modelBuilder.Entity("PARR.DAL.Models.JobModeService", b =>
modelBuilder.Entity("PARR.DAL.Models.JobMode", b =>
{
b.Navigation("Jobs");
});

View File

@@ -3,14 +3,31 @@ using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional
namespace PARR.DAL.Migrations
{
/// <inheritdoc />
public partial class AllTbls : Migration
public partial class DbV2 : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "ApplicationTypes",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
DateCreated = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
DateModified = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
Name = table.Column<string>(type: "text", nullable: false),
Description = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_ApplicationTypes", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Hosts",
columns: table => new
@@ -18,9 +35,13 @@ namespace PARR.DAL.Migrations
Id = table.Column<Guid>(type: "uuid", nullable: false),
DateCreated = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
DateModified = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
HostName = table.Column<string>(type: "text", nullable: false),
HostName = table.Column<string>(type: "text", nullable: true),
IP = table.Column<string>(type: "text", nullable: false),
EK = table.Column<string>(type: "text", nullable: true)
RegionalEK = table.Column<string>(type: "text", nullable: true),
LinkEK = table.Column<string>(type: "text", nullable: true),
Status = table.Column<string>(type: "text", nullable: true),
WorkGroup = table.Column<string>(type: "text", nullable: true),
Responsible = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
@@ -86,6 +107,77 @@ namespace PARR.DAL.Migrations
table.PrimaryKey("PK_JobTypes", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Schedulers",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
DateCreated = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
DateModified = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
Name = table.Column<string>(type: "text", nullable: true),
Frequency = table.Column<int>(type: "integer", nullable: false),
StartAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
IsEnabled = table.Column<bool>(type: "boolean", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Schedulers", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Applications",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
DateCreated = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
DateModified = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
Name = table.Column<string>(type: "text", nullable: false),
ApplicationTypeId = table.Column<Guid>(type: "uuid", nullable: false),
ApplicationId = table.Column<Guid>(type: "uuid", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Applications", x => x.Id);
table.ForeignKey(
name: "FK_Applications_ApplicationTypes_ApplicationTypeId",
column: x => x.ApplicationTypeId,
principalTable: "ApplicationTypes",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Applications_Applications_ApplicationId",
column: x => x.ApplicationId,
principalTable: "Applications",
principalColumn: "Id");
});
migrationBuilder.CreateTable(
name: "ApplicationsInHosts",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
DateCreated = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
DateModified = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
ApplicationId = table.Column<Guid>(type: "uuid", nullable: false),
HostId = table.Column<Guid>(type: "uuid", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_ApplicationsInHosts", x => x.Id);
table.ForeignKey(
name: "FK_ApplicationsInHosts_Applications_ApplicationId",
column: x => x.ApplicationId,
principalTable: "Applications",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_ApplicationsInHosts_Hosts_HostId",
column: x => x.HostId,
principalTable: "Hosts",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Jobs",
columns: table => new
@@ -94,19 +186,26 @@ namespace PARR.DAL.Migrations
DateCreated = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
DateModified = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
Name = table.Column<string>(type: "text", nullable: false),
ScriptName = table.Column<string>(type: "text", nullable: false),
JobModeId = table.Column<Guid>(type: "uuid", nullable: false),
JobCategoryId = table.Column<Guid>(type: "uuid", nullable: false),
JobTypeId = table.Column<Guid>(type: "uuid", nullable: false)
JobCategoryId = table.Column<Guid>(type: "uuid", nullable: true),
JobTypeId = table.Column<Guid>(type: "uuid", nullable: false),
ApplicationId = table.Column<Guid>(type: "uuid", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Jobs", x => x.Id);
table.ForeignKey(
name: "FK_Jobs_Applications_ApplicationId",
column: x => x.ApplicationId,
principalTable: "Applications",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Jobs_JobCategories_JobCategoryId",
column: x => x.JobCategoryId,
principalTable: "JobCategories",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
principalColumn: "Id");
table.ForeignKey(
name: "FK_Jobs_JobModes_JobModeId",
column: x => x.JobModeId,
@@ -159,6 +258,45 @@ namespace PARR.DAL.Migrations
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.InsertData(
table: "ApplicationTypes",
columns: new[] { "Id", "DateCreated", "DateModified", "Description", "Name" },
values: new object[,]
{
{ new Guid("32c28386-6f13-4f7b-8508-be165b7fabdb"), new DateTimeOffset(new DateTime(2023, 5, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0)), null, "Поле СП xml АИХ ИТ", "APP" },
{ new Guid("7848a96c-cdee-48c1-a786-de9cb889723a"), new DateTimeOffset(new DateTime(2023, 5, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0)), null, "Поле ОС xml АИХ ИТ", "OS" },
{ new Guid("aae2636f-b93a-42dc-873e-0764a90a0a40"), new DateTimeOffset(new DateTime(2023, 5, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0)), null, "Поле СУБД xml АИХ ИТ", "DB" }
});
migrationBuilder.InsertData(
table: "JobModes",
columns: new[] { "Id", "DateCreated", "DateModified", "Name" },
values: new object[,]
{
{ new Guid("7516b952-510d-4aaa-971c-a14b184fc1d5"), new DateTimeOffset(new DateTime(2023, 5, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0)), null, "manual" },
{ new Guid("fba4202c-5bad-49c4-b076-d1ca6e1fb158"), new DateTimeOffset(new DateTime(2023, 5, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0)), null, "auto" }
});
migrationBuilder.CreateIndex(
name: "IX_Applications_ApplicationId",
table: "Applications",
column: "ApplicationId");
migrationBuilder.CreateIndex(
name: "IX_Applications_ApplicationTypeId",
table: "Applications",
column: "ApplicationTypeId");
migrationBuilder.CreateIndex(
name: "IX_ApplicationsInHosts_ApplicationId",
table: "ApplicationsInHosts",
column: "ApplicationId");
migrationBuilder.CreateIndex(
name: "IX_ApplicationsInHosts_HostId",
table: "ApplicationsInHosts",
column: "HostId");
migrationBuilder.CreateIndex(
name: "IX_JobJournals_HostId",
table: "JobJournals",
@@ -174,6 +312,11 @@ namespace PARR.DAL.Migrations
table: "JobJournals",
column: "JobStatusId");
migrationBuilder.CreateIndex(
name: "IX_Jobs_ApplicationId",
table: "Jobs",
column: "ApplicationId");
migrationBuilder.CreateIndex(
name: "IX_Jobs_JobCategoryId",
table: "Jobs",
@@ -193,9 +336,15 @@ namespace PARR.DAL.Migrations
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "ApplicationsInHosts");
migrationBuilder.DropTable(
name: "JobJournals");
migrationBuilder.DropTable(
name: "Schedulers");
migrationBuilder.DropTable(
name: "Hosts");
@@ -205,6 +354,9 @@ namespace PARR.DAL.Migrations
migrationBuilder.DropTable(
name: "Jobs");
migrationBuilder.DropTable(
name: "Applications");
migrationBuilder.DropTable(
name: "JobCategories");
@@ -213,6 +365,9 @@ namespace PARR.DAL.Migrations
migrationBuilder.DropTable(
name: "JobTypes");
migrationBuilder.DropTable(
name: "ApplicationTypes");
}
}
}

View File

@@ -22,18 +22,117 @@ namespace PARR.DAL.Migrations
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("PARR.DAL.Models.Host", b =>
modelBuilder.Entity("PARR.DAL.Models.Application", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("APP")
b.Property<Guid?>("ApplicationId")
.HasColumnType("uuid");
b.Property<Guid>("ApplicationTypeId")
.HasColumnType("uuid");
b.Property<DateTimeOffset>("DateCreated")
.HasColumnType("timestamp with time zone");
b.Property<DateTimeOffset?>("DateModified")
.HasColumnType("timestamp with time zone");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<string>("DB")
b.HasKey("Id");
b.HasIndex("ApplicationId");
b.HasIndex("ApplicationTypeId");
b.ToTable("Applications");
});
modelBuilder.Entity("PARR.DAL.Models.ApplicationInHost", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<Guid>("ApplicationId")
.HasColumnType("uuid");
b.Property<DateTimeOffset>("DateCreated")
.HasColumnType("timestamp with time zone");
b.Property<DateTimeOffset?>("DateModified")
.HasColumnType("timestamp with time zone");
b.Property<Guid>("HostId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ApplicationId");
b.HasIndex("HostId");
b.ToTable("ApplicationsInHosts");
});
modelBuilder.Entity("PARR.DAL.Models.ApplicationType", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTimeOffset>("DateCreated")
.HasColumnType("timestamp with time zone");
b.Property<DateTimeOffset?>("DateModified")
.HasColumnType("timestamp with time zone");
b.Property<string>("Description")
.HasColumnType("text");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("ApplicationTypes");
b.HasData(
new
{
Id = new Guid("32c28386-6f13-4f7b-8508-be165b7fabdb"),
DateCreated = new DateTimeOffset(new DateTime(2023, 5, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0)),
Description = "Поле СП xml АИХ ИТ",
Name = "APP"
},
new
{
Id = new Guid("7848a96c-cdee-48c1-a786-de9cb889723a"),
DateCreated = new DateTimeOffset(new DateTime(2023, 5, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0)),
Description = "Поле ОС xml АИХ ИТ",
Name = "OS"
},
new
{
Id = new Guid("aae2636f-b93a-42dc-873e-0764a90a0a40"),
DateCreated = new DateTimeOffset(new DateTime(2023, 5, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0)),
Description = "Поле СУБД xml АИХ ИТ",
Name = "DB"
});
});
modelBuilder.Entity("PARR.DAL.Models.Host", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTimeOffset>("DateCreated")
.HasColumnType("timestamp with time zone");
@@ -41,7 +140,6 @@ namespace PARR.DAL.Migrations
.HasColumnType("timestamp with time zone");
b.Property<string>("HostName")
.IsRequired()
.HasColumnType("text");
b.Property<string>("IP")
@@ -51,9 +149,6 @@ namespace PARR.DAL.Migrations
b.Property<string>("LinkEK")
.HasColumnType("text");
b.Property<string>("OS")
.HasColumnType("text");
b.Property<string>("RegionalEK")
.HasColumnType("text");
@@ -77,13 +172,16 @@ namespace PARR.DAL.Migrations
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<Guid>("ApplicationId")
.HasColumnType("uuid");
b.Property<DateTimeOffset>("DateCreated")
.HasColumnType("timestamp with time zone");
b.Property<DateTimeOffset?>("DateModified")
.HasColumnType("timestamp with time zone");
b.Property<Guid>("JobCategoryId")
b.Property<Guid?>("JobCategoryId")
.HasColumnType("uuid");
b.Property<Guid>("JobModeId")
@@ -96,8 +194,14 @@ namespace PARR.DAL.Migrations
.IsRequired()
.HasColumnType("text");
b.Property<string>("ScriptName")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("ApplicationId");
b.HasIndex("JobCategoryId");
b.HasIndex("JobModeId");
@@ -175,7 +279,7 @@ namespace PARR.DAL.Migrations
b.ToTable("JobJournals");
});
modelBuilder.Entity("PARR.DAL.Models.JobModeService", b =>
modelBuilder.Entity("PARR.DAL.Models.JobMode", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
@@ -194,6 +298,20 @@ namespace PARR.DAL.Migrations
b.HasKey("Id");
b.ToTable("JobModes");
b.HasData(
new
{
Id = new Guid("fba4202c-5bad-49c4-b076-d1ca6e1fb158"),
DateCreated = new DateTimeOffset(new DateTime(2023, 5, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0)),
Name = "auto"
},
new
{
Id = new Guid("7516b952-510d-4aaa-971c-a14b184fc1d5"),
DateCreated = new DateTimeOffset(new DateTime(2023, 5, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0)),
Name = "manual"
});
});
modelBuilder.Entity("PARR.DAL.Models.JobStatus", b =>
@@ -244,15 +362,82 @@ namespace PARR.DAL.Migrations
b.ToTable("JobTypes");
});
modelBuilder.Entity("PARR.DAL.Models.Job", b =>
modelBuilder.Entity("PARR.DAL.Models.Scheduler", b =>
{
b.HasOne("PARR.DAL.Models.JobCategory", "JobCategorye")
.WithMany("Jobs")
.HasForeignKey("JobCategoryId")
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTimeOffset>("DateCreated")
.HasColumnType("timestamp with time zone");
b.Property<DateTimeOffset?>("DateModified")
.HasColumnType("timestamp with time zone");
b.Property<int>("Frequency")
.HasColumnType("integer");
b.Property<bool>("IsEnabled")
.HasColumnType("boolean");
b.Property<string>("Name")
.HasColumnType("text");
b.Property<DateTimeOffset>("StartAt")
.HasColumnType("timestamp with time zone");
b.HasKey("Id");
b.ToTable("Schedulers");
});
modelBuilder.Entity("PARR.DAL.Models.Application", b =>
{
b.HasOne("PARR.DAL.Models.Application", null)
.WithMany("Applications")
.HasForeignKey("ApplicationId");
b.HasOne("PARR.DAL.Models.ApplicationType", "ApplicationType")
.WithMany()
.HasForeignKey("ApplicationTypeId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("PARR.DAL.Models.JobModeService", "JobModeService")
b.Navigation("ApplicationType");
});
modelBuilder.Entity("PARR.DAL.Models.ApplicationInHost", b =>
{
b.HasOne("PARR.DAL.Models.Application", "Application")
.WithMany("ApplicationsInHosts")
.HasForeignKey("ApplicationId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("PARR.DAL.Models.Host", "Host")
.WithMany("ApplicationsInHosts")
.HasForeignKey("HostId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Application");
b.Navigation("Host");
});
modelBuilder.Entity("PARR.DAL.Models.Job", b =>
{
b.HasOne("PARR.DAL.Models.Application", "Application")
.WithMany()
.HasForeignKey("ApplicationId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("PARR.DAL.Models.JobCategory", "JobCategorye")
.WithMany("Jobs")
.HasForeignKey("JobCategoryId");
b.HasOne("PARR.DAL.Models.JobMode", "JobMode")
.WithMany("Jobs")
.HasForeignKey("JobModeId")
.OnDelete(DeleteBehavior.Cascade)
@@ -264,9 +449,11 @@ namespace PARR.DAL.Migrations
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Application");
b.Navigation("JobCategorye");
b.Navigation("JobModeService");
b.Navigation("JobMode");
b.Navigation("JobType");
});
@@ -298,8 +485,17 @@ namespace PARR.DAL.Migrations
b.Navigation("Status");
});
modelBuilder.Entity("PARR.DAL.Models.Application", b =>
{
b.Navigation("Applications");
b.Navigation("ApplicationsInHosts");
});
modelBuilder.Entity("PARR.DAL.Models.Host", b =>
{
b.Navigation("ApplicationsInHosts");
b.Navigation("JobJournals");
});
@@ -313,7 +509,7 @@ namespace PARR.DAL.Migrations
b.Navigation("Jobs");
});
modelBuilder.Entity("PARR.DAL.Models.JobModeService", b =>
modelBuilder.Entity("PARR.DAL.Models.JobMode", b =>
{
b.Navigation("Jobs");
});

View File

@@ -19,5 +19,6 @@ namespace PARR.DAL.Models
public ICollection<ApplicationInHost> ApplicationsInHosts { get; set; } = new HashSet<ApplicationInHost>();
public ICollection<Application> Applications { get;set; } = new HashSet<Application>();
}
}

View File

@@ -1,10 +1,5 @@
using PARR.DAL.Models.Base;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PARR.DAL.Models
{

View File

@@ -12,13 +12,14 @@ namespace PARR.DAL.Models
public DateTimeOffset DateCreated { get; set; }
public DateTimeOffset? DateModified { get; set; }
public required string Name { get; set; }
public required string ScriptName { get; set; }
public Guid JobModeId { get; set; }
[ForeignKey(nameof(JobModeId))]
public JobMode? JobMode { get; set; }
public Guid JobCategoryId { get; set; }
public Guid? JobCategoryId { get; set; }
[ForeignKey(nameof(JobCategoryId))]
public JobCategory? JobCategorye { get; set; }
@@ -26,7 +27,11 @@ namespace PARR.DAL.Models
[ForeignKey(nameof(JobTypeId))]
public JobType? JobType { get; set; }
public Guid ApplicationId { get; set; }
[ForeignKey(nameof(ApplicationId))]
public Application? Application { get; set; }
public ICollection<JobJournal> Journals { get; set; } = new HashSet<JobJournal>();
}
}

View File

@@ -19,6 +19,7 @@ namespace PARR.DAL
services.AddTransient<IApplicationService, ApplicationService>();
services.AddTransient<IApplicationTypeService, ApplicationTypeService>();
services.AddTransient<IApplicationInHostService, ApplicationInHostService>();
services.AddTransient<ISchedulerService, SchedulerService>();
//services.AddTransient<IAreasInLayerService, AreasInLayerService>();
}

View File

@@ -1,6 +1,7 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using PARR.DAL.Context;
using PARR.DAL.DomainModels;
using PARR.DAL.Models.Base;
using PARR.DAL.Services.Interfaces.Base;
@@ -109,11 +110,11 @@ namespace PARR.DAL.Services.Abstracts
return await EntitySet.FirstOrDefaultAsync(t => t.Id == id);
}
//public virtual IQueryable<T> GetPage(IQueryable<T> query, PaginationFilter paginationFilter)
//{
// int skip = (paginationFilter.PageNumber - 1) * paginationFilter.PageSize;
public virtual IQueryable<T> GetPage(IQueryable<T> query, PaginationFilter paginationFilter)
{
int skip = (paginationFilter.PageNumber - 1) * paginationFilter.PageSize;
// return query.Skip(skip).Take(paginationFilter.PageSize);
//}
return query.Skip(skip).Take(paginationFilter.PageSize);
}
}
}

View File

@@ -0,0 +1,22 @@
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 SchedulerService : BaseService<Scheduler>, ISchedulerService
{
private readonly DataContext dataContext;
public SchedulerService(DataContext dataContext, ILogger<SchedulerService> logger) : base(logger)
{
this.dataContext = dataContext;
}
protected override DbSet<Scheduler> EntitySet => dataContext.Schedulers;
protected override DataContext EntitiContext => dataContext;
}
}

View File

@@ -1,4 +1,5 @@
using PARR.DAL.Models.Base;
using PARR.DAL.DomainModels;
using PARR.DAL.Models.Base;
namespace PARR.DAL.Services.Interfaces.Base
{
@@ -6,7 +7,7 @@ namespace PARR.DAL.Services.Interfaces.Base
{
Task<T?> GetAsync(Guid id);
IQueryable<T> Get();
//IQueryable<T> GetPage(IQueryable<T> query, PaginationFilter paginationFilter);
IQueryable<T> GetPage(IQueryable<T> query, PaginationFilter paginationFilter);
Task<bool> CreateAsync(T obj);
Task<bool> AddRangeAsync(List<T> objs);

View File

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