forked from ddrilling/AsbCloudServer
Merge branch 'dev' into feature/#26940800-add-some-well-categories
This commit is contained in:
commit
bf0c3806ad
@ -1,20 +1,19 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
|
||||||
|
|
||||||
namespace AsbCloudApp.Requests;
|
namespace AsbCloudApp.Requests;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Запрос на получение статистики использования подсистем бурильщиком
|
/// Запрос на получение статистики использования подсистем бурильщиком
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class GetStatRequest: RequestBase
|
public class GetStatRequest : RequestBase
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// id скважин
|
/// id скважин
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IEnumerable<int> IdsWells { get; set; } = new List<int>();
|
public IEnumerable<int> IdsWells { get; set; } = new List<int>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// id Бурильщика
|
/// список ключей бурильщиков
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int? IdDriller { get; set; }
|
public IEnumerable<int> IdsDrillers { get; set; } = new List<int>();
|
||||||
}
|
}
|
@ -56,11 +56,11 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
public async Task<IEnumerable<ScheduleDto>> GetPageAsync(GetStatRequest request, CancellationToken token)
|
public async Task<IEnumerable<ScheduleDto>> GetPageAsync(GetStatRequest request, CancellationToken token)
|
||||||
{
|
{
|
||||||
var idWell = request.IdsWells;
|
var idWell = request.IdsWells;
|
||||||
var idDriller = request.IdDriller;
|
var idsDrillers = request.IdsDrillers;
|
||||||
var query = GetQuery().Where(s => request.IdsWells.Contains(s.IdWell));
|
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);
|
var result = await query.ToArrayAsync(token);
|
||||||
|
@ -67,22 +67,16 @@ internal class SubsystemService : ISubsystemService
|
|||||||
|
|
||||||
var detectedOperations = await detectedOperationService
|
var detectedOperations = await detectedOperationService
|
||||||
.GetOperationsAsync(byWellRequest, token);
|
.GetOperationsAsync(byWellRequest, token);
|
||||||
|
var detectedOperationsByCurrentDriller = detectedOperations.Where(d => d.Driller?.Id == schedule.IdDriller);
|
||||||
|
|
||||||
var groupByDriller = detectedOperations
|
var drillerOperationsStat = await CalcStatAsync(detectedOperationsByCurrentDriller, token);
|
||||||
.Where(operation => operation.Driller is not null)
|
var dto = new DrillerDetectedOperationStatDto
|
||||||
.GroupBy(operation => operation.Driller);
|
|
||||||
|
|
||||||
foreach (var entry in groupByDriller)
|
|
||||||
{
|
{
|
||||||
var drillerOperationsStat = await CalcStatAsync(entry, token);
|
Statistic = drillerOperationsStat,
|
||||||
var dto = new DrillerDetectedOperationStatDto
|
Schedule = schedule,
|
||||||
{
|
Well = well,
|
||||||
Statistic = drillerOperationsStat,
|
};
|
||||||
Schedule = schedule,
|
result.Add(dto);
|
||||||
Well = well,
|
|
||||||
};
|
|
||||||
result.Add(dto);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
11
AsbCloudWebApi.IntegrationTests/Clients/IDrillerClient.cs
Normal file
11
AsbCloudWebApi.IntegrationTests/Clients/IDrillerClient.cs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
using AsbCloudApp.Data;
|
||||||
|
using Refit;
|
||||||
|
|
||||||
|
namespace AsbCloudWebApi.IntegrationTests.Clients;
|
||||||
|
|
||||||
|
public interface IDrillerClient
|
||||||
|
{
|
||||||
|
|
||||||
|
[Get("/api/drillers")]
|
||||||
|
Task<IApiResponse<IEnumerable<DrillerDto>>> GetAsync([Query(CollectionFormat.Multi)] IEnumerable<int> idsWells, CancellationToken token);
|
||||||
|
}
|
@ -0,0 +1,88 @@
|
|||||||
|
using AsbCloudApp.Data;
|
||||||
|
using AsbCloudApp.Requests;
|
||||||
|
using AsbCloudDb.Model;
|
||||||
|
using AsbCloudWebApi.IntegrationTests.Clients;
|
||||||
|
using AsbCloudWebApi.IntegrationTests.Data;
|
||||||
|
using System;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace AsbCloudWebApi.IntegrationTests.Controllers;
|
||||||
|
|
||||||
|
public class DrillerControllerTest : BaseIntegrationTest
|
||||||
|
{
|
||||||
|
private readonly IDrillerClient client;
|
||||||
|
|
||||||
|
public DrillerControllerTest(WebAppFactoryFixture factory)
|
||||||
|
: base(factory)
|
||||||
|
{
|
||||||
|
client = factory.GetAuthorizedHttpClient<IDrillerClient>(string.Empty);
|
||||||
|
|
||||||
|
dbContext.CleanupDbSet<Driller>();
|
||||||
|
dbContext.CleanupDbSet<Schedule>();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task GetByWellIds_returns_success()
|
||||||
|
{
|
||||||
|
//arrange
|
||||||
|
var well1 = CreateWellAsync(2);
|
||||||
|
var well2 = CreateWellAsync(3);
|
||||||
|
var well3 = CreateWellAsync(4);
|
||||||
|
dbContext.Wells.Add(well1);
|
||||||
|
dbContext.Wells.Add(well2);
|
||||||
|
dbContext.Wells.Add(well3);
|
||||||
|
|
||||||
|
var driller1 = CreateDrillerAsync(1);
|
||||||
|
var driller2 = CreateDrillerAsync(2);
|
||||||
|
var driller3 = CreateDrillerAsync(3);
|
||||||
|
|
||||||
|
var schedule1= CreateScheduleAsync(well1.Id, driller1);
|
||||||
|
var schedule2 = CreateScheduleAsync(well2.Id, driller2);
|
||||||
|
var schedule3 = CreateScheduleAsync(well3.Id, driller3);
|
||||||
|
|
||||||
|
dbContext.Schedule.Add(schedule1);
|
||||||
|
dbContext.Schedule.Add(schedule2);
|
||||||
|
dbContext.Schedule.Add(schedule3);
|
||||||
|
|
||||||
|
await dbContext.SaveChangesAsync();
|
||||||
|
|
||||||
|
////act
|
||||||
|
var idsWells = dbContext.Wells.ToArray().Select(w => w.Id);
|
||||||
|
var response = await client.GetAsync(idsWells, CancellationToken.None);
|
||||||
|
|
||||||
|
////assert
|
||||||
|
Assert.NotNull(response.Content);
|
||||||
|
Assert.Equal(3, response.Content.Count());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Schedule CreateScheduleAsync(int idWell, Driller driller) => new()
|
||||||
|
{
|
||||||
|
IdWell = idWell,
|
||||||
|
ShiftStart = new TimeOnly(8, 0, 0),
|
||||||
|
ShiftEnd = new TimeOnly(20, 0, 0),
|
||||||
|
DrillStart = new DateTimeOffset(new DateTime(2024, 1, 1, 0, 0, 0, DateTimeKind.Utc)),
|
||||||
|
DrillEnd = new DateTimeOffset(new DateTime(2024, 2, 1, 0, 0, 0, DateTimeKind.Utc)),
|
||||||
|
Driller = driller
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
private static Well CreateWellAsync(int idWell) => new()
|
||||||
|
{
|
||||||
|
Id = idWell,
|
||||||
|
IdWellType = 1,
|
||||||
|
IdState = 1,
|
||||||
|
Caption = $"Скважина {idWell}",
|
||||||
|
Latitude = 10,
|
||||||
|
Longitude = 20,
|
||||||
|
Timezone = Defaults.Timezone,
|
||||||
|
IdCluster = 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
private static Driller CreateDrillerAsync(int idDriller) => new()
|
||||||
|
{
|
||||||
|
Id = idDriller,
|
||||||
|
Name = idDriller.ToString(),
|
||||||
|
Patronymic = idDriller.ToString(),
|
||||||
|
Surname= idDriller.ToString()
|
||||||
|
};
|
||||||
|
}
|
@ -1,7 +1,13 @@
|
|||||||
using AsbCloudApp.Data;
|
using AsbCloudApp.Data;
|
||||||
|
using AsbCloudApp.Requests;
|
||||||
using AsbCloudApp.Services;
|
using AsbCloudApp.Services;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace AsbCloudWebApi.Controllers
|
namespace AsbCloudWebApi.Controllers
|
||||||
{
|
{
|
||||||
@ -13,8 +19,38 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
[Authorize]
|
[Authorize]
|
||||||
public class DrillerController : CrudController<DrillerDto, ICrudRepository<DrillerDto>>
|
public class DrillerController : CrudController<DrillerDto, ICrudRepository<DrillerDto>>
|
||||||
{
|
{
|
||||||
public DrillerController(ICrudRepository<DrillerDto> service)
|
private IScheduleRepository scheduleRepository;
|
||||||
|
|
||||||
|
public DrillerController(ICrudRepository<DrillerDto> service, IScheduleRepository scheduleRepository)
|
||||||
: base(service)
|
: 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