feat(api): Новый контроллер JobUnitPreview, для получения предпросмотра затрагиваемых ЭК работой
This commit is contained in:
@@ -374,8 +374,6 @@
|
|||||||
public const string Create = Base + "/jobs/";
|
public const string Create = Base + "/jobs/";
|
||||||
public const string Update = Base + "/jobs/" + getParam;
|
public const string Update = Base + "/jobs/" + getParam;
|
||||||
|
|
||||||
public const string Preview = Base + "/jobs/units/preview";
|
|
||||||
|
|
||||||
public const string getParam = "{id}";
|
public const string getParam = "{id}";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -401,7 +399,13 @@
|
|||||||
public const string appInWorkId = "{applicationInWorkId}";
|
public const string appInWorkId = "{applicationInWorkId}";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Предпросмотр затрагиваемых ЭК для фильтров создаваемой или обновляемой работы
|
||||||
|
/// </summary>
|
||||||
|
public static class JobUnitPreview
|
||||||
|
{
|
||||||
|
public const string Preview = Base + "/jobs/units/preview";
|
||||||
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Активатор/деактиватор шаблонов/расписаний
|
/// Активатор/деактиватор шаблонов/расписаний
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -27,10 +27,10 @@
|
|||||||
|
|
||||||
public class UnitFilterRequest
|
public class UnitFilterRequest
|
||||||
{
|
{
|
||||||
/// <summary>
|
///// <summary>
|
||||||
/// Id = null в методе Create, в Update обязателен
|
///// Id = null в методе Create, в Update обязателен
|
||||||
/// </summary>
|
///// </summary>
|
||||||
public Guid? Id { get; set; }
|
//public Guid? Id { get; set; }
|
||||||
|
|
||||||
public required string UnitFilterMask { get; set; }
|
public required string UnitFilterMask { get; set; }
|
||||||
|
|
||||||
|
|||||||
@@ -125,10 +125,10 @@ namespace PARR.API.Controllers.V1
|
|||||||
.Include(t => t.Tnk)
|
.Include(t => t.Tnk)
|
||||||
.Include(t => t.Group)
|
.Include(t => t.Group)
|
||||||
.Include(t => t.UnitFilters)
|
.Include(t => t.UnitFilters)
|
||||||
.ThenInclude(t => t.FieldFilters.OrderBy(o=>o.UnitField!.AihitName))
|
.ThenInclude(t => t.FieldFilters)
|
||||||
.ThenInclude(t => t.UnitField)
|
.ThenInclude(t => t.UnitField)
|
||||||
.Include(t => t.UnitFilters)
|
.Include(t => t.UnitFilters)
|
||||||
.ThenInclude(t => t.RelationshipFilters.OrderBy(o => o.UnitField!.AihitName))
|
.ThenInclude(t => t.RelationshipFilters)
|
||||||
.ThenInclude(t => t.UnitField)
|
.ThenInclude(t => t.UnitField)
|
||||||
.FirstOrDefaultAsync(t => t.Id == id);
|
.FirstOrDefaultAsync(t => t.Id == id);
|
||||||
|
|
||||||
@@ -354,8 +354,8 @@ namespace PARR.API.Controllers.V1
|
|||||||
|
|
||||||
orig.UnitFilters.Add(newUnitFilter);
|
orig.UnitFilters.Add(newUnitFilter);
|
||||||
}
|
}
|
||||||
|
/* Писал полноценный апдейт, но Миша сказал что нахрен это - просто все удаляем, а потом создаём заново
|
||||||
/*//Сразу удаляем UnitFilter которых нет
|
//Сразу удаляем UnitFilter которых нет
|
||||||
var toDelete = orig.UnitFilters.Where(t => !mappedRequest.UnitFilters.Any(e => e.Id == t.Id));
|
var toDelete = orig.UnitFilters.Where(t => !mappedRequest.UnitFilters.Any(e => e.Id == t.Id));
|
||||||
foreach (var item in toDelete)
|
foreach (var item in toDelete)
|
||||||
orig.UnitFilters.Remove(item);
|
orig.UnitFilters.Remove(item);
|
||||||
@@ -529,38 +529,6 @@ namespace PARR.API.Controllers.V1
|
|||||||
return NoContent();
|
return NoContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Получить список ЭК для которых будут созданы шаблоны
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="request"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
[HttpPost(ApiRoutes.Job.Preview)]
|
|
||||||
public async Task<IActionResult> Preview([FromBody] JobRequest request)
|
|
||||||
{
|
|
||||||
#region Валидация
|
|
||||||
var jobValidateResult = await jobValidator.ValidateAsync(request);//Валидация параметров самого задания
|
|
||||||
|
|
||||||
if (!jobValidateResult.IsValid)
|
|
||||||
return BadRequest(new Response(jobValidateResult.Errors));
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
var job = mapper.Map<Job>(request);
|
|
||||||
|
|
||||||
var group = await jobGroupService.GetAsync(request.GroupId);
|
|
||||||
|
|
||||||
job.Group = group;
|
|
||||||
|
|
||||||
var unitIds = await unitFilterService.GetUnitsIdByJobFilterAsync(job);
|
|
||||||
|
|
||||||
if (unitIds == null)
|
|
||||||
return NotFound();
|
|
||||||
|
|
||||||
var units = await unitService.Get().Where(t => unitIds.Any(a => a == t.Id)).Take(1000).ToListAsync();
|
|
||||||
|
|
||||||
var response = mapper.Map<List<UnitResponse>>(units);
|
|
||||||
|
|
||||||
return Ok(response);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Загрузка статистики
|
/// Загрузка статистики
|
||||||
@@ -599,6 +567,7 @@ namespace PARR.API.Controllers.V1
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public class JobStatModel
|
public class JobStatModel
|
||||||
{
|
{
|
||||||
public required TemplateStats TemplateStatistics { get; set; }
|
public required TemplateStats TemplateStatistics { get; set; }
|
||||||
|
|||||||
76
PARR.API/Controllers/V1/JobUnitPreviewController.cs
Normal file
76
PARR.API/Controllers/V1/JobUnitPreviewController.cs
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
using AutoMapper;
|
||||||
|
using FluentValidation;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PARR.API.Contracts.V1;
|
||||||
|
using PARR.API.Contracts.V1.Requests;
|
||||||
|
using PARR.API.Contracts.V1.Responses;
|
||||||
|
using PARR.API.Contracts.V1.Responses.Base;
|
||||||
|
using PARR.API.Controllers.V1.Base;
|
||||||
|
using PARR.Constants;
|
||||||
|
using PARR.DAL.DomainServices.Interfaces;
|
||||||
|
using PARR.DAL.Models.Job;
|
||||||
|
using PARR.DAL.Services.Interfaces.Unit;
|
||||||
|
|
||||||
|
namespace PARR.API.Controllers.V1
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Получение предварительной информации о работах
|
||||||
|
/// </summary>
|
||||||
|
[Authorize(Roles = ParrRoles.Administrator.Role)]
|
||||||
|
public class JobUnitPreviewController : BaseApiController
|
||||||
|
{
|
||||||
|
private readonly ILogger<JobUnitPreviewController> logger;
|
||||||
|
private readonly IUnitFilterService unitFilterService;
|
||||||
|
private readonly IValidator<JobRequest> jobValidator;
|
||||||
|
private readonly IUnitService unitService;
|
||||||
|
private readonly IMapper mapper;
|
||||||
|
|
||||||
|
public JobUnitPreviewController(
|
||||||
|
ILogger<JobUnitPreviewController> logger,
|
||||||
|
IUnitFilterService unitFilterService,
|
||||||
|
IValidator<JobRequest> jobValidator,
|
||||||
|
IUnitService unitService,
|
||||||
|
IMapper mapper
|
||||||
|
)
|
||||||
|
{
|
||||||
|
this.logger = logger;
|
||||||
|
this.unitFilterService = unitFilterService;
|
||||||
|
this.jobValidator = jobValidator;
|
||||||
|
this.unitService = unitService;
|
||||||
|
this.mapper = mapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Получить список ЭК по предполагаемой работе перед сохранением
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="request"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPost(ApiRoutes.JobUnitPreview.Preview)]
|
||||||
|
public async Task<IActionResult> Preview([FromBody] JobRequest request)
|
||||||
|
{
|
||||||
|
#region Валидация
|
||||||
|
var jobValidateResult = await jobValidator.ValidateAsync(request);//Валидация параметров самого задания
|
||||||
|
|
||||||
|
if (!jobValidateResult.IsValid)
|
||||||
|
return BadRequest(new Response(jobValidateResult.Errors));
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
var job = mapper.Map<Job>(request);
|
||||||
|
|
||||||
|
var unitIds = await unitFilterService.GetUnitsIdByJobFilterAsync(job, 100);
|
||||||
|
|
||||||
|
if (unitIds == null || !unitIds.Any())
|
||||||
|
return NoContent();
|
||||||
|
|
||||||
|
var query = unitService.Get().Where(t => unitIds.Any(x => x == t.Id)).OrderBy(o => o.Name);
|
||||||
|
|
||||||
|
var units = await query.ToListAsync();
|
||||||
|
|
||||||
|
var unitResponse = mapper.Map<List<UnitBaseResponse>>(units);
|
||||||
|
|
||||||
|
return Ok(new Response<List<UnitBaseResponse>>(unitResponse, true));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,10 +1,17 @@
|
|||||||
using Microsoft.AspNetCore.Authorization;
|
using AutoMapper;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
using PARR.API.Contracts.V1;
|
using PARR.API.Contracts.V1;
|
||||||
|
using PARR.API.Contracts.V1.Requests.Queries;
|
||||||
|
using PARR.API.Contracts.V1.Responses;
|
||||||
using PARR.API.Contracts.V1.Responses.Base;
|
using PARR.API.Contracts.V1.Responses.Base;
|
||||||
using PARR.API.Controllers.V1.Base;
|
using PARR.API.Controllers.V1.Base;
|
||||||
|
using PARR.API.Extensions;
|
||||||
using PARR.API.Services.Interfaces;
|
using PARR.API.Services.Interfaces;
|
||||||
using PARR.DAL.CacheServices;
|
using PARR.DAL.CacheServices;
|
||||||
|
using PARR.DAL.DomainModels;
|
||||||
|
using PARR.DAL.DomainServices.Interfaces;
|
||||||
using PARR.DAL.Models.Job;
|
using PARR.DAL.Models.Job;
|
||||||
using PARR.DAL.Services.Interfaces;
|
using PARR.DAL.Services.Interfaces;
|
||||||
using PARR.DAL.Services.Interfaces.Job;
|
using PARR.DAL.Services.Interfaces.Job;
|
||||||
@@ -24,6 +31,8 @@ namespace PARR.API.Controllers.V1
|
|||||||
private readonly IFieldFilterService fieldFilterService;
|
private readonly IFieldFilterService fieldFilterService;
|
||||||
private readonly IJobService jobService;
|
private readonly IJobService jobService;
|
||||||
private readonly IJobUnitFilterService jobUnitFilterService;
|
private readonly IJobUnitFilterService jobUnitFilterService;
|
||||||
|
private readonly IUnitFilterService unitFilterService;
|
||||||
|
private readonly IMapper mapper;
|
||||||
|
|
||||||
public TestController(
|
public TestController(
|
||||||
IClientService clientService,
|
IClientService clientService,
|
||||||
@@ -33,7 +42,9 @@ namespace PARR.API.Controllers.V1
|
|||||||
IUnitService unitService,
|
IUnitService unitService,
|
||||||
IFieldFilterService fieldFilterService,
|
IFieldFilterService fieldFilterService,
|
||||||
IJobService jobService,
|
IJobService jobService,
|
||||||
IJobUnitFilterService jobUnitFilterService
|
IJobUnitFilterService jobUnitFilterService,
|
||||||
|
IUnitFilterService unitFilterService,
|
||||||
|
IMapper mapper
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
this.clientService = clientService;
|
this.clientService = clientService;
|
||||||
@@ -44,6 +55,8 @@ namespace PARR.API.Controllers.V1
|
|||||||
this.fieldFilterService = fieldFilterService;
|
this.fieldFilterService = fieldFilterService;
|
||||||
this.jobService = jobService;
|
this.jobService = jobService;
|
||||||
this.jobUnitFilterService = jobUnitFilterService;
|
this.jobUnitFilterService = jobUnitFilterService;
|
||||||
|
this.unitFilterService = unitFilterService;
|
||||||
|
this.mapper = mapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -174,8 +187,6 @@ namespace PARR.API.Controllers.V1
|
|||||||
|
|
||||||
// return Ok(result);
|
// return Ok(result);
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class CaheRequestTest
|
public class CaheRequestTest
|
||||||
|
|||||||
@@ -105,6 +105,8 @@ namespace PARR.API.MappingProfiles
|
|||||||
|
|
||||||
#region Unit
|
#region Unit
|
||||||
|
|
||||||
|
CreateMap<Unit, UnitBaseResponse>();
|
||||||
|
|
||||||
CreateMap<UnitField, FieldResponse>()
|
CreateMap<UnitField, FieldResponse>()
|
||||||
.ForMember(d => d.Name, o => o.MapFrom(s => (string.IsNullOrEmpty(s.DisplayName)) ? s.AihitName : s.DisplayName));
|
.ForMember(d => d.Name, o => o.MapFrom(s => (string.IsNullOrEmpty(s.DisplayName)) ? s.AihitName : s.DisplayName));
|
||||||
|
|
||||||
@@ -314,7 +316,9 @@ namespace PARR.API.MappingProfiles
|
|||||||
CreateMap<Job, JobResponse>();
|
CreateMap<Job, JobResponse>();
|
||||||
|
|
||||||
CreateMap<JobUnitFilter, UnitFilterResponse>()
|
CreateMap<JobUnitFilter, UnitFilterResponse>()
|
||||||
.ForMember(d => d.UnitFilterMask, o => o.MapFrom(d => d.UnitFilter));
|
.ForMember(d => d.UnitFilterMask, o => o.MapFrom(s => s.UnitFilter))
|
||||||
|
.ForMember(d => d.FieldFilters, o => o.MapFrom(s => s.FieldFilters.OrderBy(o => o.UnitField.AihitName)))
|
||||||
|
.ForMember(d => d.RelationshipFilters, o => o.MapFrom(s => s.RelationshipFilters.OrderBy(o => o.UnitField.AihitName)));
|
||||||
|
|
||||||
CreateMap<JobFieldFilter, FieldResponse>();
|
CreateMap<JobFieldFilter, FieldResponse>();
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ namespace PARR.API.MappingProfiles
|
|||||||
});
|
});
|
||||||
|
|
||||||
CreateMap<UnitFilterRequest, JobUnitFilter>()
|
CreateMap<UnitFilterRequest, JobUnitFilter>()
|
||||||
.ForMember(d => d.Id, o => o.MapFrom(s => (s.Id == null) ? Guid.NewGuid() : s.Id))
|
|
||||||
.ForMember(d => d.DateCreated, o => o.MapFrom(s => DateTimeOffset.UtcNow))
|
.ForMember(d => d.DateCreated, o => o.MapFrom(s => DateTimeOffset.UtcNow))
|
||||||
.ForMember(d => d.UnitFilter, o => o.MapFrom(s => s.UnitFilterMask))
|
.ForMember(d => d.UnitFilter, o => o.MapFrom(s => s.UnitFilterMask))
|
||||||
.AfterMap((s, d) =>
|
.AfterMap((s, d) =>
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ namespace PARR.DAL.DomainServices.Implementations
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public async Task<IEnumerable<Guid>?> GetUnitsIdByJobFilterAsync(Guid jobId)
|
public async Task<IEnumerable<Guid>?> GetUnitsIdByJobFilterAsync(Guid jobId, int? takeCount = null)
|
||||||
{
|
{
|
||||||
|
|
||||||
var job = await jobService
|
var job = await jobService
|
||||||
@@ -45,11 +45,11 @@ namespace PARR.DAL.DomainServices.Implementations
|
|||||||
if (job == null)
|
if (job == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
return await GetUnitsIdByJobFilterAsync(job);
|
return await GetUnitsIdByJobFilterAsync(job, takeCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public async Task<IEnumerable<Guid>?> GetUnitsIdByJobFilterAsync(Job job)
|
public async Task<IEnumerable<Guid>?> GetUnitsIdByJobFilterAsync(Job job, int? takeCount = null)
|
||||||
{
|
{
|
||||||
var result = new List<Guid>();
|
var result = new List<Guid>();
|
||||||
|
|
||||||
@@ -112,6 +112,10 @@ namespace PARR.DAL.DomainServices.Implementations
|
|||||||
else
|
else
|
||||||
query = query.Where(t => t.ChildUnits.Count() >= job.MinValueRelationships && t.ChildUnits.Count() <= job.MaxValueRelationships);
|
query = query.Where(t => t.ChildUnits.Count() >= job.MinValueRelationships && t.ChildUnits.Count() <= job.MaxValueRelationships);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (takeCount.HasValue)
|
||||||
|
query = query.Take(takeCount.Value);
|
||||||
|
|
||||||
var newUnits = await query.Select(t => t.Id).ToListAsync();
|
var newUnits = await query.Select(t => t.Id).ToListAsync();
|
||||||
result.AddRange(newUnits);
|
result.AddRange(newUnits);
|
||||||
}
|
}
|
||||||
@@ -121,9 +125,9 @@ namespace PARR.DAL.DomainServices.Implementations
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
public async Task<IEnumerable<Guid>?> GetUnitsIdForExistTemplatesByJobFilterAsync(Guid jobId)
|
public async Task<IEnumerable<Guid>?> GetUnitsIdForExistTemplatesByJobFilterAsync(Guid jobId, int? takeCount = null)
|
||||||
{
|
{
|
||||||
var unitIdsMustBeCreated = await GetUnitsIdByJobFilterAsync(jobId);
|
var unitIdsMustBeCreated = await GetUnitsIdByJobFilterAsync(jobId, takeCount);
|
||||||
|
|
||||||
if (unitIdsMustBeCreated == null || !unitIdsMustBeCreated.Any())
|
if (unitIdsMustBeCreated == null || !unitIdsMustBeCreated.Any())
|
||||||
return null;
|
return null;
|
||||||
@@ -133,9 +137,9 @@ namespace PARR.DAL.DomainServices.Implementations
|
|||||||
return unitWithTemplates;
|
return unitWithTemplates;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IEnumerable<Guid>?> GetUnitsIdForNotExistTemplatesByJobFilterAsync(Guid jobId)
|
public async Task<IEnumerable<Guid>?> GetUnitsIdForNotExistTemplatesByJobFilterAsync(Guid jobId, int? takeCount = null)
|
||||||
{
|
{
|
||||||
var unitIdsMustBeCreated = await GetUnitsIdByJobFilterAsync(jobId);
|
var unitIdsMustBeCreated = await GetUnitsIdByJobFilterAsync(jobId, takeCount);
|
||||||
|
|
||||||
if (unitIdsMustBeCreated == null || !unitIdsMustBeCreated.Any())
|
if (unitIdsMustBeCreated == null || !unitIdsMustBeCreated.Any())
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -9,23 +9,24 @@ namespace PARR.DAL.DomainServices.Interfaces
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="jobId">Id работы</param>
|
/// <param name="jobId">Id работы</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<IEnumerable<Guid>?> GetUnitsIdByJobFilterAsync(Guid jobId);
|
Task<IEnumerable<Guid>?> GetUnitsIdByJobFilterAsync(Guid jobId, int? takeCount = null);
|
||||||
|
|
||||||
Task<IEnumerable<Guid>?> GetUnitsIdByJobFilterAsync(Job job);
|
Task<IEnumerable<Guid>?> GetUnitsIdByJobFilterAsync(Job job, int? takeCount = null);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Получить все Unit.Id, для которых не были созданы Template
|
/// Получить все Unit.Id, для которых не были созданы Template
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="jobId">Id работы</param>
|
/// <param name="jobId">Id работы</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<IEnumerable<Guid>?> GetUnitsIdForNotExistTemplatesByJobFilterAsync(Guid jobId);
|
Task<IEnumerable<Guid>?> GetUnitsIdForNotExistTemplatesByJobFilterAsync(Guid jobId, int? takeCount = null);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Получить все Unit.Id, для которых были созданы Template
|
/// Получить все Unit.Id, для которых были созданы Template
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="jobId">Id работы</param>
|
/// <param name="jobId">Id работы</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<IEnumerable<Guid>?> GetUnitsIdForExistTemplatesByJobFilterAsync(Guid jobId);
|
Task<IEnumerable<Guid>?> GetUnitsIdForExistTemplatesByJobFilterAsync(Guid jobId, int? takeCount = null);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user