delete manual timescale script (error index)

edit generic repository
This commit is contained in:
eugeniy_ivanov 2023-04-07 04:51:30 +05:00
parent 75738b7712
commit e26c5d98a7
5 changed files with 80 additions and 15 deletions

View File

@ -4,7 +4,7 @@ using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace AsbCloudApp.Services.WITS
namespace AsbCloudApp.Repositories
{
#nullable enable
/// <summary>

View File

@ -74,10 +74,10 @@ namespace AsbCloudDb.Migrations
onDelete: ReferentialAction.Cascade);
},
comment: "таблица данных ГТИ с типом значения string");
migrationBuilder.Sql
("SELECT create_hypertable('t_wits_string','time','id_telemetry',chunk_time_interval => INTERVAL '5 day'); " +
"SELECT create_hypertable('t_wits_float','time','id_telemetry',chunk_time_interval => INTERVAL '5 day'); " +
"SELECT create_hypertable('t_wits_int','time','id_telemetry',chunk_time_interval => INTERVAL '5 day'); ");
//migrationBuilder.Sql
// ("SELECT create_hypertable('t_wits_string','date','id_telemetry', 2, chunk_time_interval => INTERVAL '5 day'); " +
// "SELECT create_hypertable('t_wits_float','date','id_telemetry', 2, chunk_time_interval => INTERVAL '5 day'); " +
// "SELECT create_hypertable('t_wits_int','date','id_telemetry', 2, chunk_time_interval => INTERVAL '5 day'); ");
}
protected override void Down(MigrationBuilder migrationBuilder)

View File

@ -1,10 +1,12 @@
using AsbCloudApp.Data;
using AsbCloudApp.Data.GTR;
using AsbCloudApp.Data.SAUB;
using AsbCloudApp.Data.Subsystems;
using AsbCloudApp.Repositories;
using AsbCloudApp.Services;
using AsbCloudApp.Services.Subsystems;
using AsbCloudDb.Model;
using AsbCloudDb.Model.GTR;
using AsbCloudDb.Model.Subsystems;
using AsbCloudInfrastructure.Background;
using AsbCloudInfrastructure.Repository;
@ -136,6 +138,9 @@ namespace AsbCloudInfrastructure
services.AddTransient<IProcessMapReportService, ProcessMapReportService>();
services.AddTransient<IProcessMapService, ProcessMapService>();
services.AddTransient<ITrajectoryVisualizationService, TrajectoryVisualizationService>();
services.AddTransient<IGtrRepository, GtrWitsRepository<WitsItemBase<int>,int>>();
services.AddTransient<IGtrRepository, GtrWitsRepository<WitsItemBase<float>, float>>();
services.AddTransient<IGtrRepository, GtrWitsRepository<WitsItemBase<string>, string>>();
// admin crud services:
services.AddTransient<ICrudRepository<TelemetryDto>, CrudCacheRepositoryBase<TelemetryDto, Telemetry>>(s =>

View File

@ -1,6 +1,6 @@
using AsbCloudApp.Data.GTR;
using AsbCloudApp.Repositories;
using AsbCloudApp.Services;
using AsbCloudApp.Services.WITS;
using AsbCloudDb.Model;
using AsbCloudDb.Model.GTR;
using Microsoft.EntityFrameworkCore;
@ -13,19 +13,19 @@ using System.Threading.Tasks;
namespace AsbCloudInfrastructure.Repository
{
#nullable enable
public class GtrWitsRepository<T> : IGtrRepository
where T : WitsItemBase<T>
public class GtrWitsRepository<TEntity, T> : IGtrRepository
where TEntity : WitsItemBase<T>
{
private readonly IAsbCloudDbContext db;
private readonly ITelemetryService telemetryService;
private readonly DbSet<T> dbset;
private readonly DbSet<TEntity> dbset;
private static Random random = new Random((int)(DateTime.Now.Ticks % 0xFFFFFFFF));
public GtrWitsRepository(
IAsbCloudDbContext db,
ITelemetryService telemetryService)
{
dbset = db.Set<T>();
dbset = db.Set<TEntity>();
this.db = db;
this.telemetryService = telemetryService;
}
@ -60,7 +60,7 @@ namespace AsbCloudInfrastructure.Repository
// return cacheData;
var dateEnd = dateBeginUtc.AddSeconds(intervalSec);
var dbSet = db.Set<T>();
var dbSet = db.Set<TEntity>();
var query = dbSet
.Where(d => d.IdTelemetry == telemetry.Id
@ -120,7 +120,7 @@ namespace AsbCloudInfrastructure.Repository
{
if (!existingEntities.Any(e => e == entity.DateTime))
{
dbset.Add((T)entity);
dbset.Add((TEntity)entity);
}
else
{
@ -134,7 +134,7 @@ namespace AsbCloudInfrastructure.Repository
dt.Second,
(dt.Millisecond + random.Next(1, 283)) % 1000,
dt.Offset);
dbset.Add((T)entity);
dbset.Add((TEntity)entity);
}
}
await db.SaveChangesAsync(token);

View File

@ -1,5 +1,15 @@
using Microsoft.AspNetCore.Http;
using AsbCloudApp.Data.GTR;
using AsbCloudApp.Repositories;
using AsbCloudApp.Services;
using AsbCloudDb.Model;
using AsbCloudWebApi.SignalR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.SignalR;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace AsbCloudWebApi.Controllers.GTR
{
@ -7,5 +17,55 @@ namespace AsbCloudWebApi.Controllers.GTR
[ApiController]
public class GtrWitsController : ControllerBase
{
protected readonly IWellService wellService;
private readonly ITelemetryService telemetryService;
private readonly IGtrRepository gtrRepository;
private readonly IHubContext<TelemetryHub> telemetryHubContext;
//public string SirnalRMethodGetDataName { get; protected set; } = "ReceiveData";
public GtrWitsController(
ITelemetryService telemetryService,
IGtrRepository gtrRepository,
IWellService wellService,
IHubContext<TelemetryHub> telemetryHubContext)
{
this.telemetryService = telemetryService;
this.gtrRepository = gtrRepository;
this.wellService = wellService;
this.telemetryHubContext = telemetryHubContext;
}
/// <summary>
/// Возвращает данные САУБ по скважине.
/// По умолчанию за последние 10 минут.
/// </summary>
/// <param name="idWell">id скважины</param>
/// <param name="begin">дата начала выборки. По умолчанию: текущее время - intervalSec</param>
/// <param name="intervalSec">интервал времени даты начала выборки, секунды</param>
/// <param name="approxPointsCount">желаемое количество точек. Если в выборке точек будет больше, то выборка будет прорежена.</param>
/// <param name="token">Токен завершения задачи</param>
/// <returns></returns>
[HttpGet("{idWell}")]
//[Permission]
public virtual async Task<ActionResult<IEnumerable<WitsRecordDto>>> GetDataAsync(int idWell, DateTime begin = default,
int intervalSec = 600, int approxPointsCount = 1024, CancellationToken token = default)
{
//int? idCompany = User.GetCompanyId();
//if (idCompany is null)
// return Forbid();
//bool isCompanyOwnsWell = await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
// idWell, token).ConfigureAwait(false);
//if (!isCompanyOwnsWell)
// return Forbid();
var content = await gtrRepository.GetAsync(idWell, begin,
intervalSec, approxPointsCount, token).ConfigureAwait(false);
return Ok(content);
}
}
}