forked from ddrilling/AsbCloudServer
Merge branch 'DrillingModes' into dev
This commit is contained in:
commit
a860bde21e
@ -1,6 +1,6 @@
|
|||||||
namespace AsbCloudApp.Data
|
namespace AsbCloudApp.Data
|
||||||
{
|
{
|
||||||
public class DrillParamsDto
|
public class DrillParamsDto : IId
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
@ -5,15 +5,9 @@ using AsbCloudApp.Data;
|
|||||||
|
|
||||||
namespace AsbCloudApp.Services
|
namespace AsbCloudApp.Services
|
||||||
{
|
{
|
||||||
public interface IDrillParamsService
|
public interface IDrillParamsService : ICrudService<DrillParamsDto>
|
||||||
{
|
{
|
||||||
Task<DrillParamsDto> GetDefaultDrillParamsAsync(int idWell, double startDepth,
|
Task<DrillParamsDto> GetDefaultDrillParamsAsync(int idWell, double startDepth,
|
||||||
double endDepth, CancellationToken token = default);
|
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -53,6 +53,7 @@ namespace AsbCloudInfrastructure
|
|||||||
services.AddTransient<ICrudService<UserDto>, CrudServiceBase<UserDto, User>>();
|
services.AddTransient<ICrudService<UserDto>, CrudServiceBase<UserDto, User>>();
|
||||||
services.AddTransient<ICrudService<UserRoleDto>, CrudServiceBase<UserRoleDto, UserRole>>();
|
services.AddTransient<ICrudService<UserRoleDto>, CrudServiceBase<UserRoleDto, UserRole>>();
|
||||||
services.AddTransient<ICrudService<TelemetryDto>, CrudServiceBase<TelemetryDto, Telemetry>>();
|
services.AddTransient<ICrudService<TelemetryDto>, CrudServiceBase<TelemetryDto, Telemetry>>();
|
||||||
|
services.AddTransient<ICrudService<DrillParamsDto>, DrillParamsService>();
|
||||||
|
|
||||||
// TelemetryData services
|
// TelemetryData services
|
||||||
services.AddTransient<ITelemetryDataService<TelemetryDataSaubDto>, TelemetryDataSaubService>();
|
services.AddTransient<ITelemetryDataService<TelemetryDataSaubDto>, TelemetryDataSaubService>();
|
||||||
|
@ -6,18 +6,17 @@ using AsbCloudApp.Data;
|
|||||||
using AsbCloudApp.Services;
|
using AsbCloudApp.Services;
|
||||||
using AsbCloudDb.Model;
|
using AsbCloudDb.Model;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Mapster;
|
|
||||||
|
|
||||||
namespace AsbCloudInfrastructure.Services
|
namespace AsbCloudInfrastructure.Services
|
||||||
{
|
{
|
||||||
public class DrillParamsService : IDrillParamsService
|
public class DrillParamsService : CrudServiceBase<DrillParamsDto, DrillParams>, IDrillParamsService
|
||||||
{
|
{
|
||||||
private readonly IAsbCloudDbContext db;
|
private readonly IAsbCloudDbContext db;
|
||||||
private readonly ITelemetryService telemetryService;
|
private readonly ITelemetryService telemetryService;
|
||||||
|
|
||||||
public DrillParamsService(IAsbCloudDbContext db, ITelemetryService telemetryService)
|
public DrillParamsService(IAsbCloudDbContext context, ITelemetryService telemetryService)
|
||||||
|
: base(context)
|
||||||
{
|
{
|
||||||
this.db = db;
|
|
||||||
this.telemetryService = telemetryService;
|
this.telemetryService = telemetryService;
|
||||||
}
|
}
|
||||||
public async Task<DrillParamsDto> GetDefaultDrillParamsAsync(int idWell, double startDepth,
|
public async Task<DrillParamsDto> GetDefaultDrillParamsAsync(int idWell, double startDepth,
|
||||||
@ -28,39 +27,12 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
if (idTelemetry is null)
|
if (idTelemetry is null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
var axialLoads = await GetDrillParamsQuery(idWell, startDepth, endDepth,
|
var axialLoads = await GetDrillParams(idWell, startDepth, endDepth,
|
||||||
(telemetry) => telemetry.AxialLoad, token);
|
(telemetry) => telemetry.AxialLoad, token);
|
||||||
|
|
||||||
var pressures = await GetDrillParamsQuery(idWell, startDepth, endDepth,
|
var pressures = await GetDrillParams(idWell, startDepth, endDepth,
|
||||||
(telemetry) => telemetry.Pressure, token);
|
(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()
|
var drillParamsDto = new DrillParamsDto()
|
||||||
{
|
{
|
||||||
IdWell = idWell,
|
IdWell = idWell,
|
||||||
@ -86,17 +58,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
return drillParamsDto;
|
return drillParamsDto;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<int> SaveDrillParamsAsync(int idWell, DrillParamsDto drillParamsDto,
|
private async Task<(double Min, double Avg, double Max)> GetDrillParams(int idTelemetry,
|
||||||
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,
|
|
||||||
double startDepth, double endDepth, Func<TelemetryDataSaub, double?> func,
|
double startDepth, double endDepth, Func<TelemetryDataSaub, double?> func,
|
||||||
CancellationToken token = default)
|
CancellationToken token = default)
|
||||||
{
|
{
|
||||||
|
@ -10,15 +10,18 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Контроллер для режимов бурения
|
/// Контроллер для режимов бурения
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Route("/drillParams")]
|
[Route("api/drillParams")]
|
||||||
[ApiController]
|
[ApiController]
|
||||||
public class DrillParamsController : ControllerBase
|
public class DrillParamsController : ControllerBase
|
||||||
{
|
{
|
||||||
private readonly IDrillParamsService drillParamsService;
|
private readonly IDrillParamsService drillParamsService;
|
||||||
|
private readonly IWellService wellService;
|
||||||
|
|
||||||
public DrillParamsController(IDrillParamsService drillParamsService)
|
public DrillParamsController(IDrillParamsService drillParamsService,
|
||||||
|
IWellService wellService)
|
||||||
{
|
{
|
||||||
this.drillParamsService = drillParamsService;
|
this.drillParamsService = drillParamsService;
|
||||||
|
this.wellService = wellService;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -36,37 +39,40 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
{
|
{
|
||||||
var idCompany = User.GetCompanyId();
|
var idCompany = User.GetCompanyId();
|
||||||
|
|
||||||
if (idCompany is null)
|
if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
||||||
|
idWell, token).ConfigureAwait(false))
|
||||||
return Forbid();
|
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);
|
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>
|
||||||
/// Сохраняет значения для режимов бурения
|
/// Сохраняет значения для режимов бурения по секции на скважине
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="idWell"> id скважины </param>
|
/// <param name="idWell"> id скважины </param>
|
||||||
/// <param name="drillParamsDto"> Параметры режимов бурений для секции</param>
|
/// <param name="drillParamsDto"> Параметры режимов бурений для секции</param>
|
||||||
@ -79,59 +85,61 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
{
|
{
|
||||||
var idCompany = User.GetCompanyId();
|
var idCompany = User.GetCompanyId();
|
||||||
|
|
||||||
if (idCompany is null)
|
if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
||||||
|
idWell, token).ConfigureAwait(false))
|
||||||
return Forbid();
|
return Forbid();
|
||||||
|
|
||||||
var result = await drillParamsService.SaveDrillParamsAsync(idWell,
|
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 || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
||||||
|
idWell, token).ConfigureAwait(false))
|
||||||
|
return Forbid();
|
||||||
|
|
||||||
|
var result = await drillParamsService.UpdateAsync(idWell,
|
||||||
drillParamsDto, token);
|
drillParamsDto, token);
|
||||||
|
|
||||||
return Ok(result);
|
return Ok(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
// /// <summary>
|
/// <summary>
|
||||||
// /// Изменяет значения для режимов бурения
|
/// Удаляет объект значений выбранного режима бурения
|
||||||
// /// </summary>
|
/// </summary>
|
||||||
// /// <param name="idWell"> id скважины </param>
|
/// <param name="idWell"> id скважины </param>
|
||||||
// /// <param name="drillParamsDto"> Параметры режимов бурений для секции</param>
|
/// <param name="drillParamsId"> Id объекта параметров режима бурений для секции</param>
|
||||||
// /// <param name="token"> Токен отмены задачи </param>
|
/// <param name="token"> Токен отмены задачи </param>
|
||||||
// /// <returns></returns>
|
/// <returns></returns>
|
||||||
// [HttpPut("idWell")]
|
[HttpDelete("idWell")]
|
||||||
// [ProducesResponseType(typeof(int), (int) System.Net.HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(int), (int) System.Net.HttpStatusCode.OK)]
|
||||||
// public async Task<IActionResult> EditDrillParamsAsync(int idWell,
|
public async Task<IActionResult> DeleteDrillParamsAsync(int idWell,
|
||||||
// DrillParamsDto drillParamsDto, CancellationToken token = default)
|
int drillParamsId, CancellationToken token = default)
|
||||||
// {
|
{
|
||||||
// var idCompany = User.GetCompanyId();
|
var idCompany = User.GetCompanyId();
|
||||||
//
|
|
||||||
// if (idCompany is null)
|
|
||||||
// return Forbid();
|
|
||||||
//
|
|
||||||
// var result = await drillParamsService.EditDrillParamsAsync(idWell,
|
|
||||||
// drillParamsDto, token);
|
|
||||||
//
|
|
||||||
// return Ok(result);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// /// <summary>
|
if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
||||||
// /// Удаляет значения для режимов бурения
|
idWell, token).ConfigureAwait(false))
|
||||||
// /// </summary>
|
return Forbid();
|
||||||
// /// <param name="idWell"> id скважины </param>
|
|
||||||
// /// <param name="drillParamsDto"> Параметры режимов бурений для секции</param>
|
var result = await drillParamsService.DeleteAsync(drillParamsId,
|
||||||
// /// <param name="token"> Токен отмены задачи </param>
|
token);
|
||||||
// /// <returns></returns>
|
|
||||||
// [HttpDelete("idWell")]
|
return Ok(result);
|
||||||
// [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);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user