feat(api): Новый контроллер JobUnitPreview, для получения предпросмотра затрагиваемых ЭК работой
This commit is contained in:
@@ -374,8 +374,6 @@
|
||||
public const string Create = Base + "/jobs/";
|
||||
public const string Update = Base + "/jobs/" + getParam;
|
||||
|
||||
public const string Preview = Base + "/jobs/units/preview";
|
||||
|
||||
public const string getParam = "{id}";
|
||||
}
|
||||
|
||||
@@ -401,7 +399,13 @@
|
||||
public const string appInWorkId = "{applicationInWorkId}";
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Предпросмотр затрагиваемых ЭК для фильтров создаваемой или обновляемой работы
|
||||
/// </summary>
|
||||
public static class JobUnitPreview
|
||||
{
|
||||
public const string Preview = Base + "/jobs/units/preview";
|
||||
}
|
||||
/// <summary>
|
||||
/// Активатор/деактиватор шаблонов/расписаний
|
||||
/// </summary>
|
||||
@@ -436,7 +440,7 @@
|
||||
{
|
||||
public const string GetAll = Base + "/unit-fields/";
|
||||
public const string Get = Base + "/unit-fields/" + getParam;
|
||||
public const string GetAllValues = Base + "/unit-fields/" + getParam+"/values";
|
||||
public const string GetAllValues = Base + "/unit-fields/" + getParam + "/values";
|
||||
|
||||
public const string getParam = "{id}";
|
||||
}
|
||||
|
||||
@@ -27,10 +27,10 @@
|
||||
|
||||
public class UnitFilterRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// Id = null в методе Create, в Update обязателен
|
||||
/// </summary>
|
||||
public Guid? Id { get; set; }
|
||||
///// <summary>
|
||||
///// Id = null в методе Create, в Update обязателен
|
||||
///// </summary>
|
||||
//public Guid? Id { get; set; }
|
||||
|
||||
public required string UnitFilterMask { get; set; }
|
||||
|
||||
|
||||
@@ -125,10 +125,10 @@ namespace PARR.API.Controllers.V1
|
||||
.Include(t => t.Tnk)
|
||||
.Include(t => t.Group)
|
||||
.Include(t => t.UnitFilters)
|
||||
.ThenInclude(t => t.FieldFilters.OrderBy(o=>o.UnitField!.AihitName))
|
||||
.ThenInclude(t => t.FieldFilters)
|
||||
.ThenInclude(t => t.UnitField)
|
||||
.Include(t => t.UnitFilters)
|
||||
.ThenInclude(t => t.RelationshipFilters.OrderBy(o => o.UnitField!.AihitName))
|
||||
.ThenInclude(t => t.RelationshipFilters)
|
||||
.ThenInclude(t => t.UnitField)
|
||||
.FirstOrDefaultAsync(t => t.Id == id);
|
||||
|
||||
@@ -354,8 +354,8 @@ namespace PARR.API.Controllers.V1
|
||||
|
||||
orig.UnitFilters.Add(newUnitFilter);
|
||||
}
|
||||
|
||||
/*//Сразу удаляем UnitFilter которых нет
|
||||
/* Писал полноценный апдейт, но Миша сказал что нахрен это - просто все удаляем, а потом создаём заново
|
||||
//Сразу удаляем UnitFilter которых нет
|
||||
var toDelete = orig.UnitFilters.Where(t => !mappedRequest.UnitFilters.Any(e => e.Id == t.Id));
|
||||
foreach (var item in toDelete)
|
||||
orig.UnitFilters.Remove(item);
|
||||
@@ -529,38 +529,6 @@ namespace PARR.API.Controllers.V1
|
||||
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>
|
||||
/// Загрузка статистики
|
||||
@@ -599,6 +567,7 @@ namespace PARR.API.Controllers.V1
|
||||
|
||||
}
|
||||
|
||||
|
||||
public class JobStatModel
|
||||
{
|
||||
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.EntityFrameworkCore;
|
||||
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.Controllers.V1.Base;
|
||||
using PARR.API.Extensions;
|
||||
using PARR.API.Services.Interfaces;
|
||||
using PARR.DAL.CacheServices;
|
||||
using PARR.DAL.DomainModels;
|
||||
using PARR.DAL.DomainServices.Interfaces;
|
||||
using PARR.DAL.Models.Job;
|
||||
using PARR.DAL.Services.Interfaces;
|
||||
using PARR.DAL.Services.Interfaces.Job;
|
||||
@@ -24,6 +31,8 @@ namespace PARR.API.Controllers.V1
|
||||
private readonly IFieldFilterService fieldFilterService;
|
||||
private readonly IJobService jobService;
|
||||
private readonly IJobUnitFilterService jobUnitFilterService;
|
||||
private readonly IUnitFilterService unitFilterService;
|
||||
private readonly IMapper mapper;
|
||||
|
||||
public TestController(
|
||||
IClientService clientService,
|
||||
@@ -33,7 +42,9 @@ namespace PARR.API.Controllers.V1
|
||||
IUnitService unitService,
|
||||
IFieldFilterService fieldFilterService,
|
||||
IJobService jobService,
|
||||
IJobUnitFilterService jobUnitFilterService
|
||||
IJobUnitFilterService jobUnitFilterService,
|
||||
IUnitFilterService unitFilterService,
|
||||
IMapper mapper
|
||||
)
|
||||
{
|
||||
this.clientService = clientService;
|
||||
@@ -44,6 +55,8 @@ namespace PARR.API.Controllers.V1
|
||||
this.fieldFilterService = fieldFilterService;
|
||||
this.jobService = jobService;
|
||||
this.jobUnitFilterService = jobUnitFilterService;
|
||||
this.unitFilterService = unitFilterService;
|
||||
this.mapper = mapper;
|
||||
}
|
||||
|
||||
|
||||
@@ -174,8 +187,6 @@ namespace PARR.API.Controllers.V1
|
||||
|
||||
// return Ok(result);
|
||||
//}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public class CaheRequestTest
|
||||
|
||||
@@ -105,6 +105,8 @@ namespace PARR.API.MappingProfiles
|
||||
|
||||
#region Unit
|
||||
|
||||
CreateMap<Unit, UnitBaseResponse>();
|
||||
|
||||
CreateMap<UnitField, FieldResponse>()
|
||||
.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<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>();
|
||||
|
||||
|
||||
@@ -24,7 +24,6 @@ namespace PARR.API.MappingProfiles
|
||||
});
|
||||
|
||||
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.UnitFilter, o => o.MapFrom(s => s.UnitFilterMask))
|
||||
.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
|
||||
@@ -45,11 +45,11 @@ namespace PARR.DAL.DomainServices.Implementations
|
||||
if (job == 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>();
|
||||
|
||||
@@ -112,6 +112,10 @@ namespace PARR.DAL.DomainServices.Implementations
|
||||
else
|
||||
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();
|
||||
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())
|
||||
return null;
|
||||
@@ -133,9 +137,9 @@ namespace PARR.DAL.DomainServices.Implementations
|
||||
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())
|
||||
return null;
|
||||
|
||||
@@ -9,23 +9,24 @@ namespace PARR.DAL.DomainServices.Interfaces
|
||||
/// </summary>
|
||||
/// <param name="jobId">Id работы</param>
|
||||
/// <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>
|
||||
/// Получить все Unit.Id, для которых не были созданы Template
|
||||
/// </summary>
|
||||
/// <param name="jobId">Id работы</param>
|
||||
/// <returns></returns>
|
||||
Task<IEnumerable<Guid>?> GetUnitsIdForNotExistTemplatesByJobFilterAsync(Guid jobId);
|
||||
Task<IEnumerable<Guid>?> GetUnitsIdForNotExistTemplatesByJobFilterAsync(Guid jobId, int? takeCount = null);
|
||||
|
||||
/// <summary>
|
||||
/// Получить все Unit.Id, для которых были созданы Template
|
||||
/// </summary>
|
||||
/// <param name="jobId">Id работы</param>
|
||||
/// <returns></returns>
|
||||
Task<IEnumerable<Guid>?> GetUnitsIdForExistTemplatesByJobFilterAsync(Guid jobId);
|
||||
|
||||
Task<IEnumerable<Guid>?> GetUnitsIdForExistTemplatesByJobFilterAsync(Guid jobId, int? takeCount = null);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user