forked from ddrilling/AsbCloudServer
Получение записи ГГД по Id
This commit is contained in:
parent
d78f33470e
commit
a63793f339
@ -12,6 +12,14 @@ namespace AsbCloudApp.Repositories
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IWellOperationRepository
|
public interface IWellOperationRepository
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Получить запись по Id
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<WellOperationDto?> GetOrDefaultByIdAsync(int id, CancellationToken cancellationToken = default);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Список секций
|
/// Список секций
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -41,6 +41,35 @@ public class WellOperationRepository : CrudRepositoryBase<WellOperationDto, Well
|
|||||||
LazyWellSectionTypes = new(() => GetSectionTypes().ToDictionary(c => c.Id));
|
LazyWellSectionTypes = new(() => GetSectionTypes().ToDictionary(c => c.Id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<WellOperationDto?> GetOrDefaultByIdAsync(int id, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
var entity = await dbContext.WellOperations.FirstOrDefaultAsync(e => e.Id == id, cancellationToken);
|
||||||
|
|
||||||
|
if (entity == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
var firstWellOperation = await dbContext.WellOperations.Where(o => o.IdWell == entity.IdWell &&
|
||||||
|
o.IdType == entity.IdType)
|
||||||
|
.OrderBy(o => o.DateStart)
|
||||||
|
.FirstAsync(cancellationToken);
|
||||||
|
|
||||||
|
var operationsWithNpt = await dbContext.WellOperations
|
||||||
|
.Where(o => WellOperationCategory.NonProductiveTimeSubIds.Contains(o.IdCategory) &&
|
||||||
|
o.IdWell == entity.IdWell &&
|
||||||
|
o.IdType == entity.IdType)
|
||||||
|
.ToArrayAsync(cancellationToken);
|
||||||
|
|
||||||
|
var timezoneOffset = wellService.GetTimezone(entity.IdWell).Offset;
|
||||||
|
|
||||||
|
var dto = Convert(entity, timezoneOffset);
|
||||||
|
dto.Day = (entity.DateStart - firstWellOperation.DateStart).TotalDays;
|
||||||
|
dto.NptHours = operationsWithNpt
|
||||||
|
.Where(o => o.DateStart <= entity.DateStart)
|
||||||
|
.Sum(o => o.DurationHours);
|
||||||
|
|
||||||
|
return dto;
|
||||||
|
}
|
||||||
|
|
||||||
public IEnumerable<WellSectionTypeDto> GetSectionTypes() =>
|
public IEnumerable<WellSectionTypeDto> GetSectionTypes() =>
|
||||||
memoryCache
|
memoryCache
|
||||||
.GetOrCreateBasic(dbContext.WellSectionTypes)
|
.GetOrCreateBasic(dbContext.WellSectionTypes)
|
||||||
@ -209,9 +238,7 @@ public class WellOperationRepository : CrudRepositoryBase<WellOperationDto, Well
|
|||||||
var count = 0;
|
var count = 0;
|
||||||
foreach (var wellOperationsWithType in groupedByWellAndType)
|
foreach (var wellOperationsWithType in groupedByWellAndType)
|
||||||
{
|
{
|
||||||
var firstWellOperation = wellOperationsWithType
|
var firstWellOperation = wellOperationsWithType.MinBy(e => e.DateStart);
|
||||||
.OrderBy(e => e.DateStart)
|
|
||||||
.FirstOrDefault()!;
|
|
||||||
|
|
||||||
var operationsWithNpt = wellOperationsWithType
|
var operationsWithNpt = wellOperationsWithType
|
||||||
.Where(o => WellOperationCategory.NonProductiveTimeSubIds.Contains(o.IdCategory));
|
.Where(o => WellOperationCategory.NonProductiveTimeSubIds.Contains(o.IdCategory));
|
||||||
@ -225,10 +252,12 @@ public class WellOperationRepository : CrudRepositoryBase<WellOperationDto, Well
|
|||||||
if (request.Take != null)
|
if (request.Take != null)
|
||||||
filteredWellOperations = filteredWellOperations.Take((int)request.Take);
|
filteredWellOperations = filteredWellOperations.Take((int)request.Take);
|
||||||
|
|
||||||
|
var timezoneOffset = wellService.GetTimezone(wellOperationsWithType.Key.IdWell).Offset;
|
||||||
|
|
||||||
var dtos = filteredWellOperations
|
var dtos = filteredWellOperations
|
||||||
.Select(entity =>
|
.Select(entity =>
|
||||||
{
|
{
|
||||||
var dto = Convert(entity);
|
var dto = Convert(entity, timezoneOffset);
|
||||||
dto.Day = (entity.DateStart - firstWellOperation.DateStart).TotalDays;
|
dto.Day = (entity.DateStart - firstWellOperation.DateStart).TotalDays;
|
||||||
dto.NptHours = operationsWithNpt
|
dto.NptHours = operationsWithNpt
|
||||||
.Where(o => o.DateStart <= entity.DateStart)
|
.Where(o => o.DateStart <= entity.DateStart)
|
||||||
@ -427,15 +456,11 @@ public class WellOperationRepository : CrudRepositoryBase<WellOperationDto, Well
|
|||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override WellOperationDto Convert(WellOperation src)
|
private WellOperationDto Convert(WellOperation src, TimeSpan timezoneOffset)
|
||||||
{
|
{
|
||||||
//TODO: пока такое получение TimeZone скважины, нужно исправить на Lazy
|
|
||||||
//Хоть мы и тянем данные из кэша, но от получения TimeZone в этом методе нужно избавиться, пока так
|
|
||||||
var timeZoneOffset = wellService.GetTimezone(src.IdWell).Offset;
|
|
||||||
|
|
||||||
var dto = src.Adapt<WellOperationDto>();
|
var dto = src.Adapt<WellOperationDto>();
|
||||||
dto.DateStart = src.DateStart.ToOffset(timeZoneOffset);
|
dto.DateStart = src.DateStart.ToOffset(timezoneOffset);
|
||||||
dto.LastUpdateDate = src.LastUpdateDate.ToOffset(timeZoneOffset);
|
dto.LastUpdateDate = src.LastUpdateDate.ToOffset(timezoneOffset);
|
||||||
|
|
||||||
dto.OperationCategoryName = LazyWellCategories.Value.TryGetValue(src.IdCategory, out WellOperationCategoryDto? category) ? category.Name : string.Empty;
|
dto.OperationCategoryName = LazyWellCategories.Value.TryGetValue(src.IdCategory, out WellOperationCategoryDto? category) ? category.Name : string.Empty;
|
||||||
dto.WellSectionTypeCaption = LazyWellSectionTypes.Value.TryGetValue(src.IdWellSectionType, out WellSectionTypeDto? sectionType) ? sectionType.Caption : string.Empty;
|
dto.WellSectionTypeCaption = LazyWellSectionTypes.Value.TryGetValue(src.IdWellSectionType, out WellSectionTypeDto? sectionType) ? sectionType.Caption : string.Empty;
|
||||||
|
@ -201,6 +201,29 @@ public class WellOperationController : ControllerBase
|
|||||||
return Ok(result);
|
return Ok(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Получение записи по Id
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="idWell">id скважины</param>
|
||||||
|
/// <param name="id">id операции</param>
|
||||||
|
/// <param name="token"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpGet("{id}")]
|
||||||
|
[Permission]
|
||||||
|
[ProducesResponseType(typeof(WellOperationDto), StatusCodes.Status200OK)]
|
||||||
|
public async Task<IActionResult> GetByIdAsync(int idWell, int id, CancellationToken token)
|
||||||
|
{
|
||||||
|
if (!await CanUserAccessToWellAsync(idWell, token))
|
||||||
|
return Forbid();
|
||||||
|
|
||||||
|
var dto = await wellOperationRepository.GetOrDefaultByIdAsync(id, token);
|
||||||
|
|
||||||
|
if (dto == null)
|
||||||
|
return NoContent();
|
||||||
|
|
||||||
|
return Ok(dto);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Создает excel файл с "сетевым графиком"
|
/// Создает excel файл с "сетевым графиком"
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
Loading…
Reference in New Issue
Block a user