Изменения блока с наработкой подсистем

This commit is contained in:
Степанов Дмитрий 2023-11-15 17:23:17 +05:00
parent 3eeaa2b9eb
commit cc4ef55c12
8 changed files with 100 additions and 86 deletions

View File

@ -0,0 +1,25 @@
using System.ComponentModel.DataAnnotations;
namespace AsbCloudApp.Data.DailyReport.Blocks.Subsystems;
/// <summary>
/// Параметры наработки подсистемы
/// </summary>
public class SubsystemParametersDto
{
/// <summary>
/// Сумма изменения глубин при включенной подсистеме
/// </summary>
public double? SumDepthInterval { get; set; }
/// <summary>
/// Наработка подсистемы
/// </summary>
public double? UsedTimeHours { get; set; }
/// <summary>
/// Коэффициент использования
/// </summary>
[Range(0, 1)]
public double? KUsage { get; set; }
}

View File

@ -1,5 +1,3 @@
using System.ComponentModel.DataAnnotations;
namespace AsbCloudApp.Data.DailyReport.Blocks.Subsystems; namespace AsbCloudApp.Data.DailyReport.Blocks.Subsystems;
/// <summary> /// <summary>
@ -10,29 +8,15 @@ public class SubsystemRecordDto
/// <summary> /// <summary>
/// Название подсистемы /// Название подсистемы
/// </summary> /// </summary>
public string SubsystemName { get; set; } = null!; public string Name { get; set; } = null!;
/// <summary>
/// Идентификатор временного интервала
/// 1 - за сутки
/// 2 - за скважину
/// </summary>
[Range(1, 2)]
public int IdTimeInterval { get; set; }
/// <summary> /// <summary>
/// Сумма изменения глубин при включеной подсистеме /// Использование подсистемы за сутки
/// </summary> /// </summary>
public double? SumDepthInterval { get; set; } public SubsystemParametersDto? UsagePerDay { get; set; }
/// <summary> /// <summary>
/// Наработка подсистемы /// Использование подсистемы за скважину
/// </summary> /// </summary>
public double? UsedTimeHours { get; set; } public SubsystemParametersDto? UsagePerWell { get; set; }
/// <summary>
/// Коэффициент использования
/// </summary>
[Range(0, 100)]
public double? KUsage { get; set; }
} }

View File

@ -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; }
}

View File

@ -2,13 +2,9 @@ namespace AsbCloudDb.Model.DailyReports.Blocks.Subsystem;
public class SubsystemRecord public class SubsystemRecord
{ {
public string SubsystemName { get; set; } = null!; public string Name { get; set; } = null!;
public int IdTimeInterval { get; set; } public SubsystemParameters? UsagePerDay { get; set; }
public double? SumDepthInterval { get; set; } public SubsystemParameters? UsagePerWell { get; set; }
public double? UsedTimeHours { get; set; }
public double? KUsage { get; set; }
} }

View File

