/// <summary> /// 取得采集器日数据列表 /// </summary> /// <returns></returns> public void GetCollectorDaydataList() { //如果没有数据则直接返回,增加for2.0协议,分包发送消息的情况 if (!messageHeader.hasData) return; //将单元头部的发电量加入历史测点数据map中,然后统一处理 if (!messageHeader.issub)//只有电站数据加入者两个电站测点 { if(messageHeader.DayEnergy!=null) historyMonitorMap[MonitorType.PLANT_MONITORITEM_ENERGY_CODE] = messageHeader.DayEnergy; if(messageHeader.Power!=null) historyMonitorMap[MonitorType.PLANT_MONITORITEM_POWER_CODE] = messageHeader.Power; } int collectorID = GetCollectorId(); //根据历史测点数据构建设备天数据 //这里需要改进为依据设备时间,防止设备数据的时间和采集器的时间是不一致的 CollectorDayData mdd; string mapObjectKey; //遍历测点数据 foreach (int key in historyMonitorMap.Keys) { mapObjectKey = CacheKeyUtil.buildCollectorDayDataKey(collectorID, messageHeader.year + messageHeader.month, int.Parse(messageHeader.day), key); if (!collectordayDataMap.ContainsKey(mapObjectKey)) { //先从缓存中取得 mdd = CollectorDayDataService.GetInstance().getCollectorDayData(collectorID, key, int.Parse(messageHeader.day), int.Parse(messageHeader.year), int.Parse(messageHeader.month)); if (mdd == null) mdd = new CollectorDayData() { collectorID = collectorID, sendDay = int.Parse(messageHeader.day), monitorCode = key, yearmonth = messageHeader.year + messageHeader.month }; collectordayDataMap[mapObjectKey] = mdd; } else { mdd = collectordayDataMap[mapObjectKey]; } float newValue = historyMonitorMap[key]==null?0:float.Parse(historyMonitorMap[key].ToString()); string tmpStr = "#" + messageHeader.hour + messageHeader.minute + messageHeader.second + ":" + newValue; if (mdd.dataContent != null) {//避免数据串有重复数据过大 if (!mdd.dataContent.Contains(tmpStr)) mdd.dataContent += tmpStr; } else { mdd.dataContent = tmpStr; } mdd.sendtime = messageHeader.TimeNow; mdd.localAcceptTime = DateTime.Now; mdd.yearmonth = messageHeader.year + messageHeader.month; mdd.changed = true; //add by qhb in 20121028 for 会写到memcahced 以便持久化能取到改数据.采集器天数据集中缓存处有点问题,和设备天数据一样的问题。 //导致曲线数据有丢失现象 try { MemcachedClientSatat.getInstance().Set(mapObjectKey, mdd); } catch (Exception e) { Console.WriteLine("set collector day data to memecached error:" + e.Message); //出现错误,可能是mdd太大,所以整理下mdd,去掉重复数据,减少size,因为memached内存有2m限制 } //将功率和关照的最大发生时间记录下来.稍后优化下 if (key == MonitorType.PLANT_MONITORITEM_POWER_CODE) { //if (collectorID >= 189 && collectorID < 199) //{ // LogUtil.writeline(messageHeader.TimeNow + "-" + newValue); //} //LogUtil.warn("collectorDataCount = new DeviceDataCount(): collectorID is " + collectorID + "-" + messageHeader.year.ToString() + messageHeader + ""); collectorDataCount = new DeviceDataCount() { deviceId = collectorID, monitorCode = key, year = int.Parse(messageHeader.year), month = int.Parse(messageHeader.month), day = int.Parse(messageHeader.day), deviceTable = TableUtil.PLANT, maxValue = newValue, maxTime = messageHeader.TimeNow, localAcceptTime = DateTime.Now }; } } }
/// <summary> /// 获取电站日数据信息 /// </summary> /// <param name="dayData"></param> /// <returns></returns> public CollectorDayData Get(CollectorDayData dayData) { return _powerDayDataDao.Get(dayData); }
/// <summary> /// 取得采集器日数据列表 /// </summary> /// <returns></returns> public void GetCollectorDaydataList() { //将单元头部的发电量加入历史测点数据map中,然后统一处理 historyMonitorMap[MonitorType.PLANT_MONITORITEM_ENERGY_CODE] = messageHeader.DayEnergy ; historyMonitorMap[MonitorType.PLANT_MONITORITEM_POWER_CODE] = messageHeader.Power; int collectorID = GetCollectorId(); //根据历史测点数据构建设备天数据 //这里需要改进为依据设备时间,防止设备数据的时间和采集器的时间是不一致的 CollectorDayData mdd; string mapObjectKey; //遍历测点数据 foreach (int key in historyMonitorMap.Keys) { mapObjectKey = CacheKeyUtil.buildCollectorDayDataKey(collectorID, messageHeader.year + messageHeader.month, int.Parse(messageHeader.day), key); if (!collectordayDataMap.ContainsKey(mapObjectKey)) { //先从缓存中取得 mdd = CollectorDayDataService.GetInstance().getCollectorDayData(collectorID, key, int.Parse(messageHeader.day), int.Parse(messageHeader.year), int.Parse(messageHeader.month)); if (mdd == null) mdd = new CollectorDayData() { collectorID = collectorID, sendDay = int.Parse(messageHeader.day), monitorCode = key, yearmonth = messageHeader.year + messageHeader.month }; collectordayDataMap[mapObjectKey] = mdd; } else { mdd = collectordayDataMap[mapObjectKey]; } float newValue = historyMonitorMap[key]==null?0:float.Parse(historyMonitorMap[key].ToString()); mdd.dataContent += "#" + messageHeader.hour + messageHeader.minute + messageHeader.second + ":" + newValue; mdd.sendtime = messageHeader.TimeNow; mdd.localAcceptTime = DateTime.Now; mdd.yearmonth = messageHeader.year + messageHeader.month; mdd.changed = true; //将功率和关照的最大发生时间记录下来.稍后优化下 if (key == MonitorType.PLANT_MONITORITEM_POWER_CODE) { //if (collectorID >= 189 && collectorID < 199) //{ // LogUtil.writeline(messageHeader.TimeNow + "-" + newValue); //} collectorDataCount = new DeviceDataCount() { deviceId = collectorID, monitorCode = key, year = int.Parse(messageHeader.year), month = int.Parse(messageHeader.month), day = int.Parse(messageHeader.day), deviceTable = TableUtil.PLANT, maxValue = newValue, maxTime = messageHeader.TimeNow, localAcceptTime = DateTime.Now }; } } }
/// <summary> /// 删除天数据,按照id /// add by qhb in 20120828 /// </summary> /// <param name="dayData"></param> /// <returns></returns> public bool Delete(CollectorDayData dayData) { return _powerDayDataDao.Remove(dayData)>0?true:false; }