diff --git a/AsbCloudApp/Data/WellOperationDto.cs b/AsbCloudApp/Data/WellOperationDto.cs index 3ef0054f..e0eb7442 100644 --- a/AsbCloudApp/Data/WellOperationDto.cs +++ b/AsbCloudApp/Data/WellOperationDto.cs @@ -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; } /// - /// План или факт + /// 0 = план или 1 = факт /// - public WellOpertaionType Type { get; set; } + public int IdType { get; set; } public double WellDepth { get; set; } diff --git a/AsbCloudApp/Services/IWellOperationService.cs b/AsbCloudApp/Services/IWellOperationService.cs index 81f1cf30..d9f08b59 100644 --- a/AsbCloudApp/Services/IWellOperationService.cs +++ b/AsbCloudApp/Services/IWellOperationService.cs @@ -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 GetCategories(); - Task> GetAllByWellIdAsync(int idWell, - int skip = 0, int take = 32, CancellationToken token = default); + Task> GetOperationsAsync( + int idWell, + int? opertaionType = null, + IEnumerable sectionTypeIds = null, + IEnumerable operationCategoryIds = null, + DateTime begin = default, + DateTime end = default, + int skip = 0, + int take = 32, + CancellationToken token = default); Task GetAsync(int id, CancellationToken token); - Task InsertAsync(WellOperationDto wellOperationDto, - int idWell, CancellationToken token); - Task InsertRangeAsync(int idWell, IEnumerable wellOperationDtos, CancellationToken token); - Task UpdateAsync(int idWell, int idSection, WellOperationDto item, + Task UpdateAsync(int idWell, int idOperation, WellOperationDto item, CancellationToken token); Task DeleteAsync(IEnumerable ids, CancellationToken token); diff --git a/AsbCloudDb/Model/WellOperation.cs b/AsbCloudDb/Model/WellOperation.cs index ca413845..18dd678d 100644 --- a/AsbCloudDb/Model/WellOperation.cs +++ b/AsbCloudDb/Model/WellOperation.cs @@ -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; } } } diff --git a/AsbCloudInfrastructure/Services/WellOperationService.cs b/AsbCloudInfrastructure/Services/WellOperationService.cs index 25bcb065..910cb9b9 100644 --- a/AsbCloudInfrastructure/Services/WellOperationService.cs +++ b/AsbCloudInfrastructure/Services/WellOperationService.cs @@ -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> GetAllByWellIdAsync(int idWell, - int skip = 0, int take = 32, CancellationToken token = default) + public async Task> GetOperationsAsync( + int idWell, + int? opertaionType = default, + IEnumerable sectionTypeIds = default, + IEnumerable 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 { 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 InsertAsync(WellOperationDto wellOperationDto, - int idWell, CancellationToken token = default) - { - var entity = wellOperationDto.Adapt(); - context.WellOperations.Add(entity); - return await context.SaveChangesAsync(token) - .ConfigureAwait(false); - } - public async Task InsertRangeAsync(int idWell, IEnumerable wellOperationDtos, CancellationToken token = default) @@ -99,6 +116,8 @@ namespace AsbCloudInfrastructure.Services foreach(var operationDto in wellOperationDtos) { var entity = operationDto.Adapt(); + entity.Id = default; + entity.IdWell = idWell; context.WellOperations.Add(entity); } @@ -106,10 +125,12 @@ namespace AsbCloudInfrastructure.Services .ConfigureAwait(false); } - public async Task UpdateAsync(int idWell, int idSection, + public async Task UpdateAsync(int idWell, int idOperation, WellOperationDto item, CancellationToken token = default) { var entity = item.Adapt(); + entity.Id = idOperation; + entity.IdWell = idWell; context.WellOperations.Update(entity); return await context.SaveChangesAsync(token) .ConfigureAwait(false); diff --git a/AsbCloudWebApi/Controllers/WellOperationController.cs b/AsbCloudWebApi/Controllers/WellOperationController.cs index 9248cb99..d801a02f 100644 --- a/AsbCloudWebApi/Controllers/WellOperationController.cs +++ b/AsbCloudWebApi/Controllers/WellOperationController.cs @@ -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 } /// - /// Возвращает весь список операций на скважине + /// Отфильтрованный список операций на скважине. Если не применять фильтр, то вернется весь список. Сортированный по глубине затем по дате /// /// id скважины - /// Для пагинации кол-во записей пропустить - /// Для пагинации кол-во записей - /// Токен отмены задачи - /// Список операций на скважине + /// фильтр по план = 0, факт = 1 + /// фильтр по списку id конструкций секции + /// фильтр по списку id категорий операции + /// фильтр по началу операции + /// фильтр по окончанию операции + /// + /// + /// + /// Список операций на скважине в контейнере для постраничного просмотра [HttpGet] [ProducesResponseType(typeof(PaginationContainer), (int)System.Net.HttpStatusCode.OK)] - public async Task GetAllAsync(int idWell, int skip = 0, int take = 32, + public async Task GetAllAsync( + int idWell, + int? opertaionType = default, + [FromQuery] IEnumerable sectionTypeIds = default, + [FromQuery] IEnumerable 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); }