forked from ddrilling/AsbCloudServer
рефакторинг
This commit is contained in:
parent
0880c3b75c
commit
494fd2a107
@ -8,9 +8,9 @@ namespace AsbCloudApp.Data.Subsystems
|
||||
public class SubsystemActiveWellStatDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Идентификатор скважины
|
||||
/// Активная скважина
|
||||
/// </summary>
|
||||
public int IdWell { get; set; }
|
||||
public WellDto ActiveWell { get; set; }
|
||||
/// <summary>
|
||||
/// Наработки подсистем
|
||||
/// </summary>
|
||||
|
@ -201,24 +201,40 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
||||
|
||||
|
||||
public async Task<IEnumerable<SubsystemActiveWellStatDto>?> 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<SubsystemActiveWellStatDto>();
|
||||
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<SubsystemStatDto>()
|
||||
|
||||
};
|
||||
var detectedOperationsRequest = new DetectedOperationRequest()
|
||||
{
|
||||
IdWell = idWell,
|
||||
IdsCategories = new List<int>() {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<SubsystemOperationTimeDto>());
|
||||
var subsystemStat = CalcStat(dto, depthInterval);
|
||||
wellStat.listSubsystemStat.Concat(subsystemStat);
|
||||
ActiveWell = well,
|
||||
listSubsystemStat = new List<SubsystemStatDto>()
|
||||
|
||||
};
|
||||
var detectedOperationsRequest = new DetectedOperationRequest()
|
||||
{
|
||||
IdWell = well.Id,
|
||||
IdsCategories = new List<int>() { 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<SubsystemOperationTimeDto>());
|
||||
var subsystemStat = CalcStat(dto, depthInterval);
|
||||
wellStat.listSubsystemStat.Concat(subsystemStat);
|
||||
}
|
||||
result.Add(wellStat);
|
||||
}
|
||||
result.Add(wellStat);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
Loading…
Reference in New Issue
Block a user