forked from ddrilling/AsbCloudServer
64 lines
2.5 KiB
C#
64 lines
2.5 KiB
C#
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;
|
||
});
|
||
}
|
||
} |