Example #1
0
        /// <summary>
        /// 根据文章ID获得该文章的热门评论
        /// </summary>
        /// <param name="sourceId"></param>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <returns></returns>
        public static string GetRecommendComments(string sourceId, string page, string limit)
        {
            int rowcount = 0;
            List <CommentInfo> cmtLst = DataAccess_News.RecommendComments_SelectPaged(sourceId, page, limit,
                                                                                      out rowcount);
            List <string> cmtIds = new List <string>();

            foreach (var cmt in cmtLst)
            {
                cmtIds.Add(cmt.cmt_uid);
                if (!string.IsNullOrEmpty(cmt.cmt_parentIds))
                {
                    cmtIds.AddRange(cmt.cmt_parentIds.Split(','));
                }
            }
            cmtIds = cmtIds.Distinct().ToList();

            var jsonSerializer = new JavaScriptSerializer();
            var json           = "";

            // 设置没有登录的用户为匿名用户
            List <CommentInfo> comments = DataAccess_News.Comments_Selectbycmt_uidStrs(sourceId, cmtIds.ToArray());

            foreach (CommentInfo comment in comments)
            {
                comment.cmt_createUser  = (comment.cmt_createUserID == -1) ? "匿名用户" : comment.cmt_createUser;
                comment.cmt_content     = HtmlHelper.DecodeHTMLString(comment.cmt_content, false).Replace("<br/>", "\n");
                comment.cmt_checkRemark = Util.UserFace_Get(comment.cmt_createUserID);  //存放用户头像
                comment.cmt_checkTime   = Util.Get_Gentle_Time(comment.cmt_createTime); // 存放友好时间
            }
            json = jsonSerializer.Serialize(comments);


            json = "{\"list\":" + json + ",\"ids\":" + jsonSerializer.Serialize(cmtLst) + ",\"page\":" + page + ",\"pageSize\":" + limit + ",\"total\":" + rowcount + ",\"sourceId\":\"" + sourceId + "\"}";

            //CacheHelper.Cache_Store(Constants.CN_RecommendComments + sourceId + page + limit, json, TimeSpan.FromMinutes(10));

            return(json);
        }
Example #2
0
        /// <summary>
        /// 获得某文章的所有评论(最新评论在前面)
        /// </summary>
        /// <param name="sourceId">w文章ID</param>
        /// <param name="page">第几页评论</param>
        /// <param name="limit">每页最大评论数</param>
        /// <returns></returns>
        public Stream Comments_SelectPaged(string sourceId, string page, string limit)
        {
            WebOperationContext context = WebOperationContext.Current;

            context.OutgoingResponse.ContentType = "application/json; charset=utf-8";

            int rowcount = 0;
            List <CommentInfo> comments = DataAccess_News.Comments_SelectPaged(sourceId, page, limit, out rowcount);

            // 获取评论cmt_uid集合
            List <string> cmt_Uids = new List <string>();

            comments.ForEach(m =>
            {
                cmt_Uids.Add(m.cmt_uid);
                if (!string.IsNullOrEmpty(m.cmt_parentIds))
                {
                    cmt_Uids.AddRange(m.cmt_parentIds.Split(','));
                }
            });
            cmt_Uids = cmt_Uids.Distinct().ToList();

            var jsonSerialiser             = new JavaScriptSerializer();
            var json                       = "";
            List <CommentInfo> commentList = DataAccess_News.Comments_Selectbycmt_uidStrs(sourceId, cmt_Uids.ToArray());

            foreach (var comment in commentList)
            {
                comment.cmt_createUser  = (comment.cmt_createUserID == -1) ? "匿名用户" : comment.cmt_createUser;
                comment.cmt_content     = HtmlHelper.DecodeHTMLString(comment.cmt_content, false).Replace("<br/>", "\n"); // 解析编码后的危险字符
                comment.cmt_checkRemark = Util.UserFace_Get(comment.cmt_createUserID);                                    // 存放用户头像
                comment.cmt_checkTime   = Util.Get_Gentle_Time(comment.cmt_createTime);                                   // 存放友好时间
            }
            json = jsonSerialiser.Serialize(commentList);
            json = "{\"list\":" + json + ",\"ids\":" + jsonSerialiser.Serialize(comments) + ",\"page\":" + page + ",\"pageSize\":" + limit + ",\"total\":" + rowcount + ",\"sourceId\":\"" + sourceId + "\"}";

            return(new MemoryStream(Encoding.UTF8.GetBytes(json)));
        }
