forked from ddrilling/AsbCloudServer
Сервис РТК
This commit is contained in:
parent
625e977b1a
commit
a9c8fa98ab
21
AsbCloudApp/Services/ProcessMaps/IProcessMapPlanService.cs
Normal file
21
AsbCloudApp/Services/ProcessMaps/IProcessMapPlanService.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using AsbCloudApp.Data.ProcessMaps;
|
||||
|
||||
namespace AsbCloudApp.Services.ProcessMaps;
|
||||
|
||||
/// <summary>
|
||||
/// РТК
|
||||
/// </summary>
|
||||
public interface IProcessMapPlanService<T>
|
||||
where T : ProcessMapPlanBaseDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Получение РТК по скважине
|
||||
/// </summary>
|
||||
/// <param name="idWell"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<IEnumerable<ValidationResultDto<T>>> GetAsync(int idWell, CancellationToken cancellationToken);
|
||||
}
|
25
AsbCloudApp/Services/ValidationResultDto.cs
Normal file
25
AsbCloudApp/Services/ValidationResultDto.cs
Normal file
@ -0,0 +1,25 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AsbCloudApp.Services;
|
||||
|
||||
/// <summary>
|
||||
/// Результат валидации объекта
|
||||
/// </summary>
|
||||
public class ValidationResultDto<T>
|
||||
where T : class
|
||||
{
|
||||
/// <summary>
|
||||
/// Флаг валидности
|
||||
/// </summary>
|
||||
public bool IsValid { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Объект валидации
|
||||
/// </summary>
|
||||
public T Item { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Предупреждения
|
||||
/// </summary>
|
||||
public IEnumerable<string>? Warnings { get; set; }
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Data.ProcessMaps;
|
||||
using AsbCloudApp.Data.WellSections;
|
||||
using AsbCloudApp.Repositories;
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudApp.Services.ProcessMaps;
|
||||
|
||||
namespace AsbCloudInfrastructure.Services.ProcessMaps;
|
||||
|
||||
public class ProcessMapPlanService<T> : IProcessMapPlanService<T>
|
||||
where T : ProcessMapPlanBaseDto
|
||||
{
|
||||
private readonly ICrudRepository<WellSectionTypeDto> wellSectionTypeRepository;
|
||||
private readonly IProcessMapPlanRepository<T> processMapPlanRepository;
|
||||
private readonly IRepositoryWellRelated<WellSectionPlanDto> wellSectionPlanRepository;
|
||||
|
||||
public ProcessMapPlanService(ICrudRepository<WellSectionTypeDto> wellSectionTypeRepository,
|
||||
IProcessMapPlanRepository<T> processMapPlanRepository,
|
||||
IRepositoryWellRelated<WellSectionPlanDto> wellSectionPlanRepository)
|
||||
{
|
||||
this.wellSectionTypeRepository = wellSectionTypeRepository;
|
||||
this.processMapPlanRepository = processMapPlanRepository;
|
||||
this.wellSectionPlanRepository = wellSectionPlanRepository;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<ValidationResultDto<T>>> GetAsync(int idWell, CancellationToken cancellationToken)
|
||||
{
|
||||
var wellSectionTypes = await wellSectionTypeRepository.GetAllAsync(cancellationToken);
|
||||
|
||||
var planProcessMaps = await processMapPlanRepository.GetByIdWellAsync(idWell, cancellationToken);
|
||||
|
||||
var planWellSections = await wellSectionPlanRepository.GetByIdWellAsync(idWell, cancellationToken);
|
||||
|
||||
return planProcessMaps.Select(processMapPlan =>
|
||||
{
|
||||
var planWellSection = planWellSections.SingleOrDefault(s => s.IdSectionType == processMapPlan.IdWellSectionType);
|
||||
|
||||
var isValid = planWellSection is not null && planWellSection.DepthStart <= processMapPlan.DepthStart &&
|
||||
planWellSection.DepthEnd >= processMapPlan.DepthEnd;
|
||||
|
||||
var validationResult = new ValidationResultDto<T>
|
||||
{
|
||||
IsValid = isValid,
|
||||
Item = processMapPlan
|
||||
};
|
||||
|
||||
if (isValid)
|
||||
return validationResult;
|
||||
|
||||
var wellSectionType = wellSectionTypes.SingleOrDefault(s => s.Id == processMapPlan.IdWellSectionType);
|
||||
|
||||
validationResult.Warnings = new[]
|
||||
{
|
||||
$"Конструкция секции: {wellSectionType?.Caption}; Интервал бурения от {processMapPlan.DepthStart} до {processMapPlan.DepthEnd} не совпадает с данными указанными на странице Конструкция скважины / План"
|
||||
};
|
||||
|
||||
return validationResult;
|
||||
});
|
||||
}
|
||||
}
|
@ -0,0 +1,95 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Data.ProcessMaps;
|
||||
using AsbCloudApp.Data.WellSections;
|
||||
using AsbCloudApp.Repositories;
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudInfrastructure.Services.ProcessMaps;
|
||||
using NSubstitute;
|
||||
using Xunit;
|
||||
|
||||
namespace AsbCloudWebApi.Tests.UnitTests.Services.ProcessMaps;
|
||||
|
||||
public class ProcessMapPlanServiceTests
|
||||
{
|
||||
private const int idWellSectionPlan = 1;
|
||||
private const int idWell = 3;
|
||||
private const int idWellSectionType = 54;
|
||||
|
||||
private readonly IEnumerable<WellSectionPlanDto> fakeCollectionWellSectionPlan = new WellSectionPlanDto[]
|
||||
{
|
||||
new()
|
||||
{
|
||||
Id = idWellSectionPlan,
|
||||
IdWell = idWell,
|
||||
IdSectionType = idWellSectionType,
|
||||
DepthStart = 80,
|
||||
DepthEnd = 150
|
||||
}
|
||||
};
|
||||
|
||||
private readonly IEnumerable<WellSectionTypeDto> fakeCollectionWellSectionTypes = new WellSectionTypeDto[]
|
||||
{
|
||||
new()
|
||||
{
|
||||
Id = idWellSectionType,
|
||||
Caption = "Направление 1",
|
||||
Order = 1
|
||||
}
|
||||
};
|
||||
|
||||
private readonly ICrudRepository<WellSectionTypeDto> wellSectionTypeRepositoryMock =
|
||||
Substitute.For<ICrudRepository<WellSectionTypeDto>>();
|
||||
|
||||
private readonly IProcessMapPlanRepository<ProcessMapPlanWellDrillingDto> processMapPlanRepositoryMock =
|
||||
Substitute.For<IProcessMapPlanRepository<ProcessMapPlanWellDrillingDto>>();
|
||||
|
||||
private readonly IRepositoryWellRelated<WellSectionPlanDto> wellSectionPlanRepositoryMock =
|
||||
Substitute.For<IRepositoryWellRelated<WellSectionPlanDto>>();
|
||||
|
||||
private readonly ProcessMapPlanService<ProcessMapPlanWellDrillingDto> processMapPlanService;
|
||||
|
||||
public ProcessMapPlanServiceTests()
|
||||
{
|
||||
processMapPlanService = new ProcessMapPlanService<ProcessMapPlanWellDrillingDto>(wellSectionTypeRepositoryMock,
|
||||
processMapPlanRepositoryMock, wellSectionPlanRepositoryMock);
|
||||
|
||||
wellSectionPlanRepositoryMock.GetByIdWellAsync(Arg.Any<int>(), Arg.Any<CancellationToken>())
|
||||
.ReturnsForAnyArgs(fakeCollectionWellSectionPlan);
|
||||
|
||||
wellSectionTypeRepositoryMock.GetAllAsync(Arg.Any<CancellationToken>())
|
||||
.ReturnsForAnyArgs(fakeCollectionWellSectionTypes);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(80, 150, true)]
|
||||
[InlineData(90, 140, true)]
|
||||
[InlineData(0, 110, false)]
|
||||
[InlineData(110, 200, false)]
|
||||
public async Task GetAsync_ReturnsValidatedCollectionProcessMapPlanWellDrilling(int depthStart, int depthEnd, bool isValidCollection)
|
||||
{
|
||||
//arrange
|
||||
var fakeCollectionProcessMapPlanWellDrilling = new ProcessMapPlanWellDrillingDto[]
|
||||
{
|
||||
new()
|
||||
{
|
||||
IdWellSectionType = idWellSectionType,
|
||||
DepthStart = depthStart,
|
||||
DepthEnd = depthEnd
|
||||
}
|
||||
};
|
||||
|
||||
processMapPlanRepositoryMock.GetByIdWellAsync(Arg.Any<int>(), Arg.Any<CancellationToken>())
|
||||
.ReturnsForAnyArgs(fakeCollectionProcessMapPlanWellDrilling);
|
||||
|
||||
//act
|
||||
var result = (await processMapPlanService.GetAsync(idWell, CancellationToken.None)).ToArray();
|
||||
|
||||
//assert
|
||||
Assert.Equal(isValidCollection, result.All(r => r.IsValid));
|
||||
Assert.Single(result);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user