Merge branch 'DrillingModes' into dev

This commit is contained in:
KharchenkoVladimir 2021-10-11 16:43:48 +05:00
commit a860bde21e
5 changed files with 91 additions and 126 deletions

View File

@ -1,6 +1,6 @@
namespace AsbCloudApp.Data
{
public class DrillParamsDto
public class DrillParamsDto : IId
{
public int Id { get; set; }

View File

@ -5,15 +5,9 @@ using AsbCloudApp.Data;
namespace AsbCloudApp.Services
{
public interface IDrillParamsService
public interface IDrillParamsService : ICrudService<DrillParamsDto>
{
Task<DrillParamsDto> GetDefaultDrillParamsAsync(int idWell, double startDepth,
double endDepth, CancellationToken token = default);
// Task<IEnumerable<DrillParamsDto>>GetDrillParamsAsync(int idWell,
// DrillParamsDto drillParamsDto, CancellationToken token = default);
Task<int> SaveDrillParamsAsync(int idWell, DrillParamsDto drillParamsDto,
CancellationToken token = default);
}
}

View File

@ -53,6 +53,7 @@ namespace AsbCloudInfrastructure
services.AddTransient<ICrudService<UserDto>, CrudServiceBase<UserDto, User>>();
services.AddTransient<ICrudService<UserRoleDto>, CrudServiceBase<UserRoleDto, UserRole>>();
services.AddTransient<ICrudService<TelemetryDto>, CrudServiceBase<TelemetryDto, Telemetry>>();
services.AddTransient<ICrudService<DrillParamsDto>, DrillParamsService>();
// TelemetryData services
services.AddTransient<ITelemetryDataService<TelemetryDataSaubDto>, TelemetryDataSaubService>();

View File

@ -6,18 +6,17 @@ using AsbCloudApp.Data;
using AsbCloudApp.Services;
using AsbCloudDb.Model;
using Microsoft.EntityFrameworkCore;
using Mapster;
namespace AsbCloudInfrastructure.Services
{
public class DrillParamsService : IDrillParamsService
public class DrillParamsService : CrudServiceBase<DrillParamsDto, DrillParams>, IDrillParamsService
{
private readonly IAsbCloudDbContext db;
private readonly ITelemetryService telemetryService;
public DrillParamsService(IAsbCloudDbContext db, ITelemetryService telemetryService)
public DrillParamsService(IAsbCloudDbContext context, ITelemetryService telemetryService)
: base(context)
{
this.db = db;
this.telemetryService = telemetryService;
}
public async Task<DrillParamsDto> GetDefaultDrillParamsAsync(int idWell, double startDepth,
@ -28,38 +27,11 @@ namespace AsbCloudInfrastructure.Services
if (idTelemetry is null)
return null;
var axialLoads = await GetDrillParamsQuery(idWell, startDepth, endDepth,
var axialLoads = await GetDrillParams(idWell, startDepth, endDepth,
(telemetry) => telemetry.AxialLoad, token);
var pressures = await GetDrillParamsQuery(idWell, startDepth, endDepth,
var pressures = await GetDrillParams(idWell, startDepth, endDepth,
(telemetry) => telemetry.Pressure, token);
// var topDriveTorques = await (from telemetry in db.TelemetryDataSaub
// where telemetry.IdTelemetry == idTelemetry &&
// telemetry.WellDepth >= startDepth &&
// telemetry.WellDepth <= endDepth
// group telemetry.Pressure by true into g
// select new { Min = g.Min(), Avg = g.Average(), Max = g.Max() })
// .DefaultIfEmpty()
// .FirstOrDefaultAsync(token);
//
// var topDriveSpeeds = await (from telemetry in db.TelemetryDataSaub
// where telemetry.IdTelemetry == idTelemetry &&
// telemetry.WellDepth >= startDepth &&
// telemetry.WellDepth <= endDepth
// group telemetry.Pressure by true into g
// select new { Min = g.Min(), Avg = g.Average(), Max = g.Max() })
// .DefaultIfEmpty()
// .FirstOrDefaultAsync(token);
// var consumptions = await (from telemetry in db.TelemetryDataSaub
// where telemetry.IdTelemetry == idTelemetry &&
// telemetry.WellDepth >= startDepth &&
// telemetry.WellDepth <= endDepth
// group telemetry.Pressure by true into g
// select new { Min = g.Min(), Avg = g.Average(), Max = g.Max() })
// .DefaultIfEmpty()
// .FirstOrDefaultAsync(token);
var drillParamsDto = new DrillParamsDto()
{
@ -85,18 +57,8 @@ namespace AsbCloudInfrastructure.Services
return drillParamsDto;
}
public Task<int> SaveDrillParamsAsync(int idWell, DrillParamsDto drillParamsDto,
CancellationToken token = default)
{
var entity = drillParamsDto.Adapt<DrillParams>();
db.DrillParams.Add(entity);
return db.SaveChangesAsync(token);
}
private async Task<(double Min, double Avg, double Max)> GetDrillParamsQuery(int idTelemetry,
private async Task<(double Min, double Avg, double Max)> GetDrillParams(int idTelemetry,
double startDepth, double endDepth, Func<TelemetryDataSaub, double?> func,
CancellationToken token = default)
{

View File

@ -10,15 +10,18 @@ namespace AsbCloudWebApi.Controllers
/// <summary>
/// Контроллер для режимов бурения
/// </summary>
[Route("/drillParams")]
[Route("api/drillParams")]
[ApiController]
public class DrillParamsController : ControllerBase
{
private readonly IDrillParamsService drillParamsService;
private readonly IWellService wellService;
public DrillParamsController(IDrillParamsService drillParamsService)
public DrillParamsController(IDrillParamsService drillParamsService,
IWellService wellService)
{
this.drillParamsService = drillParamsService;
this.wellService = wellService;
}
/// <summary>
@ -36,37 +39,40 @@ namespace AsbCloudWebApi.Controllers
{
var idCompany = User.GetCompanyId();
if (idCompany is null)
if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
idWell, token).ConfigureAwait(false))
return Forbid();
var dto = await drillParamsService.GetDefaultDrillParamsAsync(idWell, startDepth, endDepth, token);
var drillParamsDo = await drillParamsService.GetDefaultDrillParamsAsync(idWell,
startDepth, endDepth, token);
return Ok(drillParamsDo);
}
/// <summary>
/// Возвращает все значения для режимов бурения по секции на скважине
/// </summary>
/// <param name="idWell"> id скважины </param>
/// <param name="token"> Токен отмены задачи </param>
/// <returns> Список параметров для режимов бурения на скважине </returns>
[HttpGet("idWell")]
[ProducesResponseType(typeof(IEnumerable<DrillParamsDto>), (int) System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> GetDrillParamsAsync(int idWell,
CancellationToken token = default)
{
var idCompany = User.GetCompanyId();
if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
idWell, token).ConfigureAwait(false))
return Forbid();
var dto = await drillParamsService.GetAsync(idWell, token);
return Ok(dto);
}
// /// <summary>
// /// Возвращает значения для режимов бурения gj ctrwbzv yf crdf;byt
// /// </summary>
// /// <param name="idWell"> id скважины </param>
// /// <param name="token"> Токен отмены задачи </param>
// /// <returns> Список параметров для режимов бурения на скважине </returns>
// [HttpGet("idWell")]
// [ProducesResponseType(typeof(IEnumerable<DrillParamsDto>), (int) System.Net.HttpStatusCode.OK)]
// public async Task<IActionResult> GetDrillParamsAsync(int idWell,
// CancellationToken token = default)
// {
// var idCompany = User.GetCompanyId();
//
// if (idCompany is null)
// return Forbid();
//
// var dto = await drillParamsService.GetDrillParamsAsync(idWell, token);
//
// return Ok(dto);
// }
/// <summary>
/// Сохраняет значения для режимов бурения
/// Сохраняет значения для режимов бурения по секции на скважине
/// </summary>
/// <param name="idWell"> id скважины </param>
/// <param name="drillParamsDto"> Параметры режимов бурений для секции</param>
@ -79,59 +85,61 @@ namespace AsbCloudWebApi.Controllers
{
var idCompany = User.GetCompanyId();
if (idCompany is null)
if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
idWell, token).ConfigureAwait(false))
return Forbid();
var result = await drillParamsService.SaveDrillParamsAsync(idWell,
drillParamsDto, token);
var result = await drillParamsService.InsertAsync(drillParamsDto, token);
return Ok(result);
}
// /// <summary>
// /// Изменяет значения для режимов бурения
// /// </summary>
// /// <param name="idWell"> id скважины </param>
// /// <param name="drillParamsDto"> Параметры режимов бурений для секции</param>
// /// <param name="token"> Токен отмены задачи </param>
// /// <returns></returns>
// [HttpPut("idWell")]
// [ProducesResponseType(typeof(int), (int) System.Net.HttpStatusCode.OK)]
// public async Task<IActionResult> EditDrillParamsAsync(int idWell,
// DrillParamsDto drillParamsDto, CancellationToken token = default)
// {
// var idCompany = User.GetCompanyId();
//
// if (idCompany is null)
// return Forbid();
//
// var result = await drillParamsService.EditDrillParamsAsync(idWell,
// drillParamsDto, token);
//
// return Ok(result);
// }
/// <summary>
/// Изменяет значения выбранного режима бурения
/// </summary>
/// <param name="idWell"> id скважины </param>
/// <param name="drillParamsDto"> Параметры режимов бурений для секции</param>
/// <param name="token"> Токен отмены задачи </param>
/// <returns></returns>
[HttpPut("idWell")]
[ProducesResponseType(typeof(int), (int) System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> EditDrillParamsAsync(int idWell,
DrillParamsDto drillParamsDto, CancellationToken token = default)
{
var idCompany = User.GetCompanyId();
// /// <summary>
// /// Удаляет значения для режимов бурения
// /// </summary>
// /// <param name="idWell"> id скважины </param>
// /// <param name="drillParamsDto"> Параметры режимов бурений для секции</param>
// /// <param name="token"> Токен отмены задачи </param>
// /// <returns></returns>
// [HttpDelete("idWell")]
// [ProducesResponseType(typeof(int), (int) System.Net.HttpStatusCode.OK)]
// public async Task<IActionResult> DeleteDrillParamsAsync(int idWell,
// DrillParamsDto drillParamsDto, CancellationToken token = default)
// {
// var idCompany = User.GetCompanyId();
//
// if (idCompany is null)
// return Forbid();
//
// var result = await drillParamsService.DeleteDrillParamsAsync(idWell,
// drillParamsDto, token);
//
// return Ok(result);
// }
if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
idWell, token).ConfigureAwait(false))
return Forbid();
var result = await drillParamsService.UpdateAsync(idWell,
drillParamsDto, token);
return Ok(result);
}
/// <summary>
/// Удаляет объект значений выбранного режима бурения
/// </summary>
/// <param name="idWell"> id скважины </param>
/// <param name="drillParamsId"> Id объекта параметров режима бурений для секции</param>
/// <param name="token"> Токен отмены задачи </param>
/// <returns></returns>
[HttpDelete("idWell")]
[ProducesResponseType(typeof(int), (int) System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> DeleteDrillParamsAsync(int idWell,
int drillParamsId, CancellationToken token = default)
{
var idCompany = User.GetCompanyId();
if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
idWell, token).ConfigureAwait(false))
return Forbid();
var result = await drillParamsService.DeleteAsync(drillParamsId,
token);
return Ok(result);
}
}
}