using IStation.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace IStation.Service
{
public static class ProductBaseExtensions
{
///
/// 获取所有的机泵列表
///
public static List GetEnginePumpProductList(this IEnumerable allProducts)
{
if (allProducts == null || allProducts.Count() < 1)
return default;
return allProducts.Where(x => x.Catalog == Model.ProductCatalog.机泵).OrderBy(x => x.ID).ToList();
}
///
/// 获取单泵
///
public static Model.Product GetSinglePumpProduct(this IEnumerable allProducts)
{
if (allProducts == null || allProducts.Count() < 1)
return default;
var pump = allProducts.ToList().Find(x => x.Catalog == Model.ProductCatalog.泵);
return pump;
}
///
/// 获取后代
///
public static List GetChildrenProduct(this Model.Product product, IEnumerable allProducts)
{
if (product == null)
return default;
if (allProducts == null || allProducts.Count() < 1)
return default;
var spids = TreeParentIdsHelper.GetChildParentIds(product.ID, product.ParentIds);
var product_list = allProducts.Where(t => !string.IsNullOrEmpty(t.ParentIds) && t.ParentIds.StartsWith(spids)).ToList();
return product_list;
}
///
/// 获取所有后代及自身
///
public static List GetChildsAndSelfProduct(this Model.Product product, IEnumerable allProducts)
{
if (product == null)
return default;
if (allProducts == null || allProducts.Count() < 1)
return default;
var spids = TreeParentIdsHelper.GetChildParentIds(product.ID, product.ParentIds);
var allProducts_Product = allProducts.Where(t => (t.ID == product.ID)
|| (!string.IsNullOrEmpty(t.ParentIds) && t.ParentIds.StartsWith(spids))).ToList();
return allProducts_Product;
}
///
/// 获取后代单泵
///
public static Model.Product GetChildSinglePumpProduct(this Model.Product product, IEnumerable allProducts)
{
if (product == null)
return default;
if (allProducts == null || allProducts.Count() < 1)
return default;
var spids = TreeParentIdsHelper.GetChildParentIds(product.ID, product.ParentIds);
var product_list = allProducts.Where(t => !string.IsNullOrEmpty(t.ParentIds) && t.ParentIds.StartsWith(spids)).ToList();
if (product_list == null || product_list.Count < 1)
return default;
var pump = product_list.Find(x => x.Catalog == Model.ProductCatalog.泵);
return pump;
}
///
/// 设备及以下的所有常规测点
///
public static List GetGeneralMonitorPointContainsChildren
(
this Model.Product product,
List allProducts,
List allGenerals
)
{
if (product == null)
return default;
if (allProducts == null || allProducts.Count < 1)
return default;
var allProducts_product = product.GetChildsAndSelfProduct(allProducts);
if (allProducts_product == null || allProducts_product.Count < 1)
return default;
var allSignal_Product = (from x in allProducts_product
join y in allGenerals on x.ID equals y.BelongID
where y.BelongType == ObjectType.Product_设备
select y).ToList();
return allSignal_Product;
}
///
/// 产品的所有测点
///
public static List GetGeneralViewList
(
this List allProducts,
List allViews
)
{
if (allProducts == null || allProducts.Count < 1)
return default;
var allSignal_Product = (from x in allProducts
join y in allViews on x.ID equals y.BelongID
where y.BelongType == ObjectType.Product_设备
select y).ToList();
return allSignal_Product;
}
}
}