forked from ddrilling/AsbCloudServer
Merge branch 'dev' into feature/manuals
This commit is contained in:
commit
8c3f21221b
@ -87,10 +87,5 @@ namespace AsbCloudApp.Data.ProcessMap
|
||||
/// Плановый процент использования spin master
|
||||
/// </summary>
|
||||
public double UsageSpin { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// DTO типа секции
|
||||
/// </summary>
|
||||
public WellSectionTypeDto WellSectionType { get; set; } = null!;
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,23 @@ using System.Linq;
|
||||
|
||||
namespace AsbCloudApp.Data
|
||||
{
|
||||
/// <summary>
|
||||
/// базовая информация о скважине
|
||||
/// </summary>
|
||||
public class WellWithTimezoneDto : WellInfoDto
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
[Required]
|
||||
public SimpleTimezoneDto Timezone { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// 0 - неизвестно,
|
||||
/// 1 - в работе,
|
||||
/// 2 - завершена
|
||||
/// </summary>
|
||||
public int IdState { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Скважина
|
||||
/// </summary>
|
||||
|
41
AsbCloudApp/Data/WellboreDto.cs
Normal file
41
AsbCloudApp/Data/WellboreDto.cs
Normal file
@ -0,0 +1,41 @@
|
||||
using System;
|
||||
|
||||
namespace AsbCloudApp.Data;
|
||||
|
||||
/// <summary>
|
||||
/// Ствол скважины
|
||||
/// </summary>
|
||||
public class WellboreDto
|
||||
{
|
||||
public WellWithTimezoneDto Well { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Идентификатор
|
||||
/// </summary>
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Название
|
||||
/// </summary>
|
||||
public string Name { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Начальная глубина ствола
|
||||
/// </summary>
|
||||
public double DepthStart { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Конечная глубина скважины
|
||||
/// </summary>
|
||||
public double DepthEnd { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Дата начала первой операции
|
||||
/// </summary>
|
||||
public DateTimeOffset DateStart { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Дата завершения последней операции
|
||||
/// </summary>
|
||||
public DateTimeOffset DateEnd { get; set; }
|
||||
}
|
14
AsbCloudApp/Requests/WellboreRequest.cs
Normal file
14
AsbCloudApp/Requests/WellboreRequest.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AsbCloudApp.Requests;
|
||||
|
||||
/// <summary>
|
||||
/// Параметры запроса для ствола скважины
|
||||
/// </summary>
|
||||
public class WellboreRequest : RequestBase
|
||||
{
|
||||
/// <summary>
|
||||
/// Пары идентификаторов скважины и секции
|
||||
/// </summary>
|
||||
public IEnumerable<(int idWell, int? idSection)> Ids { get; set; } = null!;
|
||||
}
|
@ -31,6 +31,14 @@ public interface IAutoGeneratedDailyReportService
|
||||
/// <param name="reportDate"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<(string fileName, Stream stream)> GenerateReportAsync(int idWell, DateOnly reportDate,
|
||||
Task<(string fileName, Stream stream)> GenerateAsync(int idWell, DateOnly reportDate,
|
||||
CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Получение диапазона дат
|
||||
/// </summary>
|
||||
/// <param name="idWell"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<DatesRangeDto?> GetDatesRangeAsync(int idWell, CancellationToken cancellationToken);
|
||||
}
|
@ -26,6 +26,16 @@ namespace AsbCloudApp.Services
|
||||
DateTime dateBegin = default, double intervalSec = 600d,
|
||||
int approxPointsCount = 1024, CancellationToken token = default);
|
||||
|
||||
/// <summary>
|
||||
/// Получение статистики за период
|
||||
/// </summary>
|
||||
/// <param name="idWell"></param>
|
||||
/// <param name="start"></param>
|
||||
/// <param name="end"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
Task<DatesRangeDto?> GetRangeAsync(int idWell, DateTimeOffset start, DateTimeOffset end, CancellationToken token);
|
||||
|
||||
/// <summary>
|
||||
/// добавить/изменить данные тех. процесса (используется панелью)
|
||||
/// </summary>
|
||||
|
30
AsbCloudApp/Services/IWellboreService.cs
Normal file
30
AsbCloudApp/Services/IWellboreService.cs
Normal file
@ -0,0 +1,30 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Requests;
|
||||
|
||||
namespace AsbCloudApp.Services;
|
||||
|
||||
/// <summary>
|
||||
/// Сервис для ствола скважины
|
||||
/// </summary>
|
||||
public interface IWellboreService
|
||||
{
|
||||
/// <summary>
|
||||
/// Получение ствола скважины
|
||||
/// </summary>
|
||||
/// <param name="idWell"></param>
|
||||
/// <param name="idSection"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<WellboreDto?> GetWellboreAsync(int idWell, int idSection, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Получение стволов скважин
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<IEnumerable<WellboreDto>> GetWellboresAsync(WellboreRequest request, CancellationToken cancellationToken);
|
||||
}
|
@ -227,6 +227,8 @@ namespace AsbCloudInfrastructure
|
||||
services.AddTransient<IManualRepository, ManualRepository>();
|
||||
services.AddTransient<IFileCategoryRepository, FileCategoryRepository>();
|
||||
|
||||
services.AddTransient<IWellboreService, WellboreService>();
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,6 @@ using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Data.AutogeneratedDailyReport;
|
||||
using AsbCloudApp.Data.SAUB;
|
||||
using AsbCloudApp.Data.Subsystems;
|
||||
using AsbCloudApp.Exceptions;
|
||||
using AsbCloudApp.Repositories;
|
||||
@ -15,7 +14,6 @@ using AsbCloudApp.Services;
|
||||
using AsbCloudApp.Services.AutoGeneratedDailyReports;
|
||||
using AsbCloudApp.Services.Subsystems;
|
||||
using AsbCloudDb.Model;
|
||||
using AsbCloudInfrastructure.Services.SAUB;
|
||||
|
||||
namespace AsbCloudInfrastructure.Services.AutoGeneratedDailyReports;
|
||||
|
||||
@ -25,7 +23,6 @@ public class AutoGeneratedDailyReportService : IAutoGeneratedDailyReportService
|
||||
|
||||
private readonly IWellService wellService;
|
||||
private readonly IWellOperationRepository wellOperationRepository;
|
||||
private readonly TelemetryDataCache<TelemetryDataSaubDto> telemetryDataCache;
|
||||
private readonly ISubsystemOperationTimeService subsystemOperationTimeService;
|
||||
private readonly ICrudRepository<SubsystemDto> subsystemRepository;
|
||||
private readonly ILimitingParameterService limitingParameterService;
|
||||
@ -33,7 +30,6 @@ public class AutoGeneratedDailyReportService : IAutoGeneratedDailyReportService
|
||||
|
||||
public AutoGeneratedDailyReportService(IWellService wellService,
|
||||
IWellOperationRepository wellOperationRepository,
|
||||
TelemetryDataCache<TelemetryDataSaubDto> telemetryDataCache,
|
||||
ISubsystemOperationTimeService subsystemOperationTimeService,
|
||||
ICrudRepository<SubsystemDto> subsystemRepository,
|
||||
ILimitingParameterService limitingParameterService,
|
||||
@ -41,7 +37,6 @@ public class AutoGeneratedDailyReportService : IAutoGeneratedDailyReportService
|
||||
{
|
||||
this.wellOperationRepository = wellOperationRepository;
|
||||
this.wellService = wellService;
|
||||
this.telemetryDataCache = telemetryDataCache;
|
||||
this.subsystemOperationTimeService = subsystemOperationTimeService;
|
||||
this.subsystemRepository = subsystemRepository;
|
||||
this.limitingParameterService = limitingParameterService;
|
||||
@ -67,12 +62,10 @@ public class AutoGeneratedDailyReportService : IAutoGeneratedDailyReportService
|
||||
if (!well.IdTelemetry.HasValue)
|
||||
throw new ArgumentInvalidException("Телеметрия для скважины отсутствует", nameof(idWell));
|
||||
|
||||
var datesRange = telemetryDataCache.GetOrDefaultDataDateRange(well.IdTelemetry.Value);
|
||||
|
||||
if (datesRange is null)
|
||||
var datesRange = await GetDatesRangeAsync(idWell, cancellationToken);
|
||||
|
||||
if (datesRange is null)
|
||||
return result;
|
||||
|
||||
result.Count = (int)(Math.Ceiling((datesRange.To - DateTime.UnixEpoch).TotalDays) - Math.Floor((datesRange.From - DateTime.UnixEpoch).TotalDays));
|
||||
|
||||
if (request.StartDate.HasValue)
|
||||
{
|
||||
@ -92,6 +85,9 @@ public class AutoGeneratedDailyReportService : IAutoGeneratedDailyReportService
|
||||
datesRange.To = finishDate;
|
||||
}
|
||||
|
||||
if (datesRange.From.AddDays(result.Skip) <= datesRange.To)
|
||||
result.Count = (int)(Math.Ceiling((datesRange.To - DateTime.UnixEpoch).TotalDays) - Math.Floor((datesRange.From - DateTime.UnixEpoch).TotalDays));
|
||||
|
||||
for (int day = result.Skip; (day - result.Skip) < result.Take && (datesRange.From.AddDays(day)) <= datesRange.To; day++)
|
||||
{
|
||||
var reportDate = DateOnly.FromDateTime(datesRange.From.AddDays(day));
|
||||
@ -109,7 +105,7 @@ public class AutoGeneratedDailyReportService : IAutoGeneratedDailyReportService
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<(string fileName, Stream stream)> GenerateReportAsync(int idWell, DateOnly reportDate,
|
||||
public async Task<(string fileName, Stream stream)> GenerateAsync(int idWell, DateOnly reportDate,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var startDate = new DateTime(reportDate.Year, reportDate.Month, reportDate.Day);
|
||||
@ -144,6 +140,21 @@ public class AutoGeneratedDailyReportService : IAutoGeneratedDailyReportService
|
||||
return (report.FileName, stream);
|
||||
}
|
||||
|
||||
public async Task<DatesRangeDto?> GetDatesRangeAsync(int idWell, CancellationToken cancellationToken)
|
||||
{
|
||||
var factOperations = await GetFactOperationsAsync(idWell, null, null,
|
||||
cancellationToken);
|
||||
|
||||
if (!factOperations.Any())
|
||||
return null;
|
||||
|
||||
return new DatesRangeDto
|
||||
{
|
||||
From = factOperations.Min(o => o.DateStart).Date,
|
||||
To = factOperations.Max(o => o.DateStart).Date
|
||||
};
|
||||
}
|
||||
|
||||
private HeadBlockDto CreateHeadBlock(WellDto well, IEnumerable<WellOperationDto> factOperations)
|
||||
{
|
||||
var customer = well.Companies.FirstOrDefault(company => company.IdCompanyType == 1);
|
||||
@ -199,8 +210,8 @@ public class AutoGeneratedDailyReportService : IAutoGeneratedDailyReportService
|
||||
});
|
||||
}
|
||||
|
||||
private Task<IEnumerable<WellOperationDto>> GetFactOperationsAsync(int idWell, DateTime startDate,
|
||||
DateTime finishDate, CancellationToken cancellationToken)
|
||||
private async Task<IOrderedEnumerable<WellOperationDto>> GetFactOperationsAsync(int idWell, DateTime? startDate,
|
||||
DateTime? finishDate, CancellationToken cancellationToken)
|
||||
{
|
||||
var request = new WellOperationRequest
|
||||
{
|
||||
@ -211,7 +222,8 @@ public class AutoGeneratedDailyReportService : IAutoGeneratedDailyReportService
|
||||
SortFields = new[] { "DateStart asc" },
|
||||
};
|
||||
|
||||
return wellOperationRepository.GetAsync(request, cancellationToken);
|
||||
return (await wellOperationRepository.GetAsync(request, cancellationToken))
|
||||
.OrderBy(w => w.DateStart);
|
||||
}
|
||||
|
||||
private Task<IEnumerable<SubsystemStatDto>?> GetSubsystemStatsAsync(int idWell, DateTime startDate,
|
||||
|
@ -75,6 +75,8 @@ public class ProcessMapPlanImportService : IProcessMapPlanImportService
|
||||
|
||||
public async Task<Stream> ExportAsync(int idWell, CancellationToken cancellationToken)
|
||||
{
|
||||
sections = (await wellSectionTypeRepository.GetAllAsync(cancellationToken)).ToArray();
|
||||
|
||||
var processMapPlans = (await processMapPlanRepository.GetByIdWellAsync(idWell,
|
||||
cancellationToken)).ToArray();
|
||||
|
||||
@ -120,7 +122,7 @@ public class ProcessMapPlanImportService : IProcessMapPlanImportService
|
||||
|
||||
private void AddToRow(IXLRow row, ProcessMapPlanDto processMap)
|
||||
{
|
||||
row.Cell(columnWellSectionType).Value = processMap.WellSectionType.Caption;
|
||||
row.Cell(columnWellSectionType).Value = sections.First(x => x.Id == processMap.IdWellSectionType).Caption;
|
||||
row.Cell(columnMode).Value = GetModeCaption(processMap.IdMode);
|
||||
row.Cell(columnDepthStart).Value = processMap.DepthStart;
|
||||
row.Cell(columnDepthEnd).Value = processMap.DepthEnd;
|
||||
|
@ -1,4 +1,5 @@
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudDb;
|
||||
using AsbCloudDb.Model;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
@ -13,7 +14,7 @@ namespace AsbCloudInfrastructure.Services.SAUB
|
||||
{
|
||||
public abstract class TelemetryDataBaseService<TDto, TEntity> : ITelemetryDataService<TDto>
|
||||
where TDto : AsbCloudApp.Data.ITelemetryData
|
||||
where TEntity : class, ITelemetryData
|
||||
where TEntity : class, AsbCloudDb.Model.ITelemetryData
|
||||
{
|
||||
protected readonly IAsbCloudDbContext db;
|
||||
protected readonly ITelemetryService telemetryService;
|
||||
@ -146,6 +147,44 @@ namespace AsbCloudInfrastructure.Services.SAUB
|
||||
return dtos;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public virtual async Task<DatesRangeDto?> GetRangeAsync(
|
||||
int idWell,
|
||||
DateTimeOffset start,
|
||||
DateTimeOffset end,
|
||||
CancellationToken token)
|
||||
{
|
||||
var telemetry = telemetryService.GetOrDefaultTelemetryByIdWell(idWell);
|
||||
if (telemetry is null)
|
||||
return default;
|
||||
|
||||
var timezone = telemetryService.GetTimezone(telemetry.Id);
|
||||
var startUtc = start.ToOffset(TimeSpan.Zero);
|
||||
var endUtc = end.ToOffset(TimeSpan.Zero);
|
||||
|
||||
var dbSet = db.Set<TEntity>();
|
||||
var query = dbSet
|
||||
.Where(i => i.IdTelemetry == telemetry.Id)
|
||||
.Where(i => i.DateTime >= startUtc)
|
||||
.Where(i => i.DateTime <= endUtc)
|
||||
.GroupBy(i => i.IdTelemetry)
|
||||
.Select(g => new
|
||||
{
|
||||
DateStart = g.Min(i => i.DateTime),
|
||||
DateEnd = g.Max(i => i.DateTime),
|
||||
});
|
||||
|
||||
var data = await query.FirstOrDefaultAsync(token);
|
||||
if (data is null)
|
||||
return default;
|
||||
|
||||
return new DatesRangeDto
|
||||
{
|
||||
From = data.DateStart.ToRemoteDateTime(timezone.Hours),
|
||||
To = data.DateEnd.ToRemoteDateTime(timezone.Hours),
|
||||
};
|
||||
}
|
||||
|
||||
public abstract TDto Convert(TEntity src, double timezoneOffset);
|
||||
|
||||
public abstract TEntity Convert(TDto src, double timezoneOffset);
|
||||
|
@ -29,18 +29,21 @@ namespace AsbCloudInfrastructure.Services
|
||||
{
|
||||
Caption = c.Caption,
|
||||
Id = c.Id,
|
||||
Users = c.Users.Select(u => new UserContactDto()
|
||||
{
|
||||
Id = u.Id,
|
||||
Name = u.Name,
|
||||
Patronymic = u.Patronymic,
|
||||
Surname = u.Surname,
|
||||
Company = u.Company.Adapt<CompanyDto>(),
|
||||
Email = u.Email,
|
||||
Phone = u.Phone,
|
||||
Position = u.Position,
|
||||
IsContact = u.RelationContactsWells.Any(rel => rel.IdWell == wellId)
|
||||
})
|
||||
Users = c.Users
|
||||
.Where(u => u.IdState == 1)
|
||||
.OrderBy(u => u.Surname)
|
||||
.Select(u => new UserContactDto()
|
||||
{
|
||||
Id = u.Id,
|
||||
Name = u.Name,
|
||||
Patronymic = u.Patronymic,
|
||||
Surname = u.Surname,
|
||||
Company = u.Company.Adapt<CompanyDto>(),
|
||||
Email = u.Email,
|
||||
Phone = u.Phone,
|
||||
Position = u.Position,
|
||||
IsContact = u.RelationContactsWells.Any(rel => rel.IdWell == wellId)
|
||||
})
|
||||
});
|
||||
|
||||
var entities = await query.AsNoTracking()
|
||||
|
91
AsbCloudInfrastructure/Services/WellboreService.cs
Normal file
91
AsbCloudInfrastructure/Services/WellboreService.cs
Normal file
@ -0,0 +1,91 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Repositories;
|
||||
using AsbCloudApp.Requests;
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudDb.Model;
|
||||
using Mapster;
|
||||
|
||||
namespace AsbCloudInfrastructure.Services;
|
||||
|
||||
public class WellboreService : IWellboreService
|
||||
{
|
||||
private readonly IWellService wellService;
|
||||
private readonly IWellOperationRepository wellOperationRepository;
|
||||
|
||||
public WellboreService(IWellService wellService, IWellOperationRepository wellOperationRepository)
|
||||
{
|
||||
this.wellService = wellService;
|
||||
this.wellOperationRepository = wellOperationRepository;
|
||||
}
|
||||
|
||||
public async Task<WellboreDto?> GetWellboreAsync(int idWell, int idSection, CancellationToken cancellationToken)
|
||||
{
|
||||
var request = new WellboreRequest
|
||||
{
|
||||
Ids = new (int, int?)[] { (idWell, idSection) },
|
||||
Take = 1,
|
||||
};
|
||||
var data = await GetWellboresAsync(request, cancellationToken);
|
||||
return data.FirstOrDefault();
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<WellboreDto>> GetWellboresAsync(WellboreRequest request,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var wellbores = new List<WellboreDto>(request.Ids.Count());
|
||||
var skip = request.Skip ?? 0;
|
||||
var take = request.Take ?? 10;
|
||||
|
||||
var sections = wellOperationRepository.GetSectionTypes()
|
||||
.ToDictionary(w => w.Id, w => w);
|
||||
|
||||
var ids = request.Ids.GroupBy(i => i.idWell);
|
||||
|
||||
foreach (var id in ids)
|
||||
{
|
||||
var well = await wellService.GetOrDefaultAsync(id.Key, cancellationToken);
|
||||
|
||||
if (well is null)
|
||||
continue;
|
||||
|
||||
var wellOperations = await GetFactOperationsAsync(well.Id, id.Select(i => i.idSection), cancellationToken);
|
||||
var groupedOperations = wellOperations.GroupBy(o => o.IdWellSectionType);
|
||||
var wellWellbores = groupedOperations.Select(group => new WellboreDto {
|
||||
Id = group.Key,
|
||||
Name = sections[group.Key].Caption,
|
||||
Well = well.Adapt<WellWithTimezoneDto>(),
|
||||
DateStart = group.Min(operation => operation.DateStart),
|
||||
DateEnd = group.Max(operation => operation.DateStart.AddHours(operation.DurationHours)),
|
||||
DepthStart = group.Min(operation => operation.DepthStart),
|
||||
DepthEnd = group.Max(operation => operation.DepthEnd),
|
||||
});
|
||||
wellbores.AddRange(wellWellbores);
|
||||
}
|
||||
|
||||
return wellbores
|
||||
.OrderBy(w => w.Well.Id).ThenBy(w => w.Id)
|
||||
.Skip(skip).Take(take);
|
||||
}
|
||||
|
||||
private async Task<IOrderedEnumerable<WellOperationDto>> GetFactOperationsAsync(int idWell, IEnumerable<int?> idsSections,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var request = new WellOperationRequest
|
||||
{
|
||||
IdWell = idWell,
|
||||
OperationType = WellOperation.IdOperationTypeFact,
|
||||
SortFields = new[] { "DateStart asc" },
|
||||
};
|
||||
|
||||
request.SectionTypeIds = idsSections.All(i => i.HasValue)
|
||||
? idsSections.Select(i => i!.Value)
|
||||
: null;
|
||||
|
||||
return (await wellOperationRepository.GetAsync(request, cancellationToken))
|
||||
.OrderBy(o => o.DateStart);
|
||||
}
|
||||
}
|
@ -49,7 +49,7 @@ public class AutoGeneratedDailyReportController : ControllerBase
|
||||
if (!await CanUserAccessToWellAsync(idWell, cancellationToken))
|
||||
return Forbid();
|
||||
|
||||
var reportFile = await autoGeneratedDailyReportService.GenerateReportAsync(idWell,
|
||||
var reportFile = await autoGeneratedDailyReportService.GenerateAsync(idWell,
|
||||
reportDate,
|
||||
cancellationToken);
|
||||
|
||||
@ -78,7 +78,23 @@ public class AutoGeneratedDailyReportController : ControllerBase
|
||||
|
||||
return Ok(reports);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Диапазон дат для формирования суточных отчётов
|
||||
/// </summary>
|
||||
/// <param name="idWell"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("datesRange")]
|
||||
[ProducesResponseType(typeof(DatesRangeDto), (int)HttpStatusCode.OK)]
|
||||
public async Task<IActionResult> GetDatesRangeAsync(int idWell, CancellationToken cancellationToken)
|
||||
{
|
||||
if (!await CanUserAccessToWellAsync(idWell, cancellationToken))
|
||||
return Forbid();
|
||||
|
||||
return Ok(await autoGeneratedDailyReportService.GetDatesRangeAsync(idWell, cancellationToken));
|
||||
}
|
||||
|
||||
private async Task<bool> CanUserAccessToWellAsync(int idWell, CancellationToken cancellationToken)
|
||||
{
|
||||
int? idCompany = User.GetCompanyId();
|
||||
|
@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@ -95,6 +96,37 @@ namespace AsbCloudWebApi.Controllers.SAUB
|
||||
return Ok(content);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Возвращает диапазон дат за которые есть телеметрия за период времени
|
||||
/// </summary>
|
||||
/// <param name="idWell"></param>
|
||||
/// <param name="start"></param>
|
||||
/// <param name="end"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("{idWell}/dateRange")]
|
||||
public virtual async Task<ActionResult<DatesRangeDto?>> GetRangeAsync(
|
||||
[FromRoute] int idWell,
|
||||
[Required] DateTimeOffset start,
|
||||
[Required] DateTimeOffset end,
|
||||
CancellationToken token)
|
||||
{
|
||||
int? idCompany = User.GetCompanyId();
|
||||
|
||||
if (idCompany is null)
|
||||
return Forbid();
|
||||
|
||||
bool isCompanyOwnsWell = await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
||||
idWell, token).ConfigureAwait(false);
|
||||
|
||||
if (!isCompanyOwnsWell)
|
||||
return Forbid();
|
||||
|
||||
var content = await telemetryDataService.GetRangeAsync(idWell, start, end, token);
|
||||
|
||||
return Ok(content);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Возвращает диапазон дат сохраненных данных.
|
||||
/// </summary>
|
||||
|
91
AsbCloudWebApi/Controllers/WellboreController.cs
Normal file
91
AsbCloudWebApi/Controllers/WellboreController.cs
Normal file
@ -0,0 +1,91 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Exceptions;
|
||||
using AsbCloudApp.Requests;
|
||||
using AsbCloudApp.Services;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace AsbCloudWebApi.Controllers;
|
||||
|
||||
/// <summary>
|
||||
/// Ствол скважины
|
||||
/// </summary>
|
||||
[Authorize]
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class WellboreController : ControllerBase
|
||||
{
|
||||
private readonly IWellboreService wellboreService;
|
||||
|
||||
public WellboreController(IWellboreService wellboreService)
|
||||
{
|
||||
this.wellboreService = wellboreService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получение ствола скважины
|
||||
/// </summary>
|
||||
/// <param name="idWell">Id скважины</param>
|
||||
/// <param name="idSection">Id типа секции скважины</param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
|
||||
[HttpGet("{idWell:int}/{idSection:int}")]
|
||||
[ProducesResponseType(typeof(WellboreDto), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
||||
public async Task<IActionResult> GetAsync(int idWell, int idSection, CancellationToken cancellationToken)
|
||||
{
|
||||
var wellbore = await wellboreService.GetWellboreAsync(idWell, idSection, cancellationToken);
|
||||
|
||||
if (wellbore is null)
|
||||
return NoContent();
|
||||
|
||||
return Ok(wellbore);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получение списка стволов скважин
|
||||
/// </summary>
|
||||
/// <param name="ids">Пары идентификаторов скважины и секции</param>
|
||||
/// <param name="skip">Опциональный параметр. Количество пропускаемых записей</param>
|
||||
/// <param name="take">Опциональный параметр. Количество получаемых записей</param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
[ProducesResponseType(typeof(IEnumerable<WellboreDto>), StatusCodes.Status200OK)]
|
||||
public async Task<IActionResult> GetAllAsync([FromQuery] IEnumerable<string> ids,
|
||||
int? skip,
|
||||
int? take,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var request = new WellboreRequest
|
||||
{
|
||||
Ids = ids.Select(id => ParseId(id)),
|
||||
Skip = skip,
|
||||
Take = take
|
||||
};
|
||||
|
||||
return Ok(await wellboreService.GetWellboresAsync(request, cancellationToken));
|
||||
}
|
||||
|
||||
private static (int, int?) ParseId(string id)
|
||||
{
|
||||
var idPair = id.Split(',');
|
||||
if (!int.TryParse(idPair[0], out var idWell))
|
||||
throw new ArgumentInvalidException($"Не удалось получить Id скважины \"{idPair[0]}\"", nameof(id));
|
||||
|
||||
if (idPair.Length > 1)
|
||||
{
|
||||
if (int.TryParse(idPair[1], out int idWellSectionType))
|
||||
return (idWell, idWellSectionType);
|
||||
else
|
||||
throw new ArgumentInvalidException($"Не удалось получить Id ствола \"{idPair[1]}\"", nameof(id));
|
||||
}
|
||||
return (idWell, null);
|
||||
}
|
||||
}
|
15
AsbCloudWebApi/Rest/wellbore.http
Normal file
15
AsbCloudWebApi/Rest/wellbore.http
Normal file
@ -0,0 +1,15 @@
|
||||
@baseUrl = http://127.0.0.1:5000
|
||||
@contentType = application/json
|
||||
@auth = Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImN0eSI6IkpXVCJ9.eyJpZCI6IjEiLCJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1lIjoiZGV2IiwiaWRDb21wYW55IjoiMSIsImh0dHA6Ly9zY2hlbWFzLm1pY3Jvc29mdC5jb20vd3MvMjAwOC8wNi9pZGVudGl0eS9jbGFpbXMvcm9sZSI6InJvb3QiLCJuYmYiOjE2NjI1NDgxNjIsImV4cCI6MTY5NDEwNTc2MiwiaXNzIjoiYSIsImF1ZCI6ImEifQ.OEAlNzxi7Jat6pzDBTAjTbChskc-tdJthJexyWwwUKE
|
||||
|
||||
@uid = 20210101_000000000
|
||||
@idCluster = 1
|
||||
@idWell = 1
|
||||
|
||||
# https://marketplace.visualstudio.com/items?itemName=humao.rest-client
|
||||
|
||||
###
|
||||
GET {{baseUrl}}/api/well/wellbore?ids=1,2
|
||||
Content-Type: {{contentType}}
|
||||
accept: */*
|
||||
Authorization: {{auth}}
|
Loading…
Reference in New Issue
Block a user