public ResultView.ResultLoadForecastMap GetLoadForecastChart() { var inputValue = _ntsPage.Request.Form["Inputs"]; var query = Newtonsoft.Json.JsonConvert.DeserializeObject <QueryLoadForecast>(inputValue); ResultLoadForecastMap res = Framework.Common.BaseWcf.CreateChannel <ServiceInterface.ILoadForecastService>("LoadForecastService").GetLoadForecastChart(query); return(res); }
public ResultLoadForecastMap GetLoadForecastChart(QueryLoadForecast loadCast) { try { ResultLoadForecastMap mapNew = new ResultLoadForecastMap(); ExecuteProcess proc = new ExecuteProcess(); proc.ActionName = ""; proc.ActionTime = DateTime.Now; proc.ActionUser = ""; proc.ExceptionMsg = ""; proc.Success = true; var basicQuery = new BasicQuery { EndTime = loadCast.EndTime, StartTime = loadCast.StartTime, ItemCode = loadCast.ItemCode, Unit = loadCast.Particle, AreaType = loadCast.ObjType, ObjectNum = loadCast.ObjectId }; // 获取数据 var resultList = GetDateTongJiData(basicQuery); List <decimal> lstDecAvg = GetYuceData(basicQuery, loadCast); List <SerialData> serData = new List <SerialData>(); foreach (var d in resultList.Enery) { SerialData ser1 = new SerialData(); ser1.name = "负荷预测值"; ser1.data = lstDecAvg; serData.Add(ser1); ser1 = new SerialData(); ser1.name = "能耗实际值"; TimeSpan ts = DateTime.Parse(System.DateTime.Now.ToString("yyyy-MM-dd")) - loadCast.StartTime; int DayChas = ts.Days; List <decimal> lstNew = d.Value; if (DayChas == 0) { for (int iCount = 0; iCount < lstNew.Count; iCount++) { lstNew[iCount] = Math.Round(lstNew[iCount], 2); } } else if (DayChas > 0) { for (int iCount = 0; iCount < lstNew.Count; iCount++) { if (iCount > DayChas) { lstNew[iCount] = 0; } else { lstNew[iCount] = Math.Round(lstNew[iCount], 2); } } } else { for (int i = 0; i < lstNew.Count; i++) { lstNew[i] = -9999; } } ser1.data = lstNew; serData.Add(ser1); } mapNew.ActionInfo = proc; // 判断是否是将来当天数据。 if (loadCast.StartTime.CompareTo(DateTime.Now) > 0) { List <SerialData> serDataNew = new List <SerialData>(); serDataNew.Add(serData[0]); mapNew.series = serDataNew; } else { mapNew.series = serData; } if (resultList.Dept.Count > 0) { mapNew.Unit = resultList.Dept[0].ToString(); } List <ResultLoadForecastList> listFore = new List <ResultLoadForecastList>(); for (int i = 0; i < serData[0].data.Count; i++) { ResultLoadForecastList list = new ResultLoadForecastList(); list.Id = i + 1; if (loadCast.StartTime.Date == loadCast.EndTime.Date) { string hour = ""; if (i < 10) { hour = "0" + i.ToString(); } else { hour = i.ToString(); } list.TimeArea = loadCast.StartTime.ToString("yyyy-MM-dd" + " " + hour + ":00:00"); } else { list.TimeArea = loadCast.StartTime.AddDays(i).ToString("yyyy-MM-dd"); } if (i < serData[1].data.Count) { list.History = Math.Round(serData[1].data[i], 2); } else { list.History = -9999; } list.ForeCast = Math.Round(serData[0].data[i], 2); if (list.History == -9999) { list.Deviation = -9999; } else { list.Deviation = Math.Round((serData[0].data[i] - serData[1].data[i]), 2); } if (list.History == -9999) { list.Pecent = "--"; listFore.Add(list); } else { decimal dec1 = (serData[0].data[i] - serData[1].data[i]) * 100; decimal dec2 = serData[1].data[i]; if (dec1 != 0 && dec2 != 0) { decimal pec = (serData[0].data[i] - serData[1].data[i]) * 100 / serData[1].data[i]; list.Pecent = Math.Round(pec, 2).ToString() + "%"; listFore.Add(list); } else { list.Pecent = "--"; listFore.Add(list); } } } mapNew.LoadForecast = listFore; mapNew.HistoryTotal = 0; Math.Round(serData[1].data.Sum(), 2); for (int rCount = 0; rCount < serData[1].data.Count; rCount++) { if (serData[1].data[rCount] != -9999) { mapNew.HistoryTotal = mapNew.HistoryTotal + serData[1].data[rCount]; } } mapNew.ForeCastTotal = Math.Round(lstDecAvg.Sum(), 2); return(mapNew); } catch (Exception ex) { ResultLoadForecastMap map2 = new ResultLoadForecastMap(); ExecuteProcess proc = new ExecuteProcess(); proc.ActionName = ""; proc.ActionTime = DateTime.Now; proc.ActionUser = ""; proc.ExceptionMsg = ex.Message; proc.Success = false; map2.ActionInfo = proc; return(map2); } }
public string ExportLoadForecast() { var inputValue = _ntsPage.Request.Form["Inputs"]; var query = Newtonsoft.Json.JsonConvert.DeserializeObject <QueryLoadForecast>(inputValue); ResultLoadForecastMap dtRef = Framework.Common.BaseWcf.CreateChannel <ServiceInterface.ILoadForecastService>("LoadForecastService").GetLoadForecastChart(query); try { if ((dtRef != null) && (dtRef.LoadForecast.Count > 0)) { DataTable dtReport = TableView.CreateFee_ForecastDataTable(); List <ResultLoadForecastList> listNew = dtRef.LoadForecast; for (var r = 0; r < listNew.Count; r++) { DataRow dr = dtReport.NewRow(); dr[1] = listNew[r].TimeArea.ToString(); dr[2] = listNew[r].ForeCast.ToString(); if (listNew[r].History == -9999) { dr[3] = "--"; dr[4] = "--"; dr[5] = "--"; } else { dr[3] = listNew[r].History.ToString(); dr[4] = listNew[r].Deviation.ToString(); dr[5] = listNew[r].Pecent.ToString(); } dtReport.Rows.Add(dr); } string temp_path = AppDomain.CurrentDomain.BaseDirectory + "temp_file\\"; if (!Directory.Exists(temp_path)) { Directory.CreateDirectory(temp_path); string[] files = Directory.GetFiles(temp_path); foreach (string fn in files) { File.Delete(temp_path + fn); } } string save_path = DateTime.Now.Ticks + ".xls"; string templatePath = AppDomain.CurrentDomain.BaseDirectory + "template\\负荷预测表.xls"; TemplateParam param = new TemplateParam("负荷预测表", new CellParam(0, 0), "", new CellParam(3, 0), false, new CellParam(4, 0)); //TemplateParam param = new TemplateParam("itemCodeName", new CellParam(1, 1),"",null, false, new CellParam(5, 0)); param.DataColumn = new[] { 0, 1, 2, 3, 4, 5 }; //param.ItemUnit = "(单位:元"; //param.ItemUnitCell = new CellParam(3, 5); dtReport.TableName = "负荷预测表"; ExportHelper.ExportExcel(dtReport, temp_path + save_path, templatePath, param); return("{\"status\":\"success\",\"msg\":\"" + "/temp_file/" + save_path + "\"}"); } else { return("{\"status\":\"error\",\"msg\":\"导出失败:当前无任何数据\"}"); } } catch (Exception ex) { return("{\"status\":\"error\",\"msg\":\"导出失败:由于当前无数据或其他原因导致" + ex.Message + "\"}"); } }