diff --git a/AsbCloudApp/Repositories/IWellOperationRepository.cs b/AsbCloudApp/Repositories/IWellOperationRepository.cs
index fcf31f00..4f9eb807 100644
--- a/AsbCloudApp/Repositories/IWellOperationRepository.cs
+++ b/AsbCloudApp/Repositories/IWellOperationRepository.cs
@@ -12,6 +12,14 @@ namespace AsbCloudApp.Repositories
///
public interface IWellOperationRepository
{
+ ///
+ /// Получить запись по Id
+ ///
+ ///
+ ///
+ ///
+ Task GetOrDefaultByIdAsync(int id, CancellationToken cancellationToken = default);
+
///
/// Список секций
///
diff --git a/AsbCloudInfrastructure/Repository/WellOperationRepository.cs b/AsbCloudInfrastructure/Repository/WellOperationRepository.cs
index 8fa9433d..d110bab3 100644
--- a/AsbCloudInfrastructure/Repository/WellOperationRepository.cs
+++ b/AsbCloudInfrastructure/Repository/WellOperationRepository.cs
@@ -41,6 +41,35 @@ public class WellOperationRepository : CrudRepositoryBase GetSectionTypes().ToDictionary(c => c.Id));
}
+ public async Task 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 GetSectionTypes() =>
memoryCache
.GetOrCreateBasic(dbContext.WellSectionTypes)
@@ -209,9 +238,7 @@ public class WellOperationRepository : CrudRepositoryBase e.DateStart)
- .FirstOrDefault()!;
+ var firstWellOperation = wellOperationsWithType.MinBy(e => e.DateStart);
var operationsWithNpt = wellOperationsWithType
.Where(o => WellOperationCategory.NonProductiveTimeSubIds.Contains(o.IdCategory));
@@ -224,11 +251,13 @@ public class WellOperationRepository : CrudRepositoryBase
{
- 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();
- 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;
diff --git a/AsbCloudWebApi/Controllers/WellOperationController.cs b/AsbCloudWebApi/Controllers/WellOperationController.cs
index eda82a08..8f20f583 100644
--- a/AsbCloudWebApi/Controllers/WellOperationController.cs
+++ b/AsbCloudWebApi/Controllers/WellOperationController.cs
@@ -201,6 +201,29 @@ public class WellOperationController : ControllerBase
return Ok(result);
}
+ ///
+ /// Получение записи по Id
+ ///
+ /// id скважины
+ /// id операции
+ ///
+ ///
+ [HttpGet("{id}")]
+ [Permission]
+ [ProducesResponseType(typeof(WellOperationDto), StatusCodes.Status200OK)]
+ public async Task 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);
+ }
+
///
/// Создает excel файл с "сетевым графиком"
///