diff --git a/AsbCloudApp/Requests/DetectedOperationRequest.cs b/AsbCloudApp/Requests/DetectedOperationRequest.cs index 1e38ff7b..dcf66aab 100644 --- a/AsbCloudApp/Requests/DetectedOperationRequest.cs +++ b/AsbCloudApp/Requests/DetectedOperationRequest.cs @@ -20,12 +20,12 @@ namespace AsbCloudApp.Requests /// Список id телеметрий /// пустой список - нет фильтрации /// - public IEnumerable IdsTelemetries { get; set; } = Enumerable.Empty(); + public IEnumerable IdsTelemetries { get; set; } = Array.Empty(); /// /// категории операций /// - public IEnumerable IdsCategories { get; set; } = Enumerable.Empty(); + public IEnumerable IdsCategories { get; set; } = Array.Empty(); /// /// Больше или равно дате @@ -50,7 +50,7 @@ namespace AsbCloudApp.Requests /// /// Фильтр по пользователю панели /// - public int? EqIdTelemetryUser { get; set; } + public int? IdTelemetryUser { get; set; } } } diff --git a/AsbCloudInfrastructure/Services/DetectOperations/DetectedOperationService.cs b/AsbCloudInfrastructure/Services/DetectOperations/DetectedOperationService.cs index a65525ad..9691c7fb 100644 --- a/AsbCloudInfrastructure/Services/DetectOperations/DetectedOperationService.cs +++ b/AsbCloudInfrastructure/Services/DetectOperations/DetectedOperationService.cs @@ -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; diff --git a/AsbCloudInfrastructure/Services/WellOperationImport/Files/WellOperationImportTemplate.xlsx b/AsbCloudInfrastructure/Services/WellOperationImport/Files/WellOperationImportTemplate.xlsx index 7e9cec5e..6f53ccfb 100644 Binary files a/AsbCloudInfrastructure/Services/WellOperationImport/Files/WellOperationImportTemplate.xlsx and b/AsbCloudInfrastructure/Services/WellOperationImport/Files/WellOperationImportTemplate.xlsx differ diff --git a/AsbCloudInfrastructure/Services/WellOperationService/OperationsStatService.cs b/AsbCloudInfrastructure/Services/WellOperationService/OperationsStatService.cs index a93dc50b..c9018051 100644 --- a/AsbCloudInfrastructure/Services/WellOperationService/OperationsStatService.cs +++ b/AsbCloudInfrastructure/Services/WellOperationService/OperationsStatService.cs @@ -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; } diff --git a/AsbCloudWebApi.Tests/ReflectionExtensions.cs b/AsbCloudWebApi.Tests/ReflectionExtensions.cs new file mode 100644 index 00000000..e08a8e38 --- /dev/null +++ b/AsbCloudWebApi.Tests/ReflectionExtensions.cs @@ -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 _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); + } +} diff --git a/AsbCloudWebApi.Tests/UnitTests/Services/WellOperationExport/WellOperationExportServiceTest.cs b/AsbCloudWebApi.Tests/UnitTests/Services/WellOperationExport/WellOperationExportServiceTest.cs index cdfd6cd8..dc000166 100644 --- a/AsbCloudWebApi.Tests/UnitTests/Services/WellOperationExport/WellOperationExportServiceTest.cs +++ b/AsbCloudWebApi.Tests/UnitTests/Services/WellOperationExport/WellOperationExportServiceTest.cs @@ -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 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(); wellOperationRepository = Substitute.For(); @@ -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 GetPropsWithDefaultValue(T dto, params string[] excludeProps) + { + IEnumerable 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; + } + } + } } diff --git a/AsbCloudWebApi/Controllers/SAUB/GtrWitsController.cs b/AsbCloudWebApi/Controllers/SAUB/GtrWitsController.cs index aab78cd3..f4cfe0b4 100644 --- a/AsbCloudWebApi/Controllers/SAUB/GtrWitsController.cs +++ b/AsbCloudWebApi/Controllers/SAUB/GtrWitsController.cs @@ -45,7 +45,6 @@ namespace AsbCloudWebApi.Controllers.SAUB /// Токен завершения задачи /// [HttpGet("{idWell}")] - [Permission] public async Task>> GetDataAsync([Required] int idWell, [FromQuery] GtrWithGetDataRequest request, CancellationToken token) @@ -75,7 +74,6 @@ namespace AsbCloudWebApi.Controllers.SAUB /// /// [HttpGet("{idWell}/{idRecord}")] - [Permission] public async Task>> GetLastDataByRecordIdAsync(int idWell, int idRecord, CancellationToken token) { int? idCompany = User.GetCompanyId(); diff --git a/AsbCloudWebApi/Controllers/WellOperationController.cs b/AsbCloudWebApi/Controllers/WellOperationController.cs index d4723657..ae0c8b92 100644 --- a/AsbCloudWebApi/Controllers/WellOperationController.cs +++ b/AsbCloudWebApi/Controllers/WellOperationController.cs @@ -403,7 +403,8 @@ namespace AsbCloudWebApi.Controllers /// /// Импорт операций из excel (xlsx) файла. ГПНХ (Хантос) /// - /// id скважины + /// Id скважины + /// Параметры парсинга /// Коллекция из одного файла xlsx /// /// @@ -412,14 +413,12 @@ namespace AsbCloudWebApi.Controllers [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)] [Permission] public Task 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), null,