Exemple #1
0
        public HttpResponseMessage GetNewsList(GetNewsList arg)
        {
            BaseJson4Page <NewsPreviewItem> resultMsg = new BaseJson4Page <NewsPreviewItem> {
                Status = (int)JsonObjectStatus.Error, Message = "服务器未知错误。", Data = null
            };

            Logger(typeof(ZxNewsController), arg.TryToJson(), "彩种下面的文章列表-GetNewsList", () =>
            {
                if (!string.IsNullOrEmpty(arg.CategoryId))
                {
                    //Pagination page = new Pagination
                    //{
                    //    rows = arg.PageSize,
                    //    page = arg.PageIndex,
                    //    sidx = "CreateDate",
                    //    sord = "desc",
                    //    records = 0,
                    //    conditionJson = ""
                    //};

                    //分类Ids
                    string id = arg.CategoryId;

                    List <NewsPreviewItem> newsPreviewItem = new List <NewsPreviewItem>();
                    int records = 0;

                    lock (_lock)
                    {
                        Trace.WriteLine("========加锁时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff"));

                        Task task = Task.Factory.StartNew(() =>
                        {
                            //获取数据
                            List <NewsEntity> news = newsBll.FindList <NewsEntity>(t => t.CategoryId.Equals(id), "CreateDate", false, arg.PageSize, arg.PageIndex, out records).ToList();//.GetPageList(t => t.CategoryId.Equals(id), page).ToList();

                            Trace.WriteLine("========请求到数据:" + news.Count);

                            if (news.Count > 0)
                            {
                                newsPreviewItem = news.Select(n => new NewsPreviewItem
                                {
                                    AddTime = n.CreateDate.TryToDateTimeToString("yyyy-MM-dd"),
                                    NewsId  = n.NewsId,
                                    Title   = n.FullHead
                                }).ToList();
                            }
                            else
                            {
                                //如果为空,则默认查询太湖字谜和彩神通字谜下面子分类咨询
                                List <DataItemDetailEntity> list = dataItemCache.GetDataItemListById(arg.CategoryId);
                                if (list != null)
                                {
                                    List <string> itemDetailIds = list.Select(d => d.ItemDetailId).ToList();

                                    //获取数据
                                    List <NewsEntity> temp = newsBll.FindList <NewsEntity>(t => itemDetailIds.Contains(t.CategoryId), "CreateDate", false, arg.PageSize, arg.PageIndex, out records).ToList();//.GetPageList(t => t.CategoryId.Equals(id), page).ToList();

                                    //newsBll.GetPageList(t => itemDetailIds.Contains(t.CategoryId), page).ToList();

                                    newsPreviewItem = temp.Select(n => new NewsPreviewItem
                                    {
                                        AddTime = n.CreateDate.TryToDateTimeToString("yyyy-MM-dd"),
                                        NewsId  = n.NewsId,
                                        Title   = n.FullHead
                                    }).ToList();
                                }
                            }
                        });
                        task.Wait();
                    }
                    Trace.WriteLine("当前线程ID:" + Thread.CurrentThread.ManagedThreadId);
                    Trace.WriteLine("========离开时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff"));

                    PageData <NewsPreviewItem> pageData = new PageData <NewsPreviewItem>
                    {
                        TotalRow  = records,
                        TotalPage = Math.Ceiling(records * 1.0 / arg.PageSize).TryToInt32(),
                        PageIndex = arg.PageIndex,
                        Rows      = newsPreviewItem
                    };

                    resultMsg = new BaseJson4Page <NewsPreviewItem>
                    {
                        Status  = (int)JsonObjectStatus.Success,
                        Data    = pageData,
                        Message = JsonObjectStatus.Success.GetEnumText(),
                        BackUrl = null
                    };
                }
                else
                {
                    resultMsg = new BaseJson4Page <NewsPreviewItem>
                    {
                        Status  = (int)JsonObjectStatus.Fail,
                        Data    = null,
                        Message = JsonObjectStatus.Fail.GetEnumText() + ",请求参数CategoryId为空。",
                        BackUrl = null
                    };
                }
            }, e =>
            {
                resultMsg = new BaseJson4Page <NewsPreviewItem>
                {
                    Status  = (int)JsonObjectStatus.Exception,
                    Data    = null,
                    Message = JsonObjectStatus.Exception.GetEnumText() + ",异常信息:" + e.Message,
                    BackUrl = null
                };
            });
            return(resultMsg.TryToJson().ToHttpResponseMessage());
        }