Shuxia Ning
2024-11-25 d4898c5d7e1bbbbba384a0e29f29c066d6f502a7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
using Yw.Vmo;
 
namespace HStation.WinFrmUI
{
    /// <summary>
    /// 监测值辅助类
    /// </summary>
    public class SimulationMonitorValueHelper
    {
        /// <summary>
        /// 
        /// </summary>
        public SimulationMonitorValueHelper(SimulationVisualListHelper visualListHelper, SimulationMonitorHelper monitorHelper)
        {
            _visualListHelper = visualListHelper;
            _monitorHelper = monitorHelper;
        }
 
        private SimulationVisualListHelper _visualListHelper = null;//可见列表辅助类
        private SimulationMonitorHelper _monitorHelper = null;//监测点辅助类     
        private List<HydroMonitorValueViewModel> _allMonitorValueList = null;//所有监测值列表
 
        /// <summary>
        /// 获取
        /// </summary>
        public async Task<List<HydroMonitorValueViewModel>> Get()
        {
            if (_allMonitorValueList == null)
            {
                _allMonitorValueList = new List<HydroMonitorValueViewModel>();
                var allVisualDict = _visualListHelper.GetVisualDict();
                if (allVisualDict != null && allVisualDict.Count > 0)
                {
                    var allMonitorList = await _monitorHelper.Get();
                    if (allMonitorList != null && allMonitorList.Count > 0)
                    {
                        foreach (var monitor in allMonitorList)
                        {
                            if (allVisualDict.ContainsKey(monitor.Relation))
                            {
                                var visual = allVisualDict[monitor.Relation];
                                var vm = new HydroMonitorValueViewModel(monitor, visual);
                                _allMonitorValueList.Add(vm);
                            }
                        }
                    }
                }
            }
            return _allMonitorValueList;
        }
 
        /// <summary>
        /// 更新
        /// </summary>
        public async void Update(string code, List<HydroMonitorVmo> monitorList)
        {
            var visual = _visualListHelper.GetVisual(code);
            if (visual == null)
            {
                return;
            }
 
            var allMonitorValueList = await Get();
            var monitorValueList = allMonitorValueList.Where(x => x.Vmo.Relation == code).ToList();
            monitorValueList?.ForEach(x =>
            {
                var result = monitorList?.Exists(t => t.Relation == x.Vmo.Relation && t.PropName == x.Vmo.PropName);
                if (!(result.HasValue && result.Value))
                {
                    allMonitorValueList.Remove(x);
                }
            });
            monitorList?.ForEach(x =>
            {
                var result = monitorValueList?.Exists(t => t.Vmo.Relation == x.Relation && t.Vmo.PropName == x.PropName);
                if (!(result.HasValue && result.Value))
                {
                    var vm = new HydroMonitorValueViewModel(x, visual);
                    allMonitorValueList.Add(vm);
                }
            });
        }
 
 
    }
}