2023-11-28 15:54:47 +05:00
|
|
|
|
using AsbCloudApp.Data.Trajectory;
|
2023-11-29 12:06:57 +05:00
|
|
|
|
using AsbCloudApp.Exceptions;
|
2023-11-21 15:10:22 +05:00
|
|
|
|
using AsbCloudApp.Repositories;
|
2023-11-29 12:06:57 +05:00
|
|
|
|
using AsbCloudApp.Requests;
|
2023-11-21 15:10:22 +05:00
|
|
|
|
using AsbCloudDb.Model;
|
2023-11-29 12:06:57 +05:00
|
|
|
|
using AsbCloudDb.Model.WITS;
|
2023-11-21 15:10:22 +05:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace AsbCloudInfrastructure.Repository
|
|
|
|
|
{
|
2023-11-29 12:06:57 +05:00
|
|
|
|
public class TrajectoryNnbRepository : ITrajectoryNnbRepository
|
2023-11-21 15:10:22 +05:00
|
|
|
|
{
|
|
|
|
|
private readonly IAsbCloudDbContext db;
|
2023-11-30 09:40:51 +05:00
|
|
|
|
public TrajectoryNnbRepository(IAsbCloudDbContext db)
|
2023-11-21 15:10:22 +05:00
|
|
|
|
{
|
|
|
|
|
this.db = db;
|
|
|
|
|
}
|
2023-11-29 12:06:57 +05:00
|
|
|
|
|
|
|
|
|
private IQueryable<Record7> BuildQuery(TrajectoryRequest request)
|
2023-11-21 15:10:22 +05:00
|
|
|
|
{
|
2023-11-29 12:06:57 +05:00
|
|
|
|
var well = db.Wells.SingleOrDefault(w => w.Id == request.IdWell);
|
|
|
|
|
|
2023-11-21 15:10:22 +05:00
|
|
|
|
if (well is null)
|
2023-11-29 12:06:57 +05:00
|
|
|
|
throw new ArgumentInvalidException($"Скважина с Id: {request.IdWell} не найдена", nameof(request.IdWell));
|
|
|
|
|
|
|
|
|
|
var query = db.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-21 15:10:22 +05:00
|
|
|
|
|
2023-11-29 12:06:57 +05:00
|
|
|
|
if (request.LeDate.HasValue)
|
|
|
|
|
query = query.Where(r => r.DateTime <= request.LeDate.Value);
|
|
|
|
|
|
|
|
|
|
return query.OrderBy(e => e.Deptsvym);
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-30 09:40:51 +05:00
|
|
|
|
public async Task<IEnumerable<TrajectoryGeoFactDto>> GetAsync(int idWell, CancellationToken token)
|
2023-11-29 12:06:57 +05:00
|
|
|
|
{
|
2023-11-30 09:40:51 +05:00
|
|
|
|
var request = new TrajectoryRequest()
|
|
|
|
|
{
|
|
|
|
|
IdWell = idWell,
|
|
|
|
|
};
|
2023-11-30 11:11:45 +05:00
|
|
|
|
var result = await GetByRequestAsync(request, token);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<IEnumerable<TrajectoryGeoFactDto>> GetByRequestAsync(TrajectoryRequest request, CancellationToken token)
|
|
|
|
|
{
|
2023-11-29 12:06:57 +05:00
|
|
|
|
var entities = (await BuildQuery(request)
|
2023-11-30 11:11:45 +05:00
|
|
|
|
.Where(coord => coord.Deptsvym.HasValue &&
|
|
|
|
|
coord.Svyinc.HasValue &&
|
|
|
|
|
coord.Svyazc.HasValue)
|
|
|
|
|
.AsNoTracking()
|
|
|
|
|
.ToArrayAsync(token));
|
2023-11-21 15:10:22 +05:00
|
|
|
|
|
|
|
|
|
var result = entities
|
|
|
|
|
.Select(coord => new TrajectoryGeoFactDto
|
|
|
|
|
{
|
2023-11-29 12:06:57 +05:00
|
|
|
|
IdWell = request.IdWell,
|
2023-11-21 15:10:22 +05:00
|
|
|
|
AzimuthMagnetic = coord.Svymtf,
|
|
|
|
|
VerticalDepth = coord.Deptsvyv,
|
|
|
|
|
WellboreDepth = coord.Deptsvym!.Value,
|
|
|
|
|
ZenithAngle = coord.Svyinc!.Value,
|
|
|
|
|
AzimuthGeo = coord.Svyazc!.Value
|
|
|
|
|
})
|
|
|
|
|
.ToArray();
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|