@ -25,7 +25,7 @@ public class DailyReportExportService : IDailyReportExportService
private const int rowStartProcessMapWellDrillingBlock = 68; private const int rowStartProcessMapWellDrillingBlock = 68;
private const int columnTimeBalanceDurationPlan = 3; private const int columnTimeBalanceDurationPlan = 3;
private const int columnTimeBalanceDurationFact = 4; private const int columnTimeBalanceDurationFact = 6;
private const int columnTimeBalanceReasonDeviation = 8; private const int columnTimeBalanceReasonDeviation = 8;
private const int columnTimeBalanceDrillingDeviationPerSection = 10; private const int columnTimeBalanceDrillingDeviationPerSection = 10;
private const int columnTimeBalanceDrillingDeviationPerDay = 11; private const int columnTimeBalanceDrillingDeviationPerDay = 11;
@ -179,25 +179,19 @@ public class DailyReportExportService : IDailyReportExportService
private static void AddSubsystemBlockToSheet(IXLWorksheet sheet, SubsystemBlockDto subsystemBlock) private static void AddSubsystemBlockToSheet(IXLWorksheet sheet, SubsystemBlockDto subsystemBlock)
{ {
var groupedSubsystems = subsystemBlock.Subsystems.OrderBy(m => m.SubsystemName)
.GroupBy(m => m.SubsystemName);
var rowСurrent = rowStartSubsystemBlock; var rowСurrent = rowStartSubsystemBlock;
foreach (var groupedModule in groupedSubsystems) foreach (var subsystem in subsystemBlock.Subsystems)
{ {
var useSubsystemPerDay = groupedModule.FirstOrDefault(m => m.IdTimeInterval == 1); sheet.Cell(rowСurrent, columnSubsystemName).Value = subsystem.Name;
var useSubsystemPerWell = groupedModule.FirstOrDefault(m => m.IdTimeInterval == 2);
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, columnUseSubsystemPerWellUsedTimeHours).Value = subsystem.UsagePerWell?.UsedTimeHours;
sheet.Cell(rowСurrent, columnUseSubsystemPerDaySumDepthInterval).Value = useSubsystemPerDay?.SumDepthInterval; sheet.Cell(rowСurrent, columnUseSubsystemPerWellSumDepthInterval).Value = subsystem.UsagePerWell?.SumDepthInterval;
sheet.Cell(rowСurrent, columnUseSubsystemPerDayKUsage).Value = useSubsystemPerDay?.KUsage; sheet.Cell(rowСurrent, columnUseSubsystemPerWellKUsage).Value = subsystem.UsagePerWell?.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;
rowСurrent++; rowСurrent++;
} }

View File

@ -296,39 +296,30 @@ public class DailyReportService : IDailyReportService
async Task<IEnumerable<SubsystemRecordDto>> GetSubsystemsAsync() async Task<IEnumerable<SubsystemRecordDto>> GetSubsystemsAsync()
{ {
var subsystems = new List<SubsystemRecordDto>(); 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, IdWell = dailyReport.IdWell,
GtDate = dailyReport.Date, GtDate = dailyReport.Date,
LtDate = dailyReport.Date.AddHours(24) LtDate = dailyReport.Date.AddHours(24)
}, cancellationToken)).Select(s => }, cancellationToken);
{
var subsystemRecord = s.Adapt<SubsystemRecordDto>();
subsystemRecord.IdTimeInterval = 1;
return subsystemRecord; var subsystems = subsystemOperationTimesPerWell
}); .Select(subsystemOperationTime => new SubsystemRecordDto
{
var statSubsystemOperationTimePerWell = (await subsystemOperationTimeService.GetStatAsync(new SubsystemOperationTimeRequest Name = subsystemOperationTime.SubsystemName,
{ UsagePerDay = subsystemOperationTimesPerDay.FirstOrDefault(s => s.IdSubsystem == subsystemOperationTime.IdSubsystem)?.Adapt<SubsystemParametersDto>(),
IdWell = dailyReport.IdWell UsagePerWell = subsystemOperationTime.Adapt<SubsystemParametersDto>()
}, cancellationToken)).Select(s => }).ToList();
{
var subsystemRecord = s.Adapt<SubsystemRecordDto>();
subsystemRecord.IdTimeInterval = 2;
return subsystemRecord;
});
subsystems.AddRange(statSubsystemOperationTimePerDay);
subsystems.AddRange(statSubsystemOperationTimePerWell);
if (dailyReport.SubsystemBlock?.Subsystems != null && dailyReport.SubsystemBlock.Subsystems.Any()) if (dailyReport.SubsystemBlock?.Subsystems != null && dailyReport.SubsystemBlock.Subsystems.Any())
subsystems.AddRange(dailyReport.SubsystemBlock.Subsystems); subsystems.AddRange(dailyReport.SubsystemBlock.Subsystems);
return subsystems.OrderBy(s => s.SubsystemName); return subsystems.OrderBy(s => s.Name);
} }
} }

View File

