forked from ddrilling/AsbCloudServer
рефакторинг
This commit is contained in:
parent
0880c3b75c
commit
494fd2a107
@ -8,9 +8,9 @@ namespace AsbCloudApp.Data.Subsystems
|
|||||||
public class SubsystemActiveWellStatDto
|
public class SubsystemActiveWellStatDto
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Идентификатор скважины
|
/// Активная скважина
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int IdWell { get; set; }
|
public WellDto ActiveWell { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Наработки подсистем
|
/// Наработки подсистем
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -201,24 +201,40 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
|||||||
|
|
||||||
|
|
||||||
public async Task<IEnumerable<SubsystemActiveWellStatDto>?> GetStatByActiveWell(int idCompany, DateTime? gtDate, DateTime? ltDate, CancellationToken token)
|
public async Task<IEnumerable<SubsystemActiveWellStatDto>?> GetStatByActiveWell(int idCompany, DateTime? gtDate, DateTime? ltDate, CancellationToken token)
|
||||||
{
|
{
|
||||||
var activeWell = await GetActiveWellByCompany(idCompany, token);
|
var activeWell = await GetActiveWellByCompany(idCompany, token);
|
||||||
var telemetryIds = activeWell.Select(w => w.IdTelemetry).Distinct();
|
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
|
var query = db.SubsystemOperationTimes
|
||||||
.Where(o => telemetryIds.Contains(o.IdTelemetry))
|
.Where(o => telemetryIds.Contains(o.IdTelemetry))
|
||||||
.AsNoTracking();
|
.AsNoTracking();
|
||||||
DateTime today = DateTime.Today;
|
|
||||||
if (!gtDate.HasValue)
|
if (gtDate is not null)
|
||||||
{
|
{
|
||||||
gtDate = today;
|
var beginUTC = ExtractDate(gtDate.Value);
|
||||||
}
|
query = query.Where(d => d.DateStart >= beginUTC);
|
||||||
query = query.Where(o => o.DateStart >= gtDate.Value.ToUniversalTime());
|
}
|
||||||
|
//query = query.Where(o => o.DateStart >= DateTime.Today.ToUtcDateTimeOffset(_well.Timezone.Hours));
|
||||||
|
|
||||||
if (!ltDate.HasValue)
|
if (ltDate is not null)
|
||||||
{
|
{
|
||||||
ltDate = today.AddDays(-1);
|
var endUTC = ExtractDate(ltDate.Value);
|
||||||
}
|
query = query.Where(d => d.DateEnd <= endUTC);
|
||||||
query = query.Where(o => o.DateEnd <= ltDate.Value.ToUniversalTime());
|
}
|
||||||
|
//query = query.Where(o => o.DateEnd <= DateTime.Today.AddDays(-1).ToUtcDateTimeOffset(_well.Timezone.Hours));
|
||||||
|
|
||||||
var result = new List<SubsystemActiveWellStatDto>();
|
var result = new List<SubsystemActiveWellStatDto>();
|
||||||
if (query is null)
|
if (query is null)
|
||||||
{
|
{
|
||||||
@ -229,33 +245,36 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
|||||||
|
|
||||||
foreach (var group in groupingSubsystemsOperationTime)
|
foreach (var group in groupingSubsystemsOperationTime)
|
||||||
{
|
{
|
||||||
var idWell = activeWell.Where(w => w.IdTelemetry == group.Key).Select(w => w.Id).FirstOrDefault();
|
var well = activeWell.Where(w => w.IdTelemetry == group.Key).FirstOrDefault();
|
||||||
var wellStat = new SubsystemActiveWellStatDto()
|
if (well != null)
|
||||||
{
|
{
|
||||||
IdWell = idWell,
|
var wellStat = new SubsystemActiveWellStatDto()
|
||||||
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 dto = subsystem.Select(s => s.Adapt<SubsystemOperationTimeDto>());
|
ActiveWell = well,
|
||||||
var subsystemStat = CalcStat(dto, depthInterval);
|
listSubsystemStat = new List<SubsystemStatDto>()
|
||||||
wellStat.listSubsystemStat.Concat(subsystemStat);
|
|
||||||
|
};
|
||||||
|
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;
|
return result;
|
||||||
|
Loading…
Reference in New Issue
Block a user