forked from ddrilling/AsbCloudServer
Получение записи ГГД по Id
This commit is contained in:
parent
d78f33470e
commit
a63793f339
@ -12,6 +12,14 @@ namespace AsbCloudApp.Repositories
|
||||
/// </summary>
|
||||
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>
|
||||
|
@ -41,6 +41,35 @@ public class WellOperationRepository : CrudRepositoryBase<WellOperationDto, Well
|
||||
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() =>
|
||||
memoryCache
|
||||
.GetOrCreateBasic(dbContext.WellSectionTypes)
|
||||
@ -209,9 +238,7 @@ public class WellOperationRepository : CrudRepositoryBase<WellOperationDto, Well
|
||||
var count = 0;
|
||||
foreach (var wellOperationsWithType in groupedByWellAndType)
|
||||
{
|
||||
var firstWellOperation = wellOperationsWithType
|
||||
.OrderBy(e => e.DateStart)
|
||||
.FirstOrDefault()!;
|
||||
var firstWellOperation = wellOperationsWithType.MinBy(e => e.DateStart);
|
||||
|
||||
var operationsWithNpt = wellOperationsWithType
|
||||
.Where(o => WellOperationCategory.NonProductiveTimeSubIds.Contains(o.IdCategory));
|
||||
@ -225,10 +252,12 @@ public class WellOperationRepository : CrudRepositoryBase<WellOperationDto, Well
|
||||
if (request.Take != null)
|
||||
filteredWellOperations = filteredWellOperations.Take((int)request.Take);
|
||||
|
||||
var timezoneOffset = wellService.GetTimezone(wellOperationsWithType.Key.IdWell).Offset;
|
||||
|
||||
var dtos = filteredWellOperations
|
||||
.Select(entity =>
|
||||
{
|
||||
var dto = Convert(entity);
|
||||
var dto = Convert(entity, timezoneOffset);
|
||||
dto.Day = (entity.DateStart - firstWellOperation.DateStart).TotalDays;
|
||||
dto.NptHours = operationsWithNpt
|
||||
.Where(o => o.DateStart <= entity.DateStart)
|
||||
@ -427,15 +456,11 @@ public class WellOperationRepository : CrudRepositoryBase<WellOperationDto, Well
|
||||
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>();
|
||||
dto.DateStart = src.DateStart.ToOffset(timeZoneOffset);
|
||||
dto.LastUpdateDate = src.LastUpdateDate.ToOffset(timeZoneOffset);
|
||||
dto.DateStart = src.DateStart.ToOffset(timezoneOffset);
|
||||
dto.LastUpdateDate = src.LastUpdateDate.ToOffset(timezoneOffset);
|
||||
|
||||
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;
|
||||
|
@ -201,6 +201,29 @@ public class WellOperationController : ControllerBase
|
||||
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>
|
||||
/// Создает excel файл с "сетевым графиком"
|
||||
/// </summary>
|
||||
|
Loading…
Reference in New Issue
Block a user