Правка по результатам ревью

This commit is contained in:
Olga Nemt 2024-04-17 11:10:56 +05:00
parent 9ead473975
commit cb54d40774
3 changed files with 51 additions and 36 deletions

View File

@ -16,11 +16,11 @@ namespace AsbCloudApp.Data
/// <summary>
/// Список операций композитной скважины
/// </summary>
public List<WellOperationDto> WellOperationsComposite { get; set; } = new();
public IEnumerable<WellOperationDto> WellOperationsComposite { get; set; } = null!;
/// <summary>
/// Список операций, сгруппированный по скважинам
/// Список операций, на основе которых были рассчитаны операции по композитной скважине
/// </summary>
public Dictionary<int, WellOperationDto[]> WellOperationsGroupedByWell { get; set; } = new();
public IEnumerable<WellCompositeOperationSourceDto> WellCompositeSourceOperations { get; set; } = null!;
}
}

View File

@ -1,23 +1,24 @@
using AsbCloudApp.Data;
using AsbCloudApp.Data.WellOperation;
using AsbCloudApp.Repositories;
using AsbCloudApp.Requests;
using AsbCloudApp.Services;
using AsbCloudDb.Model;
using Mapster;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using AsbCloudApp.Data.WellOperation;
using Mapster;
namespace AsbCloudInfrastructure.Services
{
public class WellCompositeOperationService : IWellCompositeOperationService
{
private ICrudRepository<WellSectionTypeDto> wellSectionTypeRepository;
private IWellOperationCategoryRepository wellOperationCategoryRepository;
private IWellOperationRepository wellOperationRepository;
private readonly ICrudRepository<WellSectionTypeDto> wellSectionTypeRepository;
private readonly IWellOperationCategoryRepository wellOperationCategoryRepository;
private readonly IWellOperationRepository wellOperationRepository;
private readonly IWellService wellService;
/// <summary>
/// Тип секции "Транспортный стол"
@ -128,11 +129,13 @@ namespace AsbCloudInfrastructure.Services
public WellCompositeOperationService(
ICrudRepository<WellSectionTypeDto> wellSectionTypeRepository,
IWellOperationCategoryRepository wellOperationCategoryRepository,
IWellOperationRepository wellOperationRepository)
IWellOperationRepository wellOperationRepository,
IWellService wellService)
{
this.wellSectionTypeRepository = wellSectionTypeRepository;
this.wellOperationCategoryRepository = wellOperationCategoryRepository;
this.wellOperationRepository = wellOperationRepository;
this.wellService = wellService;
}
public async Task<WellCompositeOperationDto> GetAsync(IEnumerable<int> idsWells, CancellationToken token)
@ -143,6 +146,9 @@ namespace AsbCloudInfrastructure.Services
var categories = wellOperationCategoryRepository.Get(true);
var categoriesDict = categories.ToDictionary(s => s.Id, s => s.Name);
var wells = await wellService.GetAsync(new WellRequest { Ids = idsWells }, token);
var wellsDict = wells.ToDictionary(w => w.Id, w => w.Caption);
var idsWellSectionTypes = WellSectionTypesWithCategories.Select(t => t.IdSectionType).Distinct();
var usedCategories = WellSectionTypesWithCategories.Select(c => c.IdCategory).Distinct();
@ -158,9 +164,10 @@ namespace AsbCloudInfrastructure.Services
var wellOperationsWithComposite = new List<Dictionary<int, WellOperationDto>>();
var compositeDepth = 0d;
var compositeDay = 0d;
var result = new WellCompositeOperationDto();
var prevDay = 0.0;
var compositeOperations = new List<WellOperationDto>();
foreach ((int IdSection, int IdCategory) in WellSectionTypesWithCategories)
{
var filteredByTemplate = operationsForComposite
@ -188,22 +195,32 @@ namespace AsbCloudInfrastructure.Services
.First();
compositeOperation.IdWell = 0;
compositeOperation.Day = prevDay + compositeOperation.DurationHours;
compositeOperation.Day = compositeDay + compositeOperation.DurationHours;
if (compositeDepth > compositeOperation.DepthStart)
compositeOperation.DepthStart = compositeDepth;
compositeOperations.Add(compositeOperation);
compositeDepth = compositeOperation.DepthStart;
result.WellOperationsComposite.Add(compositeOperation);
prevDay = compositeOperation.Day;
compositeDay = compositeOperation.Day;
}
var groupedByWellOperations = operations
.GroupBy(o => o.IdWell)
.ToDictionary(o => o.Key, o => o.ToArray());
result.WellOperationsGroupedByWell = groupedByWellOperations;
.ToDictionary(o => o.Key, o => o.ToArray())
.Select(o => new WellCompositeOperationSourceDto()
{
Operations = o.Value,
Well = new WellDto()
{
Id = o.Key,
Caption = wellsDict.TryGetValue(o.Key, out string? caption) ? caption : string.Empty,
}
});
result.WellOperationsComposite = compositeOperations;
result.WellCompositeSourceOperations = groupedByWellOperations;
return result;
}

