forked from ddrilling/AsbCloudServer
Merge branch 'dev' into fix/create-workers
This commit is contained in:
commit
1a3eac9060
@ -20,12 +20,12 @@ namespace AsbCloudApp.Requests
|
||||
/// Список id телеметрий
|
||||
/// пустой список - нет фильтрации
|
||||
/// </summary>
|
||||
public IEnumerable<int> IdsTelemetries { get; set; } = Enumerable.Empty<int>();
|
||||
public IEnumerable<int> IdsTelemetries { get; set; } = Array.Empty<int>();
|
||||
|
||||
/// <summary>
|
||||
/// категории операций
|
||||
/// </summary>
|
||||
public IEnumerable<int> IdsCategories { get; set; } = Enumerable.Empty<int>();
|
||||
public IEnumerable<int> IdsCategories { get; set; } = Array.Empty<int>();
|
||||
|
||||
/// <summary>
|
||||
/// Больше или равно дате
|
||||
@ -50,7 +50,7 @@ namespace AsbCloudApp.Requests
|
||||
/// <summary>
|
||||
/// Фильтр по пользователю панели
|
||||
/// </summary>
|
||||
public int? EqIdTelemetryUser { get; set; }
|
||||
public int? IdTelemetryUser { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -199,8 +199,8 @@ namespace AsbCloudInfrastructure.Services.DetectOperations
|
||||
if (request.LeDepth is not null)
|
||||
query = query.Where(o => o.DepthEnd <= request.LeDepth);
|
||||
|
||||
if (request.EqIdTelemetryUser is not null)
|
||||
query = query.Where(o => o.IdUsersAtStart == request.EqIdTelemetryUser);
|
||||
if (request.IdTelemetryUser is not null)
|
||||
query = query.Where(o => o.IdUsersAtStart == request.IdTelemetryUser);
|
||||
}
|
||||
|
||||
return query;
|
||||
|
Binary file not shown.
@ -10,7 +10,6 @@ using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using AsbCloudApp.Data.SAUB;
|
||||
using AsbCloudInfrastructure.Services.SAUB;
|
||||
using AsbCloudApp.Repositories;
|
||||
|
||||
namespace AsbCloudInfrastructure.Services.WellOperationService;
|
||||
@ -219,7 +218,7 @@ public class OperationsStatService : IOperationsStatService
|
||||
|
||||
var factEnd = lastCorrespondingFactOperation.DateStart.AddHours(lastCorrespondingFactOperation.DurationHours);
|
||||
var planEnd = lastCorrespondingPlanOperation.DateStart.AddHours(lastCorrespondingPlanOperation.DurationHours);
|
||||
var lagDays = (planEnd - factEnd).TotalDays;
|
||||
var lagDays = (factEnd - planEnd).TotalDays;
|
||||
|
||||
return lagDays;
|
||||
}
|
||||
|
47
AsbCloudWebApi.Tests/ReflectionExtensions.cs
Normal file
47
AsbCloudWebApi.Tests/ReflectionExtensions.cs
Normal file
@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AsbCloudWebApi.Tests
|
||||
{
|
||||
public static class ReflectionExtensions
|
||||
{
|
||||
private static readonly Dictionary<Type, object> _commonTypeDictionary = new()
|
||||
{
|
||||
{ typeof(int), default(int) },
|
||||
{ typeof(Guid), default(Guid) },
|
||||
{ typeof(DateOnly), default(DateOnly) },
|
||||
{ typeof(DateTime), default(DateTime) },
|
||||
{ typeof(DateTimeOffset), default(DateTimeOffset) },
|
||||
{ typeof(TimeOnly), default(TimeOnly) },
|
||||
{ typeof(long), default(long) },
|
||||
{ typeof(bool), default(bool) },
|
||||
{ typeof(double), default(double) },
|
||||
{ typeof(short), default(short) },
|
||||
{ typeof(float), default(float) },
|
||||
{ typeof(byte), default(byte) },
|
||||
{ typeof(char), default(char) },
|
||||
{ typeof(uint), default(uint) },
|
||||
{ typeof(ushort), default(ushort) },
|
||||
{ typeof(ulong), default(ulong) },
|
||||
{ typeof(sbyte), default(sbyte) }
|
||||
};
|
||||
|
||||
public static object? GetDefaultValue(this Type type)
|
||||
{
|
||||
if (!type.IsValueType)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return _commonTypeDictionary.TryGetValue(type, out var value)
|
||||
? value
|
||||
: Activator.CreateInstance(type);
|
||||
}
|
||||
|
||||
public static bool IsDefaultValue(this Type type, object? value)
|
||||
=> (value?.Equals(type.GetDefaultValue()) != false);
|
||||
}
|
||||
}
|
@ -8,11 +8,16 @@ using AsbCloudDb.Model;
|
||||
using AsbCloudInfrastructure.Services.WellOperationImport;
|
||||
using AsbCloudInfrastructure.Services.WellOperationImport.FileParser;
|
||||
using NSubstitute;
|
||||
using SignalRSwaggerGen.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text.Json;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace AsbCloudWebApi.Tests.UnitTests.Services.WellOperationExport
|
||||
{
|
||||
@ -27,31 +32,36 @@ namespace AsbCloudWebApi.Tests.UnitTests.Services.WellOperationExport
|
||||
private WellOperationImportService wellOperationImportService;
|
||||
private IWellOperationExcelParser<WellOperationImportDefaultOptionsDto> wellOperationDefaultExcelParser;
|
||||
|
||||
|
||||
private readonly WellOperationDto[] operations = new WellOperationDto[2] {
|
||||
new WellOperationDto() {
|
||||
Id = 5,
|
||||
IdWell = idWell,
|
||||
IdUser = 1,
|
||||
IdType = 0,
|
||||
IdWellSectionType = 1,
|
||||
WellSectionTypeName = "1",
|
||||
IdCategory = 1,
|
||||
CategoryInfo = "1",
|
||||
CategoryName = "1",
|
||||
CategoryInfo = "CategoryInfo 1",
|
||||
DepthStart = 10,
|
||||
DepthEnd = 20,
|
||||
DateStart = getDate(days: 0),
|
||||
DateStart = GetDate(days: 0),
|
||||
DurationHours = 10,
|
||||
Comment = "Комментарий 1",
|
||||
},
|
||||
new WellOperationDto() {
|
||||
Id = 6,
|
||||
IdWell = idWell,
|
||||
IdUser = 1,
|
||||
IdType = 0,
|
||||
IdWellSectionType = 2,
|
||||
WellSectionTypeName = "2",
|
||||
IdCategory = 2,
|
||||
CategoryInfo = "2",
|
||||
CategoryName = "2",
|
||||
CategoryInfo = "CategoryInfo 2",
|
||||
DepthStart = 20,
|
||||
DepthEnd = 30,
|
||||
DateStart = getDate(days: 1),
|
||||
DateStart = GetDate(days: 1),
|
||||
DurationHours = 20,
|
||||
Comment = "Комментарий 2",
|
||||
}
|
||||
@ -92,14 +102,15 @@ namespace AsbCloudWebApi.Tests.UnitTests.Services.WellOperationExport
|
||||
Name = "2"
|
||||
}
|
||||
};
|
||||
private readonly ITestOutputHelper output;
|
||||
|
||||
private static DateTime getDate(int days)
|
||||
private static DateTime GetDate(int days)
|
||||
{
|
||||
var date = DateTime.Now.AddDays(days);
|
||||
return new DateTime(date.Year, date.Month, date.Day, date.Hour, date.Minute, date.Second);
|
||||
}
|
||||
|
||||
public WellOperationExportServiceTest()
|
||||
public WellOperationExportServiceTest(ITestOutputHelper output)
|
||||
{
|
||||
wellService = Substitute.For<IWellService>();
|
||||
wellOperationRepository = Substitute.For<IWellOperationRepository>();
|
||||
@ -108,6 +119,7 @@ namespace AsbCloudWebApi.Tests.UnitTests.Services.WellOperationExport
|
||||
|
||||
wellOperationImportService = new WellOperationImportService(wellOperationRepository);
|
||||
wellOperationDefaultExcelParser = new WellOperationDefaultExcelParser();
|
||||
this.output = output;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@ -136,6 +148,53 @@ namespace AsbCloudWebApi.Tests.UnitTests.Services.WellOperationExport
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestDataContainsNotDefaultProps()
|
||||
{
|
||||
var initOk = true;
|
||||
for (int i = 0; i < operations.Length; i++)
|
||||
{
|
||||
var operation = operations[i];
|
||||
var propsWithDefault = GetPropsWithDefaultValue(operation,
|
||||
nameof(WellOperationDto.Id),
|
||||
nameof(WellOperationDto.IdType),
|
||||
nameof(WellOperationDto.IdPlan),
|
||||
nameof(WellOperationDto.IdParentCategory),
|
||||
nameof(WellOperationDto.Day),
|
||||
nameof(WellOperationDto.NptHours),
|
||||
nameof(WellOperationDto.UserName),
|
||||
nameof(WellOperationDto.LastUpdateDate)
|
||||
)
|
||||
.ToArray();
|
||||
|
||||
if (propsWithDefault.Any())
|
||||
{
|
||||
initOk = false;
|
||||
foreach (var propertyName in propsWithDefault)
|
||||
output.WriteLine($"{nameof(operations)}[{i}].{propertyName} is default");
|
||||
}
|
||||
}
|
||||
|
||||
Assert.True(initOk);
|
||||
}
|
||||
|
||||
private static IEnumerable<string> GetPropsWithDefaultValue<T>(T dto, params string[] excludeProps)
|
||||
{
|
||||
IEnumerable<PropertyInfo> props = typeof(T).GetProperties(
|
||||
BindingFlags.Public
|
||||
| BindingFlags.Instance);
|
||||
|
||||
props = props
|
||||
.Where(prop=>prop.CanWrite)
|
||||
.Where(prop => !excludeProps.Contains(prop.Name));
|
||||
|
||||
foreach (var prop in props)
|
||||
{
|
||||
var value = prop.GetValue(dto);
|
||||
if (prop.PropertyType.IsDefaultValue(value))
|
||||
yield return prop.Name;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -45,7 +45,6 @@ namespace AsbCloudWebApi.Controllers.SAUB
|
||||
/// <param name = "token" >Токен завершения задачи</param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("{idWell}")]
|
||||
[Permission]
|
||||
public async Task<ActionResult<IEnumerable<WitsRecordDto>>> GetDataAsync([Required] int idWell,
|
||||
[FromQuery] GtrWithGetDataRequest request,
|
||||
CancellationToken token)
|
||||
@ -75,7 +74,6 @@ namespace AsbCloudWebApi.Controllers.SAUB
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("{idWell}/{idRecord}")]
|
||||
[Permission]
|
||||
public async Task<ActionResult<IEnumerable<WitsItemRecordDto>>> GetLastDataByRecordIdAsync(int idWell, int idRecord, CancellationToken token)
|
||||
{
|
||||
int? idCompany = User.GetCompanyId();
|
||||
|
@ -403,7 +403,8 @@ namespace AsbCloudWebApi.Controllers
|
||||
/// <summary>
|
||||
/// Импорт операций из excel (xlsx) файла. ГПНХ (Хантос)
|
||||
/// </summary>
|
||||
/// <param name="idWell">id скважины</param>
|
||||
/// <param name="idWell">Id скважины</param>
|
||||
/// <param name="options">Параметры парсинга</param>
|
||||
/// <param name="files">Коллекция из одного файла xlsx</param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
@ -412,13 +413,11 @@ namespace AsbCloudWebApi.Controllers
|
||||
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
|
||||
[Permission]
|
||||
public Task<IActionResult> ImportPlanGazpromKhantosExcelFileAsync(int idWell,
|
||||
[FromQuery] WellOperationImportGazpromKhantosOptionsDto options,
|
||||
[FromForm] IFormFileCollection files,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var options = new WellOperationImportGazpromKhantosOptionsDto
|
||||
{
|
||||
IdType = WellOperation.IdOperationTypePlan
|
||||
};
|
||||
options.IdType = WellOperation.IdOperationTypePlan;
|
||||
|
||||
return ImportExcelFileAsync(idWell, files, options,
|
||||
(stream, _) => wellOperationGazpromKhantosExcelParser.Parse(stream, options),
|
||||
|
Loading…
Reference in New Issue
Block a user