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; using IStation.Calculation; using IStation.Model; namespace IStation.Application { /// /// EnergyFlow /// [Route("Run/Energy/Flow")] [ApiDescriptionSettings("Run", Name = "能流", Order = 299)] public class EngineFlow_Controller : IDynamicApiController { /// /// 通过 LogicTreeID 获取某月的能流记录 /// [Route("GetByLogicTreeIDOfMonth@V1.0")] [HttpGet] public EnergyFlowLogicalTreeItemDto GetByLogicTreeIDOfMonth ( long CorpID, long LogicTreeID, int Year, int Month ) { var cacheKey = $"Run_Energy_Flow_GetByLogicTreeIDOfMonth_{CorpID}_{LogicTreeID}"; var vm_list = MemoryCacheHelper.GetSet(cacheKey, () => { var logicTreeList = new Service.LogicTree().GetExChildAndSelfByID(CorpID,LogicTreeID); if (logicTreeList == null || logicTreeList.Count < 1) return default; #region 统计 var vmList = new List(); foreach (var logicTree in logicTreeList) { var vm = new EnergyFlowLogicalTreeItemDto(); vm.ID = $"{IStation.ObjectType.LogicTree}_{logicTree.ID}"; vm.ParentID = $"{IStation.ObjectType.LogicTree}_{TreeParentIdsHelper.GetLastParentID(logicTree.ParentIds)}"; vm.LogicalName = logicTree.LogicName; vm.LogicalType = logicTree.LogicType; vm.LogicalID = logicTree.LogicID; vm.StatisticValue = null; vm.Children = new List(); vmList.Add(vm); if (vm.LogicalType == IStation.ObjectType.Station) { var enginePumpPipeList = new Service.PipeLine().GetEnginePumpListByBelongTypeAndBelongID(CorpID, logicTree.LogicType, logicTree.LogicID); if (enginePumpPipeList != null && enginePumpPipeList.Count > 0) { foreach (var enginePumpPipe in enginePumpPipeList) { var vmEnginePump = new EnergyFlowLogicalTreeItemDto(); vmEnginePump.ID = $"{IStation.ObjectType.PipeLine}_{enginePumpPipe.ID}"; vmEnginePump.ParentID = vm.ID; vmEnginePump.LogicalName = enginePumpPipe.Name; vmEnginePump.LogicalType = IStation.ObjectType.PipeLine; vmEnginePump.LogicalID = enginePumpPipe.ID; vmEnginePump.StatisticValue = new Random().Next(100, 1000); vmEnginePump.Children = new List(); vm.Children.Add(vmEnginePump); } } } var vmParent = vmList.Find(x => x.ID == vm.ParentID); if (vmParent != null) { vmParent.Children.Add(vm); } } logicTreeList.Reverse(); foreach (var logicTree in logicTreeList) { var vm = vmList.Find(x => x.ID == $"{IStation.ObjectType.LogicTree}_{logicTree.ID}"); if (vm.Children.Count > 0) { var validChildren = vm.Children.Where(x => x.StatisticValue.HasValue).ToList(); if (validChildren.Count > 0) { vm.StatisticValue = validChildren.Sum(x => x.StatisticValue.Value); } } } #endregion return vmList.Find(x=>x.ID== $"{IStation.ObjectType.LogicTree}_{LogicTreeID}"); }, CacheHelper.CacheLevel2); return vm_list; } } }