using Microsoft.AspNetCore.Mvc;
using System.Net;
using System.Net.Http.Headers;
using Microsoft.Extensions.Hosting.Internal;
using Microsoft.AspNetCore.Http.Extensions;
using IStation.Untity;
using Furion.DynamicApiController;
using System.ComponentModel.DataAnnotations;
using Mapster;
namespace IStation.Application
{
///
/// PumpCurve
///
[Route("Product/PumpCurve/Logic")]
[ApiDescriptionSettings("Product", Name = "泵曲线", Order = 399)]
public class PumpCurve_LogicController : IDynamicApiController
{
///
/// 通过 EnginePumpID 获取频率曲线(业务)
///
[Route("GetHZByEnginePumpID@V1.0")]
[HttpGet]
public PumpHZCurveLogicDto GetHZByEnginePumpID
(
[Required,Range(1,long.MaxValue,ErrorMessage ="CorpID 必须大于0")]
long CorpID,
[Required,Range(1,long.MaxValue,ErrorMessage ="EnginePumpID 必须大于0")]
long EnginePumpID,
[Required]
double HZ
)
{
var pump = new Service.Product().GetChildPumpByEnginePumpID(CorpID, EnginePumpID);
if (pump == null)
{
throw new Exception("未检索到泵信息");
}
var curve = new Service.PumpCurveExMapping().GetDefaultWorkingByPumpID(pump.CorpID, pump.ID);
if (curve == null)
{
throw new Exception("未检索到泵曲线信息");
}
var vm = new PumpHZCurveLogicDto();
if (HZ > 49.5)
{
if (curve.CurveInfo != null && curve.CurveInfo.CurveQH != null)
{
vm.PointQH = curve.CurveInfo.CurveQH.GetFitPoints(20)?.Select(x=>new CurvePointDto(x.X,x.Y)).ToList();
if (curve.CurveInfo.CurveQP != null)
{
vm.PointQP = curve.CurveInfo.CurveQP.GetFitPoints(20)?.Select(x => new CurvePointDto(x.X, x.Y)).ToList();
}
}
}
else
{
if (curve.CurveInfo != null)
{
vm.PointQH = curve.CalcuCurveQhByHz(HZ).GetFitPoints(20)?.Select(x => new CurvePointDto(x.X, x.Y)).ToList();
vm.PointQP = curve.CalcuCurveQpByHz(HZ).GetFitPoints(20)?.Select(x => new CurvePointDto(x.X, x.Y)).ToList();
}
}
return vm;
}
///
/// 通过 PumpID 获取频率曲线(业务)
///
[Route("GetHzByPumpID@V1.0")]
[HttpGet]
public PumpHZCurveLogicDto GetHzByPumpID
(
[Required,Range(1,long.MaxValue,ErrorMessage ="CorpID 必须大于0")]
long CorpID,
[Required,Range(1,long.MaxValue,ErrorMessage ="PumpID 必须大于0")]
long PumpID,
[Required]
double HZ
)
{
var curve = new Service.PumpCurveExMapping().GetDefaultWorkingByPumpID(CorpID,PumpID);
if (curve == null)
{
throw new Exception("未检索到泵曲线信息");
}
var vm = new PumpHZCurveLogicDto();
if (HZ > 49.5)
{
if (curve.CurveInfo != null && curve.CurveInfo.CurveQH != null)
{
vm.PointQH = curve.CurveInfo.CurveQH.GetFitPoints(20)?.Select(x => new CurvePointDto(x.X, x.Y)).ToList();
if (curve.CurveInfo.CurveQP != null)
{
vm.PointQP = curve.CurveInfo.CurveQP.GetFitPoints(20)?.Select(x => new CurvePointDto(x.X, x.Y)).ToList();
}
}
}
else
{
if (curve.CurveInfo != null)
{
vm.PointQH = curve.CalcuCurveQhByHz(HZ).GetFitPoints(20)?.Select(x => new CurvePointDto(x.X, x.Y)).ToList();
vm.PointQP = curve.CalcuCurveQpByHz(HZ).GetFitPoints(20)?.Select(x => new CurvePointDto(x.X, x.Y)).ToList();
}
}
return vm;
}
///
/// 计算泵并联曲线(业务)
///
[Route("CalculateParallel@V1.0")]
[HttpPost]
public PumpParallelCurveLogicDto CalculateParallel([Required] PumpParallelCurveInput input)
{
var service = new Service.PumpCurveExMapping();
var curve_qh_list = new List();
var curve_qp_list = new List();
var h_min = double.MinValue;
var h_max = double.MaxValue;
foreach (var item in input.Items)
{
var curve = service.GetDefaultWorkingByPumpID(input.CorpID, item.PumpID);
if (curve == null)
continue;
if (item.HZ > 49.5)
{
if (curve.CurveInfo != null && curve.CurveInfo.CurveQH != null)
{
curve_qh_list.Add(curve.CurveInfo.CurveQH);
if (curve.CurveInfo.CurveQP != null)
{
curve_qp_list.Add(curve.CurveInfo.CurveQP);
}
}
}
else
{
var curve_qh = curve.CalcuCurveQhByHz(item.HZ);
if (curve_qh != null)
{
curve_qh_list.Add(curve_qh);
var curve_qp = curve.CalcuCurveQpByHz(item.HZ);
if (curve_qp != null)
{
curve_qp_list.Add(curve_qp);
}
}
}
var curve_qh_last = curve_qh_list.LastOrDefault();
if (curve_qh_last != null)
{
var curve_qh_first_point = curve_qh_last.GetFirstFitPoint();
h_max = Math.Min(h_max, curve_qh_first_point.Y);
var curve_qh_last_point = curve_qh_last.GetLastFitPoint();
h_min = Math.Max(h_min, curve_qh_last_point.Y);
}
}
if (curve_qh_list.Count < 2)
{
throw new Exception("NULL1");
}
if (h_max < h_min)
{
throw new Exception("NULL2");
}
double space_h = (h_max - h_min) / 19;
var points_qh_parallel = new List();
var points_qp_parallel = new List();
for (var h = h_min; h <= h_max; h = h + space_h)
{
double total_flow = 0;
double total_power = 0;
for (int j = 0; j < curve_qh_list.Count; j++)
{
var curve_qh = curve_qh_list[j];
var curve_qp = curve_qp_list[j];
var pts = Model.FitCurveHelper.GetInterPointX(curve_qh, h);
if (pts != null && pts.Count > 0)
{
var q = pts.Last().X;
total_flow += q;
total_power += curve_qp.GetFitPointY(q);
}
}
points_qh_parallel.Add(new Model.CurvePoint(total_flow, h));
points_qp_parallel.Add(new Model.CurvePoint(total_flow, total_power));
}
var vm = new PumpParallelCurveLogicDto();
vm.PointQH = Model.FitCurveHelper.GetFitPoints(points_qh_parallel, 20)?.Select(x => new CurvePointDto(x.X, x.Y)).ToList();
vm.PointQP = Model.FitCurveHelper.GetFitPoints(points_qp_parallel, 20)?.Select(x => new CurvePointDto(x.X, x.Y)).ToList();
return vm;
}
///
/// 计算泵并联曲线拓展(包含单泵曲线)(业务)
///
[Route("CalculateParallelEx@V1.0")]
[HttpPost]
public List CalculateParallelEx([Required] PumpParallelCurveInput input)
{
var service_product = new Service.Product();
var service_curve = new Service.PumpCurveExMapping();
var vm_list = new List();
var curve_qh_list = new List();
var curve_qp_list = new List();
var h_min = double.MinValue;
var h_max = double.MaxValue;
foreach (var item in input.Items)
{
var pump = service_product.GetByID(input.CorpID, item.PumpID);
if (pump == null)
continue;
var curve = service_curve.GetDefaultWorkingByPumpID(pump.CorpID, pump.ID);
if (curve == null)
continue;
if (item.HZ > 49.5)
{
if (curve.CurveInfo != null && curve.CurveInfo.CurveQH != null)
{
curve_qh_list.Add(curve.CurveInfo.CurveQH);
if (curve.CurveInfo.CurveQP != null)
{
curve_qp_list.Add(curve.CurveInfo.CurveQP);
}
}
}
else
{
var curve_qh = curve.CalcuCurveQhByHz(item.HZ);
if (curve_qh != null)
{
curve_qh_list.Add(curve_qh);
var curve_qp = curve.CalcuCurveQpByHz(item.HZ);
if (curve_qp != null)
{
curve_qp_list.Add(curve_qp);
}
}
}
var curve_qh_last = curve_qh_list.LastOrDefault();
if (curve_qh_last != null)
{
var curve_qh_first_point = curve_qh_last.GetFirstFitPoint();
h_max = Math.Min(h_max, curve_qh_first_point.Y);
var curve_qh_last_point = curve_qh_last.GetLastFitPoint();
h_min = Math.Max(h_min, curve_qh_last_point.Y);
}
var vm_parallel_curve = new PumpParallelCurveExLogicDto();
vm_parallel_curve.Type = 0;
vm_parallel_curve.Name = pump.Name;
vm_parallel_curve.PointQH = curve_qh_list.LastOrDefault()?.GetFitPoints(20)?.Select(x => new CurvePointDto(x.X, x.Y)).ToList();
vm_parallel_curve.PointQP = curve_qp_list.LastOrDefault()?.GetFitPoints(20)?.Select(x => new CurvePointDto(x.X, x.Y)).ToList();
vm_list.Add(vm_parallel_curve);
}
if (curve_qh_list.Count < 2)
{
throw new Exception("NULL1");
}
if (h_max < h_min)
{
throw new Exception("NULL2");
}
double space_h = (h_max - h_min) / 19;
var points_qh_parallel = new List();
var points_qp_parallel = new List();
for (var h = h_min; h <= h_max; h = h + space_h)
{
double total_flow = 0;
double total_power = 0;
for (int j = 0; j < curve_qh_list.Count; j++)
{
var curve_qh = curve_qh_list[j];
var curve_qp = curve_qp_list[j];
var pts = Model.FitCurveHelper.GetInterPointX(curve_qh, h);
if (pts != null && pts.Count > 0)
{
var q = pts.Last().X;
total_flow += q;
total_power += curve_qp.GetFitPointY(q);
}
}
points_qh_parallel.Add(new Model.CurvePoint(total_flow, h));
points_qp_parallel.Add(new Model.CurvePoint(total_flow, total_power));
}
var vm = new PumpParallelCurveExLogicDto();
vm.Type = 1;
vm.Name = "并联曲线";
vm.PointQH = Model.FitCurveHelper.GetFitPoints(points_qh_parallel, 20)?.Select(x => new CurvePointDto(x.X, x.Y)).ToList();
vm.PointQP = Model.FitCurveHelper.GetFitPoints(points_qp_parallel, 20)?.Select(x => new CurvePointDto(x.X, x.Y)).ToList();
vm_list.Insert(0, vm);
return vm_list;
}
///
/// 计算机泵并联曲线(业务)
///
[Route("CalculateEnginePumpParallel@V1.0")]
[HttpPost]
public PumpParallelCurveLogicDto CalculateEnginePumpParallel([Required] EnginePumpParallelCurveInput input)
{
var service_product = new Service.Product();
var service_curve = new Service.PumpCurveExMapping();
var curve_qh_list = new List();
var curve_qp_list = new List();
var h_min = double.MinValue;
var h_max = double.MaxValue;
foreach (var item in input.Items)
{
var pump = service_product.GetChildPumpByEnginePumpID(input.CorpID, item.EnginePumpID);
if (pump == null)
continue;
var curve = service_curve.GetDefaultWorkingByPumpID(pump.CorpID, pump.ID);
if (curve == null)
continue;
if (item.HZ > 49.5)
{
if (curve.CurveInfo != null && curve.CurveInfo.CurveQH != null)
{
curve_qh_list.Add(curve.CurveInfo.CurveQH);
if (curve.CurveInfo.CurveQP != null)
{
curve_qp_list.Add(curve.CurveInfo.CurveQP);
}
}
}
else
{
var curve_qh = curve.CalcuCurveQhByHz(item.HZ);
if (curve_qh != null)
{
curve_qh_list.Add(curve_qh);
var curve_qp = curve.CalcuCurveQpByHz(item.HZ);
if (curve_qp != null)
{
curve_qp_list.Add(curve_qp);
}
}
}
var curve_qh_last = curve_qh_list.LastOrDefault();
if (curve_qh_last != null)
{
var curve_qh_first_point = curve_qh_last.GetFirstFitPoint();
h_max = Math.Min(h_max, curve_qh_first_point.Y);
var curve_qh_last_point = curve_qh_last.GetLastFitPoint();
h_min = Math.Max(h_min, curve_qh_last_point.Y);
}
}
if (curve_qh_list.Count < 2)
{
throw new Exception("NULL1");
}
if (h_max < h_min)
{
throw new Exception("NULL2");
}
double space_h = (h_max - h_min) / 19;
var points_qh_parallel = new List();
var points_qp_parallel = new List();
for (var h = h_min; h <= h_max; h = h + space_h)
{
double total_flow = 0;
double total_power = 0;
for (int j = 0; j < curve_qh_list.Count; j++)
{
var curve_qh = curve_qh_list[j];
var curve_qp = curve_qp_list[j];
var pts = Model.FitCurveHelper.GetInterPointX(curve_qh, h);
if (pts != null && pts.Count > 0)
{
var q = pts.Last().X;
total_flow += q;
total_power += curve_qp.GetFitPointY(q);
}
}
points_qh_parallel.Add(new Model.CurvePoint(total_flow, h));
points_qp_parallel.Add(new Model.CurvePoint(total_flow, total_power));
}
var vm = new PumpParallelCurveLogicDto();
vm.PointQH = Model.FitCurveHelper.GetFitPoints(points_qh_parallel, 20)?.Select(x => new CurvePointDto(x.X, x.Y)).ToList();
vm.PointQP = Model.FitCurveHelper.GetFitPoints(points_qp_parallel, 20)?.Select(x => new CurvePointDto(x.X, x.Y)).ToList();
return vm;
}
///
/// 计算机泵并联曲线拓展(包含单泵曲线)(业务)
///
[Route("CalculateEnginePumpParallelEx@V1.0")]
[HttpPost]
public List CalculateEnginePumpParallelEx([Required] EnginePumpParallelCurveInput input)
{
var service_product = new Service.Product();
var service_curve = new Service.PumpCurveExMapping();
var vm_list = new List();
var curve_qh_list = new List();
var curve_qp_list = new List();
var h_min = double.MinValue;
var h_max = double.MaxValue;
foreach (var item in input.Items)
{
var engine_pump = service_product.GetByID(input.CorpID, item.EnginePumpID);
if (engine_pump == null)
continue;
var pump = service_product.GetChildPumpByEnginePumpID(engine_pump.CorpID, engine_pump.ID);
if (pump == null)
continue;
var curve = service_curve.GetDefaultWorkingByPumpID(pump.CorpID, pump.ID);
if (curve == null)
continue;
if (item.HZ > 49.5)
{
if (curve.CurveInfo != null && curve.CurveInfo.CurveQH != null)
{
curve_qh_list.Add(curve.CurveInfo.CurveQH);
if (curve.CurveInfo.CurveQP != null)
{
curve_qp_list.Add(curve.CurveInfo.CurveQP);
}
}
}
else
{
var curve_qh = curve.CalcuCurveQhByHz(item.HZ);
if (curve_qh != null)
{
curve_qh_list.Add(curve_qh);
var curve_qp = curve.CalcuCurveQpByHz(item.HZ);
if (curve_qp != null)
{
curve_qp_list.Add(curve_qp);
}
}
}
var curve_qh_last = curve_qh_list.LastOrDefault();
if (curve_qh_last != null)
{
var curve_qh_first_point = curve_qh_last.GetFirstFitPoint();
h_max = Math.Min(h_max, curve_qh_first_point.Y);
var curve_qh_last_point = curve_qh_last.GetLastFitPoint();
h_min = Math.Max(h_min, curve_qh_last_point.Y);
}
var vm_parallel_curve = new PumpParallelCurveExLogicDto();
vm_parallel_curve.Type = 0;
vm_parallel_curve.Name = engine_pump.Name;
vm_parallel_curve.PointQH = curve_qh_list.LastOrDefault()?.GetFitPoints(20)?.Select(x => new CurvePointDto(x.X, x.Y)).ToList();
vm_parallel_curve.PointQP = curve_qp_list.LastOrDefault()?.GetFitPoints(20)?.Select(x => new CurvePointDto(x.X, x.Y)).ToList();
vm_list.Add(vm_parallel_curve);
}
if (curve_qh_list.Count < 2)
{
throw new Exception("NULL1");
}
if (h_max < h_min)
{
throw new Exception("NULL2");
}
double space_h = (h_max - h_min) / 19;
var points_qh_parallel = new List();
var points_qp_parallel = new List();
for (var h = h_min; h <= h_max; h = h + space_h)
{
double total_flow = 0;
double total_power = 0;
for (int j = 0; j < curve_qh_list.Count; j++)
{
var curve_qh = curve_qh_list[j];
var curve_qp = curve_qp_list[j];
var pts = Model.FitCurveHelper.GetInterPointX(curve_qh, h);
if (pts != null && pts.Count > 0)
{
var q = pts.Last().X;
total_flow += q;
total_power += curve_qp.GetFitPointY(q);
}
}
points_qh_parallel.Add(new Model.CurvePoint(total_flow, h));
points_qp_parallel.Add(new Model.CurvePoint(total_flow, total_power));
}
var vm = new PumpParallelCurveExLogicDto();
vm.Type = 1;
vm.Name = "并联曲线";
vm.PointQH = Model.FitCurveHelper.GetFitPoints(points_qh_parallel, 20)?.Select(x => new CurvePointDto(x.X, x.Y)).ToList();
vm.PointQP = Model.FitCurveHelper.GetFitPoints(points_qp_parallel, 20)?.Select(x => new CurvePointDto(x.X, x.Y)).ToList();
vm_list.Insert(0, vm);
return vm_list;
}
}
}