using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using IStation.Model.Api;
using AutoMapper;
using IStation.WebApi.Models;
using IStation.Untity;
using Microsoft.Web.Http;
namespace IStation.WebApi.Controllers
{
///
/// 管路标准api
///
[RoutePrefix("v1/Standard/PipeLine")]
[ApiVersion("v1")]
public class PipeLine_StandardController : ApiController
{
///
/// 通过 BelongType 和 BelongID 获取管路信息
///
[Route("GetByBelongTypeAndBelongID")]
[HttpGet]
public Result GetByBelongTypeAndBelongID(long CorpID, string BelongType, long BelongID)
{
if (CorpID < 1)
{
return new Result(Code.Alert, "CorpID 参数错误");
}
if (string.IsNullOrEmpty(BelongType))
{
return new Result(Code.Alert, "BelongType 参数错误");
}
if (BelongID < 1)
{
return new Result(Code.Alert, "BelongID 参数错误");
}
var cacheKey = $"Standard_PipeLine_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 ViewModel.PipeLine(x)).ToList();
return vm_cache_list;
}, CacheHelper.CacheLevel4);
return new Result>(vm_list);
}
///
/// 通过 BelongType 和 BelongID 获取能效管路信息
///
[Route("GetEtaByBelongTypeAndBelongID")]
[HttpGet]
public Result GetEtaByBelongTypeAndBelongID(long CorpID, string BelongType, long BelongID)
{
if (CorpID < 1)
{
return new Result(Code.Alert, "CorpID 参数错误");
}
if (string.IsNullOrEmpty(BelongType))
{
return new Result(Code.Alert, "BelongType 参数错误");
}
if (BelongID < 1)
{
return new Result(Code.Alert, "BelongID 参数错误");
}
var cacheKey = $"Standard_PipeLine_GetEtaByBelongTypeAndBelongID_{CorpID}_{BelongType}_{BelongID}";
var vm_list = MemoryCacheHelper.GetSet(cacheKey, () =>
{
var pipe_list = new Service.PipeLine().GetEtaByBelongTypeAndBelongID(CorpID, BelongType, BelongID);
if (pipe_list == null || pipe_list.Count < 1)
return default;
var vm_cache_list = pipe_list.Select(x => new ViewModel.PipeLine(x)).ToList();
return vm_cache_list;
}, CacheHelper.CacheLevel4);
return new Result>(vm_list);
}
///
/// 通过 BelongType 和 BelongID 获取拓展泵性能曲线列表
///
[Route("GetExPumpFeatCurveListByBelongTypeAndBelongID")]
[HttpGet]
public Result GetExPumpFeatCurveListByBelongTypeAndBelongID(long CorpID, string BelongType, long BelongID)
{
if (CorpID < 1)
{
return new Result(Code.Alert, "CorpID 参数错误");
}
if (string.IsNullOrEmpty(BelongType))
{
return new Result(Code.Alert, "BelongType 参数错误");
}
if (BelongID < 1)
{
return new Result(Code.Alert, "BelongID 参数错误");
}
var cacheKey = $"Standard_PipeLine_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 == IStation.PipeLine.机泵).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.ObjectType == IStation.ObjectType.Product_设备);
if (binding == null)
continue;
var pump = service_product.GetChildPumpByEnginePumpID(binding.CorpID, binding.ObjectID);
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 ViewModel.PipeLineExPumpFeatCurve(pipe_engine_pump, pump, property_list, curve);
vm_cache_list.Add(vm_cache);
}
return vm_cache_list;
}, CacheHelper.CacheLevel3);
return new Result>(vm_list);
}
///
/// 通过 CorpID 获取机泵业务树
///
[Route("GetEnginePumpLogicTreeByCorpID")]
[HttpGet]
public Result GetEnginePumpLogicTreeByCorpID(long CorpID)
{
if (CorpID < 1)
{
return new Result(Code.Alert, "CorpID 参数错误");
}
var cacheKey = $"Standard_PipeLine_GetEnginePumpLogicTreeByCorpID_{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.LogicCatalog.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_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 = new ViewModel.LogicTree(logic_tree);
var vm_logic_tree_item = new ViewModel.LogicalTreeItem();
vm_logic_tree_item.ID = $"{IStation.ObjectType.Logic_业务清单}_{vm_logic_tree.ID}";
if (vm_logic_tree.ParentID < 1)
{
vm_logic_tree_item.ParentID = string.Empty;
}
else
{
vm_logic_tree_item.ParentID = $"{IStation.ObjectType.Logic_业务清单}_{vm_logic_tree.ParentID}";
}
vm_logic_tree_item.LogicalID = vm_logic_tree.ID;
vm_logic_tree_item.LogicalType = IStation.ObjectType.Logic_业务清单;
vm_logic_tree_item.LogicalName = vm_logic_tree.ObjectName;
vm_logic_tree_item.LogicalModel = vm_logic_tree;
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 (vm_logic_tree.ObjectType == IStation.ObjectType.Station_泵站)
{
var pipe_list = service_pipe.GetEnginePumpListByBelongTypeAndBelongID(vm_logic_tree.CorpID,vm_logic_tree.ObjectType,vm_logic_tree.ObjectID);
if (pipe_list != null && pipe_list.Count > 0)
{
foreach (var pipe in pipe_list)
{
var vm_pipe = new ViewModel.LogicalTreeItem();
vm_pipe.ID = $"{IStation.ObjectType.PipeLine_管路}_{pipe.ID}";
vm_pipe.ParentID = vm_logic_tree_item.ID;
vm_pipe.LogicalID = pipe.ID;
vm_pipe.LogicalType = IStation.ObjectType.PipeLine_管路;
vm_pipe.LogicalName = pipe.Name;
vm_pipe.LogicalModel = new ViewModel.PipeLine(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 ViewModel.LogicCatalogExLogicalTreeItems(catalog, vm_logic_tree_item_list));
}
#endregion
return vm_cache_list;
}, CacheHelper.CacheLevel3);
return new Result>(vm_list);
}
///
/// 通过 CorpID 获取机泵逻辑树
///
[Route("GetEnginePumpLogicalTreeByCorpID")]
[HttpGet]
public Result GetEnginePumpLogicalTreeByCorpID(long CorpID)
{
if (CorpID < 1)
{
return new Result(Code.Alert, "CorpID 参数错误");
}
var cacheKey = $"Standard_PipeLine_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.LogicCatalog.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 ViewModel.LogicalTreeItem();
vm_logic_tree_item.ID = $"{IStation.ObjectType.Logic_业务清单}_{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 = $"{IStation.ObjectType.Logic_业务清单}_{parentId}";
}
vm_logic_tree_item.LogicalID = logic_tree.ObjectID;
vm_logic_tree_item.LogicalType = logic_tree.ObjectType;
vm_logic_tree_item.LogicalName = logic_tree.ObjectName;
if (logic_tree.ObjectType == IStation.ObjectType.Logic_业务区域)
{
var logic_area = service_logic_area.GetByID(logic_tree.CorpID,logic_tree.ObjectID);
vm_logic_tree_item.LogicalModel = new ViewModel.LogicArea(logic_area);
}
else if (logic_tree.ObjectType == IStation.ObjectType.Station_泵站)
{
var station = service_station.GetByID(logic_tree.CorpID,logic_tree.ObjectID);
vm_logic_tree_item.LogicalModel = new ViewModel.Station(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.ObjectType == IStation.ObjectType.Station_泵站)
{
var pipe_list = service_pipe.GetEnginePumpListByBelongTypeAndBelongID(logic_tree.CorpID, logic_tree.ObjectType, logic_tree.ObjectID);
if (pipe_list != null && pipe_list.Count > 0)
{
foreach (var pipe in pipe_list)
{
var vm_pipe = new ViewModel.LogicalTreeItem();
vm_pipe.ID = $"{IStation.ObjectType.PipeLine_管路}_{pipe.ID}";
vm_pipe.ParentID = vm_logic_tree_item.ID;
vm_pipe.LogicalID = pipe.ID;
vm_pipe.LogicalType = IStation.ObjectType.PipeLine_管路;
vm_pipe.LogicalName = pipe.Name;
vm_pipe.LogicalModel = new ViewModel.PipeLine(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 ViewModel.LogicCatalogExLogicalTreeItems(catalog, vm_logic_tree_item_list));
}
#endregion
return vm_cache_list;
}, CacheHelper.CacheLevel3);
return new Result>(vm_list);
}
}
}