Удалена ProcessMapPlanWellDrillingDto

This commit is contained in:
Olga Nemt 2024-02-20 16:46:45 +05:00
parent 129ab9565f
commit f6ab09f77f
8 changed files with 154 additions and 320 deletions

View File

@ -1,61 +0,0 @@
using System;
using System.ComponentModel.DataAnnotations;
namespace AsbCloudApp.Data.ProcessMaps;
/// <inheritdoc/>
public abstract class ProcessMapPlanBaseDto : IId, IWellRelated
{
/// <inheritdoc/>
[Required]
public int Id { get; set; }
/// <summary>
/// Id скважины
/// </summary>
[Required]
[Range(1, int.MaxValue, ErrorMessage = "Id скважины не может быть меньше 1")]
public int IdWell { get; set; }
/// <summary>
/// Id пользователя
/// </summary>
public int IdUser { get; set; }
/// <summary>
/// Тип секции
/// </summary>
[Required]
[Range(1, int.MaxValue, ErrorMessage = "Id секции скважины не может быть меньше 1")]
public int IdWellSectionType { get; set; }
/// <summary>
/// Дата последнего изменения
/// </summary>
public DateTimeOffset LastUpdate { get; set; }
/// <summary>
/// Глубина по стволу от, м
/// <para>
/// на начало интервала
/// </para>
/// </summary>
[Required]
[Range(0, 99999.9, ErrorMessage = "Глубина не может быть отрицательной")]
public double DepthStart { get; set; }
/// <summary>
/// Глубина по стволу до, м
/// <para>
/// на конец интервала
/// </para>
/// </summary>
[Required]
[Range(0, 99999.9, ErrorMessage = "Глубина не может быть отрицательной")]
public double DepthEnd { get; set; }
/// <summary>
/// Комментарий
/// </summary>
public string? Comment { get; set; }
}

View File

@ -1,67 +0,0 @@
using System.ComponentModel.DataAnnotations;
namespace AsbCloudApp.Data.ProcessMaps;
/// <summary>
/// РТК план бурение скважины
/// </summary>
public class ProcessMapPlanWellDrillingDto : ProcessMapPlanBaseDto
{
/// <summary>
/// Id режима 0-ручной, 1-ротор, 2 - слайд
/// </summary>
[Required]
[Range(0, 2, ErrorMessage = "Id режима должен быть либо 0-ручной либо, 1-ротор либо 2-слайд")]
public int IdMode { get; set; }
/// <summary>
/// Нагрузка
/// </summary>
[Required]
public PlanLimitDto AxialLoad { get; set; } = null!;
/// <summary>
/// Перепад давления
/// </summary>
[Required]
public PlanLimitDto Pressure { get; set; } = null!;
/// <summary>
/// Момент на ВСП
/// </summary>
[Required]
public PlanLimitDto TopDriveTorque { get; set; } = null!;
/// <summary>
/// Обороты на ВСП
/// </summary>
[Required]
public PlanLimitDto TopDriveSpeed { get; set; } = null!;
/// <summary>
/// Расход
/// </summary>
[Required]
public PlanLimitDto Flow { get; set; } = null!;
/// <summary>
/// Плановая механическая скорость, м/ч
/// </summary>
[Required]
[Range(0, 99999.9, ErrorMessage = "Плановая механическая скорость должно быть в пределах от 0 до 99999.9")]
public double RopPlan { get; set; }
/// <summary>
/// Плановый процент использования АКБ
/// </summary>
[Required]
[Range(0, 100, ErrorMessage = "Процент использования АКБ должен быть в пределах от 0 до 100")]
public double UsageSaub { get; set; }
/// <summary>
/// Плановый процент использования spin master
/// </summary>
[Required]
[Range(0, 100, ErrorMessage = "Процент использования spin master должен быть в пределах от 0 до 100")]
public double UsageSpin { get; set; }
}

View File

