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.ViewModel;
|
using IStation.Untity;
|
using Microsoft.Web.Http;
|
|
namespace IStation.WebApi.Controllers
|
{
|
/// <summary>
|
/// 设备业务标准api
|
/// </summary>
|
[RoutePrefix("v1/Standard/Product")]
|
[ApiVersion("v1")]
|
public class Product_StandardController : ApiController
|
{
|
|
/// <summary>
|
/// 通过 BelongType 和 BelongID 获取逻辑树
|
/// </summary>
|
[Route("GetLogicalTreeByBelongTypeAndBelongID")]
|
[HttpGet]
|
public Result GetLogicalTreeByBelongTypeAndBelongID(long CorpID, string BelongType, long BelongID)
|
{
|
if (CorpID < 1)
|
{
|
return new Result(Code.Error, "CorpID 参数错误");
|
}
|
if (string.IsNullOrEmpty(BelongType))
|
{
|
return new Result(Code.Error, "BelongType 参数错误");
|
}
|
if (BelongID < 1)
|
{
|
return new Result(Code.Error, "BelongID 参数错误");
|
}
|
|
var cacheKey = $"Standard_Product_GetLogicalTreeByBelongTypeAndBelongID_{CorpID}_{BelongType}_{BelongID}";
|
var vm_list = MemoryCacheHelper.GetSet(cacheKey, () =>
|
{
|
|
#region 设备组
|
var group_list = new Service.ProductGroup().GetByBelongTypeAndBelongID(CorpID, BelongType, BelongID);
|
var vm_logical_group_list = group_list?.Select(x =>
|
{
|
var vm_logical_group = new ViewModel.LogicalTreeItem();
|
vm_logical_group.ID = $"{ObjectType.Product_设备组}_{x.ID}";
|
vm_logical_group.ParentID = $"{ObjectType.Product_设备组}_{TreeParentIdsHelper.GetLastParentID(x.ParentIds)}";
|
vm_logical_group.LogicalName = x.Name;
|
vm_logical_group.LogicalType = IStation.ObjectType.Product_设备组;
|
vm_logical_group.LogicalID = x.ID;
|
vm_logical_group.LogicalModel = new ViewModel.ProductGroup(x);
|
vm_logical_group.Children = new List<LogicalTreeItem>();
|
return vm_logical_group;
|
}).ToList();
|
|
#endregion
|
|
#region 设备
|
|
var service_product_type_property_group = new Service.ProductTypePropertyGroup();
|
var product_list = new Service.Product().GetByBelongTypeAndBelongID(CorpID, BelongType, BelongID);
|
var vm_logical_product_list = product_list?.Select(x =>
|
{
|
var vm_logical_product = new ViewModel.LogicalTreeItem();
|
vm_logical_product.ID = $"{IStation.ObjectType.Product_设备}_{x.ID}";
|
if (x.ParentIds != null && x.ParentIds.Count > 0)
|
{
|
vm_logical_product.ParentID = $"{IStation.ObjectType.Product_设备}_{x.ParentIds.Last()}";
|
}
|
else
|
{
|
vm_logical_product.ParentID = $"{IStation.ObjectType.Product_设备组}_{x.GroupID}";
|
}
|
vm_logical_product.LogicalName = x.Name;
|
vm_logical_product.LogicalType = IStation.ObjectType.Product_设备;
|
vm_logical_product.LogicalID = x.ID;
|
vm_logical_product.LogicalModel = new ViewModel.Product(x, service_product_type_property_group.GetExItemsByProductTypeID(x.CorpID, x.ProductTypeID));
|
vm_logical_product.Children = new List<LogicalTreeItem>();
|
return vm_logical_product;
|
}).ToList();
|
#endregion
|
|
#region 生成树
|
|
var vm_cache_list = new List<ViewModel.LogicalTreeItem>();
|
|
//遍历设备组
|
if (vm_logical_group_list != null && vm_logical_group_list.Count > 0)
|
{
|
foreach (var vm_logical_group in vm_logical_group_list)
|
{
|
var vm_logical_group_parent = vm_logical_group_list.Find(t => t.ID == vm_logical_group.ParentID);
|
if (vm_logical_group_parent == null)
|
{
|
vm_cache_list.Add(vm_logical_group);
|
}
|
else
|
{
|
vm_logical_group_parent.Children.Add(vm_logical_group);
|
}
|
}
|
}
|
|
//遍历设备
|
if (vm_logical_product_list != null && vm_logical_product_list.Count > 0)
|
{
|
foreach (var vm_logical_product in vm_logical_product_list)
|
{
|
var vm_logical_product_parent = vm_logical_product_list.Find(t => t.ID == vm_logical_product.ParentID);
|
if (vm_logical_product_parent == null)
|
{
|
vm_logical_product_parent = vm_logical_group_list?.Find(t => t.ID == vm_logical_product.ParentID);
|
}
|
if (vm_logical_product_parent == null)
|
{
|
vm_cache_list.Add(vm_logical_product);
|
}
|
else
|
{
|
vm_logical_product_parent.Children.Add(vm_logical_product);
|
}
|
}
|
}
|
|
|
|
return vm_cache_list;
|
|
#endregion
|
|
}, CacheHelper.CacheLevel2);
|
|
return new Result<List<ViewModel.LogicalTreeItem>>(vm_list);
|
}
|
|
/// <summary>
|
/// 通过 BelongType 和 BelongID 获取机泵列表
|
/// </summary>
|
[Route("GetEnginePumpListByBelongTypeAndBelongID")]
|
[HttpGet]
|
public Result GetEnginePumpListByBelongTypeAndBelongID(long CorpID, string BelongType, long BelongID)
|
{
|
if (CorpID < 1)
|
{
|
return new Result(Code.Error, "CorpID 参数错误");
|
}
|
if (string.IsNullOrEmpty(BelongType))
|
{
|
return new Result(Code.Error, "BelongType 参数错误");
|
}
|
if (BelongID < 1)
|
{
|
return new Result(Code.Error, "BelongID 参数错误");
|
}
|
var cacheKey = $"Standard_Product_GetEnginePumpListByBelongTypeAndBelongID_{CorpID}_{BelongType}_{BelongID}";
|
var vm_list = MemoryCacheHelper.GetSet(cacheKey, () =>
|
{
|
var service_product = new Service.Product();
|
var product_list = service_product.GetEnginePumpListByBelongTypeAndBelongID(CorpID, BelongType, BelongID);
|
if (product_list == null || product_list.Count < 1)
|
return default;
|
var service_product_type_property_group = new Service.ProductTypePropertyGroup();
|
var vm_cache_list = product_list.Select(x => new ViewModel.Product<Model.EnginePump>(x, service_product_type_property_group.GetExItemsByProductTypeID(x.CorpID, x.ProductTypeID))).ToList();
|
return vm_cache_list;
|
}, CacheHelper.CacheLevel5);
|
|
return new Result<List<ViewModel.Product<Model.EnginePump>>>(vm_list);
|
}
|
|
|
|
/// <summary>
|
/// 通过 BelongType 和 BelongID 获取泵列表
|
/// </summary>
|
[Route("GetPumpListByBelongTypeAndBelongID")]
|
[HttpGet]
|
public Result GetPumpListByBelongTypeAndBelongID(long CorpID, string BelongType, long BelongID)
|
{
|
if (CorpID < 1)
|
{
|
return new Result(Code.Error, "CorpID 参数错误");
|
}
|
if (string.IsNullOrEmpty(BelongType))
|
{
|
return new Result(Code.Error, "BelongType 参数错误");
|
}
|
if (BelongID < 1)
|
{
|
return new Result(Code.Error, "BelongID 参数错误");
|
}
|
var cacheKey = $"Standard_Product_GetPumpListByBelongTypeAndBelongID_{CorpID}_{BelongType}_{BelongID}";
|
var vm_list = MemoryCacheHelper.GetSet(cacheKey, () =>
|
{
|
var service_product = new Service.Product();
|
var product_list = service_product.GetPumpListByBelongTypeAndBelongID(CorpID, BelongType, BelongID);
|
if (product_list == null || product_list.Count < 1)
|
return default;
|
var service_product_type_property_group = new Service.ProductTypePropertyGroup();
|
var vm_cache_list = product_list.Select(x => new ViewModel.Product<Model.Pump>(x, service_product_type_property_group.GetExItemsByProductTypeID(x.CorpID, x.ProductTypeID))).ToList();
|
return vm_cache_list;
|
}, CacheHelper.CacheLevel5);
|
|
return new Result<List<ViewModel.Product<Model.Pump>>>(vm_list);
|
}
|
|
/// <summary>
|
/// 通过 BelongType 和 BelongID 获取泵拓展曲线列表
|
/// </summary>
|
[Route("GetPumpExCurveListByBelongTypeAndBelongID")]
|
[HttpGet]
|
public Result GetPumpExCurveListByBelongTypeAndBelongID(long CorpID, string BelongType, long BelongID)
|
{
|
if (CorpID < 1)
|
{
|
return new Result(Code.Error, "CorpID 参数错误");
|
}
|
if (string.IsNullOrEmpty(BelongType))
|
{
|
return new Result(Code.Error, "BelongType 参数错误");
|
}
|
if (BelongID < 1)
|
{
|
return new Result(Code.Error, "BelongID 参数错误");
|
}
|
var cacheKey = $"Standard_Product_GetPumpExCurveListByBelongTypeAndBelongID_{CorpID}_{BelongType}_{BelongID}";
|
var vm_list = MemoryCacheHelper.GetSet(cacheKey, () =>
|
{
|
var service_product = new Service.Product();
|
var product_list = service_product.GetPumpListByBelongTypeAndBelongID(CorpID, BelongType, BelongID);
|
if (product_list == null || product_list.Count < 1)
|
return default;
|
var service_product_type_property_group = new Service.ProductTypePropertyGroup();
|
var service_pump_curve_mapping = new Service.PumpCurveExMapping();
|
var vm_cache_list = new List<ViewModel.PumpExCurveList>();
|
foreach (var product in product_list)
|
{
|
var property_group_list = service_product_type_property_group.GetExItemsByProductTypeID(product.CorpID,product.ProductTypeID);
|
var curve_list = service_pump_curve_mapping.GetByPumpID(product.CorpID,product.ID);
|
var vm_cache = new ViewModel.PumpExCurveList(product,property_group_list,curve_list);
|
vm_cache_list.Add(vm_cache);
|
}
|
return vm_cache_list;
|
}, CacheHelper.CacheLevel3);
|
|
return new Result<List<ViewModel.PumpExCurveList>>(vm_list);
|
}
|
|
/// <summary>
|
/// 通过 ID 获取
|
/// </summary>
|
[Route("GetByID")]
|
[HttpGet]
|
public Result GetByID(long CorpID, long ID)
|
{
|
if (CorpID < 1)
|
{
|
return new Result(Code.Alert,"CorpID 参数错误");
|
}
|
if (ID < 1)
|
{
|
return new Result(Code.Alert,"ID 参数错误");
|
}
|
var product = new Service.Product().GetByID(CorpID,ID);
|
if (product == null)
|
{
|
return new Result(Code.Error,"未检索到设备信息");
|
}
|
var property_list = new Service.ProductTypePropertyGroup().GetExItemsByProductTypeID(product.CorpID,product.ProductTypeID);
|
var vm = new ViewModel.Product(product, property_list);
|
return new Result<ViewModel.Product>(vm);
|
}
|
|
}
|
}
|