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
|
{
|
/// <summary>
|
/// LogicTree
|
/// </summary>
|
[Route("Main/LogicTree/Logic")]
|
[ApiDescriptionSettings("Main", Name = "业务清单(业务)", Order = 997)]
|
public class LogicTree_LogicController : IDynamicApiController
|
{
|
|
/// <summary>
|
/// 通过 CorpID 获取树(业务)
|
/// </summary>
|
[Route("GetTreeByCorpID@V1.0")]
|
[HttpGet]
|
public List<LogicCatalogExItemsLogicDto> GetTreeByCorpID([FromQuery][Required] CorpIDInput input)
|
{
|
var corpId = input.CorpID;
|
var cacheKey = $"Main_LogicTree_Logic_GetTreeByCorpID_{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<LogicCatalogExItemsLogicDto>();
|
var service_logic_tree = new Service.LogicTree();
|
|
foreach (var catalog in catalog_list)
|
{
|
var logic_tree_list = service_logic_tree.GetExByCatalogID(corpId, catalog.ID);
|
var vm_logic_tree_list = new List<LogicTreeItemDto>();
|
if (logic_tree_list != null || logic_tree_list.Count > 0)
|
{
|
foreach (var logic_tree in logic_tree_list)
|
{
|
var vm_logic_tree_item = new LogicTreeItemDto(logic_tree);
|
var vm_logic_tree_parent_item = vm_logic_tree_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_list.Add(vm_logic_tree_item);
|
}
|
vm_logic_tree_list = vm_logic_tree_list.Where(t => t.ParentID == 0).OrderBy(t => t.SortCode).ToList();
|
}
|
vm_cache_list.Add(new LogicCatalogExItemsLogicDto(catalog, vm_logic_tree_list));
|
}
|
|
#endregion
|
|
return vm_cache_list;
|
|
|
}, CacheHelper.CacheLevel1);
|
return vm_list;
|
}
|
|
/// <summary>
|
/// 通过 CatalogID 获取(业务)
|
/// </summary>
|
[Route("GetTreeByCatalogID@V1.0")]
|
[HttpGet]
|
public List<LogicTreeItemDto> GetTreeByCatalogID([FromQuery][Required] CatalogIDUnderCorpInput input)
|
{
|
var corpId = input.CorpID;
|
var catalogId = input.CatalogID;
|
var cacheKey = $"Main_LogicTree_Logic_GetTreeByCatalogID_{corpId}_{catalogId}";
|
var vm_list = MemoryCacheHelper.GetSet(cacheKey, () =>
|
{
|
//获取业务清单
|
var logic_tree_list = new Service.LogicTree().GetExByCatalogID(corpId, catalogId);
|
if (logic_tree_list == null || logic_tree_list.Count < 1)
|
{
|
return default;
|
}
|
|
var vm_cache_list = new List<LogicTreeItemDto>();
|
foreach (var logic_tree in logic_tree_list)
|
{
|
var vm_cache_item = new LogicTreeItemDto(logic_tree);
|
var vm_cache_parent = vm_cache_list.Find(t => t.ID == vm_cache_item.ParentID);
|
if (vm_cache_parent != null)
|
{
|
vm_cache_parent.Children.Add(vm_cache_item);
|
}
|
vm_cache_list.Add(vm_cache_item);
|
}
|
return vm_cache_list.Where(t => t.ParentID == 0).OrderBy(t => t.SortCode).ToList();
|
}, CacheHelper.CacheLevel2);
|
|
return vm_list;
|
}
|
|
/// <summary>
|
/// 通过 CorpID 获取泵曲线逻辑树(业务)
|
/// </summary>
|
[Route("GetPumpCurveLogicalTreeByCorpID@V1.0")]
|
[HttpGet]
|
public List<LogicCatalogExLogicalTreeItemsLogicDto> GetPumpCurveLogicalTreeByCorpID([FromQuery][Required] CorpIDInput input)
|
{
|
var corpId = input.CorpID;
|
var cacheKey = $"Main_LogicTree_Logic_GetPumpCurveLogicalTreeByCorpID_{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<LogicCatalogExLogicalTreeItemsLogicDto>();
|
var service_logic_tree = new Service.LogicTree();
|
var service_logic_area = new Service.LogicArea();
|
var service_station = new Service.Station();
|
var service_product = new Service.Product();
|
var service_product_property = new Service.ProductTypePropertyGroup();
|
var service_curve = new Service.PumpCurveExMapping();
|
|
foreach (var catalog in catalog_list)
|
{
|
var logic_tree_list = service_logic_tree.GetByCatalogID(corpId, catalog.ID);
|
var vm_logic_tree_item_list = new List<LogicalTreeItemDto>();
|
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;
|
if (logic_tree.LogicType == ObjectType.LogicArea)
|
{
|
var logic_area = service_logic_area.GetByID(logic_tree.CorpID, logic_tree.LogicID);
|
vm_logic_tree_item.LogicalName = logic_area.Name;
|
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.LogicalName = station.Name;
|
vm_logic_tree_item.LogicalModel = new StationLogicDto(station);
|
}
|
vm_logic_tree_item.Children = new List<LogicalTreeItemDto>();
|
|
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 pump_list = service_product.GetPumpListByBelongTypeAndBelongID(logic_tree.CorpID, logic_tree.LogicType, logic_tree.LogicID);
|
if (pump_list != null && pump_list.Count > 0)
|
{
|
foreach (var pump in pump_list)
|
{
|
var property_list = service_product_property.GetExItemsByProductTypeID(pump.CorpID, pump.ProductTypeID);
|
var vm_pump = new ProductLogicDto<Model.Pump>(pump, property_list);
|
var vm_pump_item = new LogicalTreeItemDto();
|
vm_pump_item.ID = $"{IStation.ObjectType.Product}_{pump.ID}";
|
vm_pump_item.ParentID = vm_logic_tree_item.ID;
|
vm_pump_item.LogicalID = vm_pump.ID;
|
vm_pump_item.LogicalType = IStation.ObjectType.Product;
|
vm_pump_item.LogicalName = vm_pump.Name;
|
vm_pump_item.LogicalModel = vm_pump;
|
vm_pump_item.Children = new List<LogicalTreeItemDto>();
|
vm_logic_tree_item.Children.Add(vm_pump_item);
|
|
var curve_list = service_curve.GetByPumpID(vm_pump.CorpID, vm_pump.ID);
|
if (curve_list != null && curve_list.Count > 0)
|
{
|
foreach (var curve in curve_list)
|
{
|
var vm_curve = new PumpCurveLogicDto(curve);
|
var vm_curve_item = new LogicalTreeItemDto();
|
vm_curve_item.ID = $"{ObjectType.PumpCurveMapping}_{vm_curve.MappingID}";
|
vm_curve_item.ParentID = vm_pump_item.ID;
|
vm_pump_item.LogicalID = vm_curve.MappingID;
|
vm_curve_item.LogicalType = ObjectType.PumpCurveMapping;
|
vm_curve_item.LogicalName = vm_curve.OtherName;
|
vm_curve_item.LogicalModel = vm_curve;
|
vm_pump_item.Children.Add(vm_curve_item);
|
}
|
}
|
}
|
}
|
}
|
|
}
|
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;
|
}
|
|
}
|
}
|