CS2-61 WellOperationController.GetAllAsync(..) добавить параметры фильтрации

This commit is contained in:
Фролов 2021-08-18 16:57:20 +05:00
parent 64e06daefd
commit 7b154abb66
5 changed files with 86 additions and 42 deletions

View File

@ -2,12 +2,6 @@
namespace AsbCloudApp.Data
{
public enum WellOpertaionType
{
Plan,
Fact
}
public class WellOperationDto : IId
{
public int Id { get; set; }
@ -25,9 +19,9 @@ namespace AsbCloudApp.Data
public string CategoryInfo { get; set; }
/// <summary>
/// План или факт
/// 0 = план или 1 = факт
/// </summary>
public WellOpertaionType Type { get; set; }
public int IdType { get; set; }
public double WellDepth { get; set; }

View File

@ -1,27 +1,32 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using AsbCloudApp.Data;
namespace AsbCloudApp.Services
{
public interface IWellOperationService
{
IEnumerable<WellOperationCategoryDto> GetCategories();
Task<PaginationContainer<WellOperationDto>> GetAllByWellIdAsync(int idWell,
int skip = 0, int take = 32, CancellationToken token = default);
Task<PaginationContainer<WellOperationDto>> GetOperationsAsync(
int idWell,
int? opertaionType = null,
IEnumerable<int> sectionTypeIds = null,
IEnumerable<int> operationCategoryIds = null,
DateTime begin = default,
DateTime end = default,
int skip = 0,
int take = 32,
CancellationToken token = default);
Task<WellOperationDto> GetAsync(int id, CancellationToken token);
Task<int> InsertAsync(WellOperationDto wellOperationDto,
int idWell, CancellationToken token);
Task<int> InsertRangeAsync(int idWell,
IEnumerable<WellOperationDto> wellOperationDtos, CancellationToken token);
Task<int> UpdateAsync(int idWell, int idSection, WellOperationDto item,
Task<int> UpdateAsync(int idWell, int idOperation, WellOperationDto item,
CancellationToken token);
Task<int> DeleteAsync(IEnumerable<int> ids, CancellationToken token);

View File

@ -20,10 +20,10 @@ namespace AsbCloudDb.Model
public int IdWellSectionType { get; set; }
[Column("id_category"), Comment("Id категории операции")]
public int IdOperationCategory { get; set; }
public int IdCategory { get; set; }
[Column("type"), Comment("План или Факт")]
public int Type { get; set; }
[Column("id_type"), Comment("0 = План или 1 = Факт")]
public int IdType { get; set; }
[Column("depth"), Comment("Глубина, на которой производилась операция")]
public double WellDepth { get; set; }
@ -34,8 +34,8 @@ namespace AsbCloudDb.Model
[Column("duration_hours"), Comment("Продолжительность в часах")]
public double DurationHours { get; set; }
[Column("data"), Comment("Доп. информация к выбраной категории")]
public string Info { get; set; }
[Column("category_info"), Comment("Доп. информация к выбраной категории")]
public string CategoryInfo { get; set; }
[Column("comment"), Comment("Комментарий")]
public string Comment { get; set; }
@ -49,7 +49,7 @@ namespace AsbCloudDb.Model
public virtual WellSectionType WellSectionType { get; set; }
[JsonIgnore]
[ForeignKey(nameof(IdOperationCategory))]
[ForeignKey(nameof(IdCategory))]
public virtual WellOperationCategory OperationCategory { get; set; }
}
}

View File

@ -8,6 +8,7 @@ using AsbCloudApp.Services;
using AsbCloudDb.Model;
using AsbCloudInfrastructure.Services.Cache;
using Mapster;
using System;
namespace AsbCloudInfrastructure.Services
{
@ -30,14 +31,37 @@ namespace AsbCloudInfrastructure.Services
return result;
}
public async Task<PaginationContainer<WellOperationDto>> GetAllByWellIdAsync(int idWell,
int skip = 0, int take = 32, CancellationToken token = default)
public async Task<PaginationContainer<WellOperationDto>> GetOperationsAsync(
int idWell,
int? opertaionType = default,
IEnumerable<int> sectionTypeIds = default,
IEnumerable<int> operationCategoryIds = default,
DateTime begin = default,
DateTime end = default,
int skip = 0,
int take = 32,
CancellationToken token = default)
{
var query = context.WellOperations
.Include(s => s.WellSectionType)
.Include(s => s.OperationCategory)
.Where(s => s.IdWell == idWell);
if (opertaionType != default)
query = query.Where(e => e.IdType == (int)opertaionType);
if ((sectionTypeIds != default) && sectionTypeIds.Any())
query = query.Where(e => sectionTypeIds.Contains(e.IdWellSectionType));
if (operationCategoryIds != default && operationCategoryIds.Any())
query = query.Where(e => operationCategoryIds.Contains(e.IdCategory));
if (begin != default)
query = query.Where(e => e.StartDate >= begin);
if (end != default)
query = query.Where(e => e.StartDate <= end);
var result = new PaginationContainer<WellOperationDto>
{
Skip = skip,
@ -46,7 +70,9 @@ namespace AsbCloudInfrastructure.Services
};
query = query
.OrderBy(e => e.WellDepth);
.OrderBy(e => e.WellDepth)
.ThenBy(e => e.StartDate)
.ThenBy(e => e.Id);
if (skip > 0)
query = query.Skip(skip);
@ -83,15 +109,6 @@ namespace AsbCloudInfrastructure.Services
return dto;
}
public async Task<int> InsertAsync(WellOperationDto wellOperationDto,
int idWell, CancellationToken token = default)
{
var entity = wellOperationDto.Adapt<WellOperation>();
context.WellOperations.Add(entity);
return await context.SaveChangesAsync(token)
.ConfigureAwait(false);
}
public async Task<int> InsertRangeAsync(int idWell,
IEnumerable<WellOperationDto> wellOperationDtos,
CancellationToken token = default)
@ -99,6 +116,8 @@ namespace AsbCloudInfrastructure.Services
foreach(var operationDto in wellOperationDtos)
{
var entity = operationDto.Adapt<WellOperation>();
entity.Id = default;
entity.IdWell = idWell;
context.WellOperations.Add(entity);
}
@ -106,10 +125,12 @@ namespace AsbCloudInfrastructure.Services
.ConfigureAwait(false);
}
public async Task<int> UpdateAsync(int idWell, int idSection,
public async Task<int> UpdateAsync(int idWell, int idOperation,
WellOperationDto item, CancellationToken token = default)
{
var entity = item.Adapt<WellOperation>();
entity.Id = idOperation;
entity.IdWell = idWell;
context.WellOperations.Update(entity);
return await context.SaveChangesAsync(token)
.ConfigureAwait(false);

View File

@ -5,6 +5,7 @@ using AsbCloudApp.Data;
using AsbCloudApp.Services;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;
using System;
namespace AsbCloudWebApi.Controllers
{
@ -39,22 +40,45 @@ namespace AsbCloudWebApi.Controllers
}
/// <summary>
/// Возвращает весь список операций на скважине
/// Отфильтрованный список операций на скважине. Если не применять фильтр, то вернется весь список. Сортированный по глубине затем по дате
/// </summary>
/// <param name="idWell">id скважины</param>
/// <param name="skip">Для пагинации кол-во записей пропустить</param>
/// <param name="take">Для пагинации кол-во записей</param>
/// <param name="token">Токен отмены задачи</param>
/// <returns>Список операций на скважине</returns>
/// <param name="opertaionType">фильтр по план = 0, факт = 1</param>
/// <param name="sectionTypeIds">фильтр по списку id конструкций секции</param>
/// <param name="operationCategoryIds">фильтр по списку id категорий операции</param>
/// <param name="begin">фильтр по началу операции</param>
/// <param name="end">фильтр по окончанию операции</param>
/// <param name="skip"></param>
/// <param name="take"></param>
/// <param name="token"></param>
/// <returns>Список операций на скважине в контейнере для постраничного просмотра</returns>
[HttpGet]
[ProducesResponseType(typeof(PaginationContainer<WellOperationDto>), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> GetAllAsync(int idWell, int skip = 0, int take = 32,
public async Task<IActionResult> GetAllAsync(
int idWell,
int? opertaionType = default,
[FromQuery] IEnumerable<int> sectionTypeIds = default,
[FromQuery] IEnumerable<int> operationCategoryIds = default,
DateTime begin = default,
DateTime end = default,
int skip = 0,
int take = 32,
CancellationToken token = default)
{
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
return Forbid();
var result = await operationService.GetAllByWellIdAsync(idWell, skip, take, token).ConfigureAwait(false);
var result = await operationService.GetOperationsAsync(
idWell,
opertaionType,
sectionTypeIds,
operationCategoryIds,
begin,
end,
skip,
take,
token)
.ConfigureAwait(false);
return Ok(result);
}