2024-07-04 11:02:45 +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;
|
2023-12-20 16:42:39 +05:00
|
|
|
|
using AsbCloudApp.Services;
|
2023-11-21 15:10:22 +05:00
|
|
|
|
|
2024-08-19 10:01:07 +05:00
|
|
|
|
namespace AsbCloudInfrastructure.Repository;
|
|
|
|
|
|
|
|
|
|
public class TrajectoryNnbRepository : ITrajectoryNnbRepository
|
2023-11-21 15:10:22 +05:00
|
|
|
|
{
|
2024-08-19 10:01:07 +05:00
|
|
|
|
private readonly IAsbCloudDbContext db;
|
|
|
|
|
private readonly IWellService wellService;
|
|
|
|
|
|
|
|
|
|
public TrajectoryNnbRepository(IAsbCloudDbContext db,
|
|
|
|
|
IWellService wellService)
|
2023-11-21 15:10:22 +05:00
|
|
|
|
{
|
2024-08-19 10:01:07 +05:00
|
|
|
|
this.db = db;
|
|
|
|
|
this.wellService = wellService;
|
|
|
|
|
}
|
2023-11-29 12:06:57 +05:00
|
|
|
|
|
2024-08-19 10:01:07 +05:00
|
|
|
|
private IQueryable<Record7> BuildQuery(TrajectoryRequest request)
|
|
|
|
|
{
|
|
|
|
|
var well = db.Wells.SingleOrDefault(w => w.Id == request.IdWell);
|
|
|
|
|
var timezone = wellService.GetTimezone(request.IdWell);
|
2023-11-29 12:06:57 +05:00
|
|
|
|
|
2024-08-19 10:01:07 +05:00
|
|
|
|
if (well is null)
|
|
|
|
|
throw new ArgumentInvalidException($"Скважина с Id: {request.IdWell} не найдена", nameof(request.IdWell));
|
2023-11-29 12:06:57 +05:00
|
|
|
|
|
2024-08-19 10:01:07 +05:00
|
|
|
|
var query = db.Record7.Where(r => r.IdTelemetry == well.IdTelemetry)
|
|
|
|
|
.Where(x => x.IdTelemetry == well.IdTelemetry);
|
2023-11-29 12:06:57 +05:00
|
|
|
|
|
2024-08-19 10:01:07 +05:00
|
|
|
|
if (request.GeDate.HasValue)
|
|
|
|
|
{
|
|
|
|
|
var geDate = request.GeDate.Value.ToUniversalTime();
|
|
|
|
|
query = query.Where(r => r.DateTime >= geDate);
|
2023-11-29 12:06:57 +05:00
|
|
|
|
}
|
|
|
|
|
|
2024-08-19 10:01:07 +05:00
|
|
|
|
if (request.LeDate.HasValue)
|
2023-11-29 12:06:57 +05:00
|
|
|
|
{
|
2024-08-19 10:01:07 +05:00
|
|
|
|
var leDate = request.LeDate.Value.ToUniversalTime();
|
|
|
|
|
query = query.Where(r => r.DateTime <= leDate);
|
2023-11-30 11:11:45 +05:00
|
|
|
|
}
|
|
|
|
|
|
2024-08-19 10:01:07 +05:00
|
|
|
|
return query.OrderBy(e => e.Deptsvym);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<IEnumerable<TrajectoryGeoFactDto>> GetAsync(int idWell, CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
var request = new TrajectoryRequest()
|
2023-11-30 11:11:45 +05:00
|
|
|
|
{
|
2024-08-19 10:01:07 +05:00
|
|
|
|
IdWell = idWell,
|
|
|
|
|
};
|
|
|
|
|
var result = await GetByRequestAsync(request, token);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
2023-11-21 15:10:22 +05:00
|
|
|
|
|
2024-08-19 10:01:07 +05:00
|
|
|
|
public async Task<IEnumerable<TrajectoryGeoFactDto>> GetByRequestAsync(TrajectoryRequest request, CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
var entities = (await BuildQuery(request)
|
|
|
|
|
.Where(coord => coord.Deptsvym.HasValue &&
|
|
|
|
|
coord.Svyinc.HasValue &&
|
|
|
|
|
coord.Svyazc.HasValue)
|
|
|
|
|
.AsNoTracking()
|
|
|
|
|
.ToArrayAsync(token));
|
2023-11-21 15:10:22 +05:00
|
|
|
|
|
2024-08-19 10:01:07 +05:00
|
|
|
|
var result = entities
|
|
|
|
|
.Select(coord => new TrajectoryGeoFactDto
|
|
|
|
|
{
|
|
|
|
|
IdWell = request.IdWell,
|
|
|
|
|
AzimuthMagnetic = coord.Svymtf,
|
|
|
|
|
VerticalDepth = coord.Deptsvyv,
|
|
|
|
|
WellboreDepth = coord.Deptsvym!.Value,
|
|
|
|
|
ZenithAngle = coord.Svyinc!.Value,
|
|
|
|
|
AzimuthGeo = coord.Svyazc!.Value
|
|
|
|
|
})
|
|
|
|
|
.ToArray();
|
|
|
|
|
|
|
|
|
|
return result;
|
2023-11-21 15:10:22 +05:00
|
|
|
|
}
|
|
|
|
|
}
|