Example #3
0
        /// <summary>
        /// 获得某文章的所有评论(最新接口)
        /// </summary>
        /// <param name="sourceId">文章Id</param>
        /// <param name="page">评论所在的页码</param>
        /// <param name="limit">页最大评论数</param>
        /// <returns></returns>
        public Stream Comments_SelectPaged2(string sourceId, string page, string limit)
        {
            WebOperationContext context = WebOperationContext.Current;

            context.OutgoingResponse.ContentType = "application/json; charset=utf-8";

            // 设置评论搜索条件
            CommentsSearchInfo search = new CommentsSearchInfo();

            search.cmt_sourceId = sourceId.ToSafetyStr();
            search.cmt_status   = 1;
            search.page         = int.Parse(page);
            search.pagesize     = int.Parse(limit);

            // 获取评论
            int rowcount = 0;
            List <CommentInfo> comments = DataAccess_News.Comments_SelectPaged(search.columns, search.ToWhereString(), search.DefOrder,
                                                                               search.page, search.pagesize, true, out rowcount);


            // 评论uid集合
            List <string> cmt_uids = new List <string>();

            foreach (var cmt in comments)
            {
                cmt_uids.Add(cmt.cmt_uid);
                if (!string.IsNullOrEmpty(cmt.cmt_parentIds))
                {
                    cmt_uids.AddRange(cmt.cmt_parentIds.Split(','));
                }
            }
            cmt_uids = cmt_uids.Distinct().ToList();

            var jsonSerializer = new JavaScriptSerializer();
            var json           = "";

            // 获取所有评论uid的评论
            List <CommentInfo> commentList = null;

            commentList = DataAccess_News.Comments_Selectbycmt_uidStrs(sourceId, cmt_uids.ToArray());
            foreach (CommentInfo comment in commentList)
            {
                comment.cmt_createUser  = (comment.cmt_createUserID == -1) ? "匿名用户" : comment.cmt_createUser;
                comment.cmt_content     = HtmlHelper.DecodeHTMLString(comment.cmt_content, false).Replace("<br/>", "\n"); // 解析编码后的危险字符
                comment.cmt_checkRemark = Util.UserFace_Get(comment.cmt_createUserID);                                    //存放用户头像
            }
            json = jsonSerializer.Serialize(comments);

            /*
             * 组装成网易盖楼形式
             */
            int idCount = comments.Count;   // 楼层数
            List <List <CommentInfo> > newPosts = new List <List <CommentInfo> >();

            for (int index = 0; index < idCount; index++)
            {
                string        cmt_parentIds = comments[index].cmt_parentIds; // 获取所有父楼层Id
                List <string> idList        = new List <string>();           // 所有楼层id列表
                if (!string.IsNullOrEmpty(cmt_parentIds))
                {
                    idList.AddRange(cmt_parentIds.Split(','));
                }
                // 加上主楼
                idList.Add(comments[index].cmt_uid);

                Dictionary <string, CommentInfo> cmt = commentList.ToDictionary(a => a.cmt_uid);
                List <CommentInfo> result            = new List <CommentInfo>();
                CommentInfo        info = null;
                for (int idIndex = 0; idIndex < idList.Count; idIndex++)
                {
                    if (!cmt.TryGetValue(idList[idIndex], out info))
                    {
                        continue;
                    }
                    result.Add(info);
                }
                newPosts.Add(result);
            }
            json = "{\"list\":" + jsonSerializer.Serialize(newPosts) + ",\"page\":" + page + ",\"pageSize\":" + limit + ",\"total\":" + rowcount + ",\"sourceId\":\"" + sourceId + "\"}";

            return(new MemoryStream(Encoding.UTF8.GetBytes(json)));
        }
Example #4
0
        /// <summary>
        /// 根据文章ID获得该文章的热门评论(最新接口)
        /// </summary>
        /// <param name="sourceId"></param>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <returns></returns>
        public static string GetRecommendComments2(string sourceId, string page, string limit)
        {
            int rowcount = 0;
            List <CommentInfo> cmtLst = DataAccess_News.RecommendComments_SelectPaged(sourceId, page, limit,
                                                                                      out rowcount);

            List <string> cmtIds = new List <string>();

            foreach (var cmt in cmtLst)
            {
                cmtIds.Add(cmt.cmt_uid);
                if (!string.IsNullOrEmpty(cmt.cmt_parentIds))
                {
                    cmtIds.AddRange(cmt.cmt_parentIds.Split(','));
                }
            }
            cmtIds = cmtIds.Distinct().ToList();

            var jsonSerialiser = new JavaScriptSerializer();
            var json           = "";

            // 设置没有登录的用户为匿名用户
            List <CommentInfo> comments = DataAccess_News.Comments_Selectbycmt_uidStrs(sourceId, cmtIds.ToArray());

            foreach (CommentInfo comment in comments)
            {
                comment.cmt_createUser  = (comment.cmt_createUserID == -1) ? "匿名用户" : comment.cmt_createUser;
                comment.cmt_content     = HtmlHelper.DecodeHTMLString(comment.cmt_content, false).Replace("<br/>", "\n");
                comment.cmt_checkRemark = Util.UserFace_Get(comment.cmt_createUserID);  //存放用户头像
                comment.cmt_checkTime   = Util.Get_Gentle_Time(comment.cmt_createTime); // 存放友好时间
            }

            /*
             * 组装成网易盖楼形式
             */
            int idCount = cmtLst.Count; // 楼层数
            List <List <CommentInfo> > newPosts = new List <List <CommentInfo> >();

            for (int index = 0; (comments != null) && index < idCount; index++)
            {
                string        cmt_parentIds = cmtLst[index].cmt_parentIds; // 获得所有的父楼层Id
                List <string> idList        = new List <string>();
                if (!string.IsNullOrEmpty(cmt_parentIds))
                {
                    idList.AddRange(cmt_parentIds.Split(','));
                }

                idList.Add(cmtLst[index].cmt_uid); // 加上主楼,这样最后一楼为主楼

                Dictionary <string, CommentInfo> cmt = comments.ToDictionary(a => a.cmt_uid);
                List <CommentInfo> result            = new List <CommentInfo>();
                CommentInfo        comment           = null;
                for (int idIndex = 0; idIndex < idList.Count; idIndex++)
                {
                    if (!cmt.TryGetValue(idList[idIndex], out comment))
                    {
                        continue;
                    }

                    result.Add(comment);
                }

                newPosts.Add(result);
            }

            json = "{\"list\":" + jsonSerialiser.Serialize(newPosts) + ",\"page\":" + page + ",\"pageSize\":" + limit + ",\"total\":" + rowcount + ",\"sourceId\":\"" + sourceId + "\"}";

            //CacheHelper.Cache_Store(Constants.CN_RecommendComments_New + sourceId + page + limit, json, TimeSpan.FromMinutes(10));

            return(json);
        }