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