forked from ddrilling/AsbCloudServer
51 lines
1.7 KiB
C#
51 lines
1.7 KiB
C#
using AsbCloudApp.Data;
|
|
using AsbCloudApp.Exceptions;
|
|
using AsbCloudApp.Repositories;
|
|
using AsbCloudApp.Services;
|
|
using AsbCloudDb.Model;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace AsbCloudInfrastructure.Repository
|
|
{
|
|
internal class TrajectoryFactRepository : ITrajectoryFactRepository
|
|
{
|
|
private readonly IAsbCloudDbContext db;
|
|
private readonly IWellService wellService;
|
|
public TrajectoryFactRepository(IAsbCloudDbContext db, IWellService wellService)
|
|
{
|
|
this.db = db;
|
|
this.wellService = wellService;
|
|
}
|
|
|
|
public async Task<IEnumerable<TrajectoryGeoFactDto>> GetAsync(int idWell, CancellationToken token)
|
|
{
|
|
var well = wellService.GetOrDefault(idWell);
|
|
if (well is null || well.Timezone is null)
|
|
throw new ArgumentInvalidException("idWell doesn`t exist", nameof(idWell));
|
|
|
|
var entities = await db.Record7
|
|
.AsNoTracking()
|
|
.Where(x => x.IdTelemetry == well.IdTelemetry)
|
|
.Where(coord => coord.Deptsvym != null && coord.Svyinc != null && coord.Svyazc != null)
|
|
.OrderBy(e => e.Deptsvym)
|
|
.Select(x => new { x.Deptsvym, x.Svyinc, x.Svyazc })
|
|
.ToArrayAsync(token);
|
|
|
|
var result = entities
|
|
.Select(coord => new TrajectoryGeoFactDto
|
|
{
|
|
WellboreDepth = coord.Deptsvym!.Value,
|
|
ZenithAngle = coord.Svyinc!.Value,
|
|
AzimuthGeo = coord.Svyazc!.Value
|
|
})
|
|
.ToArray();
|
|
|
|
return result;
|
|
}
|
|
}
|
|
}
|