DD.WellWorkover.Cloud/AsbCloudInfrastructure/Repository/TrajectoryFactRepository.cs
Степанов Дмитрий 6b0db1adbc Расширение функциональности
1. Расширены репозитории: траектории, расписания
2. Расширил DTO, сервис РТК отчёт
3. Поправлен класс с методами расширения для формирования excel. В дальнейшем требуется удалить из него все неиспользуемые методы расширения
2023-11-03 18:55:49 +05:00

65 lines
1.9 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using AsbCloudApp.Data;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using AsbCloudApp.Exceptions;
using AsbCloudApp.Repositories;
using AsbCloudApp.Requests;
using AsbCloudDb.Model;
using AsbCloudDb.Model.WITS;
using Microsoft.EntityFrameworkCore;
namespace AsbCloudInfrastructure.Repository;
public class TrajectoryFactRepository : ITrajectoryFactRepository
{
private readonly IAsbCloudDbContext dbContext;
public TrajectoryFactRepository(IAsbCloudDbContext dbContext)
{
this.dbContext = dbContext;
}
public async Task<IEnumerable<TrajectoryGeoFactDto>> GetAsync(TrajectoryGeoFactRequest request, CancellationToken token) =>
(await BuildQuery(request)
.Where(coord => coord.Deptsvym.HasValue &&
coord.Svyinc.HasValue &&
coord.Svyazc.HasValue)
.AsNoTracking()
.ToArrayAsync(token))
.Select(r => new TrajectoryGeoFactDto
{
IdWell = request.IdWell,
AzimuthMagnetic = r.Svymtf,
VerticalDepth = r.Deptsvyv,
WellboreDepth = r.Deptsvym!.Value,
ZenithAngle = r.Svyinc!.Value,
AzimuthGeo = r.Svyazc!.Value
});
public Task<IEnumerable<TrajectoryGeoFactDto>> GetAsync(int idWell, CancellationToken token) =>
GetAsync(new TrajectoryGeoFactRequest
{
IdWell = idWell
}, token);
private IQueryable<Record7> BuildQuery(TrajectoryGeoFactRequest request)
{
var well = dbContext.Wells.SingleOrDefault(w => w.Id == request.IdWell);
if (well is null)
throw new ArgumentInvalidException($"Скважина с Id: {request.IdWell} не найдена", nameof(request.IdWell));
var query = dbContext.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);
if (request.LtDate.HasValue)
query = query.Where(r => r.DateTime <= request.LtDate.Value);
return query.OrderBy(e => e.Deptsvym);
}
}