2022-11-18 14:29:29 +05:00
|
|
|
|
using AsbCloudApp.Data;
|
|
|
|
|
using AsbCloudApp.Repositories;
|
|
|
|
|
using AsbCloudApp.Requests;
|
|
|
|
|
using AsbCloudDb.Model;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2023-01-16 10:29:52 +05:00
|
|
|
|
using System;
|
2022-11-18 14:29:29 +05:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace AsbCloudInfrastructure.Repository
|
|
|
|
|
{
|
2023-04-18 16:22:53 +05:00
|
|
|
|
|
2022-11-18 14:29:29 +05:00
|
|
|
|
public class LimitingParameterRepository : ILimitingParameterRepository
|
|
|
|
|
{
|
|
|
|
|
private readonly IAsbCloudDbContext context;
|
|
|
|
|
|
|
|
|
|
public LimitingParameterRepository(IAsbCloudDbContext context)
|
|
|
|
|
{
|
|
|
|
|
this.context = context;
|
|
|
|
|
}
|
2023-01-16 10:29:52 +05:00
|
|
|
|
|
2022-11-25 11:56:21 +05:00
|
|
|
|
public async Task<IEnumerable<LimitingParameterDataDto>> GetLimitingParametersAsync(LimitingParameterRequest request, WellDto wellDto, CancellationToken token)
|
2022-11-18 14:29:29 +05:00
|
|
|
|
{
|
2023-01-16 10:29:52 +05:00
|
|
|
|
var timezoneOffset = wellDto.Timezone.Hours;
|
|
|
|
|
var IdTelemetry = wellDto.IdTelemetry!.Value;
|
|
|
|
|
return await GetLimitingParametersAsync(request, IdTelemetry, timezoneOffset, token);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<IEnumerable<LimitingParameterDataDto>> GetLimitingParametersAsync(LimitingParameterRequest request, int idTelemetry, double timezoneHours, CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
var timezoneSpan = TimeSpan.FromHours(timezoneHours);
|
|
|
|
|
var query = BuildQuery(request, idTelemetry, timezoneHours);
|
2022-11-18 14:29:29 +05:00
|
|
|
|
|
2022-11-24 11:15:50 +05:00
|
|
|
|
var data = (await query.ToListAsync(token))
|
|
|
|
|
.Select(x => new LimitingParameterDataDto
|
|
|
|
|
{
|
2023-01-16 10:29:52 +05:00
|
|
|
|
IdWell = request.IdWell,
|
2022-11-24 11:15:50 +05:00
|
|
|
|
IdTelemetry = x.IdTelemetry,
|
|
|
|
|
IdFeedRegulator = x.IdFeedRegulator,
|
2024-03-22 11:01:12 +05:00
|
|
|
|
DateStart = x.DateStart.ToOffset(timezoneSpan),
|
|
|
|
|
DateEnd = x.DateEnd.ToOffset(timezoneSpan),
|
2022-11-24 11:15:50 +05:00
|
|
|
|
DepthStart = x.DepthStart,
|
|
|
|
|
DepthEnd = x.DepthEnd
|
|
|
|
|
});
|
|
|
|
|
return data;
|
2022-11-18 14:29:29 +05:00
|
|
|
|
}
|
|
|
|
|
|
2023-01-16 10:29:52 +05:00
|
|
|
|
private IQueryable<LimitingParameter> BuildQuery(LimitingParameterRequest request, int idTelemetry, double timezoneHours)
|
2022-11-18 14:29:29 +05:00
|
|
|
|
{
|
|
|
|
|
var query = context.LimitingParameter
|
2022-11-24 11:15:50 +05:00
|
|
|
|
.OrderBy(x => x.Id)
|
2023-01-16 10:29:52 +05:00
|
|
|
|
.Where(x => x.IdTelemetry == idTelemetry)
|
2022-11-18 14:29:29 +05:00
|
|
|
|
.AsNoTracking();
|
|
|
|
|
|
|
|
|
|
if (request.GtDate.HasValue)
|
|
|
|
|
{
|
2024-03-22 11:01:12 +05:00
|
|
|
|
var gtDate = request.GtDate.Value.ToUniversalTime();
|
2022-11-18 14:29:29 +05:00
|
|
|
|
query = query.Where(x => x.DateEnd >= gtDate);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (request.LtDate.HasValue)
|
|
|
|
|
{
|
2024-03-22 11:01:12 +05:00
|
|
|
|
var ltDate = request.LtDate.Value.ToUniversalTime();
|
2022-11-18 14:29:29 +05:00
|
|
|
|
query = query.Where(x => x.DateStart <= ltDate);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (request.GtDepth.HasValue)
|
|
|
|
|
query = query.Where(x => x.DepthEnd >= request.GtDepth.Value);
|
|
|
|
|
|
|
|
|
|
if (request.LtDepth.HasValue)
|
|
|
|
|
query = query.Where(x => x.DepthStart <= request.LtDepth.Value);
|
|
|
|
|
|
|
|
|
|
return query;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-04-18 16:22:53 +05:00
|
|
|
|
|
2022-11-18 14:29:29 +05:00
|
|
|
|
}
|