forked from ddrilling/AsbCloudServer
Абстрактный репозиторий для работы с data-saub-stat
This commit is contained in:
parent
d5a4b3d7fe
commit
5e5453bd30
@ -1,12 +1,11 @@
|
|||||||
using System;
|
using System;
|
||||||
using AsbCloudApp.Data.WellOperation;
|
|
||||||
|
|
||||||
namespace AsbCloudApp.Data;
|
namespace AsbCloudApp.Data;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// dto для хранения данных статистики качества бурения
|
/// dto для хранения данных статистики качества бурения
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class DataSaubStatDrillingQualityDto : IId
|
public class DataSaubStatDrillingQualityDto : IId, IDataSaubStatDto
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
|
@ -6,7 +6,7 @@ namespace AsbCloudApp.Data;
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// dto для хранения данных статистики сауб
|
/// dto для хранения данных статистики сауб
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class DataSaubStatDto : IId
|
public class DataSaubStatDto : IId, IDataSaubStatDto
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
|
19
AsbCloudApp/Data/SaubStat/IDataSaubStatDto.cs
Normal file
19
AsbCloudApp/Data/SaubStat/IDataSaubStatDto.cs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace AsbCloudApp.Data;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Dto для работы с данными dataSaubStat
|
||||||
|
/// </summary>
|
||||||
|
public interface IDataSaubStatDto
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Дата и время начала
|
||||||
|
/// </summary>
|
||||||
|
public DateTimeOffset DateStart { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Дата и время окончания
|
||||||
|
/// </summary>
|
||||||
|
public DateTimeOffset DateEnd { get; set; }
|
||||||
|
}
|
@ -1,40 +0,0 @@
|
|||||||
using AsbCloudApp.Data;
|
|
||||||
using AsbCloudApp.Services;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace AsbCloudApp.Repositories;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Репозиторий работы с данными из таблицы t_data_daub_stat_drilling_quality
|
|
||||||
/// </summary>
|
|
||||||
public interface IDataSaubStatDrillingQualityRepository : ITelemetryDataEditorService
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Получение записей по ключу телеметрии
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="idTelemetry">ключ телеметрии</param>
|
|
||||||
/// <param name="geDate">начальная дата</param>
|
|
||||||
/// <param name="leDate">конечная дата</param>
|
|
||||||
/// <param name="token"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
Task<IEnumerable<DataSaubStatDrillingQualityDto>> GetAsync(int idTelemetry, DateTimeOffset geDate, DateTimeOffset leDate, CancellationToken token);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Получение последних по дате окончания бурения записей качества в разрезе телеметрий
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="idTelemetries">ключи телеметрий</param>
|
|
||||||
/// <param name="token"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
Task<IEnumerable<DataSaubStatDrillingQualityDto>> GetLastsAsync(int[] idTelemetries, CancellationToken token);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Вставка записей статистики качества
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="dataSaubStats"></param>
|
|
||||||
/// <param name="token"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
Task<int> InsertRangeAsync(IEnumerable<DataSaubStatDrillingQualityDto> dataSaubStats, CancellationToken token);
|
|
||||||
}
|
|
@ -8,9 +8,10 @@ using System.Threading.Tasks;
|
|||||||
namespace AsbCloudApp.Repositories;
|
namespace AsbCloudApp.Repositories;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Репозиторий работы с данными из таблицы t_data_daub_stat
|
/// Репозиторий работы с данными, реализующими интерфейс IDataSaubStatDto
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IDataSaubStatRepository : ITelemetryDataEditorService
|
public interface IDataSaubStatRepository<TDto> : ITelemetryDataEditorService
|
||||||
|
where TDto : IDataSaubStatDto
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Получение записей по ключу телеметрии
|
/// Получение записей по ключу телеметрии
|
||||||
@ -20,21 +21,21 @@ public interface IDataSaubStatRepository : ITelemetryDataEditorService
|
|||||||
/// <param name="leDate">конечная дата</param>
|
/// <param name="leDate">конечная дата</param>
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<IEnumerable<DataSaubStatDto>> GetAsync(int idTelemetry, DateTimeOffset geDate, DateTimeOffset leDate, CancellationToken token);
|
Task<IEnumerable<TDto>> GetAsync(int idTelemetry, DateTimeOffset geDate, DateTimeOffset leDate, CancellationToken token);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Получение последних по дате окончания бурения записей в разрезе телеметрий
|
/// Получение последних по дате окончания бурения записей качества в разрезе телеметрий
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="idTelemetries">ключи телеметрий</param>
|
/// <param name="idTelemetries">ключи телеметрий</param>
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<IEnumerable<DataSaubStatDto>> GetLastsAsync(int[] idTelemetries, CancellationToken token);
|
Task<IEnumerable<TDto>> GetLastsAsync(int[] idTelemetries, CancellationToken token);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Вставка записей статистики
|
/// Вставка записей статистики качества
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="dataSaubStats"></param>
|
/// <param name="dataSaubStats"></param>
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<int> InsertRangeAsync(IEnumerable<DataSaubStatDto> dataSaubStats, CancellationToken token);
|
Task<int> InsertRangeAsync(IEnumerable<TDto> dataSaubStats, CancellationToken token);
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ using System.Text.Json.Serialization;
|
|||||||
namespace AsbCloudDb.Model
|
namespace AsbCloudDb.Model
|
||||||
{
|
{
|
||||||
[Table("t_data_saub_stat"), Comment("Кеш-таблица для хранения данных для РТК-отчета")]
|
[Table("t_data_saub_stat"), Comment("Кеш-таблица для хранения данных для РТК-отчета")]
|
||||||
public class DataSaubStat : IId
|
public class DataSaubStat : IId, IDataSaubStat
|
||||||
{
|
{
|
||||||
[Key]
|
[Key]
|
||||||
[Column("id")]
|
[Column("id")]
|
||||||
|
@ -2,12 +2,11 @@ using Microsoft.EntityFrameworkCore;
|
|||||||
using System;
|
using System;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
using System.Text.Json.Serialization;
|
|
||||||
|
|
||||||
namespace AsbCloudDb.Model
|
namespace AsbCloudDb.Model
|
||||||
{
|
{
|
||||||
[Table("t_data_saub_stat_drilling_quality"), Comment("Кеш-таблица для хранения данных для построения страницы \"Качество\"")]
|
[Table("t_data_saub_stat_drilling_quality"), Comment("Кеш-таблица для хранения данных для построения страницы \"Качество\"")]
|
||||||
public class DataSaubStatDrillingQuality : IId
|
public class DataSaubStatDrillingQuality : IId, IDataSaubStat
|
||||||
{
|
{
|
||||||
[Key]
|
[Key]
|
||||||
[Column("id")]
|
[Column("id")]
|
||||||
|
9
AsbCloudDb/Model/SaubStat/IDataSaubStat.cs
Normal file
9
AsbCloudDb/Model/SaubStat/IDataSaubStat.cs
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace AsbCloudDb.Model;
|
||||||
|
public interface IDataSaubStat
|
||||||
|
{
|
||||||
|
public int IdTelemetry { get; set; }
|
||||||
|
public DateTimeOffset DateStart { get; set; }
|
||||||
|
public DateTimeOffset DateEnd { get; set; }
|
||||||
|
}
|
@ -19,7 +19,7 @@ namespace AsbCloudInfrastructure.Tests.Services;
|
|||||||
public class DataSaubStatServiceTest
|
public class DataSaubStatServiceTest
|
||||||
{
|
{
|
||||||
private readonly int Gap = 5;
|
private readonly int Gap = 5;
|
||||||
private readonly IDataSaubStatRepository dataSaubStatRepositoryMock = Substitute.For<IDataSaubStatRepository>();
|
private readonly IDataSaubStatRepository<DataSaubStatDto> dataSaubStatRepositoryMock = Substitute.For<IDataSaubStatRepository<DataSaubStatDto>>();
|
||||||
private readonly ITelemetryDataCache<TelemetryDataSaubDto> telemetryDataCacheMock = Substitute.For<ITelemetryDataCache<TelemetryDataSaubDto>>();
|
private readonly ITelemetryDataCache<TelemetryDataSaubDto> telemetryDataCacheMock = Substitute.For<ITelemetryDataCache<TelemetryDataSaubDto>>();
|
||||||
private readonly IDetectedOperationRepository detectedOperationRepositoryMock = Substitute.For<IDetectedOperationRepository>();
|
private readonly IDetectedOperationRepository detectedOperationRepositoryMock = Substitute.For<IDetectedOperationRepository>();
|
||||||
private readonly ITelemetryDataSaubService dataSaubServiceMock = Substitute.For<ITelemetryDataSaubService>();
|
private readonly ITelemetryDataSaubService dataSaubServiceMock = Substitute.For<ITelemetryDataSaubService>();
|
||||||
|
@ -318,8 +318,8 @@ public static class DependencyInjection
|
|||||||
services.AddTransient<WellInfoService>();
|
services.AddTransient<WellInfoService>();
|
||||||
services.AddTransient<IHelpPageService, HelpPageService>();
|
services.AddTransient<IHelpPageService, HelpPageService>();
|
||||||
services.AddTransient<IScheduleReportService, ScheduleReportService>();
|
services.AddTransient<IScheduleReportService, ScheduleReportService>();
|
||||||
services.AddTransient<IDataSaubStatRepository, DataSaubStatRepository>();
|
services.AddTransient<IDataSaubStatRepository<DataSaubStatDto>, DataSaubStatRepository>();
|
||||||
services.AddTransient<IDataSaubStatDrillingQualityRepository, DataSaubStatDrillingQualityRepository>();
|
services.AddTransient<IDataSaubStatRepository<DataSaubStatDrillingQualityDto>, DataSaubStatDrillingQualityRepository>();
|
||||||
services.AddTransient<IDataSaubStatService, DataSaubStatService>();
|
services.AddTransient<IDataSaubStatService, DataSaubStatService>();
|
||||||
services.AddTransient<IDataSaubStatService, DataSaubStatDrillingQualityService>();
|
services.AddTransient<IDataSaubStatService, DataSaubStatDrillingQualityService>();
|
||||||
services.AddTransient<IWellOperationService, WellOperationService>();
|
services.AddTransient<IWellOperationService, WellOperationService>();
|
||||||
|
@ -0,0 +1,111 @@
|
|||||||
|
using AsbCloudApp.Repositories;
|
||||||
|
using AsbCloudApp.Requests;
|
||||||
|
using AsbCloudApp.Services;
|
||||||
|
using AsbCloudDb.Model;
|
||||||
|
using Mapster;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AsbCloudInfrastructure.Repository;
|
||||||
|
public class DataSaubStatAbstractRepository<TEntity, TDto> : IDataSaubStatRepository<TDto>
|
||||||
|
where TDto : AsbCloudApp.Data.IDataSaubStatDto
|
||||||
|
where TEntity : class, AsbCloudDb.Model.IDataSaubStat
|
||||||
|
{
|
||||||
|
private readonly IAsbCloudDbContext db;
|
||||||
|
private readonly ITelemetryService telemetryService;
|
||||||
|
|
||||||
|
public DataSaubStatAbstractRepository(IAsbCloudDbContext dbContext, ITelemetryService telemetryService)
|
||||||
|
{
|
||||||
|
db = dbContext;
|
||||||
|
this.telemetryService = telemetryService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IEnumerable<TDto>> GetLastsAsync(int[] idTelemetries, CancellationToken token)
|
||||||
|
{
|
||||||
|
var timeZoneOffsets = idTelemetries
|
||||||
|
.Distinct()
|
||||||
|
.ToDictionary(idTelemetry => idTelemetry, idTelemetry => TimeSpan.FromHours(telemetryService.GetTimezone(idTelemetry).Hours));
|
||||||
|
|
||||||
|
var stats = await db.Set<TEntity>()
|
||||||
|
.Where(s => idTelemetries.Contains(s.IdTelemetry))
|
||||||
|
.GroupBy(s => s.IdTelemetry, (key, group) => group.OrderByDescending(el => el.DateEnd).First())
|
||||||
|
.ToArrayAsync(token);
|
||||||
|
|
||||||
|
var result = stats.Select(s => ConvertToDto(s, timeZoneOffsets[s.IdTelemetry]));
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IEnumerable<TDto>> GetAsync(int idTelemetry, DateTimeOffset geDate, DateTimeOffset leDate, CancellationToken token)
|
||||||
|
{
|
||||||
|
var timeSpan = TimeSpan.FromHours(telemetryService.GetTimezone(idTelemetry).Hours);
|
||||||
|
var geDateUtc = geDate.ToUniversalTime();
|
||||||
|
var leDateUtc = leDate.ToUniversalTime();
|
||||||
|
|
||||||
|
var stats = await db.Set<TEntity>()
|
||||||
|
.Where(s => s.IdTelemetry == idTelemetry)
|
||||||
|
.Where(s => s.DateStart >= geDateUtc)
|
||||||
|
.Where(s => s.DateEnd <= leDateUtc)
|
||||||
|
.ToArrayAsync(token);
|
||||||
|
|
||||||
|
var result = stats.Select(s => ConvertToDto(s, timeSpan));
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<int> InsertRangeAsync(IEnumerable<TDto> dataSaubStats, CancellationToken token)
|
||||||
|
{
|
||||||
|
var entities = dataSaubStats.Select(data => ConvertToEntity(data));
|
||||||
|
db.Set<TEntity>().AddRange(entities);
|
||||||
|
return await db.SaveChangesAsync(token);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static TDto ConvertToDto(TEntity entity, TimeSpan timeSpan)
|
||||||
|
{
|
||||||
|
var dto = entity.Adapt<TDto>();
|
||||||
|
dto.DateStart = dto.DateStart.ToOffset(timeSpan);
|
||||||
|
dto.DateEnd = dto.DateEnd.ToOffset(timeSpan);
|
||||||
|
|
||||||
|
return dto;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static TEntity ConvertToEntity(TDto dto)
|
||||||
|
{
|
||||||
|
var entity = dto.Adapt<TEntity>();
|
||||||
|
entity.DateStart = dto.DateStart.ToUniversalTime();
|
||||||
|
entity.DateEnd = dto.DateEnd.ToUniversalTime();
|
||||||
|
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
|
|
||||||
|
private IQueryable<TEntity> BuildQuery(TelemetryPartDeleteRequest request)
|
||||||
|
{
|
||||||
|
var query = db.Set<TEntity>()
|
||||||
|
.Where(o => o.IdTelemetry == request.IdTelemetry);
|
||||||
|
|
||||||
|
if (request.LeDate is not null)
|
||||||
|
{
|
||||||
|
var leDate = request.LeDate.Value.ToUniversalTime();
|
||||||
|
query = query.Where(o => o.DateStart <= leDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (request.GeDate is not null)
|
||||||
|
{
|
||||||
|
var geDate = request.GeDate.Value.ToUniversalTime();
|
||||||
|
query = query.Where(o => o.DateEnd >= geDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
return query;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<int> DeleteAsync(TelemetryPartDeleteRequest request, CancellationToken token)
|
||||||
|
{
|
||||||
|
var query = BuildQuery(request);
|
||||||
|
db.Set<TEntity>().RemoveRange(query);
|
||||||
|
return await db.SaveChangesAsync(token);
|
||||||
|
}
|
||||||
|
}
|
@ -1,111 +1,21 @@
|
|||||||
using AsbCloudApp.Data;
|
using AsbCloudApp.Data;
|
||||||
using AsbCloudApp.Repositories;
|
|
||||||
using AsbCloudApp.Requests;
|
|
||||||
using AsbCloudApp.Services;
|
using AsbCloudApp.Services;
|
||||||
using AsbCloudDb.Model;
|
using AsbCloudDb.Model;
|
||||||
using Mapster;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace AsbCloudInfrastructure.Repository;
|
namespace AsbCloudInfrastructure.Repository;
|
||||||
|
|
||||||
public class DataSaubStatDrillingQualityRepository : IDataSaubStatDrillingQualityRepository
|
/// <summary>
|
||||||
|
/// Àáñòðàêòíûé ðåïîçèòîðèé äëÿ ðàáîòû ñ äàííûìè data_saub_stat
|
||||||
|
/// </summary>
|
||||||
|
public class DataSaubStatDrillingQualityRepository : DataSaubStatAbstractRepository<DataSaubStatDrillingQuality, DataSaubStatDrillingQualityDto>
|
||||||
{
|
{
|
||||||
private readonly IAsbCloudDbContext db;
|
/// <summary>
|
||||||
private readonly ITelemetryService telemetryService;
|
/// <inheritdoc/>
|
||||||
|
/// </summary>
|
||||||
public DataSaubStatDrillingQualityRepository(IAsbCloudDbContext dbContext, ITelemetryService telemetryService)
|
/// <param name="dbContext"></param>
|
||||||
|
/// <param name="telemetryService"></param>
|
||||||
|
public DataSaubStatDrillingQualityRepository(IAsbCloudDbContext dbContext, ITelemetryService telemetryService) : base(dbContext, telemetryService)
|
||||||
{
|
{
|
||||||
db = dbContext;
|
|
||||||
this.telemetryService = telemetryService;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<IEnumerable<DataSaubStatDrillingQualityDto>> GetLastsAsync(int[] idTelemetries, CancellationToken token)
|
|
||||||
{
|
|
||||||
var timeZoneOffsets = idTelemetries
|
|
||||||
.Distinct()
|
|
||||||
.ToDictionary(idTelemetry => idTelemetry, idTelemetry => TimeSpan.FromHours(telemetryService.GetTimezone(idTelemetry).Hours));
|
|
||||||
|
|
||||||
var stats = await db.Set<DataSaubStatDrillingQuality>()
|
|
||||||
.Where(s => idTelemetries.Contains(s.IdTelemetry))
|
|
||||||
.GroupBy(s => s.IdTelemetry, (key, group) => group.OrderByDescending(el => el.DateEnd).First())
|
|
||||||
.ToArrayAsync(token);
|
|
||||||
|
|
||||||
var result = stats.Select(s => ConvertToDto(s, timeZoneOffsets[s.IdTelemetry]));
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<IEnumerable<DataSaubStatDrillingQualityDto>> GetAsync(int idTelemetry, DateTimeOffset geDate, DateTimeOffset leDate, CancellationToken token)
|
|
||||||
{
|
|
||||||
var timeSpan = TimeSpan.FromHours(telemetryService.GetTimezone(idTelemetry).Hours);
|
|
||||||
var geDateUtc = geDate.ToUniversalTime();
|
|
||||||
var leDateUtc = leDate.ToUniversalTime();
|
|
||||||
|
|
||||||
var stats = await db.Set<DataSaubStatDrillingQuality>()
|
|
||||||
.Where(s => s.IdTelemetry == idTelemetry)
|
|
||||||
.Where(s => s.DateStart >= geDateUtc)
|
|
||||||
.Where(s => s.DateEnd <= leDateUtc)
|
|
||||||
.ToArrayAsync(token);
|
|
||||||
|
|
||||||
var result = stats.Select(s => ConvertToDto(s, timeSpan));
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<int> InsertRangeAsync(IEnumerable<DataSaubStatDrillingQualityDto> dataSaubStats, CancellationToken token)
|
|
||||||
{
|
|
||||||
var entities = dataSaubStats.Select(data => ConvertToEntity(data));
|
|
||||||
db.Set<DataSaubStatDrillingQuality>().AddRange(entities);
|
|
||||||
return await db.SaveChangesAsync(token);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static DataSaubStatDrillingQualityDto ConvertToDto(DataSaubStatDrillingQuality entity, TimeSpan timeSpan)
|
|
||||||
{
|
|
||||||
var dto = entity.Adapt<DataSaubStatDrillingQualityDto>();
|
|
||||||
dto.DateStart = dto.DateStart.ToOffset(timeSpan);
|
|
||||||
dto.DateEnd = dto.DateEnd.ToOffset(timeSpan);
|
|
||||||
|
|
||||||
return dto;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static DataSaubStatDrillingQuality ConvertToEntity(DataSaubStatDrillingQualityDto dto)
|
|
||||||
{
|
|
||||||
var entity = dto.Adapt<DataSaubStatDrillingQuality>();
|
|
||||||
entity.DateStart = dto.DateStart.ToUniversalTime();
|
|
||||||
entity.DateEnd = dto.DateEnd.ToUniversalTime();
|
|
||||||
|
|
||||||
return entity;
|
|
||||||
}
|
|
||||||
|
|
||||||
private IQueryable<DataSaubStatDrillingQuality> BuildQuery(TelemetryPartDeleteRequest request)
|
|
||||||
{
|
|
||||||
var query = db.Set<DataSaubStatDrillingQuality>()
|
|
||||||
.Where(o => o.IdTelemetry == request.IdTelemetry);
|
|
||||||
|
|
||||||
if (request.LeDate is not null)
|
|
||||||
{
|
|
||||||
var leDate = request.LeDate.Value.ToUniversalTime();
|
|
||||||
query = query.Where(o => o.DateStart <= leDate);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (request.GeDate is not null)
|
|
||||||
{
|
|
||||||
var geDate = request.GeDate.Value.ToUniversalTime();
|
|
||||||
query = query.Where(o => o.DateEnd >= geDate);
|
|
||||||
}
|
|
||||||
|
|
||||||
return query;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<int> DeleteAsync(TelemetryPartDeleteRequest request, CancellationToken token)
|
|
||||||
{
|
|
||||||
var query = BuildQuery(request);
|
|
||||||
db.Set<DataSaubStatDrillingQuality>().RemoveRange(query);
|
|
||||||
return await db.SaveChangesAsync(token);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,112 +1,18 @@
|
|||||||
using AsbCloudApp.Data;
|
using AsbCloudApp.Data;
|
||||||
using AsbCloudApp.Repositories;
|
|
||||||
using AsbCloudApp.Requests;
|
|
||||||
using AsbCloudApp.Services;
|
using AsbCloudApp.Services;
|
||||||
using AsbCloudDb.Model;
|
using AsbCloudDb.Model;
|
||||||
using Mapster;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace AsbCloudInfrastructure.Repository;
|
namespace AsbCloudInfrastructure.Repository;
|
||||||
|
|
||||||
public class DataSaubStatRepository : IDataSaubStatRepository
|
public class DataSaubStatRepository : DataSaubStatAbstractRepository<DataSaubStat, DataSaubStatDto>
|
||||||
{
|
{
|
||||||
private readonly IAsbCloudDbContext db;
|
/// <summary>
|
||||||
private readonly ITelemetryService telemetryService;
|
/// <inheritdoc/>
|
||||||
|
/// </summary>
|
||||||
public DataSaubStatRepository(IAsbCloudDbContext dbContext, ITelemetryService telemetryService)
|
/// <param name="dbContext"></param>
|
||||||
|
/// <param name="telemetryService"></param>
|
||||||
|
public DataSaubStatRepository(IAsbCloudDbContext dbContext, ITelemetryService telemetryService) : base(dbContext, telemetryService)
|
||||||
{
|
{
|
||||||
db = dbContext;
|
|
||||||
this.telemetryService = telemetryService;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IEnumerable<DataSaubStatDto>> GetLastsAsync(int[] idTelemetries, CancellationToken token)
|
|
||||||
{
|
|
||||||
var timeZoneOffsets = idTelemetries
|
|
||||||
.Distinct()
|
|
||||||
.ToDictionary(idTelemetry => idTelemetry, idTelemetry => TimeSpan.FromHours(telemetryService.GetTimezone(idTelemetry).Hours));
|
|
||||||
|
|
||||||
var stats = await db.Set<DataSaubStat>()
|
|
||||||
.Where(s => idTelemetries.Contains(s.IdTelemetry))
|
|
||||||
.GroupBy(s => s.IdTelemetry, (key, group) => group.OrderByDescending(el => el.DateEnd).First())
|
|
||||||
.ToArrayAsync(token);
|
|
||||||
|
|
||||||
var result = stats.Select(s => ConvertToDto(s, timeZoneOffsets[s.IdTelemetry]));
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<IEnumerable<DataSaubStatDto>> GetAsync(int idTelemetry, DateTimeOffset geDate, DateTimeOffset leDate, CancellationToken token)
|
|
||||||
{
|
|
||||||
var timeSpan = TimeSpan.FromHours(telemetryService.GetTimezone(idTelemetry).Hours);
|
|
||||||
var geDateUtc = geDate.ToUniversalTime();
|
|
||||||
var leDateUtc = leDate.ToUniversalTime();
|
|
||||||
|
|
||||||
var stats = await db.Set<DataSaubStat>()
|
|
||||||
.Where(s => s.IdTelemetry == idTelemetry)
|
|
||||||
.Where(s => s.DateStart >= geDateUtc)
|
|
||||||
.Where(s => s.DateEnd <= leDateUtc)
|
|
||||||
.ToArrayAsync(token);
|
|
||||||
|
|
||||||
var result = stats.Select(s => ConvertToDto(s, timeSpan));
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<int> InsertRangeAsync(IEnumerable<DataSaubStatDto> dataSaubStats, CancellationToken token)
|
|
||||||
{
|
|
||||||
var entities = dataSaubStats.Select(data => ConvertToEntity(data));
|
|
||||||
db.Set<DataSaubStat>().AddRange(entities);
|
|
||||||
return await db.SaveChangesAsync(token);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static DataSaubStatDto ConvertToDto(DataSaubStat entity, TimeSpan timeSpan)
|
|
||||||
{
|
|
||||||
var dto = entity.Adapt<DataSaubStatDto>();
|
|
||||||
dto.DateStart = dto.DateStart.ToOffset(timeSpan);
|
|
||||||
dto.DateEnd = dto.DateEnd.ToOffset(timeSpan);
|
|
||||||
|
|
||||||
return dto;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static DataSaubStat ConvertToEntity(DataSaubStatDto dto)
|
|
||||||
{
|
|
||||||
var entity = dto.Adapt<DataSaubStat>();
|
|
||||||
entity.DateStart = dto.DateStart.ToUniversalTime();
|
|
||||||
entity.DateEnd = dto.DateEnd.ToUniversalTime();
|
|
||||||
|
|
||||||
return entity;
|
|
||||||
}
|
|
||||||
|
|
||||||
private IQueryable<DataSaubStat> BuildQuery(TelemetryPartDeleteRequest request)
|
|
||||||
{
|
|
||||||
var query = db.Set<DataSaubStat>()
|
|
||||||
.Where(o => o.IdTelemetry == request.IdTelemetry);
|
|
||||||
|
|
||||||
if (request.LeDate is not null)
|
|
||||||
{
|
|
||||||
var leDate = request.LeDate.Value.ToUniversalTime();
|
|
||||||
query = query.Where(o => o.DateStart <= leDate);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (request.GeDate is not null)
|
|
||||||
{
|
|
||||||
var geDate = request.GeDate.Value.ToUniversalTime();
|
|
||||||
query = query.Where(o => o.DateEnd >= geDate);
|
|
||||||
}
|
|
||||||
|
|
||||||
return query;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<int> DeleteAsync(TelemetryPartDeleteRequest request, CancellationToken token)
|
|
||||||
{
|
|
||||||
var query = BuildQuery(request);
|
|
||||||
db.Set<DataSaubStat>().RemoveRange(query);
|
|
||||||
return await db.SaveChangesAsync(token);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@ using AsbCloudApp.Data.SAUB;
|
|||||||
using AsbCloudApp.Repositories;
|
using AsbCloudApp.Repositories;
|
||||||
using AsbCloudApp.Requests;
|
using AsbCloudApp.Requests;
|
||||||
using AsbCloudApp.Services;
|
using AsbCloudApp.Services;
|
||||||
using AsbCloudInfrastructure.Services.SAUB;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@ -15,14 +14,14 @@ namespace AsbCloudInfrastructure.Services;
|
|||||||
|
|
||||||
public class DataSaubStatDrillingQualityService : IDataSaubStatService
|
public class DataSaubStatDrillingQualityService : IDataSaubStatService
|
||||||
{
|
{
|
||||||
private IDataSaubStatDrillingQualityRepository dataSaubStatDrillingQualityRepository;
|
private IDataSaubStatRepository<DataSaubStatDrillingQualityDto> dataSaubStatDrillingQualityRepository;
|
||||||
private ITelemetryDataSaubService dataSaubService;
|
private ITelemetryDataSaubService dataSaubService;
|
||||||
private ITelemetryDataCache<TelemetryDataSaubDto> telemetryDataCache;
|
private ITelemetryDataCache<TelemetryDataSaubDto> telemetryDataCache;
|
||||||
|
|
||||||
public Dictionary<int, Predicate<TelemetryDataSaubDto>> QualitySettingsForFeedRegulators { get; }
|
public Dictionary<int, Predicate<TelemetryDataSaubDto>> QualitySettingsForFeedRegulators { get; }
|
||||||
|
|
||||||
public DataSaubStatDrillingQualityService(
|
public DataSaubStatDrillingQualityService(
|
||||||
IDataSaubStatDrillingQualityRepository dataSaubStatDrillingQualityRepository,
|
IDataSaubStatRepository<DataSaubStatDrillingQualityDto> dataSaubStatDrillingQualityRepository,
|
||||||
ITelemetryDataCache<TelemetryDataSaubDto> telemetryDataCache,
|
ITelemetryDataCache<TelemetryDataSaubDto> telemetryDataCache,
|
||||||
ITelemetryDataSaubService dataSaubService)
|
ITelemetryDataSaubService dataSaubService)
|
||||||
{
|
{
|
||||||
@ -115,7 +114,7 @@ public class DataSaubStatDrillingQualityService : IDataSaubStatService
|
|||||||
var indexStart = 0;
|
var indexStart = 0;
|
||||||
var indexEnd = 0;
|
var indexEnd = 0;
|
||||||
|
|
||||||
while (indexEnd < dataSaub.Count())
|
while (indexEnd < dataSaub.Count() - 1)
|
||||||
{
|
{
|
||||||
indexStart = Array.FindIndex(dataSaub, indexEnd, t => t.IdFeedRegulator == idFeedRegulator);
|
indexStart = Array.FindIndex(dataSaub, indexEnd, t => t.IdFeedRegulator == idFeedRegulator);
|
||||||
if (indexStart < 0)
|
if (indexStart < 0)
|
||||||
|
@ -16,13 +16,13 @@ namespace AsbCloudInfrastructure.Services;
|
|||||||
|
|
||||||
public class DataSaubStatService : IDataSaubStatService
|
public class DataSaubStatService : IDataSaubStatService
|
||||||
{
|
{
|
||||||
private IDataSaubStatRepository dataSaubStatRepository;
|
private IDataSaubStatRepository<DataSaubStatDto> dataSaubStatRepository;
|
||||||
private ITelemetryDataCache<TelemetryDataSaubDto> telemetryDataCache;
|
private ITelemetryDataCache<TelemetryDataSaubDto> telemetryDataCache;
|
||||||
private ITelemetryDataSaubService dataSaubService;
|
private ITelemetryDataSaubService dataSaubService;
|
||||||
private IDetectedOperationRepository detectedOperationRepository;
|
private IDetectedOperationRepository detectedOperationRepository;
|
||||||
|
|
||||||
public DataSaubStatService(
|
public DataSaubStatService(
|
||||||
IDataSaubStatRepository dataSaubStatRepository,
|
IDataSaubStatRepository<DataSaubStatDto> dataSaubStatRepository,
|
||||||
ITelemetryDataCache<TelemetryDataSaubDto> telemetryDataCache,
|
ITelemetryDataCache<TelemetryDataSaubDto> telemetryDataCache,
|
||||||
ITelemetryDataSaubService dataSaubService,
|
ITelemetryDataSaubService dataSaubService,
|
||||||
IDetectedOperationRepository detectedOperationRepository)
|
IDetectedOperationRepository detectedOperationRepository)
|
||||||
|
@ -23,7 +23,7 @@ public class ProcessMapReportDrillingService : IProcessMapReportDrillingService
|
|||||||
private readonly IWellService wellService;
|
private readonly IWellService wellService;
|
||||||
private readonly IChangeLogRepository<ProcessMapPlanRotorDto, ProcessMapPlanBaseRequestWithWell> processMapPlanRotorRepository;
|
private readonly IChangeLogRepository<ProcessMapPlanRotorDto, ProcessMapPlanBaseRequestWithWell> processMapPlanRotorRepository;
|
||||||
private readonly IChangeLogRepository<ProcessMapPlanSlideDto, ProcessMapPlanBaseRequestWithWell> processMapPlanSlideRepository;
|
private readonly IChangeLogRepository<ProcessMapPlanSlideDto, ProcessMapPlanBaseRequestWithWell> processMapPlanSlideRepository;
|
||||||
private readonly IDataSaubStatRepository dataSaubStatRepository;
|
private readonly IDataSaubStatRepository<DataSaubStatDto> dataSaubStatRepository;
|
||||||
private readonly IWellOperationRepository wellOperationRepository;
|
private readonly IWellOperationRepository wellOperationRepository;
|
||||||
private readonly IWellOperationCategoryRepository wellOperationCategoryRepository;
|
private readonly IWellOperationCategoryRepository wellOperationCategoryRepository;
|
||||||
private readonly IWellOperationService wellOperationService;
|
private readonly IWellOperationService wellOperationService;
|
||||||
@ -31,7 +31,7 @@ public class ProcessMapReportDrillingService : IProcessMapReportDrillingService
|
|||||||
public ProcessMapReportDrillingService(IWellService wellService,
|
public ProcessMapReportDrillingService(IWellService wellService,
|
||||||
IChangeLogRepository<ProcessMapPlanRotorDto, ProcessMapPlanBaseRequestWithWell> processMapPlanRotorRepository,
|
IChangeLogRepository<ProcessMapPlanRotorDto, ProcessMapPlanBaseRequestWithWell> processMapPlanRotorRepository,
|
||||||
IChangeLogRepository<ProcessMapPlanSlideDto, ProcessMapPlanBaseRequestWithWell> processMapPlanSlideRepository,
|
IChangeLogRepository<ProcessMapPlanSlideDto, ProcessMapPlanBaseRequestWithWell> processMapPlanSlideRepository,
|
||||||
IDataSaubStatRepository dataSaubStatRepository,
|
IDataSaubStatRepository<DataSaubStatDto> dataSaubStatRepository,
|
||||||
IWellOperationRepository wellOperationRepository,
|
IWellOperationRepository wellOperationRepository,
|
||||||
IWellOperationCategoryRepository wellOperationCategoryRepository,
|
IWellOperationCategoryRepository wellOperationCategoryRepository,
|
||||||
IWellOperationService wellOperationService
|
IWellOperationService wellOperationService
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
using AsbCloudApp.Data;
|
||||||
using AsbCloudApp.Data.SAUB;
|
using AsbCloudApp.Data.SAUB;
|
||||||
using AsbCloudApp.Data.WITS;
|
using AsbCloudApp.Data.WITS;
|
||||||
using AsbCloudApp.Repositories;
|
using AsbCloudApp.Repositories;
|
||||||
@ -35,7 +36,7 @@ public class TelemetryDataEditorService : ITelemetryDataEditorService
|
|||||||
public TelemetryDataEditorService(
|
public TelemetryDataEditorService(
|
||||||
ITelemetryDataSaubService dataSaubService,
|
ITelemetryDataSaubService dataSaubService,
|
||||||
ITelemetryDataService<TelemetryDataSpinDto> dataSpinService,
|
ITelemetryDataService<TelemetryDataSpinDto> dataSpinService,
|
||||||
IDataSaubStatRepository dataSaubStatRepository,
|
IDataSaubStatRepository<DataSaubStatDto> dataSaubStatRepository,
|
||||||
IMessageRepository messageRepository,
|
IMessageRepository messageRepository,
|
||||||
IDrillTestRepository drillTestRepository,
|
IDrillTestRepository drillTestRepository,
|
||||||
ILimitingParameterRepository limitingParameterRepository,
|
ILimitingParameterRepository limitingParameterRepository,
|
||||||
|
@ -10,12 +10,12 @@ namespace AsbCloudWebApi.IntegrationTests.Repository;
|
|||||||
|
|
||||||
public class DataSaubStatRepositoryTest : BaseIntegrationTest
|
public class DataSaubStatRepositoryTest : BaseIntegrationTest
|
||||||
{
|
{
|
||||||
private readonly IDataSaubStatRepository dataSaubStatRepository;
|
private readonly IDataSaubStatRepository<DataSaubStatDto> dataSaubStatRepository;
|
||||||
|
|
||||||
public DataSaubStatRepositoryTest(WebAppFactoryFixture factory)
|
public DataSaubStatRepositoryTest(WebAppFactoryFixture factory)
|
||||||
: base(factory)
|
: base(factory)
|
||||||
{
|
{
|
||||||
dataSaubStatRepository = scope.ServiceProvider.GetRequiredService<IDataSaubStatRepository>();
|
dataSaubStatRepository = scope.ServiceProvider.GetRequiredService<IDataSaubStatRepository<DataSaubStatDto>>();
|
||||||
dbContext.CleanupDbSet<DataSaubStat>();
|
dbContext.CleanupDbSet<DataSaubStat>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user