/// <summary> /// 分页获取排行数据 /// </summary> /// <param name="areaCode">地区代码</param> /// <param name="categoryId">类别Id</param> /// <param name="sortBy">排序字段</param> /// <param name="pageSize">每页记录数</param> /// <param name="pageIndex">页码</param> /// <returns></returns> public PagingDataSet <TopicEntity> Gets(string areaCode, long?categoryId, SortBy_Topic sortBy, int pageSize, int pageIndex) { return(GetPagingEntities(pageSize, pageIndex, CachingExpirationType.UsualObjectCollection, () => { StringBuilder cacheKey = new StringBuilder(); cacheKey.AppendFormat("PagingTopicRanks::areaCode-{0}:categoryId-{1}:sortBy-{2}", areaCode, categoryId, sortBy); return cacheKey.ToString(); }, () => { return Getsqls(areaCode, categoryId, null, sortBy); })); }
/// <summary> /// 标签显示专题列表 /// </summary> public ActionResult ListByTag(string tagName, SortBy_Topic sortBy = SortBy_Topic.DateCreated_Desc, int pageIndex = 1) { tagName = WebUtility.UrlDecode(tagName); var tag = new TagService(TenantTypeIds.Instance().Topic()).Get(tagName); if (tag == null) { return(HttpNotFound()); } PagingDataSet <TopicEntity> groups = topicService.GetsByTag(tagName, sortBy, pageIndex: pageIndex); pageResourceManager.InsertTitlePart(tagName); ViewData["tag"] = tag; ViewData["sortBy"] = sortBy; return(View(groups)); }
/// <summary> /// 根据标签名获取专题分页集合 /// </summary> /// <param name="tagName">标签名</param></param> /// <param name="sortBy">排序依据</param> /// <param name="pageSize">每页记录数</param> /// <param name="pageIndex">页码</param> /// <returns>分页列表</returns> public PagingDataSet <TopicEntity> GetsByTag(string tagName, SortBy_Topic sortBy, int pageSize, int pageIndex) { return(GetPagingEntities(pageSize, pageIndex, CachingExpirationType.UsualObjectCollection, () => { StringBuilder cacheKey = new StringBuilder(); cacheKey.AppendFormat("TopicsByTag::TagName-{0}:SortBy-{1}", tagName, sortBy); return cacheKey.ToString(); }, () => { Sql sql = Sql.Builder; sql.Select("spt_Topics.*").From("spt_Topics"); sql.InnerJoin("tn_ItemsInTags").On("TopicId = tn_ItemsInTags.ItemId") .Where("tn_ItemsInTags.TagName = @0 and tn_ItemsInTags.TenantTypeId = @1", tagName, TenantTypeIds.Instance().Topic()) .Where("spt_Topics.IsPublic = 1"); switch (sortBy) { case SortBy_Topic.DateCreated_Desc: sql.OrderBy("DateCreated desc"); break; case SortBy_Topic.GrowthValue_Desc: sql.OrderBy("GrowthValue desc"); break; case SortBy_Topic.MemberCount_Desc: sql.OrderBy("MemberCount desc"); break; default: sql.OrderBy("GrowthValue desc"); break; } return sql; })); }
/// <summary> /// 分页获取排行数据 /// </summary> /// <param name="areaCode">地区代码</param> /// <param name="categoryId">类别Id</param> /// <param name="sortBy">排序字段</param> /// <param name="pageSize">每页记录数</param> /// <param name="pageIndex">页码</param> /// <returns></returns> public PagingDataSet<TopicEntity> Gets(string areaCode, long? categoryId, SortBy_Topic sortBy, int pageSize = 20, int pageIndex = 1) { //无需维护缓存即时性 return topicRepository.Gets(areaCode, categoryId, sortBy, pageSize, pageIndex); }
/// <summary> /// 获取匹配的前N个排行专题 /// </summary> /// <param name="topNumber">前多少个</param> /// <param name="areaCode">地区代码</param> /// <param name="categoryId">类别Id</param> /// <param name="sortBy">排序字段</param> /// <returns></returns> public IEnumerable<TopicEntity> GetMatchTops(int topNumber, string keyword, string areaCode, long? categoryId, SortBy_Topic sortBy) { return topicRepository.GetMatchTops(topNumber, keyword, areaCode, categoryId, sortBy); }
/// <summary> /// 获取前N个排行专题 /// </summary> /// <param name="topNumber">前多少个</param> /// <param name="areaCode">地区代码</param> /// <param name="categoryId">类别Id</param> /// <param name="sortBy">排序字段</param> /// <returns></returns> public IEnumerable<TopicEntity> GetTops(int topNumber, string areaCode, long? categoryId, SortBy_Topic sortBy) { //设计要点 //1、查询areaCode时需要包含后代地区; //2、查询categoryId时需要包含后代类别; //3、无需维护缓存即时性 return topicRepository.GetTops(topNumber, areaCode, categoryId, sortBy); }
/// <summary> /// 根据标签名获取专题分页集合 /// </summary> /// <param name="tagName">标签名</param></param> /// <param name="sortBy">排序依据</param> /// <param name="pageSize">每页记录数</param> /// <param name="pageIndex">页码</param> /// <returns>分页列表</returns> public PagingDataSet <TopicEntity> GetsByTag(string tagName, SortBy_Topic sortBy, int pageSize = 20, int pageIndex = 1) { //无需维护缓存即时性 return(groupRepository.GetsByTag(tagName, sortBy, pageSize, pageIndex)); }
/// <summary> /// 发现专题 /// </summary> /// <param name="siteUrls"></param> /// <param name="nameKeyword"></param> /// <param name="areaCode"></param> /// <param name="categoryId"></param> /// <param name="sortBy"></param> /// <returns></returns> public static string FindTopic(this SiteUrls siteUrls, string areaCode = null, long? categoryId = null, SortBy_Topic? sortBy = null, string nameKeyword = null) { RouteValueDictionary routeValueDictionary = new RouteValueDictionary(); if (!string.IsNullOrEmpty(areaCode)) routeValueDictionary.Add("areaCode", areaCode); if (categoryId.HasValue && categoryId.Value > 0) routeValueDictionary.Add("categoryId", categoryId); if (sortBy.HasValue) routeValueDictionary.Add("sortBy", sortBy); if (!string.IsNullOrEmpty(nameKeyword)) routeValueDictionary.Add("nameKeyword", WebUtility.UrlEncode(nameKeyword)); return CachedUrlHelper.Action("FindTopic", "ChannelTopic", TopicAreaName, routeValueDictionary); }
/// <summary> /// 标签显示专题列表 /// </summary> public ActionResult ListByTag(string tagName, SortBy_Topic sortBy = SortBy_Topic.DateCreated_Desc, int pageIndex = 1) { tagName = WebUtility.UrlDecode(tagName); var tag = new TagService(TenantTypeIds.Instance().Topic()).Get(tagName); if (tag == null) { return HttpNotFound(); } PagingDataSet<TopicEntity> topics = topicService.GetsByTag(tagName, sortBy, pageIndex: pageIndex); pageResourceManager.InsertTitlePart(tagName); ViewData["tag"] = tag; ViewData["sortBy"] = sortBy; return View(topics); }
/// <summary> /// 发现专题 /// </summary> /// <returns></returns> public ActionResult FindTopic(string nameKeyword, string areaCode, long? categoryId, SortBy_Topic? sortBy, int pageIndex = 1) { nameKeyword = WebUtility.UrlDecode(nameKeyword); string pageTitle = string.Empty; IEnumerable<Category> childCategories = null; if (categoryId.HasValue && categoryId.Value > 0) { var category = categoryService.Get(categoryId.Value); if (category != null) { if (category.ChildCount > 0) { childCategories = category.Children; } else//若是叶子节点,则取同辈分类 { if (category.Parent != null) childCategories = category.Parent.Children; } List<Category> allParentCategories = new List<Category>(); //递归获取所有父级类别,若不是叶子节点,则包含其自身 RecursiveGetAllParentCategories(category.ChildCount > 0 ? category : category.Parent, ref allParentCategories); ViewData["allParentCategories"] = allParentCategories; ViewData["currentCategory"] = category; pageTitle = category.CategoryName; } } if (childCategories == null) childCategories = categoryService.GetRootCategories(TenantTypeIds.Instance().Topic()); ViewData["childCategories"] = childCategories; AreaSettings areaSettings = DIContainer.Resolve<ISettingsManager<AreaSettings>>().Get(); IEnumerable<Area> childArea = null; if (!string.IsNullOrEmpty(areaCode)) { var area = areaService.Get(areaCode); if (area != null) { if (area.ChildCount > 0) { childArea = area.Children; } else { if (!string.IsNullOrEmpty(area.ParentCode)) { var parentArea = areaService.Get(area.ParentCode); if (parentArea != null) childArea = parentArea.Children; } } } List<Area> allParentAreas = new List<Area>(); RecursiveGetAllParentArea(area.ChildCount > 0 ? area : areaService.Get(area.ParentCode), areaSettings.RootAreaCode, ref allParentAreas); ViewData["allParentAreas"] = allParentAreas; ViewData["currentArea"] = area; if (!string.IsNullOrEmpty(pageTitle)) pageTitle += ","; pageTitle += area.Name; } if (childArea == null) { Area rootArea = areaService.Get(areaSettings.RootAreaCode); if (rootArea != null) childArea = rootArea.Children; else childArea = areaService.GetRoots(); } ViewData["childArea"] = childArea; if (!string.IsNullOrEmpty(nameKeyword)) { if (!string.IsNullOrEmpty(pageTitle)) pageTitle += ","; pageTitle += nameKeyword; } if (string.IsNullOrEmpty(pageTitle)) pageTitle = "发现专题"; pageResourceManager.InsertTitlePart(pageTitle); PagingDataSet<TopicEntity> topics = topicService.Gets(areaCode, categoryId, sortBy ?? SortBy_Topic.DateCreated_Desc, pageIndex: pageIndex); if (Request.IsAjaxRequest()) { return PartialView("_List", topics); } return View(topics); }
/// <summary> /// 专题地区导航内容块 /// </summary> /// <returns></returns> public ActionResult _AreaTopics(int topNumber, string areaCode, long? categoryId, SortBy_Topic sortBy = SortBy_Topic.DateCreated_Desc) { IUser iUser = (User)UserContext.CurrentUser; User user = null; if (iUser == null) { user = new User(); } else { user = userService.GetFullUser(iUser.UserId); } if (string.IsNullOrEmpty(areaCode) && Request.Cookies["AreaTopicCookie" + user.UserId] != null && !string.IsNullOrEmpty(Request.Cookies["AreaTopicCookie" + user.UserId].Value)) areaCode = Request.Cookies["AreaTopicCookie" + user.UserId].Value; if (string.IsNullOrEmpty(areaCode)) { string ip = WebUtility.GetIP(); areaCode = IPSeeker.Instance().GetAreaCode(ip); if (string.IsNullOrEmpty(areaCode) && user.Profile != null) { areaCode = user.Profile.NowAreaCode; } } ViewData["areaCode"] = areaCode; if (!string.IsNullOrEmpty(areaCode)) { Area area = areaService.Get(areaCode); if (!string.IsNullOrEmpty(area.ParentCode)) { Area parentArea = areaService.Get(area.ParentCode); ViewData["parentCode"] = parentArea.AreaCode; } } IEnumerable<TopicEntity> topics = topicService.GetTops(topNumber, areaCode, categoryId, sortBy); HttpCookie cookie = new HttpCookie("AreaTopicCookie" + user.UserId, areaCode); Response.Cookies.Add(cookie); return PartialView(topics); }
public ActionResult _TopTopics(int topNumber, string areaCode, long? categoryId, SortBy_Topic? sortBy, string viewName = "_TopTopics_List") { var topics = topicService.GetTops(topNumber, areaCode, categoryId, sortBy ?? SortBy_Topic.DateCreated_Desc); ViewData["SortBy"] = sortBy; return PartialView(viewName, topics); }
/// <summary> /// Gets和GetTops的sql语句 /// </summary> private Sql Getsqls(string areaCode, long?categoryId, string keyword, SortBy_Topic sortBy) { Sql sql = Sql.Builder; var whereSql = Sql.Builder; var orderSql = Sql.Builder; sql.Select("spt_Topics.*").From("spt_Topics"); if (categoryId != null && categoryId.Value > 0) { CategoryService categoryService = new CategoryService(); IEnumerable <Category> categories = categoryService.GetDescendants(categoryId.Value); List <long> categoryIds = new List <long> { categoryId.Value }; if (categories != null && categories.Count() > 0) { categoryIds.AddRange(categories.Select(n => n.CategoryId)); } sql.InnerJoin("tn_ItemsInCategories") .On("spt_Topics.TopicId = tn_ItemsInCategories.ItemId"); whereSql.Where("tn_ItemsInCategories.CategoryId in(@categoryIds)", new { categoryIds = categoryIds }); } if (!string.IsNullOrEmpty(areaCode)) { if (areaCode.Equals("A1560000", StringComparison.CurrentCultureIgnoreCase)) { //已修改 whereSql.Where("AreaCode like '1%' or AreaCode like '2%' or AreaCode like '3%' or AreaCode like '4%' or AreaCode like '5%' or AreaCode like '6%' or AreaCode like '7%' or AreaCode like '8%' or AreaCode like '9%' "); } else { areaCode = areaCode.TrimEnd('0'); if (areaCode.Length % 2 == 1) { areaCode = areaCode + "0"; } whereSql.Where("AreaCode like @0 ", StringUtility.StripSQLInjection(areaCode) + "%"); } } if (!string.IsNullOrEmpty(keyword)) { whereSql.Where("TopicName like @0", StringUtility.StripSQLInjection(keyword) + "%"); } whereSql.Where("spt_Topics.IsPublic = 1"); //已修改 switch (this.PubliclyAuditStatus) { case PubliclyAuditStatus.Again: case PubliclyAuditStatus.Fail: case PubliclyAuditStatus.Pending: case PubliclyAuditStatus.Success: whereSql.Where("AuditStatus=@0", this.PubliclyAuditStatus); break; case PubliclyAuditStatus.Again_GreaterThanOrEqual: case PubliclyAuditStatus.Pending_GreaterThanOrEqual: whereSql.Where("AuditStatus>@0", this.PubliclyAuditStatus); break; default: break; } CountService countService = new CountService(TenantTypeIds.Instance().Topic()); string countTableName = countService.GetTableName_Counts(); switch (sortBy) { case SortBy_Topic.DateCreated_Desc: orderSql.OrderBy("DateCreated desc"); break; case SortBy_Topic.GrowthValue_Desc: orderSql.OrderBy("GrowthValue desc"); break; case SortBy_Topic.MemberCount_Desc: orderSql.OrderBy("MemberCount desc"); break; case SortBy_Topic.HitTimes: sql.LeftJoin(string.Format("(select * from {0} WHERE ({0}.CountType = '{1}')) c", countTableName, CountTypes.Instance().HitTimes())) .On("TopicId = c.ObjectId"); orderSql.OrderBy("c.StatisticsCount desc"); break; case SortBy_Topic.StageHitTimes: StageCountTypeManager stageCountTypeManager = StageCountTypeManager.Instance(TenantTypeIds.Instance().Topic()); int stageCountDays = stageCountTypeManager.GetMaxDayCount(CountTypes.Instance().HitTimes()); string stageCountType = stageCountTypeManager.GetStageCountType(CountTypes.Instance().HitTimes(), stageCountDays); sql.LeftJoin(string.Format("(select * from {0} WHERE ({0}.CountType = '{1}')) c", countTableName, stageCountType)) .On("TopicId = c.ObjectId"); orderSql.OrderBy("c.StatisticsCount desc"); break; default: orderSql.OrderBy("DateCreated desc"); break; } sql.Append(whereSql).Append(orderSql); return(sql); }
/// <summary> /// 根据标签名获取专题分页集合 /// </summary> /// <param name="tagName">标签名</param></param> /// <param name="sortBy">排序依据</param> /// <param name="pageSize">每页记录数</param> /// <param name="pageIndex">页码</param> /// <returns>分页列表</returns> public PagingDataSet<TopicEntity> GetsByTag(string tagName, SortBy_Topic sortBy, int pageSize = 20, int pageIndex = 1) { //无需维护缓存即时性 return topicRepository.GetsByTag(tagName, sortBy, pageSize, pageIndex); }
/// <summary> /// 获取前N个排行专题 /// </summary> /// <param name="topNumber">前多少个</param> /// <param name="areaCode">地区代码</param> /// <param name="categoryId">类别Id</param> /// <param name="sortBy">排序字段</param> /// <returns></returns> public IEnumerable <TopicEntity> GetTops(int topNumber, string areaCode, long?categoryId, SortBy_Topic sortBy) { //设计要点 //1、查询areaCode时需要包含后代地区; //2、查询categoryId时需要包含后代类别; //3、无需维护缓存即时性 return(groupRepository.GetTops(topNumber, areaCode, categoryId, sortBy)); }
/// <summary> /// 专题地区导航内容块 /// </summary> /// <returns></returns> public static string _AreaTopics(this SiteUrls siteUrls, long topNumber = 5, string areaCode = null, long? categoryId = null, SortBy_Topic? sortBy = null) { RouteValueDictionary routeValueDictionary = new RouteValueDictionary(); if (!string.IsNullOrEmpty(areaCode)) routeValueDictionary.Add("areaCode", areaCode); if (categoryId.HasValue && categoryId.Value > 0) routeValueDictionary.Add("categoryId", categoryId); if (sortBy.HasValue) routeValueDictionary.Add("sortBy", sortBy); if (topNumber != 0) { routeValueDictionary.Add("topNumber", topNumber); } return CachedUrlHelper.Action("_AreaTopics", "ChannelTopic", TopicAreaName, routeValueDictionary); }
/// <summary> /// 获取匹配的前N个排行专题 /// </summary> /// <param name="topNumber">前多少个</param> /// <param name="areaCode">地区代码</param> /// <param name="categoryId">类别Id</param> /// <param name="sortBy">排序字段</param> /// <returns></returns> public IEnumerable <TopicEntity> GetMatchTops(int topNumber, string keyword, string areaCode, long?categoryId, SortBy_Topic sortBy) { return(groupRepository.GetMatchTops(topNumber, keyword, areaCode, categoryId, sortBy)); }
/// <summary> /// 标签下的专题 /// </summary> /// <param name="siteUrls"></param> /// <param name="tagName"></param> /// <param name="sortBy"></param> /// <returns></returns> public static string ListByTagOfTopic(this SiteUrls siteUrls, string tagName, SortBy_Topic? sortBy = null) { RouteValueDictionary routeValueDictionary = new RouteValueDictionary(); if (sortBy.HasValue) { routeValueDictionary.Add("sortBy", sortBy); } routeValueDictionary.Add("tagName", tagName); return CachedUrlHelper.Action("ListByTag", "ChannelTopic", TopicAreaName, routeValueDictionary); }
/// <summary> /// 分页获取排行数据 /// </summary> /// <param name="areaCode">地区代码</param> /// <param name="categoryId">类别Id</param> /// <param name="sortBy">排序字段</param> /// <param name="pageSize">每页记录数</param> /// <param name="pageIndex">页码</param> /// <returns></returns> public PagingDataSet <TopicEntity> Gets(string areaCode, long?categoryId, SortBy_Topic sortBy, int pageSize = 20, int pageIndex = 1) { //无需维护缓存即时性 return(groupRepository.Gets(areaCode, categoryId, sortBy, pageSize, pageIndex)); }
/// <summary> /// 专题地区导航内容块 /// </summary> /// <returns></returns> public ActionResult _AreaTopics(int topNumber, string areaCode, long?categoryId, SortBy_Topic sortBy = SortBy_Topic.DateCreated_Desc) { IUser iUser = (User)UserContext.CurrentUser; User user = null; if (iUser == null) { user = new User(); } else { user = userService.GetFullUser(iUser.UserId); } if (string.IsNullOrEmpty(areaCode) && Request.Cookies["AreaTopicCookie" + user.UserId] != null && !string.IsNullOrEmpty(Request.Cookies["AreaTopicCookie" + user.UserId].Value)) { areaCode = Request.Cookies["AreaTopicCookie" + user.UserId].Value; } if (string.IsNullOrEmpty(areaCode)) { string ip = WebUtility.GetIP(); areaCode = IPSeeker.Instance().GetAreaCode(ip); if (string.IsNullOrEmpty(areaCode) && user.Profile != null) { areaCode = user.Profile.NowAreaCode; } } ViewData["areaCode"] = areaCode; if (!string.IsNullOrEmpty(areaCode)) { Area area = areaService.Get(areaCode); if (!string.IsNullOrEmpty(area.ParentCode)) { Area parentArea = areaService.Get(area.ParentCode); ViewData["parentCode"] = parentArea.AreaCode; } } IEnumerable <TopicEntity> groups = topicService.GetTops(topNumber, areaCode, categoryId, sortBy); HttpCookie cookie = new HttpCookie("AreaTopicCookie" + user.UserId, areaCode); Response.Cookies.Add(cookie); return(PartialView(groups)); }
/// <summary> /// 获取匹配的前N个排行专题 /// </summary> /// <param name="topNumber">前多少个</param> /// <param name="keyword">关键字</param> /// <param name="areaCode">地区代码</param> /// <param name="categoryId">类别Id</param> /// <param name="sortBy">排序字段</param> /// <returns></returns> public IEnumerable <TopicEntity> GetMatchTops(int topNumber, string keyword, string areaCode, long?categoryId, SortBy_Topic sortBy) { return(GetTopEntities(topNumber, CachingExpirationType.UsualObjectCollection, () => { StringBuilder cacheKey = new StringBuilder(); cacheKey.AppendFormat("TopTopics::areaCode-{0}:categoryId-{1}:sortBy-{2}:keyword-{3}", areaCode, categoryId, sortBy, keyword); return cacheKey.ToString(); }, () => { return Getsqls(areaCode, categoryId, keyword, sortBy); })); }