forked from ddrilling/AsbCloudServer
fix controller
This commit is contained in:
parent
33ebaf39c1
commit
f81f092c64
@ -55,18 +55,15 @@ namespace AsbCloudInfrastructure.Repository
|
||||
var dateEnd = dateBeginUtc.AddSeconds(intervalSec);
|
||||
|
||||
var queryWitsInt = db.Set<WitsItemInt>()
|
||||
.Where(d => d.IdTelemetry == telemetry.Id
|
||||
&& d.DateTime >= dateBeginUtc);
|
||||
.Where(d => d.IdTelemetry == telemetry.Id);
|
||||
var queryWitsString = db.Set<WitsItemString>()
|
||||
.Where(d => d.IdTelemetry == telemetry.Id
|
||||
&& d.DateTime >= dateBeginUtc);
|
||||
.Where(d => d.IdTelemetry == telemetry.Id);
|
||||
var queryWitsFloat = db.Set<WitsItemFloat>()
|
||||
.Where(d => d.IdTelemetry == telemetry.Id
|
||||
&& d.DateTime >= dateBeginUtc);
|
||||
.Where(d => d.IdTelemetry == telemetry.Id);
|
||||
|
||||
var recordAllInt = await GetItemsOrDefaultAsync(queryWitsInt, dateEnd, filterByDateEnd, approxPointsCount, timezone.Hours, token);
|
||||
var recordAllFloat = await GetItemsOrDefaultAsync(queryWitsFloat, dateEnd, filterByDateEnd, approxPointsCount,timezone.Hours, token);
|
||||
var recordAllString = await GetItemsOrDefaultAsync(queryWitsString, dateEnd, filterByDateEnd, approxPointsCount, timezone.Hours, token);
|
||||
var recordAllInt = await GetItemsOrDefaultAsync(queryWitsInt, dateBeginUtc, dateEnd, filterByDateEnd, approxPointsCount, timezone.Hours, token);
|
||||
var recordAllFloat = await GetItemsOrDefaultAsync(queryWitsFloat, dateBeginUtc, dateEnd, filterByDateEnd, approxPointsCount,timezone.Hours, token);
|
||||
var recordAllString = await GetItemsOrDefaultAsync(queryWitsString, dateBeginUtc, dateEnd, filterByDateEnd, approxPointsCount, timezone.Hours, token);
|
||||
var groupRecordDate = (recordAllFloat.Union(recordAllInt)).Union(recordAllString)
|
||||
.GroupBy(g => new
|
||||
{
|
||||
@ -114,27 +111,29 @@ namespace AsbCloudInfrastructure.Repository
|
||||
}
|
||||
|
||||
private static async Task<IEnumerable<ItemRecord>> GetItemsOrDefaultAsync<T>(IQueryable<WitsItemBase<T>> query,
|
||||
DateTimeOffset dateBeginUtc,
|
||||
DateTimeOffset dateEnd, bool filterByDateEnd, int approxPointsCount, double timezoneHours
|
||||
, CancellationToken token)
|
||||
where T: notnull
|
||||
{
|
||||
if (filterByDateEnd)
|
||||
query = query.Where(d => d.DateTime <= dateEnd);
|
||||
//if (filterByDateEnd)
|
||||
// query = query.Where(d => d.DateTime <= dateEnd);
|
||||
|
||||
var fullDataCount = await query.CountAsync(token)
|
||||
.ConfigureAwait(false);
|
||||
//var fullDataCount = await query.CountAsync(token)
|
||||
// .ConfigureAwait(false);
|
||||
|
||||
if (fullDataCount == 0)
|
||||
return Enumerable.Empty<ItemRecord>();
|
||||
//if (fullDataCount == 0)
|
||||
// return Enumerable.Empty<ItemRecord>();
|
||||
|
||||
if (fullDataCount > 1.75 * approxPointsCount)
|
||||
{
|
||||
var m = (int)Math.Round(1d * fullDataCount / approxPointsCount);
|
||||
if (m > 1)
|
||||
query = query.Where((d) => (((d.DateTime.DayOfYear * 24 + d.DateTime.Hour) * 60 + d.DateTime.Minute) * 60 + d.DateTime.Second) % m == 0);
|
||||
}
|
||||
//if (fullDataCount > 1.75 * approxPointsCount)
|
||||
//{
|
||||
// var m = (int)Math.Round(1d * fullDataCount / approxPointsCount);
|
||||
// if (m > 1)
|
||||
// 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
|
||||
.Where(d => d.DateTime >= dateBeginUtc)
|
||||
.OrderBy(d => d.DateTime)
|
||||
.AsNoTracking()
|
||||
.ToListAsync(token)
|
||||
|
@ -10,12 +10,12 @@ using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AsbCloudWebApi.Controllers.GTR
|
||||
namespace AsbCloudWebApi.Controllers.SAUB
|
||||
{
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class GtrWitsController : ControllerBase
|
||||
|
||||
|
||||
{
|
||||
protected readonly IWellService wellService;
|
||||
private readonly ITelemetryService telemetryService;
|
||||
@ -37,7 +37,7 @@ namespace AsbCloudWebApi.Controllers.GTR
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// Получить загруженные данные ГТИ по скважине
|
||||
/// </summary>
|
||||
/// <param name = "idWell" > id скважины</param>
|
||||
/// <param name = "begin" > дата начала выборки.По умолчанию: текущее время - intervalSec</param>
|
||||
@ -46,20 +46,20 @@ namespace AsbCloudWebApi.Controllers.GTR
|
||||
/// <param name = "token" > Токен завершения задачи</param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("{idWell}")]
|
||||
[Permission]
|
||||
// [Permission]
|
||||
public async Task<ActionResult<IEnumerable<WitsRecordDto>>> GetDataAsync(int idWell, DateTime begin = default,
|
||||
int intervalSec = 600, int approxPointsCount = 1024, CancellationToken token = default)
|
||||
{
|
||||
int? idCompany = User.GetCompanyId();
|
||||
//int? idCompany = User.GetCompanyId();
|
||||
|
||||
if (idCompany is null)
|
||||
return Forbid();
|
||||
//if (idCompany is null)
|
||||
// return Forbid();
|
||||
|
||||
bool isCompanyOwnsWell = await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
||||
idWell, token).ConfigureAwait(false);
|
||||
//bool isCompanyOwnsWell = await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
||||
// idWell, token).ConfigureAwait(false);
|
||||
|
||||
if (!isCompanyOwnsWell)
|
||||
return Forbid();
|
||||
//if (!isCompanyOwnsWell)
|
||||
// return Forbid();
|
||||
|
||||
var content = await gtrRepository.GetAsync(idWell, begin,
|
||||
intervalSec, approxPointsCount, token).ConfigureAwait(false);
|
||||
@ -67,17 +67,25 @@ namespace AsbCloudWebApi.Controllers.GTR
|
||||
return Ok(content);
|
||||
}
|
||||
|
||||
[HttpPost("{uid}")]
|
||||
/// <summary>
|
||||
/// Метод для получения WITS записи от панели оператора.
|
||||
/// Сохраняет в БД.
|
||||
/// </summary>
|
||||
/// <param name="uid">уникальный идентификатор телеметрии</param>
|
||||
/// <param name="dto">WITS запись</param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("{uid}")]
|
||||
public async Task<IActionResult> PostDataAsync(
|
||||
string uid,
|
||||
[FromBody] WitsRecordDto dto,
|
||||
[FromBody] WitsRecordDto dto,
|
||||
CancellationToken token = default)
|
||||
{
|
||||
var idTelemetry = telemetryService.GetOrCreateTelemetryIdByUid(uid);
|
||||
await gtrRepository.SaveDataAsync(idTelemetry, dto, token).ConfigureAwait(false);
|
||||
var idWell = telemetryService.GetIdWellByTelemetryUid(uid);
|
||||
if (idWell is not null && dto is not null)
|
||||
_ = Task.Run(() => telemetryHubContext.Clients.Group($"well_{idWell}_wits")
|
||||
_ = Task.Run(() => telemetryHubContext.Clients.Group($"well_{idWell}_gtr")
|
||||
.SendAsync(SirnalRMethodGetDataName, dto), CancellationToken.None);
|
||||
return Ok();
|
||||
}
|
Loading…
Reference in New Issue
Block a user