public async Task <List <T1_SystemEvent> > GetSystemEvent(string ip, DateTime start, DateTime end, string name, CustomSystemType systemtype) { List <T_SystemEvent> list = new List <T_SystemEvent>(); if (name.Trim() == "" && systemtype == CustomSystemType.None) { list = await _databaseComponent.Query <T_SystemEvent>(ip, null, "(EventTime >= @0 and EventTime <= @1)", new object[] { start, end, }); } else if (name.Trim() != "" && systemtype == CustomSystemType.None) { list = await _databaseComponent.Query <T_SystemEvent>(ip, null, "((EventTime >= @0 and EventTime <= @1) and Remarks like '%'+ @2+ '%')", new object[] { start, end, name }); } else if (name.Trim() == "" && systemtype != CustomSystemType.None) { list = await _databaseComponent.Query <T_SystemEvent>(ip, null, "((EventTime >= @0 and EventTime <= @1) and Type = @2)", new object[] { start, end, ((int)systemtype) }); } else { list = await _databaseComponent.Query <T_SystemEvent>(ip, null, "((EventTime >= @0 and EventTime <= @1) and Remarks like '%'+ @2+ '%' and Type = @3)", new object[] { start, end, name, ((short)systemtype).ToString() }); } return(list.Select(p => ClassCopyHelper.AutoCopy <T_SystemEvent, T1_SystemEvent>(p)).ToList()); }
public async Task <List <T1_OperateRecord> > GetOperateRecord(string ip, DateTime start, DateTime end, string name, UserOperateType operateType) { List <T_OperateRecord> list = new List <T_OperateRecord>(); if (name.Trim() == "" && operateType == UserOperateType.None) { list = await _databaseComponent.Query <T_OperateRecord>(ip, null, "(OperateTime >= @0 and OperateTime <= @1)", new object[] { start, end, }); } else if (name.Trim() != "" && operateType == UserOperateType.None) { list = await _databaseComponent.Query <T_OperateRecord>(ip, null, "((OperateTime >= @0 and OperateTime <= @1) and T_User_Name like '%'+ @2+ '%')", new object[] { start, end, name }); } else if (name.Trim() == "" && operateType != UserOperateType.None) { list = await _databaseComponent.Query <T_OperateRecord>(ip, null, "((OperateTime >= @0 and OperateTime <= @1) and UserOperateType = @2)", new object[] { start, end, ((short)operateType) }); } else { list = await _databaseComponent.Query <T_OperateRecord>(ip, null, "((OperateTime >= @0 and OperateTime <= @1) and T_User_Name like '%'+ @2+ '%' and UserOperateType = @3)", new object[] { start, end, name, ((short)operateType).ToString() }); } return(list.Select(p => ClassCopyHelper.AutoCopy <T_OperateRecord, T1_OperateRecord>(p)).ToList()); }
public async Task AddData(ItemTreeItemViewModel item, DateTime start, DateTime end) { string selectedip = item.ServerIP; #region 测点 if (item != null) { try { WaitInfo = "获取数据中"; Status = ViewModelStatus.Querying; if (item.T_Item.ItemType == (int)ChannelType.WirelessVibrationChannelInfo) { var result = await _databaseComponent.GetHistoryData <D_WirelessVibrationSlot>(selectedip, item.T_Item.Guid, new string[] { "ACQDatetime", "Result", "Unit", "AlarmGrade", "IsValidWave", "RecordLab", "RPM" }, start, end, null, null); result = result.Where(p => p.IsValidWave == true).ToList(); if (result == null || result.Count == 0) { return; } BaseDivfreChannelToken channeltoken = new BaseDivfreChannelToken() { DisplayName = item.BaseAlarmSignal.DeviceItemName, IP = selectedip, Guid = item.T_Item.Guid, DataContracts = result.Select(p => ClassCopyHelper.AutoCopy <D_WirelessVibrationSlot, D1_WirelessVibrationSlot>(p) as IBaseAlarmSlot).ToList(), }; foreach (var color in DefaultColors.SeriesForBlackBackgroundWpf) { if (!ColorList.Contains(color)) { ColorList.Add(color); channeltoken.SolidColorBrush = new SolidColorBrush(color); break; } } amsReplayVM.AddChannel(channeltoken); timeDomainVM.AddChannel(channeltoken); frequencyDomainVM.AddChannel(channeltoken); powerSpectrumVM.AddChannel(channeltoken); powerSpectrumDensityVM.AddChannel(channeltoken); alarmPointTrendVM.AddChannel(channeltoken); orthoDataVM.AddChannel(channeltoken); offDesignConditionVM.AddChannel(channeltoken); } else if (item.T_Item.ItemType == (int)ChannelType.WirelessScalarChannelInfo) { var result = await _databaseComponent.GetHistoryData <D_WirelessScalarSlot>(selectedip, item.T_Item.Guid, new string[] { "ACQDatetime", "Result", "Unit", "AlarmGrade" }, start, end, null, null); if (result == null || result.Count == 0) { return; } BaseAlarmChannelToken channeltoken = new BaseAlarmChannelToken() { DisplayName = item.BaseAlarmSignal.DeviceItemName, IP = selectedip, Guid = item.T_Item.Guid, DataContracts = result.Select(p => ClassCopyHelper.AutoCopy <D_WirelessScalarSlot, D1_WirelessScalarSlot>(p) as IBaseAlarmSlot).ToList(), }; foreach (var color in DefaultColors.SeriesForBlackBackgroundWpf) { if (!ColorList.Contains(color)) { ColorList.Add(color); channeltoken.SolidColorBrush = new SolidColorBrush(color); break; } } amsReplayVM.AddChannel(channeltoken); timeDomainVM.IsVisible = false; frequencyDomainVM.IsVisible = false; } } catch (Exception ex) { _eventAggregator.GetEvent <ThrowExceptionEvent>().Publish(Tuple.Create <string, Exception>("数据回放-测点查询", ex)); } finally { Status = ViewModelStatus.None; } } #endregion }
//统一返回基础类型 public async Task <List <IBaseAlarmSlot> > GetUniformHistoryData(int itemType, string ip, Guid guid, string[] columns, DateTime startTime, DateTime endTime, string condition, object[] args) { return(await Task.Run(() => { var client = new DataProvider(ip, LocalSetting.ServerPort, LocalSetting.MajorVersion, LocalSetting.MinorVersion); string errorMessage = null; switch (itemType) { case (int)ChannelType.IEPEChannelInfo: { var historyResult = client.QueryHistorySampleData <D_IEPESlot>(new Guid[] { guid }, columns, startTime, endTime, condition, args); //先判断是不是OK if (historyResult.IsOK) { return historyResult.ResponseItem.OrderBy(p => p.ACQDatetime).Select(p => ClassCopyHelper.AutoCopy <D_IEPESlot, D1_IEPESlot>(p) as IBaseAlarmSlot).ToList(); } else { errorMessage = historyResult.ErrorMessage; } break; } case (int)ChannelType.EddyCurrentDisplacementChannelInfo: { var historyResult = client.QueryHistorySampleData <D_EddyCurrentDisplacementSlot>(new Guid[] { guid }, columns, startTime, endTime, condition, args); //先判断是不是OK if (historyResult.IsOK) { return historyResult.ResponseItem.OrderBy(p => p.ACQDatetime).Select(p => ClassCopyHelper.AutoCopy <D_EddyCurrentDisplacementSlot, D1_EddyCurrentDisplacementSlot>(p) as IBaseAlarmSlot).ToList(); } else { errorMessage = historyResult.ErrorMessage; } break; } case (int)ChannelType.EddyCurrentKeyPhaseChannelInfo: { var historyResult = client.QueryHistorySampleData <D_EddyCurrentKeyPhaseSlot>(new Guid[] { guid }, columns, startTime, endTime, condition, args); //先判断是不是OK if (historyResult.IsOK) { return historyResult.ResponseItem.OrderBy(p => p.ACQDatetime).Select(p => ClassCopyHelper.AutoCopy <D_EddyCurrentKeyPhaseSlot, D1_EddyCurrentKeyPhaseSlot>(p) as IBaseAlarmSlot).ToList(); } break; } case (int)ChannelType.DigitTachometerChannelInfo: { var historyResult = client.QueryHistorySampleData <D_DigitTachometerSlot>(new Guid[] { guid }, columns, startTime, endTime, condition, args); //先判断是不是OK if (historyResult.IsOK) { return historyResult.ResponseItem.OrderBy(p => p.ACQDatetime).Select(p => ClassCopyHelper.AutoCopy <D_DigitTachometerSlot, D1_DigitTachometerSlot>(p) as IBaseAlarmSlot).ToList(); } break; } case (int)ChannelType.AnalogRransducerInChannelInfo: { var historyResult = client.QueryHistorySampleData <D_AnalogRransducerInSlot>(new Guid[] { guid }, columns, startTime, endTime, condition, args); //先判断是不是OK if (historyResult.IsOK) { return historyResult.ResponseItem.OrderBy(p => p.ACQDatetime).Select(p => ClassCopyHelper.AutoCopy <D_AnalogRransducerInSlot, D1_AnalogRransducerInSlot>(p) as IBaseAlarmSlot).ToList(); } break; } case (int)ChannelType.RelayChannelInfo: { var historyResult = client.QueryHistorySampleData <D_RelaySlot>(new Guid[] { guid }, columns, startTime, endTime, condition, args); //先判断是不是OK if (historyResult.IsOK) { return historyResult.ResponseItem.OrderBy(p => p.ACQDatetime).Select(p => ClassCopyHelper.AutoCopy <D_RelaySlot, D1_RelaySlot>(p) as IBaseAlarmSlot).ToList(); } break; } case (int)ChannelType.DigitRransducerInChannelInfo: { var historyResult = client.QueryHistorySampleData <D_DigitRransducerInSlot>(new Guid[] { guid }, columns, startTime, endTime, condition, args); //先判断是不是OK if (historyResult.IsOK) { return historyResult.ResponseItem.OrderBy(p => p.ACQDatetime).Select(p => ClassCopyHelper.AutoCopy <D_DigitRransducerInSlot, D1_DigitRransducerInSlot>(p) as IBaseAlarmSlot).ToList(); } break; } case (int)ChannelType.DigitRransducerOutChannelInfo: { var historyResult = client.QueryHistorySampleData <D_DigitRransducerOutSlot>(new Guid[] { guid }, columns, startTime, endTime, condition, args); //先判断是不是OK if (historyResult.IsOK) { return historyResult.ResponseItem.OrderBy(p => p.ACQDatetime).Select(p => ClassCopyHelper.AutoCopy <D_DigitRransducerOutSlot, D1_DigitRransducerOutSlot>(p) as IBaseAlarmSlot).ToList(); } break; } case (int)ChannelType.AnalogRransducerOutChannelInfo: { var historyResult = client.QueryHistorySampleData <D_AnalogRransducerOutSlot>(new Guid[] { guid }, columns, startTime, endTime, condition, args); //先判断是不是OK if (historyResult.IsOK) { return historyResult.ResponseItem.OrderBy(p => p.ACQDatetime).Select(p => ClassCopyHelper.AutoCopy <D_AnalogRransducerOutSlot, D1_AnalogRransducerOutSlot>(p) as IBaseAlarmSlot).ToList(); } break; } case (int)ChannelType.WirelessVibrationChannelInfo: { var historyResult = client.QueryHistorySampleData <D_WirelessVibrationSlot>(new Guid[] { guid }, columns, startTime, endTime, condition, args); //先判断是不是OK if (historyResult.IsOK) { return historyResult.ResponseItem.OrderBy(p => p.ACQDatetime).Select(p => ClassCopyHelper.AutoCopy <D_WirelessVibrationSlot, D1_WirelessVibrationSlot>(p) as IBaseAlarmSlot).ToList(); } break; } case (int)ChannelType.WirelessScalarChannelInfo: { var historyResult = client.QueryHistorySampleData <D_WirelessScalarSlot>(new Guid[] { guid }, columns, startTime, endTime, condition, args); //先判断是不是OK if (historyResult.IsOK) { return historyResult.ResponseItem.OrderBy(p => p.ACQDatetime).Select(p => ClassCopyHelper.AutoCopy <D_WirelessScalarSlot, D1_WirelessScalarSlot>(p) as IBaseAlarmSlot).ToList(); } break; } default: return null; } if (errorMessage != null) { EventAggregatorService.Instance.EventAggregator.GetEvent <ThrowExceptionEvent>().Publish(Tuple.Create <string, Exception>("数据库操作", new Exception(errorMessage))); } return null; })); }
private async Task AMSTrackChanged(IEnumerable <BaseWaveChannelToken> tokens) { try { if (tokens == null) { return; } var unValidTokens = tokens.Where(o => o.CurrentIndex == -1); foreach (var token in unValidTokens) { token.VData = null; } var validTokens = tokens.Where(o => o.CurrentIndex != -1).ToArray(); if (validTokens.Length == 0) { return; } //var globalIndexes = validTokens.Select(o => o.DataContracts[o.CurrentIndex].ChannelGlobalIndex).ToArray(); //var ids = validTokens.Select(o => o.DataContracts[o.CurrentIndex].id).ToArray(); //var date = validTokens.Select(o => o.DataContracts[o.CurrentIndex].ACQDatetime).First(); List <IWaveformData> result = new List <IWaveformData>(); foreach (var token in validTokens) { if (token is BaseDivfreChannelToken) { var divtoken = token as BaseDivfreChannelToken; List <D_WirelessVibrationSlot_Waveform> data = null; if (divtoken.CurrentIndex != -1 && (divtoken.DataContracts[divtoken.CurrentIndex] as IBaseDivfreSlot).IsValidWave.Value == true)//修正拖动太快,CurrentIndex一直在变 { data = await _databaseComponent.GetHistoryData <D_WirelessVibrationSlot_Waveform>(divtoken.IP, divtoken.Guid, new string[] { "WaveData", "SampleFre", "SamplePoint", "WaveUnit" }, divtoken.DataContracts[divtoken.CurrentIndex].ACQDatetime.AddSeconds(-1), divtoken.DataContracts[divtoken.CurrentIndex].ACQDatetime.AddSeconds(20), "(RecordLab = @0)", new object[] { divtoken.DataContracts[divtoken.CurrentIndex].RecordLab }); } else { token.VData = null; } if (data != null && data.Count > 0) { result.Add(ClassCopyHelper.AutoCopy <D_WirelessVibrationSlot_Waveform, WirelessVibrationSlotData_Waveform>(data[0])); } else { token.VData = null; } } } await Task.Run(() => Parallel.For(0, result.Count, i => { VibrationData vdata = new VibrationData(); vdata.Waveform = Algorithm.ByteToSingle(result[i].WaveData); vdata.SampleFre = result[i].SampleFre ?? 0; vdata.SamplePoint = result[i].SamplePoint ?? 0; vdata.Unit = result[i].WaveUnit; var paras = Algorithm.CalculatePara(vdata.Waveform); if (paras != null) { vdata.RMSValue = paras[0]; vdata.PeakValue = paras[1]; vdata.PeakPeakValue = paras[2]; vdata.Slope = paras[3]; vdata.Kurtosis = paras[4]; vdata.KurtosisValue = paras[5]; vdata.WaveIndex = paras[6]; vdata.PeakIndex = paras[7]; vdata.ImpulsionIndex = paras[8]; vdata.RootAmplitude = paras[9]; vdata.ToleranceIndex = paras[10]; } double sampleFre = vdata.SampleFre; if (vdata.Trigger == TriggerType.Angle) { if (vdata.RPM > 0 && vdata.TeethNumber > 0) { sampleFre = vdata.RPM *vdata.TeethNumber / 60; } } int length = (int)(vdata.SamplePoint / 2.56) + 1; if (vdata.Frequency == null || vdata.Frequency.Length != length) { vdata.Frequency = new double[length]; } double frequencyInterval = sampleFre / vdata.SamplePoint; for (int j = 0; j < length; j++) { vdata.Frequency[j] = frequencyInterval *j; } var output = Algorithm.Instance.FFT2AndPhaseAction(vdata.Waveform, vdata.SamplePoint); if (output != null) { vdata.Amplitude = output[0].Take(length).ToArray(); vdata.Phase = output[1].Take(length).ToArray(); } validTokens[i].VData = vdata; })); timeDomainVM.ChangeChannelData(tokens); frequencyDomainVM.ChangeChannelData(tokens); } catch (Exception ex) { _eventAggregator.GetEvent <ThrowExceptionEvent>().Publish(Tuple.Create <string, Exception>("数据回放-TrackChanged", ex)); } }