From 4efe844d9bcc03435cbbeb1aedbda5bf6ebf5912 Mon Sep 17 00:00:00 2001 From: ningshuxia <ningshuxia0927@outlook.com> Date: 星期二, 22 十一月 2022 16:46:58 +0800 Subject: [PATCH] 数据对接 --- Application/IStation.Application.Run/energy_flow/EngineFlow_Controller.cs | 83 +++++++++++++++++++++++++++++++++++++---- 1 files changed, 75 insertions(+), 8 deletions(-) diff --git a/Application/IStation.Application.Run/energy_flow/EngineFlow_Controller.cs b/Application/IStation.Application.Run/energy_flow/EngineFlow_Controller.cs index 7ad43c0..c3585d3 100644 --- a/Application/IStation.Application.Run/energy_flow/EngineFlow_Controller.cs +++ b/Application/IStation.Application.Run/energy_flow/EngineFlow_Controller.cs @@ -9,6 +9,7 @@ using Mapster; using IStation.Calculation; using IStation.Model; +using System.Reflection.Metadata.Ecma335; namespace IStation.Application { @@ -20,13 +21,12 @@ public class EngineFlow_Controller : IDynamicApiController { - /// <summary> /// 閫氳繃 LogicTreeID 鑾峰彇鏌愭湀鐨勮兘娴佽褰� /// </summary> [Route("GetByLogicTreeIDOfMonth@V1.0")] [HttpGet] - public EnergyFlowLogicalTreeItemDto GetByLogicTreeIDOfMonth + public EnergyFlowLogicalTreeItemDto GetByLogicTreeIDOfMonth ( long CorpID, long LogicTreeID, @@ -34,18 +34,27 @@ int Month ) { - var cacheKey = $"Run_Energy_Flow_GetByLogicTreeIDOfMonth_{CorpID}_{LogicTreeID}"; + var currentTime= DateTime.Now; + var currentYear = currentTime.Year; + var currentMonth = currentTime.Month; + if (currentYear == Year && currentMonth == Month) + return new EnergyFlowLogicalTreeItemDto(); + + var cacheKey = $"Run_Energy_Flow_GetByLogicTreeIDOfMonth_{CorpID}_{LogicTreeID}_{Year}_{Month}"; var vm_list = MemoryCacheHelper.GetSet(cacheKey, () => { - var logicTreeList = new Service.LogicTree().GetExChildAndSelfByID(CorpID,LogicTreeID); + var logicTreeList = new Service.LogicTree().GetExChildAndSelfByID(CorpID, LogicTreeID); if (logicTreeList == null || logicTreeList.Count < 1) return default; #region 缁熻 + var bllMonitor = new Service.MonitorPoint(); + var bllMonitorMappings = new Service.MonitorPointMapping(); + var bllMonitorMonthRecord = new Service.MonitorMonthRecord(); var vmList = new List<EnergyFlowLogicalTreeItemDto>(); 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)}"; @@ -69,11 +78,63 @@ vmEnginePump.LogicalName = enginePumpPipe.Name; vmEnginePump.LogicalType = IStation.ObjectType.PipeLine; vmEnginePump.LogicalID = enginePumpPipe.ID; - vmEnginePump.StatisticValue = new Random().Next(100, 1000); vmEnginePump.Children = new List<EnergyFlowLogicalTreeItemDto>(); + + var enginePumpPipeMonitorMappings = bllMonitorMappings.GetByObjectTypeAndObjectID(CorpID, vmEnginePump.LogicalType, vmEnginePump.LogicalID); + if (enginePumpPipeMonitorMappings != null && enginePumpPipeMonitorMappings.Count > 0) + { + var mappingIds = enginePumpPipeMonitorMappings.Select(x => x.MonitorPointID).ToList(); + var enginePumpPipeMonitorList = bllMonitor.GetExSignalWithSignalTypeByIds(CorpID, mappingIds); + enginePumpPipeMonitorList = enginePumpPipeMonitorList?.Where(x => x.MonitorType == eMonitorType.General && x.SourceType == Model.Monitor.eSourceType.Analyse && x.CronType == Model.Monitor.eCronType.EachMonth).ToList(); + enginePumpPipeMonitorList = enginePumpPipeMonitorList?.Where(x => x.SignalList != null && x.SignalList.Count > 0).ToList(); + if (enginePumpPipeMonitorList != null && enginePumpPipeMonitorList.Count > 0) + { + var enginePumpPipeElMonitorList = enginePumpPipeMonitorList.Where(x => x.SignalList.Exists(x => x.SignalType.Identifier == IStation.SignalType.鏈夊姛鐢靛害)).ToList(); + if (enginePumpPipeElMonitorList != null && enginePumpPipeElMonitorList.Count > 0) + { + var enginePumpPipeElMonitor = enginePumpPipeElMonitorList.Find(x => x.Flags != null && x.Flags.Contains(IStation.LogicFlags.榛樿)); + if (enginePumpPipeElMonitor == null) + enginePumpPipeElMonitor = enginePumpPipeElMonitorList.First(); + var enginePumpPipeElValues = bllMonitorMonthRecord.GetByMonitorPointIDOfMonth(CorpID, enginePumpPipeElMonitor.ID, Year, Month); + vmEnginePump.StatisticValue = enginePumpPipeElValues?.Sum(x => + { + if (double.TryParse(x.DataValue, out double enginePumpPipeElValue)) + { + return enginePumpPipeElValue; + } + return 0; + }); + } + } + } vm.Children.Add(vmEnginePump); } } + + var vmMonitorList = bllMonitor.GetExSignalWithSignalTypeByBelongTypeAndBelongID(CorpID, vm.LogicalType, vm.LogicalID); + vmMonitorList = vmMonitorList?.Where(x => x.MonitorType == eMonitorType.General && x.SourceType == Model.Monitor.eSourceType.Analyse && x.CronType == Model.Monitor.eCronType.EachMonth).ToList(); + vmMonitorList = vmMonitorList?.Where(x => x.SignalList != null && x.SignalList.Count > 0).ToList(); + if (vmMonitorList != null && vmMonitorList.Count > 0) + { + var vmElMonitorList = vmMonitorList.Where(x => x.SignalList.Exists(x => x.SignalType.Identifier == IStation.SignalType.鏈夊姛鐢靛害)).ToList(); + if (vmElMonitorList != null && vmElMonitorList.Count > 0) + { + var vmElMonitor = vmElMonitorList.Find(x => x.Flags != null && x.Flags.Contains(IStation.LogicFlags.鎬荤珯)); + if (vmElMonitor != null) + { + var vmElValues = bllMonitorMonthRecord.GetByMonitorPointIDOfMonth(CorpID, vmElMonitor.ID, Year, Month); + vm.StatisticValue = vmElValues?.Sum(x => + { + if (double.TryParse(x.DataValue, out double vmElValue)) + { + return vmElValue; + } + return 0; + }); + } + } + } + } var vmParent = vmList.Find(x => x.ID == vm.ParentID); @@ -92,14 +153,20 @@ var validChildren = vm.Children.Where(x => x.StatisticValue.HasValue).ToList(); if (validChildren.Count > 0) { - vm.StatisticValue = validChildren.Sum(x => x.StatisticValue.Value); + var validChildrenStatisticValue = validChildren.Sum(x => x.StatisticValue.Value); + /*if (vm.LogicalType == IStation.ObjectType.Station) + { + if (vm.StatisticValue > validChildrenStatisticValue) + continue; + }*/ + vm.StatisticValue = validChildrenStatisticValue; } } } #endregion - return vmList.Find(x=>x.ID== $"{IStation.ObjectType.LogicTree}_{LogicTreeID}"); + return vmList.Find(x => x.ID == $"{IStation.ObjectType.LogicTree}_{LogicTreeID}"); }, CacheHelper.CacheLevel2); -- Gitblit v1.9.3