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 { /// /// PipeLine /// [Route("Main/PipeLine/Logic")] [ApiDescriptionSettings("Main", Name = "管路", Order = 599)] public class PipeLine_LogicController : IDynamicApiController { /// /// 通过 BelongType 和 BelongID 获取管路信息(业务) /// [Route("GetByBelongTypeAndBelongID@V1.0")] [HttpGet] public List GetByBelongTypeAndBelongID([FromQuery][Required] BelongUnderCorpInput input) { var corpId = input.CorpID; var belongType = input.BelongType; var belongId = input.BelongID; var cacheKey = $"Main_PipeLine_Logic_GetByBelongTypeAndBelongID_{corpId}_{belongType}_{belongId}"; var vm_list = MemoryCacheHelper.GetSet(cacheKey, () => { var pipe_list = new Service.PipeLine().GetByBelongTypeAndBelongID(corpId, belongType, belongId); if (pipe_list == null || pipe_list.Count < 1) return default; var vm_cache_list = pipe_list.Select(x => new PipeLineLogicDto(x)).ToList(); return vm_cache_list; }, CacheHelper.CacheLevel4); return vm_list; } /// /// 通过 BelongType 和 BelongID 获取能效管路信息(业务) /// [Route("GetEtaByBelongTypeAndBelongID@V1.0")] [HttpGet] public List GetEtaByBelongTypeAndBelongID([FromQuery][Required] BelongUnderCorpInput input) { var corpId = input.CorpID; var belongType = input.BelongType; var belongId = input.BelongID; var cacheKey = $"Main_PipeLine_Logic_GetEtaByBelongTypeAndBelongID_{corpId}_{belongType}_{belongId}"; var vm_list = MemoryCacheHelper.GetSet(cacheKey, () => { var pipe_list = new Service.PipeLine().GetEtaListByBelongTypeAndBelongID(corpId, belongType, belongId); if (pipe_list == null || pipe_list.Count < 1) return default; var vm_cache_list = pipe_list.Select(x => new PipeLineLogicDto(x)).ToList(); return vm_cache_list; }, CacheHelper.CacheLevel4); return vm_list; } /// /// 通过 BelongType 和 BelongID 获取拓展泵性能曲线列表(业务) /// [Route("GetExPumpFeatCurveListByBelongTypeAndBelongID@V1.0")] [HttpGet] public List GetExPumpFeatCurveListByBelongTypeAndBelongID([FromQuery][Required] BelongUnderCorpInput input) { var corpId = input.CorpID; var belongType = input.BelongType; var belongId = input.BelongID; var cacheKey = $"Main_PipeLine_Logic_GetExPumpFeatCurveListByBelongTypeAndBelongID_{corpId}_{belongType}_{belongId}"; var vm_list = MemoryCacheHelper.GetSet(cacheKey, () => { var pipe_list = new Service.PipeLine().GetByBelongTypeAndBelongID(corpId, belongType, belongId); if (pipe_list == null || pipe_list.Count < 1) return default; var pipe_engine_pump_list = pipe_list.Where(x => x.Catalog == PipeLine.EnginePump).OrderBy(x => x.SerialNO).ToList(); if (pipe_engine_pump_list.Count < 1) return default; var service_binding = new Service.PipeLineBinding(); var service_product = new Service.Product(); var service_property = new Service.ProductTypePropertyGroup(); var service_curve = new Service.PumpCurveExMapping(); var vm_cache_list = new List(); foreach (var pipe_engine_pump in pipe_engine_pump_list) { var binding_list = service_binding.GetUseByPipeLineID(pipe_engine_pump.CorpID, pipe_engine_pump.ID); if (binding_list == null || binding_list.Count < 1) continue; var binding = binding_list.Find(x => x.BindingType == IStation.ObjectType.Product); if (binding == null) continue; var pump = service_product.GetChildPumpByEnginePumpID(binding.CorpID, binding.BindingID); if (pump == null) continue; var property_list = service_property.GetExItemsByProductTypeID(pump.CorpID, pump.ProductTypeID); var curve = service_curve.GetDefaultWorkingByPumpID(pump.CorpID, pump.ID); if (curve == null) continue; var vm_cache = new PipeLineExPumpFeatCurveLogicDto(pipe_engine_pump, pump, property_list, curve); vm_cache_list.Add(vm_cache); } return vm_cache_list; }, CacheHelper.CacheLevel3); return vm_list; } /// /// 通过 CorpID 获取机泵逻辑树(业务) /// [Route("GetEnginePumpLogicalTreeByCorpID@V1.0")] [HttpGet] public List GetEnginePumpLogicalTreeByCorpID([FromQuery][Required] CorpIDInput input) { var corpId = input.CorpID; var cacheKey = $"Main_PipeLine_Logic_GetEnginePumpLogicalTreeByCorpID_{corpId}"; var vm_list = MemoryCacheHelper.GetSet(cacheKey, () => { #region 获取业务类别列表 var service_logic_catalog = new Service.LogicCatalog(); var catalog_list = service_logic_catalog.GetByCorpID(corpId); if (catalog_list == null || catalog_list.Count < 1) { return default; } catalog_list = catalog_list.Where(x => x.UseStatus == Model.eUseStatus.Enable).ToList(); if (catalog_list.Count < 1) { return default; } #endregion #region 获取业务清单列表 var vm_cache_list = new List(); var service_logic_tree = new Service.LogicTree(); var service_logic_area = new Service.LogicArea(); var service_station = new Service.Station(); var service_pipe = new Service.PipeLine(); foreach (var catalog in catalog_list) { var logic_tree_list = service_logic_tree.GetExByCatalogID(corpId, catalog.ID); var vm_logic_tree_item_list = new List(); if (logic_tree_list != null || logic_tree_list.Count > 0) { foreach (var logic_tree in logic_tree_list) { var vm_logic_tree_item = new LogicalTreeItemDto(); vm_logic_tree_item.ID = $"{ObjectType.LogicTree}_{logic_tree.ID}"; var parentId = TreeParentIdsHelper.GetLastParentID(logic_tree.ParentIds); if (parentId < 1) { vm_logic_tree_item.ParentID = string.Empty; } else { vm_logic_tree_item.ParentID = $"{ObjectType.LogicTree}_{parentId}"; } vm_logic_tree_item.LogicalID = logic_tree.LogicID; vm_logic_tree_item.LogicalType = logic_tree.LogicType; vm_logic_tree_item.LogicalName = logic_tree.LogicName; if (logic_tree.LogicType == ObjectType.LogicArea) { var logic_area = service_logic_area.GetByID(logic_tree.CorpID, logic_tree.LogicID); vm_logic_tree_item.LogicalModel = new LogicAreaLogicDto(logic_area); } else if (logic_tree.LogicType == ObjectType.Station) { var station = service_station.GetByID(logic_tree.CorpID, logic_tree.LogicID); vm_logic_tree_item.LogicalModel = new StationLogicDto(station); } vm_logic_tree_item.Children = new List(); var vm_logic_tree_parent_item = vm_logic_tree_item_list.Find(t => t.ID == vm_logic_tree_item.ParentID); if (vm_logic_tree_parent_item != null) { vm_logic_tree_parent_item.Children.Add(vm_logic_tree_item); } vm_logic_tree_item_list.Add(vm_logic_tree_item); if (logic_tree.LogicType == ObjectType.Station) { var pipe_list = service_pipe.GetEnginePumpListByBelongTypeAndBelongID(logic_tree.CorpID, logic_tree.LogicType, logic_tree.LogicID); if (pipe_list != null && pipe_list.Count > 0) { foreach (var pipe in pipe_list) { var vm_pipe = new LogicalTreeItemDto(); vm_pipe.ID = $"{ObjectType.PipeLine}_{pipe.ID}"; vm_pipe.ParentID = vm_logic_tree_item.ID; vm_pipe.LogicalID = pipe.ID; vm_pipe.LogicalType = ObjectType.PipeLine; vm_pipe.LogicalName = pipe.Name; vm_pipe.LogicalModel = new PipeLineLogicDto(pipe); vm_pipe.Children = new List(); vm_logic_tree_item.Children.Add(vm_pipe); } } } } vm_logic_tree_item_list = vm_logic_tree_item_list.Where(t => string.IsNullOrEmpty(t.ParentID)).ToList(); } vm_cache_list.Add(new LogicCatalogExLogicalTreeItemsLogicDto(catalog, vm_logic_tree_item_list)); } #endregion return vm_cache_list; }, CacheHelper.CacheLevel3); return vm_list; } /// /// 通过 ID 获取泵频率曲线(业务) /// [Route("GetPumpHZCurveByID@V1.0")] [HttpGet] public PumpHZCurveLogicDto GetPumpHZCurveByID ( [Required,Range(1,long.MaxValue,ErrorMessage ="CorpID 必须大于0")] long CorpID, [Required,Range(1,long.MaxValue,ErrorMessage ="ID 必须大于0")] long ID, [Required] double HZ ) { var binding_list = new Service.PipeLineBinding().GetUseByPipeLineID(CorpID, ID); if (binding_list == null || binding_list.Count < 1) { return default; } var binding = binding_list.Find(x => x.BindingType == ObjectType.Product); if (binding == null) { return default; } var pump = new Service.Product().GetChildPumpByEnginePumpID(binding.CorpID, binding.BindingID); if (pump == null) { return default; } var curve = new Service.PumpCurveExMapping().GetDefaultWorkingByPumpID(pump.CorpID, pump.ID); if (curve == null) { return default; } 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("CalculatePumpParallelCurve@V1.0")] [HttpPost] public PumpParallelCurveLogicDto CalculatePumpParallelCurve([Required] PipeLineParallelCurveInput input) { var service_pipe = new Service.PipeLine(); var service_binding = new Service.PipeLineBinding(); 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 pipe = service_pipe.GetByID(input.CorpID, item.ID); if (pipe == null) continue; var binding_list = service_binding.GetUseByPipeLineID(input.CorpID, item.ID); if (binding_list == null || binding_list.Count < 1) continue; var binding = binding_list.Find(x => x.BindingType == ObjectType.Product); if (binding == null) continue; var pump = service_product.GetChildPumpByEnginePumpID(binding.CorpID, binding.BindingID); 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("CalculatePipeLineParallelEx@V1.0")] [HttpPost] public List CalculatePumpParallelCurveEx([Required] PipeLineParallelCurveInput input) { var service_pipe = new Service.PipeLine(); var service_binding = new Service.PipeLineBinding(); 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 pipe = service_pipe.GetByID(input.CorpID, item.ID); if (pipe == null) continue; var binding_list = service_binding.GetUseByPipeLineID(input.CorpID, item.ID); if (binding_list == null || binding_list.Count < 1) continue; var binding = binding_list.Find(x => x.BindingType == ObjectType.Product); if (binding == null) continue; var pump = service_product.GetChildPumpByEnginePumpID(binding.CorpID, binding.BindingID); 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 = pipe.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; } } }