forked from ddrilling/AsbCloudServer
Рефакторинг WellOperationRepository
This commit is contained in:
parent
2734b674ce
commit
88c928cd5d
@ -1,5 +1,5 @@
|
|||||||
using AsbCloudApp.Data;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Generic;
|
using AsbCloudApp.Data.WellOperation;
|
||||||
|
|
||||||
namespace AsbCloudApp.Repositories
|
namespace AsbCloudApp.Repositories
|
||||||
{
|
{
|
||||||
|
@ -4,6 +4,7 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using AsbCloudApp.Data.WellOperation;
|
||||||
|
|
||||||
namespace AsbCloudApp.Repositories
|
namespace AsbCloudApp.Repositories
|
||||||
{
|
{
|
||||||
@ -18,23 +19,7 @@ namespace AsbCloudApp.Repositories
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
IEnumerable<WellSectionTypeDto> GetSectionTypes();
|
IEnumerable<WellSectionTypeDto> GetSectionTypes();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// список плановых операций для сопоставления
|
|
||||||
/// <param name="idWell"></param>
|
|
||||||
/// <param name="currentDate"></param>
|
|
||||||
/// <param name="token"></param>
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
Task<WellOperationPlanDto> GetOperationsPlanAsync(int idWell, DateTime? currentDate, CancellationToken token);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// дата/время первой операции по скважине
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="idWell"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
DateTimeOffset? FirstOperationDate(int idWell);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Получить страницу списка операций
|
/// Получить страницу списка операций
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="request"></param>
|
/// <param name="request"></param>
|
||||||
@ -42,15 +27,7 @@ namespace AsbCloudApp.Repositories
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<IEnumerable<WellOperationDto>> GetAsync(WellOperationRequest request, CancellationToken token);
|
Task<IEnumerable<WellOperationDto>> GetAsync(WellOperationRequest request, CancellationToken token);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Получить список операций по запросу
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="request"></param>
|
|
||||||
/// <param name="token"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
Task<IEnumerable<WellOperationDataDto>> GetAsync(WellsOperationRequest request, CancellationToken token);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Получить страницу списка операций
|
/// Получить страницу списка операций
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="request"></param>
|
/// <param name="request"></param>
|
||||||
@ -58,39 +35,30 @@ namespace AsbCloudApp.Repositories
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<PaginationContainer<WellOperationDto>> GetPageAsync(WellOperationRequest request, CancellationToken token);
|
Task<PaginationContainer<WellOperationDto>> GetPageAsync(WellOperationRequest request, CancellationToken token);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Получить операцию по id
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="id"></param>
|
|
||||||
/// <param name="token"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
Task<WellOperationDto?> GetOrDefaultAsync(int id, CancellationToken token);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Получить статистику операции по скважине с группировкой по категориям
|
/// Получить статистику операции по скважине с группировкой по категориям
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="request"></param>
|
/// <param name="request"></param>
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<IEnumerable<WellGroupOpertionDto>> GetGroupOperationsStatAsync(
|
Task<IEnumerable<WellGroupOpertionDto>> GetGroupOperationsStatAsync(WellOperationRequest request, CancellationToken token);
|
||||||
WellOperationRequest request,
|
|
||||||
CancellationToken token);
|
/// <summary>
|
||||||
|
/// Добавить несколько операций
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="dtos"></param>
|
||||||
|
/// <param name="deleteBeforeInsert"></param>
|
||||||
|
/// <param name="token"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<int> InsertRangeAsync(IEnumerable<WellOperationDto> dtos, bool deleteBeforeInsert, CancellationToken token);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Добавить несколько операций за один раз
|
/// Обновить несколько существующую операций
|
||||||
/// </summary>
|
|
||||||
/// <param name="wellOperationDtos"></param>
|
|
||||||
/// <param name="token"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
Task<int> InsertRangeAsync(IEnumerable<WellOperationDto> wellOperationDtos, CancellationToken token);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Обновить существующую операцию
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="dto"></param>
|
/// <param name="dto"></param>
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<int> UpdateAsync(WellOperationDto dto, CancellationToken token);
|
Task<int> UpdateRangeAsync(IEnumerable<WellOperationDto> dtos, CancellationToken token);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Удалить операции по id
|
/// Удалить операции по id
|
||||||
@ -98,7 +66,7 @@ namespace AsbCloudApp.Repositories
|
|||||||
/// <param name="ids"></param>
|
/// <param name="ids"></param>
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<int> DeleteAsync(IEnumerable<int> ids, CancellationToken token);
|
Task<int> DeleteRangeAsync(IEnumerable<int> ids, CancellationToken token);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Получить секции скважин из операций ГГД. Секцие поделены на плановые и фактические.
|
/// Получить секции скважин из операций ГГД. Секцие поделены на плановые и фактические.
|
||||||
@ -116,23 +84,5 @@ namespace AsbCloudApp.Repositories
|
|||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<DatesRangeDto?> GetDatesRangeAsync(int idWell, int idType, CancellationToken cancellationToken);
|
Task<DatesRangeDto?> GetDatesRangeAsync(int idWell, int idType, CancellationToken cancellationToken);
|
||||||
|
}
|
||||||
/// <summary>
|
|
||||||
/// Удаление полных дубликатов операций по всем скважинам
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="onProgressCallback"></param>
|
|
||||||
/// <param name="token"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
Task<int> RemoveDuplicates(Action<string, double?> onProgressCallback, CancellationToken token);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Усечение пересекающейся последующей операции по дате и глубине забоя
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="geDate">Фильтр по дате. Если хоть одна операция попадет в в фильтр, то будет обработана вся скважина, а не только эта операция</param>
|
|
||||||
/// <param name="leDate">Фильтр по дате. Если хоть одна операция попадет в в фильтр, то будет обработана вся скважина, а не только эта операция</param>
|
|
||||||
/// <param name="onProgressCallback"></param>
|
|
||||||
/// <param name="token"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
Task<int> TrimOverlapping(DateTimeOffset? geDate, DateTimeOffset leDate, Action<string, double?> onProgressCallback, CancellationToken token);
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -3,110 +3,50 @@ using System.Collections.Generic;
|
|||||||
|
|
||||||
namespace AsbCloudApp.Requests
|
namespace AsbCloudApp.Requests
|
||||||
{
|
{
|
||||||
/// <summary>
|
public class WellOperationRequest : RequestBase
|
||||||
/// параметры для запроса списка операций
|
{
|
||||||
/// </summary>
|
/// <summary>
|
||||||
public class WellOperationRequestBase : RequestBase
|
/// Идентификаторы скважин
|
||||||
{
|
/// </summary>
|
||||||
/// <summary>
|
public IEnumerable<int>? IdsWell { get; set; }
|
||||||
/// фильтр по дате начала операции
|
|
||||||
/// </summary>
|
|
||||||
public DateTime? GeDate { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// фильтр по дате окончания операции
|
/// Больше или равно дате начала операции
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public DateTime? LtDate { get; set; }
|
public DateTimeOffset? GeDate { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// фильтр. Больше или равно глубины скважины на начало операции.
|
/// Меньше или равно дате окончания операции
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public double? GeDepth { get; set; }
|
public DateTimeOffset? LeDate { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// фильтр. Меньше или равно глубины скважины на конец операции.
|
/// Больше или равно глубины скважины на начало операции.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public double? LeDepth { get; set; }
|
public double? GeDepth { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// фильтр по списку id категорий операции
|
/// Меньше или равно глубины скважины на конец операции.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IEnumerable<int>? OperationCategoryIds { get; set; }
|
public double? LeDepth { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// фильтр по план = 0, факт = 1
|
/// Идентификаторы категорий операции
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int? OperationType { get; set; }
|
public IEnumerable<int>? OperationCategoryIds { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// фильтр по списку id конструкций секции
|
/// Тип операций
|
||||||
/// </summary>
|
/// <list type="bullet">
|
||||||
public IEnumerable<int>? SectionTypeIds { get; set; }
|
/// <item>0 - плановая операция</item>
|
||||||
|
/// <item>1 - фактическая операция</item>
|
||||||
|
/// </list>
|
||||||
|
/// </summary>
|
||||||
|
public int? OperationType { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Параметры для запроса списка операций.
|
/// Идентификаторы конструкций секции
|
||||||
/// Базовый конструктор
|
/// </summary>
|
||||||
/// </summary>
|
public IEnumerable<int>? SectionTypeIds { get; set; }
|
||||||
public WellOperationRequestBase()
|
}
|
||||||
{ }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Параметры для запроса списка операций.
|
|
||||||
/// Копирующий конструктор
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="request"></param>
|
|
||||||
public WellOperationRequestBase(WellOperationRequestBase request)
|
|
||||||
{
|
|
||||||
GeDepth = request.GeDepth;
|
|
||||||
LeDepth = request.LeDepth;
|
|
||||||
GeDate = request.GeDate;
|
|
||||||
LtDate = request.LtDate;
|
|
||||||
|
|
||||||
OperationCategoryIds = request.OperationCategoryIds;
|
|
||||||
OperationType = request.OperationType;
|
|
||||||
SectionTypeIds = request.SectionTypeIds;
|
|
||||||
|
|
||||||
Skip = request.Skip;
|
|
||||||
Take = request.Take;
|
|
||||||
SortFields = request.SortFields;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Параметры для запроса списка операций (с id скважины)
|
|
||||||
/// </summary>
|
|
||||||
public class WellOperationRequest : WellOperationRequestBase
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// id скважины
|
|
||||||
/// </summary>
|
|
||||||
public int IdWell { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// ctor
|
|
||||||
/// </summary>
|
|
||||||
public WellOperationRequest() { }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// копирующий конструктор
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="request"></param>
|
|
||||||
/// <param name="idWell"></param>
|
|
||||||
public WellOperationRequest(WellOperationRequestBase request, int idWell)
|
|
||||||
:base(request)
|
|
||||||
{
|
|
||||||
IdWell = idWell;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Параметры для запроса списка операций (с массивом id скважин)
|
|
||||||
/// </summary>
|
|
||||||
public class WellsOperationRequest : WellOperationRequestBase
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// ids скважин
|
|
||||||
/// </summary>
|
|
||||||
public IEnumerable<int> IdsWell { get; set; } = null!;
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -1,10 +1,10 @@
|
|||||||
using System;
|
using System;
|
||||||
using AsbCloudApp.Data;
|
|
||||||
using AsbCloudApp.Data.DetectedOperation;
|
using AsbCloudApp.Data.DetectedOperation;
|
||||||
using AsbCloudApp.Requests;
|
using AsbCloudApp.Requests;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using AsbCloudApp.Data.WellOperation;
|
||||||
|
|
||||||
namespace AsbCloudApp.Services
|
namespace AsbCloudApp.Services
|
||||||
{
|
{
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using AsbCloudApp.Data.WellOperation;
|
||||||
|
|
||||||
namespace AsbCloudApp.Services
|
namespace AsbCloudApp.Services
|
||||||
{
|
{
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
using AsbCloudApp.Data;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using AsbCloudApp.Data.WellOperation;
|
||||||
|
|
||||||
namespace AsbCloudApp.Services
|
namespace AsbCloudApp.Services
|
||||||
{
|
{
|
||||||
@ -16,6 +16,6 @@ namespace AsbCloudApp.Services
|
|||||||
/// <param name="idsWells"></param>
|
/// <param name="idsWells"></param>
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<List<Dictionary<int, WellOperationDataDto>>> GetAsync(IEnumerable<int> idsWells, CancellationToken token);
|
Task<IEnumerable<Dictionary<int, WellOperationDto>>> GetAsync(IEnumerable<int> idsWells, CancellationToken token);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -115,6 +115,26 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
return entry.Entity.Id;
|
return entry.Entity.Id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual async Task<int> UpdateRangeAsync(IEnumerable<TDto> dtos, CancellationToken token)
|
||||||
|
{
|
||||||
|
if (!dtos.Any())
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
var ids = dtos.Select(d => d.Id);
|
||||||
|
|
||||||
|
var countExistingEntities = await dbSet
|
||||||
|
.Where(d => ids.Contains(d.Id))
|
||||||
|
.CountAsync(token);
|
||||||
|
|
||||||
|
if (ids.Count() > countExistingEntities)
|
||||||
|
return ICrudRepository<TDto>.ErrorIdNotFound;
|
||||||
|
|
||||||
|
var entities = dtos.Select(Convert);
|
||||||
|
dbContext.Set<TEntity>().UpdateRange(entities);
|
||||||
|
|
||||||
|
return await dbContext.SaveChangesAsync(token);
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public virtual Task<int> DeleteAsync(int id, CancellationToken token)
|
public virtual Task<int> DeleteAsync(int id, CancellationToken token)
|
||||||
{
|
{
|
||||||
@ -129,6 +149,14 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
return affected;
|
return affected;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual async Task<int> DeleteRangeAsync(IEnumerable<int> ids, CancellationToken token)
|
||||||
|
{
|
||||||
|
var query = dbContext.Set<TEntity>().Where(e => ids.Contains(e.Id));
|
||||||
|
dbContext.Set<TEntity>().RemoveRange(query);
|
||||||
|
|
||||||
|
return await dbContext.SaveChangesAsync(token);
|
||||||
|
}
|
||||||
|
|
||||||
protected virtual TDto Convert(TEntity src) => src.Adapt<TDto>();
|
protected virtual TDto Convert(TEntity src) => src.Adapt<TDto>();
|
||||||
|
|
||||||
protected virtual TEntity Convert(TDto src) => src.Adapt<TEntity>();
|
protected virtual TEntity Convert(TDto src) => src.Adapt<TEntity>();
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
using AsbCloudApp.Data;
|
using AsbCloudApp.Repositories;
|
||||||
using AsbCloudApp.Repositories;
|
|
||||||
using AsbCloudDb.Model;
|
using AsbCloudDb.Model;
|
||||||
using Mapster;
|
using Mapster;
|
||||||
using Microsoft.Extensions.Caching.Memory;
|
using Microsoft.Extensions.Caching.Memory;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using AsbCloudApp.Data.WellOperation;
|
||||||
|
|
||||||
namespace AsbCloudInfrastructure.Repository;
|
namespace AsbCloudInfrastructure.Repository;
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user