forked from ddrilling/AsbCloudServer
Fix DrillParamsService.GetAllAsync(..)
This commit is contained in:
parent
ed5f181754
commit
df5c98838d
@ -89,16 +89,31 @@ namespace AsbCloudInfrastructure.Services
|
||||
public async Task<IEnumerable<DrillParamsDto>> GetAllAsync(int idWell,
|
||||
CancellationToken token = default)
|
||||
{
|
||||
var entities = await (from p in db.DrillParams
|
||||
where p.IdWell == idWell
|
||||
orderby p.Id
|
||||
select p)
|
||||
var entities = await db.DrillParams
|
||||
.Where(p => p.IdWell == idWell)
|
||||
.OrderBy(p=> p.Id)
|
||||
.AsNoTracking()
|
||||
.ToListAsync(token)
|
||||
.ToArrayAsync(token)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
var dto = entities.Adapt<IEnumerable<DrillParamsDto>>();
|
||||
var dtos = entities.Select(p =>
|
||||
{
|
||||
var dto = new DrillParamsDto
|
||||
{
|
||||
IdWell = p.IdWell,
|
||||
Id = p.Id,
|
||||
IdWellSectionType = p.IdWellSectionType,
|
||||
Depth = new MinMaxDto<double> { Max = p.PressureMax, Min = p.PressureMin },
|
||||
Pressure = MakeMinMaxExtended(p.PressureAvg, p.PressureMax, p.PressureMin),
|
||||
AxialLoad = MakeMinMaxExtended(p.AxialLoadAvg, p.AxialLoadMax, p.AxialLoadMin),
|
||||
Flow = MakeMinMaxExtended(p.FlowAvg, p.FlowMax, p.FlowMin),
|
||||
RotorSpeed = MakeMinMaxExtended(p.RotorSpeedAvg, p.RotorSpeedMax, p.RotorSpeedMin),
|
||||
RotorTorque = MakeMinMaxExtended(p.RotorTorqueAvg, p.RotorTorqueMax, p.RotorTorqueMin)
|
||||
};
|
||||
return dto;
|
||||
});
|
||||
|
||||
return dtos;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<DrillParamsDto>> GetCompositeAllAsync(int idWell,
|
||||
@ -181,26 +196,26 @@ namespace AsbCloudInfrastructure.Services
|
||||
{
|
||||
Id = entity.Id,
|
||||
IdWellSectionType = entity.IdWellSectionType,
|
||||
AxialLoad = GetMinMaxExtended(entity.AxialLoadAvg, entity.AxialLoadMax, entity.AxialLoadMin, drillParams.Select(x => (x.AxialLoadMin, x.AxialLoadMax))),
|
||||
AxialLoad = MakeMinMaxExtended(entity.AxialLoadAvg, entity.AxialLoadMax, entity.AxialLoadMin, drillParams.Select(x => (x.AxialLoadMin, x.AxialLoadMax))),
|
||||
Depth = new MinMaxDto<double> {
|
||||
Min = entity.DepthEnd,
|
||||
Max = entity.DepthStart
|
||||
},
|
||||
Flow = GetMinMaxExtended(entity.FlowAvg, entity.FlowMax, entity.FlowMin, drillParams.Select(x => (x.FlowMin, x.FlowMax))),
|
||||
Flow = MakeMinMaxExtended(entity.FlowAvg, entity.FlowMax, entity.FlowMin, drillParams.Select(x => (x.FlowMin, x.FlowMax))),
|
||||
IdWell = entity.IdWell,
|
||||
Pressure = GetMinMaxExtended(entity.PressureAvg, entity.PressureMax, entity.PressureMin, drillParams.Select(x => (x.PressureMin, x.PressureMax))),
|
||||
RotorSpeed = GetMinMaxExtended(entity.RotorSpeedAvg, entity.RotorSpeedMax, entity.RotorSpeedMin, drillParams.Select(x => (x.RotorSpeedMin, x.RotorSpeedMax))),
|
||||
RotorTorque = GetMinMaxExtended(entity.RotorTorqueAvg, entity.RotorTorqueMax, entity.RotorTorqueMin, drillParams.Select(x => (x.RotorTorqueMin, x.RotorTorqueMax)))
|
||||
Pressure = MakeMinMaxExtended(entity.PressureAvg, entity.PressureMax, entity.PressureMin, drillParams.Select(x => (x.PressureMin, x.PressureMax))),
|
||||
RotorSpeed = MakeMinMaxExtended(entity.RotorSpeedAvg, entity.RotorSpeedMax, entity.RotorSpeedMin, drillParams.Select(x => (x.RotorSpeedMin, x.RotorSpeedMax))),
|
||||
RotorTorque = MakeMinMaxExtended(entity.RotorTorqueAvg, entity.RotorTorqueMax, entity.RotorTorqueMin, drillParams.Select(x => (x.RotorTorqueMin, x.RotorTorqueMax)))
|
||||
};
|
||||
}
|
||||
|
||||
private static MinMaxExtendedViewDto GetMinMaxExtended(double avg, double max, double min, IEnumerable<(double min, double max)> allDrillParams)
|
||||
private static MinMaxExtendedViewDto MakeMinMaxExtended(double avg, double max, double min, IEnumerable<(double min, double max)>? allDrillParams = null)
|
||||
=> new MinMaxExtendedViewDto {
|
||||
Avg = avg,
|
||||
Max = max,
|
||||
Min = min,
|
||||
IsMax = allDrillParams.Any(mx => mx.max > max),
|
||||
IsMin = allDrillParams.Any(mn => mn.min < min)
|
||||
IsMax = allDrillParams?.Any(mx => mx.max > max) ?? false,
|
||||
IsMin = allDrillParams?.Any(mn => mn.min < min) ?? false
|
||||
};
|
||||
}
|
||||
#nullable disable
|
||||
|
Loading…
Reference in New Issue
Block a user