/// <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); }
/// <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); }