public ActionResult Units_Output(int id) { Plant plant = FindPlant(id); IList <PlantUnit> plantUnits = PlantUnitService.GetInstance().GetAllPlantUnitsByPlantId(id); CsvStreamWriter writer = new CsvStreamWriter(); IList <string> listData = new List <string>(); listData.Add(string.Format("{0},{1},{2},{3},{4},{5},{6},{7},{8},", Resources.SunResource.PLANT_UNIT_LIST_STATUS, Resources.SunResource.PLANT_UNIT_DATA_SOURCE_CODE , Resources.SunResource.PLANT_UNIT_LIST_UNIT_NAME, Resources.SunResource.PLANT_UNIT_LIST_POWER + "(kW)", Resources.SunResource.PLANT_UNIT_LIST_YEAR_ENERGY + "(kWh)", Resources.SunResource.PLANT_UNIT_LIST_ENERGY + "(kWh)", Resources.SunResource.PLANT_UNIT_LIST_MONTH_ENERGY + "(kWh)", Resources.SunResource.PLANT_UNIT_LIST_MONTH_ENERGY_KWP + "(kWh/kWp)", Resources.SunResource.PLANT_UNIT_LIST_YEAR_ENERGY_KWP + "(kWh/kWp)" )); CollectorMonthDayData cmData = null; CollectorYearData cyData = null; foreach (PlantUnit unit in plantUnits) { float currentMonthEnergy = 0; float currentYearEnergy = 0; cmData = CollectorMonthDayDataService.GetInstance().GetCollectorMonthDayData(DateTime.Now.Year, unit.collector.id, DateTime.Now.Month); currentMonthEnergy = cmData == null ? 0 : cmData.count(); cyData = CollectorYearDataService.GetInstance().GetCollectorYearData(unit.collector.id, DateTime.Now.Year); currentYearEnergy = cyData == null ? 0 : cyData.dataValue; listData.Add(string.Format("{0},{1},{2},{3},{4},{5},{6},{7},{8},", unit.isWork(plant.timezone) ? Resources.SunResource.MONITORITEM_WORKING : Resources.SunResource.MONITORITEM_STOPPED, string.Format("\t{0}", unit.collector.code) , string.Format("\t{0}", unit.displayname), unit.TodayPower(plant.timezone).ToString(), currentYearEnergy.ToString(), unit.displayTotalEnergy.ToString(), currentMonthEnergy.ToString(), Math.Round(currentMonthEnergy / unit.chartPower, 2).Equals(double.NaN) ? "0" : Math.Round(currentMonthEnergy / unit.chartPower, 2).ToString(), Math.Round(currentYearEnergy / unit.chartPower, 2).Equals(double.NaN) ? "0" : Math.Round(currentYearEnergy / unit.chartPower, 2).ToString() )); } writer.AddStrDataList(listData); string fullFile = Server.MapPath("/") + "tempexportfile\\" + Resources.SunResource.PLANT_UNIT_LIST_FILENAME + ".csv"; writer.Save(fullFile); //转化为csv格式的字符串 ActionResult tmp = File(fullFile, "text/csv; charset=UTF-8", urlcode(Resources.SunResource.PLANT_UNIT_LIST_FILENAME) + ".csv"); return(tmp); }
/// <summary> /// 缓存采集器发电量统计 /// 要进行修正缓存丢失 /// /// </summary> /// <param name="tcpmessage"></param> private static void CacheCollectorEnergyData(IDictionary <string, double?> collectorEnergyMap) { int collectorID; string[] keyArr; int year; int month; int day; float? data; Collector collector = null; //string[] keys = collectorEnergyMap.Keys.ToArray(); foreach (string ekey in collectorEnergyMap.Keys) { try { keyArr = ekey.Split(':'); collectorID = int.Parse(keyArr[0]); //原来是通过消息头部取得,现在改为 data = collectorEnergyMap[ekey] == null ? 0 : float.Parse(collectorEnergyMap[ekey].ToString()); if (data == 0)//如果头部未传或者为0则再从设备累计下看看 { //现在改为通过采集器的设备的今日电量来累加 collector = CollectorInfoService.GetInstance().Get(collectorID); if (keyArr.Length < 4 || (string.IsNullOrEmpty(keyArr[1]) || string.IsNullOrEmpty(keyArr[2]) || string.IsNullOrEmpty(keyArr[3]))) { continue; } data = collector.deviceTodayEnergy(keyArr[1] + keyArr[2] + keyArr[3]); } year = int.Parse(keyArr[1]); month = int.Parse(keyArr[2]); day = int.Parse(keyArr[3]); string d_column = "d_" + day; //取得月天数据对象 CollectorMonthDayData collectorMonthDayData = CollectorMonthDayDataService.GetInstance().GetCollectorMonthDayData(year, collectorID, month); collectorMonthDayData.curDay = day; //给相应属性赋值 if (collectorMonthDayData != null) { object ovalue = ReflectionUtil.getProperty(collectorMonthDayData, d_column); if (ovalue == null || float.Parse(ovalue.ToString()) < data) { ReflectionUtil.setProperty(collectorMonthDayData, d_column, data); } } CollectorMonthDayDataService.GetInstance().Cache(collectorMonthDayData); //更新年月发电量数据 //统计年月 string m_column = "m_" + month; float? m_value = collectorMonthDayData.count(); CollectorYearMonthData ymdData = CollectorYearMonthDataService.GetInstance().GetCollectorYearMonthData(collectorID, year);; ymdData.curMonth = month; //给年月数据对象相应属性赋值 if (ymdData != null) { object ovalue = ReflectionUtil.getProperty(ymdData, m_column); if (ovalue == null || float.Parse(ovalue.ToString()) < m_value) { ReflectionUtil.setProperty(ymdData, m_column, m_value); } } CollectorYearMonthDataService.GetInstance().Cache(ymdData); //统计总体发电量 float? y_value = ymdData.count(); CollectorYearData yd = CollectorYearDataService.GetInstance().GetCollectorYearData(collectorID, year); if (yd == null) { yd = new CollectorYearData() { dataValue = 0, collectorID = collectorID, year = year } } ; yd.localAcceptTime = DateTime.Now; //给年月数据对象相应属性赋值 if (yd != null) { object ovalue = yd.dataValue; if (ovalue == null || float.Parse(ovalue.ToString()) < y_value) { yd.dataValue = y_value == null ? 0 : float.Parse(y_value.ToString()); } } CollectorYearDataService.GetInstance().Cache(yd); } catch (Exception onee) {//捕获单个异常,保证一个错误不影响其他采集器数据处理 LogUtil.error("Cache collectorEnergyMap of ekey is " + ekey + " error:" + onee.Message); } } }
public void peristentData() { Console.WriteLine("开始持久化"); //持久化设备天数据 try { DeviceDayDataService.GetInstance().batchSave(BaseMessage.devicedayDataMapList); } catch (Exception ee) { LogUtil.error("持久化设备天数据异常:" + ee.Message); } //持久化采集器天数据 try { CollectorDayDataService.GetInstance().batchSave(BaseMessage.collectordayDataMap); } catch (Exception ee) { LogUtil.error("持久化采集器天数据异常:" + ee.Message); } //持久化设备实时数据 try{ DeviceRunDataService.GetInstance().batchSave(); } catch (Exception ee) { LogUtil.error("持久化设备实时数据数据异常:" + ee.Message); } //持久化采集器实时数据 try { LogUtil.writeline("start 持久化采集器实时数据"); CollectorRunDataService.GetInstance().batchSave(); } catch (Exception ee) { LogUtil.error("持久化采集器实时数据异常:" + ee.Message); } //持久化最大值统计 try{ DeviceDataCountService.GetInstance().batchSave(); } catch (Exception ee) { LogUtil.error("持久化最大值统计异常:" + ee.Message); } //持久化设备月天数据 try{ DeviceMonthDayDataService.GetInstance().batchSave(); } catch (Exception ee) { LogUtil.error("持久化设备月天数据异常:" + ee.Message); } //持久化采集器月天数据 try{ CollectorMonthDayDataService.GetInstance().batchSave(); } catch (Exception ee) { LogUtil.error("持久化采集器月天数据异常:" + ee.Message); } //持久化设备年月数据 try{ DeviceYearMonthDataService.GetInstance().batchSave(); } catch (Exception ee) { LogUtil.error("持久化设备年月数据异常:" + ee.Message); DeviceYearMonthDataService.GetInstance().batchSave(); } //持久化采集器年月数据 try{ CollectorYearMonthDataService.GetInstance().batchSave(); } catch (Exception ee) { LogUtil.error("持久化采集器年月数据异常:" + ee.Message); } //持久化设备总体数据 try{ DeviceYearDataService.GetInstance().batchSave(); } catch (Exception ee) { LogUtil.error("持久化采集器年月数据异常:" + ee.Message); } //持久化采集器总体数据 try { CollectorYearDataService.GetInstance().batchSave(); } catch (Exception ee) { LogUtil.error("持久化采集器总体数据异常:" + ee.Message); } }
public static void peristentData() { Console.WriteLine("开始持久化"); //持久化设备天数据 try { DeviceDayDataService.GetInstance().batchSave(BaseMessage.devicedayDataMapList); } catch (Exception ee) { LogUtil.error("持久化设备天数据异常:" + ee.Message); } //持久化采集器天数据 try { CollectorDayDataService.GetInstance().batchSave(BaseMessage.collectordayDataMap); } catch (Exception ee) { LogUtil.error("持久化采集器天数据异常:" + ee.Message); } //持久化设备实时数据 try{ DeviceRunDataService.GetInstance().batchSave(); } catch (Exception ee) { LogUtil.error("持久化设备实时数据数据异常:" + ee.Message); } //持久化采集器实时数据 try { LogUtil.writeline("start 持久化采集器实时数据"); CollectorRunDataService.GetInstance().batchSave(); } catch (Exception ee) { LogUtil.error("持久化采集器实时数据异常:" + ee.Message); } //持久化最大值统计 try{ DeviceDataCountService.GetInstance().batchSave(); } catch (Exception ee) { LogUtil.error("持久化最大值统计异常:" + ee.Message); } //持久化设备月天数据 try{ DeviceMonthDayDataService.GetInstance().batchSave(); } catch (Exception ee) { LogUtil.error("持久化设备月天数据异常:" + ee.Message); } //持久化采集器月天数据 try{ CollectorMonthDayDataService.GetInstance().batchSave(); } catch (Exception ee) { LogUtil.error("持久化采集器月天数据异常:" + ee.Message); } //持久化设备年月数据 try{ DeviceYearMonthDataService.GetInstance().batchSave(); } catch (Exception ee) { LogUtil.error("持久化设备年月数据异常:" + ee.Message); //DeviceYearMonthDataService.GetInstance().batchSave(); } //持久化采集器年月数据 try{ CollectorYearMonthDataService.GetInstance().batchSave(); } catch (Exception ee) { LogUtil.error("持久化采集器年月数据异常:" + ee.Message); } //持久化设备总体数据 try{ DeviceYearDataService.GetInstance().batchSave(); } catch (Exception ee) { LogUtil.error("持久化采集器年月数据异常:" + ee.Message); } //持久化采集器总体数据 try { CollectorYearDataService.GetInstance().batchSave(); } catch (Exception ee) { LogUtil.error("持久化采集器总体数据异常:" + ee.Message); } //add by qhb in 20120415 for 2.0协议持久化电站信息,持久化后不删除, try { PlantService.GetInstance().batchSave(BaseMessage.plantInfoMap); } catch (Exception ee) { LogUtil.error("持久化电站信息数据异常:" + ee.Message); } //add by qhb in 20120715 for 2.0协议持久化设备信息,持久化后不删除, try { DeviceService.GetInstance().batchSave(BaseMessage.deviceInfoMap); } catch (Exception ee) { LogUtil.error("持久化设备信息数据异常:" + ee.Message); } }
/// <summary> /// 缓存采集器发电量统计 /// 要进行修正缓存丢失 /// /// </summary> /// <param name="tcpmessage"></param> private static void CacheCollectorEnergyData(IDictionary <string, double> collectorEnergyMap) { int collectorID; string[] keyArr; int year; int month; int day; float? data; Collector collector = null; //string[] keys = collectorEnergyMap.Keys.ToArray(); foreach (string ekey in collectorEnergyMap.Keys) { //原来是通过消息头部取得,现在改为 //data = float.Parse(collectorEnergyMap[ekey].ToString()); //现在改为通过采集器的设备的今日电量来累加 keyArr = ekey.Split(':'); collectorID = int.Parse(keyArr[0]); collector = CollectorInfoService.GetInstance().Get(collectorID); data = collector.TodayEnergy(keyArr[1] + keyArr[2] + keyArr[3]); //改为通过所含设备的 year = int.Parse(keyArr[1]); month = int.Parse(keyArr[2]); day = int.Parse(keyArr[3]); string d_column = "d_" + day; //取得月天数据对象 CollectorMonthDayData collectorMonthDayData = CollectorMonthDayDataService.GetInstance().GetCollectorMonthDayData(year, collectorID, month); collectorMonthDayData.curDay = day; //给相应属性赋值 if (collectorMonthDayData != null) { object ovalue = ReflectionUtil.getProperty(collectorMonthDayData, d_column); //if (ovalue == null || float.Parse(ovalue.ToString()) < data) //{ ReflectionUtil.setProperty(collectorMonthDayData, d_column, data); //} } CollectorMonthDayDataService.GetInstance().Cache(collectorMonthDayData); //更新年月发电量数据 //统计年月 string m_column = "m_" + month; float? m_value = collectorMonthDayData.count(); CollectorYearMonthData ymdData = CollectorYearMonthDataService.GetInstance().GetCollectorYearMonthData(collectorID, year);; ymdData.curMonth = month; //给年月数据对象相应属性赋值 if (ymdData != null) { object ovalue = ReflectionUtil.getProperty(ymdData, m_column); if (ovalue == null || float.Parse(ovalue.ToString()) < m_value) { ReflectionUtil.setProperty(ymdData, m_column, m_value); } } CollectorYearMonthDataService.GetInstance().Cache(ymdData); //统计总体发电量 float? y_value = ymdData.count(); CollectorYearData yd = CollectorYearDataService.GetInstance().GetCollectorYearData(collectorID, year); if (yd == null) { yd = new CollectorYearData() { dataValue = 0, collectorID = collectorID, year = year } } ; yd.localAcceptTime = DateTime.Now; //给年月数据对象相应属性赋值 if (yd != null) { object ovalue = yd.dataValue; if (ovalue == null || float.Parse(ovalue.ToString()) < y_value) { yd.dataValue = y_value == null ? 0 : float.Parse(y_value.ToString()); } } CollectorYearDataService.GetInstance().Cache(yd); } } }