forked from ddrilling/AsbCloudServer
Reviewed-on: http://test.digitaldrilling.ru:8080/DDrilling/AsbCloudServer/pulls/97
This commit is contained in:
commit
80a07d0b4e
64
AsbCloudApp/Data/WellboreDto.cs
Normal file
64
AsbCloudApp/Data/WellboreDto.cs
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace AsbCloudApp.Data;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Ствол скважины
|
||||||
|
/// </summary>
|
||||||
|
public class WellboreDto
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Идентификатор
|
||||||
|
/// </summary>
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Название
|
||||||
|
/// </summary>
|
||||||
|
public string Name { get; set; } = null!;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Идентификатор скважины
|
||||||
|
/// </summary>
|
||||||
|
public int IdWell { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Состояние скважины
|
||||||
|
/// </summary>
|
||||||
|
public int IdWellState { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Идентификатор телеметрии
|
||||||
|
/// </summary>
|
||||||
|
public int? IdWellTelemetry { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Временная зона скважины
|
||||||
|
/// </summary>
|
||||||
|
public SimpleTimezoneDto? WellTimezone { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Название скважины
|
||||||
|
/// </summary>
|
||||||
|
public string WellName { get; set; } = null!;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Начальная глубина ствола
|
||||||
|
/// </summary>
|
||||||
|
public double DepthStart { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Конечная глубина скважины
|
||||||
|
/// </summary>
|
||||||
|
public double DepthEnd { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Дата начала первой операции
|
||||||
|
/// </summary>
|
||||||
|
public DateTimeOffset DateStart { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Дата завершения последней операции
|
||||||
|
/// </summary>
|
||||||
|
public DateTimeOffset DateEnd { get; set; }
|
||||||
|
}
|
14
AsbCloudApp/Requests/WellboreRequest.cs
Normal file
14
AsbCloudApp/Requests/WellboreRequest.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace AsbCloudApp.Requests;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Параметры запроса для ствола скважины
|
||||||
|
/// </summary>
|
||||||
|
public class WellboreRequest : RequestBase
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Пары идентификаторов скважины и секции
|
||||||
|
/// </summary>
|
||||||
|
public IEnumerable<(int idWell, int? idSection)> Ids { get; set; } = null!;
|
||||||
|
}
|
30
AsbCloudApp/Services/IWellboreService.cs
Normal file
30
AsbCloudApp/Services/IWellboreService.cs
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using AsbCloudApp.Data;
|
||||||
|
using AsbCloudApp.Requests;
|
||||||
|
|
||||||
|
namespace AsbCloudApp.Services;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Сервис для ствола скважины
|
||||||
|
/// </summary>
|
||||||
|
public interface IWellboreService
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Получение ствола скважины
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="idWell"></param>
|
||||||
|
/// <param name="idSection"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<WellboreDto?> GetWellboreAsync(int idWell, int idSection, CancellationToken cancellationToken);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Получение стволов скважин
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="request"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<IEnumerable<WellboreDto>> GetWellboresAsync(WellboreRequest request, CancellationToken cancellationToken);
|
||||||
|
}
|
@ -222,6 +222,8 @@ namespace AsbCloudInfrastructure
|
|||||||
services.AddTransient<IAutoGeneratedDailyReportService, AutoGeneratedDailyReportService>();
|
services.AddTransient<IAutoGeneratedDailyReportService, AutoGeneratedDailyReportService>();
|
||||||
services.AddTransient<IAutoGeneratedDailyReportMakerService, AutoGeneratedDailyReportMakerService>();
|
services.AddTransient<IAutoGeneratedDailyReportMakerService, AutoGeneratedDailyReportMakerService>();
|
||||||
|
|
||||||
|
services.AddTransient<IWellboreService, WellboreService>();
|
||||||
|
|
||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
95
AsbCloudInfrastructure/Services/WellboreService.cs
Normal file
95
AsbCloudInfrastructure/Services/WellboreService.cs
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using AsbCloudApp.Data;
|
||||||
|
using AsbCloudApp.Repositories;
|
||||||
|
using AsbCloudApp.Requests;
|
||||||
|
using AsbCloudApp.Services;
|
||||||
|
using AsbCloudDb.Model;
|
||||||
|
|
||||||
|
namespace AsbCloudInfrastructure.Services;
|
||||||
|
|
||||||
|
public class WellboreService : IWellboreService
|
||||||
|
{
|
||||||
|
private readonly IWellService wellService;
|
||||||
|
private readonly IWellOperationRepository wellOperationRepository;
|
||||||
|
|
||||||
|
public WellboreService(IWellService wellService, IWellOperationRepository wellOperationRepository)
|
||||||
|
{
|
||||||
|
this.wellService = wellService;
|
||||||
|
this.wellOperationRepository = wellOperationRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<WellboreDto?> GetWellboreAsync(int idWell, int idSection, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var request = new WellboreRequest
|
||||||
|
{
|
||||||
|
Ids = new (int, int?)[] { (idWell, idSection) },
|
||||||
|
Take = 1,
|
||||||
|
};
|
||||||
|
var data = await GetWellboresAsync(request, cancellationToken);
|
||||||
|
return data.FirstOrDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IEnumerable<WellboreDto>> GetWellboresAsync(WellboreRequest request,
|
||||||
|
CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var wellbores = new List<WellboreDto>(request.Ids.Count());
|
||||||
|
var skip = request.Skip ?? 0;
|
||||||
|
var take = request.Take ?? 10;
|
||||||
|
|
||||||
|
var sections = wellOperationRepository.GetSectionTypes()
|
||||||
|
.ToDictionary(w => w.Id, w => w);
|
||||||
|
|
||||||
|
var ids = request.Ids.GroupBy(i => i.idWell);
|
||||||
|
|
||||||
|
foreach (var id in ids)
|
||||||
|
{
|
||||||
|
var well = await wellService.GetOrDefaultAsync(id.Key, cancellationToken);
|
||||||
|
|
||||||
|
if (well is null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
var wellOperations = await GetFactOperationsAsync(well.Id, id.Select(i => i.idSection), cancellationToken);
|
||||||
|
var groupedOperations = wellOperations.GroupBy(o => o.IdWellSectionType);
|
||||||
|
var wellWellbores = groupedOperations.Select(group => new WellboreDto {
|
||||||
|
Id = group.Key,
|
||||||
|
IdWell = well.Id,
|
||||||
|
IdWellState = well.IdState,
|
||||||
|
IdWellTelemetry = well.IdTelemetry,
|
||||||
|
Name = sections[group.Key].Caption,
|
||||||
|
WellName = well.Caption,
|
||||||
|
WellTimezone = well.Timezone,
|
||||||
|
|
||||||
|
DateStart = group.Min(operation => operation.DateStart),
|
||||||
|
DateEnd = group.Max(operation => operation.DateStart.AddHours(operation.DurationHours)),
|
||||||
|
DepthStart = group.Min(operation => operation.DepthStart),
|
||||||
|
DepthEnd = group.Max(operation => operation.DepthEnd),
|
||||||
|
});
|
||||||
|
wellbores.AddRange(wellWellbores);
|
||||||
|
}
|
||||||
|
|
||||||
|
return wellbores
|
||||||
|
.OrderBy(w =>w.IdWell).ThenBy(w=>w.Id)
|
||||||
|
.Skip(skip).Take(take);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<IOrderedEnumerable<WellOperationDto>> GetFactOperationsAsync(int idWell, IEnumerable<int?> idsSections,
|
||||||
|
CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var request = new WellOperationRequest
|
||||||
|
{
|
||||||
|
IdWell = idWell,
|
||||||
|
OperationType = WellOperation.IdOperationTypeFact,
|
||||||
|
SortFields = new[] { "DateStart asc" },
|
||||||
|
};
|
||||||
|
|
||||||
|
request.SectionTypeIds = idsSections.All(i => i.HasValue)
|
||||||
|
? idsSections.Select(i => i!.Value)
|
||||||
|
: null;
|
||||||
|
|
||||||
|
return (await wellOperationRepository.GetAsync(request, cancellationToken))
|
||||||
|
.OrderBy(o => o.DateStart);
|
||||||
|
}
|
||||||
|
}
|
92
AsbCloudWebApi/Controllers/WellboreController.cs
Normal file
92
AsbCloudWebApi/Controllers/WellboreController.cs
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using AsbCloudApp.Data;
|
||||||
|
using AsbCloudApp.Exceptions;
|
||||||
|
using AsbCloudApp.Requests;
|
||||||
|
using AsbCloudApp.Services;
|
||||||
|
using AsbCloudDb.Model;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace AsbCloudWebApi.Controllers;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Ствол скважины
|
||||||
|
/// </summary>
|
||||||
|
[Authorize]
|
||||||
|
[ApiController]
|
||||||
|
[Route("api/well/[controller]")]
|
||||||
|
public class WellboreController : ControllerBase
|
||||||
|
{
|
||||||
|
private readonly IWellboreService wellboreService;
|
||||||
|
|
||||||
|
public WellboreController(IWellboreService wellboreService)
|
||||||
|
{
|
||||||
|
this.wellboreService = wellboreService;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Получение ствола скважины
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="idWell">Id скважины</param>
|
||||||
|
/// <param name="idSection">Id типа секции скважины</param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
|
||||||
|
[HttpGet("{idWell:int}/{idSection:int}")]
|
||||||
|
[ProducesResponseType(typeof(WellboreDto), StatusCodes.Status200OK)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
||||||
|
public async Task<IActionResult> GetAsync(int idWell, int idSection, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var wellbore = await wellboreService.GetWellboreAsync(idWell, idSection, cancellationToken);
|
||||||
|
|
||||||
|
if (wellbore is null)
|
||||||
|
return NoContent();
|
||||||
|
|
||||||
|
return Ok(wellbore);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Получение списка стволов скважин
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ids">Пары идентификаторов скважины и секции</param>
|
||||||
|
/// <param name="skip">Опциональный параметр. Количество пропускаемых записей</param>
|
||||||
|
/// <param name="take">Опциональный параметр. Количество получаемых записей</param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpGet]
|
||||||
|
[ProducesResponseType(typeof(IEnumerable<WellboreDto>), StatusCodes.Status200OK)]
|
||||||
|
public async Task<IActionResult> GetAllAsync([FromQuery] IEnumerable<string> ids,
|
||||||
|
int? skip,
|
||||||
|
int? take,
|
||||||
|
CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var request = new WellboreRequest
|
||||||
|
{
|
||||||
|
Ids = ids.Select(id => ParseId(id)),
|
||||||
|
Skip = skip,
|
||||||
|
Take = take
|
||||||
|
};
|
||||||
|
|
||||||
|
return Ok(await wellboreService.GetWellboresAsync(request, cancellationToken));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static (int, int?) ParseId(string id)
|
||||||
|
{
|
||||||
|
var idPair = id.Split(',');
|
||||||
|
if (!int.TryParse(idPair[0], out var idWell))
|
||||||
|
throw new ArgumentInvalidException($"Не удалось получить Id скважины \"{idPair[0]}\"", nameof(id));
|
||||||
|
|
||||||
|
if (idPair.Length > 1)
|
||||||
|
{
|
||||||
|
if (int.TryParse(idPair[1], out int idWellSectionType))
|
||||||
|
return (idWell, idWellSectionType);
|
||||||
|
else
|
||||||
|
throw new ArgumentInvalidException($"Не удалось получить Id ствола \"{idPair[1]}\"", nameof(id));
|
||||||
|
}
|
||||||
|
return (idWell, null);
|
||||||
|
}
|
||||||
|
}
|
15
AsbCloudWebApi/Rest/wellbore.http
Normal file
15
AsbCloudWebApi/Rest/wellbore.http
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
@baseUrl = http://127.0.0.1:5000
|
||||||
|
@contentType = application/json
|
||||||
|
@auth = Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImN0eSI6IkpXVCJ9.eyJpZCI6IjEiLCJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1lIjoiZGV2IiwiaWRDb21wYW55IjoiMSIsImh0dHA6Ly9zY2hlbWFzLm1pY3Jvc29mdC5jb20vd3MvMjAwOC8wNi9pZGVudGl0eS9jbGFpbXMvcm9sZSI6InJvb3QiLCJuYmYiOjE2NjI1NDgxNjIsImV4cCI6MTY5NDEwNTc2MiwiaXNzIjoiYSIsImF1ZCI6ImEifQ.OEAlNzxi7Jat6pzDBTAjTbChskc-tdJthJexyWwwUKE
|
||||||
|
|
||||||
|
@uid = 20210101_000000000
|
||||||
|
@idCluster = 1
|
||||||
|
@idWell = 1
|
||||||
|
|
||||||
|
# https://marketplace.visualstudio.com/items?itemName=humao.rest-client
|
||||||
|
|
||||||
|
###
|
||||||
|
GET {{baseUrl}}/api/well/wellbore?ids=1,2
|
||||||
|
Content-Type: {{contentType}}
|
||||||
|
accept: */*
|
||||||
|
Authorization: {{auth}}
|
Loading…
Reference in New Issue
Block a user