diff --git a/AsbCloudApp/Data/Subsystems/SubsystemActiveWellStatDto.cs b/AsbCloudApp/Data/Subsystems/SubsystemActiveWellStatDto.cs
index fd3c1054..a06f1064 100644
--- a/AsbCloudApp/Data/Subsystems/SubsystemActiveWellStatDto.cs
+++ b/AsbCloudApp/Data/Subsystems/SubsystemActiveWellStatDto.cs
@@ -8,9 +8,9 @@ namespace AsbCloudApp.Data.Subsystems
public class SubsystemActiveWellStatDto
{
///
- /// Идентификатор скважины
+ /// Активная скважина
///
- public int IdWell { get; set; }
+ public WellDto ActiveWell { get; set; }
///
/// Наработки подсистем
///
diff --git a/AsbCloudInfrastructure/Services/Subsystems/SubsystemOperationTimeService.cs b/AsbCloudInfrastructure/Services/Subsystems/SubsystemOperationTimeService.cs
index 65c68188..2852a52e 100644
--- a/AsbCloudInfrastructure/Services/Subsystems/SubsystemOperationTimeService.cs
+++ b/AsbCloudInfrastructure/Services/Subsystems/SubsystemOperationTimeService.cs
@@ -201,24 +201,40 @@ namespace AsbCloudInfrastructure.Services.Subsystems
public async Task?> GetStatByActiveWell(int idCompany, DateTime? gtDate, DateTime? ltDate, CancellationToken token)
- {
+ {
var activeWell = await GetActiveWellByCompany(idCompany, token);
var telemetryIds = activeWell.Select(w => w.IdTelemetry).Distinct();
+ var firstWell = activeWell.FirstOrDefault();
+ if (firstWell == null)
+ return null;
+ var _well = wellService.GetOrDefault(firstWell.Id);
+ if (_well is null || _well.Timezone is null)
+ return null;
+ DateTimeOffset ExtractDate(DateTime dateTime)
+ {
+ var dateTimeOffset = dateTime.ToUtcDateTimeOffset(_well!.Timezone.Hours);
+ var date = new DateTimeOffset(dateTimeOffset.Year, dateTimeOffset.Month, dateTimeOffset.Day, 0, 0, 0, TimeSpan.Zero);
+ return date;
+ }
+
var query = db.SubsystemOperationTimes
.Where(o => telemetryIds.Contains(o.IdTelemetry))
- .AsNoTracking();
- DateTime today = DateTime.Today;
- if (!gtDate.HasValue)
+ .AsNoTracking();
+
+ if (gtDate is not null)
{
- gtDate = today;
- }
- query = query.Where(o => o.DateStart >= gtDate.Value.ToUniversalTime());
+ var beginUTC = ExtractDate(gtDate.Value);
+ query = query.Where(d => d.DateStart >= beginUTC);
+ }
+ //query = query.Where(o => o.DateStart >= DateTime.Today.ToUtcDateTimeOffset(_well.Timezone.Hours));
- if (!ltDate.HasValue)
+ if (ltDate is not null)
{
- ltDate = today.AddDays(-1);
- }
- query = query.Where(o => o.DateEnd <= ltDate.Value.ToUniversalTime());
+ var endUTC = ExtractDate(ltDate.Value);
+ query = query.Where(d => d.DateEnd <= endUTC);
+ }
+ //query = query.Where(o => o.DateEnd <= DateTime.Today.AddDays(-1).ToUtcDateTimeOffset(_well.Timezone.Hours));
+
var result = new List();
if (query is null)
{
@@ -229,33 +245,36 @@ namespace AsbCloudInfrastructure.Services.Subsystems
foreach (var group in groupingSubsystemsOperationTime)
{
- var idWell = activeWell.Where(w => w.IdTelemetry == group.Key).Select(w => w.Id).FirstOrDefault();
- var wellStat = new SubsystemActiveWellStatDto()
+ var well = activeWell.Where(w => w.IdTelemetry == group.Key).FirstOrDefault();
+ if (well != null)
{
- IdWell = idWell,
- listSubsystemStat = new List()
-
- };
- var detectedOperationsRequest = new DetectedOperationRequest()
- {
- IdWell = idWell,
- IdsCategories = new List() {1,3},
- LtDate = ltDate,
- GtDate = gtDate,
- };
- var detectedOperations = await detectedOperationService.GetOperationsAsync(detectedOperationsRequest, token);
- if (detectedOperations is not null && detectedOperations.Any())
- {
- var depthInterval = GetDepthInterval(detectedOperations);
- var groupSubsystem = group.GroupBy(g => g.IdSubsystem);
-
- foreach (var subsystem in groupSubsystem)
+ var wellStat = new SubsystemActiveWellStatDto()
{
- var dto = subsystem.Select(s => s.Adapt());
- var subsystemStat = CalcStat(dto, depthInterval);
- wellStat.listSubsystemStat.Concat(subsystemStat);
+ ActiveWell = well,
+ listSubsystemStat = new List()
+
+ };
+ var detectedOperationsRequest = new DetectedOperationRequest()
+ {
+ IdWell = well.Id,
+ IdsCategories = new List() { 1, 3 },
+ LtDate = ltDate,
+ GtDate = gtDate,
+ };
+ var detectedOperations = await detectedOperationService.GetOperationsAsync(detectedOperationsRequest, token);
+ if (detectedOperations is not null && detectedOperations.Any())
+ {
+ var depthInterval = GetDepthInterval(detectedOperations);
+ var groupSubsystem = group.GroupBy(g => g.IdSubsystem);
+
+ foreach (var subsystem in groupSubsystem)
+ {
+ var dto = subsystem.Select(s => s.Adapt());
+ var subsystemStat = CalcStat(dto, depthInterval);
+ wellStat.listSubsystemStat.Concat(subsystemStat);
+ }
+ result.Add(wellStat);
}
- result.Add(wellStat);
}
}
return result;