edit generic

This commit is contained in:
eugeniy_ivanov 2023-04-07 05:32:03 +05:00
parent 75ae8485cb
commit 8e663e7bef
4 changed files with 34 additions and 32 deletions

View File

@ -4,13 +4,14 @@ using System.Collections.Generic;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace AsbCloudApp.Repositories namespace AsbCloudApp.Repositories
{ {
#nullable enable #nullable enable
/// <summary> /// <summary>
/// данные ГТИ /// данные ГТИ
/// </summary> /// </summary>
public interface IGtrRepository public interface IGtrRepository<T>
{ {
/// <summary> /// <summary>
/// добавить данные (для панели бурильщика) /// добавить данные (для панели бурильщика)

View File

@ -138,9 +138,9 @@ namespace AsbCloudInfrastructure
services.AddTransient<IProcessMapReportService, ProcessMapReportService>(); services.AddTransient<IProcessMapReportService, ProcessMapReportService>();
services.AddTransient<IProcessMapService, ProcessMapService>(); services.AddTransient<IProcessMapService, ProcessMapService>();
services.AddTransient<ITrajectoryVisualizationService, TrajectoryVisualizationService>(); services.AddTransient<ITrajectoryVisualizationService, TrajectoryVisualizationService>();
services.AddTransient<IGtrRepository, GtrWitsRepository<WitsItemInt,int>>(); services.AddTransient<IGtrRepository<int>, GtrWitsRepository<WitsItemInt,int>>();
services.AddTransient<IGtrRepository, GtrWitsRepository<WitsItemFloat, float>>(); services.AddTransient<IGtrRepository<float>, GtrWitsRepository<WitsItemFloat, float>>();
services.AddTransient<IGtrRepository, GtrWitsRepository<WitsItemString, string>>(); services.AddTransient<IGtrRepository<string>, GtrWitsRepository<WitsItemString, string>>();
// admin crud services: // admin crud services:
services.AddTransient<ICrudRepository<TelemetryDto>, CrudCacheRepositoryBase<TelemetryDto, Telemetry>>(s => services.AddTransient<ICrudRepository<TelemetryDto>, CrudCacheRepositoryBase<TelemetryDto, Telemetry>>(s =>

View File

@ -13,7 +13,7 @@ using System.Threading.Tasks;
namespace AsbCloudInfrastructure.Repository namespace AsbCloudInfrastructure.Repository
{ {
#nullable enable #nullable enable
public class GtrWitsRepository<TEntity, T> : IGtrRepository public class GtrWitsRepository<TEntity, T> : IGtrRepository <T>
where TEntity : WitsItemBase<T> where TEntity : WitsItemBase<T>
{ {
private readonly IAsbCloudDbContext db; private readonly IAsbCloudDbContext db;
@ -72,15 +72,15 @@ namespace AsbCloudInfrastructure.Repository
var fullDataCount = await query.CountAsync(token) var fullDataCount = await query.CountAsync(token)
.ConfigureAwait(false); .ConfigureAwait(false);
if (fullDataCount == 0) //if (fullDataCount == 0)
return Enumerable.Empty<WitsRecordDto>(); // return Enumerable.Empty<WitsRecordDto>();
if (fullDataCount > 1.75 * approxPointsCount) //if (fullDataCount > 1.75 * approxPointsCount)
{ //{
var m = (int)Math.Round(1d * fullDataCount / approxPointsCount); // var m = (int)Math.Round(1d * fullDataCount / approxPointsCount);
if (m > 1) // if (m > 1)
query = query.Where((d) => (((d.DateTime.DayOfYear * 24 + d.DateTime.Hour) * 60 + d.DateTime.Minute) * 60 + d.DateTime.Second) % m == 0); // query = query.Where((d) => (((d.DateTime.DayOfYear * 24 + d.DateTime.Hour) * 60 + d.DateTime.Minute) * 60 + d.DateTime.Second) % m == 0);
} //}
var entities = await query var entities = await query
.OrderBy(d => d.DateTime) .OrderBy(d => d.DateTime)

View File

@ -16,22 +16,23 @@ namespace AsbCloudWebApi.Controllers.GTR
[Route("api/[controller]")] [Route("api/[controller]")]
[ApiController] [ApiController]
public class GtrWitsController : ControllerBase public class GtrWitsController : ControllerBase
{ {
protected readonly IWellService wellService; protected readonly IWellService wellService;
private readonly ITelemetryService telemetryService; private readonly ITelemetryService telemetryService;
private readonly IGtrRepository gtrRepository; //private readonly IGtrRepository<float> gtrRepository;
private readonly IHubContext<TelemetryHub> telemetryHubContext; private readonly IHubContext<TelemetryHub> telemetryHubContext;
//public string SirnalRMethodGetDataName { get; protected set; } = "ReceiveData"; //public string SirnalRMethodGetDataName { get; protected set; } = "ReceiveData";
public GtrWitsController( public GtrWitsController(
ITelemetryService telemetryService, ITelemetryService telemetryService,
IGtrRepository gtrRepository, // IGtrRepository<float> gtrRepository,
IWellService wellService, IWellService wellService,
IHubContext<TelemetryHub> telemetryHubContext) IHubContext<TelemetryHub> telemetryHubContext)
{ {
this.telemetryService = telemetryService; this.telemetryService = telemetryService;
this.gtrRepository = gtrRepository; //this.gtrRepository = gtrRepository;
this.wellService = wellService; this.wellService = wellService;
this.telemetryHubContext = telemetryHubContext; this.telemetryHubContext = telemetryHubContext;
} }
@ -46,26 +47,26 @@ namespace AsbCloudWebApi.Controllers.GTR
/// <param name="approxPointsCount">желаемое количество точек. Если в выборке точек будет больше, то выборка будет прорежена.</param> /// <param name="approxPointsCount">желаемое количество точек. Если в выборке точек будет больше, то выборка будет прорежена.</param>
/// <param name="token">Токен завершения задачи</param> /// <param name="token">Токен завершения задачи</param>
/// <returns></returns> /// <returns></returns>
[HttpGet("{idWell}")] //[HttpGet("{idWell}")]
//[Permission] ////[Permission]
public virtual async Task<ActionResult<IEnumerable<WitsRecordDto>>> GetDataAsync(int idWell, DateTime begin = default, //public async Task<ActionResult<IEnumerable<WitsRecordDto>>> GetDataAsync(int idWell, DateTime begin = default,
int intervalSec = 600, int approxPointsCount = 1024, CancellationToken token = default) // int intervalSec = 600, int approxPointsCount = 1024, CancellationToken token = default)
{ //{
//int? idCompany = User.GetCompanyId(); // //int? idCompany = User.GetCompanyId();
//if (idCompany is null) // //if (idCompany is null)
// return Forbid(); // // return Forbid();
//bool isCompanyOwnsWell = await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, // //bool isCompanyOwnsWell = await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
// idWell, token).ConfigureAwait(false); // // idWell, token).ConfigureAwait(false);
//if (!isCompanyOwnsWell) // //if (!isCompanyOwnsWell)
// return Forbid(); // // return Forbid();
var content = await gtrRepository.GetAsync(idWell, begin, // //var content = await gtrRepository.GetAsync(idWell, begin,
intervalSec, approxPointsCount, token).ConfigureAwait(false); // // intervalSec, approxPointsCount, token).ConfigureAwait(false);
return Ok(content); // //return Ok(content);
} //}
} }
} }