duheng
2025-01-14 bbb914ac62d8fb646492872f5fabf9ddfd5dd05f
WinFrmUI/HStation.WinFrmUI.Xhs.Core/03-simulation/00-core/04-monitor/02-value/SimulationMonitorValueHelper.cs
@@ -1,6 +1,4 @@
using DevExpress.Xpo.Helpers;
using Yw.Hydro;
using Yw.Vmo;
using Yw.Hydro;
namespace HStation.WinFrmUI
{
@@ -22,6 +20,7 @@
            _visualListHelper = visualListHelper;
            _monitorHelper = monitorHelper;
            _calcuResultHelper = calcuResultHelper;
            _calcuResultHelper.InitialEvent += async () => await Update();
        }
        private readonly SimulationVisualListHelper _visualListHelper = null;//可见列表辅助类
@@ -45,11 +44,11 @@
                    {
                        foreach (var monitor in allMonitorList)
                        {
                            if (allVisualDict.ContainsKey(monitor.Relation))
                            if (allVisualDict.ContainsKey(monitor.Parter))
                            {
                                var visual = allVisualDict[monitor.Relation];
                                var visual = allVisualDict[monitor.Parter];
                                double? propValue = null;
                                var calcuVisualResult = _calcuResultHelper.GetVisual(monitor.Relation);
                                var calcuVisualResult = _calcuResultHelper.GetVisual(monitor.Parter);
                                if (calcuVisualResult != null)
                                {
                                    propValue = calcuVisualResult.GetCalcuValue(monitor.PropName);
@@ -85,43 +84,24 @@
        /// <summary>
        /// 更新
        /// </summary>
        public async void Update(string code, List<HydroMonitorVmo> monitorList)
        public async Task Update()
        {
            if (string.IsNullOrEmpty(code))
            var all = await GetAll();
            foreach (var item in all)
            {
                return;
            }
            var visual = _visualListHelper.GetVisual(code);
            if (visual == null)
            {
                return;
            }
            var allValueList = await GetAll();
            var valueList = allValueList.Where(x => x.Vmo.Relation == code).ToList();
            valueList.ForEach(x =>
            {
                var result = monitorList?.Exists(t => t.Relation == x.Vmo.Relation && t.PropName == x.Vmo.PropName);
                if (!(result.HasValue && result.Value))
                if (!item.PropValue.HasValue)
                {
                    allValueList.Remove(x);
                }
            });
            monitorList?.ForEach(x =>
            {
                var result = valueList?.Exists(t => t.Vmo.Relation == x.Relation && t.Vmo.PropName == x.PropName);
                if (!(result.HasValue && result.Value))
                {
                    double? propValue = null;
                    var calcuVisualResult = _calcuResultHelper.GetVisual(x.Relation);
                    var calcuVisualResult = _calcuResultHelper.GetVisual(item.Vmo.Parter);
                    if (calcuVisualResult != null)
                    {
                        propValue = calcuVisualResult.GetCalcuValue(x.PropName);
                        var propValue = calcuVisualResult.GetCalcuValue(item.Vmo.PropName);
                        if (propValue.HasValue)
                        {
                            item.PropValue = item.Vmo.GetPropValue(propValue.Value);
                        }
                    }
                    var vm = new HydroMonitorValueViewModel(x, visual, propValue);
                    allValueList.Add(vm);
                }
            });
            }
        }
        /// <summary>
@@ -130,7 +110,7 @@
        public async Task Update(string code, eSourceType sourceType, List<HydroMonitorValueViewModel> valueList)
        {
            var all = await GetAll();
            all.RemoveAll(x => x.Vmo.Relation == code && x.Vmo.SourceType == sourceType);
            all.RemoveAll(x => x.Vmo.Parter == code && x.Vmo.SourceType == sourceType);
            if (valueList != null && valueList.Count > 0)
            {
                all.AddRange(valueList);
@@ -138,56 +118,12 @@
        }
        /// <summary>
        /// 更新
        /// </summary>
        public async void Update(string code, List<HydroMonitorVmo> monitorList, List<HydroMonitorDockingViewModel> monitorDockingList)
        {
            if (string.IsNullOrEmpty(code))
            {
                return;
            }
            var visual = _visualListHelper.GetVisual(code);
            if (visual == null)
            {
                return;
            }
            var allValueList = await GetAll();
            var valueList = allValueList.Where(x => x.Vmo.Relation == code).ToList();
            valueList.ForEach(x =>
            {
                var result = monitorList?.Exists(t => t.Relation == x.Vmo.Relation && t.PropName == x.Vmo.PropName);
                if (!(result.HasValue && result.Value))
                {
                    allValueList.Remove(x);
                }
            });
            monitorList?.ForEach(x =>
            {
                var result = valueList?.Exists(t => t.Vmo.Relation == x.Relation && t.Vmo.PropName == x.PropName);
                if (!(result.HasValue && result.Value))
                {
                    double? propValue = null;
                    var monitorDocking = monitorDockingList?.Find(t => t.Vmo.Relation == x.Relation && t.Vmo.PropName == x.PropName);
                    propValue = monitorDocking?.PropValue;
                    if (!propValue.HasValue)
                    {
                        var calcuVisualResult = _calcuResultHelper.GetVisual(x.Relation);
                        propValue = calcuVisualResult?.GetCalcuValue(x.PropName);
                    }
                    var vm = new HydroMonitorValueViewModel(x, visual, propValue);
                    allValueList.Add(vm);
                }
            });
        }
        /// <summary>
        /// 重置
        /// </summary>
        public async void Reset(List<HydroWorkingMonitorViewModel> allWorkingMonitorList)
        public async Task Reset(List<HydroWorkingMonitorViewModel> allWorkingMonitorList)
        {
            var allMonitorValueList = await GetAll();
            allMonitorValueList.UpdateMonitorValue(allWorkingMonitorList);
            var all = await GetAll();
            all.UpdateMonitorValue(allWorkingMonitorList);
        }
        /// <summary>