remove efModel wellSection. Cleanup. Split categories lastData and files

This commit is contained in:
Фролов 2021-08-24 10:59:10 +05:00
parent a2cb8071c8
commit 99d242101e
36 changed files with 518 additions and 361 deletions

View File

@ -9,7 +9,6 @@ namespace AsbCloudApp.Services
{
Task<IEnumerable<WellSectionDto>> GetSectionsByWellIdAsync(int idWell,
CancellationToken token = default);
Task<WellSectionDto> GetSectionByWellIdAsync(int id,
CancellationToken token = default);
}
}

View File

@ -29,7 +29,6 @@ namespace AsbCloudDb.Model
public virtual DbSet<TelemetryUser> TelemetryUsers { get; set; }
public virtual DbSet<WellOperationCategory> TelemetryOperations { get; set; }
public virtual DbSet<TelemetryAnalysis> TelemetryAnalysis { get; set; }
public virtual DbSet<WellSection> WellSections { get; set; }
public virtual DbSet<WellSectionType> WellSectionTypes { get; set; }
public virtual DbSet<WellOperation> WellOperations { get; set; }
public virtual DbSet<WellType> WellTypes { get; set; }
@ -141,12 +140,6 @@ namespace AsbCloudDb.Model
.HasConstraintName("t_well_t_telemetry_id_fk");
});
modelBuilder.Entity<WellSection>(entity =>
{
entity.HasIndex(e => e.WellDepthPlan)
.HasDatabaseName("IX_t_well_section_well_depth_plan");
});
modelBuilder.Entity<RelationCompanyWell>(entity =>
{

View File

@ -25,7 +25,6 @@ namespace AsbCloudDb.Model
DbSet<WellOperationCategory> TelemetryOperations { get; set; }
DbSet<TelemetryAnalysis> TelemetryAnalysis { get; set; }
DbSet<Well> Wells { get; set; }
DbSet<WellSection> WellSections { get; set; }
DbSet<WellSectionType> WellSectionTypes { get; set; }
DbSet<WellOperation> WellOperations { get; set; }
DbSet<WellType> WellTypes { get; set; }

View File

@ -27,6 +27,6 @@ namespace AsbCloudDb.Model
[JsonIgnore]
[ForeignKey(nameof(IdCategory))]
public virtual FileCategory FileCategory { get; set; }
public virtual LastDataCategory LastDataCategory { get; set; }
}
}

View File

@ -0,0 +1,20 @@
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace AsbCloudDb.Model
{
[Table("t_last_data_category"), Comment("Категория последних данных")]
public class LastDataCategory : IId
{
[Key]
[Column("id")]
public int Id { get; set; }
[Column("name"), Comment("Название категории")]
public string Name { get; set; }
[Column("short_name"), Comment("Короткое название категории")]
public string ShortName { get; set; }
}
}

View File

@ -35,40 +35,10 @@ namespace AsbCloudDb.Model
[Column("longitude")]
public double? Longitude { get; set; }
[Column("plan_start", TypeName = "timestamp with time zone")]
public DateTime? PlanStart { get; set; }
[Column("plan_end", TypeName = "timestamp with time zone")]
public DateTime? PlanEnd { get; set; }
[Column("fact_start", TypeName = "timestamp with time zone")]
public DateTime? FactStart { get; set; }
[Column("fact_end", TypeName = "timestamp with time zone")]
public DateTime? FactEnd { get; set; }
[Column("un_productive_time_days"), Comment("НПВ, сут")]
public double? UnProductiveDays { get; set; }
[Column("rate_of_penetration_plan"), Comment("МСП план")]
public double? RateOfPenetrationPlan { get; set; }
[Column("rate_of_penetration_fact"), Comment("МСП факт")]
public double? RateOfPenetrationFact { get; set; }
[Column("route_speed_plan"), Comment("Рейсовая скорость план")]
public double? RouteSpeedPlan { get; set; }
[Column("route_speed_fact"), Comment("Рейсовая скорость факт")]
public double? RouteSpeedFact { get; set; }
[ForeignKey(nameof(IdWellType))]
[InverseProperty(nameof(Model.WellType.Wells))]
public virtual WellType WellType { get; set; }
[InverseProperty(nameof(WellSection.Well))]
public virtual ICollection<WellSection> Sections { get; set; }
[InverseProperty(nameof(RelationCompanyWell.Well))]
public virtual ICollection<RelationCompanyWell> RelationCompaniesWells { get; set; }

