DD.WellWorkover.Cloud/AsbCloudInfrastructure/Repository/GtrWitsRepository.cs
eugeniy_ivanov 3ced1a0e20 new migration
refact entity model
wits rep and interface
2023-04-04 21:21:06 +05:00

67 lines
2.2 KiB
C#

using AsbCloudApp.Data.GTR;
using AsbCloudApp.Services;
using AsbCloudApp.Services.WITS;
using AsbCloudDb.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace AsbCloudInfrastructure.Repository
{
#nullable enable
public class GtrWitsRepository: IGtrService
{
private readonly IAsbCloudDbContext db;
private readonly ITelemetryService telemetryService;
public GtrWitsRepository(
IAsbCloudDbContext db,
ITelemetryService telemetryService)
{
this.db = db;
this.telemetryService = telemetryService;
}
public async Task<IEnumerable<WitsRecordDto>> GetAsync(int idWell, DateTime dateBegin = default, double intervalSec = 600, int approxPointsCount = 1024, CancellationToken token = default)
{
var telemetry = telemetryService.GetOrDefaultTelemetryByIdWell(idWell);
if (telemetry is null)
return Enumerable.Empty<WitsRecordDto>();
var timezone = telemetryService.GetTimezone(telemetry.Id);
var filterByDateEnd = dateBegin != default;
DateTimeOffset dateBeginUtc;
if (dateBegin == default)
{
dateBeginUtc = telemetryService.GetLastTelemetryDate(telemetry.Id)
.ToUtcDateTimeOffset(timezone.Hours);
if (dateBeginUtc != default)
dateBeginUtc = dateBeginUtc.AddSeconds(-intervalSec);
}
else
{
dateBeginUtc = dateBegin.ToUtcDateTimeOffset(timezone.Hours);
}
if (dateBeginUtc == default)
dateBeginUtc = DateTime.UtcNow.AddSeconds(-intervalSec);
var dateEnd = dateBeginUtc.AddSeconds(intervalSec);
//временная заглушка(для билда без ошибок)
return Enumerable.Empty<WitsRecordDto>();
}
public Task<int> UpdateAsync(string uid, IEnumerable<WitsRecordDto> dtos, CancellationToken token)
{
throw new NotImplementedException();
}
}
#nullable disable
}