diff --git a/AsbCloudInfrastructure/Services/DrillParamsService.cs b/AsbCloudInfrastructure/Services/DrillParamsService.cs index c2df1214..c120be59 100644 --- a/AsbCloudInfrastructure/Services/DrillParamsService.cs +++ b/AsbCloudInfrastructure/Services/DrillParamsService.cs @@ -30,93 +30,40 @@ namespace AsbCloudInfrastructure.Services if (idTelemetry is null) return null; - var axialLoads = await GetTelemetryGroupQuery(idWell, startDepth, endDepth) - .Select(g => new - { - Min = g.Min(t=> t.AxialLoad), - Avg = g.Average(t => t.AxialLoad), - Max = g.Max(t => t.AxialLoad) - }) - .AsNoTracking() - .DefaultIfEmpty() - .OrderBy(t => t.Min) - .FirstOrDefaultAsync(token) - .ConfigureAwait(false); - - var pressures = await GetTelemetryGroupQuery(idWell, startDepth, endDepth) - .Select(g => new - { - Min = g.Min(t=> t.Pressure), - Avg = g.Average(t => t.Pressure), - Max = g.Max(t => t.Pressure) - }) - .AsNoTracking() - .DefaultIfEmpty() - .OrderBy(t => t.Min) - .FirstOrDefaultAsync(token) - .ConfigureAwait(false); - - var rotorTorques = await GetTelemetryGroupQuery(idWell, startDepth, endDepth) - .Select(g => new - { - Min = g.Min(t=> t.RotorTorque), - Avg = g.Average(t => t.RotorTorque), - Max = g.Max(t => t.RotorTorque) - }) - .AsNoTracking() - .DefaultIfEmpty() - .OrderBy(t => t.Min) - .FirstOrDefaultAsync(token) - .ConfigureAwait(false); - - var rotorSpeeds = await GetTelemetryGroupQuery(idWell, startDepth, endDepth) - .Select(g => new - { - Min = g.Min(t=> t.RotorSpeed), - Avg = g.Average(t => t.RotorSpeed), - Max = g.Max(t => t.RotorSpeed) - }) - .AsNoTracking() - .DefaultIfEmpty() - .OrderBy(t => t.Min) - .FirstOrDefaultAsync(token) - .ConfigureAwait(false); - - var flows = await GetTelemetryGroupQuery(idWell, startDepth, endDepth) - .Select(g => new + var drillParamsDto = 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 DrillParamsDto() { - Min = g.Min(t=> t.Flow), - Avg = g.Average(t => t.Flow), - Max = g.Max(t => t.Flow) + IdWell = idWell, + DepthStart = startDepth, + DepthEnd = endDepth, + IdWellSectionType = 0, + AxialLoadMin = g.Min(t=> t.AxialLoad) ?? double.NaN, + AxialLoadAvg = g.Average(t => t.AxialLoad) ?? double.NaN, + AxialLoadMax = g.Max(t => t.AxialLoad) ?? double.NaN, + PressureMin = g.Min(t=> t.Pressure) ?? double.NaN, + PressureAvg = g.Average(t => t.Pressure) ?? double.NaN, + PressureMax = g.Max(t => t.Pressure) ?? double.NaN, + RotorTorqueMin = g.Min(t=> t.RotorTorque) ?? double.NaN, + RotorTorqueAvg = g.Average(t => t.RotorTorque) ?? double.NaN, + RotorTorqueMax = g.Max(t => t.RotorTorque) ?? double.NaN, + RotorSpeedMin = g.Min(t=> t.RotorSpeed) ?? double.NaN, + RotorSpeedAvg = g.Average(t => t.RotorSpeed) ?? double.NaN, + RotorSpeedMax = g.Max(t => t.RotorSpeed) ?? double.NaN, + FlowMin = g.Min(t => t.Flow) ?? double.NaN, + FlowAvg = g.Min(t => t.Flow) ?? double.NaN, + FlowMax = g.Min(t => t.Flow) ?? double.NaN }) .AsNoTracking() .DefaultIfEmpty() - .OrderBy(t => t.Min) + .OrderBy(t => t.AxialLoadMin) .FirstOrDefaultAsync(token) .ConfigureAwait(false); - return new DrillParamsDto() - { - IdWell = idWell, - DepthStart = startDepth, - DepthEnd = endDepth, - IdWellSectionType = 0, - AxialLoadMin = axialLoads.Min ?? 0, - AxialLoadAvg = axialLoads.Avg ?? 0, - AxialLoadMax = axialLoads.Max ?? 0, - PressureMin = pressures.Min ?? 0, - PressureAvg = pressures.Avg ?? 0, - PressureMax = pressures.Max ?? 0, - RotorTorqueMin = rotorTorques.Min ?? 0, - RotorTorqueAvg = rotorTorques.Avg ?? 0, - RotorTorqueMax = rotorTorques.Max ?? 0, - RotorSpeedMin = rotorSpeeds.Min ?? 0, - RotorSpeedAvg = rotorSpeeds.Avg ?? 0, - RotorSpeedMax = rotorSpeeds.Max ?? 0, - FlowMin = flows.Min ?? 0, - FlowAvg = flows.Avg ?? 0, - FlowMax = flows.Max ?? 0, - }; + return drillParamsDto; } public async Task> GetAllAsync(int idWell, @@ -126,11 +73,11 @@ namespace AsbCloudInfrastructure.Services where p.IdWell == idWell orderby p.Id select p) + .AsNoTracking() .ToListAsync(token) .ConfigureAwait(false); - var dto = entities.Select(entity => - entity.Adapt()); + var dto = entities.Adapt(); return dto; } @@ -144,10 +91,11 @@ namespace AsbCloudInfrastructure.Services p.IdWell == c.IdWellSrc && p.IdWellSectionType == c.IdWellSectionType select p) + .AsNoTracking() .ToListAsync(token) .ConfigureAwait(false); - var compositeDrillParamsDtos = compositeWellDrillParams.Select(c => c.Adapt()); + var compositeDrillParamsDtos = compositeWellDrillParams.Adapt(); return compositeDrillParamsDtos; } @@ -157,7 +105,7 @@ namespace AsbCloudInfrastructure.Services { dto.IdWell = idWell; - var result = await base.InsertAsync(dto, token); + var result = await base.InsertAsync(dto, token).ConfigureAwait(false); return result; } @@ -168,28 +116,18 @@ namespace AsbCloudInfrastructure.Services foreach (var dto in dtos) dto.IdWell = idWell; - var result = await base.InsertRangeAsync(dtos, token); + var result = await base.InsertRangeAsync(dtos, token).ConfigureAwait(false); return result; } - public override async Task UpdateAsync(int idWell, DrillParamsDto dto, + public async Task UpdateAsync(int idWell, int dtoId, DrillParamsDto dto, CancellationToken token = default) { dto.IdWell = idWell; - var result = await base.UpdateAsync(dto.Id, dto, token); + var result = await base.UpdateAsync(dtoId, dto, token).ConfigureAwait(false); return result; } - - private IQueryable> GetTelemetryGroupQuery(int idTelemetry, - double startDepth, double endDepth) - { - return from telemetry in db.TelemetryDataSaub - where telemetry.IdTelemetry == idTelemetry && - telemetry.WellDepth >= startDepth && - telemetry.WellDepth <= endDepth - group telemetry by telemetry.IdTelemetry; - } } } diff --git a/AsbCloudWebApi/Controllers/DrillParamsController.cs b/AsbCloudWebApi/Controllers/DrillParamsController.cs index 6b0d9009..dcf0b776 100644 --- a/AsbCloudWebApi/Controllers/DrillParamsController.cs +++ b/AsbCloudWebApi/Controllers/DrillParamsController.cs @@ -122,12 +122,13 @@ namespace AsbCloudWebApi.Controllers /// Изменяет значения выбранного режима бурения /// /// id скважины + /// id dto для изменения /// Параметры режимов бурений для секции /// Токен отмены задачи /// [HttpPut] [ProducesResponseType(typeof(int), (int) System.Net.HttpStatusCode.OK)] - public async Task EditAsync(int idWell, + public async Task UpdateAsync(int idWell, int dtoId, DrillParamsDto drillParamsDto, CancellationToken token = default) { var idCompany = User.GetCompanyId(); @@ -136,7 +137,7 @@ namespace AsbCloudWebApi.Controllers idWell, token).ConfigureAwait(false)) return Forbid(); - var result = await drillParamsService.UpdateAsync(idWell, + var result = await drillParamsService.UpdateAsync(idWell, dtoId, drillParamsDto, token); return Ok(result);