forked from ddrilling/AsbCloudServer
CS2-94: Added main DrillParams controller and service methods
This commit is contained in:
parent
c962374b6c
commit
afd2801715
45
AsbCloudApp/Data/DrillParamsDto.cs
Normal file
45
AsbCloudApp/Data/DrillParamsDto.cs
Normal file
@ -0,0 +1,45 @@
|
||||
namespace AsbCloudApp.Data
|
||||
{
|
||||
public class DrillParamsDto
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public int IdWell { get; set; }
|
||||
|
||||
public string WellSectionTypeName { get; set; }
|
||||
|
||||
public double DepthStart { get; set; }
|
||||
|
||||
public double DepthEnd { get; set; }
|
||||
|
||||
public double AxialLoadMin { get; set; }
|
||||
|
||||
public double AxialLoadAvg { get; set; }
|
||||
|
||||
public double AxialLoadMax { get; set; }
|
||||
|
||||
public double PressureMin { get; set; }
|
||||
|
||||
public double PressureAvg { get; set; }
|
||||
|
||||
public double PressureMax { get; set; }
|
||||
|
||||
public double TopDriveTorqueMin { get; set; }
|
||||
|
||||
public double TopDriveTorqueAvg { get; set; }
|
||||
|
||||
public double TopDriveTorqueMax { get; set; }
|
||||
|
||||
public double TopDriveSpeedMin { get; set; }
|
||||
|
||||
public double TopDriveSpeedAvg { get; set; }
|
||||
|
||||
public double TopDriveSpeedMax { get; set; }
|
||||
|
||||
public double ConsumptionMin { get; set; }
|
||||
|
||||
public double ConsumptionAvg { get; set; }
|
||||
|
||||
public double ConsumptionMax { get; set; }
|
||||
}
|
||||
}
|
19
AsbCloudApp/Services/IDrillParamsService.cs
Normal file
19
AsbCloudApp/Services/IDrillParamsService.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using AsbCloudApp.Data;
|
||||
|
||||
namespace AsbCloudApp.Services
|
||||
{
|
||||
public interface IDrillParamsService
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AsbCloudApp.Services
|
||||
{
|
||||
public interface IDrillingParamsService
|
||||
{
|
||||
|
||||
}
|
||||
}
|
@ -180,18 +180,19 @@ namespace AsbCloudDb.Model
|
||||
entity.HasIndex(d => d.DateStart);
|
||||
});
|
||||
|
||||
//modelBuilder.Entity<DrillParams>(entity =>
|
||||
//{
|
||||
// entity.HasOne(r => r.Well)
|
||||
// .WithOne(w => w.)
|
||||
// .HasForeignKey(r => r)
|
||||
// .HasConstraintName("t_relation_company_well_t_well_id_fk");
|
||||
modelBuilder.Entity<DrillParams>(entity =>
|
||||
{
|
||||
// entity.HasOne(d => d.Well)
|
||||
// .WithOne(p => p.)
|
||||
// .HasForeignKey<Well>(d => d.IdTelemetry)
|
||||
// .OnDelete(DeleteBehavior.SetNull)
|
||||
// .HasConstraintName("t_well_t_telemetry_id_fk");
|
||||
|
||||
// entity.HasOne(r => r.WellSectionType)
|
||||
// .WithOne(w => w.RelationCompaniesWells)
|
||||
// .HasForeignKey(r => r.IdCompany)
|
||||
// .HasConstraintName("t_relation_company_well_t_company_id_fk");
|
||||
//});
|
||||
entity.HasOne(r => r.WellSectionType)
|
||||
.WithMany(w => w.DrillParamsCollection)
|
||||
.HasForeignKey(r => r.IdWellSectionType)
|
||||
.HasConstraintName("t_drill_params_t_well_section_type_id_fk");
|
||||
});
|
||||
|
||||
FillData(modelBuilder);
|
||||
}
|
||||
|
@ -1,9 +1,7 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Text.Json.Serialization;
|
||||
#nullable disable
|
||||
|
||||
namespace AsbCloudDb.Model
|
||||
{
|
||||
@ -16,8 +14,14 @@ namespace AsbCloudDb.Model
|
||||
|
||||
[Column("well_id"), Comment("Id скважины")]
|
||||
public int IdWell { get; set; }
|
||||
|
||||
[Column("depth_start"), Comment("Стартовая глубина")]
|
||||
public double DepthStart { get; set; }
|
||||
|
||||
[Column("wellsection_type_id"), Comment("Id с типом секции скважины")]
|
||||
[Column("depth_end"), Comment("Глубина окончания интервала")]
|
||||
public double DepthEnd { get; set; }
|
||||
|
||||
[Column("id_wellsection_type"), Comment("Id с типом секции скважины")]
|
||||
public int IdWellSectionType { get; set; }
|
||||
|
||||
[Column("axial_load_min"), Comment("Минимальная нагрузка")]
|
||||
@ -38,12 +42,6 @@ namespace AsbCloudDb.Model
|
||||
[Column("pressure_max"), Comment("Максимальное давление")]
|
||||
public double PressureMax { get; set; }
|
||||
|
||||
[Column("depth_start"), Comment("Минимальный момент на ВСП")]
|
||||
public double DepthStart { get; set; }
|
||||
|
||||
[Column("depth_end"), Comment("Максимальный момент на ВСП")]
|
||||
public double DepthEnd { get; set; }
|
||||
|
||||
[Column("top_drive_min"), Comment("Минимальный момент на ВСП")]
|
||||
public double TopDriveTorqueMin { get; set; }
|
||||
|
||||
|
@ -21,5 +21,9 @@ namespace AsbCloudDb.Model
|
||||
[JsonIgnore]
|
||||
[InverseProperty(nameof(WellOperation.WellSectionType))]
|
||||
public virtual ICollection<WellOperation> WellOperations { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
[InverseProperty(nameof(DrillParams.WellSectionType))]
|
||||
public virtual ICollection<DrillParams> DrillParamsCollection { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ namespace AsbCloudInfrastructure
|
||||
services.AddTransient<IMeasureService, MeasureService>();
|
||||
services.AddTransient<IDrillingProgramService, DrillingProgramService>();
|
||||
services.AddTransient<IDrillingProgramApacheService, DrillingProgramApacheService>();
|
||||
services.AddTransient<IDrillingParamsService, DrillingParamsService>();
|
||||
services.AddTransient<IDrillParamsService, DrillParamsService>();
|
||||
|
||||
// admin crud services:
|
||||
services.AddTransient<ICrudService<DepositDto>, CrudServiceBase<DepositDto, Deposit>>();
|
||||
|
118
AsbCloudInfrastructure/Services/DrillParamsService.cs
Normal file
118
AsbCloudInfrastructure/Services/DrillParamsService.cs
Normal file
@ -0,0 +1,118 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudDb.Model;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Mapster;
|
||||
|
||||
namespace AsbCloudInfrastructure.Services
|
||||
{
|
||||
public class DrillParamsService : IDrillParamsService
|
||||
{
|
||||
private readonly IAsbCloudDbContext db;
|
||||
private readonly ITelemetryService telemetryService;
|
||||
|
||||
public DrillParamsService(IAsbCloudDbContext db, ITelemetryService telemetryService)
|
||||
{
|
||||
this.db = db;
|
||||
this.telemetryService = telemetryService;
|
||||
}
|
||||
public async Task<DrillParamsDto> GetDefaultDrillParamsAsync(int idWell, double startDepth,
|
||||
double endDepth, CancellationToken token = default)
|
||||
{
|
||||
var idTelemetry = telemetryService.GetIdTelemetryByIdWell(idWell);
|
||||
|
||||
if (idTelemetry is null)
|
||||
return null;
|
||||
|
||||
var axialLoads = await GetDrillParamsQuery(idWell, startDepth, endDepth,
|
||||
(telemetry) => telemetry.AxialLoad, token);
|
||||
|
||||
var pressures = await GetDrillParamsQuery(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()
|
||||
{
|
||||
IdWell = idWell,
|
||||
DepthStart = startDepth,
|
||||
DepthEnd = endDepth,
|
||||
AxialLoadMin = axialLoads.Min,
|
||||
AxialLoadAvg = axialLoads.Avg,
|
||||
AxialLoadMax = axialLoads.Max,
|
||||
PressureMin = pressures.Min,
|
||||
PressureAvg = pressures.Avg,
|
||||
PressureMax = pressures.Max,
|
||||
// TopDriveTorqueMin = topDriveTorques.Min ?? 0,
|
||||
// TopDriveTorqueAvg = topDriveTorques.Avg ?? 0,
|
||||
// TopDriveTorqueMax = topDriveTorques.Max ?? 0,
|
||||
// TopDriveSpeedMin = topDriveSpeeds.Min ?? 0,
|
||||
// TopDriveSpeedAvg = topDriveSpeeds.Avg ?? 0,
|
||||
// TopDriveSpeedMax = topDriveSpeeds.Max ?? 0,
|
||||
// ConsumptionMin = consumptions.Min ?? 0,
|
||||
// ConsumptionAvg = consumptions.Avg ?? 0,
|
||||
// ConsumptionMax = consumptions.Max ?? 0,
|
||||
};
|
||||
|
||||
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,
|
||||
double startDepth, double endDepth, Func<TelemetryDataSaub, double?> func,
|
||||
CancellationToken token = default)
|
||||
{
|
||||
var res = await (from telemetry in db.TelemetryDataSaub
|
||||
where telemetry.IdTelemetry == idTelemetry &&
|
||||
telemetry.WellDepth >= startDepth &&
|
||||
telemetry.WellDepth <= endDepth
|
||||
group telemetry by telemetry.IdTelemetry into g
|
||||
select new { Min = g.Min(func), Avg = g.Average(func), Max = g.Max(func) })
|
||||
.DefaultIfEmpty()
|
||||
.AsNoTracking()
|
||||
.FirstOrDefaultAsync(token)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
return (res.Min ?? 0, res.Avg ?? 0, res.Max ?? 0);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using AsbCloudApp.Services;
|
||||
|
||||
namespace AsbCloudInfrastructure.Services
|
||||
{
|
||||
public class DrillingParamsService : IDrillingParamsService
|
||||
{
|
||||
|
||||
}
|
||||
}
|
137
AsbCloudWebApi/Controllers/DrillParamsController.cs
Normal file
137
AsbCloudWebApi/Controllers/DrillParamsController.cs
Normal file
@ -0,0 +1,137 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Services;
|
||||
|
||||
namespace AsbCloudWebApi.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// Контроллер для режимов бурения
|
||||
/// </summary>
|
||||
[Route("/drillParams")]
|
||||
[ApiController]
|
||||
public class DrillParamsController : ControllerBase
|
||||
{
|
||||
private readonly IDrillParamsService drillParamsService;
|
||||
|
||||
public DrillParamsController(IDrillParamsService drillParamsService)
|
||||
{
|
||||
this.drillParamsService = drillParamsService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Возвращает автоматически расчитанные значения для режимов бурения
|
||||
/// </summary>
|
||||
/// <param name="idWell"> id скважины </param>
|
||||
/// <param name="startDepth"> Стартовая глубина </param>
|
||||
/// <param name="endDepth"> Конечная глубина </param>
|
||||
/// <param name="token"> Токен отмены задачи </param>
|
||||
/// <returns> Значения по умолчанию для режимов бурения </returns>
|
||||
[HttpGet("idWell/autoParams")]
|
||||
[ProducesResponseType(typeof(DrillParamsDto), (int) System.Net.HttpStatusCode.OK)]
|
||||
public async Task<IActionResult> GetDefaultDrillParamsAsync(int idWell, double startDepth,
|
||||
double endDepth, CancellationToken token = default)
|
||||
{
|
||||
var idCompany = User.GetCompanyId();
|
||||
|
||||
if (idCompany is null)
|
||||
return Forbid();
|
||||
|
||||
var dto = await drillParamsService.GetDefaultDrillParamsAsync(idWell, startDepth, endDepth, 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>
|
||||
/// <param name="token"> Токен отмены задачи </param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("idWell")]
|
||||
[ProducesResponseType(typeof(int), (int) System.Net.HttpStatusCode.OK)]
|
||||
public async Task<IActionResult> SaveDrillParamsAsync(int idWell,
|
||||
DrillParamsDto drillParamsDto, CancellationToken token = default)
|
||||
{
|
||||
var idCompany = User.GetCompanyId();
|
||||
|
||||
if (idCompany is null)
|
||||
return Forbid();
|
||||
|
||||
var result = await drillParamsService.SaveDrillParamsAsync(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();
|
||||
//
|
||||
// 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>
|
||||
// [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);
|
||||
// }
|
||||
}
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using AsbCloudApp.Services;
|
||||
|
||||
namespace AsbCloudWebApi.Controllers
|
||||
{
|
||||
[Route("/mode")]
|
||||
[ApiController]
|
||||
public class DrillingParamsController : ControllerBase
|
||||
{
|
||||
private readonly IDrillingParamsService modeService;
|
||||
|
||||
public DrillingParamsController(IDrillingParamsService modeService)
|
||||
{
|
||||
this.modeService = modeService;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user