@ -1,3 +1,4 @@
using AsbCloudApp.Data.ProcessMapPlan;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
@ -6,7 +7,7 @@ namespace AsbCloudApp.Data.ProcessMaps;
/// <summary>
/// РТК план проработка скважины
/// </summary>
public class ProcessMapPlanWellReamDto : AsbCloudApp.Data.ProcessMapPlan.ProcessMapPlanBaseDto, IValidatableObject
public class ProcessMapPlanWellReamDto : ProcessMapPlanBaseDto, IValidatableObject
{
/// <summary>
/// Количество повторений

View File

@ -2,6 +2,7 @@ using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using AsbCloudApp.Data;
using AsbCloudApp.Data.ProcessMapPlan;
namespace AsbCloudApp.Services.ProcessMaps;
@ -9,7 +10,7 @@ namespace AsbCloudApp.Services.ProcessMaps;
/// РТК
/// </summary>
public interface IProcessMapPlanService<T>
where T : AsbCloudApp.Data.ProcessMapPlan.ProcessMapPlanBaseDto
where T : ProcessMapPlanBaseDto
{
/// <summary>
/// Получение РТК план по скважине

View File

@ -101,48 +101,6 @@ namespace AsbCloudInfrastructure
.Ignore(dst => dst.NotificationCategory,
dst => dst.User);
TypeAdapterConfig.GlobalSettings.Default.Config
.ForType<ProcessMapWellDrilling, ProcessMapPlanWellDrillingDto>()
.Map(dest => dest.AxialLoad, src => new PlanLimitDto
{
LimitMax = src.AxialLoadLimitMax,
Plan = src.AxialLoadPlan
})
.Map(dest => dest.Flow, src => new PlanLimitDto
{
LimitMax = src.FlowLimitMax,
Plan = src.FlowPlan
})
.Map(dest => dest.Pressure, src => new PlanLimitDto
{
LimitMax = src.PressureLimitMax,
Plan = src.PressurePlan
})
.Map(dest => dest.TopDriveSpeed, src => new PlanLimitDto
{
LimitMax = src.TopDriveSpeedLimitMax,
Plan = src.TopDriveSpeedPlan
})
.Map(dest => dest.TopDriveTorque, src => new PlanLimitDto
{
LimitMax = src.TopDriveTorqueLimitMax,
Plan = src.TopDriveTorquePlan
});
TypeAdapterConfig.GlobalSettings.Default.Config
.ForType<ProcessMapPlanWellDrillingDto, ProcessMapWellDrilling>()
.Map(dest => dest.AxialLoadPlan, src => src.AxialLoad.Plan)
.Map(dest => dest.AxialLoadLimitMax, src => src.AxialLoad.LimitMax)
.Map(dest => dest.FlowPlan, src => src.Flow.Plan)
.Map(dest => dest.FlowLimitMax, src => src.Flow.LimitMax)
.Map(dest => dest.PressurePlan, src => src.Pressure.Plan)
.Map(dest => dest.PressureLimitMax, src => src.Pressure.LimitMax)
.Map(dest => dest.TopDriveSpeedPlan, src => src.TopDriveSpeed.Plan)
.Map(dest => dest.TopDriveSpeedLimitMax, src => src.TopDriveSpeed.LimitMax)
.Map(dest => dest.TopDriveTorquePlan, src => src.TopDriveTorque.Plan)
.Map(dest => dest.TopDriveTorqueLimitMax, src => src.TopDriveTorque.LimitMax);
TypeAdapterConfig.GlobalSettings.Default.Config
.ForType<TimeBalanceRecord, TimeBalanceRecordDto>()
.Map(dest => dest.DurationHours, src => new PlanFactDto<double?>()

View File

@ -1,4 +1,5 @@
using AsbCloudApp.Data;
using AsbCloudApp.Data.ProcessMapPlan;
using AsbCloudApp.Data.ProcessMaps;
using AsbCloudApp.Repositories;
using AsbCloudApp.Requests;
@ -12,7 +13,7 @@ using System.Threading.Tasks;
namespace AsbCloudInfrastructure.Services.ProcessMaps;
public class ProcessMapPlanService<T> : AsbCloudApp.Services.ProcessMaps.IProcessMapPlanService<T>
where T : AsbCloudApp.Data.ProcessMapPlan.ProcessMapPlanBaseDto
where T : ProcessMapPlanBaseDto
{
private readonly ICrudRepository<WellSectionTypeDto> wellSectionTypeRepository;
private readonly IChangeLogRepository<T, ProcessMapPlanBaseRequestWithWell> processMapPlanBaseRepository;

View File

@ -1,9 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using AsbCloudApp.Data;
using AsbCloudApp.Data.ProcessMapPlan;
using AsbCloudApp.Data.ProcessMaps;
using AsbCloudApp.Exceptions;
using AsbCloudApp.Repositories;
@ -11,6 +7,11 @@ using AsbCloudApp.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace AsbCloudWebApi.Controllers.ProcessMaps;
@ -22,167 +23,167 @@ namespace AsbCloudWebApi.Controllers.ProcessMaps;
[Authorize]
public class WellSectionPlanController : ControllerBase
{
private readonly IWellService wellService;
private readonly IWellSectionPlanRepository wellSectionPlanRepository;
private readonly ICrudRepository<WellSectionTypeDto> wellSectionRepository;
private readonly IWellService wellService;
private readonly IWellSectionPlanRepository wellSectionPlanRepository;
private readonly ICrudRepository<WellSectionTypeDto> wellSectionRepository;
public WellSectionPlanController(IWellService wellService,
IWellSectionPlanRepository wellSectionPlanRepository,
ICrudRepository<WellSectionTypeDto> wellSectionRepository)
{
this.wellService = wellService;
this.wellSectionPlanRepository = wellSectionPlanRepository;
this.wellSectionRepository = wellSectionRepository;
}
public WellSectionPlanController(IWellService wellService,
IWellSectionPlanRepository wellSectionPlanRepository,
ICrudRepository<WellSectionTypeDto> wellSectionRepository)
{
this.wellService = wellService;
this.wellSectionPlanRepository = wellSectionPlanRepository;
this.wellSectionRepository = wellSectionRepository;
}
//TODO: так же следует вынести в базовый контроллер
private int IdUser
{
get
{
var idUser = User.GetUserId();
//TODO: так же следует вынести в базовый контроллер
private int IdUser
{
get
{
var idUser = User.GetUserId();
if (!idUser.HasValue)
throw new ForbidException("Неизвестный пользователь");
if (!idUser.HasValue)
throw new ForbidException("Неизвестный пользователь");
return idUser.Value;
}
}
return idUser.Value;
}
}
/// <summary>
/// Добавить секцию
/// </summary>
/// <param name="idWell">Идентификатор скважины</param>
/// <param name="wellSection">Секция скважины - план</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpPost]
[Permission]
[ProducesResponseType(typeof(int), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
public async Task<IActionResult> InsertAsync(int idWell, WellSectionPlanDto wellSection, CancellationToken cancellationToken)
{
wellSection.IdWell = idWell;
wellSection.IdUser = IdUser;
await CheckIsExistsWellSectionTypeAsync(wellSection.IdSectionType, cancellationToken);
await AssertUserAccessToWell(idWell, cancellationToken);
/// <summary>
/// Добавить секцию
/// </summary>
/// <param name="idWell">Идентификатор скважины</param>
/// <param name="wellSection">Секция скважины - план</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpPost]
[Permission]
[ProducesResponseType(typeof(int), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
public async Task<IActionResult> InsertAsync(int idWell, WellSectionPlanDto wellSection, CancellationToken cancellationToken)
{
wellSection.IdWell = idWell;
wellSection.IdUser = IdUser;
var wellSectionId = await wellSectionPlanRepository.InsertAsync(wellSection, cancellationToken);
await CheckIsExistsWellSectionTypeAsync(wellSection.IdSectionType, cancellationToken);
return Ok(wellSectionId);
}
/// <summary>
/// Обновить секцию
/// </summary>
/// <param name="idWell">Идентификатор скважины</param>
/// <param name="wellSection">Секция скважины - план</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpPut]
[Permission]
[ProducesResponseType(typeof(int), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
public async Task<IActionResult> UpdateAsync(int idWell, WellSectionPlanDto wellSection, CancellationToken cancellationToken)
{
wellSection.IdWell = idWell;
wellSection.IdUser = IdUser;
wellSection.LastUpdateDate = DateTimeOffset.UtcNow;
await AssertUserAccessToWell(idWell, cancellationToken);
await CheckIsExistsWellSectionTypeAsync(wellSection.IdSectionType, cancellationToken);
await AssertUserAccessToWell(idWell, cancellationToken);
var wellSectionId = await wellSectionPlanRepository.InsertAsync(wellSection, cancellationToken);
var wellSectionId = await wellSectionPlanRepository.UpdateAsync(wellSection, cancellationToken);
return Ok(wellSectionId);
}
if (wellSectionId == ICrudRepository<WellSectionPlanDto>.ErrorIdNotFound)
return this.ValidationBadRequest(nameof(wellSection.Id), $"Секции скважины с Id: {wellSection.Id} не существует");
/// <summary>
/// Обновить секцию
/// </summary>
/// <param name="idWell">Идентификатор скважины</param>
/// <param name="wellSection">Секция скважины - план</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpPut]
[Permission]
[ProducesResponseType(typeof(int), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
public async Task<IActionResult> UpdateAsync(int idWell, WellSectionPlanDto wellSection, CancellationToken cancellationToken)
{
wellSection.IdWell = idWell;
wellSection.IdUser = IdUser;
wellSection.LastUpdateDate = DateTimeOffset.UtcNow;
return Ok(wellSectionId);
}
await CheckIsExistsWellSectionTypeAsync(wellSection.IdSectionType, cancellationToken);
/// <summary>
/// Получить типы секций
/// </summary>
/// <param name="idWell">Идентификатор скважины</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpGet("wellSectionTypes")]
[ProducesResponseType(typeof(IEnumerable<WellSectionTypeDto>), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
public async Task<IActionResult> GetWellSectionTypesAsync(int idWell, CancellationToken cancellationToken)
{
await AssertUserAccessToWell(idWell, cancellationToken);
await AssertUserAccessToWell(idWell, cancellationToken);
var wellSectionTypes = await wellSectionPlanRepository.GetWellSectionTypesAsync(idWell, cancellationToken);
var wellSectionId = await wellSectionPlanRepository.UpdateAsync(wellSection, cancellationToken);
if (!wellSectionTypes.Any())
return NoContent();
if (wellSectionId == ICrudRepository<WellSectionPlanDto>.ErrorIdNotFound)
return this.ValidationBadRequest(nameof(wellSection.Id), $"Секции скважины с Id: {wellSection.Id} не существует");
return Ok(wellSectionTypes);
}
return Ok(wellSectionId);
}
/// <summary>
/// Получить список секций
/// </summary>
/// <param name="idWell">Идентификатор скважины</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpGet]
[ProducesResponseType(typeof(IEnumerable<WellSectionPlanDto>), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
public async Task<IActionResult> GetPlanWellSectionsAsync(int idWell, CancellationToken cancellationToken)
{
await AssertUserAccessToWell(idWell, cancellationToken);
/// <summary>
/// Получить типы секций
/// </summary>
/// <param name="idWell">Идентификатор скважины</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpGet("wellSectionTypes")]
[ProducesResponseType(typeof(IEnumerable<WellSectionTypeDto>), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
public async Task<IActionResult> GetWellSectionTypesAsync(int idWell, CancellationToken cancellationToken)
{
await AssertUserAccessToWell(idWell, cancellationToken);
var planWellSections = await wellSectionPlanRepository.GetByIdWellAsync(idWell, cancellationToken);
if (!planWellSections.Any())
return NoContent();
var wellSectionTypes = await wellSectionPlanRepository.GetWellSectionTypesAsync(idWell, cancellationToken);
return Ok(planWellSections);
}
if (!wellSectionTypes.Any())
return NoContent();
/// <summary>
/// Удалить секцию
/// </summary>
/// <param name="idWell">Идентификатор скважины</param>
/// <param name="id">Идентификатор плановой секции</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpDelete]
[Permission]
[ProducesResponseType(typeof(int), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
public async Task<IActionResult> DeleteAsync(int idWell, int id, CancellationToken cancellationToken)
{
await AssertUserAccessToWell(idWell, cancellationToken);
return Ok(wellSectionTypes);
}
var deletedWellSectionPlanCount = await wellSectionPlanRepository.DeleteAsync(id, cancellationToken);
/// <summary>
/// Получить список секций
/// </summary>
/// <param name="idWell">Идентификатор скважины</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpGet]
[ProducesResponseType(typeof(IEnumerable<WellSectionPlanDto>), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
public async Task<IActionResult> GetPlanWellSectionsAsync(int idWell, CancellationToken cancellationToken)
{
await AssertUserAccessToWell(idWell, cancellationToken);
return Ok(deletedWellSectionPlanCount);
}
var planWellSections = await wellSectionPlanRepository.GetByIdWellAsync(idWell, cancellationToken);
//TODO: нужно создать базовый контроллер связанный со скважиной и вынести этот метод туда. Данный метод много где дублируется
private async Task AssertUserAccessToWell(int idWell, CancellationToken cancellationToken)
{
var idCompany = User.GetCompanyId();
if (!planWellSections.Any())
return NoContent();
if (!idCompany.HasValue || !await wellService.IsCompanyInvolvedInWellAsync(idCompany.Value, idWell, cancellationToken))
throw new ForbidException("Нет доступа к скважине");
}
return Ok(planWellSections);
}
//TODO: тоже нужно вынести в базовый контроллер
private async Task CheckIsExistsWellSectionTypeAsync(int idWellSectionType, CancellationToken cancellationToken)
{
_ = await wellSectionRepository.GetOrDefaultAsync(idWellSectionType, cancellationToken)
?? throw new ArgumentInvalidException(nameof(ProcessMapPlanWellDrillingDto.IdWellSectionType),
$"Тип секции с Id: {idWellSectionType} не найден");
}
/// <summary>
/// Удалить секцию
/// </summary>
/// <param name="idWell">Идентификатор скважины</param>
/// <param name="id">Идентификатор плановой секции</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpDelete]
[Permission]
[ProducesResponseType(typeof(int), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
public async Task<IActionResult> DeleteAsync(int idWell, int id, CancellationToken cancellationToken)
{
await AssertUserAccessToWell(idWell, cancellationToken);
var deletedWellSectionPlanCount = await wellSectionPlanRepository.DeleteAsync(id, cancellationToken);
return Ok(deletedWellSectionPlanCount);
}
//TODO: нужно создать базовый контроллер связанный со скважиной и вынести этот метод туда. Данный метод много где дублируется
private async Task AssertUserAccessToWell(int idWell, CancellationToken cancellationToken)
{
var idCompany = User.GetCompanyId();
if (!idCompany.HasValue || !await wellService.IsCompanyInvolvedInWellAsync(idCompany.Value, idWell, cancellationToken))
throw new ForbidException("Нет доступа к скважине");
}
//TODO: тоже нужно вынести в базовый контроллер
private async Task CheckIsExistsWellSectionTypeAsync(int idWellSectionType, CancellationToken cancellationToken)
{
_ = await wellSectionRepository.GetOrDefaultAsync(idWellSectionType, cancellationToken)
?? throw new ArgumentInvalidException(nameof(ProcessMapPlanDrillingDto.IdWellSectionType),
$"Тип секции с Id: {idWellSectionType} не найден");
}
}

View File

@ -1,4 +1,5 @@
using AsbCloudApp.Data;
using AsbCloudApp.Data.ProcessMapPlan;
using AsbCloudApp.Repositories;
using AsbCloudApp.Services;
using Microsoft.AspNetCore.Authorization;
@ -6,7 +7,6 @@ using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using AsbCloudApp.Data.ProcessMaps;
namespace AsbCloudWebApi.Controllers
{
@ -22,7 +22,7 @@ namespace AsbCloudWebApi.Controllers
private readonly IWellCompositeRepository wellCompositeRepository;
private readonly IWellService wellService;
public WellCompositeController(IWellCompositeRepository wellCompositeRepository,
public WellCompositeController(IWellCompositeRepository wellCompositeRepository,
IWellService wellService)
{
this.wellCompositeRepository = wellCompositeRepository;
@ -73,7 +73,7 @@ namespace AsbCloudWebApi.Controllers
/// <returns></returns>
[HttpGet("compositeProcessMap")]
[Permission]
[ProducesResponseType(typeof(IEnumerable<ProcessMapPlanWellDrillingDto>), (int)System.Net.HttpStatusCode.OK)]
[ProducesResponseType(typeof(IEnumerable<ProcessMapPlanDrillingDto>), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> GetCompositeProcessMap(int idWell, CancellationToken token)
{
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))