forked from ddrilling/AsbCloudServer
Merge branch 'dev' into feature/refactoring-daily-report-form
This commit is contained in:
commit
ee8f000ab1
@ -22,10 +22,6 @@ namespace AsbCloudApp.Data
|
|||||||
[Range(1, int.MaxValue, ErrorMessage = "Id категории не может быть ниже 1")]
|
[Range(1, int.MaxValue, ErrorMessage = "Id категории не может быть ниже 1")]
|
||||||
public int CategoryId { get; set; }
|
public int CategoryId { get; set; }
|
||||||
|
|
||||||
//TODO: в модели дто сообщения отсутствует поле Id скважины
|
|
||||||
// скорее всего опечатка т.к. используется глубина в правиле валидатора
|
|
||||||
//в других валидаторах парамтр глубины идет рэнжированный от...до
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// глубина забоя, при котором событие возникло
|
/// глубина забоя, при котором событие возникло
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -10,7 +10,6 @@ namespace AsbCloudApp.Services
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IScheduleRepository : IRepositoryWellRelated<ScheduleDto>
|
public interface IScheduleRepository : IRepositoryWellRelated<ScheduleDto>
|
||||||
{
|
{
|
||||||
// TODO: this should be nullable.
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// получить бурильщика по idWell и времени
|
/// получить бурильщика по idWell и времени
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -18,6 +17,6 @@ namespace AsbCloudApp.Services
|
|||||||
/// <param name="workTime"></param>
|
/// <param name="workTime"></param>
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<DrillerDto?> GetDrillerAsync(int idWell, DateTime workTime, CancellationToken token);
|
Task<DrillerDto?> GetOrDefaultDrillerAsync(int idWell, DateTime workTime, CancellationToken token);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ namespace AsbCloudApp.Services
|
|||||||
/// <param name="approxPointsCount">кол-во элементов до которых эти данные прореживаются</param>
|
/// <param name="approxPointsCount">кол-во элементов до которых эти данные прореживаются</param>
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<IEnumerable<TDto>?> GetOrDefaultAsync(int idWell,
|
Task<IEnumerable<TDto>> GetAsync(int idWell,
|
||||||
DateTime dateBegin = default, double intervalSec = 600d,
|
DateTime dateBegin = default, double intervalSec = 600d,
|
||||||
int approxPointsCount = 1024, CancellationToken token = default);
|
int approxPointsCount = 1024, CancellationToken token = default);
|
||||||
|
|
||||||
|
80
AsbCloudApp/ValidationAttributes/DateValidationAttribute.cs
Normal file
80
AsbCloudApp/ValidationAttributes/DateValidationAttribute.cs
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
using System;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace AsbCloudApp.ValidationAttributes
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Атрибут валидации даты-времени
|
||||||
|
/// </summary>
|
||||||
|
[AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Property)]
|
||||||
|
public class DateValidationAttribute : ValidationAttribute
|
||||||
|
{
|
||||||
|
private DateTime? gtDate;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// null разрешен
|
||||||
|
/// </summary>
|
||||||
|
public bool AllowNull { get; set; } = true;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Разрешена только дат.
|
||||||
|
/// При наличии времени в DateTime инвалидирует.
|
||||||
|
/// При наличии UTC тоже инвалидирует.
|
||||||
|
/// </summary>
|
||||||
|
public bool IsDateOnly { get; set; } = false;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Допустима дата-время в UTC
|
||||||
|
/// </summary>
|
||||||
|
public bool AllowUtc { get; set; } = true;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Дата больше которой должно быть проверяемое значение.
|
||||||
|
/// Формат строки - любой поддерживаемый DateTime.Parse.
|
||||||
|
/// Желательно использовать ISO 8601 формат
|
||||||
|
/// </summary>
|
||||||
|
public string? GtDate {
|
||||||
|
get => gtDate.ToString();
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if(value is null)
|
||||||
|
gtDate = null;
|
||||||
|
else
|
||||||
|
gtDate = DateTime.Parse(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Проверка значения
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="value"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override bool IsValid(object? value)
|
||||||
|
{
|
||||||
|
if (value is null)
|
||||||
|
return AllowNull;
|
||||||
|
|
||||||
|
if (value is not DateTime dateTime)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (IsDateOnly)
|
||||||
|
{
|
||||||
|
if (dateTime.Hour > 0 ||
|
||||||
|
dateTime.Minute > 0 ||
|
||||||
|
dateTime.Second > 0 ||
|
||||||
|
dateTime.Millisecond > 0 ||
|
||||||
|
dateTime.Kind == DateTimeKind.Utc)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!AllowUtc && dateTime.Kind == DateTimeKind.Utc)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (gtDate.HasValue && dateTime <= gtDate)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -21,7 +21,7 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
this.wellService = wellService;
|
this.wellService = wellService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<DrillerDto?> GetDrillerAsync(int idWell, DateTime workTime, CancellationToken token)
|
public async Task<DrillerDto?> GetOrDefaultDrillerAsync(int idWell, DateTime workTime, CancellationToken token)
|
||||||
{
|
{
|
||||||
var hoursOffset = wellService.GetTimezone(idWell).Hours;
|
var hoursOffset = wellService.GetTimezone(idWell).Hours;
|
||||||
var date = workTime.ToUtcDateTimeOffset(hoursOffset);
|
var date = workTime.ToUtcDateTimeOffset(hoursOffset);
|
||||||
|
@ -86,16 +86,14 @@ namespace AsbCloudInfrastructure.Services.SAUB
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// TODO: It shouldn`t be nullable. Throw exceptions instead and return empty.
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public virtual async Task<IEnumerable<TDto>?> GetOrDefaultAsync(int idWell,
|
public virtual async Task<IEnumerable<TDto>> GetAsync(int idWell,
|
||||||
DateTime dateBegin = default, double intervalSec = 600d,
|
DateTime dateBegin = default, double intervalSec = 600d,
|
||||||
int approxPointsCount = 1024, CancellationToken token = default)
|
int approxPointsCount = 1024, CancellationToken token = default)
|
||||||
{
|
{
|
||||||
var telemetry = telemetryService.GetOrDefaultTelemetryByIdWell(idWell);
|
var telemetry = telemetryService.GetOrDefaultTelemetryByIdWell(idWell);
|
||||||
if (telemetry is null)
|
if (telemetry is null)
|
||||||
return null;
|
return Enumerable.Empty<TDto>();
|
||||||
|
|
||||||
var timezone = telemetryService.GetTimezone(telemetry.Id);
|
var timezone = telemetryService.GetTimezone(telemetry.Id);
|
||||||
|
|
||||||
@ -134,7 +132,7 @@ namespace AsbCloudInfrastructure.Services.SAUB
|
|||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
|
|
||||||
if (fullDataCount == 0)
|
if (fullDataCount == 0)
|
||||||
return default;
|
return Enumerable.Empty<TDto>();
|
||||||
|
|
||||||
if (fullDataCount > 1.75 * approxPointsCount)
|
if (fullDataCount > 1.75 * approxPointsCount)
|
||||||
{
|
{
|
||||||
|
@ -121,8 +121,7 @@ namespace AsbCloudInfrastructure.Services.SAUB
|
|||||||
_ => 32_768
|
_ => 32_768
|
||||||
};
|
};
|
||||||
|
|
||||||
var data = await GetOrDefaultAsync(idWell, beginDate, intervalSec, approxPointsCount, token )
|
var data = await GetAsync(idWell, beginDate, intervalSec, approxPointsCount, token );
|
||||||
?? Enumerable.Empty<TelemetryDataSaubDto>();
|
|
||||||
|
|
||||||
var fileName = $"DataSaub idWell{idWell}";
|
var fileName = $"DataSaub idWell{idWell}";
|
||||||
if (telemetry.Info is not null)
|
if (telemetry.Info is not null)
|
||||||
|
@ -0,0 +1,108 @@
|
|||||||
|
using AsbCloudApp.ValidationAttributes;
|
||||||
|
using System;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace AsbCloudWebApi.Tests.AttributeTest
|
||||||
|
{
|
||||||
|
public class DateValidationAttributeTest
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void AllowNull_true_on_null_valid()
|
||||||
|
{
|
||||||
|
var attribute = new DateValidationAttribute { AllowNull = true };
|
||||||
|
var result = attribute.IsValid(null);
|
||||||
|
Assert.True(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void AllowNull_false_on_null_invalid()
|
||||||
|
{
|
||||||
|
var attribute = new DateValidationAttribute { AllowNull = false };
|
||||||
|
var result = attribute.IsValid(null);
|
||||||
|
Assert.False(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void IsDateOnly_true_on_empty_timePart_valid()
|
||||||
|
{
|
||||||
|
var attribute = new DateValidationAttribute { IsDateOnly = true };
|
||||||
|
var date = new DateTime(2023, 01, 01, 00, 00, 00);
|
||||||
|
var result = attribute.IsValid(date);
|
||||||
|
Assert.True(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void IsDateOnly_true_on_timePart_invalid()
|
||||||
|
{
|
||||||
|
var attribute = new DateValidationAttribute { IsDateOnly = true };
|
||||||
|
var date = new DateTime(2023, 01, 01, 01, 01, 01);
|
||||||
|
var result = attribute.IsValid(date);
|
||||||
|
Assert.False(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void IsDateOnly_true_on_utc_invalid()
|
||||||
|
{
|
||||||
|
var attribute = new DateValidationAttribute { IsDateOnly = true };
|
||||||
|
var date = new DateTime(2023, 01, 01, 00, 00, 00, DateTimeKind.Utc);
|
||||||
|
var result = attribute.IsValid(date);
|
||||||
|
Assert.False(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void AllowUtc_true_on_unspecified_valid()
|
||||||
|
{
|
||||||
|
var attribute = new DateValidationAttribute { AllowUtc = true };
|
||||||
|
var date = new DateTime(2023, 01, 01, 00, 00, 00, DateTimeKind.Unspecified);
|
||||||
|
var result = attribute.IsValid(date);
|
||||||
|
Assert.True(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void AllowUtc_true_on_utc_valid()
|
||||||
|
{
|
||||||
|
var attribute = new DateValidationAttribute { AllowUtc = true };
|
||||||
|
var date = new DateTime(2023, 01, 01, 00, 00, 00, DateTimeKind.Utc);
|
||||||
|
var result = attribute.IsValid(date);
|
||||||
|
Assert.True(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void AllowUtc_false_on_utc_invalid()
|
||||||
|
{
|
||||||
|
var attribute = new DateValidationAttribute { AllowUtc = false };
|
||||||
|
var date = new DateTime(2023, 01, 01, 00, 00, 00, DateTimeKind.Utc);
|
||||||
|
var result = attribute.IsValid(date);
|
||||||
|
Assert.False(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void AllowUtc_false_on_unspecified_valid()
|
||||||
|
{
|
||||||
|
var attribute = new DateValidationAttribute { AllowUtc = false };
|
||||||
|
var date = new DateTime(2023, 01, 01, 00, 00, 00, DateTimeKind.Unspecified);
|
||||||
|
var result = attribute.IsValid(date);
|
||||||
|
Assert.True(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void GtDate_on_same_date_invalid()
|
||||||
|
{
|
||||||
|
var gtDate = "2023-01-01T00:00:00";
|
||||||
|
var date = DateTime.Parse(gtDate);
|
||||||
|
var attribute = new DateValidationAttribute { GtDate = gtDate };
|
||||||
|
var result = attribute.IsValid(date);
|
||||||
|
Assert.False(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void GtDate_on_greater_date_valid()
|
||||||
|
{
|
||||||
|
var gtDate = "2023-01-01T00:00:00";
|
||||||
|
var date = DateTime.Parse(gtDate).AddMilliseconds(1);
|
||||||
|
var attribute = new DateValidationAttribute { GtDate = gtDate };
|
||||||
|
var result = attribute.IsValid(date);
|
||||||
|
Assert.True(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -35,7 +35,7 @@ namespace AsbCloudWebApi.Tests.Middlware
|
|||||||
|
|
||||||
public class TelemetryDataSaubService : ITelemetryDataSaubService
|
public class TelemetryDataSaubService : ITelemetryDataSaubService
|
||||||
{
|
{
|
||||||
public async Task<IEnumerable<TelemetryDataSaubDto>?> GetOrDefaultAsync(int idWell, DateTime dateBegin = default, double intervalSec = 600, int approxPointsCount = 1024, CancellationToken token = default)
|
public async Task<IEnumerable<TelemetryDataSaubDto>?> GetAsync(int idWell, DateTime dateBegin = default, double intervalSec = 600, int approxPointsCount = 1024, CancellationToken token = default)
|
||||||
{
|
{
|
||||||
await Task.Delay(1000, token);
|
await Task.Delay(1000, token);
|
||||||
return Enumerable.Empty<TelemetryDataSaubDto>();
|
return Enumerable.Empty<TelemetryDataSaubDto>();
|
||||||
|
@ -77,22 +77,17 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Route("cluster/{idCluster}/stat")] // TODO: Это статистика кластера, перенести в ClusterOperationStatController
|
[Route("cluster/{idCluster}/stat")]
|
||||||
[Permission]
|
[Permission]
|
||||||
[ProducesResponseType(typeof(StatClusterDto), (int)System.Net.HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(StatClusterDto), (int)System.Net.HttpStatusCode.OK)]
|
||||||
public async Task<IActionResult> GetStatClusterAsync(int idCluster,
|
public async Task<IActionResult> GetStatClusterAsync(int idCluster,
|
||||||
CancellationToken token = default)
|
CancellationToken token = default)
|
||||||
{
|
{
|
||||||
int? idCompanyOrNull = User.GetCompanyId();
|
int? idCompany = User.GetCompanyId();
|
||||||
if (idCompanyOrNull is null)
|
if (idCompany is null)
|
||||||
return Forbid();
|
return Forbid();
|
||||||
|
|
||||||
int idCompany = idCompanyOrNull ?? 0;
|
var result = await operationsStatService.GetStatClusterAsync(idCluster, idCompany.Value, token)
|
||||||
// TODO: Fix next commented lines
|
|
||||||
//if (!await CanUserAccessToWellAsync(idCluster, token).ConfigureAwait(false))
|
|
||||||
// return Forbid();
|
|
||||||
|
|
||||||
var result = await operationsStatService.GetStatClusterAsync(idCluster, idCompany, token)
|
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
return Ok(result);
|
return Ok(result);
|
||||||
}
|
}
|
||||||
|
@ -86,7 +86,7 @@ namespace AsbCloudWebApi.Controllers.SAUB
|
|||||||
if (!isCompanyOwnsWell)
|
if (!isCompanyOwnsWell)
|
||||||
return Forbid();
|
return Forbid();
|
||||||
|
|
||||||
var content = await telemetryDataService.GetOrDefaultAsync(idWell, begin,
|
var content = await telemetryDataService.GetAsync(idWell, begin,
|
||||||
intervalSec, approxPointsCount, token).ConfigureAwait(false);
|
intervalSec, approxPointsCount, token).ConfigureAwait(false);
|
||||||
|
|
||||||
return Ok(content);
|
return Ok(content);
|
||||||
|
@ -8,6 +8,7 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace AsbCloudWebApi.Controllers
|
namespace AsbCloudWebApi.Controllers
|
||||||
{
|
{
|
||||||
|
#nullable enable
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Расписание бурильщиков
|
/// Расписание бурильщиков
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -32,12 +33,12 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns>бурильщик</returns>
|
/// <returns>бурильщик</returns>
|
||||||
[HttpGet("driller")]
|
[HttpGet("driller")]
|
||||||
public async Task<ActionResult<DrillerDto>> GetDrillerAsync(int idWell, DateTime workTime, CancellationToken token)
|
public async Task<ActionResult<DrillerDto?>> GetDrillerAsync(int idWell, DateTime workTime, CancellationToken token)
|
||||||
{
|
{
|
||||||
if (!await UserHasAccesToWellAsync(idWell, token))
|
if (!await UserHasAccesToWellAsync(idWell, token))
|
||||||
return Forbid();
|
return Forbid();
|
||||||
|
|
||||||
var result = await scheduleService.GetDrillerAsync(idWell, workTime, token);
|
var result = await scheduleService.GetOrDefaultDrillerAsync(idWell, workTime, token);
|
||||||
return Ok(result);
|
return Ok(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user