2024-07-04 11:02:45 +05:00
|
|
|
using AsbCloudApp.Data;
|
2024-04-02 14:16:40 +05:00
|
|
|
using AsbCloudApp.Requests;
|
2022-05-22 21:18:43 +05:00
|
|
|
using AsbCloudApp.Services;
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
2024-04-02 14:16:40 +05:00
|
|
|
using Microsoft.AspNetCore.Http;
|
2022-05-22 21:18:43 +05:00
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2024-04-02 14:16:40 +05:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Threading;
|
|
|
|
using System.Threading.Tasks;
|
2022-05-22 21:18:43 +05:00
|
|
|
|
2024-08-19 10:01:07 +05:00
|
|
|
namespace AsbCloudWebApi.Controllers;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Справочник бурильщиков
|
|
|
|
/// </summary>
|
|
|
|
[Route("api/driller")]
|
|
|
|
[ApiController]
|
|
|
|
[Authorize]
|
|
|
|
public class DrillerController : CrudController<DrillerDto, ICrudRepository<DrillerDto>>
|
2022-05-22 21:18:43 +05:00
|
|
|
{
|
2024-08-19 10:01:07 +05:00
|
|
|
private IScheduleRepository scheduleRepository;
|
|
|
|
|
|
|
|
public DrillerController(ICrudRepository<DrillerDto> service, IScheduleRepository scheduleRepository)
|
|
|
|
: base(service)
|
|
|
|
{
|
|
|
|
this.scheduleRepository = scheduleRepository;
|
|
|
|
}
|
|
|
|
|
2022-06-16 17:37:10 +05:00
|
|
|
/// <summary>
|
2024-08-19 10:01:07 +05:00
|
|
|
/// Получить список бурильщиков по ключам скважин
|
2022-06-16 17:37:10 +05:00
|
|
|
/// </summary>
|
2024-08-19 10:01:07 +05:00
|
|
|
/// <param name="idsWells">массив ключей скважин</param>
|
|
|
|
/// <param name="token">token</param>
|
|
|
|
/// <returns>все записи</returns>
|
|
|
|
[HttpGet("/api/drillers")]
|
|
|
|
[Permission]
|
|
|
|
[ProducesResponseType(typeof(IEnumerable<DrillerDto>), StatusCodes.Status200OK)]
|
|
|
|
public async Task<IActionResult> GetAsync([FromQuery] IEnumerable<int> idsWells, CancellationToken token)
|
2022-05-22 21:18:43 +05:00
|
|
|
{
|
2024-08-19 10:01:07 +05:00
|
|
|
var request = new GetStatRequest()
|
2024-04-02 14:16:40 +05:00
|
|
|
{
|
2024-08-19 10:01:07 +05:00
|
|
|
IdsWells = idsWells,
|
|
|
|
};
|
|
|
|
var schedulePage = await scheduleRepository.GetPageAsync(request, token);
|
|
|
|
var drillers = schedulePage
|
|
|
|
.Select(s => s.Driller)
|
|
|
|
.Where(d => d is not null)
|
|
|
|
.GroupBy(d => d!.Id)
|
|
|
|
.Select(group => group.First())
|
|
|
|
.OrderBy(d => d!.Surname);
|
2024-04-02 14:16:40 +05:00
|
|
|
|
2024-08-19 10:01:07 +05:00
|
|
|
return Ok(drillers);
|
2022-05-22 21:18:43 +05:00
|
|
|
}
|
|
|
|
}
|