private void AnalyseData(IList <string> row, string strByteData) { string sysNo = ParseHelper.ParseString(row[(int)SystemData.SystemNo]); string batchNo = ParseHelper.ParseString(row[(int)SystemData.BatchNo]); DateTime timestamp = ConvertDate(row[(int)SystemData.Timestamp]); SensorHelper <object> helperSensor = new SensorHelper <object>(); SensorEntity eSensor = helperSensor.SelectSingle <SensorEntity>(string.Format("SensorGroup = '{0}' AND SensorKey = '{1}'", mSensorGroup, sysNo), string.Empty); if (eSensor == null) { logger.WarnFormat("系统中组和编号为:[{0}].[{1}]的设备没有登记。", mSensorGroup, sysNo); return; } SensorDataHeadEntity eHead = helperSensor.SelectSingle <SensorDataHeadEntity>(string.Format("SensorID = '{0}' AND DataKey = '{1}'", eSensor.SensorID.ToString().ToUpper(), batchNo), string.Empty); Enumerator.BelimedStatus status;//0-Off,1-On,2-Run,3-End try { status = (Enumerator.BelimedStatus)Enum.Parse(typeof(Enumerator.BelimedStatus), row[(int)SystemData.Status]); } catch (Exception ex) { logger.ErrorFormat("传感器状态取得失败,状态值:[{0}]", row[(int)SystemData.Status]); throw ex; } System.Threading.Monitor.Enter(Monitor.Common.Utility.SyncSqlLock); try { logger.Info("开始保存数据。"); using (TransactionScope tran = Monitor.Common.Utility.GetTransactionScope()) { switch (status) { case Enumerator.BelimedStatus.Off: eSensor.PositionMark = status.ToString(); helperSensor.Update(eSensor); break; case Enumerator.BelimedStatus.On: eSensor.PositionMark = status.ToString(); helperSensor.Update(eSensor); break; case Enumerator.BelimedStatus.Run: if (eHead == null) { // 主数据 eHead = new SensorDataHeadEntity(); eHead.SensorDataHeadID = Guid.NewGuid(); eHead.SensorID = eSensor.SensorID; eHead.DataKey = batchNo; eHead.BeginDate = timestamp; eHead.IsCompressed = false; eHead.DataVer = DataVersion.V1.ToString(); helperSensor.Create(eHead); } eSensor.PositionMark = status.ToString(); helperSensor.Update(eSensor); // 原始数据 SensorDataRawLineEntity eRawLine = new SensorDataRawLineEntity(); eRawLine.SensorDataRawLineID = Guid.NewGuid(); eRawLine.SensorDataHeadID = eHead.SensorDataHeadID; eRawLine.ReceivedDate = DateTime.Now; eRawLine.RawData = strByteData; helperSensor.Create(eRawLine); // 解析数据 SensorDataLineEntity eLine = new SensorDataLineEntity(); eLine.SensorDataLineID = Guid.NewGuid(); eLine.SensorDataHeadID = eHead.SensorDataHeadID; eLine.SensorDataRawLineID = eRawLine.SensorDataRawLineID; eLine.ReceivedDate = eRawLine.ReceivedDate; eLine.SensorDate = timestamp; if (eLine.SensorDate != null && eLine.SensorDate.HasValue && eHead.BeginDate != null && eHead.BeginDate.HasValue) { eLine.SensorTimeSpan = Convert.ToInt64(eLine.SensorDate.Value.Subtract(eHead.BeginDate.Value).TotalMilliseconds); } //eLine.AnalysedData = row.ToString(); eLine.AnalysedData = string.Join(";", row.ToArray <string>()); helperSensor.Create(eLine); SensorDataLineValueEntity eLineValue = null; for (int i = 0; i < row.Count; i++) { eLineValue = new SensorDataLineValueEntity(); eLineValue.SensorDataLineValueID = Guid.NewGuid(); eLineValue.SensorDataHeadID = eLine.SensorDataHeadID; eLineValue.SensorDataLineID = eLine.SensorDataLineID; switch (i) { case (int)SystemData.Status: string ss = ParseHelper.ParseString(row[i]); if (!string.IsNullOrEmpty(ss)) { eLineValue.ValueType = SystemData.Status.ToString(); eLineValue.ContentString = ss; helperSensor.Create(eLineValue); } break; case (int)SystemData.ErrorNo: string errorNo = ParseHelper.ParseString(row[i]); if (!string.IsNullOrEmpty(errorNo)) { eLineValue.ValueType = SystemData.ErrorNo.ToString(); eLineValue.ContentString = errorNo; helperSensor.Create(eLineValue); } break; case (int)SystemData.ProgramNo: eLineValue.ValueType = SystemData.ProgramNo.ToString(); eLineValue.ContentString = ParseHelper.ParseString(row[i]); helperSensor.Create(eLineValue); break; case (int)SystemData.ProgramName: eLineValue.ValueType = SystemData.ProgramName.ToString(); eLineValue.ContentString = ParseHelper.ParseString(row[i]); helperSensor.Create(eLineValue); break; case (int)SystemData.ProgramPhase: eLineValue.ValueType = SystemData.ProgramPhase.ToString(); eLineValue.ContentString = ParseHelper.ParseString(row[i]); helperSensor.Create(eLineValue); break; default: break; } if (Convert.ToInt32(eSensor.SensorType).Equals(Convert.ToInt32(Common.Consts.SensorType.Washer))) { switch (i) { case (int)SystemData.MeasurementSensor1: // Med eLineValue.ValueType = SystemData.MeasurementSensor1.ToString(); eLineValue.ContentNumber = Convert.ToDecimal(row[i]); helperSensor.Create(eLineValue); break; case (int)SystemData.MeasurementSensor2: // CT eLineValue.ValueType = SystemData.MeasurementSensor2.ToString(); eLineValue.ContentNumber = Convert.ToDecimal(row[i]) / 10; helperSensor.Create(eLineValue); break; case (int)SystemData.MeasurementSensor3: // CDNo eLineValue.ValueType = SystemData.MeasurementSensor3.ToString(); eLineValue.ContentNumber = Convert.ToDecimal(row[i]); helperSensor.Create(eLineValue); break; case (int)SystemData.MeasurementSensor4: // DosV eLineValue.ValueType = SystemData.MeasurementSensor4.ToString(); eLineValue.ContentNumber = Convert.ToDecimal(row[i]) / 10; helperSensor.Create(eLineValue); break; case (int)SystemData.MeasurementSensor5: // Ao eLineValue.ValueType = SystemData.MeasurementSensor5.ToString(); eLineValue.ContentNumber = Convert.ToDecimal(row[i]); helperSensor.Create(eLineValue); break; default: break; } } else if (Convert.ToInt32(eSensor.SensorType).Equals(Convert.ToInt32(Common.Consts.SensorType.Sterilizer))) { switch (i) { case (int)SystemData.MeasurementSensor1: // T1 eLineValue.ValueType = SystemData.MeasurementSensor1.ToString(); eLineValue.ContentNumber = Convert.ToDecimal(row[i]) / 10; helperSensor.Create(eLineValue); break; case (int)SystemData.MeasurementSensor2: // T2 eLineValue.ValueType = SystemData.MeasurementSensor2.ToString(); eLineValue.ContentNumber = Convert.ToDecimal(row[i]) / 10; helperSensor.Create(eLineValue); break; case (int)SystemData.MeasurementSensor4: // P1 eLineValue.ValueType = SystemData.MeasurementSensor4.ToString(); eLineValue.ContentNumber = Convert.ToDecimal(row[i]); helperSensor.Create(eLineValue); break; case (int)SystemData.MeasurementSensor5: // P2 eLineValue.ValueType = SystemData.MeasurementSensor5.ToString(); eLineValue.ContentNumber = Convert.ToDecimal(row[i]); helperSensor.Create(eLineValue); break; case (int)SystemData.MeasurementSensor6: // P3 eLineValue.ValueType = SystemData.MeasurementSensor6.ToString(); eLineValue.ContentNumber = Convert.ToDecimal(row[i]); helperSensor.Create(eLineValue); break; case (int)SystemData.MeasurementSensor7: // P4 eLineValue.ValueType = SystemData.MeasurementSensor7.ToString(); eLineValue.ContentNumber = Convert.ToDecimal(row[i]); helperSensor.Create(eLineValue); break; default: break; } } } break; case Enumerator.BelimedStatus.End: if (eHead != null) { eHead.EndDate = ConvertDate(row[(int)SystemData.Timestamp]); helperSensor.Update(eHead); eSensor.PositionMark = status.ToString(); eSensor.Remarks = ParseHelper.ParseString(row[(int)SystemData.StatusInfo]); helperSensor.Update(eSensor); if (eHead.LogID != null && eHead.LogID.HasValue && eHead.LogID.Value != Guid.Empty) { DevicesUseLogEntity logEntity = helperSensor.SelectSingle <DevicesUseLogEntity>("LogID='" + eHead.LogID.Value.ToString().ToUpper() + "'", string.Empty); if (logEntity != null) { if (eHead.BeginDate != null && eHead.BeginDate.HasValue) { logEntity.OldBeginDate = logEntity.BeginDate; logEntity.BeginDate = eHead.BeginDate.Value; } logEntity.EndDate = eHead.EndDate; // TODO: DevicesUseLog 关联到 Sensor 的字段 //logEntity.MonitorDataID = eHead.SensorDataHeadID; helperSensor.Update(logEntity); } } } break; default: break; } tran.Complete(); logger.Info("数据保存成功。"); } } finally { System.Threading.Monitor.Exit(Monitor.Common.Utility.SyncSqlLock); } }
/// <summary> /// 匹配CSSD记录 /// </summary> /// <param name="dv"></param> private void MatchMonitorRecord(MonitorDeviceEntity dv) { try { MonitorDeviceQueueEntity MonitorEntity = null; MonitorCollectDataEntity CollectEntity = null; MonitorDeviceEntity Device = dv; MonitorHelper monitor = new MonitorHelper(); MonitorEntity = (MonitorDeviceQueueEntity)monitor.SelectSingle(typeof(MonitorDeviceQueueEntity), String.Format("FDeviceID='{0}'", Device.Code), "FBeginDate Desc"); if (MonitorEntity != null) { DateTime deBegin = MonitorEntity.FBeginDate.Value.AddMinutes(-5); DateTime deEnd = MonitorEntity.FBeginDate.Value.AddMinutes(20); #region 队列表中有记录处理 CollectEntity = (MonitorCollectDataEntity)monitor.SelectSingle(typeof(MonitorCollectDataEntity), string.Format("FLogID='{0}' And FDeviceID='{1}' And FMonitorType={2}", MonitorEntity.FLogID, MonitorEntity.FDeviceID, Device.DeviceType), string.Empty); if (CollectEntity != null) { //正常情况处理:正常情况是指先在PC系统中做灭菌记录,然后开始启动灭菌设备. if (CollectEntity.FEndDate != null) { monitor.Delete(MonitorEntity); } logger.Info("正常情况匹配完成"); } else { //非正常情况处理 CollectEntity = monitor.SelectSingle("FDeviceID='" + MonitorEntity.FDeviceID + "' And FBeginDate>='" + deBegin.ToString("yyyy-MM-dd HH:mm:ss") + "' And FBeginDate<='" + deEnd.ToString("yyyy-MM-dd HH:mm:ss") + "'", "FBeginDate Desc"); //CollectEntity = (MonitorCollectDataEntity)monitor.SelectSingle(typeof(MonitorCollectDataEntity), // string.Format("FDeviceID='{0}' And FMonitorType={1}", // MonitorEntity.FDeviceID, Device.DeviceType), "FBeginDate Desc"); //如果有记录,取时间最近的与当前灭菌记录匹配,并更新FLogID if (CollectEntity == null) { logger.WarnFormat("非正常情况:在时间区间【-5~20】内,未找到监控主数据!(设备ID:[{0}]; 开始时间:[{1}]; 结束时间:[{2}])", MonitorEntity.FDeviceID, deBegin.ToString("yyyy-MM-dd HH:mm:ss"), deEnd.ToString("yyyy-MM-dd HH:mm:ss")); //CollectEntity = new MonitorCollectDataEntity(); //CollectEntity.FID = monitor.GetMaxIDByEntity(typeof(MonitorCollectDataEntity)); //CollectEntity.FLogID = MonitorEntity.FLogID; CollectEntity.FDeviceID = MonitorEntity.FDeviceID; //CollectEntity.FMonitorType = Device.DeviceType; //CollectEntity.FDataSourceType = Device.SourceType; //CollectEntity.FBeginDate = MonitorEntity.FBeginDate; //monitor.Create(CollectEntity); } else { using (TransactionScope tran = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 5, 0))) { CollectEntity.FLogID = MonitorEntity.FLogID; monitor.Update(CollectEntity); DevicesUseLogEntity uselog = (DevicesUseLogEntity)monitor.SelectSingle(typeof(DevicesUseLogEntity), string.Format("LogID='{0}'", MonitorEntity.FLogID), string.Empty); if (uselog != null) { uselog.MonitorDataID = CollectEntity.FID; if (CollectEntity.FBeginDate != null && CollectEntity.FBeginDate.HasValue) { uselog.OldBeginDate = uselog.BeginDate; uselog.BeginDate = CollectEntity.FBeginDate.Value; } uselog.EndDate = CollectEntity.FEndDate; monitor.Update(uselog); } tran.Complete(); } logger.InfoFormat("非正常情况匹配成功,MonitorDeviceQueueEntity.FlogID: [{0}]", MonitorEntity.FLogID); } } #endregion } else { } } catch (Exception ex) { logger.Error(dv); throw ex; } }