@ -42,11 +42,19 @@ public class DailyReportServiceTest
{ {
new SubsystemRecordDto new SubsystemRecordDto
{ {
SubsystemName = "АвтоСПО", Name = "АвтоСПО",
IdTimeInterval = 2, UsagePerDay = new SubsystemParametersDto
UsedTimeHours = 24, {
SumDepthInterval = 1500, UsedTimeHours = 24,
KUsage = 100 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 = "АПД", SubsystemName = "АПД",
SumDepthInterval = 250, SumDepthInterval = 250,
@ -258,7 +266,7 @@ public class DailyReportServiceTest
.ReturnsForAnyArgs(fakeWellOperationSlipsTime); .ReturnsForAnyArgs(fakeWellOperationSlipsTime);
subsystemOperationTimeServiceMock.GetStatAsync(Arg.Any<SubsystemOperationTimeRequest>(), Arg.Any<CancellationToken>()) subsystemOperationTimeServiceMock.GetStatAsync(Arg.Any<SubsystemOperationTimeRequest>(), Arg.Any<CancellationToken>())
.ReturnsForAnyArgs(new[] { fakeStatSubsystemOperationTimePerDay }); .ReturnsForAnyArgs(new[] { fakeStatSubsystemOperationTime });
scheduleRepositoryMock.GetAsync(idWell, dateDailyReport, Arg.Any<CancellationToken>()) scheduleRepositoryMock.GetAsync(idWell, dateDailyReport, Arg.Any<CancellationToken>())
.ReturnsForAnyArgs(new[] { fakeShedule }); .ReturnsForAnyArgs(new[] { fakeShedule });
@ -453,23 +461,29 @@ public class DailyReportServiceTest
//assert //assert
Assert.NotNull(result.SubsystemBlock); 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); var subsystemRecord0 = result.SubsystemBlock?.Subsystems.ElementAt(0);
Assert.Equal("АвтоСПО", subsystemRecord0?.SubsystemName); Assert.Equal("АвтоСПО", subsystemRecord0?.Name);
Assert.Equal(2, subsystemRecord0?.IdTimeInterval); Assert.Equal(24, subsystemRecord0?.UsagePerDay?.UsedTimeHours);
Assert.Equal(24, subsystemRecord0?.UsedTimeHours); Assert.Equal(1500, subsystemRecord0?.UsagePerDay?.SumDepthInterval);
Assert.Equal(1500, subsystemRecord0?.SumDepthInterval); Assert.Equal(15, subsystemRecord0?.UsagePerDay?.KUsage);
Assert.Equal(100, subsystemRecord0?.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); var subsystemRecord1 = result.SubsystemBlock?.Subsystems.ElementAt(1);
Assert.Equal(fakeStatSubsystemOperationTimePerDay.SubsystemName, subsystemRecord1?.SubsystemName); Assert.Equal("АПД", subsystemRecord1?.Name);
Assert.Equal(1, subsystemRecord1?.IdTimeInterval); Assert.Equal(200, subsystemRecord1?.UsagePerDay?.UsedTimeHours);
Assert.Equal(fakeStatSubsystemOperationTimePerDay.UsedTimeHours, subsystemRecord1?.UsedTimeHours); Assert.Equal(250, subsystemRecord1?.UsagePerDay?.SumDepthInterval);
Assert.Equal(fakeStatSubsystemOperationTimePerDay.SumDepthInterval, subsystemRecord1?.SumDepthInterval); Assert.Equal(30, subsystemRecord1?.UsagePerDay?.KUsage);
Assert.Equal(fakeStatSubsystemOperationTimePerDay.KUsage, subsystemRecord1?.KUsage);
Assert.Equal(200, subsystemRecord1?.UsagePerWell?.UsedTimeHours);
Assert.Equal(250, subsystemRecord1?.UsagePerWell?.SumDepthInterval);
Assert.Equal(30, subsystemRecord1?.UsagePerWell?.KUsage);
} }
[Fact] [Fact]

View File

@ -89,7 +89,7 @@ public class DailyReportController : ControllerBase
{ {
var validSubsystemNames = new[] { "АвтоСПО", "Автопроработка" }; 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)}", throw new ArgumentInvalidException($"Возможно добавить подсистемы с именами {string.Join(", ", validSubsystemNames)}",
nameof(subsystemBlock.Subsystems)); nameof(subsystemBlock.Subsystems));