From cc4ef55c129c23a942c0f93de12dee0b4b12d6c0 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: Wed, 15 Nov 2023 17:23:17 +0500 Subject: [PATCH] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F=20=D0=B1=D0=BB=D0=BE=D0=BA=D0=B0=20=D1=81=20=D0=BD?= =?UTF-8?q?=D0=B0=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=BA=D0=BE=D0=B9=20=D0=BF?= =?UTF-8?q?=D0=BE=D0=B4=D1=81=D0=B8=D1=81=D1=82=D0=B5=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Subsystems/SubsystemParametersDto.cs | 25 ++++++++++ .../Blocks/Subsystems/SubsystemRecordDto.cs | 26 ++-------- .../Blocks/Subsystem/SubsystemParameters.cs | 10 ++++ .../Blocks/Subsystem/SubsystemRecord.cs | 12 ++--- .../DailyReport/DailyReportExportService.cs | 24 ++++----- .../DailyReport/DailyReportService.cs | 37 ++++++-------- .../Services/DailyReportServiceTest.cs | 50 ++++++++++++------- .../Controllers/DailyReportController.cs | 2 +- 8 files changed, 100 insertions(+), 86 deletions(-) create mode 100644 AsbCloudApp/Data/DailyReport/Blocks/Subsystems/SubsystemParametersDto.cs create mode 100644 AsbCloudDb/Model/DailyReports/Blocks/Subsystem/SubsystemParameters.cs diff --git a/AsbCloudApp/Data/DailyReport/Blocks/Subsystems/SubsystemParametersDto.cs b/AsbCloudApp/Data/DailyReport/Blocks/Subsystems/SubsystemParametersDto.cs new file mode 100644 index 00000000..e02d8714 --- /dev/null +++ b/AsbCloudApp/Data/DailyReport/Blocks/Subsystems/SubsystemParametersDto.cs @@ -0,0 +1,25 @@ +using System.ComponentModel.DataAnnotations; + +namespace AsbCloudApp.Data.DailyReport.Blocks.Subsystems; + +/// +/// Параметры наработки подсистемы +/// +public class SubsystemParametersDto +{ + /// + /// Сумма изменения глубин при включенной подсистеме + /// + public double? SumDepthInterval { get; set; } + + /// + /// Наработка подсистемы + /// + public double? UsedTimeHours { get; set; } + + /// + /// Коэффициент использования + /// + [Range(0, 1)] + public double? KUsage { get; set; } +} \ No newline at end of file diff --git a/AsbCloudApp/Data/DailyReport/Blocks/Subsystems/SubsystemRecordDto.cs b/AsbCloudApp/Data/DailyReport/Blocks/Subsystems/SubsystemRecordDto.cs index b8ff05b9..fab29d57 100644 --- a/AsbCloudApp/Data/DailyReport/Blocks/Subsystems/SubsystemRecordDto.cs +++ b/AsbCloudApp/Data/DailyReport/Blocks/Subsystems/SubsystemRecordDto.cs @@ -1,5 +1,3 @@ -using System.ComponentModel.DataAnnotations; - namespace AsbCloudApp.Data.DailyReport.Blocks.Subsystems; /// @@ -10,29 +8,15 @@ public class SubsystemRecordDto /// /// Название подсистемы /// - public string SubsystemName { get; set; } = null!; - - /// - /// Идентификатор временного интервала - /// 1 - за сутки - /// 2 - за скважину - /// - [Range(1, 2)] - public int IdTimeInterval { get; set; } + public string Name { get; set; } = null!; /// - /// Сумма изменения глубин при включеной подсистеме + /// Использование подсистемы за сутки /// - public double? SumDepthInterval { get; set; } + public SubsystemParametersDto? UsagePerDay { get; set; } /// - /// Наработка подсистемы + /// Использование подсистемы за скважину /// - public double? UsedTimeHours { get; set; } - - /// - /// Коэффициент использования - /// - [Range(0, 100)] - public double? KUsage { get; set; } + public SubsystemParametersDto? UsagePerWell { get; set; } } \ No newline at end of file diff --git a/AsbCloudDb/Model/DailyReports/Blocks/Subsystem/SubsystemParameters.cs b/AsbCloudDb/Model/DailyReports/Blocks/Subsystem/SubsystemParameters.cs new file mode 100644 index 00000000..839e181c --- /dev/null +++ b/AsbCloudDb/Model/DailyReports/Blocks/Subsystem/SubsystemParameters.cs @@ -0,0 +1,10 @@ +namespace AsbCloudDb.Model.DailyReports.Blocks.Subsystem; + +public class SubsystemParameters +{ + public double? SumDepthInterval { get; set; } + + public double? UsedTimeHours { get; set; } + + public double? KUsage { get; set; } +} \ No newline at end of file diff --git a/AsbCloudDb/Model/DailyReports/Blocks/Subsystem/SubsystemRecord.cs b/AsbCloudDb/Model/DailyReports/Blocks/Subsystem/SubsystemRecord.cs index 7464a842..86b376b6 100644 --- a/AsbCloudDb/Model/DailyReports/Blocks/Subsystem/SubsystemRecord.cs +++ b/AsbCloudDb/Model/DailyReports/Blocks/Subsystem/SubsystemRecord.cs @@ -2,13 +2,9 @@ namespace AsbCloudDb.Model.DailyReports.Blocks.Subsystem; public class SubsystemRecord { - public string SubsystemName { get; set; } = null!; + public string Name { get; set; } = null!; - public int IdTimeInterval { get; set; } - - public double? SumDepthInterval { get; set; } - - public double? UsedTimeHours { get; set; } - - public double? KUsage { get; set; } + public SubsystemParameters? UsagePerDay { get; set; } + + public SubsystemParameters? UsagePerWell { get; set; } } \ No newline at end of file diff --git a/AsbCloudInfrastructure/Services/DailyReport/DailyReportExportService.cs b/AsbCloudInfrastructure/Services/DailyReport/DailyReportExportService.cs index ed47cc02..63c4c414 100644 --- a/AsbCloudInfrastructure/Services/DailyReport/DailyReportExportService.cs +++ b/AsbCloudInfrastructure/Services/DailyReport/DailyReportExportService.cs @@ -25,7 +25,7 @@ public class DailyReportExportService : IDailyReportExportService private const int rowStartProcessMapWellDrillingBlock = 68; private const int columnTimeBalanceDurationPlan = 3; - private const int columnTimeBalanceDurationFact = 4; + private const int columnTimeBalanceDurationFact = 6; private const int columnTimeBalanceReasonDeviation = 8; private const int columnTimeBalanceDrillingDeviationPerSection = 10; private const int columnTimeBalanceDrillingDeviationPerDay = 11; @@ -179,25 +179,19 @@ public class DailyReportExportService : IDailyReportExportService private static void AddSubsystemBlockToSheet(IXLWorksheet sheet, SubsystemBlockDto subsystemBlock) { - var groupedSubsystems = subsystemBlock.Subsystems.OrderBy(m => m.SubsystemName) - .GroupBy(m => m.SubsystemName); - var rowСurrent = rowStartSubsystemBlock; - foreach (var groupedModule in groupedSubsystems) + foreach (var subsystem in subsystemBlock.Subsystems) { - var useSubsystemPerDay = groupedModule.FirstOrDefault(m => m.IdTimeInterval == 1); - var useSubsystemPerWell = groupedModule.FirstOrDefault(m => m.IdTimeInterval == 2); + sheet.Cell(rowСurrent, columnSubsystemName).Value = subsystem.Name; - sheet.Cell(rowСurrent, columnSubsystemName).Value = groupedModule.Key; + sheet.Cell(rowСurrent, columnUseSubsystemPerDayUsedTimeHours).Value = subsystem.UsagePerDay?.UsedTimeHours; + sheet.Cell(rowСurrent, columnUseSubsystemPerDaySumDepthInterval).Value = subsystem.UsagePerDay?.SumDepthInterval; + sheet.Cell(rowСurrent, columnUseSubsystemPerDayKUsage).Value = subsystem.UsagePerDay?.KUsage; - sheet.Cell(rowСurrent, columnUseSubsystemPerDayUsedTimeHours).Value = useSubsystemPerDay?.UsedTimeHours; - sheet.Cell(rowСurrent, columnUseSubsystemPerDaySumDepthInterval).Value = useSubsystemPerDay?.SumDepthInterval; - sheet.Cell(rowСurrent, columnUseSubsystemPerDayKUsage).Value = useSubsystemPerDay?.KUsage; - - sheet.Cell(rowСurrent, columnUseSubsystemPerWellUsedTimeHours).Value = useSubsystemPerWell?.UsedTimeHours; - sheet.Cell(rowСurrent, columnUseSubsystemPerWellSumDepthInterval).Value = useSubsystemPerWell?.SumDepthInterval; - sheet.Cell(rowСurrent, columnUseSubsystemPerWellKUsage).Value = useSubsystemPerWell?.KUsage; + sheet.Cell(rowСurrent, columnUseSubsystemPerWellUsedTimeHours).Value = subsystem.UsagePerWell?.UsedTimeHours; + sheet.Cell(rowСurrent, columnUseSubsystemPerWellSumDepthInterval).Value = subsystem.UsagePerWell?.SumDepthInterval; + sheet.Cell(rowСurrent, columnUseSubsystemPerWellKUsage).Value = subsystem.UsagePerWell?.KUsage; rowСurrent++; } diff --git a/AsbCloudInfrastructure/Services/DailyReport/DailyReportService.cs b/AsbCloudInfrastructure/Services/DailyReport/DailyReportService.cs index a55b8e91..ae8a3d7a 100644 --- a/AsbCloudInfrastructure/Services/DailyReport/DailyReportService.cs +++ b/AsbCloudInfrastructure/Services/DailyReport/DailyReportService.cs @@ -296,39 +296,30 @@ public class DailyReportService : IDailyReportService async Task> GetSubsystemsAsync() { - var subsystems = new List(); + var subsystemOperationTimesPerWell = await subsystemOperationTimeService.GetStatAsync(new SubsystemOperationTimeRequest + { + IdWell = dailyReport.IdWell + }, cancellationToken); - var statSubsystemOperationTimePerDay = (await subsystemOperationTimeService.GetStatAsync(new SubsystemOperationTimeRequest + var subsystemOperationTimesPerDay = await subsystemOperationTimeService.GetStatAsync(new SubsystemOperationTimeRequest { IdWell = dailyReport.IdWell, GtDate = dailyReport.Date, LtDate = dailyReport.Date.AddHours(24) - }, cancellationToken)).Select(s => - { - var subsystemRecord = s.Adapt(); - subsystemRecord.IdTimeInterval = 1; + }, cancellationToken); - return subsystemRecord; - }); - - var statSubsystemOperationTimePerWell = (await subsystemOperationTimeService.GetStatAsync(new SubsystemOperationTimeRequest - { - IdWell = dailyReport.IdWell - }, cancellationToken)).Select(s => - { - var subsystemRecord = s.Adapt(); - subsystemRecord.IdTimeInterval = 2; - - return subsystemRecord; - }); - - subsystems.AddRange(statSubsystemOperationTimePerDay); - subsystems.AddRange(statSubsystemOperationTimePerWell); + var subsystems = subsystemOperationTimesPerWell + .Select(subsystemOperationTime => new SubsystemRecordDto + { + Name = subsystemOperationTime.SubsystemName, + UsagePerDay = subsystemOperationTimesPerDay.FirstOrDefault(s => s.IdSubsystem == subsystemOperationTime.IdSubsystem)?.Adapt(), + UsagePerWell = subsystemOperationTime.Adapt() + }).ToList(); if (dailyReport.SubsystemBlock?.Subsystems != null && dailyReport.SubsystemBlock.Subsystems.Any()) subsystems.AddRange(dailyReport.SubsystemBlock.Subsystems); - return subsystems.OrderBy(s => s.SubsystemName); + return subsystems.OrderBy(s => s.Name); } } diff --git a/AsbCloudWebApi.Tests/Services/DailyReportServiceTest.cs b/AsbCloudWebApi.Tests/Services/DailyReportServiceTest.cs index 9b090d5b..54dd47db 100644 --- a/AsbCloudWebApi.Tests/Services/DailyReportServiceTest.cs +++ b/AsbCloudWebApi.Tests/Services/DailyReportServiceTest.cs @@ -42,11 +42,19 @@ public class DailyReportServiceTest { new SubsystemRecordDto { - SubsystemName = "АвтоСПО", - IdTimeInterval = 2, - UsedTimeHours = 24, - SumDepthInterval = 1500, - KUsage = 100 + Name = "АвтоСПО", + UsagePerDay = new SubsystemParametersDto + { + UsedTimeHours = 24, + SumDepthInterval = 1500, + KUsage = 15 + }, + UsagePerWell = new SubsystemParametersDto + { + UsedTimeHours = 500, + SumDepthInterval = 3000, + KUsage = 100 + } } } }; @@ -182,7 +190,7 @@ public class DailyReportServiceTest } }; - private readonly SubsystemStatDto fakeStatSubsystemOperationTimePerDay = new() + private readonly SubsystemStatDto fakeStatSubsystemOperationTime = new() { SubsystemName = "АПД", SumDepthInterval = 250, @@ -258,7 +266,7 @@ public class DailyReportServiceTest .ReturnsForAnyArgs(fakeWellOperationSlipsTime); subsystemOperationTimeServiceMock.GetStatAsync(Arg.Any(), Arg.Any()) - .ReturnsForAnyArgs(new[] { fakeStatSubsystemOperationTimePerDay }); + .ReturnsForAnyArgs(new[] { fakeStatSubsystemOperationTime }); scheduleRepositoryMock.GetAsync(idWell, dateDailyReport, Arg.Any()) .ReturnsForAnyArgs(new[] { fakeShedule }); @@ -453,23 +461,29 @@ public class DailyReportServiceTest //assert Assert.NotNull(result.SubsystemBlock); - Assert.Equal(3, result.SubsystemBlock?.Subsystems.Count()); + Assert.Equal(2, result.SubsystemBlock?.Subsystems.Count()); var subsystemRecord0 = result.SubsystemBlock?.Subsystems.ElementAt(0); - Assert.Equal("АвтоСПО", subsystemRecord0?.SubsystemName); - Assert.Equal(2, subsystemRecord0?.IdTimeInterval); - Assert.Equal(24, subsystemRecord0?.UsedTimeHours); - Assert.Equal(1500, subsystemRecord0?.SumDepthInterval); - Assert.Equal(100, subsystemRecord0?.KUsage); + Assert.Equal("АвтоСПО", subsystemRecord0?.Name); + Assert.Equal(24, subsystemRecord0?.UsagePerDay?.UsedTimeHours); + Assert.Equal(1500, subsystemRecord0?.UsagePerDay?.SumDepthInterval); + Assert.Equal(15, subsystemRecord0?.UsagePerDay?.KUsage); + Assert.Equal(500, subsystemRecord0?.UsagePerWell?.UsedTimeHours); + Assert.Equal(3000, subsystemRecord0?.UsagePerWell?.SumDepthInterval); + Assert.Equal(100, subsystemRecord0?.UsagePerWell?.KUsage); + var subsystemRecord1 = result.SubsystemBlock?.Subsystems.ElementAt(1); - Assert.Equal(fakeStatSubsystemOperationTimePerDay.SubsystemName, subsystemRecord1?.SubsystemName); - Assert.Equal(1, subsystemRecord1?.IdTimeInterval); - Assert.Equal(fakeStatSubsystemOperationTimePerDay.UsedTimeHours, subsystemRecord1?.UsedTimeHours); - Assert.Equal(fakeStatSubsystemOperationTimePerDay.SumDepthInterval, subsystemRecord1?.SumDepthInterval); - Assert.Equal(fakeStatSubsystemOperationTimePerDay.KUsage, subsystemRecord1?.KUsage); + Assert.Equal("АПД", subsystemRecord1?.Name); + Assert.Equal(200, subsystemRecord1?.UsagePerDay?.UsedTimeHours); + Assert.Equal(250, subsystemRecord1?.UsagePerDay?.SumDepthInterval); + Assert.Equal(30, subsystemRecord1?.UsagePerDay?.KUsage); + + Assert.Equal(200, subsystemRecord1?.UsagePerWell?.UsedTimeHours); + Assert.Equal(250, subsystemRecord1?.UsagePerWell?.SumDepthInterval); + Assert.Equal(30, subsystemRecord1?.UsagePerWell?.KUsage); } [Fact] diff --git a/AsbCloudWebApi/Controllers/DailyReportController.cs b/AsbCloudWebApi/Controllers/DailyReportController.cs index 4ff80ad7..93d2fbe3 100644 --- a/AsbCloudWebApi/Controllers/DailyReportController.cs +++ b/AsbCloudWebApi/Controllers/DailyReportController.cs @@ -89,7 +89,7 @@ public class DailyReportController : ControllerBase { var validSubsystemNames = new[] { "АвтоСПО", "Автопроработка" }; - if (subsystemBlock.Subsystems.Any(m => !validSubsystemNames.Contains(m.SubsystemName))) + if (subsystemBlock.Subsystems.Any(m => !validSubsystemNames.Contains(m.Name))) throw new ArgumentInvalidException($"Возможно добавить подсистемы с именами {string.Join(", ", validSubsystemNames)}", nameof(subsystemBlock.Subsystems));