DD.WellWorkover.Cloud/AsbCloudInfrastructure/Services/ProcessMaps/ProcessMapPlanService.cs

68 lines
3.0 KiB
C#
Raw Normal View History

using AsbCloudApp.Data;
using AsbCloudApp.Data.ProcessMaps;
using AsbCloudApp.Repositories;
using AsbCloudApp.Requests;
using AsbCloudApp.Services;
2023-12-04 17:09:58 +05:00
using System.Collections.Generic;
2023-12-13 18:06:48 +05:00
using System.ComponentModel.DataAnnotations;
2023-12-04 17:09:58 +05:00
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace AsbCloudInfrastructure.Services.ProcessMaps;
public class ProcessMapPlanService<T> : AsbCloudApp.Services.ProcessMaps.IProcessMapPlanService<T>
where T : AsbCloudApp.Data.ProcessMapPlan.ProcessMapPlanBaseDto
2023-12-04 17:09:58 +05:00
{
private readonly ICrudRepository<WellSectionTypeDto> wellSectionTypeRepository;
private readonly IChangeLogRepository<T, ProcessMapPlanBaseRequestWithWell> processMapPlanBaseRepository;
private readonly IRepositoryWellRelated<WellSectionPlanDto> wellSectionPlanRepository;
public ProcessMapPlanService(
ICrudRepository<WellSectionTypeDto> wellSectionTypeRepository,
IChangeLogRepository<T, ProcessMapPlanBaseRequestWithWell> processMapPlanBaseRepository,
IRepositoryWellRelated<WellSectionPlanDto> wellSectionPlanRepository)
{
this.wellSectionTypeRepository = wellSectionTypeRepository;
this.processMapPlanBaseRepository = processMapPlanBaseRepository;
this.wellSectionPlanRepository = wellSectionPlanRepository;
}
2023-12-04 17:09:58 +05:00
public async Task<IEnumerable<ValidationResultDto<T>>> GetAsync(int idWell, CancellationToken cancellationToken)
{
var wellSectionTypes = await wellSectionTypeRepository.GetAllAsync(cancellationToken);
2023-12-04 17:09:58 +05:00
var request = new ProcessMapPlanBaseRequestWithWell(idWell);
2023-12-04 17:09:58 +05:00
var processMapsPlan = await processMapPlanBaseRepository.Get(request, cancellationToken);
2023-12-04 17:09:58 +05:00
var wellSectionsPlan = await wellSectionPlanRepository.GetByIdWellAsync(idWell, cancellationToken);
2023-12-13 18:06:48 +05:00
return processMapsPlan.Select(processMapPlan =>
{
var wellSectionPlan = wellSectionsPlan.FirstOrDefault(s => s.IdSectionType == processMapPlan.IdWellSectionType);
2023-12-04 17:09:58 +05:00
var isValid = wellSectionPlan is not null && wellSectionPlan.DepthStart <= processMapPlan.DepthStart &&
wellSectionPlan.DepthEnd >= processMapPlan.DepthEnd;
2023-12-04 17:09:58 +05:00
var validationResult = new ValidationResultDto<T>
{
Item = processMapPlan
};
2023-12-04 17:09:58 +05:00
if (isValid)
return validationResult;
2023-12-13 18:06:48 +05:00
var wellSectionType = wellSectionTypes.FirstOrDefault(s => s.Id == processMapPlan.IdWellSectionType);
2023-12-13 18:06:48 +05:00
validationResult.Warnings = new ValidationResult[]
{
new($"Конструкция секции: {wellSectionType?.Caption}; " +
$"Интервал бурения от {processMapPlan.DepthStart} до {processMapPlan.DepthEnd} не совпадает с данными указанными на странице " +
$"Конструкция скважины / План", new[] { nameof(processMapPlan.DepthStart), nameof(processMapPlan.DepthEnd) })
};
2023-12-13 18:06:48 +05:00
return validationResult;
});
}
2023-12-04 17:09:58 +05:00
}