/// <summary> /// 获取存档的日志分页集合 /// </summary> /// <param name="tenantTypeId">租户类型Id</param> /// <param name="ownerId">ownerId</param> /// <param name="ignoreAudit">忽略审核状态</param> /// <param name="ignorePrivate">忽略隐私状态为私有的记录</param> /// <param name="archivePeriod">归档阶段</param> /// <param name="archiveItem">归档统计项目</param> /// <param name="pageSize">每页记录数</param> /// <param name="pageIndex">页码</param> /// <returns>日志分页列表</returns> public PagingDataSet <BlogThread> GetsForArchive(string tenantTypeId, long ownerId, bool ignoreAudit, bool ignorePrivate, ArchivePeriod archivePeriod, ArchiveItem archiveItem, int pageSize = 20, int pageIndex = 1) { //只获取可对外显示审核状态的主题帖 //排除草稿 //缓存周期:对象集合,不用维护即时性 return(blogThreadRepository.GetsForArchive(tenantTypeId, ownerId, ignoreAudit, ignorePrivate, archivePeriod, archiveItem, pageSize, pageIndex)); }
/// <summary> /// 获取存档的日志分页集合 /// </summary> /// <param name="tenantTypeId">租户类型Id</param> /// <param name="ownerId">所有者id</param> /// <param name="ignoreAudit">是否忽略审核状态(作者或管理员查看时忽略审核状态)</param> /// <param name="ignorePrivate">是否忽略私有</param> /// <param name="archivePeriod">归档阶段</param> /// <param name="archiveItem">归档日期标识</param> /// <param name="pageSize">分页大小</param> /// <param name="pageIndex">页码</param> /// <returns>日志分页列表</returns> public PagingDataSet <BlogThread> GetsForArchive(string tenantTypeId, long ownerId, bool ignoreAudit, bool ignorePrivate, ArchivePeriod archivePeriod, ArchiveItem archiveItem, int pageSize = 20, int pageIndex = 1) { return(GetPagingEntities(pageSize, pageIndex, CachingExpirationType.ObjectCollection, () => { StringBuilder cacheKey = new StringBuilder(); cacheKey.Append(RealTimeCacheHelper.GetListCacheKeyPrefix(CacheVersionType.AreaVersion, "OwnerId", ownerId)); cacheKey.AppendFormat("BlogArchives::TenantTypeId-{0}:ArchivePeriod-{1}:ArchiveItem-{2}:IgnoreAudit-{3}:IgnorePrivate-{4}", tenantTypeId, archivePeriod, archiveItem, ignoreAudit, ignorePrivate); return cacheKey.ToString(); }, () => { var sql = Sql.Builder.Select("spb_BlogThreads.*") .From("spb_BlogThreads") .Where("TenantTypeId=@0", tenantTypeId) .Where("OwnerId=@0", ownerId) .Where("IsDraft=0"); if (!ignoreAudit) { switch (this.PubliclyAuditStatus) { case PubliclyAuditStatus.Again: case PubliclyAuditStatus.Fail: case PubliclyAuditStatus.Pending: case PubliclyAuditStatus.Success: sql.Where("AuditStatus=@0", this.PubliclyAuditStatus); break; case PubliclyAuditStatus.Again_GreaterThanOrEqual: case PubliclyAuditStatus.Pending_GreaterThanOrEqual: sql.Where("AuditStatus>@0", this.PubliclyAuditStatus); break; default: break; } } if (ignorePrivate) { sql.Where("PrivacyStatus<>@0", PrivacyStatus.Private); } DateTime beginDate = new DateTime(1900, 1, 1); DateTime endDate = DateTime.Now; switch (archivePeriod) { case ArchivePeriod.Year: beginDate = new DateTime(archiveItem.Year, 1, 1).ToUniversalTime(); endDate = new DateTime(archiveItem.Year + 1, 1, 1).ToUniversalTime(); break; case ArchivePeriod.Month: beginDate = new DateTime(archiveItem.Year, archiveItem.Month, 1).ToUniversalTime(); endDate = beginDate.AddMonths(1); break; case ArchivePeriod.Day: beginDate = new DateTime(archiveItem.Year, archiveItem.Month, archiveItem.Day).ToUniversalTime(); endDate = new DateTime(archiveItem.Year, archiveItem.Month, archiveItem.Day + 1).ToUniversalTime(); break; default: break; } sql.Where("DateCreated >= @0 and DateCreated < @1", beginDate, endDate).OrderBy("ThreadId desc"); return sql; })); }
/// <summary> /// 日志列表 /// </summary> public ActionResult List(string spaceKey, ListType listType, string tag = null, int year = 0, int month = 0, long categoryId = 0, int pageIndex = 1) { PagingDataSet<BlogThread> blogs = null; IUser currentUser = UserContext.CurrentUser; string title = string.Empty; switch (listType) { case ListType.Archive: ArchivePeriod archivePeriod = ArchivePeriod.Year; if (month > 0) { archivePeriod = ArchivePeriod.Month; } ArchiveItem archiveItem = new ArchiveItem(); archiveItem.Year = year; archiveItem.Month = month; if (currentUser != null && currentUser.UserName == spaceKey) { blogs = blogService.GetsForArchive(TenantTypeIds.Instance().User(), currentUser.UserId, true, false, archivePeriod, archiveItem, 20, pageIndex); } else { blogs = blogService.GetsForArchive(TenantTypeIds.Instance().User(), UserIdToUserNameDictionary.GetUserId(spaceKey), false, true, archivePeriod, archiveItem, 20, pageIndex); } title = "归档:" + year + "年"; if (month > 0) { title += month + "月"; } break; case ListType.Category: if (currentUser != null && currentUser.UserName == spaceKey) { blogs = blogService.GetOwnerThreads(TenantTypeIds.Instance().User(), currentUser.UserId, true, false, categoryId, null, false, 20, pageIndex); } else { blogs = blogService.GetOwnerThreads(TenantTypeIds.Instance().User(), UserIdToUserNameDictionary.GetUserId(spaceKey), false, true, categoryId, null, false, 20, pageIndex); } Category category = categoryService.Get(categoryId); title = "分类:" + category.CategoryName; break; case ListType.Tag: if (currentUser != null && currentUser.UserName == spaceKey) { blogs = blogService.GetOwnerThreads(TenantTypeIds.Instance().User(), currentUser.UserId, true, false, null, tag, false, 20, pageIndex); } else { blogs = blogService.GetOwnerThreads(TenantTypeIds.Instance().User(), UserIdToUserNameDictionary.GetUserId(spaceKey), false, true, null, tag, false, 20, pageIndex); } title = "标签:" + tag; break; default: break; } ViewData["title"] = title; pageResourceManager.InsertTitlePart(title); return View(blogs); }