DD.WellWorkover.Cloud/AsbCloudInfrastructure/Repository/TrajectoryNnbRepository.cs

88 lines
2.7 KiB
C#
Raw Normal View History

using AsbCloudApp.Data.Trajectory;
using AsbCloudApp.Exceptions;
using AsbCloudApp.Repositories;
using AsbCloudApp.Requests;
using AsbCloudDb.Model;
using AsbCloudDb.Model.WITS;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using AsbCloudApp.Services;
2024-08-19 10:01:07 +05:00
namespace AsbCloudInfrastructure.Repository;
public class TrajectoryNnbRepository : ITrajectoryNnbRepository
{
2024-08-19 10:01:07 +05:00
private readonly IAsbCloudDbContext db;
private readonly IWellService wellService;
public TrajectoryNnbRepository(IAsbCloudDbContext db,
IWellService wellService)
{
2024-08-19 10:01:07 +05:00
this.db = db;
this.wellService = wellService;
}
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);
2024-08-19 10:01:07 +05:00
if (well is null)
throw new ArgumentInvalidException($"Скважина с Id: {request.IdWell} не найдена", nameof(request.IdWell));
2024-08-19 10:01:07 +05:00
var query = db.Record7.Where(r => r.IdTelemetry == well.IdTelemetry)
.Where(x => x.IdTelemetry == well.IdTelemetry);
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);
}
2024-08-19 10:01:07 +05:00
if (request.LeDate.HasValue)
{
2024-08-19 10:01:07 +05:00
var leDate = request.LeDate.Value.ToUniversalTime();
query = query.Where(r => r.DateTime <= leDate);
}
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()
{
2024-08-19 10:01:07 +05:00
IdWell = idWell,
};
var result = await GetByRequestAsync(request, token);
return result;
}
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));
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;
}
}