forked from ddrilling/AsbCloudServer
CS2-65: Added operations calculation for whole well
This commit is contained in:
parent
9d50f0d1c9
commit
fbff8e986a
78
AsbCloudApp/Data/WellOperationsDto.cs
Normal file
78
AsbCloudApp/Data/WellOperationsDto.cs
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
namespace AsbCloudApp.Data
|
||||||
|
{
|
||||||
|
public class WellOperationsDto : IId
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Глубина план, м
|
||||||
|
/// </summary>
|
||||||
|
public double WellDepthPlan { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Глубина факт, м
|
||||||
|
/// </summary>
|
||||||
|
public double WellDepthFact { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Период план, д
|
||||||
|
/// </summary>
|
||||||
|
public double DurationPlan { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Период факт, д
|
||||||
|
/// </summary>
|
||||||
|
public double DurationFact { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Механическая скорость проходки план, м/час
|
||||||
|
/// </summary>
|
||||||
|
public double MechSpeedPlan { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Механическая скорость проходки факт, м/час
|
||||||
|
/// </summary>
|
||||||
|
public double MechSpeedFact { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Рейсовая скорость план, м/час
|
||||||
|
/// </summary>
|
||||||
|
public double RouteSpeedPlan { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Рейсовая скорость план, м/час
|
||||||
|
/// </summary>
|
||||||
|
public double RouteSpeedFact { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Скорость подъема КНБК план
|
||||||
|
/// </summary>
|
||||||
|
public double BhaUpSpeedPlan { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Скорость подъема КНБК факт
|
||||||
|
/// </summary>
|
||||||
|
public double BhaUpSpeedFact { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Скорость спуска КНБК план
|
||||||
|
/// </summary>
|
||||||
|
public double BhaDownSpeedPlan { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Скорость спуска КНБК факт
|
||||||
|
/// </summary>
|
||||||
|
public double BhaDownSpeedFact { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Скорость спуска обсадной колонны план
|
||||||
|
/// </summary>
|
||||||
|
public double CasingDownSpeedPlan { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Скорость спуска обсадной колонны факт
|
||||||
|
/// </summary>
|
||||||
|
public double CasingDownSpeedFact { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,4 @@
|
|||||||
using AsbCloudApp.Data;
|
using AsbCloudApp.Data;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@ -8,7 +7,10 @@ namespace AsbCloudApp.Services
|
|||||||
public interface IWellSectionService
|
public interface IWellSectionService
|
||||||
{
|
{
|
||||||
Task<string[]> GetTypesAsync(CancellationToken token);
|
Task<string[]> GetTypesAsync(CancellationToken token);
|
||||||
Task<PaginationContainer<WellSectionDto>> GetSectionsByWellIdAsync(int idWell, int skip = 0, int take = 32, CancellationToken token = default);
|
Task<PaginationContainer<WellOperationsDto>> GetAggregatedWellByWellIdAsync(int idWell,
|
||||||
|
int skip, int take, CancellationToken token);
|
||||||
|
Task<PaginationContainer<WellSectionDto>> GetSectionsByWellIdAsync(int idWell, int skip = 0, int take = 32,
|
||||||
|
CancellationToken token = default);
|
||||||
Task<WellSectionDto> GetSectionByWellIdAsync(int id, CancellationToken token = default);
|
Task<WellSectionDto> GetSectionByWellIdAsync(int id, CancellationToken token = default);
|
||||||
//Task<WellSectionDto> InsertAsync(WellSectionDto newItem, int idWell, CancellationToken token = default);
|
//Task<WellSectionDto> InsertAsync(WellSectionDto newItem, int idWell, CancellationToken token = default);
|
||||||
//Task<IEnumerable<WellSectionDto>> InsertRangeAsync(int idWell, IEnumerable<WellSectionDto> newItems, CancellationToken token = default);
|
//Task<IEnumerable<WellSectionDto>> InsertRangeAsync(int idWell, IEnumerable<WellSectionDto> newItems, CancellationToken token = default);
|
||||||
|
@ -26,6 +26,61 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
public Task<string[]> GetTypesAsync(CancellationToken token) =>
|
public Task<string[]> GetTypesAsync(CancellationToken token) =>
|
||||||
db.WellSectionTypes.Select(e => e.Caption).Distinct().AsNoTracking().ToArrayAsync(token);
|
db.WellSectionTypes.Select(e => e.Caption).Distinct().AsNoTracking().ToArrayAsync(token);
|
||||||
|
|
||||||
|
public async Task<PaginationContainer<WellOperationsDto>> GetAggregatedWellByWellIdAsync(int idWell,
|
||||||
|
int skip, int take, CancellationToken token)
|
||||||
|
{
|
||||||
|
var wellOperations = await (from w in db.WellOperations
|
||||||
|
where w.IdWell == idWell
|
||||||
|
select w)
|
||||||
|
.ToListAsync(token)
|
||||||
|
.ConfigureAwait(false);
|
||||||
|
|
||||||
|
var wellOperationsGroupedByIdWell = wellOperations
|
||||||
|
.GroupBy(op => op.IdWell).ToList();
|
||||||
|
|
||||||
|
var result = PaginateData<WellOperationsDto, WellOperation>(wellOperationsGroupedByIdWell,
|
||||||
|
skip, take);
|
||||||
|
|
||||||
|
if (!wellOperationsGroupedByIdWell.Any())
|
||||||
|
return result;
|
||||||
|
|
||||||
|
var depthsPlanFactList = GetWellDepthPlanFact(wellOperationsGroupedByIdWell).ToList();
|
||||||
|
|
||||||
|
var durationsPlanFactList = GetWellDurationPlanFact(wellOperationsGroupedByIdWell).ToList();
|
||||||
|
|
||||||
|
var mechSpeedsList = GetWellMechSpeedPlanFact(wellOperationsGroupedByIdWell).ToList();
|
||||||
|
|
||||||
|
var bhaUpSpeedList = GetWellBhaUpSpeedPlanFact(wellOperationsGroupedByIdWell).ToList();
|
||||||
|
|
||||||
|
var bhaDownSpeedList = GetWellBhaDownSpeedPlanFact(wellOperationsGroupedByIdWell).ToList();
|
||||||
|
|
||||||
|
var casingDownList = GetWellCasingDownPlanFact(wellOperationsGroupedByIdWell).ToList();
|
||||||
|
|
||||||
|
var routeSpeeds = GetWellRouteSpeedsPlanFact(wellOperationsGroupedByIdWell).ToList();
|
||||||
|
|
||||||
|
var dto = new WellOperationsDto
|
||||||
|
{
|
||||||
|
WellDepthPlan = depthsPlanFactList[0].DepthPlan,
|
||||||
|
WellDepthFact = depthsPlanFactList[0].DepthFact,
|
||||||
|
DurationPlan = durationsPlanFactList[0].DurationPlan,
|
||||||
|
DurationFact = durationsPlanFactList[0].DurationFact,
|
||||||
|
MechSpeedPlan = mechSpeedsList[0].MechSpeedPlan,
|
||||||
|
MechSpeedFact = mechSpeedsList[0].MechSpeedFact,
|
||||||
|
BhaUpSpeedPlan = bhaUpSpeedList[0].BhaUpSpeedPlan,
|
||||||
|
BhaUpSpeedFact = bhaUpSpeedList[0].BhaUpSpeedFact,
|
||||||
|
BhaDownSpeedPlan = bhaDownSpeedList[0].BhaDownSpeedPlan,
|
||||||
|
BhaDownSpeedFact = bhaDownSpeedList[0].BhaDownSpeedFact,
|
||||||
|
CasingDownSpeedPlan = casingDownList[0].CasingDownSpeedPlan,
|
||||||
|
CasingDownSpeedFact = casingDownList[0].CasingDownSpeedFact,
|
||||||
|
RouteSpeedPlan = routeSpeeds[0].RouteSpeedPlan,
|
||||||
|
RouteSpeedFact = routeSpeeds[0].RouteSpeedFact
|
||||||
|
};
|
||||||
|
|
||||||
|
result.Items.Add(dto);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<PaginationContainer<WellSectionDto>> GetSectionsByWellIdAsync(int idWell,
|
public async Task<PaginationContainer<WellSectionDto>> GetSectionsByWellIdAsync(int idWell,
|
||||||
int skip, int take, CancellationToken token = default)
|
int skip, int take, CancellationToken token = default)
|
||||||
{
|
{
|
||||||
@ -39,17 +94,8 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
var wellOperationsGroupedBySections = wellOperations
|
var wellOperationsGroupedBySections = wellOperations
|
||||||
.GroupBy(op => op.IdWellSectionType).ToList();
|
.GroupBy(op => op.IdWellSectionType).ToList();
|
||||||
|
|
||||||
if (skip > 0)
|
var result = PaginateData<WellSectionDto, WellOperation>(wellOperationsGroupedBySections,
|
||||||
wellOperationsGroupedBySections = wellOperationsGroupedBySections.Skip(skip).ToList();
|
skip, take);
|
||||||
|
|
||||||
wellOperationsGroupedBySections = wellOperationsGroupedBySections.Take(take).ToList();
|
|
||||||
|
|
||||||
var result = new PaginationContainer<WellSectionDto>
|
|
||||||
{
|
|
||||||
Skip = skip,
|
|
||||||
Take = take,
|
|
||||||
Count = wellOperationsGroupedBySections.Count
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!wellOperationsGroupedBySections.Any())
|
if (!wellOperationsGroupedBySections.Any())
|
||||||
return result;
|
return result;
|
||||||
@ -180,6 +226,24 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
// return context.SaveChangesAsync(token);
|
// return context.SaveChangesAsync(token);
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
private static PaginationContainer<Tdto> PaginateData<Tdto, TEntity>(IEnumerable<IGrouping<int, TEntity>> groupedCollection,
|
||||||
|
int skip, int take)
|
||||||
|
{
|
||||||
|
if (skip > 0)
|
||||||
|
groupedCollection = groupedCollection.Skip(skip).ToList();
|
||||||
|
|
||||||
|
groupedCollection = groupedCollection.Take(take).ToList();
|
||||||
|
|
||||||
|
var result = new PaginationContainer<Tdto>
|
||||||
|
{
|
||||||
|
Skip = skip,
|
||||||
|
Take = take,
|
||||||
|
Count = groupedCollection.Count()
|
||||||
|
};
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
private static IEnumerable<(double DepthPlan, double DepthFact)> GetWellDepthPlanFact(
|
private static IEnumerable<(double DepthPlan, double DepthFact)> GetWellDepthPlanFact(
|
||||||
IEnumerable<IGrouping<int, WellOperation>> groupedOperations)
|
IEnumerable<IGrouping<int, WellOperation>> groupedOperations)
|
||||||
{
|
{
|
||||||
|
@ -34,14 +34,30 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
|
[Route("aggregated")]
|
||||||
|
[ProducesResponseType(typeof(PaginationContainer<WellOperationsDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||||
|
public async Task<IActionResult> GetAggregatedWellByWellIdAsync(int idWell, int skip = 0, int take = 32,
|
||||||
|
CancellationToken token = default)
|
||||||
|
{
|
||||||
|
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
||||||
|
return Forbid();
|
||||||
|
|
||||||
|
var result = await sectionsService.GetAggregatedWellByWellIdAsync(idWell, skip, take, token)
|
||||||
|
.ConfigureAwait(false);
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
[Route("divided")]
|
||||||
[ProducesResponseType(typeof(PaginationContainer<WellSectionDto>), (int)System.Net.HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(PaginationContainer<WellSectionDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||||
public async Task<IActionResult> GetAllAsync(int idWell, int skip = 0, int take = 32,
|
public async Task<IActionResult> GetSectionsByWellIdAsync(int idWell, int skip = 0, int take = 32,
|
||||||
CancellationToken token = default)
|
CancellationToken token = default)
|
||||||
{
|
{
|
||||||
if(!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
if(!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
||||||
return Forbid();
|
return Forbid();
|
||||||
|
|
||||||
var result = await sectionsService.GetSectionsByWellIdAsync(idWell, skip, take, token).ConfigureAwait(false);
|
var result = await sectionsService.GetSectionsByWellIdAsync(idWell, skip, take, token)
|
||||||
|
.ConfigureAwait(false);
|
||||||
return Ok(result);
|
return Ok(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user