2025-09-24 10:08:50 +10:00
|
|
|
|
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;
|
2026-04-30 10:35:31 +10:00
|
|
|
|
using PARR.Core.Repositories.Interfaces.Job;
|
|
|
|
|
|
using PARR.Core.Repositories.Interfaces.Unit;
|
2026-05-04 11:55:07 +10:00
|
|
|
|
using PARR.Core.Services.UnitFilterService;
|
2026-04-14 12:01:49 +10:00
|
|
|
|
using PARR.Domain.Common.Roles;
|
2026-04-30 10:35:31 +10:00
|
|
|
|
using Job = PARR.Domain.Entities.Job.Job;
|
2025-09-24 10:08:50 +10:00
|
|
|
|
|
|
|
|
|
|
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;
|
2026-04-30 10:35:31 +10:00
|
|
|
|
private readonly IUnitRepository unitService;
|
|
|
|
|
|
private readonly IJobGroupRepository jobGroupService;
|
2025-09-24 10:08:50 +10:00
|
|
|
|
private readonly IMapper mapper;
|
|
|
|
|
|
|
|
|
|
|
|
public JobUnitPreviewController(
|
|
|
|
|
|
ILogger<JobUnitPreviewController> logger,
|
|
|
|
|
|
IUnitFilterService unitFilterService,
|
|
|
|
|
|
IValidator<JobRequest> jobValidator,
|
2026-04-30 10:35:31 +10:00
|
|
|
|
IUnitRepository unitService,
|
|
|
|
|
|
IJobGroupRepository jobGroupService,
|
2025-09-24 10:08:50 +10:00
|
|
|
|
IMapper mapper
|
|
|
|
|
|
)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.logger = logger;
|
|
|
|
|
|
this.unitFilterService = unitFilterService;
|
|
|
|
|
|
this.jobValidator = jobValidator;
|
|
|
|
|
|
this.unitService = unitService;
|
2025-11-20 11:37:44 +10:00
|
|
|
|
this.jobGroupService = jobGroupService;
|
2025-09-24 10:08:50 +10:00
|
|
|
|
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);
|
|
|
|
|
|
|
2025-11-20 11:37:44 +10:00
|
|
|
|
var jobGroup = await jobGroupService.Get().AsNoTracking()
|
2025-12-09 16:50:35 +10:00
|
|
|
|
.Include(t => t.GroupType)
|
|
|
|
|
|
.FirstAsync(t => t.Id == job.GroupId);
|
2025-11-20 11:37:44 +10:00
|
|
|
|
job.Group = jobGroup;
|
|
|
|
|
|
|
2025-09-24 10:08:50 +10:00
|
|
|
|
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();
|
|
|
|
|
|
|
2025-09-24 10:16:18 +10:00
|
|
|
|
if (!units.Any())
|
|
|
|
|
|
return NoContent();
|
|
|
|
|
|
|
2025-09-24 10:08:50 +10:00
|
|
|
|
var unitResponse = mapper.Map<List<UnitBaseResponse>>(units);
|
|
|
|
|
|
|
|
|
|
|
|
return Ok(new Response<List<UnitBaseResponse>>(unitResponse, true));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|