forked from ddrilling/AsbCloudServer
CS2-50: Controllers and some services are made async
This commit is contained in:
parent
e4800bf281
commit
4c4048865c
@ -1,20 +1,21 @@
|
|||||||
using AsbCloudApp.Data;
|
using AsbCloudApp.Data;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace AsbCloudApp.Services
|
namespace AsbCloudApp.Services
|
||||||
{
|
{
|
||||||
public interface IAnalyticsService
|
public interface IAnalyticsService
|
||||||
{
|
{
|
||||||
PaginationContainer<TelemetryOperationDto> GetOperationsByWell(int idWell,
|
Task<PaginationContainer<TelemetryOperationDto>> GetOperationsByWellAsync(int idWell,
|
||||||
IEnumerable<int> categoryids = default, DateTime begin = default,
|
IEnumerable<int> categoryids = default, DateTime begin = default,
|
||||||
DateTime end = default, int skip = 0, int take = 32);
|
DateTime end = default, int skip = 0, int take = 32);
|
||||||
IEnumerable<WellDepthToDayDto> GetWellDepthToDay(int idWell);
|
Task<IEnumerable<WellDepthToDayDto>> GetWellDepthToDayAsync(int idWell);
|
||||||
IEnumerable<WellDepthToIntervalDto> GetWellDepthToInterval(int idWell,
|
Task<IEnumerable<WellDepthToIntervalDto>> GetWellDepthToIntervalAsync(int idWell,
|
||||||
int intervalHoursTimestamp, int workBeginTimestamp);
|
int intervalHoursTimestamp, int workBeginTimestamp);
|
||||||
IEnumerable<TelemetryOperationDurationDto> GetOperationsSummary(int idWell,
|
Task<IEnumerable<TelemetryOperationDurationDto>> GetOperationsSummaryAsync(int idWell,
|
||||||
DateTime begin = default, DateTime end = default);
|
DateTime begin = default, DateTime end = default);
|
||||||
IEnumerable<TelemetryOperationInfoDto> GetOperationsToInterval(int idWell,
|
Task<IEnumerable<TelemetryOperationInfoDto>> GetOperationsToIntervalAsync(int idWell,
|
||||||
int intervalHoursTimestamp, int workBeginTimestamp);
|
int intervalHoursTimestamp, int workBeginTimestamp);
|
||||||
void SaveAnalytics(DataSaubBaseDto dataSaub);
|
void SaveAnalytics(DataSaubBaseDto dataSaub);
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,15 @@
|
|||||||
using AsbCloudApp.Data;
|
using AsbCloudApp.Data;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace AsbCloudApp.Services
|
namespace AsbCloudApp.Services
|
||||||
{
|
{
|
||||||
public interface IClusterService
|
public interface IClusterService
|
||||||
{
|
{
|
||||||
IEnumerable<DepositDto> GetDeposits(int idCompany);
|
Task<IEnumerable<DepositDto>> GetDepositsAsync(int idCompany);
|
||||||
IEnumerable<ClusterDto> GetClusters(int idCompany, int depositId);
|
Task<IEnumerable<ClusterDto>> GetClustersAsync(int idCompany, int depositId);
|
||||||
IEnumerable<ClusterDto> GetClusters(int idCompany);
|
Task<IEnumerable<ClusterDto>> GetClustersAsync(int idCompany);
|
||||||
IEnumerable<WellDto> GetWells(int idCompany, int clusterId);
|
Task<IEnumerable<WellDto>> GetWellsAsync(int idCompany, int clusterId);
|
||||||
ClusterStatDto GetStat(int idCompany, int clusterId);
|
Task<ClusterStatDto> GetStatAsync(int idCompany, int clusterId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,14 @@
|
|||||||
using AsbCloudApp.Data;
|
using AsbCloudApp.Data;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace AsbCloudApp.Services
|
namespace AsbCloudApp.Services
|
||||||
{
|
{
|
||||||
public interface IWellService
|
public interface IWellService
|
||||||
{
|
{
|
||||||
IEnumerable<WellDto> GetWellsByCompany(int idCompany);
|
Task<IEnumerable<WellDto>> GetWellsByCompanyAsync(int idCompany);
|
||||||
IEnumerable<WellDto> GetTransmittingWells(int idCompany);
|
Task<IEnumerable<WellDto>> GetTransmittingWellsAsync(int idCompany);
|
||||||
bool IsCompanyInvolvedInWell(int idCompany, int idWell);
|
Task<bool> IsCompanyInvolvedInWellAsync(int idCompany, int idWell);
|
||||||
IEnumerable<WellOperationDto> GetOperations(int idWell);
|
Task<IEnumerable<WellOperationDto>> GetOperationsAsync(int idWell);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using System.Data.Common;
|
||||||
|
|
||||||
#nullable disable
|
#nullable disable
|
||||||
|
|
||||||
@ -490,7 +491,7 @@ namespace AsbCloudDb.Model
|
|||||||
return (datesRange.From, datesRange.To);
|
return (datesRange.From, datesRange.To);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<(double? MinDepth, double? MaxDepth, DateTime BeginPeriodDate)> GetDepthToInterval(int telemetryId,
|
public async Task<IEnumerable<(double? MinDepth, double? MaxDepth, DateTime BeginPeriodDate)>> GetDepthToIntervalAsync(int telemetryId,
|
||||||
int intervalHoursTimestamp, int workStartTimestamp, double timezoneOffset)
|
int intervalHoursTimestamp, int workStartTimestamp, double timezoneOffset)
|
||||||
{
|
{
|
||||||
//TODO: Сменить на LINQ группирование
|
//TODO: Сменить на LINQ группирование
|
||||||
@ -502,8 +503,11 @@ namespace AsbCloudDb.Model
|
|||||||
GROUP BY floor((extract(epoch from t.date) - {workStartTimestamp} + {timezoneOffset}) / {intervalHoursTimestamp});";
|
GROUP BY floor((extract(epoch from t.date) - {workStartTimestamp} + {timezoneOffset}) / {intervalHoursTimestamp});";
|
||||||
|
|
||||||
Database.OpenConnection();
|
Database.OpenConnection();
|
||||||
using var reader = command.ExecuteReader();
|
using var reader = await command.ExecuteReaderAsync();
|
||||||
if (reader.HasRows)
|
|
||||||
|
IEnumerable<(double? MinDepth, double? MaxDepth, DateTime BeginPeriodDate)> GetResult(DbDataReader rd)
|
||||||
|
{
|
||||||
|
if (rd.HasRows)
|
||||||
{
|
{
|
||||||
while (reader.Read())
|
while (reader.Read())
|
||||||
{
|
{
|
||||||
@ -517,6 +521,9 @@ namespace AsbCloudDb.Model
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return GetResult(reader);
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<int> CreatePartitionAsync<TEntity>(string propertyName, int id, CancellationToken token = default)
|
public async Task<int> CreatePartitionAsync<TEntity>(string propertyName, int id, CancellationToken token = default)
|
||||||
where TEntity : class
|
where TEntity : class
|
||||||
{
|
{
|
||||||
|
@ -41,7 +41,7 @@ namespace AsbCloudDb.Model
|
|||||||
IQueryable<Well> GetWellsForCompany(int idCompany);
|
IQueryable<Well> GetWellsForCompany(int idCompany);
|
||||||
IQueryable<User> GetUsersByLogin(string login);
|
IQueryable<User> GetUsersByLogin(string login);
|
||||||
(DateTime From, DateTime To) GetDatesRange<T>(int idTelemetry) where T : class, IIdTelemetryDate;
|
(DateTime From, DateTime To) GetDatesRange<T>(int idTelemetry) where T : class, IIdTelemetryDate;
|
||||||
IEnumerable<(double? MinDepth, double? MaxDepth, DateTime BeginPeriodDate)> GetDepthToInterval(int telemetryId,
|
Task<IEnumerable<(double? MinDepth, double? MaxDepth, DateTime BeginPeriodDate)>> GetDepthToIntervalAsync(int telemetryId,
|
||||||
int intervalHoursTimestamp, int workStartTimestamp, double timezoneOffset);
|
int intervalHoursTimestamp, int workStartTimestamp, double timezoneOffset);
|
||||||
Task<int> CreatePartitionAsync<TEntity>(string propertyName, int id, CancellationToken token = default) where TEntity : class;
|
Task<int> CreatePartitionAsync<TEntity>(string propertyName, int id, CancellationToken token = default) where TEntity : class;
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ using Microsoft.EntityFrameworkCore;
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace AsbCloudInfrastructure.Services
|
namespace AsbCloudInfrastructure.Services
|
||||||
{
|
{
|
||||||
@ -30,7 +31,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
operationDetectorService = new TelemetryOperationDetectorService(operations);
|
operationDetectorService = new TelemetryOperationDetectorService(operations);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<WellDepthToDayDto> GetWellDepthToDay(int idWell)
|
public async Task<IEnumerable<WellDepthToDayDto>> GetWellDepthToDayAsync(int idWell)
|
||||||
{
|
{
|
||||||
var telemetryId = telemetryService.GetIdTelemetryByIdWell(idWell);
|
var telemetryId = telemetryService.GetIdTelemetryByIdWell(idWell);
|
||||||
|
|
||||||
@ -52,15 +53,15 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
if (m > 1)
|
if (m > 1)
|
||||||
depthToTimeData = depthToTimeData.Where(d => d.Id % m == 0);
|
depthToTimeData = depthToTimeData.Where(d => d.Id % m == 0);
|
||||||
|
|
||||||
return depthToTimeData.Select(d => new WellDepthToDayDto
|
return await depthToTimeData.Select(d => new WellDepthToDayDto
|
||||||
{
|
{
|
||||||
WellDepth = d.WellDepth ?? 0.0,
|
WellDepth = d.WellDepth ?? 0.0,
|
||||||
BitDepth = d.BitDepth ?? 0.0,
|
BitDepth = d.BitDepth ?? 0.0,
|
||||||
Date = d.Date
|
Date = d.Date
|
||||||
}).AsNoTracking().ToList();
|
}).AsNoTracking().ToListAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<WellDepthToIntervalDto> GetWellDepthToInterval(int idWell,
|
public async Task<IEnumerable<WellDepthToIntervalDto>> GetWellDepthToIntervalAsync(int idWell,
|
||||||
int intervalSeconds, int workBeginSeconds)
|
int intervalSeconds, int workBeginSeconds)
|
||||||
{
|
{
|
||||||
intervalSeconds = intervalSeconds == 0 ? 86400 : intervalSeconds;
|
intervalSeconds = intervalSeconds == 0 ? 86400 : intervalSeconds;
|
||||||
@ -72,7 +73,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
|
|
||||||
var timezoneOffset = telemetryService.GetTimezoneOffsetByTelemetryId((int)telemetryId);
|
var timezoneOffset = telemetryService.GetTimezoneOffsetByTelemetryId((int)telemetryId);
|
||||||
|
|
||||||
var drillingPeriodsInfo = db.GetDepthToInterval((int)telemetryId, intervalSeconds,
|
var drillingPeriodsInfo = await db.GetDepthToIntervalAsync((int)telemetryId, intervalSeconds,
|
||||||
workBeginSeconds, timezoneOffset);
|
workBeginSeconds, timezoneOffset);
|
||||||
|
|
||||||
var wellDepthToIntervalData = drillingPeriodsInfo.Select(d => new WellDepthToIntervalDto
|
var wellDepthToIntervalData = drillingPeriodsInfo.Select(d => new WellDepthToIntervalDto
|
||||||
@ -84,7 +85,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
return wellDepthToIntervalData;
|
return wellDepthToIntervalData;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PaginationContainer<TelemetryOperationDto> GetOperationsByWell(int idWell,
|
public async Task<PaginationContainer<TelemetryOperationDto>> GetOperationsByWellAsync(int idWell,
|
||||||
IEnumerable<int> categoryIds = default, DateTime begin = default,
|
IEnumerable<int> categoryIds = default, DateTime begin = default,
|
||||||
DateTime end = default, int skip = 0, int take = 32)
|
DateTime end = default, int skip = 0, int take = 32)
|
||||||
{
|
{
|
||||||
@ -125,7 +126,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
if (skip > 0)
|
if (skip > 0)
|
||||||
operations = operations.Skip(skip);
|
operations = operations.Skip(skip);
|
||||||
|
|
||||||
var operationsList = operations.Take(take).AsNoTracking().ToList();
|
var operationsList = await operations.Take(take).AsNoTracking().ToListAsync();
|
||||||
|
|
||||||
if (operationsList.Count == 0)
|
if (operationsList.Count == 0)
|
||||||
return result;
|
return result;
|
||||||
@ -148,7 +149,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<TelemetryOperationDurationDto> GetOperationsSummary(int idWell,
|
public async Task<IEnumerable<TelemetryOperationDurationDto>> GetOperationsSummaryAsync(int idWell,
|
||||||
DateTime begin = default, DateTime end = default)
|
DateTime begin = default, DateTime end = default)
|
||||||
{
|
{
|
||||||
var telemetryId = telemetryService.GetIdTelemetryByIdWell(idWell);
|
var telemetryId = telemetryService.GetIdTelemetryByIdWell(idWell);
|
||||||
@ -159,7 +160,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
var unixBegin = (begin - new DateTime(1970, 1, 1)).TotalSeconds;
|
var unixBegin = (begin - new DateTime(1970, 1, 1)).TotalSeconds;
|
||||||
var unixEnd = (end - new DateTime(1970, 1, 1)).TotalSeconds;
|
var unixEnd = (end - new DateTime(1970, 1, 1)).TotalSeconds;
|
||||||
|
|
||||||
var operations = (from a in db.TelemetryAnalysis
|
var operations = await (from a in db.TelemetryAnalysis
|
||||||
where a.IdTelemetry == telemetryId &&
|
where a.IdTelemetry == telemetryId &&
|
||||||
a.UnixDate > unixBegin && a.UnixDate < unixEnd
|
a.UnixDate > unixBegin && a.UnixDate < unixEnd
|
||||||
join o in db.TelemetryOperations on a.IdOperation equals o.Id
|
join o in db.TelemetryOperations on a.IdOperation equals o.Id
|
||||||
@ -169,12 +170,12 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
OperationName = g.Key.Name,
|
OperationName = g.Key.Name,
|
||||||
Duration = g.Where(g => g.DurationSec > 0)
|
Duration = g.Where(g => g.DurationSec > 0)
|
||||||
.Sum(a => a.DurationSec)
|
.Sum(a => a.DurationSec)
|
||||||
}).AsNoTracking().ToList();
|
}).AsNoTracking().ToListAsync();
|
||||||
|
|
||||||
return operations;
|
return operations;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<TelemetryOperationInfoDto> GetOperationsToInterval(int idWell,
|
public async Task<IEnumerable<TelemetryOperationInfoDto>> GetOperationsToIntervalAsync(int idWell,
|
||||||
int intervalSeconds, int workBeginSeconds)
|
int intervalSeconds, int workBeginSeconds)
|
||||||
{
|
{
|
||||||
intervalSeconds = intervalSeconds == 0 ? 86400 : intervalSeconds;
|
intervalSeconds = intervalSeconds == 0 ? 86400 : intervalSeconds;
|
||||||
@ -186,7 +187,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
|
|
||||||
var timezoneOffset = telemetryService.GetTimezoneOffsetByTelemetryId((int)telemetryId);
|
var timezoneOffset = telemetryService.GetTimezoneOffsetByTelemetryId((int)telemetryId);
|
||||||
|
|
||||||
var operations = (from a in db.TelemetryAnalysis
|
var operations = await (from a in db.TelemetryAnalysis
|
||||||
where a.IdTelemetry == telemetryId
|
where a.IdTelemetry == telemetryId
|
||||||
join o in db.TelemetryOperations on a.IdOperation equals o.Id
|
join o in db.TelemetryOperations on a.IdOperation equals o.Id
|
||||||
group a by new
|
group a by new
|
||||||
@ -200,7 +201,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
IntervalStart = g.Min(d => d.UnixDate),
|
IntervalStart = g.Min(d => d.UnixDate),
|
||||||
OperationName = g.Key.Name,
|
OperationName = g.Key.Name,
|
||||||
OperationsDuration = g.Sum(an => an.DurationSec)
|
OperationsDuration = g.Sum(an => an.DurationSec)
|
||||||
}).AsNoTracking().ToList();
|
}).AsNoTracking().ToListAsync();
|
||||||
|
|
||||||
var operationsGroupedByInterval = operations.GroupBy(op => op.IntervalStart)
|
var operationsGroupedByInterval = operations.GroupBy(op => op.IntervalStart)
|
||||||
.Select(o => new TelemetryOperationInfoDto
|
.Select(o => new TelemetryOperationInfoDto
|
||||||
|
@ -4,6 +4,7 @@ using AsbCloudDb.Model;
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace AsbCloudInfrastructure.Services
|
namespace AsbCloudInfrastructure.Services
|
||||||
{
|
{
|
||||||
@ -16,15 +17,15 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
this.db = db;
|
this.db = db;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<DepositDto> GetDeposits(int idCompany)
|
public async Task<IEnumerable<DepositDto>> GetDepositsAsync(int idCompany)
|
||||||
{
|
{
|
||||||
var wellEntities = (from well in db.Wells
|
var wellEntities = await (from well in db.Wells
|
||||||
.Include(w => w.RelationCompaniesWells)
|
.Include(w => w.RelationCompaniesWells)
|
||||||
.Include(w => w.WellType)
|
.Include(w => w.WellType)
|
||||||
.Include(w => w.Cluster)
|
.Include(w => w.Cluster)
|
||||||
.ThenInclude(c => c.Deposit)
|
.ThenInclude(c => c.Deposit)
|
||||||
where well.RelationCompaniesWells.Any(r => r.IdCompany == idCompany)
|
where well.RelationCompaniesWells.Any(r => r.IdCompany == idCompany)
|
||||||
select well).AsNoTracking().ToList();
|
select well).AsNoTracking().ToListAsync();
|
||||||
|
|
||||||
var gDepositEntities = wellEntities
|
var gDepositEntities = wellEntities
|
||||||
.GroupBy(w => w.Cluster)
|
.GroupBy(w => w.Cluster)
|
||||||
@ -60,13 +61,13 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
return dtos;
|
return dtos;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<ClusterDto> GetClusters(int idCompany)
|
public async Task<IEnumerable<ClusterDto>> GetClustersAsync(int idCompany)
|
||||||
{
|
{
|
||||||
var entities = db.GetWellsForCompany(idCompany)
|
var entities = await db.GetWellsForCompany(idCompany)
|
||||||
.Select(e => e.Cluster)
|
.Select(e => e.Cluster)
|
||||||
.Distinct()
|
.Distinct()
|
||||||
.AsNoTracking()
|
.AsNoTracking()
|
||||||
.ToList();
|
.ToListAsync();
|
||||||
|
|
||||||
var dtos = entities.Select(e => new ClusterDto
|
var dtos = entities.Select(e => new ClusterDto
|
||||||
{
|
{
|
||||||
@ -79,14 +80,14 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
return dtos;
|
return dtos;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<ClusterDto> GetClusters(int idCompany, int depositId)
|
public async Task<IEnumerable<ClusterDto>> GetClustersAsync(int idCompany, int depositId)
|
||||||
{
|
{
|
||||||
var entities = db.GetWellsForCompany(idCompany)
|
var entities = await db.GetWellsForCompany(idCompany)
|
||||||
.Select(e => e.Cluster)
|
.Select(e => e.Cluster)
|
||||||
.Where(e => e.IdDeposit == depositId)
|
.Where(e => e.IdDeposit == depositId)
|
||||||
.Distinct()
|
.Distinct()
|
||||||
.AsNoTracking()
|
.AsNoTracking()
|
||||||
.ToList();
|
.ToListAsync();
|
||||||
|
|
||||||
var dtos = entities.Select(e => new ClusterDto
|
var dtos = entities.Select(e => new ClusterDto
|
||||||
{
|
{
|
||||||
@ -99,12 +100,12 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
return dtos;
|
return dtos;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<WellDto> GetWells(int idCompany, int idCluster)
|
public async Task<IEnumerable<WellDto>> GetWellsAsync(int idCompany, int idCluster)
|
||||||
{
|
{
|
||||||
var entities = db.GetWellsForCompany(idCompany)
|
var entities = await db.GetWellsForCompany(idCompany)
|
||||||
.Where(e => e.IdCluster == idCluster)
|
.Where(e => e.IdCluster == idCluster)
|
||||||
.AsNoTracking()
|
.AsNoTracking()
|
||||||
.ToList();
|
.ToListAsync();
|
||||||
|
|
||||||
var dtos = entities.Select(e => new WellDto
|
var dtos = entities.Select(e => new WellDto
|
||||||
{
|
{
|
||||||
@ -119,13 +120,13 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
return dtos;
|
return dtos;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ClusterStatDto GetStat(int idCompany, int idCluster)
|
public async Task<ClusterStatDto> GetStatAsync(int idCompany, int idCluster)
|
||||||
{
|
{
|
||||||
var wellEntities = from w in db.Wells
|
var wellEntities = from w in db.Wells
|
||||||
where w.IdCluster == idCluster && w.RelationCompaniesWells.Any(c => c.IdCompany == idCompany)
|
where w.IdCluster == idCluster && w.RelationCompaniesWells.Any(c => c.IdCompany == idCompany)
|
||||||
select w;
|
select w;
|
||||||
|
|
||||||
var wellStatDtos = wellEntities.Select(e => new WellStatDto
|
var wellStatDtos = await wellEntities.Select(e => new WellStatDto
|
||||||
{
|
{
|
||||||
Id = e.Id,
|
Id = e.Id,
|
||||||
Caption = e.Caption,
|
Caption = e.Caption,
|
||||||
@ -167,7 +168,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
CompanyType = c.Company.CompanyType.Caption,
|
CompanyType = c.Company.CompanyType.Caption,
|
||||||
}),
|
}),
|
||||||
WellType = e.WellType.Caption,
|
WellType = e.WellType.Caption,
|
||||||
}).AsNoTracking().ToList();
|
}).AsNoTracking().ToListAsync();
|
||||||
|
|
||||||
if (!wellStatDtos.Any())
|
if (!wellStatDtos.Any())
|
||||||
return null;
|
return null;
|
||||||
|
@ -6,6 +6,8 @@ using Mapster;
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace AsbCloudInfrastructure.Services
|
namespace AsbCloudInfrastructure.Services
|
||||||
@ -23,36 +25,35 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
cacheRelationCompaniesWells = cacheDb.GetCachedTable<RelationCompanyWell>((AsbCloudDbContext)db);
|
cacheRelationCompaniesWells = cacheDb.GetCachedTable<RelationCompanyWell>((AsbCloudDbContext)db);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<WellDto> GetTransmittingWells(int idCompany)
|
public async Task<IEnumerable<WellDto>> GetTransmittingWellsAsync(int idCompany)
|
||||||
{
|
{
|
||||||
var wells = new List<Well>();
|
var wells = new List<Well>();
|
||||||
IEnumerable<string> activeTelemetriesUids = telemetryTracker.GetTransmittingTelemetryUids();
|
IEnumerable<string> activeTelemetriesUids = telemetryTracker.GetTransmittingTelemetryUids();
|
||||||
if (activeTelemetriesUids.Any())
|
if (activeTelemetriesUids.Any())
|
||||||
{
|
{
|
||||||
wells = db.GetWellsForCompany(idCompany)
|
wells = await db.GetWellsForCompany(idCompany)
|
||||||
.Where(w => activeTelemetriesUids.Contains(w.Telemetry.RemoteUid))
|
.Where(w => activeTelemetriesUids.Contains(w.Telemetry.RemoteUid))
|
||||||
.AsNoTracking()
|
.AsNoTracking()
|
||||||
.ToList();
|
.ToListAsync();
|
||||||
}
|
}
|
||||||
return wells.Select(w => From(w));
|
return wells.Select(w => From(w));
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<WellDto> GetWellsByCompany(int idCompany)
|
public async Task<IEnumerable<WellDto>> GetWellsByCompanyAsync(int idCompany)
|
||||||
{
|
{
|
||||||
var wells = db.GetWellsForCompany(idCompany).ToList();
|
var wells = await db.GetWellsForCompany(idCompany).ToListAsync();
|
||||||
return wells.Select(w => From(w));
|
return wells.Select(w => From(w));
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsCompanyInvolvedInWell(int idCompany, int idWell)
|
public async Task<bool> IsCompanyInvolvedInWellAsync(int idCompany, int idWell)
|
||||||
=> cacheRelationCompaniesWells.Contains(r => r.IdWell == idWell && r.IdCompany == idCompany);
|
=> await cacheRelationCompaniesWells.ContainsAsync(r => r.IdWell == idWell &&
|
||||||
|
r.IdCompany == idCompany, new CancellationToken());
|
||||||
|
|
||||||
public IEnumerable<WellOperationDto> GetOperations(int idWell)
|
public async Task<IEnumerable<WellOperationDto>> GetOperationsAsync(int idWell)
|
||||||
{
|
{
|
||||||
var entities = db
|
var entities = await db.WellOperations.Where(o => o.IdWell == idWell)
|
||||||
.WellOperations
|
|
||||||
.Where(o => o.IdWell == idWell)
|
|
||||||
.AsNoTracking()
|
.AsNoTracking()
|
||||||
.ToList();
|
.ToListAsync();
|
||||||
|
|
||||||
var dtos = entities.Adapt<WellOperationDto>();
|
var dtos = entities.Adapt<WellOperationDto>();
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ using Microsoft.AspNetCore.Mvc;
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace AsbCloudWebApi.Controllers
|
namespace AsbCloudWebApi.Controllers
|
||||||
{
|
{
|
||||||
@ -35,15 +36,15 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Route("{idWell}/operationsByWell")]
|
[Route("{idWell}/operationsByWell")]
|
||||||
[ProducesResponseType(typeof(PaginationContainer<TelemetryOperationDto>), (int)System.Net.HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(PaginationContainer<TelemetryOperationDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||||
public IActionResult GetOperationsByWell(int idWell, int skip = 0, int take = 32,
|
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)
|
||||||
{
|
{
|
||||||
int? idCompany = User.GetCompanyId();
|
int? idCompany = User.GetCompanyId();
|
||||||
|
|
||||||
if (idCompany is null || !wellService.IsCompanyInvolvedInWell((int)idCompany, idWell))
|
if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell))
|
||||||
return Forbid();
|
return Forbid();
|
||||||
|
|
||||||
var analytics = analyticsService.GetOperationsByWell(idWell, categoryIds, begin, end, skip, take);
|
var analytics = await analyticsService.GetOperationsByWellAsync(idWell, categoryIds, begin, end, skip, take);
|
||||||
|
|
||||||
if (analytics is null || analytics.Count == 0)
|
if (analytics is null || analytics.Count == 0)
|
||||||
return NoContent();
|
return NoContent();
|
||||||
@ -59,14 +60,14 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Route("{idWell}/wellDepthToDay")]
|
[Route("{idWell}/wellDepthToDay")]
|
||||||
[ProducesResponseType(typeof(IEnumerable<WellDepthToDayDto>), (int)System.Net.HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(IEnumerable<WellDepthToDayDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||||
public IActionResult GetWellDepthToDay(int idWell)
|
public async Task<IActionResult> GetWellDepthToDayAsync(int idWell)
|
||||||
{
|
{
|
||||||
int? idCompany = User.GetCompanyId();
|
int? idCompany = User.GetCompanyId();
|
||||||
|
|
||||||
if (idCompany is null || !wellService.IsCompanyInvolvedInWell((int)idCompany, idWell))
|
if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell))
|
||||||
return Forbid();
|
return Forbid();
|
||||||
|
|
||||||
var wellDepthToDayData = analyticsService.GetWellDepthToDay(idWell);
|
var wellDepthToDayData = await analyticsService.GetWellDepthToDayAsync(idWell);
|
||||||
|
|
||||||
if (wellDepthToDayData is null || !wellDepthToDayData.Any())
|
if (wellDepthToDayData is null || !wellDepthToDayData.Any())
|
||||||
return NoContent();
|
return NoContent();
|
||||||
@ -84,15 +85,15 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Route("{idWell}/wellDepthToInterval")]
|
[Route("{idWell}/wellDepthToInterval")]
|
||||||
[ProducesResponseType(typeof(IEnumerable<WellDepthToIntervalDto>), (int)System.Net.HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(IEnumerable<WellDepthToIntervalDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||||
public IActionResult GetWellDepthToInterval(int idWell,
|
public async Task<IActionResult> GetWellDepthToIntervalAsync(int idWell,
|
||||||
int intervalSeconds, int workBeginSeconds)
|
int intervalSeconds, int workBeginSeconds)
|
||||||
{
|
{
|
||||||
int? idCompany = User.GetCompanyId();
|
int? idCompany = User.GetCompanyId();
|
||||||
|
|
||||||
if (idCompany is null || !wellService.IsCompanyInvolvedInWell((int)idCompany, idWell))
|
if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync ((int)idCompany, idWell))
|
||||||
return Forbid();
|
return Forbid();
|
||||||
|
|
||||||
var wellDepthToIntervalData = analyticsService.GetWellDepthToInterval(idWell,
|
var wellDepthToIntervalData = await analyticsService.GetWellDepthToIntervalAsync(idWell,
|
||||||
intervalSeconds, workBeginSeconds);
|
intervalSeconds, workBeginSeconds);
|
||||||
|
|
||||||
if (wellDepthToIntervalData is null || !wellDepthToIntervalData.Any())
|
if (wellDepthToIntervalData is null || !wellDepthToIntervalData.Any())
|
||||||
@ -111,14 +112,14 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Route("{idWell}/operationsSummary")]
|
[Route("{idWell}/operationsSummary")]
|
||||||
[ProducesResponseType(typeof(IEnumerable<TelemetryOperationDurationDto>), (int)System.Net.HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(IEnumerable<TelemetryOperationDurationDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||||
public IActionResult GetOperationsSummary(int idWell, DateTime begin = default, DateTime end = default)
|
public async Task<IActionResult> GetOperationsSummaryAsync(int idWell, DateTime begin = default, DateTime end = default)
|
||||||
{
|
{
|
||||||
int? idCompany = User.GetCompanyId();
|
int? idCompany = User.GetCompanyId();
|
||||||
|
|
||||||
if (idCompany is null || !wellService.IsCompanyInvolvedInWell((int)idCompany, idWell))
|
if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync ((int)idCompany, idWell))
|
||||||
return Forbid();
|
return Forbid();
|
||||||
|
|
||||||
var analytics = analyticsService.GetOperationsSummary(idWell, begin, end);
|
var analytics = await analyticsService .GetOperationsSummaryAsync(idWell, begin, end);
|
||||||
|
|
||||||
if (analytics is null || !analytics.Any())
|
if (analytics is null || !analytics.Any())
|
||||||
return NoContent();
|
return NoContent();
|
||||||
@ -136,15 +137,15 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Route("{idWell}/operationsToInterval")]
|
[Route("{idWell}/operationsToInterval")]
|
||||||
[ProducesResponseType(typeof(IEnumerable<TelemetryOperationDurationDto>), (int)System.Net.HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(IEnumerable<TelemetryOperationDurationDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||||
public IActionResult GetOperationsToInterval(int idWell,
|
public async Task<IActionResult> GetOperationsToIntervalAsync(int idWell,
|
||||||
int intervalSeconds, int workBeginSeconds)
|
int intervalSeconds, int workBeginSeconds)
|
||||||
{
|
{
|
||||||
int? idCompany = User.GetCompanyId();
|
int? idCompany = User.GetCompanyId();
|
||||||
|
|
||||||
if (idCompany is null || !wellService.IsCompanyInvolvedInWell((int)idCompany, idWell))
|
if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync ((int)idCompany, idWell))
|
||||||
return Forbid();
|
return Forbid();
|
||||||
|
|
||||||
var analytics = analyticsService.GetOperationsToInterval(idWell, intervalSeconds, workBeginSeconds);
|
var analytics = await analyticsService.GetOperationsToIntervalAsync(idWell, intervalSeconds, workBeginSeconds);
|
||||||
|
|
||||||
if (analytics is null || !analytics.Any())
|
if (analytics is null || !analytics.Any())
|
||||||
return NoContent();
|
return NoContent();
|
||||||
|
@ -3,6 +3,7 @@ using AsbCloudApp.Services;
|
|||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace AsbCloudWebApi.Controllers
|
namespace AsbCloudWebApi.Controllers
|
||||||
{
|
{
|
||||||
@ -27,14 +28,14 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpGet()]
|
[HttpGet()]
|
||||||
[ProducesResponseType(typeof(IEnumerable<ClusterDto>), (int)System.Net.HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(IEnumerable<ClusterDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||||
public IActionResult GetClusters()
|
public async Task<IActionResult> GetClustersAsync()
|
||||||
{
|
{
|
||||||
int? idCompany = User.GetCompanyId();
|
int? idCompany = User.GetCompanyId();
|
||||||
|
|
||||||
if (idCompany is null)
|
if (idCompany is null)
|
||||||
return Forbid();
|
return Forbid();
|
||||||
|
|
||||||
var result = clusterService.GetClusters((int)idCompany);
|
var result = await clusterService.GetClustersAsync((int)idCompany);
|
||||||
return Ok(result);
|
return Ok(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,14 +46,14 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpGet("{idCluster}")]
|
[HttpGet("{idCluster}")]
|
||||||
[ProducesResponseType(typeof(IEnumerable<WellDto>), (int)System.Net.HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(IEnumerable<WellDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||||
public IActionResult GetWells(int idCluster)
|
public async Task<IActionResult> GetWellsAsync(int idCluster)
|
||||||
{
|
{
|
||||||
int? idCompany = User.GetCompanyId();
|
int? idCompany = User.GetCompanyId();
|
||||||
|
|
||||||
if (idCompany is null)
|
if (idCompany is null)
|
||||||
return Forbid();
|
return Forbid();
|
||||||
|
|
||||||
var result = clusterService.GetWells((int)idCompany, idCluster);
|
var result = await clusterService.GetWellsAsync((int)idCompany, idCluster);
|
||||||
return Ok(result);
|
return Ok(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,14 +64,14 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpGet("{idCluster}/Stat")]
|
[HttpGet("{idCluster}/Stat")]
|
||||||
[ProducesResponseType(typeof(ClusterStatDto), (int)System.Net.HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(ClusterStatDto), (int)System.Net.HttpStatusCode.OK)]
|
||||||
public IActionResult GetStat(int idCluster)
|
public async Task<IActionResult> GetStatAsync(int idCluster)
|
||||||
{
|
{
|
||||||
int? idCompany = User.GetCompanyId();
|
int? idCompany = User.GetCompanyId();
|
||||||
|
|
||||||
if (idCompany is null)
|
if (idCompany is null)
|
||||||
return Forbid();
|
return Forbid();
|
||||||
|
|
||||||
var result = clusterService.GetStat((int)idCompany, idCluster);
|
var result = await clusterService.GetStatAsync((int)idCompany, idCluster);
|
||||||
return Ok(result);
|
return Ok(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ using Microsoft.AspNetCore.Mvc;
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace AsbCloudWebApi.Controllers
|
namespace AsbCloudWebApi.Controllers
|
||||||
{
|
{
|
||||||
@ -52,14 +53,14 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Route("{idWell}/dataDatesRange")]
|
[Route("{idWell}/dataDatesRange")]
|
||||||
[ProducesResponseType(typeof(DatesRangeDto), (int)System.Net.HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(DatesRangeDto), (int)System.Net.HttpStatusCode.OK)]
|
||||||
public IActionResult GetDataDatesRange(int idWell)
|
public async Task<IActionResult> GetDataDatesRangeAsync(int idWell)
|
||||||
{
|
{
|
||||||
int? idCompany = User.GetCompanyId();
|
int? idCompany = User.GetCompanyId();
|
||||||
|
|
||||||
if (idCompany is null)
|
if (idCompany is null)
|
||||||
return Forbid();
|
return Forbid();
|
||||||
|
|
||||||
bool isCompanyOwnsWell = wellService.IsCompanyInvolvedInWell((int)idCompany, idWell);
|
bool isCompanyOwnsWell = await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell);
|
||||||
|
|
||||||
if (!isCompanyOwnsWell)
|
if (!isCompanyOwnsWell)
|
||||||
return Forbid();
|
return Forbid();
|
||||||
|
@ -3,6 +3,7 @@ using AsbCloudApp.Services;
|
|||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace AsbCloudWebApi.Controllers
|
namespace AsbCloudWebApi.Controllers
|
||||||
{
|
{
|
||||||
@ -27,14 +28,14 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[ProducesResponseType(typeof(IEnumerable<DepositDto>), (int)System.Net.HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(IEnumerable<DepositDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||||
public IActionResult GetDeposits()
|
public async Task<IActionResult> GetDepositsAsync()
|
||||||
{
|
{
|
||||||
int? idCompany = User.GetCompanyId();
|
int? idCompany = User.GetCompanyId();
|
||||||
|
|
||||||
if (idCompany is null)
|
if (idCompany is null)
|
||||||
return Forbid();
|
return Forbid();
|
||||||
|
|
||||||
var result = clusterService.GetDeposits((int)idCompany);
|
var result = await clusterService.GetDepositsAsync((int)idCompany);
|
||||||
return Ok(result);
|
return Ok(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,14 +46,14 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpGet("{depositId}")]
|
[HttpGet("{depositId}")]
|
||||||
[ProducesResponseType(typeof(IEnumerable<ClusterDto>), (int)System.Net.HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(IEnumerable<ClusterDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||||
public IActionResult GetClusters(int depositId)
|
public async Task<IActionResult> GetClustersAsync(int depositId)
|
||||||
{
|
{
|
||||||
int? idCompany = User.GetCompanyId();
|
int? idCompany = User.GetCompanyId();
|
||||||
|
|
||||||
if (idCompany is null)
|
if (idCompany is null)
|
||||||
return Forbid();
|
return Forbid();
|
||||||
|
|
||||||
var result = clusterService.GetClusters((int)idCompany, depositId);
|
var result = await clusterService.GetClustersAsync((int)idCompany, depositId);
|
||||||
return Ok(result);
|
return Ok(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Mvc;
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace AsbCloudWebApi.Controllers
|
namespace AsbCloudWebApi.Controllers
|
||||||
{
|
{
|
||||||
@ -34,7 +35,7 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
[HttpPost]
|
[HttpPost]
|
||||||
[Route("{idWell}/files")]
|
[Route("{idWell}/files")]
|
||||||
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
||||||
public IActionResult SaveFiles(int idWell, int idCategory, int idUser,
|
public async Task<IActionResult> SaveFilesAsync(int idWell, int idCategory, int idUser,
|
||||||
[FromForm] IFormFileCollection files)
|
[FromForm] IFormFileCollection files)
|
||||||
{
|
{
|
||||||
int? idCompany = User.GetCompanyId();
|
int? idCompany = User.GetCompanyId();
|
||||||
@ -42,7 +43,7 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
if (idCompany is null)
|
if (idCompany is null)
|
||||||
return Forbid();
|
return Forbid();
|
||||||
|
|
||||||
if (!wellService.IsCompanyInvolvedInWell((int)idCompany, idWell))
|
if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell))
|
||||||
return Forbid();
|
return Forbid();
|
||||||
|
|
||||||
var fileInfoCollection = files.Select(f =>
|
var fileInfoCollection = files.Select(f =>
|
||||||
@ -81,13 +82,13 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Route("{idWell}")]
|
[Route("{idWell}")]
|
||||||
[ProducesResponseType(typeof(PaginationContainer<FilePropertiesDto>), (int)System.Net.HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(PaginationContainer<FilePropertiesDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||||
public IActionResult GetFilesInfo([FromRoute] int idWell,
|
public async Task<IActionResult> GetFilesInfoAsync([FromRoute] int idWell,
|
||||||
int skip = 0, int take = 32, int idCategory = default,
|
int skip = 0, int take = 32, int idCategory = default,
|
||||||
DateTime begin = default, DateTime end = default)
|
DateTime begin = default, DateTime end = default)
|
||||||
{
|
{
|
||||||
int? idCompany = User.GetCompanyId();
|
int? idCompany = User.GetCompanyId();
|
||||||
|
|
||||||
if (idCompany is null || !wellService.IsCompanyInvolvedInWell((int)idCompany, idWell))
|
if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell))
|
||||||
return Forbid();
|
return Forbid();
|
||||||
|
|
||||||
var filesInfo = fileService.GetFilesInfo(idWell, idCategory,
|
var filesInfo = fileService.GetFilesInfo(idWell, idCategory,
|
||||||
@ -108,7 +109,7 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Route("{idWell}/{fileId}")]
|
[Route("{idWell}/{fileId}")]
|
||||||
[ProducesResponseType(typeof(PhysicalFileResult), (int)System.Net.HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(PhysicalFileResult), (int)System.Net.HttpStatusCode.OK)]
|
||||||
public IActionResult GetFile([FromRoute] int idWell, int fileId)
|
public async Task<IActionResult> GetFileAsync([FromRoute] int idWell, int fileId)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -117,7 +118,7 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
if (idCompany is null)
|
if (idCompany is null)
|
||||||
return Forbid();
|
return Forbid();
|
||||||
|
|
||||||
if (!wellService.IsCompanyInvolvedInWell((int)idCompany, idWell))
|
if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell))
|
||||||
return Forbid();
|
return Forbid();
|
||||||
|
|
||||||
var fileInfo = fileService.GetFileInfo(fileId);
|
var fileInfo = fileService.GetFileInfo(fileId);
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using AsbCloudApp.Services;
|
using AsbCloudApp.Services;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace AsbCloudWebApi.Controllers
|
namespace AsbCloudWebApi.Controllers
|
||||||
{
|
{
|
||||||
@ -18,11 +19,11 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public IActionResult Get([FromRoute] int idWell, [FromQuery] int idCategory)
|
public async Task<IActionResult> GetAsync([FromRoute] int idWell, [FromQuery] int idCategory)
|
||||||
{
|
{
|
||||||
int? idCompany = User.GetCompanyId();
|
int? idCompany = User.GetCompanyId();
|
||||||
|
|
||||||
if (idCompany is null || !wellService.IsCompanyInvolvedInWell((int)idCompany, idWell))
|
if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell))
|
||||||
return Forbid();
|
return Forbid();
|
||||||
|
|
||||||
var result = lastDataService.Get(idWell, idCategory);
|
var result = lastDataService.Get(idWell, idCategory);
|
||||||
@ -30,11 +31,11 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public IActionResult Put([FromRoute] int idWell, [FromQuery] int idCategory, T data)
|
public async Task<IActionResult> PutAsync([FromRoute] int idWell, [FromQuery] int idCategory, T data)
|
||||||
{
|
{
|
||||||
int? idCompany = User.GetCompanyId();
|
int? idCompany = User.GetCompanyId();
|
||||||
|
|
||||||
if (idCompany is null || !wellService.IsCompanyInvolvedInWell((int)idCompany, idWell))
|
if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell))
|
||||||
return Forbid();
|
return Forbid();
|
||||||
|
|
||||||
lastDataService.Upsert(idWell, idCategory, data);
|
lastDataService.Upsert(idWell, idCategory, data);
|
||||||
|
@ -3,6 +3,7 @@ using AsbCloudApp.Services;
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace AsbCloudWebApi.Controllers
|
namespace AsbCloudWebApi.Controllers
|
||||||
{
|
{
|
||||||
@ -51,14 +52,14 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Route("{idWell}/messagesDatesRange")]
|
[Route("{idWell}/messagesDatesRange")]
|
||||||
[ProducesResponseType(typeof(DatesRangeDto), (int)System.Net.HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(DatesRangeDto), (int)System.Net.HttpStatusCode.OK)]
|
||||||
public IActionResult GetMessagesDateRange(int idWell)
|
public async Task<IActionResult> GetMessagesDateRangeAsync(int idWell)
|
||||||
{
|
{
|
||||||
int? idCompany = User.GetCompanyId();
|
int? idCompany = User.GetCompanyId();
|
||||||
|
|
||||||
if (idCompany is null)
|
if (idCompany is null)
|
||||||
return Forbid();
|
return Forbid();
|
||||||
|
|
||||||
bool isCompanyOwnsWell = wellService.IsCompanyInvolvedInWell((int)idCompany, idWell);
|
bool isCompanyOwnsWell = await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell);
|
||||||
|
|
||||||
if (!isCompanyOwnsWell)
|
if (!isCompanyOwnsWell)
|
||||||
return Forbid();
|
return Forbid();
|
||||||
|
@ -64,7 +64,7 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
[HttpPost]
|
[HttpPost]
|
||||||
[Route("{idWell}/report")]
|
[Route("{idWell}/report")]
|
||||||
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
||||||
public IActionResult CreateReport(int idWell, int idUser, int stepSeconds, int format,
|
public async Task<IActionResult> CreateReportAsync(int idWell, int idUser, int stepSeconds, int format,
|
||||||
DateTime begin = default, DateTime end = default)
|
DateTime begin = default, DateTime end = default)
|
||||||
{
|
{
|
||||||
int? idCompany = User.GetCompanyId();
|
int? idCompany = User.GetCompanyId();
|
||||||
@ -72,7 +72,7 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
if (idCompany is null)
|
if (idCompany is null)
|
||||||
return Forbid();
|
return Forbid();
|
||||||
|
|
||||||
if (!wellService.IsCompanyInvolvedInWell((int)idCompany, idWell))
|
if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell))
|
||||||
return Forbid();
|
return Forbid();
|
||||||
|
|
||||||
var id = reportService.CreateReport(idWell, idUser,
|
var id = reportService.CreateReport(idWell, idUser,
|
||||||
@ -90,7 +90,7 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Route("{idWell}/{reportName}")]
|
[Route("{idWell}/{reportName}")]
|
||||||
[ProducesResponseType(typeof(PhysicalFileResult), (int)System.Net.HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(PhysicalFileResult), (int)System.Net.HttpStatusCode.OK)]
|
||||||
public IActionResult GetReport([FromRoute] int idWell, string reportName)
|
public async Task<IActionResult> GetReportAsync([FromRoute] int idWell, string reportName)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -99,7 +99,7 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
if (idCompany is null)
|
if (idCompany is null)
|
||||||
return Forbid();
|
return Forbid();
|
||||||
|
|
||||||
if (!wellService.IsCompanyInvolvedInWell((int)idCompany, idWell))
|
if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell))
|
||||||
return Forbid();
|
return Forbid();
|
||||||
// TODO: словарь content typoв
|
// TODO: словарь content typoв
|
||||||
var relativePath = Path.Combine(fileService.RootPath, $"{idWell}",
|
var relativePath = Path.Combine(fileService.RootPath, $"{idWell}",
|
||||||
@ -148,14 +148,14 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Route("{idWell}/reportSize")]
|
[Route("{idWell}/reportSize")]
|
||||||
[ProducesResponseType(typeof(string), (int)System.Net.HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(string), (int)System.Net.HttpStatusCode.OK)]
|
||||||
public IActionResult GetReportSize(int idWell, int stepSeconds, int format, DateTime begin = default, DateTime end = default)
|
public async Task<IActionResult> GetReportSizeAsync(int idWell, int stepSeconds, int format, DateTime begin = default, DateTime end = default)
|
||||||
{
|
{
|
||||||
int? idCompany = User.GetCompanyId();
|
int? idCompany = User.GetCompanyId();
|
||||||
|
|
||||||
if (idCompany is null)
|
if (idCompany is null)
|
||||||
return Forbid();
|
return Forbid();
|
||||||
|
|
||||||
if (!wellService.IsCompanyInvolvedInWell((int)idCompany, idWell))
|
if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell))
|
||||||
return Forbid();
|
return Forbid();
|
||||||
|
|
||||||
int reportSize = reportService.GetReportPagesCount(idWell, begin, end, stepSeconds, format);
|
int reportSize = reportService.GetReportPagesCount(idWell, begin, end, stepSeconds, format);
|
||||||
@ -171,14 +171,14 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Route("{idWell}/reportsDatesRange")]
|
[Route("{idWell}/reportsDatesRange")]
|
||||||
[ProducesResponseType(typeof(DatesRangeDto), (int)System.Net.HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(DatesRangeDto), (int)System.Net.HttpStatusCode.OK)]
|
||||||
public IActionResult GetReportsDateRange(int idWell)
|
public async Task<IActionResult> GetReportsDateRangeAsync(int idWell)
|
||||||
{
|
{
|
||||||
int? idCompany = User.GetCompanyId();
|
int? idCompany = User.GetCompanyId();
|
||||||
|
|
||||||
if (idCompany is null)
|
if (idCompany is null)
|
||||||
return Forbid();
|
return Forbid();
|
||||||
|
|
||||||
if (!wellService.IsCompanyInvolvedInWell((int)idCompany, idWell))
|
if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell))
|
||||||
return Forbid();
|
return Forbid();
|
||||||
|
|
||||||
DatesRangeDto wellReportsDatesRange = reportService.GetReportsDatesRange(idWell);
|
DatesRangeDto wellReportsDatesRange = reportService.GetReportsDatesRange(idWell);
|
||||||
|
@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Authorization;
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace AsbCloudWebApi.Controllers
|
namespace AsbCloudWebApi.Controllers
|
||||||
{
|
{
|
||||||
@ -21,7 +22,7 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[ProducesResponseType(typeof(IEnumerable<WellDto>), (int)System.Net.HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(IEnumerable<WellDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||||
public IActionResult GetWells()
|
public async Task<IActionResult> GetWellsAsync()
|
||||||
{
|
{
|
||||||
var idCompany = User.GetCompanyId();
|
var idCompany = User.GetCompanyId();
|
||||||
|
|
||||||
@ -30,7 +31,7 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
return NoContent();
|
return NoContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
var wells = wellService.GetWellsByCompany((int)idCompany);
|
var wells = await wellService.GetWellsByCompanyAsync((int)idCompany);
|
||||||
|
|
||||||
if (wells is null || !wells.Any())
|
if (wells is null || !wells.Any())
|
||||||
return NoContent();
|
return NoContent();
|
||||||
@ -40,31 +41,31 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
|
|
||||||
[HttpGet("{idWell}/operations")]
|
[HttpGet("{idWell}/operations")]
|
||||||
[ProducesResponseType(typeof(IEnumerable<WellOperationDto>), (int)System.Net.HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(IEnumerable<WellOperationDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||||
public IActionResult GetOperations(int idWell)
|
public async Task<IActionResult> GetOperationsAsync(int idWell)
|
||||||
{
|
{
|
||||||
var idCompany = User.GetCompanyId();
|
var idCompany = User.GetCompanyId();
|
||||||
|
|
||||||
if (idCompany is null)
|
if (idCompany is null)
|
||||||
return NoContent();
|
return NoContent();
|
||||||
|
|
||||||
if (!wellService.IsCompanyInvolvedInWell((int)idCompany, idWell))
|
if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell))
|
||||||
return Forbid();
|
return Forbid();
|
||||||
|
|
||||||
var dto = wellService.GetOperations(idWell);
|
var dto = await wellService.GetOperationsAsync(idWell);
|
||||||
|
|
||||||
return Ok(dto);
|
return Ok(dto);
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("transmittingWells")]
|
[HttpGet("transmittingWells")]
|
||||||
[ProducesResponseType(typeof(IEnumerable<WellDto>), (int)System.Net.HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(IEnumerable<WellDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||||
public IActionResult GetTransmittingWells()
|
public async Task<IActionResult> GetTransmittingWellsAsync()
|
||||||
{
|
{
|
||||||
var idCompany = User.GetCompanyId();
|
var idCompany = User.GetCompanyId();
|
||||||
|
|
||||||
if (idCompany is null)
|
if (idCompany is null)
|
||||||
return NoContent();
|
return NoContent();
|
||||||
|
|
||||||
var transmittingWells = wellService.GetTransmittingWells((int)idCompany);
|
var transmittingWells = await wellService.GetTransmittingWellsAsync((int)idCompany);
|
||||||
|
|
||||||
if (transmittingWells is null || !transmittingWells.Any())
|
if (transmittingWells is null || !transmittingWells.Any())
|
||||||
return NoContent();
|
return NoContent();
|
||||||
|
@ -25,7 +25,7 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
[HttpGet]
|
[HttpGet]
|
||||||
public async Task<IActionResult> GetAllAsync(int idWell, int skip = 0, int take = 32, CancellationToken token = default)
|
public async Task<IActionResult> GetAllAsync(int idWell, int skip = 0, int take = 32, CancellationToken token = default)
|
||||||
{
|
{
|
||||||
if(!CanUserAccessToWell(idWell))
|
if(!await CanUserAccessToWellAsync(idWell))
|
||||||
return Forbid();
|
return Forbid();
|
||||||
|
|
||||||
var result = await sectionsService.GetAllByWellIdAsync(idWell, skip, take, token).ConfigureAwait(false);
|
var result = await sectionsService.GetAllByWellIdAsync(idWell, skip, take, token).ConfigureAwait(false);
|
||||||
@ -36,7 +36,7 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
[Route("{idSection}")]
|
[Route("{idSection}")]
|
||||||
public async Task<IActionResult> GetAsync(int idSection, int idWell, CancellationToken token = default)
|
public async Task<IActionResult> GetAsync(int idSection, int idWell, CancellationToken token = default)
|
||||||
{
|
{
|
||||||
if (!CanUserAccessToWell(idWell))
|
if (!await CanUserAccessToWellAsync(idWell))
|
||||||
return Forbid();
|
return Forbid();
|
||||||
|
|
||||||
var result = await sectionsService.GetAsync(idSection, token).ConfigureAwait(false);
|
var result = await sectionsService.GetAsync(idSection, token).ConfigureAwait(false);
|
||||||
@ -44,9 +44,9 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public async Task<IActionResult> Insert(int idWell, [FromBody] IEnumerable<WellSectionDto> values, CancellationToken token = default)
|
public async Task<IActionResult> InsertAsync(int idWell, [FromBody] IEnumerable<WellSectionDto> values, CancellationToken token = default)
|
||||||
{
|
{
|
||||||
if (!CanUserAccessToWell(idWell))
|
if (!await CanUserAccessToWellAsync(idWell))
|
||||||
return Forbid();
|
return Forbid();
|
||||||
|
|
||||||
var result = await sectionsService.InsertRangeAsync(values, idWell, token).ConfigureAwait(false);
|
var result = await sectionsService.InsertRangeAsync(values, idWell, token).ConfigureAwait(false);
|
||||||
@ -54,9 +54,9 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpPut("{id}")]
|
[HttpPut("{id}")]
|
||||||
public async Task<IActionResult> Put(int id, int idWell, [FromBody] WellSectionDto value, CancellationToken token = default)
|
public async Task<IActionResult> PutAsync(int id, int idWell, [FromBody] WellSectionDto value, CancellationToken token = default)
|
||||||
{
|
{
|
||||||
if (!CanUserAccessToWell(idWell))
|
if (!await CanUserAccessToWellAsync(idWell))
|
||||||
return Forbid();
|
return Forbid();
|
||||||
|
|
||||||
var result = await sectionsService.UpdateAsync(value, id, idWell, token).ConfigureAwait(false);
|
var result = await sectionsService.UpdateAsync(value, id, idWell, token).ConfigureAwait(false);
|
||||||
@ -64,19 +64,19 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpDelete("{id}")]
|
[HttpDelete("{id}")]
|
||||||
public async Task<IActionResult> Delete(int id, int idWell, CancellationToken token = default)
|
public async Task<IActionResult> DeleteAsync(int id, int idWell, CancellationToken token = default)
|
||||||
{
|
{
|
||||||
if (!CanUserAccessToWell(idWell))
|
if (!await CanUserAccessToWellAsync(idWell))
|
||||||
return Forbid();
|
return Forbid();
|
||||||
|
|
||||||
var result = await sectionsService.DeleteAsync(new int[] { id }, token).ConfigureAwait(false);
|
var result = await sectionsService.DeleteAsync(new int[] { id }, token).ConfigureAwait(false);
|
||||||
return Ok(result);
|
return Ok(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool CanUserAccessToWell(int idWell)
|
private async Task<bool> CanUserAccessToWellAsync(int idWell)
|
||||||
{
|
{
|
||||||
int? idCompany = User.GetCompanyId();
|
int? idCompany = User.GetCompanyId();
|
||||||
return idCompany is not null && wellService.IsCompanyInvolvedInWell((int)idCompany, idWell);
|
return idCompany is not null && await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user