forked from ddrilling/AsbCloudServer
Merge pull request 'ГГД - Добавить в справочник новые операции' (#248) from feature/#26940800-add-some-well-categories into dev
Reviewed-on: http://test.digitaldrilling.ru:8080/DDrilling/AsbCloudServer/pulls/248
This commit is contained in:
commit
0b629afcf0
@ -12,6 +12,6 @@ namespace AsbCloudApp.Repositories
|
|||||||
/// список названий операций
|
/// список названий операций
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
IEnumerable<WellOperationCategoryDto> Get(bool includeParents);
|
IEnumerable<WellOperationCategoryDto> Get(bool includeParents, bool includeHidden = true);
|
||||||
}
|
}
|
||||||
}
|
}
|
9590
AsbCloudDb/Migrations/20240408112202_Add_NewWellOperationCategories.Designer.cs
generated
Normal file
9590
AsbCloudDb/Migrations/20240408112202_Add_NewWellOperationCategories.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -39,6 +39,11 @@ namespace AsbCloudDb.Model
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public const int IdNonProductiveTime = 3005;
|
public const int IdNonProductiveTime = 3005;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Заключительные работы
|
||||||
|
/// </summary>
|
||||||
|
public const int IdFinalWorks = 3006;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// КНБК
|
/// КНБК
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -129,6 +134,11 @@ namespace AsbCloudDb.Model
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public const int IdOperationsNotIncludedGGD = 4017;
|
public const int IdOperationsNotIncludedGGD = 4017;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Заключительные операции
|
||||||
|
/// </summary>
|
||||||
|
public const int IdFinalOperations = 4019;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Разборка КНБК
|
/// Разборка КНБК
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -240,6 +250,7 @@ namespace AsbCloudDb.Model
|
|||||||
new() { Id = IdGFR, Name = "ГФР", KeyValueName = "dT", KeyValueUnits = "мин" },
|
new() { Id = IdGFR, Name = "ГФР", KeyValueName = "dT", KeyValueUnits = "мин" },
|
||||||
new() { Id = IdAuxiliaryOperations, Name = "Вспомогательные операции", KeyValueName = "dT", KeyValueUnits = "мин" },
|
new() { Id = IdAuxiliaryOperations, Name = "Вспомогательные операции", KeyValueName = "dT", KeyValueUnits = "мин" },
|
||||||
new() { Id = IdNonProductiveTime, Name = "Непроизводительное время (НПВ)", KeyValueName = "dT", KeyValueUnits = "мин" },
|
new() { Id = IdNonProductiveTime, Name = "Непроизводительное время (НПВ)", KeyValueName = "dT", KeyValueUnits = "мин" },
|
||||||
|
new() { Id = IdFinalWorks, Name = "Заключительные работы", KeyValueName = "dT", KeyValueUnits = "мин" },
|
||||||
};
|
};
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -265,6 +276,7 @@ namespace AsbCloudDb.Model
|
|||||||
new () {Id = IdEmergencyWork, IdParent = 3005, Name = "Аварийные работы", KeyValueName = "dT", KeyValueUnits = "мин" },
|
new () {Id = IdEmergencyWork, IdParent = 3005, Name = "Аварийные работы", KeyValueName = "dT", KeyValueUnits = "мин" },
|
||||||
new () {Id = IdComplication, IdParent = 3005, Name = "Осложнение", KeyValueName = "dT", KeyValueUnits = "мин" },
|
new () {Id = IdComplication, IdParent = 3005, Name = "Осложнение", KeyValueName = "dT", KeyValueUnits = "мин" },
|
||||||
new () {Id = IdOperationsNotIncludedGGD, IdParent = 3005, Name = "Незаложенные в ГГД операции", KeyValueName = "dT", KeyValueUnits = "мин" },
|
new () {Id = IdOperationsNotIncludedGGD, IdParent = 3005, Name = "Незаложенные в ГГД операции", KeyValueName = "dT", KeyValueUnits = "мин" },
|
||||||
|
new () {Id = IdFinalOperations, IdParent = IdFinalWorks, Name = "Заключительные операции", KeyValueName = "dT", KeyValueUnits = "мин" },
|
||||||
};
|
};
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -273,8 +285,8 @@ namespace AsbCloudDb.Model
|
|||||||
public static WellOperationCategory[] WorkCategories { get; } = new WellOperationCategory[]{
|
public static WellOperationCategory[] WorkCategories { get; } = new WellOperationCategory[]{
|
||||||
new () {Id = IdBhaDisassembly, IdParent = 4000, Name = "Разборка КНБК", KeyValueName = "dT", KeyValueUnits = "мин" },
|
new () {Id = IdBhaDisassembly, IdParent = 4000, Name = "Разборка КНБК", KeyValueName = "dT", KeyValueUnits = "мин" },
|
||||||
new () {Id = IdBhaAssembly, IdParent = 4000, Name = "Сборка КНБК", KeyValueName = "dT", KeyValueUnits = "мин" },
|
new () {Id = IdBhaAssembly, IdParent = 4000, Name = "Сборка КНБК", KeyValueName = "dT", KeyValueUnits = "мин" },
|
||||||
new () {Id = IdSlide, IdParent = 4001, Name = "Бурение слайдом", KeyValueName = "МСП", KeyValueUnits = "м/ч" },
|
new () {Id = IdSlide, IsHidden = true, IdParent = 4001, Name = "Бурение слайдом", KeyValueName = "МСП", KeyValueUnits = "м/ч" },
|
||||||
new () {Id = IdRotor, IdParent = 4001, Name = "Бурение ротором", KeyValueName = "МСП", KeyValueUnits = "м/ч" },
|
new () {Id = IdRotor, IsHidden = true, IdParent = 4001, Name = "Бурение ротором", KeyValueName = "МСП", KeyValueUnits = "м/ч" },
|
||||||
new () {Id = IdStaticSurveying, IdParent = 4002, Name = "Замер ЗТС (запись MWD)", KeyValueName = "dT", KeyValueUnits = "мин" },
|
new () {Id = IdStaticSurveying, IdParent = 4002, Name = "Замер ЗТС (запись MWD)", KeyValueName = "dT", KeyValueUnits = "мин" },
|
||||||
new () {Id = IdFlashingBeforeConnection, IdParent = 4003, Name = "Промывка перед наращиванием", KeyValueName = "dT", KeyValueUnits = "мин" },
|
new () {Id = IdFlashingBeforeConnection, IdParent = 4003, Name = "Промывка перед наращиванием", KeyValueName = "dT", KeyValueUnits = "мин" },
|
||||||
new () {Id = 5006, IdParent = 4003, Name = "Проработка во время бурения", KeyValueName = "dT", KeyValueUnits = "мин" },
|
new () {Id = 5006, IdParent = 4003, Name = "Проработка во время бурения", KeyValueName = "dT", KeyValueUnits = "мин" },
|
||||||
@ -381,7 +393,12 @@ namespace AsbCloudDb.Model
|
|||||||
new () {Id = 5109, IdParent = 4018, Name = "Стыковка стингера с хвостовиком основного ствола", KeyValueName = "dT", KeyValueUnits = "мин"},
|
new () {Id = 5109, IdParent = 4018, Name = "Стыковка стингера с хвостовиком основного ствола", KeyValueName = "dT", KeyValueUnits = "мин"},
|
||||||
new () {Id = 5110, IdParent = 4018, Name = "Ориентирование и установка стыковочного узла хвостовика", KeyValueName = "dT", KeyValueUnits = "мин"},
|
new () {Id = 5110, IdParent = 4018, Name = "Ориентирование и установка стыковочного узла хвостовика", KeyValueName = "dT", KeyValueUnits = "мин"},
|
||||||
new () {Id = 5111, IdParent = 4001, Name = "Бурение с отбором керна", KeyValueName = "МСП", KeyValueUnits = "м/ч"},
|
new () {Id = 5111, IdParent = 4001, Name = "Бурение с отбором керна", KeyValueName = "МСП", KeyValueUnits = "м/ч"},
|
||||||
new () {Id = 5112, IdParent = 4018, Name = "Работа пакером в обсадной колонне", KeyValueName = "dT", KeyValueUnits = "мин"}
|
new () {Id = 5112, IdParent = 4018, Name = "Работа пакером в обсадной колонне", KeyValueName = "dT", KeyValueUnits = "мин"},
|
||||||
|
new () {Id = 5113, IdParent = 4001, Name = "Бурение", KeyValueName = "МСП", KeyValueUnits = "м/ч"},
|
||||||
|
new () {Id = 5114, IdParent = 4013, Name = "ТО оборудования", KeyValueName = "dT", KeyValueUnits = "мин"},
|
||||||
|
new () {Id = 5115, IdParent = IdFinalOperations, Name = "Спуск НКТ", KeyValueName = "dT", KeyValueUnits = "мин"},
|
||||||
|
new () {Id = 5116, IdParent = IdAuxiliaryWork, Name = "Вырезка окна", KeyValueName = "dT", KeyValueUnits = "мин"},
|
||||||
|
new () {Id = 5117, IdParent = IdAuxiliaryWork, Name = "Расширение ствола", KeyValueName = "dT", KeyValueUnits = "мин"},
|
||||||
};
|
};
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -401,6 +418,8 @@ namespace AsbCloudDb.Model
|
|||||||
[Column("key_value_units"), Comment("Единицы измерения ключевого показателя операции"), StringLength(16)]
|
[Column("key_value_units"), Comment("Единицы измерения ключевого показателя операции"), StringLength(16)]
|
||||||
public string? KeyValueUnits { get; set; }
|
public string? KeyValueUnits { get; set; }
|
||||||
|
|
||||||
|
public bool IsHidden { get; set; } = false;
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
[ForeignKey(nameof(IdParent))]
|
[ForeignKey(nameof(IdParent))]
|
||||||
public virtual WellOperationCategory? Parent { get; set; } = null!;
|
public virtual WellOperationCategory? Parent { get; set; } = null!;
|
||||||
|
@ -19,11 +19,14 @@ public class WellOperationCategoryRepository : IWellOperationCategoryRepository
|
|||||||
this.memoryCache = memoryCache;
|
this.memoryCache = memoryCache;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<WellOperationCategoryDto> Get(bool includeParents)
|
public IEnumerable<WellOperationCategoryDto> Get(bool includeParents, bool includeHidden = true)
|
||||||
{
|
{
|
||||||
var categories = memoryCache
|
var categories = memoryCache
|
||||||
.GetOrCreateBasic(db.Set<WellOperationCategory>());
|
.GetOrCreateBasic(db.Set<WellOperationCategory>());
|
||||||
|
|
||||||
|
if (!includeHidden)
|
||||||
|
categories = categories.Where(o => o.IsHidden == false);
|
||||||
|
|
||||||
if (!includeParents)
|
if (!includeParents)
|
||||||
{
|
{
|
||||||
var parentIds = categories
|
var parentIds = categories
|
||||||
|
Binary file not shown.
Binary file not shown.
@ -27,323 +27,323 @@ namespace AsbCloudWebApi.Controllers;
|
|||||||
[Authorize]
|
[Authorize]
|
||||||
public class WellOperationController : ControllerBase
|
public class WellOperationController : ControllerBase
|
||||||
{
|
{
|
||||||
private readonly IDictionary<int, string> templateNames = new Dictionary<int, string>
|
private readonly IDictionary<int, string> templateNames = new Dictionary<int, string>
|
||||||
{
|
{
|
||||||
{ WellOperation.IdOperationTypeFact, "ЕЦП_шаблон_файла_фактические_операции.xlsx" },
|
{ WellOperation.IdOperationTypeFact, "ЕЦП_шаблон_файла_фактические_операции.xlsx" },
|
||||||
{ WellOperation.IdOperationTypePlan, "ЕЦП_шаблон_файла_плановые_операции.xlsx" }
|
{ WellOperation.IdOperationTypePlan, "ЕЦП_шаблон_файла_плановые_операции.xlsx" }
|
||||||
};
|
};
|
||||||
|
|
||||||
private readonly IUserRepository userRepository;
|
private readonly IUserRepository userRepository;
|
||||||
private readonly IWellOperationRepository wellOperationRepository;
|
private readonly IWellOperationRepository wellOperationRepository;
|
||||||
private readonly IWellOperationCategoryRepository wellOperationCategoryRepository;
|
private readonly IWellOperationCategoryRepository wellOperationCategoryRepository;
|
||||||
private readonly IWellService wellService;
|
private readonly IWellService wellService;
|
||||||
|
|
||||||
private readonly WellOperationParserFactory wellOperationParserFactory;
|
private readonly WellOperationParserFactory wellOperationParserFactory;
|
||||||
private readonly WellOperationExportServiceFactory wellOperationExportServiceFactory;
|
private readonly WellOperationExportServiceFactory wellOperationExportServiceFactory;
|
||||||
|
|
||||||
public WellOperationController(IWellOperationRepository wellOperationRepository,
|
public WellOperationController(IWellOperationRepository wellOperationRepository,
|
||||||
IWellOperationCategoryRepository wellOperationCategoryRepository,
|
IWellOperationCategoryRepository wellOperationCategoryRepository,
|
||||||
IWellService wellService,
|
IWellService wellService,
|
||||||
IUserRepository userRepository,
|
IUserRepository userRepository,
|
||||||
WellOperationParserFactory wellOperationParserFactory,
|
WellOperationParserFactory wellOperationParserFactory,
|
||||||
WellOperationExportServiceFactory wellOperationExportServiceFactory)
|
WellOperationExportServiceFactory wellOperationExportServiceFactory)
|
||||||
{
|
{
|
||||||
this.wellOperationRepository = wellOperationRepository;
|
this.wellOperationRepository = wellOperationRepository;
|
||||||
this.wellOperationCategoryRepository = wellOperationCategoryRepository;
|
this.wellOperationCategoryRepository = wellOperationCategoryRepository;
|
||||||
this.wellService = wellService;
|
this.wellService = wellService;
|
||||||
this.userRepository = userRepository;
|
this.userRepository = userRepository;
|
||||||
this.wellOperationParserFactory = wellOperationParserFactory;
|
this.wellOperationParserFactory = wellOperationParserFactory;
|
||||||
this.wellOperationExportServiceFactory = wellOperationExportServiceFactory;
|
this.wellOperationExportServiceFactory = wellOperationExportServiceFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Добавляет новые операции на скважине
|
/// Добавляет новые операции на скважине
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="idWell">Id скважины</param>
|
/// <param name="idWell">Id скважины</param>
|
||||||
/// <param name="dtos">Добавляемые операции</param>
|
/// <param name="dtos">Добавляемые операции</param>
|
||||||
/// <param name="deleteBeforeInsert">Удалить операции перед сохранением</param>
|
/// <param name="deleteBeforeInsert">Удалить операции перед сохранением</param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns>Количество добавленных в БД записей</returns>
|
/// <returns>Количество добавленных в БД записей</returns>
|
||||||
[HttpPost("{deleteBeforeInsert:bool}")]
|
[HttpPost("{deleteBeforeInsert:bool}")]
|
||||||
[Permission]
|
[Permission]
|
||||||
[ProducesResponseType(typeof(int), StatusCodes.Status200OK)]
|
[ProducesResponseType(typeof(int), StatusCodes.Status200OK)]
|
||||||
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
|
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
|
||||||
public async Task<IActionResult> InsertRangeAsync(
|
public async Task<IActionResult> InsertRangeAsync(
|
||||||
[Range(1, int.MaxValue, ErrorMessage = "Id скважины не может быть меньше 1")]
|
[Range(1, int.MaxValue, ErrorMessage = "Id скважины не может быть меньше 1")]
|
||||||
int idWell,
|
int idWell,
|
||||||
bool deleteBeforeInsert,
|
bool deleteBeforeInsert,
|
||||||
[FromBody] IEnumerable<WellOperationDto> dtos,
|
[FromBody] IEnumerable<WellOperationDto> dtos,
|
||||||
CancellationToken cancellationToken)
|
CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
if (!await CanUserAccessToWellAsync(idWell, cancellationToken))
|
if (!await CanUserAccessToWellAsync(idWell, cancellationToken))
|
||||||
return Forbid();
|
return Forbid();
|
||||||
|
|
||||||
if (!await CanUserEditWellOperationsAsync(idWell, cancellationToken))
|
if (!await CanUserEditWellOperationsAsync(idWell, cancellationToken))
|
||||||
return Forbid();
|
return Forbid();
|
||||||
|
|
||||||
foreach (var dto in dtos)
|
foreach (var dto in dtos)
|
||||||
{
|
{
|
||||||
dto.IdWell = idWell;
|
dto.IdWell = idWell;
|
||||||
dto.LastUpdateDate = null;
|
dto.LastUpdateDate = null;
|
||||||
dto.IdUser = User.GetUserId();
|
dto.IdUser = User.GetUserId();
|
||||||
}
|
}
|
||||||
|
|
||||||
var result = await wellOperationRepository.InsertRangeAsync(dtos, deleteBeforeInsert, cancellationToken);
|
var result = await wellOperationRepository.InsertRangeAsync(dtos, deleteBeforeInsert, cancellationToken);
|
||||||
|
|
||||||
return Ok(result);
|
return Ok(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Обновляет выбранную операцию на скважине
|
/// Обновляет выбранную операцию на скважине
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="idWell">id скважины</param>
|
/// <param name="idWell">id скважины</param>
|
||||||
/// <param name="dtos"></param>
|
/// <param name="dtos"></param>
|
||||||
/// <param name="token">Токен отмены задачи</param>
|
/// <param name="token">Токен отмены задачи</param>
|
||||||
/// <returns>Количество обновленных в БД строк</returns>
|
/// <returns>Количество обновленных в БД строк</returns>
|
||||||
[HttpPut]
|
[HttpPut]
|
||||||
[Permission]
|
[Permission]
|
||||||
[ProducesResponseType(typeof(int), StatusCodes.Status200OK)]
|
[ProducesResponseType(typeof(int), StatusCodes.Status200OK)]
|
||||||
public async Task<IActionResult> UpdateRangeAsync(int idWell,
|
public async Task<IActionResult> UpdateRangeAsync(int idWell,
|
||||||
[FromBody] IEnumerable<WellOperationDto> dtos,
|
[FromBody] IEnumerable<WellOperationDto> dtos,
|
||||||
CancellationToken token)
|
CancellationToken token)
|
||||||
{
|
{
|
||||||
if (!await CanUserAccessToWellAsync(idWell, token))
|
if (!await CanUserAccessToWellAsync(idWell, token))
|
||||||
return Forbid();
|
return Forbid();
|
||||||
|
|
||||||
if (!await CanUserEditWellOperationsAsync(idWell, token))
|
if (!await CanUserEditWellOperationsAsync(idWell, token))
|
||||||
return Forbid();
|
return Forbid();
|
||||||
|
|
||||||
foreach (var dto in dtos)
|
foreach (var dto in dtos)
|
||||||
{
|
{
|
||||||
dto.IdWell = idWell;
|
dto.IdWell = idWell;
|
||||||
dto.IdUser = User.GetUserId();
|
dto.IdUser = User.GetUserId();
|
||||||
dto.LastUpdateDate = DateTimeOffset.UtcNow;
|
dto.LastUpdateDate = DateTimeOffset.UtcNow;
|
||||||
}
|
}
|
||||||
|
|
||||||
var result = await wellOperationRepository.UpdateRangeAsync(dtos, token);
|
var result = await wellOperationRepository.UpdateRangeAsync(dtos, token);
|
||||||
|
|
||||||
return Ok(result);
|
return Ok(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Возвращает словарь типов секций
|
/// Возвращает словарь типов секций
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpGet("sectionTypes")]
|
[HttpGet("sectionTypes")]
|
||||||
[Permission]
|
[Permission]
|
||||||
[ProducesResponseType(typeof(IEnumerable<WellSectionTypeDto>), StatusCodes.Status200OK)]
|
[ProducesResponseType(typeof(IEnumerable<WellSectionTypeDto>), StatusCodes.Status200OK)]
|
||||||
public IActionResult GetSectionTypes()
|
public IActionResult GetSectionTypes()
|
||||||
{
|
{
|
||||||
var result = wellOperationRepository.GetSectionTypes();
|
var result = wellOperationRepository.GetSectionTypes();
|
||||||
return Ok(result);
|
return Ok(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Статистика операций по скважине, группированная по категориям
|
/// Статистика операций по скважине, группированная по категориям
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="idWell">id скважины</param>
|
/// <param name="idWell">id скважины</param>
|
||||||
/// <param name="request"></param>
|
/// <param name="request"></param>
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpGet("groupStat")]
|
[HttpGet("groupStat")]
|
||||||
[Permission]
|
[Permission]
|
||||||
[ProducesResponseType(typeof(IEnumerable<WellGroupOpertionDto>), (int)System.Net.HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(IEnumerable<WellGroupOpertionDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||||
public async Task<IActionResult> GetGroupOperationsAsync(
|
public async Task<IActionResult> GetGroupOperationsAsync(
|
||||||
[FromRoute] int idWell,
|
[FromRoute] int idWell,
|
||||||
[FromQuery] WellOperationRequestBase request,
|
[FromQuery] WellOperationRequestBase request,
|
||||||
CancellationToken token)
|
CancellationToken token)
|
||||||
{
|
{
|
||||||
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
||||||
return Forbid();
|
return Forbid();
|
||||||
|
|
||||||
var requestToservice = new WellOperationRequest(request, new[] { idWell });
|
var requestToservice = new WellOperationRequest(request, new[] { idWell });
|
||||||
|
|
||||||
var result = await wellOperationRepository.GetGroupOperationsStatAsync(requestToservice, token);
|
|
||||||
return Ok(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
var result = await wellOperationRepository.GetGroupOperationsStatAsync(requestToservice, token);
|
||||||
/// Возвращает список имен типов операций на скважине
|
return Ok(result);
|
||||||
/// </summary>
|
}
|
||||||
/// <param name="includeParents">флаг, нужно ли включать родителей в список</param>
|
|
||||||
/// <returns></returns>
|
|
||||||
[HttpGet("categories")]
|
|
||||||
[Permission]
|
|
||||||
[ProducesResponseType(typeof(IEnumerable<WellOperationCategoryDto>), StatusCodes.Status200OK)]
|
|
||||||
public IActionResult GetCategories(bool includeParents = true)
|
|
||||||
{
|
|
||||||
var result = wellOperationCategoryRepository.Get(includeParents);
|
|
||||||
return Ok(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Постраничный список операций на скважине.
|
/// Возвращает список имен типов операций на скважине
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="idWell">id скважины</param>
|
/// <param name="includeParents">флаг, нужно ли включать родителей в список</param>
|
||||||
/// <param name="request"></param>
|
/// <returns></returns>
|
||||||
/// <param name="token"></param>
|
[HttpGet("categories")]
|
||||||
/// <returns>Список операций на скважине</returns>
|
[Permission]
|
||||||
[HttpGet]
|
[ProducesResponseType(typeof(IEnumerable<WellOperationCategoryDto>), StatusCodes.Status200OK)]
|
||||||
[Permission]
|
public IActionResult GetCategories(bool includeParents = true)
|
||||||
[ProducesResponseType(typeof(PaginationContainer<WellOperationDto>), StatusCodes.Status200OK)]
|
{
|
||||||
public async Task<IActionResult> GetPageOperationsAsync(
|
var result = wellOperationCategoryRepository.Get(includeParents, false);
|
||||||
[FromRoute] int idWell,
|
return Ok(result);
|
||||||
[FromQuery] WellOperationRequestBase request,
|
}
|
||||||
CancellationToken token)
|
|
||||||
{
|
|
||||||
if (!await CanUserAccessToWellAsync(idWell, token))
|
|
||||||
return Forbid();
|
|
||||||
|
|
||||||
var requestToService = new WellOperationRequest(request, new[] { idWell });
|
/// <summary>
|
||||||
|
/// Постраничный список операций на скважине.
|
||||||
var result = await wellOperationRepository.GetPageAsync(requestToService, token);
|
/// </summary>
|
||||||
return Ok(result);
|
/// <param name="idWell">id скважины</param>
|
||||||
}
|
/// <param name="request"></param>
|
||||||
|
/// <param name="token"></param>
|
||||||
|
/// <returns>Список операций на скважине</returns>
|
||||||
|
[HttpGet]
|
||||||
|
[Permission]
|
||||||
|
[ProducesResponseType(typeof(PaginationContainer<WellOperationDto>), StatusCodes.Status200OK)]
|
||||||
|
public async Task<IActionResult> GetPageOperationsAsync(
|
||||||
|
[FromRoute] int idWell,
|
||||||
|
[FromQuery] WellOperationRequestBase request,
|
||||||
|
CancellationToken token)
|
||||||
|
{
|
||||||
|
if (!await CanUserAccessToWellAsync(idWell, token))
|
||||||
|
return Forbid();
|
||||||
|
|
||||||
/// <summary>
|
var requestToService = new WellOperationRequest(request, new[] { idWell });
|
||||||
/// Создает excel файл с "сетевым графиком"
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="idWell">id скважины</param>
|
|
||||||
/// <param name="scheduleReportService"></param>
|
|
||||||
/// <param name="token"></param>
|
|
||||||
/// <returns>Запрашиваемый файл</returns>
|
|
||||||
[HttpGet("scheduleReport")]
|
|
||||||
[Permission]
|
|
||||||
[ProducesResponseType(typeof(PhysicalFileResult), StatusCodes.Status200OK)]
|
|
||||||
public async Task<IActionResult> ScheduleReportAsync([FromRoute] int idWell,
|
|
||||||
[FromServices] IScheduleReportService scheduleReportService,
|
|
||||||
CancellationToken token)
|
|
||||||
{
|
|
||||||
var idCompany = User.GetCompanyId();
|
|
||||||
|
|
||||||
if (idCompany is null)
|
var result = await wellOperationRepository.GetPageAsync(requestToService, token);
|
||||||
return Forbid();
|
return Ok(result);
|
||||||
|
}
|
||||||
|
|
||||||
if (!await wellService.IsCompanyInvolvedInWellAsync(idCompany.Value, idWell, token))
|
/// <summary>
|
||||||
return Forbid();
|
/// Создает excel файл с "сетевым графиком"
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="idWell">id скважины</param>
|
||||||
|
/// <param name="scheduleReportService"></param>
|
||||||
|
/// <param name="token"></param>
|
||||||
|
/// <returns>Запрашиваемый файл</returns>
|
||||||
|
[HttpGet("scheduleReport")]
|
||||||
|
[Permission]
|
||||||
|
[ProducesResponseType(typeof(PhysicalFileResult), StatusCodes.Status200OK)]
|
||||||
|
public async Task<IActionResult> ScheduleReportAsync([FromRoute] int idWell,
|
||||||
|
[FromServices] IScheduleReportService scheduleReportService,
|
||||||
|
CancellationToken token)
|
||||||
|
{
|
||||||
|
var idCompany = User.GetCompanyId();
|
||||||
|
|
||||||
var stream = await scheduleReportService.MakeReportAsync(idWell, token);
|
if (idCompany is null)
|
||||||
var fileName = await wellService.GetWellCaptionByIdAsync(idWell, token) + "_ScheduleReport.xlsx";
|
return Forbid();
|
||||||
return File(stream, "application/octet-stream", fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
if (!await wellService.IsCompanyInvolvedInWellAsync(idCompany.Value, idWell, token))
|
||||||
/// Удаляет выбранную операцию на скважине
|
return Forbid();
|
||||||
/// </summary>
|
|
||||||
/// <param name="idWell">id скважины</param>
|
|
||||||
/// <param name="idOperation">id выбранной операции</param>
|
|
||||||
/// <param name="token">Токен отмены задачи</param>
|
|
||||||
/// <returns>Количество удаленных из БД строк</returns>
|
|
||||||
[HttpDelete("{idOperation}")]
|
|
||||||
[Permission]
|
|
||||||
[ProducesResponseType(typeof(int), StatusCodes.Status200OK)]
|
|
||||||
public async Task<IActionResult> DeleteAsync(int idWell, int idOperation, CancellationToken token)
|
|
||||||
{
|
|
||||||
if (!await CanUserAccessToWellAsync(idWell, token))
|
|
||||||
return Forbid();
|
|
||||||
|
|
||||||
if (!await CanUserEditWellOperationsAsync(idWell, token))
|
var stream = await scheduleReportService.MakeReportAsync(idWell, token);
|
||||||
return Forbid();
|
var fileName = await wellService.GetWellCaptionByIdAsync(idWell, token) + "_ScheduleReport.xlsx";
|
||||||
|
return File(stream, "application/octet-stream", fileName);
|
||||||
|
}
|
||||||
|
|
||||||
var result = await wellOperationRepository.DeleteRangeAsync(new[] { idOperation }, token);
|
/// <summary>
|
||||||
|
/// Удаляет выбранную операцию на скважине
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="idWell">id скважины</param>
|
||||||
|
/// <param name="idOperation">id выбранной операции</param>
|
||||||
|
/// <param name="token">Токен отмены задачи</param>
|
||||||
|
/// <returns>Количество удаленных из БД строк</returns>
|
||||||
|
[HttpDelete("{idOperation}")]
|
||||||
|
[Permission]
|
||||||
|
[ProducesResponseType(typeof(int), StatusCodes.Status200OK)]
|
||||||
|
public async Task<IActionResult> DeleteAsync(int idWell, int idOperation, CancellationToken token)
|
||||||
|
{
|
||||||
|
if (!await CanUserAccessToWellAsync(idWell, token))
|
||||||
|
return Forbid();
|
||||||
|
|
||||||
return Ok(result);
|
if (!await CanUserEditWellOperationsAsync(idWell, token))
|
||||||
}
|
return Forbid();
|
||||||
|
|
||||||
/// <summary>
|
var result = await wellOperationRepository.DeleteRangeAsync(new[] { idOperation }, token);
|
||||||
/// Формирование excel файла с операциями на скважине
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="idWell"></param>
|
|
||||||
/// <param name="idType"></param>
|
|
||||||
/// <param name="token"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
[HttpGet("export")]
|
|
||||||
[ProducesResponseType(typeof(PhysicalFileResult), StatusCodes.Status200OK, "application/octet-stream")]
|
|
||||||
public async Task<IActionResult> ExportAsync(int idWell,
|
|
||||||
int idType,
|
|
||||||
CancellationToken token)
|
|
||||||
{
|
|
||||||
var options = new WellOperationExportRequest(idWell, idType);
|
|
||||||
var exportService = wellOperationExportServiceFactory.CreateExportService<WellOperationExportRequest>(idType);
|
|
||||||
|
|
||||||
var (fileName, file) = await exportService.ExportAsync(options, token);
|
return Ok(result);
|
||||||
|
}
|
||||||
|
|
||||||
return File(file, "application/octet-stream", fileName);
|
/// <summary>
|
||||||
}
|
/// Формирование excel файла с операциями на скважине
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="idWell"></param>
|
||||||
|
/// <param name="idType"></param>
|
||||||
|
/// <param name="token"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpGet("export")]
|
||||||
|
[ProducesResponseType(typeof(PhysicalFileResult), StatusCodes.Status200OK, "application/octet-stream")]
|
||||||
|
public async Task<IActionResult> ExportAsync(int idWell,
|
||||||
|
int idType,
|
||||||
|
CancellationToken token)
|
||||||
|
{
|
||||||
|
var options = new WellOperationExportRequest(idWell, idType);
|
||||||
|
var exportService = wellOperationExportServiceFactory.CreateExportService<WellOperationExportRequest>(idType);
|
||||||
|
|
||||||
/// <summary>
|
var (fileName, file) = await exportService.ExportAsync(options, token);
|
||||||
/// Парсинг ГГД из excel (xlsx) файла
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="idWell"></param>
|
|
||||||
/// <param name="idType"></param>
|
|
||||||
/// <param name="file"></param>
|
|
||||||
/// <param name="token"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
[HttpPost("parse/{idType}")]
|
|
||||||
[Permission]
|
|
||||||
[ProducesResponseType(typeof(ParserResultDto<WellOperationDto>), StatusCodes.Status200OK)]
|
|
||||||
public async Task<IActionResult> ParseAsync(int idWell,
|
|
||||||
int idType,
|
|
||||||
[Required] IFormFile file,
|
|
||||||
CancellationToken token)
|
|
||||||
{
|
|
||||||
if (!await CanUserAccessToWellAsync(idWell, token))
|
|
||||||
return Forbid();
|
|
||||||
|
|
||||||
if (!await CanUserEditWellOperationsAsync(idWell, token))
|
return File(file, "application/octet-stream", fileName);
|
||||||
return Forbid();
|
}
|
||||||
|
|
||||||
var stream = file.GetExcelFile();
|
/// <summary>
|
||||||
|
/// Парсинг ГГД из excel (xlsx) файла
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="idWell"></param>
|
||||||
|
/// <param name="idType"></param>
|
||||||
|
/// <param name="file"></param>
|
||||||
|
/// <param name="token"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPost("parse/{idType}")]
|
||||||
|
[Permission]
|
||||||
|
[ProducesResponseType(typeof(ParserResultDto<WellOperationDto>), StatusCodes.Status200OK)]
|
||||||
|
public async Task<IActionResult> ParseAsync(int idWell,
|
||||||
|
int idType,
|
||||||
|
[Required] IFormFile file,
|
||||||
|
CancellationToken token)
|
||||||
|
{
|
||||||
|
if (!await CanUserAccessToWellAsync(idWell, token))
|
||||||
|
return Forbid();
|
||||||
|
|
||||||
try
|
if (!await CanUserEditWellOperationsAsync(idWell, token))
|
||||||
{
|
return Forbid();
|
||||||
var timezone = wellService.GetTimezone(idWell);
|
|
||||||
var options = new WellOperationParserRequest(idWell, idType, timezone);
|
|
||||||
var parser = wellOperationParserFactory.CreateParser<WellOperationParserRequest>(idType);
|
|
||||||
var result = parser.Parse(stream, options);
|
|
||||||
|
|
||||||
return Ok(result);
|
var stream = file.GetExcelFile();
|
||||||
}
|
|
||||||
catch (FileFormatException ex)
|
|
||||||
{
|
|
||||||
return this.ValidationBadRequest(nameof(file), ex.Message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
try
|
||||||
/// Получение шаблона для заполнения ГГД
|
{
|
||||||
/// </summary>
|
var timezone = wellService.GetTimezone(idWell);
|
||||||
/// <returns></returns>
|
var options = new WellOperationParserRequest(idWell, idType, timezone);
|
||||||
[HttpGet("template")]
|
var parser = wellOperationParserFactory.CreateParser<WellOperationParserRequest>(idType);
|
||||||
[AllowAnonymous]
|
var result = parser.Parse(stream, options);
|
||||||
[ProducesResponseType(typeof(PhysicalFileResult), StatusCodes.Status200OK, "application/octet-stream")]
|
|
||||||
public IActionResult GetTemplate(int idType)
|
|
||||||
{
|
|
||||||
var parser = wellOperationParserFactory.CreateParser<WellOperationParserRequest>(idType);
|
|
||||||
var stream = parser.GetTemplateFile();
|
|
||||||
|
|
||||||
return File(stream, "application/octet-stream", templateNames[idType]);
|
return Ok(result);
|
||||||
}
|
}
|
||||||
|
catch (FileFormatException ex)
|
||||||
|
{
|
||||||
|
return this.ValidationBadRequest(nameof(file), ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private async Task<bool> CanUserAccessToWellAsync(int idWell, CancellationToken token)
|
/// <summary>
|
||||||
{
|
/// Получение шаблона для заполнения ГГД
|
||||||
var idCompany = User.GetCompanyId();
|
/// </summary>
|
||||||
return idCompany is not null && await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
/// <returns></returns>
|
||||||
idWell, token).ConfigureAwait(false);
|
[HttpGet("template")]
|
||||||
}
|
[AllowAnonymous]
|
||||||
|
[ProducesResponseType(typeof(PhysicalFileResult), StatusCodes.Status200OK, "application/octet-stream")]
|
||||||
|
public IActionResult GetTemplate(int idType)
|
||||||
|
{
|
||||||
|
var parser = wellOperationParserFactory.CreateParser<WellOperationParserRequest>(idType);
|
||||||
|
var stream = parser.GetTemplateFile();
|
||||||
|
|
||||||
private async Task<bool> CanUserEditWellOperationsAsync(int idWell, CancellationToken token)
|
return File(stream, "application/octet-stream", templateNames[idType]);
|
||||||
{
|
}
|
||||||
var idUser = User.GetUserId();
|
|
||||||
|
|
||||||
if (!idUser.HasValue)
|
private async Task<bool> CanUserAccessToWellAsync(int idWell, CancellationToken token)
|
||||||
return false;
|
{
|
||||||
|
var idCompany = User.GetCompanyId();
|
||||||
|
return idCompany is not null && await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
||||||
|
idWell, token).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
var well = await wellService.GetOrDefaultAsync(idWell, token);
|
private async Task<bool> CanUserEditWellOperationsAsync(int idWell, CancellationToken token)
|
||||||
|
{
|
||||||
|
var idUser = User.GetUserId();
|
||||||
|
|
||||||
if (well is null)
|
if (!idUser.HasValue)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return well.IdState != 2 || userRepository.HasPermission(idUser.Value, "WellOperation.editCompletedWell");
|
var well = await wellService.GetOrDefaultAsync(idWell, token);
|
||||||
}
|
|
||||||
|
if (well is null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return well.IdState != 2 || userRepository.HasPermission(idUser.Value, "WellOperation.editCompletedWell");
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user