View File

@ -1,75 +0,0 @@
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text.Json.Serialization;
#nullable disable
namespace AsbCloudDb.Model
{
[Table("t_well_section"), Comment("секция скважины")]
public class WellSection: IId, IIdWell
{
[Key]
[Column("id")]
public int Id { get; set; }
[Column("id_well_section_type")]
public int IdWellSectionType { get; set; }
[Column("id_well")]
public int IdWell { get; set; }
[Column("well_depth_plan"), Comment("глубина план, м")]
public double WellDepthPlan { get; set; }
[Column("well_depth_fact"), Comment("глубина факт, м")]
public double WellDepthFact { get; set; }
[Column("build_days_plan"), Comment("период план, д")]
public double BuildDaysPlan { get; set; }
[Column("build_days_fact"), Comment("период факт, д")]
public double BuildDaysFact { get; set; }
[Column("rate_of_penetration_plan"), Comment("Механическая скорость проходки план, м/час")]
public double RateOfPenetrationPlan { get; set; }
[Column("rate_of_penetration_fact"), Comment("Механическая скорость проходки факт, м/час")]
public double RateOfPenetrationFact { get; set; }
[Column("route_speed_plan"), Comment("Рейсовая скорость план, м/час")]
public double RouteSpeedPlan { get; set; }
[Column("route_speed_fact"), Comment("Рейсовая скорость факт, м/час")]
public double RouteSpeedFact { get; set; }
[Column("bha_down_speed_plan"), Comment("Скорость спуска КНБК план")]
public double BhaDownSpeedPlan { get; set; }
[Column("bha_down_speed_fact"), Comment("Скорость спуска КНБК факт")]
public double BhaDownSpeedFact { get; set; }
[Column("bha_up_speed_plan"), Comment("Скорость подъема КНБК план")]
public double BhaUpSpeedPlan { get; set; }
[Column("bha_up_speed_fact"), Comment("Скорость подъема КНБК факт")]
public double BhaUpSpeedFact { get; set; }
[Column("casing_down_speed_plan"), Comment("Скорость спуска обсадной колонны план")]
public double CasingDownSpeedPlan { get; set; }
[Column("casing_down_speed_fact"), Comment("Скорость спуска обсадной колонны факт")]
public double CasingDownSpeedFact { get; set; }
[JsonIgnore]
[ForeignKey(nameof(IdWell))]
[InverseProperty(nameof(Model.Well.Sections))]
public virtual Well Well { get; set; }
[JsonIgnore]
[ForeignKey(nameof(IdWellSectionType))]
[InverseProperty(nameof(Model.WellSectionType.WellSections))]
public virtual WellSectionType WellSectionType { get; set; }
}
}

View File

@ -18,10 +18,6 @@ namespace AsbCloudDb.Model
[StringLength(255)]
public string Caption { get; set; }
[JsonIgnore]
[InverseProperty(nameof(WellSection.WellSectionType))]
public virtual ICollection<WellSection> WellSections { get; set; }
[JsonIgnore]
[InverseProperty(nameof(WellOperation.WellSectionType))]
public virtual ICollection<WellOperation> WellOperations { get; set; }

View File

@ -0,0 +1,55 @@
using System;
namespace AsbCloudInfrastructure
{
public static class Helper
{
public static T Max<T>(params T[] items)
where T : IComparable
{
var count = items.Length;
if (count < 1)
throw new ArgumentException("Count of params must be greater than 1");
var max = items[0];
for (var i = 1; i < count; i++)
if (max.CompareTo(items[i]) > 0)
max = items[i];
return max;
}
public static T Min<T>(params T[] items)
where T : IComparable
{
var count = items.Length;
if (count < 1)
throw new ArgumentException("Count of params must be greater than 1");
var min = items[0];
for (var i = 1; i < count; i++)
if (min.CompareTo(items[i]) < 0)
min = items[i];
return min;
}
public static (T min, T max) MinMax<T>(params T[] items)
where T : IComparable
{
var count = items.Length;
if (count < 1)
throw new ArgumentException("Count of params must be greater than 1");
var min = items[0];
var max = items[0];
for (var i = 1; i < count; i++)
if (max.CompareTo(items[i]) > 0)
max = items[i];
else if (min.CompareTo(items[i]) < 0)
min = items[i];
return (min, max);
}
}
}

