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

@ -42,7 +42,7 @@ namespace AsbCloudInfrastructure
services.AddTransient<ILastDataService<FluidDataDto>, LastDataService<FluidDataDto, FluidData>>();
services.AddTransient<ILastDataService<MudDiagramDataDto>, LastDataService<MudDiagramDataDto, MudDiagramData>>();
services.AddTransient<ILastDataService<NnbDataDto>, LastDataService<NnbDataDto, NnbData>>();
return services;
}
}

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;
@ -141,7 +141,7 @@ namespace AsbCloudInfrastructure.Services
return new JwtSecurityTokenHandler().WriteToken(jwt);
}
private async Task<(ClaimsIdentity Identity, User User)> GetClaimsUserAsync(string login,
private async Task<(ClaimsIdentity Identity, User User)> GetClaimsUserAsync(string login,
string password, CancellationToken token = default)
{
var user = await db

View File

@ -43,7 +43,7 @@ namespace AsbCloudInfrastructure.Services.Cache
if (cached.Any())
{
await semaphore.WaitAsync(token).ConfigureAwait(true);
cached.Clear();
cached.Clear();
}
var dbEntities = await context.Set<TEntity>().AsNoTracking().ToListAsync(token).ConfigureAwait(false);
cached.AddRange(dbEntities);
@ -167,12 +167,12 @@ namespace AsbCloudInfrastructure.Services.Cache
return result;
}
public async Task<IEnumerable<TEntity>> WhereAsync(Func<TEntity, bool> predicate = default,
public async Task<IEnumerable<TEntity>> WhereAsync(Func<TEntity, bool> predicate = default,
RefreshMode refreshMode = RefreshMode.IfResultEmpty, CancellationToken token = default)
{
bool isUpdated = await CheckRefreshAsync(refreshMode, token);
var result = (predicate != default)
? cached.Where(predicate)
bool isUpdated = await CheckRefreshAsync(refreshMode, token);
var result = (predicate != default)
? cached.Where(predicate)
: cached;
if (!result.Any() && refreshMode == RefreshMode.IfResultEmpty && !isUpdated)
{

View File

@ -26,8 +26,8 @@ namespace AsbCloudInfrastructure.Services
.Include(w => w.WellType)
.Include(w => w.Cluster)
.ThenInclude(c => c.Deposit)
where well.RelationCompaniesWells.Any(r => r.IdCompany == idCompany)
select well).ToListAsync(token)
where well.RelationCompaniesWells.Any(r => r.IdCompany == idCompany)
select well).ToListAsync(token)
.ConfigureAwait(false);
var gDepositEntities = wellEntities
@ -85,7 +85,7 @@ namespace AsbCloudInfrastructure.Services
return dtos;
}
public async Task<IEnumerable<ClusterDto>> GetClustersAsync(int idCompany,
public async Task<IEnumerable<ClusterDto>> GetClustersAsync(int idCompany,
int depositId, CancellationToken token = default)
{
var entities = await db.GetWellsForCompany(idCompany)
@ -107,7 +107,7 @@ namespace AsbCloudInfrastructure.Services
return dtos;
}
public async Task<IEnumerable<WellDto>> GetWellsAsync(int idCompany,
public async Task<IEnumerable<WellDto>> GetWellsAsync(int idCompany,
int idCluster, CancellationToken token = default)
{
var entities = await db.GetWellsForCompany(idCompany)
@ -129,7 +129,7 @@ namespace AsbCloudInfrastructure.Services
return dtos;
}
public async Task<ClusterStatDto> GetStatAsync(int idCompany,
public async Task<ClusterStatDto> GetStatAsync(int idCompany,
int idCluster, CancellationToken token = default)
{
var wellEntities = from w in db.Wells
@ -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;
@ -30,8 +30,8 @@ namespace AsbCloudInfrastructure.Services
cacheWells = cacheDb.GetCachedTable<Well>((AsbCloudDbContext)db);
}
public async Task<IEnumerable<DataSaubBaseDto>> GetAsync(int idWell,
DateTime dateBegin = default, double intervalSec = 600d,
public async Task<IEnumerable<DataSaubBaseDto>> GetAsync(int idWell,
DateTime dateBegin = default, double intervalSec = 600d,
int approxPointsCount = 1024, CancellationToken token = default)
{
var well = cacheWells.FirstOrDefault(w => w.Id == idWell);
@ -84,10 +84,10 @@ namespace AsbCloudInfrastructure.Services
var dtoMaxDate = dtos.Max(d => d.Date);
var oldDataSaubBase = await (from d in db.DataSaubBases
where d.IdTelemetry == telemetryId
&& d.Date > dtoMinDate
&& d.Date < dtoMaxDate
select d).AsNoTracking()
where d.IdTelemetry == telemetryId
&& d.Date > dtoMinDate
&& d.Date < dtoMaxDate
select d).AsNoTracking()
.ToListAsync(token)
.ConfigureAwait(false);

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
{
@ -47,7 +47,7 @@ namespace AsbCloudInfrastructure.Services
return fileIdsToNames;
}
public async Task SaveFile(int idWell, int idCategory, int fileId,
public async Task SaveFile(int idWell, int idCategory, int fileId,
string fileExtension, Stream fileStream)
{
var relativePath = Path.Combine(RootPath, $"{idWell}",
@ -62,7 +62,7 @@ namespace AsbCloudInfrastructure.Services
}
public async Task<PaginationContainer<FileInfoDto>> GetFilesInfoAsync(int idWell,
int idCategory, IEnumerable<int> companies = default, DateTime begin = default,
int idCategory, IEnumerable<int> companies = default, DateTime begin = default,
DateTime end = default, int skip = 0, int take = 32, CancellationToken token = default)
{
var query = db.Files
@ -84,8 +84,9 @@ namespace AsbCloudInfrastructure.Services
var count = await query.CountAsync(token).ConfigureAwait(false);
var result = new PaginationContainer<FileInfoDto>(count) {
Skip = skip,
var result = new PaginationContainer<FileInfoDto>(count)
{
Skip = skip,
Take = take,
Count = count,
};
@ -131,7 +132,7 @@ namespace AsbCloudInfrastructure.Services
return dto;
}
public async Task<int> DeleteFileAsync(int idFile,
public async Task<int> DeleteFileAsync(int idFile,
CancellationToken token = default)
{
var fileInfo = db.Files.FirstOrDefault(f => f.Id == idFile);

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
{
@ -17,7 +17,7 @@ namespace AsbCloudInfrastructure.Services
this.db = db;
}
public async Task<Tdto> GetAsync(int idWell, int idCategory,
public async Task<Tdto> GetAsync(int idWell, int idCategory,
CancellationToken token = default)
{
var entity = await db.LastData.AsNoTracking().FirstOrDefaultAsync(e =>
@ -31,7 +31,7 @@ namespace AsbCloudInfrastructure.Services
return dto;
}
public async Task<int> UpsertAsync(int idWell, int idCategory,
public async Task<int> UpsertAsync(int idWell, int idCategory,
Tdto value, CancellationToken token = default)
{
var model = value.Adapt<TModel>();

View File

@ -92,10 +92,10 @@ namespace AsbCloudInfrastructure.Services
return generator.GetPagesCount();
}
public async Task<IEnumerable<ReportPropertiesDto>> GetSuitableReportsAsync(int idWell,
public async Task<IEnumerable<ReportPropertiesDto>> GetSuitableReportsAsync(int idWell,
DateTime begin, DateTime end, int stepSeconds, int format, CancellationToken token = default)
{
var suitableReportsFromDb = await GetSuitableReportsFromDbAsync(idWell,
var suitableReportsFromDb = await GetSuitableReportsFromDbAsync(idWell,
begin, end, stepSeconds, format, token).ConfigureAwait(false);
var suitableReportsProperties = suitableReportsFromDb.Select(r => new ReportPropertiesDto
@ -145,17 +145,17 @@ namespace AsbCloudInfrastructure.Services
};
}
private async Task<IEnumerable<ReportProperty>> GetSuitableReportsFromDbAsync(int idWell,
private async Task<IEnumerable<ReportProperty>> GetSuitableReportsFromDbAsync(int idWell,
DateTime begin, DateTime end, int stepSeconds, int format,
CancellationToken token = default)
{
var suitableReportsNames = await(from r in db.ReportProperties.Include(r => r.File)
where r.IdWell == idWell
&& r.Begin >= begin
&& r.End <= end
&& r.Step <= stepSeconds
&& r.Format == format
select r).OrderBy(o => o.File.UploadDate)
var suitableReportsNames = await (from r in db.ReportProperties.Include(r => r.File)
where r.IdWell == idWell
&& r.Begin >= begin
&& r.End <= end
&& r.Step <= stepSeconds
&& r.Format == format
select r).OrderBy(o => o.File.UploadDate)
.AsNoTracking()
.Take(512).ToListAsync(token)
.ConfigureAwait(false);
@ -163,7 +163,7 @@ namespace AsbCloudInfrastructure.Services
return suitableReportsNames;
}
private IReportGenerator GetReportGenerator(int idWell, DateTime begin,
private IReportGenerator GetReportGenerator(int idWell, DateTime begin,
DateTime end, int stepSeconds, int format, AsbCloudDbContext context)
{
var dataSource = new ReportDataSourcePgCloud(context, idWell);

View File

@ -165,16 +165,16 @@ namespace AsbCloudInfrastructure.Services
var unixEnd = (end - new DateTime(1970, 1, 1)).TotalSeconds;
return await (from a in db.TelemetryAnalysis
where a.IdTelemetry == telemetryId &&
a.UnixDate > unixBegin && a.UnixDate < unixEnd
join o in db.TelemetryOperations on a.IdOperation equals o.Id
group a by new { a.IdOperation, o.Name } into g
select new TelemetryOperationDurationDto
{
OperationName = g.Key.Name,
Duration = g.Where(g => g.DurationSec > 0)
.Sum(a => a.DurationSec)
}).AsNoTracking().ToListAsync(token)
where a.IdTelemetry == telemetryId &&
a.UnixDate > unixBegin && a.UnixDate < unixEnd
join o in db.TelemetryOperations on a.IdOperation equals o.Id
group a by new { a.IdOperation, o.Name } into g
select new TelemetryOperationDurationDto
{
OperationName = g.Key.Name,
Duration = g.Where(g => g.DurationSec > 0)
.Sum(a => a.DurationSec)
}).AsNoTracking().ToListAsync(token)
.ConfigureAwait(false);
}
@ -194,19 +194,19 @@ namespace AsbCloudInfrastructure.Services
// Get'n'Group all operations only by start date and by name (if there were several operations in interval).
// Without dividing these operations duration by given interval
var ops = await (from a in db.TelemetryAnalysis
where a.IdTelemetry == telemetryId
join o in db.TelemetryOperations on a.IdOperation equals o.Id
group a by new
{
Interval = Math.Floor((a.UnixDate - workBeginSeconds + timezoneOffset) / intervalSeconds),
o.Name
} into g
select new
{
IntervalStart = g.Min(d => d.UnixDate),
OperationName = g.Key.Name,
OperationDuration = g.Sum(an => an.DurationSec)
}).AsNoTracking()
where a.IdTelemetry == telemetryId
join o in db.TelemetryOperations on a.IdOperation equals o.Id
group a by new
{
Interval = Math.Floor((a.UnixDate - workBeginSeconds + timezoneOffset) / intervalSeconds),
o.Name
} into g
select new
{
IntervalStart = g.Min(d => d.UnixDate),
OperationName = g.Key.Name,
OperationDuration = g.Sum(an => an.DurationSec)
}).AsNoTracking()
.OrderBy(op => op.IntervalStart)
.ToListAsync(token)
.ConfigureAwait(false);

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
{
@ -49,7 +47,7 @@ namespace AsbCloudInfrastructure.Services
var tele = cacheTelemetry.FirstOrDefault(t => t.RemoteUid == uid, RefreshMode.IfResultEmpty);
if (tele is null)
return null;
return cacheWells.FirstOrDefault(w => w?.IdTelemetry == tele.Id);
}

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
{
@ -99,7 +99,7 @@ namespace AsbCloudInfrastructure.Services
return result;
}
public async Task<WellOperationDto> GetAsync(int id,
public async Task<WellOperationDto> GetAsync(int id,
CancellationToken token = default)
{
var entity = await context.WellOperations
@ -117,11 +117,11 @@ namespace AsbCloudInfrastructure.Services
return dto;
}
public async Task<int> InsertRangeAsync(int idWell,
IEnumerable<WellOperationDto> wellOperationDtos,
public async Task<int> InsertRangeAsync(int idWell,
IEnumerable<WellOperationDto> wellOperationDtos,
CancellationToken token = default)
{
foreach(var operationDto in wellOperationDtos)
foreach (var operationDto in wellOperationDtos)
{
var entity = operationDto.Adapt<WellOperation>();
entity.Id = default;
@ -133,7 +133,7 @@ namespace AsbCloudInfrastructure.Services
.ConfigureAwait(false);
}
public async Task<int> UpdateAsync(int idWell, int idOperation,
public async Task<int> UpdateAsync(int idWell, int idOperation,
WellOperationDto item, CancellationToken token = default)
{
var entity = item.Adapt<WellOperation>();

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,28 +105,13 @@ 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)
{
return groupedOperations.Select(group => group.Where(o => o.IdType == type)
.DefaultIfEmpty().Max(w => w?.WellDepth ?? 0.0));
}
private static IEnumerable<double> GetWellDurationStats(
IEnumerable<IGrouping<int, WellOperation>> groupedOperations, int type)
@ -165,7 +146,7 @@ namespace AsbCloudInfrastructure.Services
private static IEnumerable<double> GetWellRouteSpeedStats(
IEnumerable<IGrouping<int, WellOperation>> groupedOperations, int type)
{
var bhaRaiseDecreaseCollection = new List<(WellOperation FirstBhaPositionDecrease,
var bhaRaiseDecreaseCollection = new List<(WellOperation FirstBhaPositionDecrease,
WellOperation LastBhaPositionIncrease)>();
foreach (var group in groupedOperations)
@ -182,10 +163,10 @@ namespace AsbCloudInfrastructure.Services
}
var routeSpeedsBase = bhaRaiseDecreaseCollection.Select(el =>
(
(
RouteDepth: (el.LastBhaPositionIncrease?.WellDepth - el.FirstBhaPositionDecrease?.WellDepth) ?? 0,
RouteDuration: (el.LastBhaPositionIncrease?.StartDate +
TimeSpan.FromHours(el.LastBhaPositionIncrease?.DurationHours ?? 0) -
RouteDuration: (el.LastBhaPositionIncrease?.StartDate +
TimeSpan.FromHours(el.LastBhaPositionIncrease?.DurationHours ?? 0) -
el.FirstBhaPositionDecrease?.StartDate)?.TotalHours ?? 0
));
@ -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
{
@ -47,7 +47,7 @@ namespace AsbCloudInfrastructure.Services
}
public async Task<bool> IsCompanyInvolvedInWellAsync(int idCompany, int idWell, CancellationToken token)
=> await cacheRelationCompaniesWells.ContainsAsync(r => r.IdWell == idWell &&
=> await cacheRelationCompaniesWells.ContainsAsync(r => r.IdWell == idWell &&
r.IdCompany == idCompany, token).ConfigureAwait(false);
public async Task<IEnumerable<WellOperationDto>> GetOperationsAsync(int idWell, CancellationToken token)

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
{
@ -32,7 +32,7 @@ namespace AsbCloudWebApi.Controllers
[ProducesResponseType(typeof(UserTokenDto), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> LoginAsync([FromBody] AuthDto auth, CancellationToken token = default)
{
var userToken = await authService.LoginAsync(auth.Login,
var userToken = await authService.LoginAsync(auth.Login,
auth.Password, token).ConfigureAwait(false);
if (userToken is null)

View File

@ -37,7 +37,7 @@ namespace AsbCloudWebApi.Controllers
if (idCompany is null)
return Forbid();
var result = await clusterService.GetClustersAsync((int)idCompany,
var result = await clusterService.GetClustersAsync((int)idCompany,
token).ConfigureAwait(false);
return Ok(result);
}
@ -57,7 +57,7 @@ namespace AsbCloudWebApi.Controllers
if (idCompany is null)
return Forbid();
var result = await clusterService.GetWellsAsync((int)idCompany,
var result = await clusterService.GetWellsAsync((int)idCompany,
idCluster, token).ConfigureAwait(false);
return Ok(result);
}
@ -77,7 +77,7 @@ namespace AsbCloudWebApi.Controllers
if (idCompany is null)
return Forbid();
var result = await clusterService.GetStatAsync((int)idCompany,
var result = await clusterService.GetStatAsync((int)idCompany,
idCluster, token).ConfigureAwait(false);
return Ok(result);
}

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

@ -39,12 +39,12 @@ namespace AsbCloudWebApi.Controllers
/// <returns></returns>
[HttpGet]
[ProducesResponseType(typeof(IEnumerable<DataSaubBaseDto>), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> GetDataAsync(int idWell, DateTime begin = default,
public async Task<IActionResult> GetDataAsync(int idWell, DateTime begin = default,
int intervalSec = 600, int approxPointsCount = 1024, CancellationToken token = default)
{
if (begin == default)
begin = DateTime.Now.AddSeconds(-intervalSec);
var content = await telemetryDataService.GetAsync(idWell, begin,
var content = await telemetryDataService.GetAsync(idWell, begin,
intervalSec, approxPointsCount, token).ConfigureAwait(false);
if (content is null || !content.Any())
@ -70,7 +70,7 @@ namespace AsbCloudWebApi.Controllers
if (idCompany is null)
return Forbid();
bool isCompanyOwnsWell = await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
bool isCompanyOwnsWell = await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
idWell, token).ConfigureAwait(false);
if (!isCompanyOwnsWell)

View File

@ -37,7 +37,7 @@ namespace AsbCloudWebApi.Controllers
if (idCompany is null)
return Forbid();
var result = await clusterService.GetDepositsAsync((int)idCompany,
var result = await clusterService.GetDepositsAsync((int)idCompany,
token).ConfigureAwait(false);
return Ok(result);
}
@ -58,7 +58,7 @@ namespace AsbCloudWebApi.Controllers
if (idCompany is null)
return Forbid();
var result = await clusterService.GetClustersAsync((int)idCompany,
var result = await clusterService.GetClustersAsync((int)idCompany,
depositId, token).ConfigureAwait(false);
return Ok(result);
}

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;
@ -50,9 +50,9 @@ namespace AsbCloudWebApi.Controllers
return Forbid();
var fileInfoCollection = files.Select(f => new FileInfoDto
{
Name = f.FileName,
IdCategory = idCategory,
{
Name = f.FileName,
IdCategory = idCategory,
UploadDate = DateTime.Now
});
@ -91,7 +91,7 @@ namespace AsbCloudWebApi.Controllers
[ProducesResponseType(typeof(PaginationContainer<FileInfoDto>), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> GetFilesInfoAsync([FromRoute] int idWell,
int skip = 0, int take = 32, int idCategory = default,
DateTime begin = default, DateTime end = default,
DateTime begin = default, DateTime end = default,
CancellationToken token = default, [FromQuery] IEnumerable<int> companies = default)
{
int? idCompany = User.GetCompanyId();

View File

@ -20,31 +20,31 @@ namespace AsbCloudWebApi.Controllers
}
[HttpGet]
public async Task<IActionResult> GetAsync([FromRoute] int idWell,
public async Task<IActionResult> GetAsync([FromRoute] int idWell,
[FromQuery] int idCategory, CancellationToken token = default)
{
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();
return Forbid();
var result = await lastDataService.GetAsync(idWell,
var result = await lastDataService.GetAsync(idWell,
idCategory, token).ConfigureAwait(false);
return Ok(result);
}
[HttpPost]
public async Task<IActionResult> PutAsync([FromRoute] int idWell,
public async Task<IActionResult> PutAsync([FromRoute] int idWell,
[FromQuery] int idCategory, T data, CancellationToken token = default)
{
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();
return Forbid();
await lastDataService.UpsertAsync(idWell,
await lastDataService.UpsertAsync(idWell,
idCategory, data, token).ConfigureAwait(false);
return Ok();
}

View File

@ -35,9 +35,9 @@ namespace AsbCloudWebApi.Controllers
/// <returns>список сообщений по скважине</returns>
[HttpGet]
[ProducesResponseType(typeof(PaginationContainer<MessageDto>), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> GetMessagesAsync(int idWell, int skip = 0, int take = 32,
[FromQuery] IEnumerable<int> categoryids = default,
DateTime begin = default, DateTime end = default,
public async Task<IActionResult> GetMessagesAsync(int idWell, int skip = 0, int take = 32,
[FromQuery] IEnumerable<int> categoryids = default,
DateTime begin = default, DateTime end = default,
string searchString = default,
CancellationToken token = default)
{
@ -47,8 +47,8 @@ namespace AsbCloudWebApi.Controllers
if (begin > DateTime.Now)
begin = default;
var result = await messageService.GetMessagesAsync(idWell,
categoryids, begin, end, searchString,
var result = await messageService.GetMessagesAsync(idWell,
categoryids, begin, end, searchString,
skip, take, token).ConfigureAwait(false);
if (result is null || result.Count == 0)
@ -74,7 +74,7 @@ namespace AsbCloudWebApi.Controllers
if (idCompany is null)
return Forbid();
bool isCompanyOwnsWell = await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
bool isCompanyOwnsWell = await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
idWell, token).ConfigureAwait(false);
if (!isCompanyOwnsWell)

View File

@ -74,9 +74,9 @@ namespace AsbCloudWebApi.Controllers
if (idCompany is null)
return Forbid();
if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
idWell, token).ConfigureAwait(false))
return Forbid();
return Forbid();
var id = reportService.CreateReport(idWell, idUser,
stepSeconds, format, begin, end, HandleReportProgressAsync, HandleReportNameAsync);
@ -94,7 +94,7 @@ namespace AsbCloudWebApi.Controllers
[HttpGet]
[Route("{reportName}")]
[ProducesResponseType(typeof(PhysicalFileResult), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> GetReportAsync([FromRoute] int idWell,
public async Task<IActionResult> GetReportAsync([FromRoute] int idWell,
string reportName, CancellationToken token = default)
{
try
@ -104,9 +104,9 @@ namespace AsbCloudWebApi.Controllers
if (idCompany is null)
return Forbid();
if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
idWell, token).ConfigureAwait(false))
return Forbid();
return Forbid();
// TODO: словарь content typoв
var relativePath = Path.Combine(fileService.RootPath, $"{idWell}",
@ -137,7 +137,7 @@ namespace AsbCloudWebApi.Controllers
DateTime begin = default, DateTime end = default,
CancellationToken token = default)
{
var suitableReportsNames = await reportService.GetSuitableReportsAsync(idWell,
var suitableReportsNames = await reportService.GetSuitableReportsAsync(idWell,
begin, end, stepSeconds, format, token).ConfigureAwait(false);
if (suitableReportsNames is null || !suitableReportsNames.Any())
@ -159,8 +159,8 @@ namespace AsbCloudWebApi.Controllers
[HttpGet]
[Route("reportSize")]
[ProducesResponseType(typeof(string), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> GetReportSizeAsync(int idWell,
int stepSeconds, int format, DateTime begin = default,
public async Task<IActionResult> GetReportSizeAsync(int idWell,
int stepSeconds, int format, DateTime begin = default,
DateTime end = default, CancellationToken token = default)
{
int? idCompany = User.GetCompanyId();
@ -168,11 +168,11 @@ namespace AsbCloudWebApi.Controllers
if (idCompany is null)
return Forbid();
if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
idWell, token).ConfigureAwait(false))
return Forbid();
return Forbid();
int reportSize = reportService.GetReportPagesCount(idWell,
int reportSize = reportService.GetReportPagesCount(idWell,
begin, end, stepSeconds, format);
return Ok(reportSize);
@ -187,7 +187,7 @@ namespace AsbCloudWebApi.Controllers
[HttpGet]
[Route("datesRange")]
[ProducesResponseType(typeof(DatesRangeDto), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> GetReportsDateRangeAsync(int idWell,
public async Task<IActionResult> GetReportsDateRangeAsync(int idWell,
CancellationToken token = default)
{
int? idCompany = User.GetCompanyId();
@ -195,9 +195,9 @@ namespace AsbCloudWebApi.Controllers
if (idCompany is null)
return Forbid();
if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
idWell, token).ConfigureAwait(false))
return Forbid();
return Forbid();
DatesRangeDto wellReportsDatesRange = await reportService.GetReportsDatesRangeAsync(idWell,
token).ConfigureAwait(false);

View File

@ -39,14 +39,14 @@ namespace AsbCloudWebApi.Controllers
[Route("operationsByWell")]
[ProducesResponseType(typeof(PaginationContainer<TelemetryOperationDto>), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> GetOperationsByWellAsync(int idWell, int skip = 0, int take = 32,
[FromQuery] IEnumerable<int> categoryIds = default, DateTime begin = default, DateTime end = default,
[FromQuery] IEnumerable<int> categoryIds = default, DateTime begin = default, DateTime end = default,
CancellationToken token = default)
{
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();
return Forbid();
var analytics = await analyticsService.GetOperationsByWellAsync(idWell, categoryIds, begin, end, skip, take, token)
.ConfigureAwait(false);
@ -71,9 +71,9 @@ 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();
return Forbid();
var wellDepthToDayData = await analyticsService.GetWellDepthToDayAsync(idWell, token)
.ConfigureAwait(false);
@ -100,9 +100,9 @@ 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();
return Forbid();
var wellDepthToIntervalData = await analyticsService.GetWellDepthToIntervalAsync(idWell,
intervalSeconds, workBeginSeconds, token).ConfigureAwait(false);
@ -124,16 +124,16 @@ namespace AsbCloudWebApi.Controllers
[HttpGet]
[Route("operationsSummary")]
[ProducesResponseType(typeof(IEnumerable<TelemetryOperationDurationDto>), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> GetOperationsSummaryAsync(int idWell, DateTime begin = default,
public async Task<IActionResult> GetOperationsSummaryAsync(int idWell, DateTime begin = default,
DateTime end = default, CancellationToken token = default)
{
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();
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,11 +158,11 @@ 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();
return Forbid();
var analytics = await analyticsService.GetOperationsToIntervalAsync(idWell,
var analytics = await analyticsService.GetOperationsToIntervalAsync(idWell,
intervalSeconds, workBeginSeconds, token).ConfigureAwait(false);
if (analytics is null || !analytics.Any())

View File

@ -32,7 +32,7 @@ namespace AsbCloudWebApi.Controllers
return NoContent();
}
var wells = await wellService.GetWellsByCompanyAsync((int)idCompany,
var wells = await wellService.GetWellsByCompanyAsync((int)idCompany,
token).ConfigureAwait(false);
if (wells is null || !wells.Any())
@ -50,11 +50,11 @@ namespace AsbCloudWebApi.Controllers
if (idCompany is null)
return NoContent();
if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
idWell, token).ConfigureAwait(false))
return Forbid();
return Forbid();
var dto = await wellService.GetOperationsAsync(idWell,
var dto = await wellService.GetOperationsAsync(idWell,
token).ConfigureAwait(false);
return Ok(dto);
@ -69,7 +69,7 @@ namespace AsbCloudWebApi.Controllers
if (idCompany is null)
return NoContent();
var transmittingWells = await wellService.GetTransmittingWellsAsync((int)idCompany,
var transmittingWells = await wellService.GetTransmittingWellsAsync((int)idCompany,
token).ConfigureAwait(false);
if (transmittingWells is null || !transmittingWells.Any())

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
{
@ -57,15 +57,15 @@ namespace AsbCloudWebApi.Controllers
[HttpGet]
[ProducesResponseType(typeof(PaginationContainer<WellOperationDto>), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> GetOperationsAsync(
int idWell,
int idWell,
int? opertaionType = default,
[FromQuery] IEnumerable<int> sectionTypeIds = default,
[FromQuery] IEnumerable<int> operationCategoryIds = default,
DateTime begin = default,
DateTime end = default,
double minDepth = double.MinValue,
double minDepth = double.MinValue,
double maxDepth = double.MaxValue,
int skip = 0,
int skip = 0,
int take = 32,
CancellationToken token = default)
{
@ -138,7 +138,7 @@ namespace AsbCloudWebApi.Controllers
/// <returns>Количество обновленных в БД строк</returns>
[HttpPut("{idOperation}")]
[ProducesResponseType(typeof(WellOperationDto), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> UpdateAsync(int idWell, int idOperation,
public async Task<IActionResult> UpdateAsync(int idWell, int idOperation,
[FromBody] WellOperationDto value, CancellationToken token = default)
{
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))

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();