using DevExpress.Xpo.Helpers;
using Yw.Hydro;
using Yw.Vmo;
namespace HStation.WinFrmUI
{
///
/// 监测值辅助类
///
public class SimulationMonitorValueHelper
{
///
///
///
public SimulationMonitorValueHelper
(
SimulationVisualListHelper visualListHelper,
SimulationMonitorHelper monitorHelper,
SimulationCalcuResultHelper calcuResultHelper
)
{
_visualListHelper = visualListHelper;
_monitorHelper = monitorHelper;
_calcuResultHelper = calcuResultHelper;
}
private readonly SimulationVisualListHelper _visualListHelper = null;//可见列表辅助类
private readonly SimulationMonitorHelper _monitorHelper = null;//监测点辅助类
private readonly SimulationCalcuResultHelper _calcuResultHelper = null;//计算结果辅助类
private List _allList = null;//所有监测值列表
///
/// 获取所有
///
public async Task> GetAll()
{
if (_allList == null)
{
_allList = new List();
var allVisualDict = _visualListHelper.GetVisualDict();
if (allVisualDict != null && allVisualDict.Count > 0)
{
var allMonitorList = await _monitorHelper.GetAll();
if (allMonitorList != null && allMonitorList.Count > 0)
{
foreach (var monitor in allMonitorList)
{
if (allVisualDict.ContainsKey(monitor.Relation))
{
var visual = allVisualDict[monitor.Relation];
double? propValue = null;
var calcuVisualResult = _calcuResultHelper.GetVisual(monitor.Relation);
if (calcuVisualResult != null)
{
propValue = calcuVisualResult.GetCalcuValue(monitor.PropName);
}
var vm = new HydroMonitorValueViewModel(monitor, visual, propValue);
_allList.Add(vm);
}
}
}
}
}
return _allList;
}
///
/// 获取对接列表
///
public async Task> GetDockingList()
{
var all = await GetAll();
return all.Where(x => x.Vmo.SourceType == eSourceType.Docking).ToList();
}
///
/// 获取分析列表
///
public async Task> GetAnalyseList()
{
var all = await GetAll();
return all.Where(x => x.Vmo.SourceType == eSourceType.Analyse).ToList();
}
///
/// 更新
///
public async void Update(string code, List monitorList)
{
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 calcuVisualResult = _calcuResultHelper.GetVisual(x.Relation);
if (calcuVisualResult != null)
{
propValue = calcuVisualResult.GetCalcuValue(x.PropName);
}
var vm = new HydroMonitorValueViewModel(x, visual, propValue);
allValueList.Add(vm);
}
});
}
///
/// 更新
///
public async Task Update(string code, eSourceType sourceType, List valueList)
{
var all = await GetAll();
all.RemoveAll(x => x.Vmo.Relation == code && x.Vmo.SourceType == sourceType);
if (valueList != null && valueList.Count > 0)
{
all.AddRange(valueList);
}
}
///
/// 更新
///
public async void Update(string code, List monitorList, List 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);
}
});
}
///
/// 重置
///
public async void Reset(List allWorkingMonitorList)
{
var allMonitorValueList = await GetAll();
allMonitorValueList.UpdateMonitorValue(allWorkingMonitorList);
}
///
/// 重置
///
public async void Reset(string monitorInfo)
{
var allMonitorValueList = await GetAll();
allMonitorValueList.UpdateMonitorValue(monitorInfo);
}
}
}