From 72669b05262f8730c74ba41520aaf74776af5b58 Mon Sep 17 00:00:00 2001 From: ngfrolov Date: Thu, 22 Feb 2024 10:48:49 +0500 Subject: [PATCH 1/5] fix SubsystemController --- AsbCloudWebApi/Controllers/Subsystems/SubsystemController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AsbCloudWebApi/Controllers/Subsystems/SubsystemController.cs b/AsbCloudWebApi/Controllers/Subsystems/SubsystemController.cs index 4d16958b..f8124d8d 100644 --- a/AsbCloudWebApi/Controllers/Subsystems/SubsystemController.cs +++ b/AsbCloudWebApi/Controllers/Subsystems/SubsystemController.cs @@ -65,7 +65,7 @@ namespace AsbCloudWebApi.Controllers.Subsystems [HttpGet("drillerDetectedOperationStat")] [ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)] - public async Task GetByWellsAsync(GetStatRequest request, + public async Task GetByWellsAsync([FromQuery] GetStatRequest request, CancellationToken token) { if (!request.IdsWells.Any()) From 2ec609b56f529b75b8012ccdfef2ca6d9878e5c7 Mon Sep 17 00:00:00 2001 From: ngfrolov Date: Thu, 22 Feb 2024 13:34:05 +0500 Subject: [PATCH 2/5] fix test Check_Exported_WellOperations_With_Operations_In_Db --- .../Repositories/IWellOperationRepository.cs | 9 --- .../Repository/WellOperationRepository.cs | 10 +--- .../WellOperationExportService.cs | 12 ++-- .../WellOperationImportService.cs | 18 ++++-- .../WellOperationExportServiceTest.cs | 58 ++++++++++--------- .../Controllers/WellOperationController.cs | 7 ++- 6 files changed, 56 insertions(+), 58 deletions(-) diff --git a/AsbCloudApp/Repositories/IWellOperationRepository.cs b/AsbCloudApp/Repositories/IWellOperationRepository.cs index 2ac586aa..cf277304 100644 --- a/AsbCloudApp/Repositories/IWellOperationRepository.cs +++ b/AsbCloudApp/Repositories/IWellOperationRepository.cs @@ -2,7 +2,6 @@ using AsbCloudApp.Requests; using System; using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; using System.Threading; using System.Threading.Tasks; @@ -13,14 +12,6 @@ namespace AsbCloudApp.Repositories /// public interface IWellOperationRepository { - //TODO: replace all references - /// - /// список названий операций - /// - /// - [Obsolete("use IWellOperationCategoryRepository.GetCategories(bool includeParents)")] - IEnumerable GetCategories(bool includeParents); - /// /// Список секций /// diff --git a/AsbCloudInfrastructure/Repository/WellOperationRepository.cs b/AsbCloudInfrastructure/Repository/WellOperationRepository.cs index c6edb30b..57bf3768 100644 --- a/AsbCloudInfrastructure/Repository/WellOperationRepository.cs +++ b/AsbCloudInfrastructure/Repository/WellOperationRepository.cs @@ -23,7 +23,6 @@ namespace AsbCloudInfrastructure.Repository; public class WellOperationRepository : IWellOperationRepository { private const string KeyCacheSections = "OperationsBySectionSummarties"; - private const int Gap = 90; private readonly IAsbCloudDbContext db; private readonly IMemoryCache memoryCache; @@ -38,13 +37,6 @@ public class WellOperationRepository : IWellOperationRepository this.wellOperationCategoryRepository = wellOperationCategoryRepository; } - /// - public IEnumerable GetCategories(bool includeParents) - { - return wellOperationCategoryRepository.Get(includeParents); - } - - /// public IEnumerable GetSectionTypes() => memoryCache .GetOrCreateBasic(db.Set()) @@ -272,7 +264,7 @@ public class WellOperationRepository : IWellOperationRepository DurationDepth = o.DepthEnd - o.DepthStart }) .ToListAsync(token); - var parentRelationDictionary = GetCategories(true) + var parentRelationDictionary = wellOperationCategoryRepository.Get(true) .ToDictionary(c => c.Id, c => new { c.Name, diff --git a/AsbCloudInfrastructure/Services/WellOperationImport/WellOperationExportService.cs b/AsbCloudInfrastructure/Services/WellOperationImport/WellOperationExportService.cs index 5ce7a2e2..142b751f 100644 --- a/AsbCloudInfrastructure/Services/WellOperationImport/WellOperationExportService.cs +++ b/AsbCloudInfrastructure/Services/WellOperationImport/WellOperationExportService.cs @@ -19,15 +19,19 @@ public class WellOperationExportService : IWellOperationExportService private readonly IWellOperationRepository wellOperationRepository; private readonly IWellService wellService; private readonly IWellOperationImportTemplateService wellOperationImportTemplateService; + private readonly IWellOperationCategoryRepository wellOperationCategoryRepository; - public WellOperationExportService(IWellOperationRepository wellOperationRepository, + public WellOperationExportService( + IWellOperationRepository wellOperationRepository, IWellService wellService, - IWellOperationImportTemplateService wellOperationImportTemplateService) + IWellOperationImportTemplateService wellOperationImportTemplateService, + IWellOperationCategoryRepository wellOperationCategoryRepository) { this.wellOperationRepository = wellOperationRepository; this.wellService = wellService; this.wellOperationImportTemplateService = wellOperationImportTemplateService; - } + this.wellOperationCategoryRepository = wellOperationCategoryRepository; + } public async Task ExportAsync(int idWell, CancellationToken cancellationToken) { @@ -76,7 +80,7 @@ public class WellOperationExportService : IWellOperationExportService var operationsToArray = operations.ToArray(); var sections = wellOperationRepository.GetSectionTypes(); - var categories = wellOperationRepository.GetCategories(false); + var categories = wellOperationCategoryRepository.Get(false); for (int i = 0; i < operationsToArray.Length; i++) { diff --git a/AsbCloudInfrastructure/Services/WellOperationImport/WellOperationImportService.cs b/AsbCloudInfrastructure/Services/WellOperationImport/WellOperationImportService.cs index 800979e5..6ad227a3 100644 --- a/AsbCloudInfrastructure/Services/WellOperationImport/WellOperationImportService.cs +++ b/AsbCloudInfrastructure/Services/WellOperationImport/WellOperationImportService.cs @@ -14,24 +14,28 @@ public class WellOperationImportService : IWellOperationImportService { private readonly IWellService wellService; private readonly IWellOperationRepository wellOperationRepository; - - private static readonly DateTime dateLimitMin = new(2001, 1, 1, 0, 0, 0); + private readonly IWellOperationCategoryRepository wellOperationCategoryRepository; + private static readonly DateTime dateLimitMin = new(2001, 1, 1, 0, 0, 0); private static readonly DateTime dateLimitMax = new(2099, 1, 1, 0, 0, 0); private static readonly TimeSpan drillingDurationLimitMax = TimeSpan.FromDays(366); - public WellOperationImportService(IWellService wellService, - IWellOperationRepository wellOperationRepository) + public WellOperationImportService( + IWellService wellService, + IWellOperationRepository wellOperationRepository, + IWellOperationCategoryRepository wellOperationCategoryRepository + ) { this.wellService = wellService; this.wellOperationRepository = wellOperationRepository; - } + this.wellOperationCategoryRepository = wellOperationCategoryRepository; + } public IEnumerable Import(int idWell, int idUser, int idType, SheetDto sheet) { var validationErrors = new List(); var sections = wellOperationRepository.GetSectionTypes(); - var categories = wellOperationRepository.GetCategories(false); + var categories = wellOperationCategoryRepository.Get(false); var wellOperations = new List(); @@ -83,7 +87,9 @@ public class WellOperationImportService : IWellOperationImportService IdUser = idUser, IdType = idType, IdWellSectionType = section.Id, + WellSectionTypeName = section.Caption, IdCategory = category.Id, + CategoryName = category.Name, CategoryInfo = row.CategoryInfo, DepthStart = row.DepthStart, DepthEnd = row.DepthEnd, diff --git a/AsbCloudWebApi.Tests/Services/WellOperationExport/WellOperationExportServiceTest.cs b/AsbCloudWebApi.Tests/Services/WellOperationExport/WellOperationExportServiceTest.cs index 3d66aab9..e58adda7 100644 --- a/AsbCloudWebApi.Tests/Services/WellOperationExport/WellOperationExportServiceTest.cs +++ b/AsbCloudWebApi.Tests/Services/WellOperationExport/WellOperationExportServiceTest.cs @@ -5,6 +5,7 @@ using AsbCloudApp.Requests; using AsbCloudApp.Services; using AsbCloudApp.Services.WellOperationImport; using AsbCloudDb.Model; +using AsbCloudInfrastructure.Repository; using AsbCloudInfrastructure.Services.WellOperationImport; using AsbCloudInfrastructure.Services.WellOperationImport.FileParser; using NSubstitute; @@ -27,6 +28,7 @@ namespace AsbCloudWebApi.Tests.Services.WellOperationExport private IWellService wellService; private IWellOperationRepository wellOperationRepository; + private IWellOperationCategoryRepository wellOperationCategoryRepository; private IWellOperationImportTemplateService wellOperationImportTemplateService; private WellOperationExportService wellOperationExportService; private WellOperationImportService wellOperationImportService; @@ -114,46 +116,46 @@ namespace AsbCloudWebApi.Tests.Services.WellOperationExport { wellService = Substitute.For(); wellOperationRepository = Substitute.For(); + wellOperationCategoryRepository = Substitute.For(); wellOperationImportTemplateService = new WellOperationImportTemplateService(); - wellOperationExportService = new WellOperationExportService(wellOperationRepository, wellService, wellOperationImportTemplateService); + wellOperationExportService = new WellOperationExportService(wellOperationRepository, wellService, wellOperationImportTemplateService, wellOperationCategoryRepository); - wellOperationImportService = new WellOperationImportService(wellService, wellOperationRepository); + wellOperationImportService = new WellOperationImportService(wellService, wellOperationRepository, wellOperationCategoryRepository); wellOperationDefaultExcelParser = new WellOperationDefaultExcelParser(); this.output = output; } -#warning Test Check_Exported_WellOperations_With_Operations_In_Db Fails and commented for debug deployment task - //[Fact] - //public async Task Check_Exported_WellOperations_With_Operations_In_Db() - //{ - // wellService.GetTimezone(idWell).Returns(new SimpleTimezoneDto() - // { - // Hours = 5 - // }); + [Fact] + public async Task Check_Exported_WellOperations_With_Operations_In_Db() + { + wellService.GetTimezone(idWell).Returns(new SimpleTimezoneDto() + { + Hours = 5 + }); - // var localOperations = operations.ToArray(); - // foreach (var operation in localOperations) - // operation.Id = 0; + var localOperations = operations.ToArray(); + foreach (var operation in localOperations) + operation.Id = 0; - // wellOperationRepository.GetAsync(Arg.Any(), Arg.Any()) - // .ReturnsForAnyArgs(localOperations); - // wellOperationRepository.GetSectionTypes().Returns(sectionTypes); - // wellOperationRepository.GetCategories(false).Returns(categories); + wellOperationRepository.GetAsync(Arg.Any(), Arg.Any()) + .ReturnsForAnyArgs(localOperations); + wellOperationRepository.GetSectionTypes().Returns(sectionTypes); + wellOperationCategoryRepository.Get(false).Returns(categories); - // var stream = await wellOperationExportService.ExportAsync(idWell, CancellationToken.None); + var stream = await wellOperationExportService.ExportAsync(idWell, CancellationToken.None); - // var options = new WellOperationImportDefaultOptionsDto - // { - // IdType = WellOperation.IdOperationTypePlan - // }; - // var sheet = wellOperationDefaultExcelParser.Parse(stream, options); - // var result = wellOperationImportService.Import(idWell, 1, options.IdType, sheet); + var options = new WellOperationImportDefaultOptionsDto + { + IdType = WellOperation.IdOperationTypePlan + }; + var sheet = wellOperationDefaultExcelParser.Parse(stream, options); + var result = wellOperationImportService.Import(idWell, 1, options.IdType, sheet); - // var expected = JsonSerializer.Serialize(localOperations); - // var actual = JsonSerializer.Serialize(result); + var expected = JsonSerializer.Serialize(localOperations); + var actual = JsonSerializer.Serialize(result); - // Assert.Equal(expected, actual); - //} + Assert.Equal(expected, actual); + } [Fact] public void TestDataContainsNotDefaultProps() diff --git a/AsbCloudWebApi/Controllers/WellOperationController.cs b/AsbCloudWebApi/Controllers/WellOperationController.cs index 0d53a4ad..d624e89a 100644 --- a/AsbCloudWebApi/Controllers/WellOperationController.cs +++ b/AsbCloudWebApi/Controllers/WellOperationController.cs @@ -35,6 +35,7 @@ namespace AsbCloudWebApi.Controllers private readonly IWellOperationExportService wellOperationExportService; private readonly IWellOperationImportTemplateService wellOperationImportTemplateService; private readonly IWellOperationImportService wellOperationImportService; + private readonly IWellOperationCategoryRepository wellOperationCategoryRepository; private readonly IWellOperationExcelParser wellOperationDefaultExcelParser; private readonly IWellOperationExcelParser wellOperationGazpromKhantosExcelParser; private readonly IUserRepository userRepository; @@ -44,6 +45,7 @@ namespace AsbCloudWebApi.Controllers IWellOperationImportTemplateService wellOperationImportTemplateService, IWellOperationExportService wellOperationExportService, IWellOperationImportService wellOperationImportService, + IWellOperationCategoryRepository wellOperationCategoryRepository, IWellOperationExcelParser wellOperationDefaultExcelParser, IWellOperationExcelParser wellOperationGazpromKhantosExcelParser, IUserRepository userRepository) @@ -53,6 +55,7 @@ namespace AsbCloudWebApi.Controllers this.wellOperationImportTemplateService = wellOperationImportTemplateService; this.wellOperationExportService = wellOperationExportService; this.wellOperationImportService = wellOperationImportService; + this.wellOperationCategoryRepository = wellOperationCategoryRepository; this.wellOperationDefaultExcelParser = wellOperationDefaultExcelParser; this.wellOperationGazpromKhantosExcelParser = wellOperationGazpromKhantosExcelParser; this.userRepository = userRepository; @@ -81,7 +84,7 @@ namespace AsbCloudWebApi.Controllers [ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)] public IActionResult GetCategories(bool includeParents = true) { - var result = operationRepository.GetCategories(includeParents); + var result = wellOperationCategoryRepository.Get(includeParents); return Ok(result); } @@ -163,7 +166,7 @@ namespace AsbCloudWebApi.Controllers } /// - /// Статистика операций по скважине, группированая по категориям + /// Статистика операций по скважине, группированная по категориям /// /// id скважины /// From adfd1ad5974a70adfa357e4a2e0ded38eedcec7f Mon Sep 17 00:00:00 2001 From: ngfrolov Date: Thu, 22 Feb 2024 13:47:11 +0500 Subject: [PATCH 3/5] GetStatRequest fix init --- AsbCloudApp/Requests/GetStatRequest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AsbCloudApp/Requests/GetStatRequest.cs b/AsbCloudApp/Requests/GetStatRequest.cs index 8794198b..5ebb9550 100644 --- a/AsbCloudApp/Requests/GetStatRequest.cs +++ b/AsbCloudApp/Requests/GetStatRequest.cs @@ -11,7 +11,7 @@ public class GetStatRequest: RequestBase /// /// id /// - public IEnumerable IdsWells { get; set; } = Enumerable.Empty(); + public IEnumerable IdsWells { get; set; } = new List(); /// /// id From fd15622ad1a2f2c4df10bab1304ec50dcf2bb797 Mon Sep 17 00:00:00 2001 From: ngfrolov Date: Thu, 22 Feb 2024 14:00:20 +0500 Subject: [PATCH 4/5] =?UTF-8?q?WellOperationExportService=20=D1=83=D0=B4?= =?UTF-8?q?=D0=B0=D0=BB=D0=B8=D1=82=D1=8C=20=D0=BD=D0=B5=D0=B8=D1=81=D0=BF?= =?UTF-8?q?=D0=BE=D0=BB=D1=8C=D0=B7=D1=83=D0=B5=D0=BC=D1=83=D1=8E=20=D0=B7?= =?UTF-8?q?=D0=B0=D0=B2=D0=B8=D1=81=D0=B8=D0=BC=D0=BE=D1=81=D1=82=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../WellOperationImport/WellOperationExportService.cs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/AsbCloudInfrastructure/Services/WellOperationImport/WellOperationExportService.cs b/AsbCloudInfrastructure/Services/WellOperationImport/WellOperationExportService.cs index 142b751f..96e640b8 100644 --- a/AsbCloudInfrastructure/Services/WellOperationImport/WellOperationExportService.cs +++ b/AsbCloudInfrastructure/Services/WellOperationImport/WellOperationExportService.cs @@ -6,7 +6,6 @@ using System.Threading.Tasks; using AsbCloudApp.Data; using AsbCloudApp.Repositories; using AsbCloudApp.Requests; -using AsbCloudApp.Services; using AsbCloudApp.Services.WellOperationImport; using AsbCloudInfrastructure.Services.WellOperationImport.Constants; using ClosedXML.Excel; @@ -15,20 +14,16 @@ namespace AsbCloudInfrastructure.Services.WellOperationImport; public class WellOperationExportService : IWellOperationExportService { - //TODO: удалить неиспользуемую зависимость private readonly IWellOperationRepository wellOperationRepository; - private readonly IWellService wellService; private readonly IWellOperationImportTemplateService wellOperationImportTemplateService; private readonly IWellOperationCategoryRepository wellOperationCategoryRepository; public WellOperationExportService( IWellOperationRepository wellOperationRepository, - IWellService wellService, IWellOperationImportTemplateService wellOperationImportTemplateService, IWellOperationCategoryRepository wellOperationCategoryRepository) { this.wellOperationRepository = wellOperationRepository; - this.wellService = wellService; this.wellOperationImportTemplateService = wellOperationImportTemplateService; this.wellOperationCategoryRepository = wellOperationCategoryRepository; } From 1de54b43e6b7e54ed41af75bfa74d63ab0208527 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D1=82=D0=B5=D0=BF=D0=B0=D0=BD=D0=BE=D0=B2=20=D0=94?= =?UTF-8?q?=D0=BC=D0=B8=D1=82=D1=80=D0=B8=D0=B9?= Date: Mon, 26 Feb 2024 07:49:15 +0300 Subject: [PATCH 5/5] =?UTF-8?q?=D0=A4=D0=B8=D0=BA=D1=81=20=D0=B1=D0=B0?= =?UTF-8?q?=D0=B3=D0=B0=20=D0=BE=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F=20=D0=B1=D1=83=D1=80=D0=B8=D0=BB=D1=8C=D1=89=D0=B8?= =?UTF-8?q?=D0=BA=D0=B0=20=D0=B2=20=D1=80=D0=B0=D1=81=D0=BF=D0=B8=D1=81?= =?UTF-8?q?=D0=B0=D0=BD=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AsbCloudInfrastructure/DependencyInjection.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/AsbCloudInfrastructure/DependencyInjection.cs b/AsbCloudInfrastructure/DependencyInjection.cs index ce742684..d61ddc57 100644 --- a/AsbCloudInfrastructure/DependencyInjection.cs +++ b/AsbCloudInfrastructure/DependencyInjection.cs @@ -56,6 +56,10 @@ namespace AsbCloudInfrastructure { public static void MapsterSetup() { + TypeAdapterConfig.GlobalSettings.Default.Config + .ForType() + .Ignore(source => source.Driller); + TypeAdapterConfig.GlobalSettings.Default.Config .ForType() .MapWith((source) => source.DateTime);