forked from ddrilling/AsbCloudServer
Фильтрация наработок по массиву ключей бурильщиков
Подгрузка списка бурильщиков в зависимости от ключей скважин
This commit is contained in:
parent
e4f3adb101
commit
ddbd84e933
@ -14,7 +14,7 @@ public class GetStatRequest: RequestBase
|
||||
public IEnumerable<int> IdsWells { get; set; } = new List<int>();
|
||||
|
||||
/// <summary>
|
||||
/// id Áóðèëüùèêà
|
||||
/// ńďčńîę ęëţ÷ĺé áóđčëüůčęîâ
|
||||
/// </summary>
|
||||
public int? IdDriller { get; set; }
|
||||
public IEnumerable<int> IdsDrillers { get; set; } = new List<int>();
|
||||
}
|
@ -57,11 +57,11 @@ namespace AsbCloudInfrastructure.Repository
|
||||
public async Task<IEnumerable<ScheduleDto>> GetPageAsync(GetStatRequest request, CancellationToken token)
|
||||
{
|
||||
var idWell = request.IdsWells;
|
||||
var idDriller = request.IdDriller;
|
||||
var idsDrillers = request.IdsDrillers;
|
||||
var query = GetQuery().Where(s => request.IdsWells.Contains(s.IdWell));
|
||||
if (idDriller is not null)
|
||||
if (idsDrillers.Any())
|
||||
{
|
||||
query.Where(s => s.IdDriller == idDriller);
|
||||
query = query.Where(s => idsDrillers.Contains(s.IdDriller));
|
||||
}
|
||||
|
||||
var result = await query.ToArrayAsync(token);
|
||||
|
@ -1,7 +1,13 @@
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Requests;
|
||||
using AsbCloudApp.Services;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AsbCloudWebApi.Controllers
|
||||
{
|
||||
@ -13,8 +19,38 @@ namespace AsbCloudWebApi.Controllers
|
||||
[Authorize]
|
||||
public class DrillerController : CrudController<DrillerDto, ICrudRepository<DrillerDto>>
|
||||
{
|
||||
public DrillerController(ICrudRepository<DrillerDto> service)
|
||||
private IScheduleRepository scheduleRepository;
|
||||
|
||||
public DrillerController(ICrudRepository<DrillerDto> service, IScheduleRepository scheduleRepository)
|
||||
: base(service)
|
||||
{ }
|
||||
{
|
||||
this.scheduleRepository = scheduleRepository;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получить список бурильщиков по ключам скважин
|
||||
/// </summary>
|
||||
/// <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)
|
||||
{
|
||||
var request = new GetStatRequest()
|
||||
{
|
||||
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);
|
||||
|
||||
return Ok(drillers);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user