2023-05-11 11:50:45 +05:00
|
|
|
|
using AsbCloudApp.Data;
|
|
|
|
|
using AsbCloudApp.Data.WITS;
|
2023-05-04 16:54:09 +05:00
|
|
|
|
using AsbCloudApp.Exceptions;
|
|
|
|
|
using AsbCloudApp.Repositories;
|
|
|
|
|
using AsbCloudApp.Services;
|
|
|
|
|
using AsbCloudDb.Model;
|
2023-05-11 11:50:45 +05:00
|
|
|
|
using Mapster;
|
2023-05-04 16:54:09 +05:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace AsbCloudInfrastructure.Repository
|
|
|
|
|
{
|
|
|
|
|
internal class FactualTrajectoryRepository : IFactualTrajectoryRepository
|
|
|
|
|
{
|
|
|
|
|
private readonly IAsbCloudDbContext db;
|
|
|
|
|
private readonly IWellService wellService;
|
|
|
|
|
public FactualTrajectoryRepository(IAsbCloudDbContext db, IWellService wellService)
|
|
|
|
|
{
|
|
|
|
|
this.db = db;
|
|
|
|
|
this.wellService = wellService;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<IEnumerable<Record7Dto>> 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 query = db.Record7
|
|
|
|
|
.AsNoTracking()
|
|
|
|
|
.Where(x => x.IdTelemetry == well.IdTelemetry);
|
|
|
|
|
var entities = await query
|
|
|
|
|
.OrderBy(e => e.Deptsvym)
|
|
|
|
|
.ToListAsync(token);
|
|
|
|
|
var result = entities
|
2023-05-11 11:50:45 +05:00
|
|
|
|
.Select(r => r.Adapt<Record7Dto>());
|
2023-05-04 16:54:09 +05:00
|
|
|
|
return result;
|
|
|
|
|
}
|
2023-05-11 11:50:45 +05:00
|
|
|
|
|
|
|
|
|
public async Task<TrajectoryDto[]> GetTrajectoryAsync(int idWell, CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
return (await GetAsync(idWell, token))
|
|
|
|
|
.Where(coord => coord.Deptsvym != null && coord.Svyinc != null && coord.Svyazc != null)
|
|
|
|
|
.Select(coord => new TrajectoryDto(coord.Deptsvym!.Value, coord.Svyinc!.Value, coord.Svyazc!.Value))
|
|
|
|
|
.ToArray();
|
|
|
|
|
}
|
2023-05-04 16:54:09 +05:00
|
|
|
|
}
|
|
|
|
|
}
|