forked from ddrilling/AsbCloudServer
Merge branch 'dev' into feature/refactoring_process_map
This commit is contained in:
commit
b36b1bdd3c
@ -7,14 +7,13 @@ using System.Linq;
|
|||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using AsbCloudInfrastructure.Background;
|
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
||||||
namespace AsbCloudInfrastructure.Services;
|
namespace AsbCloudInfrastructure.Background;
|
||||||
|
|
||||||
public class WorkLimitingParameterCalc : Work
|
public class WorkLimitingParameterCalc : Work
|
||||||
{
|
{
|
||||||
public WorkLimitingParameterCalc()
|
public WorkLimitingParameterCalc()
|
||||||
: base("Limiting parameter calc")
|
: base("Limiting parameter calc")
|
||||||
{
|
{
|
||||||
Timeout = TimeSpan.FromMinutes(30);
|
Timeout = TimeSpan.FromMinutes(30);
|
||||||
@ -51,7 +50,7 @@ public class WorkLimitingParameterCalc : Work
|
|||||||
var i = 0d;
|
var i = 0d;
|
||||||
foreach (var item in telemetryLastDetectedDates)
|
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);
|
var newLimitingParameters = await GetLimitingParameterAsync(item.IdTelemetry, item.LastDate ?? DateTimeOffset.MinValue, db, token);
|
||||||
if (newLimitingParameters?.Any() == true)
|
if (newLimitingParameters?.Any() == true)
|
||||||
{
|
{
|
||||||
@ -63,7 +62,7 @@ public class WorkLimitingParameterCalc : Work
|
|||||||
|
|
||||||
private static async Task<IEnumerable<LimitingParameter>> GetLimitingParameterAsync(int idTelemetry, DateTimeOffset begin, IAsbCloudDbContext db, CancellationToken token)
|
private static async Task<IEnumerable<LimitingParameter>> GetLimitingParameterAsync(int idTelemetry, DateTimeOffset begin, IAsbCloudDbContext db, CancellationToken token)
|
||||||
{
|
{
|
||||||
var query =
|
var query =
|
||||||
$"select " +
|
$"select " +
|
||||||
$"limiting_parameters.date, limiting_parameters.id_feed_regulator, limiting_parameters.well_depth " +
|
$"limiting_parameters.date, limiting_parameters.id_feed_regulator, limiting_parameters.well_depth " +
|
||||||
$"from ( " +
|
$"from ( " +
|
||||||
@ -72,9 +71,9 @@ public class WorkLimitingParameterCalc : Work
|
|||||||
$"lag(id_feed_regulator, 1) over (order by date) as id_feed_regulator_lag, " +
|
$"lag(id_feed_regulator, 1) over (order by date) as id_feed_regulator_lag, " +
|
||||||
$"lead(id_feed_regulator, 1) over (order by date) as id_feed_regulator_lead " +
|
$"lead(id_feed_regulator, 1) over (order by date) as id_feed_regulator_lead " +
|
||||||
$"from t_telemetry_data_saub " +
|
$"from t_telemetry_data_saub " +
|
||||||
$"where id_feed_regulator is not null " +
|
$"where id_feed_regulator is not null " +
|
||||||
$"and id_telemetry = {idTelemetry}" +
|
$"and id_telemetry = {idTelemetry} " +
|
||||||
$"and date >= '{begin:u}'" +
|
$"and date >= '{begin:u}' " +
|
||||||
$"order by date) as limiting_parameters " +
|
$"order by date) as limiting_parameters " +
|
||||||
$"where id_feed_regulator_lag is null " +
|
$"where id_feed_regulator_lag is null " +
|
||||||
$"or (id_feed_regulator != id_feed_regulator_lag and id_feed_regulator_lead != id_feed_regulator_lag) " +
|
$"or (id_feed_regulator != id_feed_regulator_lag and id_feed_regulator_lead != id_feed_regulator_lag) " +
|
||||||
@ -102,14 +101,15 @@ public class WorkLimitingParameterCalc : Work
|
|||||||
|
|
||||||
if (limitingLast.IdFeedRegulator != idLimiting || limitingLast.DepthStart < wellDepth)
|
if (limitingLast.IdFeedRegulator != idLimiting || limitingLast.DepthStart < wellDepth)
|
||||||
{
|
{
|
||||||
limitingParameters.Add(new LimitingParameter {
|
limitingParameters.Add(new LimitingParameter
|
||||||
|
{
|
||||||
IdTelemetry = idTelemetry,
|
IdTelemetry = idTelemetry,
|
||||||
IdFeedRegulator = limitingLast.IdFeedRegulator,
|
IdFeedRegulator = limitingLast.IdFeedRegulator,
|
||||||
DateStart = limitingLast.DateStart,
|
DateStart = limitingLast.DateStart,
|
||||||
DateEnd = date,
|
DateEnd = date,
|
||||||
DepthStart = limitingLast.DepthStart,
|
DepthStart = limitingLast.DepthStart,
|
||||||
DepthEnd = wellDepth
|
DepthEnd = wellDepth
|
||||||
});
|
});
|
||||||
|
|
||||||
limitingLast = new LimitingParameter
|
limitingLast = new LimitingParameter
|
||||||
{
|
{
|
@ -27,7 +27,7 @@ public class WellInfoService
|
|||||||
public WorkWellInfoUpdate()
|
public WorkWellInfoUpdate()
|
||||||
: base("Well statistics update")
|
: 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)
|
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 messageHub = services.GetRequiredService<IIntegrationEventHandler<UpdateWellInfoEvent>>();
|
||||||
|
|
||||||
var wells = await wellService.GetAllAsync(token);
|
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 wellDrillingProcessMapRequests = wellsIds.Select(id => new WellDrillingProcessMapRequest { IdWell = id });
|
||||||
var wellDrillingProcessMaps = await wellDrillingProcessMapRepository.GetAsync(wellDrillingProcessMapRequests, token);
|
var wellDrillingProcessMaps = await wellDrillingProcessMapRepository.GetAsync(wellDrillingProcessMapRequests, token);
|
||||||
@ -58,9 +59,11 @@ public class WellInfoService
|
|||||||
|
|
||||||
var subsystemStat = await subsystemOperationTimeService
|
var subsystemStat = await subsystemOperationTimeService
|
||||||
.GetStatByActiveWells(wellsIds, token);
|
.GetStatByActiveWells(wellsIds, token);
|
||||||
var count = wells.Count();
|
subsystemStat = subsystemStat.ToArray();
|
||||||
|
|
||||||
|
var count = activeWells.Count();
|
||||||
var i = 0d;
|
var i = 0d;
|
||||||
WellMapInfo = wells.Select(well => {
|
WellMapInfo = activeWells.Select(well => {
|
||||||
var wellMapInfo = well.Adapt<WellMapInfoWithComanies>();
|
var wellMapInfo = well.Adapt<WellMapInfoWithComanies>();
|
||||||
wellMapInfo.IdState = well.IdState;
|
wellMapInfo.IdState = well.IdState;
|
||||||
onProgressCallback($"Start updating info by well({well.Id}): {well.Caption}", i++ / count);
|
onProgressCallback($"Start updating info by well({well.Id}): {well.Caption}", i++ / count);
|
||||||
|
@ -9,17 +9,16 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
[Route("api/[controller]")]
|
[Route("api/[controller]")]
|
||||||
[Authorize]
|
[Authorize]
|
||||||
[ApiController]
|
[ApiController]
|
||||||
public class BackgroundWork : ControllerBase
|
public class BackgroundWorkController : ControllerBase
|
||||||
{
|
{
|
||||||
private readonly BackgroundWorker backgroundWorker;
|
private readonly BackgroundWorker backgroundWorker;
|
||||||
|
|
||||||
public BackgroundWork(BackgroundWorker backgroundWorker)
|
public BackgroundWorkController(BackgroundWorker backgroundWorker)
|
||||||
{
|
{
|
||||||
this.backgroundWorker = backgroundWorker;
|
this.backgroundWorker = backgroundWorker;
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
//[ProducesResponseType(typeof(IEnumerable<DepositDto>), (int)System.Net.HttpStatusCode.OK)]
|
|
||||||
public IActionResult GetAll()
|
public IActionResult GetAll()
|
||||||
{
|
{
|
||||||
var result = new {
|
var result = new {
|
||||||
@ -30,5 +29,19 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
};
|
};
|
||||||
return Ok(result);
|
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;
|
||||||
using AsbCloudApp.Data.Subsystems;
|
using AsbCloudApp.Data.Subsystems;
|
||||||
using AsbCloudApp.Exceptions;
|
|
||||||
using AsbCloudApp.Requests;
|
using AsbCloudApp.Requests;
|
||||||
using AsbCloudApp.Services;
|
using AsbCloudApp.Services;
|
||||||
using AsbCloudApp.Services.Subsystems;
|
using AsbCloudApp.Services.Subsystems;
|
||||||
using AsbCloudDb.Model;
|
using AsbCloudDb.Model;
|
||||||
using AsbCloudInfrastructure;
|
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using System;
|
using System;
|
||||||
@ -56,7 +54,6 @@ namespace AsbCloudWebApi.Controllers.Subsystems
|
|||||||
{
|
{
|
||||||
if (!await UserHasAccesToWellAsync(request.IdWell, token))
|
if (!await UserHasAccesToWellAsync(request.IdWell, token))
|
||||||
return Forbid();
|
return Forbid();
|
||||||
await CustomValidate(request, token);
|
|
||||||
var subsystemResult = await subsystemOperationTimeService.GetStatAsync(request, token);
|
var subsystemResult = await subsystemOperationTimeService.GetStatAsync(request, token);
|
||||||
return Ok(subsystemResult);
|
return Ok(subsystemResult);
|
||||||
}
|
}
|
||||||
@ -133,7 +130,6 @@ namespace AsbCloudWebApi.Controllers.Subsystems
|
|||||||
{
|
{
|
||||||
if (!await UserHasAccesToWellAsync(request.IdWell, token))
|
if (!await UserHasAccesToWellAsync(request.IdWell, token))
|
||||||
return Forbid();
|
return Forbid();
|
||||||
await CustomValidate(request, token);
|
|
||||||
|
|
||||||
var result = await subsystemOperationTimeService.GetOperationTimeAsync(request, token);
|
var result = await subsystemOperationTimeService.GetOperationTimeAsync(request, token);
|
||||||
return Ok(result);
|
return Ok(result);
|
||||||
@ -155,7 +151,6 @@ namespace AsbCloudWebApi.Controllers.Subsystems
|
|||||||
{
|
{
|
||||||
if (!await UserHasAccesToWellAsync(request.IdWell, token))
|
if (!await UserHasAccesToWellAsync(request.IdWell, token))
|
||||||
return Forbid();
|
return Forbid();
|
||||||
await CustomValidate(request, token);
|
|
||||||
var result = await subsystemOperationTimeService.DeleteAsync(request, token);
|
var result = await subsystemOperationTimeService.DeleteAsync(request, token);
|
||||||
return Ok(result);
|
return Ok(result);
|
||||||
}
|
}
|
||||||
@ -180,24 +175,5 @@ namespace AsbCloudWebApi.Controllers.Subsystems
|
|||||||
return true;
|
return true;
|
||||||
return false;
|
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