View File

@ -1,22 +1,16 @@
using AsbCloudApp.Requests;
using AsbCloudDb.Model;
using AsbCloudInfrastructure.Repository;
using AsbCloudInfrastructure.Services.ProcessMaps.Report;
using AsbCloudApp.Data;
using AsbCloudApp.Data.WellOperation;
using AsbCloudApp.Repositories;
using AsbCloudApp.Requests;
using AsbCloudApp.Services;
using AsbCloudInfrastructure.Services;
using NSubstitute;
using ProtoBuf.Meta;
using SignalRSwaggerGen.Enums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Xunit;
using AsbCloudApp.Repositories;
using AsbCloudApp.Data;
using AsbCloudApp.Data.WellOperation;
using AsbCloudApp.Services;
namespace AsbCloudWebApi.Tests.Services.WellCompositeOperation
{
@ -30,8 +24,10 @@ namespace AsbCloudWebApi.Tests.Services.WellCompositeOperation
= Substitute.For<IWellOperationCategoryRepository>();
private IWellOperationRepository wellOperationRepository
= Substitute.For<IWellOperationRepository>();
private IWellService wellService
= Substitute.For<IWellService>();
private readonly static IEnumerable<WellOperationCategoryDto> operationCategories = new List<WellOperationCategoryDto>()
{
@ -61,7 +57,7 @@ namespace AsbCloudWebApi.Tests.Services.WellCompositeOperation
IdWell = 55,
IdWellSectionType = 2,
OperationCategoryName = "Шаблонирование перед спуском",
WellSectionTypeCaption = "Направление"
WellSectionTypeCaption = "Направление"
},
new()
{
@ -167,9 +163,10 @@ namespace AsbCloudWebApi.Tests.Services.WellCompositeOperation
.Returns(operationCategories);
service = new WellCompositeOperationService(
wellSectionTypeRepository,
wellSectionTypeRepository,
wellOperationCategoryRepository,
wellOperationRepository);
wellOperationRepository,
wellService);
}
/// <summary>
@ -185,7 +182,7 @@ namespace AsbCloudWebApi.Tests.Services.WellCompositeOperation
wellOperationRepository.GetAsync(Arg.Any<WellOperationRequest>(), Arg.Any<CancellationToken>())
.Returns(wellOperations1);
var idsWell = new List<int>() { 55, 64 };
var idsWell = new List<int>() { 55, 64 };
// act
var result = await service.GetAsync(idsWell, CancellationToken.None);
@ -221,7 +218,7 @@ namespace AsbCloudWebApi.Tests.Services.WellCompositeOperation
// assert
var compositeWellOperations = result.WellOperationsComposite;
Assert.Single (compositeWellOperations);
Assert.Single(compositeWellOperations);
Assert.Equal(5003, compositeWellOperations.FirstOrDefault()!.IdCategory);
Assert.Equal(1.5, compositeWellOperations.FirstOrDefault()!.DurationHours);
Assert.Equal(10, compositeWellOperations.FirstOrDefault()!.DepthStart);
@ -306,7 +303,8 @@ namespace AsbCloudWebApi.Tests.Services.WellCompositeOperation
var result = await service.GetAsync(idsWell, CancellationToken.None);
// assert
var wellOperationsCount = result.WellOperationsGroupedByWell.SelectMany(v => v.Value).Count();
var wellOperationsCount = result.WellCompositeSourceOperations
.SelectMany(o => o.Operations).Count();
Assert.Equal(wellOperations.Count(), wellOperationsCount);
var lastOperationComposite = result.WellOperationsComposite.Last();