/// <summary> /// 预测--修改工作簿内容 /// </summary> /// <param name="readworkbook"></param> /// <param name="para"></param> /// <param name="outlist">出口数据集合</param> /// <param name="inlist">入口数据集合</param> /// <returns></returns> public IWorkbook GenerateSheet(IWorkbook readworkbook, QueryParameters para, List <IReportViewModel> outlist, List <IReportViewModel> inlist) { //数据是外界传进来的,不需要载将单位转为万元 List <DataDailyInfoViewModel> pOutList = new List <DataDailyInfoViewModel>(); List <DataDailyInfoViewModel> pInList = new List <DataDailyInfoViewModel>(); foreach (var item in outlist) { DataDailyInfoViewModel datadaily = item as DataDailyInfoViewModel; pOutList.Add(datadaily); } foreach (var item in inlist) { DataDailyInfoViewModel datadaily = item as DataDailyInfoViewModel; pInList.Add(datadaily); } //获取工作簿 ISheet sheet = readworkbook.GetSheetAt(0); //设置日期 SetReportDate(sheet, 0, 8, DateTime.Parse(DateTime.Now.ToShortDateString()), para.ReportType); for (int i = 0; i < 4; i++) { string ptemp = i.ToString(); int rnum = i; //表样不完全相同,需要更改赋值单元格行数,1和2行数相同,3和4行数相同 if (para.ReportType == 3 || para.ReportType == 4) { rnum = i - 1; } //0小型客车,1其他客车,2货车(不包含绿通),3绿通 //出口 SetValue(sheet, rnum + 4, 2, pOutList.Where(s => s.VehType == ptemp).Sum(s => s.VehNum).ToString()); SetValue(sheet, rnum + 4, 4, pOutList.Where(s => s.VehType == ptemp).Sum(s => s.CarChag).ToString()); //入口 SetValue(sheet, rnum + 8, 2, pInList.Where(s => s.VehType == ptemp).Sum(s => s.VehNum).ToString()); } return(readworkbook); }
/// <summary> /// 预测数据 /// </summary> /// <param name="para"></param> /// <returns></returns> public CustomResult ForecastData(QueryParameters para) { CustomResult pReturnValue = new CustomResult(); //浮动范围 double pFloating = para.FloatingRange * 0.01; List <RP_Daily> pDailyList = new List <RP_Daily>(); //预测数据集合 List <IReportViewModel> pOutList = new List <IReportViewModel>(); 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_Daily> pRefDataDailyInfo = db.RP_Daily.Where(s => s.CalcuTime == para.StartTime && s.StaType == para.StationType).ToList(); //如果参考日期数据为0 则返回失败 if (pRefDataDailyInfo.Count == 0) { pReturnValue.ResultKey = (byte)EResult.Fail; pReturnValue.ResultValue = TipInfo.ForecastFaileFaileRefNoData; return(pReturnValue); } foreach (RP_Daily info in pRefDataDailyInfo) { DataDailyInfoViewModel pOutInfo = new DataDailyInfoViewModel(); DataDailyInfoViewModel pInInfo = new DataDailyInfoViewModel(); pInInfo.VehNum = (float)Math.Round((double)(info.InNum + info.InNum * pFloating), 0); pOutInfo.VehNum = (float)Math.Round((double)(info.OutNum + info.OutNum * pFloating), 0); pInInfo.VehType = info.VehType.ToString(); pOutInfo.VehType = info.VehType.ToString(); pOutInfo.CarChag = Math.Round((decimal)(info.ChagFee + info.ChagFee * (decimal)pFloating) / 10000, 2); pOutList.Add(pOutInfo); pInList.Add(pInInfo); } string path = Export(para, pOutList, pInList); 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> public IReportViewModel GetListByPra(QueryParameters para) { QueryDataDailyInfoViewModel pQueryDataList = new QueryDataDailyInfoViewModel(); using (DataSubmittedEntities db = new DataSubmittedEntities()) { //出口数据集合 List <DataDailyInfoViewModel> pOutlist = db.RP_Daily.Where(s => s.CalcuTime == para.StartTime && s.StaType == para.StationType).ToList().Select(s => new DataDailyInfoViewModel() { CarChag = s.ChagFee, VehNum = (float)s.OutNum,//出口 VehType = s.VehType.ToString() }).ToList(); //入口数据集合 List <DataDailyInfoViewModel> pInlist = db.RP_Daily.Where(s => s.CalcuTime == para.StartTime && s.StaType == para.StationType).ToList().Select(s => new DataDailyInfoViewModel() { CarChag = s.ChagFee, ExEn = "1", VehNum = (float)s.InNum,//入口 VehType = s.VehType.ToString() }).ToList(); //插入数据, if (db.RP_Daily.Count(s => s.CalcuTime == para.StartTime && s.StaType == para.StationType) < 4) { InsertNull(para.StartTime.Value, para.StationType.Value); } //list.AddRange(pOutlist); //list.AddRange(pInlist); //遍历出口和入口四种车型 List <DataDailyInfoViewModel> list = new List <DataDailyInfoViewModel>(); for (int i = 0; i < 4; i++) { string ptemp = i.ToString(); //0小型客车,1其他客车,2货车(不包含绿通),3绿通 //出口 DataDailyInfoViewModel outdailyinfo = new DataDailyInfoViewModel(); outdailyinfo.VehType = i.ToString(); outdailyinfo.ExEn = "0"; outdailyinfo.CarChag = Math.Round(pOutlist.Where(s => s.VehType == ptemp).Sum(s => s.CarChag.Value) / 10000, 2); outdailyinfo.VehNum = pOutlist.Where(s => s.VehType == ptemp).Sum(s => s.VehNum); //入口//入口无收费免征金额 DataDailyInfoViewModel indailyinfo = new DataDailyInfoViewModel(); indailyinfo.VehType = i.ToString(); indailyinfo.ExEn = "1"; indailyinfo.VehNum = pInlist.Where(s => s.VehType == ptemp).Sum(s => s.VehNum); //将出口和入口数据加到查询集合中 list.Add(outdailyinfo); list.Add(indailyinfo); } //按出口和车型升序排序, pQueryDataList.ReportData = list.OrderBy(s => s.ExEn).ThenBy(s => s.VehType).ToList(); foreach (DataDailyInfoViewModel info in pQueryDataList.ReportData) { if (info.VehType == "0") { info.VehType = SystemConst.SmallCar; } if (info.VehType == "1") { info.VehType = SystemConst.OtherCar; } if (info.VehType == "2") { info.VehType = SystemConst.Truk; } if (info.VehType == "3") { info.VehType = SystemConst.Green; } if (info.ExEn == "0") { info.ExEn = SystemConst.Out; } if (info.ExEn == "1") { info.ExEn = SystemConst.In; } } //判断当前统计站类型,数据是否完整 if (GetNoDataList(para).Count() > 0) { pQueryDataList.IsFull = 0;//不完整 } else { pQueryDataList.IsFull = 1;//完整 } } return(pQueryDataList); }