//done:zhengw,by mazq 这个方法为什么要重写呢? //zhengw回复:已删除 /// <summary> /// 获取我的邀请好友记录 /// </summary> /// <param name="userId">用户Id</param> /// <param name="pageIndex">页码</param> /// <returns>被邀请的好友Id列表</returns> public PagingEntityIdCollection GetMyInviteFriendRecords(long userId, int pageIndex = 1) { PetaPocoDatabase dao = CreateDAO(); //仿照其他分页方法做 var sql = Sql.Builder; sql.Select("InvitedUserId") .From("tn_InviteFriendRecords") //done:bianchx by libsh,不需要加判断 //回复:已经删除了对应的判断。 .Where("UserId = @0", userId) .OrderBy("DateCreated desc"); PagingEntityIdCollection peic = null; if (pageIndex <= CacheablePageCount) { string cacheKey = GetCacheKey_InviteUserIds(userId); peic = cacheService.Get <PagingEntityIdCollection>(cacheKey); if (peic == null) { peic = dao.FetchPagingPrimaryKeys(PrimaryMaxRecords, pageSize * CacheablePageCount, 1, "InvitedUserId", sql); peic.IsContainsMultiplePages = true; cacheService.Add(cacheKey, peic, CachingExpirationType.ObjectCollection); } } else { peic = dao.FetchPagingPrimaryKeys(PrimaryMaxRecords, pageSize, pageIndex, "InvitedUserId", sql); } return(peic); }
/// <summary> /// 获取收藏对象Id分页数据 /// </summary> /// <param name="userId">用户Id</param> /// <param name="tenantTypeId">租户类型Id</param> /// <param name="pageIndex">页码</param> /// <param name="pageSize">每页显示的内容数</param> ///<returns></returns> public PagingDataSet <long> GetPagingObjectIds(long userId, string tenantTypeId, int pageIndex, int?pageSize = null) { PagingEntityIdCollection peic = null; Sql sql = Sql.Builder; sql.Select("ObjectId") .From("tn_Favorites") .Where("UserId = @0", userId) .Where("TenantTypeId = @0", tenantTypeId) .OrderBy("Id desc"); if (!pageSize.HasValue) { pageSize = this.pageSize; } PetaPocoDatabase dao = CreateDAO(); if (pageIndex < CacheablePageCount) { string cacheKey = GetCacheKey_PaingObjectIds(userId, tenantTypeId); peic = cacheService.Get <PagingEntityIdCollection>(cacheKey); if (peic == null) { peic = dao.FetchPagingPrimaryKeys(PrimaryMaxRecords, pageSize.Value * CacheablePageCount, 1, "ObjectId", sql); peic.IsContainsMultiplePages = true; cacheService.Add(cacheKey, peic, CachingExpirationType.ObjectCollection); } } else { peic = dao.FetchPagingPrimaryKeys(PrimaryMaxRecords, pageSize.Value, pageIndex, "ObjectId", sql); } if (peic != null) { PagingDataSet <long> pds = new PagingDataSet <long>(peic.GetPagingEntityIds(pageSize.Value, pageIndex).Cast <long>()); pds.PageSize = pageSize.Value; pds.PageIndex = pageIndex; pds.TotalRecords = peic.TotalRecords; return(pds); } return(null); }
/// <summary> /// 获取操作对象Id集合 用于分页 /// </summary> /// <param name="tenantTypeId"> 租户类型Id</param> /// <param name="pageIndex">页码</param> /// <param name="ownerId">拥有者Id</param> public PagingEntityIdCollection GetPagingObjectIds(string tenantTypeId, int pageIndex = 1, long ownerId = 0) { //从评价信息表中查询 并按综合评价倒序排序 var sql = Sql.Builder; sql.Select("ObjectId") .From("tn_Ratings") .Where("TenantTypeId = @0", tenantTypeId); if (ownerId > 0) { sql.Where("OwnerId = @0", ownerId); } sql.OrderBy("Comprehensive DESC"); PetaPocoDatabase dao = CreateDAO(); PagingEntityIdCollection peic = null; if (pageIndex <= CacheablePageCount) { string cacheKey = GetCacheKey_ObjectIds(tenantTypeId, ownerId); peic = cacheService.Get <PagingEntityIdCollection>(cacheKey); if (peic == null) { peic = dao.FetchPagingPrimaryKeys(PrimaryMaxRecords, pageSize * CacheablePageCount, 1, "ObjectId", sql); peic.IsContainsMultiplePages = true; cacheService.Add(cacheKey, peic, CachingExpirationType.ObjectCollection); } } else { peic = dao.FetchPagingPrimaryKeys(PrimaryMaxRecords, pageSize, pageIndex, "ObjectId", sql); } return(peic); }
/// <summary> /// 获取多个标签的内容项集合 /// </summary> /// <param name="tagNames">标签名称列表</param> /// <param name="tenantTypeId">租户类型Id</param> /// <param name="ownerId">拥有者Id</param> /// <param name="pageSize">每页记录数</param> /// <param name="pageIndex">当前页码(从1开始)</param> /// <returns>返回指定页码的内容项Id集合</returns> public PagingEntityIdCollection GetItemIds(IEnumerable <string> tagNames, string tenantTypeId, long?ownerId, int pageSize, int pageIndex) { //获取缓存 StringBuilder cacheKey = new StringBuilder(RealTimeCacheHelper.GetListCacheKeyPrefix(CacheVersionType.AreaVersion, "TagNames", tagNames)); cacheKey.AppendFormat(":ItemIds-TenantTypeId:{0}-OwnerId:{0}", tenantTypeId, ownerId.HasValue ? ownerId.ToString() : string.Empty); var sql = PetaPoco.Sql.Builder; if (ownerId.HasValue && ownerId > 0) { //组装sql语句 sql.Select("ItemId") .From("tn_ItemsInTags IT") .InnerJoin("tn_TagsInOwners TIO") .On("IT.TagInOwnerId = TIO.Id") .Where("TIO.OwnerId = @0", ownerId); if (!string.IsNullOrEmpty(tenantTypeId)) { sql.Where("TIO.TenantTypeId = @0", tenantTypeId); } if (tagNames != null && tagNames.Count() > 0) { sql.Where("TIO.TagName IN (@tagNames)", new { tagNames = tagNames }); } } else { //组装sql语句 sql.Select("ItemId") .From("tn_ItemsInTags"); if (!string.IsNullOrEmpty(tenantTypeId)) { sql.Where("TenantTypeId = @0", tenantTypeId); } if (tagNames != null && tagNames.Count() > 0) { sql.Where("TagName IN (@tagNames)", new { tagNames = tagNames }); } } PetaPocoDatabase dao = CreateDAO(); PagingEntityIdCollection peic = null; if (pageIndex < CacheablePageCount) { peic = cacheService.Get <PagingEntityIdCollection>(cacheKey.ToString()); if (peic == null) { peic = dao.FetchPagingPrimaryKeys(PrimaryMaxRecords, pageSize * CacheablePageCount, 1, "ItemId", sql); peic.IsContainsMultiplePages = true; cacheService.Add(cacheKey.ToString(), peic, CachingExpirationType.ObjectCollection); } } else { peic = dao.FetchPagingPrimaryKeys(PrimaryMaxRecords, pageSize, pageIndex, "ItemId", sql); } return(peic); }
/// <summary> /// 获取用户Id分页数据 /// </summary> /// <param name="dataKey">dataKey</param> /// <param name="pageIndex">页码</param> /// <param name="sortBy">排序字段</param> /// <returns></returns> public PagingDataSet <long> GetPagingOwnerIds(string dataKey, string tenantTypeId, int pageIndex, OwnerData_SortBy?sortBy = null) { PagingEntityIdCollection peic = null; Sql sql = Sql.Builder; sql.Select("OwnerId") .From("tn_OwnerData") .Where("DataKey = @0", dataKey) .Where("TenantTypeId = @0", tenantTypeId); if (sortBy.HasValue) { switch (sortBy) { case OwnerData_SortBy.LongValue: sql.OrderBy("LongValue ASC"); break; case OwnerData_SortBy.LongValue_DESC: sql.OrderBy("LongValue DESC"); break; case OwnerData_SortBy.DecimalValue: sql.OrderBy("DecimalValue ASC"); break; case OwnerData_SortBy.DecimalValue_DESC: sql.OrderBy("DecimalValue DESC"); break; } } PetaPocoDatabase dao = CreateDAO(); if (pageIndex < CacheablePageCount) { string cacheKey = string.Format("PagingOwnerIdsFromOwnerData::DataKey:{0}-SortBy:{1}-TenantTypeId:{2}", dataKey, sortBy, tenantTypeId); peic = cacheService.Get <PagingEntityIdCollection>(cacheKey); if (peic == null) { peic = dao.FetchPagingPrimaryKeys(PrimaryMaxRecords, pageSize * CacheablePageCount, 1, "OwnerId", sql); peic.IsContainsMultiplePages = true; cacheService.Add(cacheKey, peic, CachingExpirationType.ObjectCollection); } } else { peic = dao.FetchPagingPrimaryKeys(PrimaryMaxRecords, pageSize, pageIndex, "OwnerId", sql); } IEnumerable <object> temIds = peic.GetPagingEntityIds(pageSize, pageIndex); PagingDataSet <long> pagingOwnerIds = new PagingDataSet <long>(temIds.Select(n => Convert.ToInt64(n))) { PageIndex = pageIndex, PageSize = pageSize, TotalRecords = peic.TotalRecords }; return(pagingOwnerIds); }