forked from ddrilling/AsbCloudServer
Merge branch 'dev' into feature/refactoring_process_map
This commit is contained in:
commit
b36b1bdd3c
@ -7,10 +7,9 @@ using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Generic;
|
||||
using AsbCloudInfrastructure.Background;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace AsbCloudInfrastructure.Services;
|
||||
namespace AsbCloudInfrastructure.Background;
|
||||
|
||||
public class WorkLimitingParameterCalc : Work
|
||||
{
|
||||
@ -51,7 +50,7 @@ public class WorkLimitingParameterCalc : Work
|
||||
var i = 0d;
|
||||
foreach (var item in telemetryLastDetectedDates)
|
||||
{
|
||||
onProgressCallback($"Start hanling telemetry: {item.IdTelemetry} from {item.LastDate}", i++/count);
|
||||
onProgressCallback($"Start hanling telemetry: {item.IdTelemetry} from {item.LastDate}", i++ / count);
|
||||
var newLimitingParameters = await GetLimitingParameterAsync(item.IdTelemetry, item.LastDate ?? DateTimeOffset.MinValue, db, token);
|
||||
if (newLimitingParameters?.Any() == true)
|
||||
{
|
||||
@ -73,8 +72,8 @@ public class WorkLimitingParameterCalc : Work
|
||||
$"lead(id_feed_regulator, 1) over (order by date) as id_feed_regulator_lead " +
|
||||
$"from t_telemetry_data_saub " +
|
||||
$"where id_feed_regulator is not null " +
|
||||
$"and id_telemetry = {idTelemetry}" +
|
||||
$"and date >= '{begin:u}'" +
|
||||
$"and id_telemetry = {idTelemetry} " +
|
||||
$"and date >= '{begin:u}' " +
|
||||
$"order by date) as limiting_parameters " +
|
||||
$"where id_feed_regulator_lag is null " +
|
||||
$"or (id_feed_regulator != id_feed_regulator_lag and id_feed_regulator_lead != id_feed_regulator_lag) " +
|
||||
@ -102,7 +101,8 @@ public class WorkLimitingParameterCalc : Work
|
||||
|
||||
if (limitingLast.IdFeedRegulator != idLimiting || limitingLast.DepthStart < wellDepth)
|
||||
{
|
||||
limitingParameters.Add(new LimitingParameter {
|
||||
limitingParameters.Add(new LimitingParameter
|
||||
{
|
||||
IdTelemetry = idTelemetry,
|
||||
IdFeedRegulator = limitingLast.IdFeedRegulator,
|
||||
DateStart = limitingLast.DateStart,
|
@ -27,7 +27,7 @@ public class WellInfoService
|
||||
public WorkWellInfoUpdate()
|
||||
: base("Well statistics update")
|
||||
{
|
||||
Timeout = TimeSpan.FromMinutes(20);
|
||||
Timeout = TimeSpan.FromMinutes(30);
|
||||
}
|
||||
|
||||
protected override async Task Action(string id, IServiceProvider services, Action<string, double?> onProgressCallback, CancellationToken token)
|
||||
@ -40,8 +40,9 @@ public class WellInfoService
|
||||
var messageHub = services.GetRequiredService<IIntegrationEventHandler<UpdateWellInfoEvent>>();
|
||||
|
||||
var wells = await wellService.GetAllAsync(token);
|
||||
var activeWells = wells.Where(well => well.IdState == 1);
|
||||
|
||||
var wellsIds = wells.Select(w => w.Id);
|
||||
var wellsIds = activeWells.Select(w => w.Id);
|
||||
|
||||
var wellDrillingProcessMapRequests = wellsIds.Select(id => new WellDrillingProcessMapRequest { IdWell = id });
|
||||
var wellDrillingProcessMaps = await wellDrillingProcessMapRepository.GetAsync(wellDrillingProcessMapRequests, token);
|
||||
@ -58,9 +59,11 @@ public class WellInfoService
|
||||
|
||||
var subsystemStat = await subsystemOperationTimeService
|
||||
.GetStatByActiveWells(wellsIds, token);
|
||||
var count = wells.Count();
|
||||
subsystemStat = subsystemStat.ToArray();
|
||||
|
||||
var count = activeWells.Count();
|
||||
var i = 0d;
|
||||
WellMapInfo = wells.Select(well => {
|
||||
WellMapInfo = activeWells.Select(well => {
|
||||
var wellMapInfo = well.Adapt<WellMapInfoWithComanies>();
|
||||
wellMapInfo.IdState = well.IdState;
|
||||
onProgressCallback($"Start updating info by well({well.Id}): {well.Caption}", i++ / count);
|
||||
|
@ -9,17 +9,16 @@ namespace AsbCloudWebApi.Controllers
|
||||
[Route("api/[controller]")]
|
||||
[Authorize]
|
||||
[ApiController]
|
||||
public class BackgroundWork : ControllerBase
|
||||
public class BackgroundWorkController : ControllerBase
|
||||
{
|
||||
private readonly BackgroundWorker backgroundWorker;
|
||||
|
||||
public BackgroundWork(BackgroundWorker backgroundWorker)
|
||||
public BackgroundWorkController(BackgroundWorker backgroundWorker)
|
||||
{
|
||||
this.backgroundWorker = backgroundWorker;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
//[ProducesResponseType(typeof(IEnumerable<DepositDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||
public IActionResult GetAll()
|
||||
{
|
||||
var result = new {
|
||||
@ -30,5 +29,19 @@ namespace AsbCloudWebApi.Controllers
|
||||
};
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
[HttpGet("Current")]
|
||||
public IActionResult GetCurrent()
|
||||
{
|
||||
var result = (BackgroundWorkDto?)backgroundWorker.CurrentWork;
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
[HttpGet("Failed")]
|
||||
public IActionResult GetFelled()
|
||||
{
|
||||
var result = backgroundWorker.WorkStore.Felled.Select(work => (BackgroundWorkDto)work);
|
||||
return Ok(result);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,11 +1,9 @@
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Data.Subsystems;
|
||||
using AsbCloudApp.Exceptions;
|
||||
using AsbCloudApp.Requests;
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudApp.Services.Subsystems;
|
||||
using AsbCloudDb.Model;
|
||||
using AsbCloudInfrastructure;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
@ -56,7 +54,6 @@ namespace AsbCloudWebApi.Controllers.Subsystems
|
||||
{
|
||||
if (!await UserHasAccesToWellAsync(request.IdWell, token))
|
||||
return Forbid();
|
||||
await CustomValidate(request, token);
|
||||
var subsystemResult = await subsystemOperationTimeService.GetStatAsync(request, token);
|
||||
return Ok(subsystemResult);
|
||||
}
|
||||
@ -133,7 +130,6 @@ namespace AsbCloudWebApi.Controllers.Subsystems
|
||||
{
|
||||
if (!await UserHasAccesToWellAsync(request.IdWell, token))
|
||||
return Forbid();
|
||||
await CustomValidate(request, token);
|
||||
|
||||
var result = await subsystemOperationTimeService.GetOperationTimeAsync(request, token);
|
||||
return Ok(result);
|
||||
@ -155,7 +151,6 @@ namespace AsbCloudWebApi.Controllers.Subsystems
|
||||
{
|
||||
if (!await UserHasAccesToWellAsync(request.IdWell, token))
|
||||
return Forbid();
|
||||
await CustomValidate(request, token);
|
||||
var result = await subsystemOperationTimeService.DeleteAsync(request, token);
|
||||
return Ok(result);
|
||||
}
|
||||
@ -180,24 +175,5 @@ namespace AsbCloudWebApi.Controllers.Subsystems
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Валидирует запрос и бросает исключение ArgumentInvalidException
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="ArgumentException"></exception>
|
||||
private async Task CustomValidate(SubsystemOperationTimeRequest request, CancellationToken token)
|
||||
{
|
||||
var well = await wellService.GetOrDefaultAsync(request.IdWell, token);
|
||||
if (well is not null && request.LtDate.HasValue)
|
||||
{
|
||||
var ltDate = request.LtDate.Value;
|
||||
var utcDateRequest = ltDate.ToUtcDateTimeOffset(well.Timezone.Hours);
|
||||
if (utcDateRequest.AddHours(2) > DateTime.UtcNow)
|
||||
throw new ArgumentInvalidException(nameof(request.LtDate), "Запрашиваемый диапазон должен заканчиваться за 2 часа до текущего времени");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user