/// <summary>
        /// 根据查询条件获取数据列表
        /// </summary>
        /// <param name="query">查询条件</param>
        /// <returns></returns>
        public Result_List_Pager <Result_TransactionRecord> GetTransactionRecordList(TransactionRecordQuery query)
        {
            Result_List_Pager <Result_TransactionRecord> res = new Result_List_Pager <Result_TransactionRecord>()
            {
                List     = new List <Result_TransactionRecord>(),
                PageInfo = new PageInfo(),
                Msg      = new Result_Msg()
                {
                    IsSuccess = true
                }
            };

            try
            {
                if (query.StartDate > query.EndDate)
                {
                    res.Msg.IsSuccess = false;
                    res.Msg.Message   = "开始时间不能大于结束时间";
                }
                else
                {
                    //开始月份与结束月份相同或开始月份小于结束月份时,查询开始月份第一天至结束月份最后一天内的数据

                    query.StartDate = query.StartDate.Date;
                    query.EndDate   = query.EndDate.Date.AddMonths(1);
                    int total = 0;
                    List <TransactionRecord> list;
                    if (query.CurveType == 0)
                    {
                        total = (from p in context.TransactionRecord where p.YearMonth >= query.StartDate && p.YearMonth < query.EndDate select p).Count();
                        list  = (from p in context.TransactionRecord where p.YearMonth >= query.StartDate && p.YearMonth < query.EndDate select p).OrderBy(p => p.YearMonth).Skip((query.PageNo - 1) * query.PageSize).Take(query.PageSize).ToList();
                    }
                    else
                    {
                        total = (from p in context.TransactionRecord where p.YearMonth >= query.StartDate && p.YearMonth < query.EndDate && p.CurveType == query.CurveType select p).Count();
                        list  = (from p in context.TransactionRecord where p.YearMonth >= query.StartDate && p.YearMonth < query.EndDate && p.CurveType == query.CurveType select p).OrderBy(p => p.YearMonth).Skip((query.PageNo - 1) * query.PageSize).Take(query.PageSize).ToList();
                    }
                    res.List = list.Select(x => new Result_TransactionRecord()
                    {
                        Id               = x.Id,
                        XName_CN         = x.XName_CN,
                        XName_Eng        = x.XName_Eng,
                        Y_CompleteAmount = x.Y_CompleteAmount,
                        Y_CompleteNumber = x.Y_CompleteNumber,
                        Y_OrderAmount    = x.Y_OrderAmount,
                        Y_OrderQuantity  = x.Y_OrderQuantity,
                        CurveType        = HashSet_Common.hashCurveType.Where(y => y.Key == x.CurveType).FirstOrDefault().Value,
                        YearMonth        = x.YearMonth.Year.ToString() + "-" + x.YearMonth.Month.ToString(),
                        IsTrue           = x.IsTrue
                    }).ToList();

                    res.PageInfo.CurrentPage = query.PageNo;
                    res.PageInfo.PageSize    = query.PageSize;
                    res.PageInfo.Total       = total;
                    res.PageInfo.PageCount   = Convert.ToInt32(Math.Ceiling((double)total / (double)query.PageSize));


                    res.Msg.IsSuccess = true;
                }
            }
            catch (Exception ex)
            {
                res.Msg.IsSuccess = false;
                res.Msg.Message   = "查询失败,失败原因:" + ex.Message;
            }
            return(res);
        }
Пример #2
0
        public string GetTransactionRecordList(TransactionRecordQuery query)
        {
            Result_List_Pager <Result_TransactionRecord> res = bannerIndexService.GetTransactionRecordList(query);

            return(Newtonsoft.Json.JsonConvert.SerializeObject(res));
        }