diff --git a/AsbCloudApp/Data/WellOperationsDto.cs b/AsbCloudApp/Data/WellOperationsDto.cs
new file mode 100644
index 00000000..75fc1026
--- /dev/null
+++ b/AsbCloudApp/Data/WellOperationsDto.cs
@@ -0,0 +1,78 @@
+namespace AsbCloudApp.Data
+{
+ public class WellOperationsDto : IId
+ {
+ public int Id { get; set; }
+
+
+ ///
+ /// Глубина план, м
+ ///
+ public double WellDepthPlan { get; set; }
+
+ ///
+ /// Глубина факт, м
+ ///
+ public double WellDepthFact { get; set; }
+
+ ///
+ /// Период план, д
+ ///
+ public double DurationPlan { get; set; }
+
+ ///
+ /// Период факт, д
+ ///
+ public double DurationFact { get; set; }
+
+ ///
+ /// Механическая скорость проходки план, м/час
+ ///
+ public double MechSpeedPlan { get; set; }
+
+ ///
+ /// Механическая скорость проходки факт, м/час
+ ///
+ public double MechSpeedFact { get; set; }
+
+ ///
+ /// Рейсовая скорость план, м/час
+ ///
+ public double RouteSpeedPlan { get; set; }
+
+ ///
+ /// Рейсовая скорость план, м/час
+ ///
+ public double RouteSpeedFact { get; set; }
+
+ ///
+ /// Скорость подъема КНБК план
+ ///
+ public double BhaUpSpeedPlan { get; set; }
+
+ ///
+ /// Скорость подъема КНБК факт
+ ///
+ public double BhaUpSpeedFact { get; set; }
+
+ ///
+ /// Скорость спуска КНБК план
+ ///
+ public double BhaDownSpeedPlan { get; set; }
+
+ ///
+ /// Скорость спуска КНБК факт
+ ///
+ public double BhaDownSpeedFact { get; set; }
+
+ ///
+ /// Скорость спуска обсадной колонны план
+ ///
+ public double CasingDownSpeedPlan { get; set; }
+
+ ///
+ /// Скорость спуска обсадной колонны факт
+ ///
+ public double CasingDownSpeedFact { get; set; }
+ }
+}
diff --git a/AsbCloudApp/Services/IWellSectionService.cs b/AsbCloudApp/Services/IWellSectionService.cs
index 1deb15ba..fa22c6bb 100644
--- a/AsbCloudApp/Services/IWellSectionService.cs
+++ b/AsbCloudApp/Services/IWellSectionService.cs
@@ -1,5 +1,4 @@
using AsbCloudApp.Data;
-using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
@@ -8,7 +7,10 @@ namespace AsbCloudApp.Services
public interface IWellSectionService
{
Task GetTypesAsync(CancellationToken token);
- Task> GetSectionsByWellIdAsync(int idWell, int skip = 0, int take = 32, CancellationToken token = default);
+ Task> GetAggregatedWellByWellIdAsync(int idWell,
+ int skip, int take, CancellationToken token);
+ Task> GetSectionsByWellIdAsync(int idWell, int skip = 0, int take = 32,
+ CancellationToken token = default);
Task GetSectionByWellIdAsync(int id, CancellationToken token = default);
//Task InsertAsync(WellSectionDto newItem, int idWell, CancellationToken token = default);
//Task> InsertRangeAsync(int idWell, IEnumerable newItems, CancellationToken token = default);
diff --git a/AsbCloudInfrastructure/Services/WellSectionService.cs b/AsbCloudInfrastructure/Services/WellSectionService.cs
index 74b6d7b5..bdb4c577 100644
--- a/AsbCloudInfrastructure/Services/WellSectionService.cs
+++ b/AsbCloudInfrastructure/Services/WellSectionService.cs
@@ -26,6 +26,61 @@ namespace AsbCloudInfrastructure.Services
public Task GetTypesAsync(CancellationToken token) =>
db.WellSectionTypes.Select(e => e.Caption).Distinct().AsNoTracking().ToArrayAsync(token);
+ public async Task> 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(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> GetSectionsByWellIdAsync(int idWell,
int skip, int take, CancellationToken token = default)
{
@@ -34,22 +89,13 @@ namespace AsbCloudInfrastructure.Services
select w)
.Include(w => w.WellSectionType)
.ToListAsync(token)
- .ConfigureAwait(false);
+ .ConfigureAwait(false);
var wellOperationsGroupedBySections = wellOperations
.GroupBy(op => op.IdWellSectionType).ToList();
- if (skip > 0)
- wellOperationsGroupedBySections = wellOperationsGroupedBySections.Skip(skip).ToList();
-
- wellOperationsGroupedBySections = wellOperationsGroupedBySections.Take(take).ToList();
-
- var result = new PaginationContainer
- {
- Skip = skip,
- Take = take,
- Count = wellOperationsGroupedBySections.Count
- };
+ var result = PaginateData(wellOperationsGroupedBySections,
+ skip, take);
if (!wellOperationsGroupedBySections.Any())
return result;
@@ -180,6 +226,24 @@ namespace AsbCloudInfrastructure.Services
// return context.SaveChangesAsync(token);
//}
+ private static PaginationContainer PaginateData(IEnumerable> groupedCollection,
+ int skip, int take)
+ {
+ if (skip > 0)
+ groupedCollection = groupedCollection.Skip(skip).ToList();
+
+ groupedCollection = groupedCollection.Take(take).ToList();
+
+ var result = new PaginationContainer
+ {
+ Skip = skip,
+ Take = take,
+ Count = groupedCollection.Count()
+ };
+
+ return result;
+ }
+
private static IEnumerable<(double DepthPlan, double DepthFact)> GetWellDepthPlanFact(
IEnumerable> groupedOperations)
{
diff --git a/AsbCloudWebApi/Controllers/WellSectionController.cs b/AsbCloudWebApi/Controllers/WellSectionController.cs
index 227b9c3e..c38ca2c8 100644
--- a/AsbCloudWebApi/Controllers/WellSectionController.cs
+++ b/AsbCloudWebApi/Controllers/WellSectionController.cs
@@ -34,14 +34,30 @@ namespace AsbCloudWebApi.Controllers
}
[HttpGet]
+ [Route("aggregated")]
+ [ProducesResponseType(typeof(PaginationContainer), (int)System.Net.HttpStatusCode.OK)]
+ public async Task 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), (int)System.Net.HttpStatusCode.OK)]
- public async Task GetAllAsync(int idWell, int skip = 0, int take = 32,
+ public async Task GetSectionsByWellIdAsync(int idWell, int skip = 0, int take = 32,
CancellationToken token = default)
{
if(!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
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);
}