forked from ddrilling/AsbCloudServer
correction SubsystemOperationTimeService
This commit is contained in:
parent
74901407c0
commit
4f27adf9ea
@ -65,9 +65,11 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
||||
if (!request.LtDate.HasValue)
|
||||
throw new ArgumentNullException(nameof(request.LtDate));
|
||||
var end = request.LtDate.Value.ToUtcDateTimeOffset(well.Timezone.Hours);
|
||||
var data = query.ToList();
|
||||
IEnumerable<SubsystemOperationTime>? data = query.ToList();
|
||||
data = Trim(data, begin, end);
|
||||
return data.Select(o => Convert(o, well));
|
||||
if (data is not null)
|
||||
return data.Select(o => Convert(o, well));
|
||||
return null;
|
||||
}
|
||||
var dtos = query.Select(o => Convert(o, well));
|
||||
return dtos;
|
||||
@ -81,23 +83,23 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
||||
var statList = CalcStat(data, request);
|
||||
return statList;
|
||||
}
|
||||
private List<SubsystemOperationTime> Trim(List<SubsystemOperationTime> data, DateTimeOffset gtDate, DateTimeOffset ltDate)
|
||||
private IEnumerable<SubsystemOperationTime>? Trim(IEnumerable<SubsystemOperationTime>? data, DateTimeOffset gtDate, DateTimeOffset ltDate)
|
||||
{
|
||||
if (data is null)
|
||||
return null;
|
||||
var ItemsNormal = data.Where(q =>
|
||||
(q.DateStart >= gtDate) && (q.DateEnd <= ltDate)).ToList();
|
||||
var itemsToTrim = data.Where(q =>
|
||||
(q.DateStart < gtDate && q.DateEnd <= ltDate && q.DateEnd > gtDate) ||
|
||||
(q.DateStart >= gtDate && q.DateEnd > ltDate && q.DateStart < ltDate) ||
|
||||
(q.DateStart < gtDate && q.DateEnd > ltDate))
|
||||
q.DateStart < gtDate || ltDate < q.DateEnd)
|
||||
.Select(o => new SubsystemOperationTime
|
||||
{
|
||||
Id = o.Id,
|
||||
DateStart = (o.DateStart >= gtDate) && (o.DateStart <= ltDate) ? o.DateStart : gtDate,
|
||||
DateEnd = (o.DateEnd >= gtDate) && (o.DateEnd <= ltDate) ? o.DateEnd : ltDate,
|
||||
DateStart = gtDate < o.DateStart ? o.DateStart : gtDate,
|
||||
DateEnd = ltDate > o.DateEnd ? o.DateEnd : ltDate,
|
||||
IdSubsystem = o.IdSubsystem,
|
||||
IdTelemetry = o.IdTelemetry,
|
||||
DepthEnd = (o.DateEnd >= gtDate) && (o.DateEnd <= ltDate) ? o.DepthEnd : null ,
|
||||
DepthStart = (o.DateStart >= gtDate) && (o.DateStart <= ltDate) ? o.DepthStart : null,
|
||||
DepthStart = gtDate > o.DateEnd ? o.DepthStart : null,
|
||||
DepthEnd = ltDate < o.DateStart ? o.DepthEnd : null,
|
||||
Subsystem = o.Subsystem,
|
||||
Telemetry = o.Telemetry
|
||||
})
|
||||
@ -140,21 +142,34 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
||||
var query = db.SubsystemOperationTimes
|
||||
.Include(o => o.Subsystem)
|
||||
.Where(o => o.IdTelemetry == well.IdTelemetry);
|
||||
|
||||
if(request.IdsSubsystems?.Any() == true)
|
||||
DateTimeOffset gtDateWellTime;
|
||||
DateTimeOffset ltDateWellTime;
|
||||
if (request.IdsSubsystems?.Any() == true)
|
||||
query = query.Where(o => request.IdsSubsystems.Contains(o.IdSubsystem));
|
||||
|
||||
|
||||
if (request.GtDate is not null && request.LtDate is not null)
|
||||
{
|
||||
query = query.Where(o => (o.DateStart >= request.GtDate.Value.ToUtcDateTimeOffset(well.Timezone.Hours))
|
||||
||(o.DateEnd <= request.LtDate.Value.ToUtcDateTimeOffset(well.Timezone.Hours)));
|
||||
gtDateWellTime = request.GtDate.Value.ToUtcDateTimeOffset(well.Timezone.Hours);
|
||||
ltDateWellTime = request.LtDate.Value.ToUtcDateTimeOffset(well.Timezone.Hours);
|
||||
//query = query.Where(o => (o.DateStart >= gtDateWellTime)
|
||||
//|| (o.DateEnd <= ltDateWellTime));
|
||||
query = query.Where(q =>
|
||||
(q.DateStart < gtDateWellTime && q.DateEnd <= ltDateWellTime && q.DateEnd > gtDateWellTime) ||
|
||||
(q.DateStart >= gtDateWellTime && q.DateEnd > ltDateWellTime && q.DateStart < ltDateWellTime) ||
|
||||
(q.DateStart < gtDateWellTime && q.DateEnd > ltDateWellTime) ||
|
||||
(q.DateStart >= gtDateWellTime && q.DateEnd <= ltDateWellTime));
|
||||
}
|
||||
else if (request.GtDate is not null)
|
||||
query = query.Where(o => o.DateStart >= request.GtDate.Value.ToUtcDateTimeOffset(well.Timezone.Hours));
|
||||
{
|
||||
gtDateWellTime = request.GtDate.Value.ToUtcDateTimeOffset(well.Timezone.Hours);
|
||||
query = query.Where(o => o.DateStart >= gtDateWellTime);
|
||||
}
|
||||
|
||||
else if (request.LtDate is not null)
|
||||
query = query.Where(o => o.DateEnd <= request.LtDate.Value.ToUtcDateTimeOffset(well.Timezone.Hours));
|
||||
{
|
||||
ltDateWellTime = request.LtDate.Value.ToUtcDateTimeOffset(well.Timezone.Hours);
|
||||
query = query.Where(o => o.DateEnd <= ltDateWellTime);
|
||||
}
|
||||
|
||||
|
||||
if (request.GtDepth is not null)
|
||||
|
Loading…
Reference in New Issue
Block a user