/// <summary> /// 取得采集器实时数据 /// </summary> /// <returns></returns> public void GetCollectorRunData() { //如果没有数据则直接返回,增加for2.0协议,分包发送消息的情况 if (!messageHeader.hasData) return; int collectorID = GetCollectorId(); CollectorRunData dsrd; if (!collectorRunDataMap.ContainsKey(collectorID)) { dsrd = CollectorRunDataService.GetInstance().Get(collectorID); if (dsrd == null) dsrd = new CollectorRunData(); dsrd.collectorID = collectorID; collectorRunDataMap[collectorID] = dsrd; } else { dsrd = collectorRunDataMap[collectorID]; } //modify by hbqian for 历史数据不更新实时数据,只有当原有数据是超前的才会被历史数据替换 at 2013-07-29 //比如他现在传输的应该是 17号11点30的数据,传输完了后,又传了个历史数据是17号6点的数据,那么这个时候实时数据显示的是17号6点的历史数据,而不是17号11点30的实时数据,要显示为最新的即11:30的数据,这个地方请加个判断 //旧的数据不再更新实时数据,20130729修改为 当原有时间是超前的仍然更新,这里用服务器时间判断没有考虑时差,还是有点不准确,非超前则不更新,即实时数据始终显示最新的 if (messageHeader.TimeNow < dsrd.sendTime && dsrd.sendTime < DateTime.Now) return; if ((messageHeader.DayEnergy!=null && dsrd.dayEnergy < messageHeader.DayEnergy) || (messageHeader.DayEnergy!=null && dsrd.sendTime.Day != messageHeader.TimeNow.Day)) dsrd.dayEnergy = messageHeader.DayEnergy.Value; if (messageHeader.TotalEnergy!=null && dsrd.totalEnergy < messageHeader.TotalEnergy) dsrd.totalEnergy = messageHeader.TotalEnergy.Value; if(messageHeader.Power!=null) { dsrd.power = messageHeader.Power.Value; } dsrd.sendTime = messageHeader.TimeNow; //if (realMonitorMap.ContainsKey(MonitorType.PLANT_MONITORITEM_WINDSPEED)) //{ //string str = this.realMonitorMap[MonitorType.PLANT_MONITORITEM_WINDSPEED].ToString(); //dsrd.windSpeed = str.IndexOf(".") > 0 ? int.Parse(str.Substring(0, str.IndexOf("."))) : int.Parse(str); // } //else { //dsrd.windSpeed = null; //} //if (realMonitorMap.ContainsKey(MonitorType.PLANT_MONITORITEM_WINDDIRECTION)) //{ //string str = this.realMonitorMap[MonitorType.PLANT_MONITORITEM_WINDDIRECTION].ToString(); //dsrd.windDirection = str.IndexOf(".") > 0 ? int.Parse(str.Substring(0, str.IndexOf("."))) : int.Parse(str); //} //else { //dsrd.windDirection = null; //} //if (realMonitorMap.ContainsKey(MonitorType.PLANT_MONITORITEM_AMBIENTTEMP_CODE)) //dsrd.temperature = float.Parse(this.realMonitorMap[MonitorType.PLANT_MONITORITEM_AMBIENTTEMP_CODE].ToString()); //else { //只有电站数据才用其数据更新实时数据 //if (!messageHeader.issub) //{ dsrd.temperature = messageHeader.temperature; //} //} //不在从环境监测仪取数据,该有前台显示时判断 先去环境建议侧 //if (realMonitorMap.ContainsKey(MonitorType.PLANT_MONITORITEM_LINGT_CODE)) //{ //string str = this.realMonitorMap[MonitorType.PLANT_MONITORITEM_LINGT_CODE].ToString(); //dsrd.sunStrength = str.IndexOf(".") > 0 ? int.Parse(str.Substring(0, str.IndexOf("."))) : int.Parse(str); //} //else { //只有电站数据才用其数据更新实时数据 //if (!messageHeader.issub) //{ dsrd.sunStrength = messageHeader.sunStrength; //} //} //dsrd.changed = true; }
/// <summary> /// 判断采集器对应的实时数据是否存在 /// </summary> /// <param name="rundata"></param> /// <returns></returns> private bool ExistCollectorRunData(CollectorRunData rundata) { if (collectorIdList.Contains(rundata.collectorID)) return true; else { //LogUtil.writeline("get collector Run Data" + rundata.collectorID); CollectorRunData tmp = _plantRunDataDao.Get(rundata); if (tmp == null) return false; collectorIdList.Add(tmp.collectorID); return true; } }
/// <summary> /// 取得采集器实时数据 /// </summary> /// <returns></returns> public void GetCollectorRunData() { int collectorID = GetCollectorId(); CollectorRunData dsrd; if (!collectorRunDataMap.ContainsKey(collectorID)) { dsrd = CollectorRunDataService.GetInstance().Get(collectorID); if (dsrd == null) dsrd = new CollectorRunData(); dsrd.collectorID = collectorID; collectorRunDataMap[collectorID] = dsrd; } else { dsrd = collectorRunDataMap[collectorID]; } if ((dsrd.dayEnergy < messageHeader.DayEnergy || dsrd.sendTime.Day != messageHeader.TimeNow.Day) || (messageHeader.TimeNow.Hour<6 && messageHeader.DayEnergy==0)) dsrd.dayEnergy = messageHeader.DayEnergy; if (dsrd.totalEnergy < messageHeader.TotalEnergy) dsrd.totalEnergy = messageHeader.TotalEnergy; dsrd.power = messageHeader.Power; dsrd.sendTime = messageHeader.TimeNow; if (realMonitorMap.ContainsKey(MonitorType.PLANT_MONITORITEM_WINDSPEED)) { string str = this.realMonitorMap[MonitorType.PLANT_MONITORITEM_WINDSPEED].ToString(); dsrd.windSpeed = str.IndexOf(".") > 0 ? int.Parse(str.Substring(0, str.IndexOf("."))) : int.Parse(str); } else { dsrd.windSpeed = null; } if (realMonitorMap.ContainsKey(MonitorType.PLANT_MONITORITEM_WINDDIRECTION)) { string str = this.realMonitorMap[MonitorType.PLANT_MONITORITEM_WINDDIRECTION].ToString(); dsrd.windDirection = str.IndexOf(".") > 0 ? int.Parse(str.Substring(0, str.IndexOf("."))) : int.Parse(str); } else { dsrd.windDirection = null; } if (realMonitorMap.ContainsKey(MonitorType.PLANT_MONITORITEM_AMBIENTTEMP_CODE)) dsrd.temperature = float.Parse(this.realMonitorMap[MonitorType.PLANT_MONITORITEM_AMBIENTTEMP_CODE].ToString()); else { dsrd.temperature = null; } if (realMonitorMap.ContainsKey(MonitorType.PLANT_MONITORITEM_LINGT_CODE)) { string str = this.realMonitorMap[MonitorType.PLANT_MONITORITEM_LINGT_CODE].ToString(); dsrd.sunStrength = str.IndexOf(".") > 0 ? int.Parse(str.Substring(0, str.IndexOf("."))) : int.Parse(str); } else { dsrd.sunStrength = null; } //dsrd.changed = true; }
/// <summary> /// 保存采集器实时数据 /// </summary> /// <param name="runData"></param> public void save(CollectorRunData runData) { if (runData == null) return; if (ExistCollectorRunData(runData)) { _plantRunDataDao.Update(runData); } else { _plantRunDataDao.Insert(runData); } }