using Aitex.Core.RT.DataCenter; using Aitex.Core.RT.Log; using Aitex.Core.UI.MVVM; using CyberX8_Core; using CyberX8_MainPages.Model; using CyberX8_Themes.CustomControls; using ExcelLibrary.BinaryFileFormat; using MECF.Framework.Common.CommonData.Metal; using MECF.Framework.Common.CommonData.Reservoir; using MECF.Framework.Common.CommonData.TemperatureControl; using MECF.Framework.Common.DataCenter; using MECF.Framework.Common.OperationCenter; using MECF.Framework.Common.Persistent.Reservoirs; using MECF.Framework.Common.RecipeCenter; using MECF.Framework.Common.Utilities; using OpenSEMI.ClientBase.Command; using Prism.Mvvm; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Input; using System.Windows.Threading; namespace CyberX8_MainPages.ViewModels { public class ReservoirsCatholyteViewModel : BindableBase { #region 常量 private const string RESERVOIRS_DATA = "ReservoirsData"; private const string RESERVOIRS = "reservoirs"; private const string PERSISTENT_VALUE = "PersistentValue"; #endregion #region 内部变量 private string _module; private string _recipeContent; private string _operatingMode; private string _state; private string _recipeMode; private List _rtDataKeys = new List(); DispatcherTimer _timer; private Dictionary _rtDataValueDic = new Dictionary(); private ObservableCollection _recipeNodes; private string _currentRecipeFileName; private string _recipeType; private string _tcName; private double _caPumpSpeed; private bool _isDIReplenFault; private double _flowAdjustDelta; private double _maxFlowDelta; private bool _isFolwDeltaUnBlance = false; private bool _isHighLevel; private bool _isLowLevel; private bool _isLeakDetected; private bool _cdaOn; private bool _isError; private ResRecipe _currentRecipe; private double _avgCALevel; /// /// 是否配置Exhaust /// private bool _isEvaporatorConfig; /// /// 是否正在手动注水 /// private bool _isManualReplen; /// /// 手动注水时长(秒) /// private int _manualFillSeconds; /// /// DIValveMaxOnTime /// private double _diValveMaxOnTime; /// /// TemperatureControl Module Name /// private TemperatureControllerData _temperatureControlData; /// /// Persistent /// private ReservoirsPersistentValue _reservoirsPersistent; /// /// Reservoir数据 /// private CompactMembranReservoirData _reservoirData; /// /// CellModuleName集合 /// private ObservableCollection _cellModuleNameCollection = new ObservableCollection(); /// /// Cell A面Flow集合 /// private ObservableCollection _cellModuleNameFlowCollection = new ObservableCollection(); /// /// MetalData /// private ObservableCollection _metalDatas = new ObservableCollection(); /// /// MetalData的CellFlow集合 /// private ObservableCollection _metalCellFlowDatas = new ObservableCollection(); /// /// 页面功能启用 /// private bool _isEnabled; /// /// AutoMode页面功能启用 /// private bool _isAutoEnabled; /// /// Meatl UI数据 /// private ObservableCollection _reservoirsUIDatas = new ObservableCollection(); /// /// TC Enable状态 /// private string _tcEnableStatus; #endregion #region 属性 public double AvgCALevel { get { return _avgCALevel; } set { SetProperty(ref _avgCALevel, value); } } public string CurrentRecipeFileName { get { return _currentRecipeFileName; } set { SetProperty(ref _currentRecipeFileName, value); } } public ObservableCollection RecipeNodes { get { return _recipeNodes; } set { SetProperty(ref _recipeNodes, value); } } public string Module { get { return _module; } set { SetProperty(ref _module, value); } } public string ReservoirRecipeContent { get { return _recipeContent; } set { SetProperty(ref _recipeContent, value); } } public string OperatingMode { get { return _operatingMode; } set { SetProperty(ref _operatingMode, value); } } public string State { get { return _state; } set { SetProperty(ref _state, value); } } public string RecipeMode { get { return _recipeMode; } set { SetProperty(ref _recipeMode, value); } } public string RecipeType { get { return _recipeType; } set { SetProperty(ref _recipeType, value); } } public double CAPumpSpeed { get { return _caPumpSpeed; } set { SetProperty(ref _caPumpSpeed, value); } } public ResRecipe CurrentRecipe { get { return _currentRecipe; } set { SetProperty(ref _currentRecipe, value); } } /// /// Threshold /// public ReservoirsPersistentValue ReservoirsPersistent { get { return _reservoirsPersistent; } set { SetProperty(ref _reservoirsPersistent, value); } } /// /// CellModuleName集合 /// public ObservableCollection CellModuleNameCollection { get { return _cellModuleNameCollection; } set { SetProperty(ref _cellModuleNameCollection, value); } } /// /// 模块Flow集合 /// public ObservableCollection CellModuleNameFlowCollection { get { return _cellModuleNameFlowCollection; } set { SetProperty(ref _cellModuleNameFlowCollection, value); } } /// /// Reservoir数据 /// public CompactMembranReservoirData ReservoirData { get { return _reservoirData; } set { SetProperty(ref _reservoirData, value); } } /// /// MetalData /// public ObservableCollection MetalDatas { get { return _metalDatas; } set { SetProperty(ref _metalDatas, value); } } /// /// MetalDataCellFlow /// public ObservableCollection MetalCellFlowDatas { get { return _metalCellFlowDatas; } set { SetProperty(ref _metalCellFlowDatas, value); } } /// /// 是否Error /// public bool IsError { get { return _isError; } set { SetProperty(ref _isError, value); } } /// /// 正在手动注水 /// public bool IsManualReplen { get { return _isManualReplen; } set { SetProperty(ref _isManualReplen, value); } } /// /// 手动注水时长 /// public int ManualFillSeconds { get { return _manualFillSeconds; } set { SetProperty(ref _manualFillSeconds, value); } } /// /// 单次注水最大时长 /// public double DIValveMaxOnTime { get { return _diValveMaxOnTime; } set { SetProperty(ref _diValveMaxOnTime, value); } } /// /// 是否补水异常 /// public bool IsDIReplenFault { get { return _isDIReplenFault; } set { SetProperty(ref _isDIReplenFault, value); } } /// /// metal cell 水位最大值和最小值之差 /// public double FlowAdjustDelta { get { return _flowAdjustDelta; } set { SetProperty(ref _flowAdjustDelta, value); } } /// /// 流量误差是否超过0.5 /// public bool IsFolwDeltaUnBlance { get { return _isFolwDeltaUnBlance; } set { SetProperty(ref _isFolwDeltaUnBlance, value); } } /// /// 是否触发高水位 /// public bool IsHighLevel { get { return _isHighLevel; } set { SetProperty(ref _isHighLevel, value); } } /// /// 是否触发低水位 /// public bool IsLowLevel { get { return _isLowLevel; } set { SetProperty(ref _isLowLevel, value); } } /// /// TemperatureControl Module Name /// public TemperatureControllerData TemperatureControlData { get { return _temperatureControlData; } set { SetProperty(ref _temperatureControlData, value); } } /// /// 页面功能启用 /// public bool IsEnabled { get { return _isEnabled; } set { SetProperty(ref _isEnabled, value); } } /// /// AutoMode页面功能启用 /// public bool IsAutoEnabled { get { return _isAutoEnabled; } set { SetProperty(ref _isAutoEnabled, value); } } /// /// metal ui数据 /// public ObservableCollection ReservoirsUIDatas { get { return _reservoirsUIDatas; } set { SetProperty(ref _reservoirsUIDatas, value); } } /// /// 是否配有排气模块 /// public bool IsEvaporatorConfig { get { return _isEvaporatorConfig; } set { SetProperty(ref _isEvaporatorConfig, value); } } /// /// 排期模块是否检测到漏液 /// public bool IsLeakDetected { get { return _isLeakDetected; } set { SetProperty(ref _isLeakDetected, value); } } /// /// 排气是否打开 /// public bool CdaOn { get { return _cdaOn; } set { SetProperty(ref _cdaOn, value); } } /// /// TC Enable状态 /// public string TCEnableStatus { get { return _tcEnableStatus; } set { SetProperty(ref _tcEnableStatus, value); } } #endregion #region 指令 public ICommand ControlValveCommand { get; private set; } public ICommand ManualDireplenCommand { get; set; } public ICommand ResetTotalCommand { get; set; } public ICommand CAPumpSpeedCommand { get; private set; } public ICommand BackCommand { get; set; } public ICommand JumpToTCCommand { get; set; } #endregion public ReservoirsCatholyteViewModel() { ControlValveCommand = new DelegateCommand(OnControlValve); ManualDireplenCommand = new DelegateCommand(ManualDireplenAction); ResetTotalCommand = new DelegateCommand(ResetTotalAction); CAPumpSpeedCommand = new DelegateCommand(CAPumpSpeedAction); BackCommand = new DelegateCommand(BackAction); JumpToTCCommand = new DelegateCommand(JumpToTCAction); } #region 命令方法 /// /// 回到Reservoir主页面 /// /// private void BackAction(object param) { GlobalEvents.OnSwitchFixedChildSubItem(Module, Module); } /// /// 跳转到对应的TC页面 /// /// private void JumpToTCAction(object param) { if (_tcName != null) { GlobalEvents.OnSwitchFixedTabItem("HardWare", "TemperatureController", $"{_tcName.Substring(0, 3)}"); } else { GlobalEvents.OnSwitchFixedTabItem("HardWare", "TemperatureController", ""); } } /// /// Control Valve /// /// private void OnControlValve(object obj) { CommonValveControl commonValveControl = (CommonValveControl)obj; if (commonValveControl.IsCanEdit == true) { string cmd = commonValveControl.OperationName; if (!commonValveControl.Status) { commonValveControl.Status = !commonValveControl.Status; InvokeClient.Instance.Service.DoOperation($"{cmd}On"); } else { commonValveControl.Status = !commonValveControl.Status; InvokeClient.Instance.Service.DoOperation($"{cmd}Off"); } } } /// /// CA Pump调速 /// /// private void CAPumpSpeedAction(object obj) { object[] objects = (object[])obj; if (objects.Length >= 2) { InvokeClient.Instance.Service.DoOperation($"{Module}.CAPumpSpeed", objects[1]); } } /// /// 手动注水 /// /// private void ManualDireplenAction(object param) { InvokeClient.Instance.Service.DoOperation($"{Module}.ManualCADiReplen", ManualFillSeconds); } /// /// 重置TotalTime /// private void ResetTotalAction(object param) { InvokeClient.Instance.Service.DoOperation($"{Module}.ResetTotalTime"); } #endregion public void LoadData(string systemName) { RecipeType = "res"; Module = systemName; _rtDataKeys.Clear(); _rtDataKeys.Add($"{Module}.Metals"); Dictionary tmpMetals = QueryDataClient.Instance.Service.PollData(_rtDataKeys); if (tmpMetals != null) { List strMetals = CommonFunction.GetValue>(tmpMetals, $"{Module}.Metals"); int cellsCount = strMetals.Count; if (strMetals != null) { CellModuleNameCollection.Clear(); CellModuleNameFlowCollection.Clear(); MetalDatas.Clear(); MetalCellFlowDatas.Clear(); ReservoirsUIDatas.Clear(); for (int i = 0; i < cellsCount; i++) { CellModuleNameCollection.Add(strMetals[i]); CellModuleNameFlowCollection.Add(0); MetalDatas.Add(null); MetalCellFlowDatas.Add(0); ReservoirsUIData reservoirsUIData = new ReservoirsUIData(); reservoirsUIData.Name = strMetals[i]; ReservoirsUIDatas.Add(reservoirsUIData); } } } _rtDataKeys.Clear(); for (int i = 0; i < CellModuleNameCollection.Count; i++) { _rtDataKeys.Add($"{CellModuleNameCollection[i]}.CellFlow"); _rtDataKeys.Add($"{CellModuleNameCollection[i]}.MetalData"); } _rtDataKeys.Add($"{Module}.{PERSISTENT_VALUE}"); _rtDataKeys.Add($"{Module}.ReservoirData"); _rtDataKeys.Add($"{Module}.IsManualCAReplen"); _rtDataKeys.Add($"{Module}.DIValveMaxOnTime"); _rtDataKeys.Add($"{Module}.CAPumpSpeed"); _rtDataKeys.Add($"{Module}.IsCAHighLevel"); _rtDataKeys.Add($"{Module}.IsCALowLevel"); _rtDataKeys.Add($"{Module}.IsDIReplenInFault"); _rtDataKeys.Add($"{Module}.TemperatureControllerData"); _rtDataKeys.Add($"{Module}.CurrentRecipe"); _rtDataKeys.Add($"{Module}.FsmState"); _rtDataKeys.Add($"{Module}.EvaporatorType"); _rtDataKeys.Add($"{Module}.ReservoirAverageCALevel"); _rtDataKeys.Add($"System.Facilities.CDAEnable"); if (_timer == null) { _timer = new DispatcherTimer(); _timer.Interval = TimeSpan.FromMilliseconds(200); _timer.Tick += Timer_Tick; } _timer.Start(); } private void Timer_Tick(object sender, EventArgs e) { if (_rtDataKeys.Count != 0) { _rtDataValueDic = QueryDataClient.Instance.Service.PollData(_rtDataKeys); if (_rtDataValueDic != null) { State = CommonFunction.GetValue(_rtDataValueDic, $"{Module}.FsmState"); IsError = "Error".Equals(State) ? true : false; ReservoirsPersistent = CommonFunction.GetValue(_rtDataValueDic, $"{Module}.{PERSISTENT_VALUE}"); ReservoirData = CommonFunction.GetValue(_rtDataValueDic, $"{Module}.ReservoirData"); AvgCALevel = CommonFunction.GetValue(_rtDataValueDic, $"{Module}.ReservoirAverageCALevel"); CurrentRecipe = CommonFunction.GetValue(_rtDataValueDic, $"{Module}.CurrentRecipe"); IsManualReplen = CommonFunction.GetValue(_rtDataValueDic, $"{Module}.IsManualCAReplen"); DIValveMaxOnTime = CommonFunction.GetValue(_rtDataValueDic, $"{Module}.DIValveMaxOnTime"); CAPumpSpeed = CommonFunction.GetValue(_rtDataValueDic, $"{Module}.CAPumpSpeed"); IsHighLevel = CommonFunction.GetValue(_rtDataValueDic, $"{Module}.IsCAHighLevel"); IsLowLevel = CommonFunction.GetValue(_rtDataValueDic, $"{Module}.IsCALowLevel"); IsDIReplenFault = CommonFunction.GetValue(_rtDataValueDic, $"{Module}.IsDIReplenInFault"); CdaOn = CommonFunction.GetValue(_rtDataValueDic, $"System.Facilities.CDAEnable"); TemperatureControlData = CommonFunction.GetValue(_rtDataValueDic, $"{Module}.TemperatureControllerData"); TCEnableStatus = TemperatureControlData.ControlOperationModel == 0 ? "Disable" : "Enable"; _tcName = TemperatureControlData.Name; for (int i = 0; i < CellModuleNameCollection.Count; i++) { CellModuleNameFlowCollection[i] = CommonFunction.GetValue(_rtDataValueDic, $"{CellModuleNameCollection[i]}.CellFlow"); MetalDatas[i] = CommonFunction.GetValue(_rtDataValueDic, $"{CellModuleNameCollection[i]}.MetalData"); MetalCellFlowDatas[i] = MetalDatas[i].CellFlow; ReservoirsUIDatas[i].MetalCellFlow = MetalCellFlowDatas[i]; ReservoirsUIDatas[i].IsFlowing3 = MetalDatas[i].CellFlowValve; ReservoirsUIDatas[i].IsFlowing2 = MetalDatas[i].WHUnclamp; ReservoirsUIDatas[i].IsFlowing1 = MetalDatas[i].WHClamp; ReservoirsUIDatas[i].IsEnable = IsEnabled; ReservoirsUIDatas[i].IsAutoEnable = IsAutoEnabled; } //list记录参与循环的metal阴极的流量情况 List list = new List(); for (int i = 0; i < CellModuleNameCollection.Count; i++) { if (MetalDatas[i].CellFlowValve) { list.Add(MetalDatas[i].CellFlow); } } //如果参与循环的流量全是0或者没有参与循环的metal,直接跳过流量差相关逻辑 if (list.Count==0 || list.All(num => num == 0)) { for (int i = 0; i < CellModuleNameCollection.Count; i++) { ReservoirsUIDatas[i].IsMetalCellHigh = false; ReservoirsUIDatas[i].IsMetalCellLow = false; } } else { FlowAdjustDelta = list.Max() - list.Min(); IsFolwDeltaUnBlance = FlowAdjustDelta > 0.5 ? true : false; if (IsFolwDeltaUnBlance) { for (int i = 0; i < CellModuleNameCollection.Count; i++) { if (list.Max() == MetalDatas[i].CellFlow && MetalDatas[i].CellFlowValve) { ReservoirsUIDatas[i].IsMetalCellHigh = true; } else { ReservoirsUIDatas[i].IsMetalCellHigh = false; } if (list.Min() == MetalDatas[i].CellFlow && MetalDatas[i].CellFlowValve) { ReservoirsUIDatas[i].IsMetalCellLow = true; } else { ReservoirsUIDatas[i].IsMetalCellLow = false; } } } else { for (int i = 0; i < CellModuleNameCollection.Count; i++) { ReservoirsUIDatas[i].IsMetalCellHigh = false; ReservoirsUIDatas[i].IsMetalCellLow = false; } } } list.Clear(); if ("Manual".Equals(ReservoirsPersistent.OperatingMode)) { IsEnabled = true; IsAutoEnabled = true; } else if ("Auto".Equals(ReservoirsPersistent.OperatingMode)) { IsAutoEnabled = true; IsEnabled = false; } else { State = "Stopped"; IsEnabled = false; IsAutoEnabled = false; } string evaporatorType = CommonFunction.GetValue(_rtDataValueDic, $"{Module}.EvaporatorType"); if ("STD".Equals(evaporatorType)) { IsEvaporatorConfig = true; } else { IsEvaporatorConfig = false; } } } } /// /// 隐藏 /// public void Hide() { if (_timer != null) { _timer.Stop(); } } } }