/// <summary> /// 预测 /// </summary> /// <param name="para"></param> /// <returns></returns> public CustomResult ForecastData(QueryParameters para) { if (listExport != null) listExport.Clear(); CustomResult pReturnValue = new CustomResult(); //浮动范围 double pFloating = 1 + para.FloatingRange * 0.01; List<RoadRunSitViewModel> pForeList = new List<RoadRunSitViewModel>(); //预测数据集合 List<IReportViewModel> pInList = new List<IReportViewModel>(); try { using (DataSubmittedEntities db = new DataSubmittedEntities()) { //判断报表浮动百分比配置是否存在 OT_HDayConfig pds = HolidayConfig.GetInstance().GetById(para.ReportType); if (pds == null) { pReturnValue.ResultKey = (byte)EResult.Fail; pReturnValue.ResultValue = TipInfo.ForecastFaileNoConfig; return pReturnValue; } //判断报表预测浮动百分比配置是否正确 if (Math.Abs(para.FloatingRange) > (double)pds.ForeFloat.Value) { pReturnValue.ResultKey = (byte)EResult.Fail; pReturnValue.ResultValue = TipInfo.ErrorInfo + "范围应在负" + pds.ForeFloat.Value + "%-正" + pds.ForeFloat.Value + "%之间"; return pReturnValue; } //获取参考日期符合的数据 List<RP_AADTSta> pRefInfoList = db.RP_AADTSta.Where(s => s.CalculTime == para.StartTime).ToList(); //如果参考日期数据为0 则返回失败 if (pRefInfoList==null||pRefInfoList.Count == 0) { pReturnValue.ResultKey = (byte)EResult.Fail; pReturnValue.ResultValue = TipInfo.ForecastFaileFaileRefNoData; return pReturnValue; } //预测数据 RoadRunSitViewModel info = new RoadRunSitViewModel(); //预测数据集合 List<IReportViewModel> plist = new List<IReportViewModel>(); //参考数据 foreach (RP_AADTSta pRefInfo in pRefInfoList) { //出京总交通量(路线) info.LineExSum = Math.Round(pRefInfo.LineExSum == null ? 0 : pRefInfo.LineExSum.Value * pFloating, 2); //进京总交通量(路线) info.LineEnSum = Math.Round(pRefInfo.LineEnSum == null ? 0 : pRefInfo.LineEnSum.Value * pFloating, 2); //总交通量(路线) info.LineSum = info.LineExSum + info.LineEnSum; //小型客车免费通行交通量(合计) info.SmaCarFeeNum = Math.Round(pRefInfo.ExSmaCarFee == null ? 0 : pRefInfo.ExSmaCarFee.Value + pRefInfo.EnSmaCarFee == null ? 0 : pRefInfo.EnSmaCarFee.Value, 2); //小型客车免费金额 info.SmaCarFee = Math.Round(pRefInfo.SmaCarFee == null ? 0 : pRefInfo.SmaCarFee.Value * (decimal)pFloating, 2); //收费车辆(合计) info.ChagSumNum = Math.Round(pRefInfo.ChagSumNum == null ? 0 : pRefInfo.ChagSumNum.Value * pFloating, 2); //数据日期 info.CalculTime = (pRefInfo.CalculTime).Month + "月" + (pRefInfo.CalculTime).Day + "日"; //出进京比“出进京比”=出京交通量/进京交通量,保留两位小数。 if (info.LineEnSum != 0) { info.ExEnPer = Math.Round(info.LineExSum / info.LineEnSum, 2); } //“同比增幅”=(本年数据-去年数据)/去年数据*100%,保留两位小数。 //小型客车交通量同比增幅 info.SmaCarCompGrow = pRefInfo.SmaCarCompGrow == null ? "0.00" : Math.Round(pRefInfo.SmaCarCompGrow.Value, 2).ToString(); //总交通量同比增幅 info.SumGrow = pRefInfo.SumGrow == null ? "0.00" : Math.Round(pRefInfo.SumGrow.Value, 2).ToString(); plist.Add(info); } string path = Export(para, plist); pReturnValue.ResultKey = (byte)EResult.Succeed; pReturnValue.ResultValue = path; } } catch (Exception e) { pReturnValue.ResultKey = (byte)EResult.Fail; pReturnValue.ResultValue = TipInfo.ForecastFail + e.Message.ToString(); SystemLog.GetInstance().Error(TipInfo.ForecastFail, e); return pReturnValue; } return pReturnValue; }
/// <summary> /// 获取和构造数据 /// </summary> /// <param name="para"></param> /// <returns></returns> private List<RoadRunSitViewModel> GetData(QueryParameters para) { RepairData(para);//补数据 List<RoadRunSitViewModel> list; using (DataSubmittedEntities db = new DataSubmittedEntities()) { list = StrWhere(db, para).OrderBy(a => a.CalculTime).Select(a => new RoadRunSitViewModel { CalculTime = ((DateTime)a.CalculTime).Month + "月" + ((DateTime)a.CalculTime).Day + "日", ChagSumNum = Math.Round((double)a.ChagSumNum / 10000, 2), ExEnPer = Math.Round((double)a.ExEnPer, 2), LineEnSum = Math.Round((double)a.LineEnSum / 10000, 2), LineExSum = Math.Round((double)a.LineExSum / 10000, 2), LineSum = Math.Round((double)a.LineSum / 10000, 2), SmaCarCompGrow = a.SmaCarCompGrow.Value == null ? "0.00" : Math.Round(a.SmaCarCompGrow.Value, 2).ToString(), SmaCarFee = Math.Round((decimal)a.SmaCarFee, 2), SmaCarFeeNum = Math.Round((double)a.SmaCarFeeNum / 10000, 2), SumGrow = a.SumGrow.Value == null ? "0.00" : Math.Round(a.SumGrow.Value, 2).ToString(), }).ToList(); //查询后无数据则按照查询时间构造数据 if (list == null || list.Count == 0) { RoadRunSitViewModel model = new RoadRunSitViewModel(); model.CalculTime = ((DateTime)para.StartTime).ToString("M月d日"); model.ChagSumNum = 0.00; model.ExEnPer = 0.00; model.LineEnSum = 0.00; model.LineExSum = 0.00; model.LineSum = 0.00; model.SmaCarCompGrow = "0.00"; model.SmaCarFee = (decimal)0.00; model.SmaCarFeeNum = 0.00; model.SumGrow = "0.00"; list.Add(model); } listExport.Clear(); listExport.AddRange(list); } return list; }