diff --git a/AsbCloudApp/Data/WellOperation/WellOperationDto.cs b/AsbCloudApp/Data/WellOperation/WellOperationDto.cs index 2d8b8c87..17015451 100644 --- a/AsbCloudApp/Data/WellOperation/WellOperationDto.cs +++ b/AsbCloudApp/Data/WellOperation/WellOperationDto.cs @@ -6,7 +6,8 @@ namespace AsbCloudApp.Data.WellOperation; public class WellOperationDto : ItemInfoDto, IId, - IWellRelated + IWellRelated, + IValidatableObject { /// [Required] diff --git a/AsbCloudInfrastructure/Repository/WellOperationRepository.cs b/AsbCloudInfrastructure/Repository/WellOperationRepository.cs index 702ca982..7532b2aa 100644 --- a/AsbCloudInfrastructure/Repository/WellOperationRepository.cs +++ b/AsbCloudInfrastructure/Repository/WellOperationRepository.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Threading; @@ -176,10 +176,10 @@ public class WellOperationRepository : CrudRepositoryBase BuildQuery(WellOperationRequest request) { var currentWellOperations = GetQuery() - .Where(e => request.IdsWell != null && request.IdsWell.Contains(e.Id)); + .Where(e => request.IdsWell != null && request.IdsWell.Contains(e.IdWell)); var query = GetQuery() - .Where(e => request.IdsWell != null && request.IdsWell.Contains(e.Id)) + .Where(e => request.IdsWell != null && request.IdsWell.Contains(e.IdWell)) .Select(o => new WellOperation { Id = o.Id, diff --git a/AsbCloudInfrastructure/Services/DailyReport/DailyReportService.cs b/AsbCloudInfrastructure/Services/DailyReport/DailyReportService.cs index 43fb0abf..fface665 100644 --- a/AsbCloudInfrastructure/Services/DailyReport/DailyReportService.cs +++ b/AsbCloudInfrastructure/Services/DailyReport/DailyReportService.cs @@ -13,6 +13,7 @@ using AsbCloudApp.Data.DailyReport.Blocks.Sign; using AsbCloudApp.Data.DailyReport.Blocks.Subsystems; using AsbCloudApp.Data.DailyReport.Blocks.TimeBalance; using AsbCloudApp.Data.DailyReport.Blocks.WellOperation; +using AsbCloudApp.Data.WellOperation; using AsbCloudApp.Requests; using AsbCloudApp.Services.DailyReport; using AsbCloudApp.Services.ProcessMaps.WellDrilling; @@ -107,14 +108,14 @@ public class DailyReportService : IDailyReportService }; var geDate = dailyReport.Date.ToDateTime(TimeOnly.MinValue, DateTimeKind.Unspecified); - var ltDate = dailyReport.Date.AddDays(1).ToDateTime(TimeOnly.MinValue, DateTimeKind.Unspecified); + var leDate = dailyReport.Date.AddDays(1).ToDateTime(TimeOnly.MinValue, DateTimeKind.Unspecified); var factOperationRequest = new WellOperationRequest { - IdWell = idWell, + IdsWell = new []{ idWell }, OperationType = WellOperation.IdOperationTypeFact, GeDate = geDate, - LtDate = ltDate + LeDate = leDate }; var factWellOperations = (await wellOperationRepository.GetAsync(factOperationRequest, cancellationToken)) @@ -184,14 +185,14 @@ public class DailyReportService : IDailyReportService var existingDailyReports = await dailyReportRepository.GetAsync(idWell, request, cancellationToken); var geDateFactWellOperation = datesRange.From.AddDays(result.Skip); - var ltDateFactWellOperation = geDateFactWellOperation.AddDays(result.Take); + var leDateFactWellOperation = geDateFactWellOperation.AddDays(result.Take); var factWellOperationRequest = new WellOperationRequest { - IdWell = idWell, + IdsWell = new[] { idWell }, OperationType = WellOperation.IdOperationTypeFact, GeDate = geDateFactWellOperation, - LtDate = ltDateFactWellOperation + LeDate = leDateFactWellOperation }; var factWellOperations = await wellOperationRepository.GetAsync(factWellOperationRequest, cancellationToken); @@ -200,7 +201,7 @@ public class DailyReportService : IDailyReportService { for (var day = result.Skip; day - result.Skip < result.Take && datesRange.To.AddDays(-day) >= datesRange.From; day++) { - var dateDailyReport = DateOnly.FromDateTime(datesRange.To.AddDays(-day)); + var dateDailyReport = DateOnly.FromDateTime(datesRange.To.AddDays(-day).DateTime); AddDailyReport(dateDailyReport); } @@ -209,7 +210,7 @@ public class DailyReportService : IDailyReportService { for (var day = result.Skip; day - result.Skip < result.Take && datesRange.From.AddDays(day) <= datesRange.To; day++) { - var dateDailyReport = DateOnly.FromDateTime(datesRange.From.AddDays(day)); + var dateDailyReport = DateOnly.FromDateTime(datesRange.From.AddDays(day).DateTime); AddDailyReport(dateDailyReport); } @@ -401,7 +402,7 @@ public class DailyReportService : IDailyReportService WellOperations = factWellOperations.GroupBy(o => o.IdCategory) .Select(g => new WellOperationRecordDto { - CategoryName = g.First().CategoryName, + CategoryName = g.First().OperationCategoryName, DurationHours = g.Sum(o => o.DurationHours) }), @@ -418,8 +419,8 @@ public class DailyReportService : IDailyReportService if (datesRange is null) return false; - var from = DateOnly.FromDateTime(datesRange.From); - var to = DateOnly.FromDateTime(datesRange.To); + var from = DateOnly.FromDateTime(datesRange.From.DateTime); + var to = DateOnly.FromDateTime(datesRange.To.DateTime); return dateDailyReport >= from && dateDailyReport <= to; } diff --git a/AsbCloudInfrastructure/Services/DetectOperations/DetectedOperationExportService.cs b/AsbCloudInfrastructure/Services/DetectOperations/DetectedOperationExportService.cs index fd33c32a..6ed731f6 100644 --- a/AsbCloudInfrastructure/Services/DetectOperations/DetectedOperationExportService.cs +++ b/AsbCloudInfrastructure/Services/DetectOperations/DetectedOperationExportService.cs @@ -13,6 +13,7 @@ using Microsoft.AspNetCore.Http.Extensions; using AsbCloudApp.Exceptions; using AsbCloudApp.Services; using AsbCloudApp.Data; +using AsbCloudApp.Data.WellOperation; using AsbCloudInfrastructure.Services.DetectOperations.Detectors; namespace AsbCloudInfrastructure.Services.DetectOperations; diff --git a/AsbCloudInfrastructure/Services/DetectOperations/DetectedOperationService.cs b/AsbCloudInfrastructure/Services/DetectOperations/DetectedOperationService.cs index b53b1cd0..9059d6bb 100644 --- a/AsbCloudInfrastructure/Services/DetectOperations/DetectedOperationService.cs +++ b/AsbCloudInfrastructure/Services/DetectOperations/DetectedOperationService.cs @@ -10,6 +10,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; +using AsbCloudApp.Data.WellOperation; using AsbCloudInfrastructure.Services.DetectOperations.Detectors; namespace AsbCloudInfrastructure.Services.DetectOperations; diff --git a/AsbCloudInfrastructure/Services/SAUB/TelemetryDataBaseService.cs b/AsbCloudInfrastructure/Services/SAUB/TelemetryDataBaseService.cs index f9cc64ee..a491b483 100644 --- a/AsbCloudInfrastructure/Services/SAUB/TelemetryDataBaseService.cs +++ b/AsbCloudInfrastructure/Services/SAUB/TelemetryDataBaseService.cs @@ -102,7 +102,7 @@ namespace AsbCloudInfrastructure.Services.SAUB if (dateBegin == default) { var dateRange = telemetryDataCache.GetOrDefaultDataDateRange(telemetry.Id); - dateBeginUtc = (dateRange?.To.ToUtcDateTimeOffset(timezone.Hours) ?? DateTime.UtcNow) + dateBeginUtc = (dateRange?.To.UtcDateTime ?? DateTime.UtcNow) .AddSeconds(-intervalSec); } else diff --git a/AsbCloudInfrastructure/Services/WellCompositeOperationService.cs b/AsbCloudInfrastructure/Services/WellCompositeOperationService.cs index 6ba97ea0..4334e8be 100644 --- a/AsbCloudInfrastructure/Services/WellCompositeOperationService.cs +++ b/AsbCloudInfrastructure/Services/WellCompositeOperationService.cs @@ -8,6 +8,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; +using AsbCloudApp.Data.WellOperation; namespace AsbCloudInfrastructure.Services { @@ -133,7 +134,7 @@ namespace AsbCloudInfrastructure.Services this.wellOperationRepository = wellOperationRepository; } - public async Task>> GetAsync(IEnumerable idsWells, CancellationToken token) + public async Task>> GetAsync(IEnumerable idsWells, CancellationToken token) { var sections = await wellSectionTypeRepository.GetAllAsync(token); var sectionsDict = sections.ToDictionary(s => s.Id, s => s.Caption); @@ -144,7 +145,7 @@ namespace AsbCloudInfrastructure.Services var idsWellSectionTypes = WellSectionTypesWithCategories.Select(t => t.IdSectionType).Distinct(); var usedCategories = WellSectionTypesWithCategories.Select(c => c.IdCategory).Distinct(); - var wellOperationRequest = new WellsOperationRequest() + var wellOperationRequest = new WellOperationRequest { IdsWell = idsWells, OperationCategoryIds = usedCategories, @@ -155,7 +156,7 @@ namespace AsbCloudInfrastructure.Services var renamedOperations = operations.Select(o => UpdateIdWellSectionAndIdCategory(o, sectionsDict, categoriesDict)); - var wellOperationsWithComposite = new List>(); + var wellOperationsWithComposite = new List>(); var compositeDepth = 0d; foreach ((int IdSection, int IdCategory) in WellSectionTypesWithCategories) { @@ -168,7 +169,7 @@ namespace AsbCloudInfrastructure.Services var groupedByWell = filteredByTemplate.GroupBy(o => o.IdWell); - var aggreagtedByWell = groupedByWell.Select(g => new WellOperationDataDto + var aggreagtedByWell = groupedByWell.Select(g => new WellOperationDto { IdCategory = IdCategory, IdWell = g.Key, @@ -197,15 +198,15 @@ namespace AsbCloudInfrastructure.Services return wellOperationsWithComposite; } - private static WellOperationDataDto UpdateIdWellSectionAndIdCategory( - WellOperationDataDto dto, - Dictionary sectionTypes, - Dictionary operationCategories) + private static WellOperationDto UpdateIdWellSectionAndIdCategory( + WellOperationDto dto, + IDictionary sectionTypes, + IDictionary operationCategories) { if (dto.IdWellSectionType == wellSectionTransportTable) { dto.IdWellSectionType = wellSectionProductionString; - dto.WellSectionTypeCaption = sectionTypes[dto.IdWellSectionType] ?? string.Empty; + dto.WellSectionTypeCaption = sectionTypes[dto.IdWellSectionType]; } if ((SettingsForSectionCategoryChange.TryGetValue((dto.IdWellSectionType, dto.IdCategory), out int newIdCategory))) diff --git a/AsbCloudInfrastructure/Services/WellOperationService/OperationsStatService.cs b/AsbCloudInfrastructure/Services/WellOperationService/OperationsStatService.cs index c9018051..e5d46b27 100644 --- a/AsbCloudInfrastructure/Services/WellOperationService/OperationsStatService.cs +++ b/AsbCloudInfrastructure/Services/WellOperationService/OperationsStatService.cs @@ -10,6 +10,7 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; using AsbCloudApp.Data.SAUB; +using AsbCloudApp.Data.WellOperation; using AsbCloudApp.Repositories; namespace AsbCloudInfrastructure.Services.WellOperationService; @@ -552,8 +553,8 @@ public class OperationsStatService : IOperationsStatService private static WellOperationDto Convert(WellOperation source, double tzOffsetHours) { var destination = source.Adapt(); - destination.CategoryName = source.OperationCategory?.Name; - destination.WellSectionTypeName = source.WellSectionType?.Caption; + destination.OperationCategoryName = source.OperationCategory.Name; + destination.WellSectionTypeCaption = source.WellSectionType.Caption; destination.DateStart = source.DateStart.ToRemoteDateTime(tzOffsetHours); return destination; } diff --git a/AsbCloudInfrastructure/Services/WellService.cs b/AsbCloudInfrastructure/Services/WellService.cs index 4d6ec10a..1b306f15 100644 --- a/AsbCloudInfrastructure/Services/WellService.cs +++ b/AsbCloudInfrastructure/Services/WellService.cs @@ -47,7 +47,7 @@ namespace AsbCloudInfrastructure.Services this.telemetryService = telemetryService; this.timezoneService = timezoneService; this.wellInfoService = wellInfoService; - this.wellOperationRepository = new WellOperationRepository(db, memoryCache, this, wellOperationCategoryRepository); + wellOperationRepository = new WellOperationRepository(db, memoryCache, wellOperationCategoryRepository, this); companyTypesService = new CrudCacheRepositoryBase(dbContext, memoryCache); } @@ -71,7 +71,7 @@ namespace AsbCloudInfrastructure.Services return DateTime.MinValue; var datesRange = telemetryService.GetDatesRange(well.IdTelemetry.Value); - return datesRange.To; + return datesRange.To.DateTime; } /// @@ -273,12 +273,13 @@ namespace AsbCloudInfrastructure.Services if (entity.Timezone is null) dto.Timezone = GetTimezone(entity.Id); - dto.StartDate = wellOperationRepository.FirstOperationDate(entity.Id)?.ToRemoteDateTime(dto.Timezone.Hours); + //TODO: фикс + //dto.StartDate = wellOperationRepository.GetDatesRangeAsync(entity.Id, ).FirstOperationDate(entity.Id)?.ToRemoteDateTime(dto.Timezone.Hours); dto.WellType = entity.WellType.Caption; dto.Cluster = entity.Cluster.Caption; dto.Deposit = entity.Cluster.Deposit.Caption; if (entity.IdTelemetry is not null) - dto.LastTelemetryDate = telemetryService.GetDatesRange(entity.IdTelemetry.Value).To; + dto.LastTelemetryDate = telemetryService.GetDatesRange(entity.IdTelemetry.Value).To.DateTime; dto.Companies = entity.RelationCompaniesWells .Select(r => Convert(r.Company)) .ToList(); diff --git a/AsbCloudWebApi.Tests/Services/DailyReportServiceTest.cs b/AsbCloudWebApi.Tests/Services/DailyReportServiceTest.cs index 58f23ccc..d7af2c1c 100644 --- a/AsbCloudWebApi.Tests/Services/DailyReportServiceTest.cs +++ b/AsbCloudWebApi.Tests/Services/DailyReportServiceTest.cs @@ -19,6 +19,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; +using AsbCloudApp.Data.WellOperation; using Xunit; namespace AsbCloudWebApi.Tests.Services; @@ -154,7 +155,7 @@ public class DailyReportServiceTest IdWell = idWell, IdParentCategory = 4001, IdWellSectionType = 1, - CategoryName = "Механическое. бурение", + OperationCategoryName = "Механическое. бурение", DateStart = new DateTime(2023, 10, 26), DepthStart = 80, DepthEnd = 150, @@ -164,7 +165,7 @@ public class DailyReportServiceTest private readonly WellOperationDto fakeLastFactWellOperation = new() { IdWell = idWell, - CategoryName = "Механическое. бурение", + OperationCategoryName = "Механическое. бурение", IdWellSectionType = 1, IdParentCategory = 4001, DateStart = new DateTime(2023, 10, 26), diff --git a/AsbCloudWebApi.Tests/Services/WellCompositeOperation/WellCompositeOperationServiceTest.cs b/AsbCloudWebApi.Tests/Services/WellCompositeOperation/WellCompositeOperationServiceTest.cs index d4659d8a..4018417c 100644 --- a/AsbCloudWebApi.Tests/Services/WellCompositeOperation/WellCompositeOperationServiceTest.cs +++ b/AsbCloudWebApi.Tests/Services/WellCompositeOperation/WellCompositeOperationServiceTest.cs @@ -15,6 +15,7 @@ using System.Threading.Tasks; using Xunit; using AsbCloudApp.Repositories; using AsbCloudApp.Data; +using AsbCloudApp.Data.WellOperation; using AsbCloudApp.Services; namespace AsbCloudWebApi.Tests.Services.WellCompositeOperation @@ -50,9 +51,9 @@ namespace AsbCloudWebApi.Tests.Services.WellCompositeOperation new() {Id = 31, Caption = "Техническая колонна", Order = 2} }; - private readonly static IEnumerable wellOperations1 = new List() + private readonly static IEnumerable wellOperations1 = new List() { - new WellOperationDataDto() + new() { DepthStart = 50, DurationHours = 1, @@ -62,7 +63,7 @@ namespace AsbCloudWebApi.Tests.Services.WellCompositeOperation OperationCategoryName = "Шаблонирование перед спуском", WellSectionTypeCaption = "Направление" }, - new WellOperationDataDto() + new() { DepthStart = 84, DurationHours = 1, @@ -74,9 +75,9 @@ namespace AsbCloudWebApi.Tests.Services.WellCompositeOperation } }; - private readonly static IEnumerable wellOperations2 = new List() + private readonly static IEnumerable wellOperations2 = new List() { - new WellOperationDataDto() + new() { DepthStart = 10, DurationHours = 1.5, @@ -86,7 +87,7 @@ namespace AsbCloudWebApi.Tests.Services.WellCompositeOperation OperationCategoryName = "Бурение ротором", WellSectionTypeCaption = "Направление" }, - new WellOperationDataDto() + new() { DepthStart = 20, DurationHours = 3.5, @@ -98,9 +99,9 @@ namespace AsbCloudWebApi.Tests.Services.WellCompositeOperation } }; - private readonly static IEnumerable wellOperations3 = new List() + private readonly static IEnumerable wellOperations3 = new List() { - new WellOperationDataDto() + new() { DepthStart = 1372, DurationHours = 3, @@ -110,7 +111,7 @@ namespace AsbCloudWebApi.Tests.Services.WellCompositeOperation OperationCategoryName = "Промывка", WellSectionTypeCaption = "Кондуктор" }, - new WellOperationDataDto() + new() { DepthStart = 1435, DurationHours = 4, @@ -122,9 +123,9 @@ namespace AsbCloudWebApi.Tests.Services.WellCompositeOperation } }; - private readonly static IEnumerable wellOperations4 = new List() + private readonly static IEnumerable wellOperations4 = new List() { - new WellOperationDataDto() + new() { DepthStart = 1000, DurationHours = 10, @@ -134,7 +135,7 @@ namespace AsbCloudWebApi.Tests.Services.WellCompositeOperation OperationCategoryName = "Подъем инструмента", WellSectionTypeCaption = "Техническая колонна" }, - new WellOperationDataDto() + new() { DepthStart = 500, DurationHours = 5, @@ -144,7 +145,7 @@ namespace AsbCloudWebApi.Tests.Services.WellCompositeOperation OperationCategoryName = "Проработка принудительная", WellSectionTypeCaption = "Техническая колонна" }, - new WellOperationDataDto() + new() { DepthStart = 600, DurationHours = 5, @@ -181,7 +182,7 @@ namespace AsbCloudWebApi.Tests.Services.WellCompositeOperation public async Task GetAsync_return_composite_and_others_with_category_5013() { // arrange - wellOperationRepository.GetAsync(Arg.Any(), Arg.Any()) + wellOperationRepository.GetAsync(Arg.Any(), Arg.Any()) .Returns(wellOperations1); var idsWell = new List() { 55, 64 }; @@ -216,7 +217,7 @@ namespace AsbCloudWebApi.Tests.Services.WellCompositeOperation public async Task GetAsync_return_composite_with_minimum_depth_start() { // arrange - wellOperationRepository.GetAsync(Arg.Any(), Arg.Any()) + wellOperationRepository.GetAsync(Arg.Any(), Arg.Any()) .Returns(wellOperations2); var idsWell = new List() { 55, 64 }; @@ -242,7 +243,7 @@ namespace AsbCloudWebApi.Tests.Services.WellCompositeOperation public async Task GetAsync_return_data3() { // arrange - wellOperationRepository.GetAsync(Arg.Any(), Arg.Any()) + wellOperationRepository.GetAsync(Arg.Any(), Arg.Any()) .Returns(wellOperations3); var idsWell = new List() { 55, 64 }; @@ -272,7 +273,7 @@ namespace AsbCloudWebApi.Tests.Services.WellCompositeOperation public async Task GetAsync_return_data4() { // arrange - wellOperationRepository.GetAsync(Arg.Any(), Arg.Any()) + wellOperationRepository.GetAsync(Arg.Any(), Arg.Any()) .Returns(wellOperations4); var idsWell = new List() { 55, 64 }; @@ -312,13 +313,13 @@ namespace AsbCloudWebApi.Tests.Services.WellCompositeOperation public async Task GetAsync_return_data5() { // arrange - var wellOperations = new List(); + var wellOperations = new List(); wellOperations.AddRange(wellOperations1); wellOperations.AddRange(wellOperations2); wellOperations.AddRange(wellOperations3); wellOperations.AddRange(wellOperations4); - wellOperationRepository.GetAsync(Arg.Any(), Arg.Any()) + wellOperationRepository.GetAsync(Arg.Any(), Arg.Any()) .Returns(wellOperations); var idsWell = new List() { 55, 64 }; diff --git a/AsbCloudWebApi/Controllers/OperationStatController.cs b/AsbCloudWebApi/Controllers/OperationStatController.cs index d4346255..7126c5f5 100644 --- a/AsbCloudWebApi/Controllers/OperationStatController.cs +++ b/AsbCloudWebApi/Controllers/OperationStatController.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; +using AsbCloudApp.Data.WellOperation; namespace AsbCloudWebApi.Controllers { diff --git a/AsbCloudWebApi/Controllers/SAUB/DetectedOperationController.cs b/AsbCloudWebApi/Controllers/SAUB/DetectedOperationController.cs index c6bd6dda..9b478a2d 100644 --- a/AsbCloudWebApi/Controllers/SAUB/DetectedOperationController.cs +++ b/AsbCloudWebApi/Controllers/SAUB/DetectedOperationController.cs @@ -1,5 +1,4 @@ -using AsbCloudApp.Data; -using AsbCloudApp.Data.DetectedOperation; +using AsbCloudApp.Data.DetectedOperation; using AsbCloudApp.Requests; using AsbCloudApp.Services; using Microsoft.AspNetCore.Authorization; @@ -7,6 +6,7 @@ using Microsoft.AspNetCore.Mvc; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; +using AsbCloudApp.Data.WellOperation; using AsbCloudInfrastructure.Services.DetectOperations; using Microsoft.AspNetCore.Http; diff --git a/AsbCloudWebApi/Controllers/WellCompositeOperationController.cs b/AsbCloudWebApi/Controllers/WellCompositeOperationController.cs index d662e4e8..ab4555c0 100644 --- a/AsbCloudWebApi/Controllers/WellCompositeOperationController.cs +++ b/AsbCloudWebApi/Controllers/WellCompositeOperationController.cs @@ -5,6 +5,7 @@ using Microsoft.AspNetCore.Mvc; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; +using AsbCloudApp.Data.WellOperation; namespace AsbCloudWebApi.Controllers { @@ -24,7 +25,7 @@ namespace AsbCloudWebApi.Controllers } [HttpGet] - [ProducesResponseType(typeof(IList>), (int)System.Net.HttpStatusCode.OK)] + [ProducesResponseType(typeof(IList>), (int)System.Net.HttpStatusCode.OK)] public async Task GetAsync([FromQuery] IEnumerable idsWells, CancellationToken token) { foreach (var idWell in idsWells)