2023-05-11 11:50:45 +05:00
|
|
|
|
using AsbCloudApp.Data;
|
2023-05-17 11:42:14 +05:00
|
|
|
|
using System.Collections.Generic;
|
2023-05-04 16:54:09 +05:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
2023-11-03 18:55:49 +05:00
|
|
|
|
using AsbCloudApp.Exceptions;
|
|
|
|
|
using AsbCloudApp.Repositories;
|
|
|
|
|
using AsbCloudApp.Requests;
|
|
|
|
|
using AsbCloudDb.Model;
|
|
|
|
|
using AsbCloudDb.Model.WITS;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2023-05-04 16:54:09 +05:00
|
|
|
|
|
2023-11-03 18:55:49 +05:00
|
|
|
|
namespace AsbCloudInfrastructure.Repository;
|
|
|
|
|
|
|
|
|
|
public class TrajectoryFactRepository : ITrajectoryFactRepository
|
2023-05-04 16:54:09 +05:00
|
|
|
|
{
|
2023-11-03 18:55:49 +05:00
|
|
|
|
private readonly IAsbCloudDbContext dbContext;
|
|
|
|
|
|
|
|
|
|
public TrajectoryFactRepository(IAsbCloudDbContext dbContext)
|
|
|
|
|
{
|
|
|
|
|
this.dbContext = dbContext;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<IEnumerable<TrajectoryGeoFactDto>> GetAsync(TrajectoryGeoFactRequest request, CancellationToken token) =>
|
|
|
|
|
(await BuildQuery(request)
|
|
|
|
|
.Where(coord => coord.Deptsvym.HasValue &&
|
|
|
|
|
coord.Svyinc.HasValue &&
|
|
|
|
|
coord.Svyazc.HasValue)
|
|
|
|
|
.AsNoTracking()
|
|
|
|
|
.ToArrayAsync(token))
|
|
|
|
|
.Select(r => new TrajectoryGeoFactDto
|
|
|
|
|
{
|
|
|
|
|
IdWell = request.IdWell,
|
|
|
|
|
AzimuthMagnetic = r.Svymtf,
|
|
|
|
|
VerticalDepth = r.Deptsvyv,
|
|
|
|
|
WellboreDepth = r.Deptsvym!.Value,
|
|
|
|
|
ZenithAngle = r.Svyinc!.Value,
|
|
|
|
|
AzimuthGeo = r.Svyazc!.Value
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
public Task<IEnumerable<TrajectoryGeoFactDto>> GetAsync(int idWell, CancellationToken token) =>
|
|
|
|
|
GetAsync(new TrajectoryGeoFactRequest
|
|
|
|
|
{
|
|
|
|
|
IdWell = idWell
|
|
|
|
|
}, token);
|
|
|
|
|
|
|
|
|
|
private IQueryable<Record7> BuildQuery(TrajectoryGeoFactRequest request)
|
|
|
|
|
{
|
|
|
|
|
var well = dbContext.Wells.SingleOrDefault(w => w.Id == request.IdWell);
|
|
|
|
|
|
|
|
|
|
if (well is null)
|
|
|
|
|
throw new ArgumentInvalidException($"Скважина с Id: {request.IdWell} не найдена", nameof(request.IdWell));
|
|
|
|
|
|
|
|
|
|
var query = dbContext.Record7.Where(r => r.IdTelemetry == well.IdTelemetry)
|
|
|
|
|
.Where(x => x.IdTelemetry == well.IdTelemetry);
|
|
|
|
|
|
|
|
|
|
if (request.GeDate.HasValue)
|
|
|
|
|
query = query.Where(r => r.DateTime >= request.GeDate.Value);
|
|
|
|
|
|
2023-11-09 15:01:29 +05:00
|
|
|
|
if (request.LeDate.HasValue)
|
|
|
|
|
query = query.Where(r => r.DateTime <= request.LeDate.Value);
|
2023-11-03 18:55:49 +05:00
|
|
|
|
|
|
|
|
|
return query.OrderBy(e => e.Deptsvym);
|
|
|
|
|
}
|
|
|
|
|
}
|