public JsonResult ForecastSearch(ForecastSearchDTO req) { Response res = new Response(); res.Successed = false; if (ModelState.IsValid) { try { if (req.BeginDate == null || req.BeginDate < DateTime.Today) { throw new Exception("起始日期错误,最小起始日期不能小于当前日期!"); } if (req.BeginDate > req.EndDate) { throw new Exception("无效日期条件,起始日期不能大于截止日期!"); } if (req.EndDate > DateTime.Today.AddDays(30)) { throw new Exception("最大查询截止日期不能超过当前日期一个月!"); } var operatorUser = OperatorProvider.Provider.GetCurrent(); req.Restaurant = operatorUser.DepartmentId.ToInt(); var info = _orderService.ForecastSearch(req); res.Data = info; res.Successed = true; } catch (Exception ex) { res.Message = ex.Message; } } else { res.Message = string.Join(",", ModelState .SelectMany(ms => ms.Value.Errors) .Select(e => e.ErrorMessage)); } return(Json(res, JsonRequestBehavior.AllowGet)); }
public ForecastInfoDTO ForecastSearch(ForecastSearchDTO req) { int days = (req.EndDate - req.BeginDate).Days + 1; ForecastInfoDTO infoObj = new ForecastInfoDTO(); //分市 var marketList = _marketRep.GetList(req.Restaurant); int marketCount = marketList.Count; infoObj.MarketList = marketList; List <ForecastDateDTO> dateList = new List <ForecastDateDTO>(); for (int i = 0; i < days; i++) { ForecastDateDTO dateDTO = new ForecastDateDTO(); dateDTO.DayOfDate = req.BeginDate.AddDays(i); dateDTO.DayOfWeekName = System.Globalization.CultureInfo.CurrentCulture .DateTimeFormat.GetDayName(req.BeginDate.AddDays(i).DayOfWeek); dateDTO.TitleDate = req.BeginDate.AddDays(i).ToString("MM-dd"); dateList.Add(dateDTO); } infoObj.DateList = dateList; List <ForecastTableDTO> tableList = new List <ForecastTableDTO>(); //台号 var tables = _tableRep.GetTables(new int[] { req.Restaurant }, null, 0); //台号预定明细 var reserveInfoList = _orderRep.GetForecastList(req); foreach (var item in tables) { ForecastTableDTO tableDTO = new ForecastTableDTO(); tableDTO.TableId = item.Id; tableDTO.TableName = item.Name; tableDTO.RestaurantId = item.R_Restaurant_Id; var contentList = reserveInfoList.Where(x => x.TableId == item.Id).ToList(); List <ForecastReserveInfoDTO> records = new List <ForecastReserveInfoDTO>(); foreach (var date in dateList) { var filteByDateList = contentList.Where(x => x.BookingDate == date.DayOfDate).ToList(); foreach (var market in marketList) { ForecastReserveInfoDTO info = new ForecastReserveInfoDTO(); if (filteByDateList != null && filteByDateList.Count > 0) { var obj = filteByDateList.Where(x => x.BookingDate == date.DayOfDate && x.MarketId == market.Id && x.TableId == item.Id).FirstOrDefault(); if (obj != null) { info = obj; } } records.Add(info); } } tableDTO.BookingList = records; tableList.Add(tableDTO); } infoObj.TableList = tableList; return(infoObj); }