Фикс репозиторий

1. Поправлена выборка в репозитории с траекториями
2. В репозитории с операциями по скважине добавлено приведение ко времени куста.
This commit is contained in:
Степанов Дмитрий 2023-12-20 16:42:39 +05:00
parent 06a72d0dca
commit 4ff7b73403
2 changed files with 22 additions and 5 deletions

View File

@ -9,20 +9,26 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using AsbCloudApp.Services;
namespace AsbCloudInfrastructure.Repository
{
public class TrajectoryNnbRepository : ITrajectoryNnbRepository
{
private readonly IAsbCloudDbContext db;
public TrajectoryNnbRepository(IAsbCloudDbContext db)
private readonly IWellService wellService;
public TrajectoryNnbRepository(IAsbCloudDbContext db,
IWellService wellService)
{
this.db = db;
this.wellService = wellService;
}
private IQueryable<Record7> BuildQuery(TrajectoryRequest request)
{
var well = db.Wells.SingleOrDefault(w => w.Id == request.IdWell);
var timezone = wellService.GetTimezone(request.IdWell);
if (well is null)
throw new ArgumentInvalidException($"Скважина с Id: {request.IdWell} не найдена", nameof(request.IdWell));
@ -31,10 +37,16 @@ namespace AsbCloudInfrastructure.Repository
.Where(x => x.IdTelemetry == well.IdTelemetry);
if (request.GeDate.HasValue)
query = query.Where(r => r.DateTime >= request.GeDate.Value);
{
var geDate = request.GeDate.Value.ToUtcDateTimeOffset(timezone.Hours);
query = query.Where(r => r.DateTime >= geDate);
}
if (request.LeDate.HasValue)
query = query.Where(r => r.DateTime <= request.LeDate.Value);
{
var leDate = request.LeDate.Value.ToUtcDateTimeOffset(timezone.Hours);
query = query.Where(r => r.DateTime <= leDate);
}
return query.OrderBy(e => e.Deptsvym);
}

View File

@ -186,15 +186,20 @@ public class WellOperationRepository : IWellOperationRepository
public async Task<DatesRangeDto?> GetDatesRangeAsync(int idWell, int idType, CancellationToken cancellationToken)
{
var timezone = wellService.GetTimezone(idWell);
var query = db.WellOperations.Where(o => o.IdWell == idWell && o.IdType == idType);
if (!await query.AnyAsync(cancellationToken))
return null;
var minDate = await query.MinAsync(o => o.DateStart, cancellationToken);
var maxDate = await query.MaxAsync(o => o.DateStart, cancellationToken);
return new DatesRangeDto
{
From = (await query.MinAsync(o => o.DateStart, cancellationToken)).Date,
To = (await query.MaxAsync(o => o.DateStart, cancellationToken)).Date
From = minDate.ToRemoteDateTime(timezone.Hours),
To = maxDate.ToRemoteDateTime(timezone.Hours)
};
}