View File

@ -1,6 +1,7 @@
using AsbCloudApp.Data;
using AsbCloudApp.Services;
using AsbCloudDb.Model;
using Microsoft.EntityFrameworkCore;
using Microsoft.IdentityModel.Tokens;
using System;
using System.Collections.Generic;
@ -9,7 +10,6 @@ using System.Linq;
using System.Security.Claims;
using System.Security.Cryptography;
using System.Text;
using Microsoft.EntityFrameworkCore;
using System.Threading;
using System.Threading.Tasks;

View File

@ -144,33 +144,7 @@ namespace AsbCloudInfrastructure.Services
Deposit = e.Cluster.Deposit.Caption,
Latitude = e.Latitude,
Longitude = e.Longitude,
FactEnd = e.FactEnd,
FactStart = e.FactStart,
PlanEnd = e.PlanEnd,
PlanStart = e.PlanStart,
RateOfPenetrationFact = e.RateOfPenetrationFact,
RateOfPenetrationPlan = e.RateOfPenetrationPlan,
RouteSpeedFact = e.RouteSpeedFact,
RouteSpeedPlan = e.RouteSpeedPlan,
Sections = e.Sections.Select(s => new WellSectionDto
{
BhaDownSpeedFact = s.BhaDownSpeedFact,
BhaDownSpeedPlan = s.BhaDownSpeedPlan,
BhaUpSpeedFact = s.BhaUpSpeedFact,
BhaUpSpeedPlan = s.BhaUpSpeedPlan,
DurationFact = s.BuildDaysFact,
DurationPlan = s.BuildDaysPlan,
CasingDownSpeedFact = s.CasingDownSpeedFact,
CasingDownSpeedPlan = s.CasingDownSpeedPlan,
MechSpeedFact = s.RateOfPenetrationFact,
MechSpeedPlan = s.RateOfPenetrationPlan,
RouteSpeedFact = s.RouteSpeedFact,
RouteSpeedPlan = s.RouteSpeedPlan,
SectionType = s.WellSectionType.Caption,
WellDepthFact = s.WellDepthFact,
WellDepthPlan = s.WellDepthPlan,
}),
UnProductiveDays = e.UnProductiveDays,
//TODO: Fill data from operations service
Companies = e.RelationCompaniesWells.Select(c => new CompanyDto
{
Id = c.Company.Id,

View File

@ -1,9 +1,9 @@
using AsbCloudApp.Data;
using AsbCloudApp.Services;
using AsbCloudDb.Model;
using Microsoft.EntityFrameworkCore;
using AsbCloudInfrastructure.Services.Cache;
using Mapster;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;

View File

@ -5,10 +5,10 @@ using Mapster;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.IO;
namespace AsbCloudInfrastructure.Services
{
@ -84,7 +84,8 @@ namespace AsbCloudInfrastructure.Services
var count = await query.CountAsync(token).ConfigureAwait(false);
var result = new PaginationContainer<FileInfoDto>(count) {
var result = new PaginationContainer<FileInfoDto>(count)
{
Skip = skip,
Take = take,
Count = count,

View File

@ -1,10 +1,10 @@
using AsbCloudApp.Services;
using AsbCloudDb.Model;
using Mapster;
using Microsoft.EntityFrameworkCore;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
namespace AsbCloudInfrastructure.Services
{

View File

@ -149,7 +149,7 @@ namespace AsbCloudInfrastructure.Services
DateTime begin, DateTime end, int stepSeconds, int format,
CancellationToken token = default)
{
var suitableReportsNames = await(from r in db.ReportProperties.Include(r => r.File)
var suitableReportsNames = await (from r in db.ReportProperties.Include(r => r.File)
where r.IdWell == idWell
&& r.Begin >= begin
&& r.End <= end

View File

@ -3,8 +3,6 @@ using AsbCloudApp.Services;
using AsbCloudDb.Model;
using AsbCloudInfrastructure.Services.Cache;
using Mapster;
using System.Threading;
using System.Threading.Tasks;
namespace AsbCloudInfrastructure.Services
{

View File

@ -1,14 +1,14 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using AsbCloudApp.Data;
using AsbCloudApp.Data;
using AsbCloudApp.Services;
using AsbCloudDb.Model;
using AsbCloudInfrastructure.Services.Cache;
using Mapster;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace AsbCloudInfrastructure.Services
{
@ -121,7 +121,7 @@ namespace AsbCloudInfrastructure.Services
IEnumerable<WellOperationDto> wellOperationDtos,
CancellationToken token = default)
{
foreach(var operationDto in wellOperationDtos)
foreach (var operationDto in wellOperationDtos)
{
var entity = operationDto.Adapt<WellOperation>();
entity.Id = default;

View File

@ -0,0 +1,276 @@
using AsbCloudApp.Data;
using AsbCloudDb.Model;
using AsbCloudInfrastructure.Services.Cache;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace AsbCloudInfrastructure.Services
{
class OperationParams
{
public OperationParams() { }
public OperationParams(WellOperation operation)
{
Id = operation.Id;
IdWellSectionType = operation.IdWellSectionType;
IdCategory = operation.IdCategory;
WellDepth = operation.WellDepth;
StartDate = operation.StartDate;
DurationHours = operation.DurationHours;
WellDepthReal = operation.WellDepth;
DeltaDepth = 0;
DurationToNextOperationHours = operation.DurationHours;
}
public int Id { get; }
public int IdWellSectionType { get; }
public int IdCategory { get; }
public double WellDepth { get; }
public DateTime StartDate { get; }
public double DurationHours { get; }
public double WellDepthReal { get; set; }
public double DeltaDepth { get; set; }
public double DurationToNextOperationHours { get; set; }
}
class Race
{
public DateTime StartDate { get; set; }
public double StartWellDepth { get; set; }
public DateTime EndDate { get; set; }
public double EndWellDepth { get; set; }
public double DrillingTime { get; set; }
public double NonProductiveHours { get; set; }
public double DeltaDepth => EndWellDepth - StartWellDepth;
public double DeltaHoursTimeNoNpt => (EndDate - StartDate).TotalHours - NonProductiveHours;
public double Speed => DeltaDepth / (DeltaHoursTimeNoNpt + double.Epsilon);
}
class SectionStat
{
public DateTime StartDate { get; set; }
public double StartWellDepth { get; set; }
public DateTime EndDate { get; set; }
public double EndWellDepth { get; set; }
public double AvgRaceSpeed { get; set; }
public double Rop { get; set; }
public double BhaDownSpeed { get; set; }
public double BhaUpSpeed { get; set; }
public double CasingDownSpeed { get; set; }
public int IdSectionType { get; internal set; }
public double Hours => (EndDate - StartDate).TotalHours;
}
public class WellOperationsStatService
{
private readonly IAsbCloudDbContext db;
private readonly CacheTable<WellSectionType> cachedSectionsTypes;
const int idOperationBhaAssembly = 1025;
const int idOperationBhaDisassembly = 1026;
private const int idOperationNonProductiveTime = 1043;
private const int idOperationDrilling = 1001;
private const int idOperationBhaDown = 1046;
private const int idOperationBhaUp = 1047;
private const int IdOperationCasingDown = 1048;
public WellOperationsStatService(IAsbCloudDbContext db, Cache.CacheDb cache)
{
this.db = db;
cachedSectionsTypes = cache.GetCachedTable<WellSectionType>((DbContext)db);
}
public async Task<IEnumerable<WellSectionDto>> GetSectionsByWellIdAsync(int idWell,
CancellationToken token = default)
{
var operationsAll = await db.WellOperations
.Where(o => o.IdWell == idWell)
.OrderBy(o => o.StartDate) // ускорит дальнейшие сортировки
.AsNoTracking()
.ToListAsync(token);
var operationsPlan = operationsAll
.Where(o => o.IdType == 0);
var sectionsPlan = CalcSectionsStats(operationsPlan);
var operationsFact = operationsAll
.Where(o => o.IdType == 1);
var sectionsFact = CalcSectionsStats(operationsFact);
var sectionTypesIds = operationsAll.Select(o => o.IdWellSectionType).Distinct();
var sections = new List<WellSectionDto>(sectionTypesIds.Count());
foreach (var idSectionType in sectionTypesIds)
{
var statPlan = sectionsPlan.FirstOrDefault(s => s.IdSectionType == idSectionType);
var statFact = sectionsFact.FirstOrDefault(s => s.IdSectionType == idSectionType);
WellSectionDto section = MakeWellSectionDto(idSectionType, statPlan, statFact);
sections.Add(section);
}
return sections;
}
private WellSectionDto MakeWellSectionDto(int idSectionType, SectionStat statPlan, SectionStat statFact)
{
return new WellSectionDto
{
Id = idSectionType,
SectionType = cachedSectionsTypes.FirstOrDefault(s => s.Id == idSectionType)?.Caption,
BhaDownSpeedPlan = statPlan?.BhaDownSpeed ?? double.NaN,
BhaUpSpeedPlan = statPlan?.BhaUpSpeed ?? double.NaN,
MechSpeedPlan = statPlan?.Rop ?? double.NaN,
CasingDownSpeedPlan = statPlan?.CasingDownSpeed ?? double.NaN,
RouteSpeedPlan = statPlan?.AvgRaceSpeed ?? double.NaN,
WellDepthPlan = statPlan?.EndWellDepth ?? double.NaN,
DurationPlan = statPlan?.Hours ?? double.NaN,
BhaDownSpeedFact = statFact?.BhaDownSpeed ?? double.NaN,
BhaUpSpeedFact = statFact?.BhaUpSpeed ?? double.NaN,
MechSpeedFact = statFact?.Rop ?? double.NaN,
CasingDownSpeedFact = statFact?.CasingDownSpeed ?? double.NaN,
RouteSpeedFact = statFact?.AvgRaceSpeed ?? double.NaN,
WellDepthFact = statFact?.EndWellDepth ?? double.NaN,
DurationFact = statFact?.Hours ?? double.NaN,
};
}
private static IEnumerable<SectionStat> CalcSectionsStats(IEnumerable<WellOperation> wellOperations)
{
var operations = MakeOperationsExt(wellOperations);
var sectionTypesIds = operations.Select(o => o.IdWellSectionType).Distinct();
var sectionsStats = new List<SectionStat>(sectionTypesIds.Count());
foreach (var idSection in sectionTypesIds)
{
var section = CalcSectionStat(operations, idSection);
sectionsStats.Add(section);
}
return sectionsStats;
}
private static SectionStat CalcSectionStat(IEnumerable<OperationParams> allOperations, int idSectionType)
{
var sectionOperations = allOperations
.Where(o => o.IdWellSectionType == idSectionType)
.OrderBy(o => o.StartDate)
.ThenBy(o => o.WellDepth);
var section = new SectionStat
{
IdSectionType = idSectionType,
StartDate = sectionOperations.First().StartDate,
EndDate = sectionOperations.Max(o => (o.StartDate.AddHours(o.DurationHours))),
StartWellDepth = sectionOperations.Min(o => o.WellDepthReal),
EndWellDepth = sectionOperations.Max(o => o.WellDepthReal),
AvgRaceSpeed = CalcAvgRaceSpeed(sectionOperations),
Rop = CalcROP(sectionOperations),
BhaDownSpeed = CalcSpeedByOperation(sectionOperations, idOperationBhaDown),
BhaUpSpeed = CalcSpeedByOperation(sectionOperations, idOperationBhaUp),
CasingDownSpeed = CalcSpeedByOperation(sectionOperations, IdOperationCasingDown),
};
return section;
}
private static double CalcSpeedByOperation(IEnumerable<OperationParams> operationsProps, int idOperation)
{
var ops = operationsProps.Where(o => o.IdCategory == idOperation);
var maxDepth = 0d;
var dHours = 0d;
foreach (var operation in ops)
{
if (maxDepth > operation.WellDepthReal)
maxDepth = operation.WellDepthReal;
dHours += operation.DurationHours;
}
return maxDepth / (dHours + double.Epsilon);
}
private static double CalcROP(IEnumerable<OperationParams> operationsProps)
{
var drillingOperations = operationsProps.Where(o => o.IdCategory == idOperationDrilling);
var dDepth = 0d;
var dHours = 0d;
foreach (var operation in drillingOperations)
{
dDepth += operation.DeltaDepth;
dHours += operation.DurationHours;
}
return dDepth / (dHours + double.Epsilon);
}
// Метры в час
private static double CalcAvgRaceSpeed(IEnumerable<OperationParams> operations)
{
var races = GetCompleteRaces(operations);
var dDepth = 0d;
var dHours = 0d;
foreach (var race in races)
{
dHours += race.DeltaHoursTimeNoNpt;
dDepth += race.DeltaDepth;
}
return dDepth / (dHours + double.Epsilon);
}
private static IEnumerable<OperationParams> MakeOperationsExt(IEnumerable<WellOperation> operations)
{
var count = operations.Count();
var ops = new List<OperationParams>(count);
var item = operations.ElementAt(0);
var wellDepth = item.WellDepth;
var pre = new OperationParams(item);
var current = new OperationParams(item);
for (int i = 1; i < count; i++)
{
item = operations.ElementAt(i);
current = new OperationParams(item)
{
WellDepthReal = Helper.Max(wellDepth, item.WellDepth) // TODO: учесть операциии с уменьшение глубины ствола.
};
pre.DeltaDepth = current.WellDepthReal - wellDepth;
pre.DurationToNextOperationHours = (current.StartDate - pre.StartDate).TotalHours;
ops.Add(pre);
pre = current;
}
ops.Add(current);
return ops;
}
private static IEnumerable<Race> GetCompleteRaces(IEnumerable<OperationParams> operations)
{
var races = new List<Race>(4);
var iterator = operations.GetEnumerator();
while (iterator.MoveNext())
{
if (iterator.Current.IdCategory == idOperationBhaAssembly)
{
var race = new Race
{
StartDate = iterator.Current.StartDate.AddHours(iterator.Current.DurationHours),
StartWellDepth = iterator.Current.WellDepthReal
};
while (iterator.MoveNext())
{
if (iterator.Current.IdCategory == idOperationNonProductiveTime)
{
race.NonProductiveHours += iterator.Current.DurationHours;
}
if (iterator.Current.IdCategory == idOperationBhaDisassembly)
{
race.EndDate = iterator.Current.StartDate.AddHours(iterator.Current.DurationHours);
race.EndWellDepth = iterator.Current.WellDepthReal;
races.Add(race);
}
}
}
}
return races;
}
}
}

View File

@ -1,26 +1,22 @@
using AsbCloudApp.Data;
using AsbCloudApp.Services;
using AsbCloudDb.Model;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using Mapster;
using Microsoft.EntityFrameworkCore;
using System.Threading.Tasks;
using System.Threading;
using AsbCloudInfrastructure.Services.Cache;
using System.Threading.Tasks;
namespace AsbCloudInfrastructure.Services
{
public class WellSectionService: IWellSectionService
public class WellSectionService : IWellSectionService
{
private readonly IAsbCloudDbContext db;
private readonly CacheTable<WellSectionType> cachedSectionsTypes;
public WellSectionService(IAsbCloudDbContext db, Cache.CacheDb cache)
public WellSectionService(IAsbCloudDbContext db)
{
this.db = db;
cachedSectionsTypes = cache.GetCachedTable<WellSectionType>((DbContext)db);
}
public async Task<IEnumerable<WellSectionDto>> GetSectionsByWellIdAsync(int idWell,
@ -81,7 +77,7 @@ namespace AsbCloudInfrastructure.Services
var dtos = new List<WellSectionDto>();
for(int i = 0; i < wellOperationsGroupedBySections.Count; i++)
for (int i = 0; i < wellOperationsGroupedBySections.Count; i++)
{
var dto = new WellSectionDto
{
@ -109,21 +105,6 @@ namespace AsbCloudInfrastructure.Services
return dtos.OrderBy(d => d.WellDepthPlan);
}
public async Task<WellSectionDto> GetSectionByWellIdAsync(int id, CancellationToken token = default)
{
var entity = await db.WellSections
.Include(s => s.WellSectionType)
.FirstOrDefaultAsync(e => e.Id == id, token)
.ConfigureAwait(false);
if (entity is null)
return null;
var dto = entity.Adapt<WellSectionDto>();
dto.SectionType = entity.WellSectionType.Caption;
return dto;
}
private static IEnumerable<double> GetWellDepthStats(
IEnumerable<IGrouping<int, WellOperation>> groupedOperations, int type)
{
@ -202,22 +183,5 @@ namespace AsbCloudInfrastructure.Services
);
}
private async Task<WellSectionType> GetWellSectionTypeFromCacheAndAssertAsync(string wellSectionType, CancellationToken token = default)
{
if (string.IsNullOrEmpty(wellSectionType))
throw new ArgumentException("Тип секции должен быть указан", nameof(WellSectionDto.SectionType));
var sectionType = await cachedSectionsTypes
.FirstOrDefaultAsync(s => s.Caption.Equals(wellSectionType, StringComparison.OrdinalIgnoreCase), token)
.ConfigureAwait(false);
if (sectionType is null)
{
throw new ArgumentException($"Тип секции '{wellSectionType}' отсутствует в справочнике", nameof(WellSectionDto.SectionType));
//sectionType = await cachedSectionsTypes.InsertAsync(new WellSectionType { Caption = item.SectionType}, token);
}
return sectionType;
}
}
}

View File

@ -3,12 +3,12 @@ using AsbCloudApp.Services;
using AsbCloudDb.Model;
using AsbCloudInfrastructure.Services.Cache;
using Mapster;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
namespace AsbCloudInfrastructure.Services
{

View File

@ -2,9 +2,9 @@
using AsbCloudApp.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Swashbuckle.AspNetCore.Annotations;
using System.Threading;
using System.Threading.Tasks;
using Swashbuckle.AspNetCore.Annotations;
namespace AsbCloudWebApi.Controllers
{

View File

@ -10,7 +10,7 @@ namespace AsbCloudWebApi.Controllers
[ApiController]
public abstract class CrudController<T, TService> : ControllerBase
where T : IId
where TService: ICrudService<T>
where TService : ICrudService<T>
{
protected readonly TService service;

View File

@ -4,8 +4,8 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.IO;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

View File

@ -133,7 +133,7 @@ namespace AsbCloudWebApi.Controllers
idWell, token).ConfigureAwait(false))
return Forbid();
var analytics = await analyticsService .GetOperationsSummaryAsync(idWell,
var analytics = await analyticsService.GetOperationsSummaryAsync(idWell,
begin, end, token).ConfigureAwait(false);
if (analytics is null || !analytics.Any())
@ -158,7 +158,7 @@ namespace AsbCloudWebApi.Controllers
{
int? idCompany = User.GetCompanyId();
if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync ((int)idCompany,
if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
idWell, token).ConfigureAwait(false))
return Forbid();

View File

@ -1,11 +1,11 @@
using System.Collections.Generic;
using AsbCloudApp.Data;
using AsbCloudApp.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using AsbCloudApp.Data;
using AsbCloudApp.Services;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;
using System;
namespace AsbCloudWebApi.Controllers
{

View File

@ -1,8 +1,8 @@
using System.Collections.Generic;
using AsbCloudApp.Data;
using AsbCloudApp.Data;
using AsbCloudApp.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
@ -30,7 +30,7 @@ namespace AsbCloudWebApi.Controllers
public async Task<IActionResult> GetSectionsByWellIdAsync(int idWell,
CancellationToken token = default)
{
if(!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
return Forbid();
var result = await sectionsService.GetSectionsByWellIdAsync(idWell, token)
@ -38,19 +38,6 @@ namespace AsbCloudWebApi.Controllers
return Ok(result);
}
[HttpGet]
[Route("{idSection}")]
[ProducesResponseType(typeof(WellSectionDto), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> GetAsync(int idWell, int idSection,
CancellationToken token = default)
{
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
return Forbid();
var result = await sectionsService.GetSectionByWellIdAsync(idSection, token).ConfigureAwait(false);
return Ok(result);
}
private async Task<bool> CanUserAccessToWellAsync(int idWell, CancellationToken token = default)
{
int? idCompany = User.GetCompanyId();