Exemplo n.º 1
0
        /// <summary>
        /// 获取分页查询数据(启用缓存)
        /// </summary>
        /// <param name="pageSize">每页记录数</param>
        /// <param name="pageIndex">当前页码(从1开始)</param>
        /// <param name="cachingExpirationTypes">缓存策略</param>
        /// <param name="getCacheKey">生成cacheKey的委托</param>
        /// <param name="generateSql">生成PetaPoco.Sql的委托</param>
        /// <returns></returns>
        protected virtual PagingDataSet <TEntity> GetPagingEntities(int pageSize, int pageIndex, CachingExpirationType cachingExpirationTypes, Func <string> getCacheKey, Func <PetaPoco.Sql> generateSql)
        {
            PagingEntityIdCollection peic = null;

            //modified by jiangshl:分页过大时缓存多页没有意义,所以加了pageSize <= SecondaryMaxRecords的限制
            if (pageIndex < CacheablePageCount && pageSize <= SecondaryMaxRecords)
            {
                string cacheKey = getCacheKey();
                peic = cacheService.Get <PagingEntityIdCollection>(cacheKey);
                if (peic == null)
                {
                    peic = CreateDAO().FetchPagingPrimaryKeys <TEntity>(PrimaryMaxRecords, pageSize * CacheablePageCount, 1, generateSql());
                    peic.IsContainsMultiplePages = true;
                    cacheService.Add(cacheKey, peic, cachingExpirationTypes);
                }
            }
            else
            {
                peic = CreateDAO().FetchPagingPrimaryKeys <TEntity>(PrimaryMaxRecords, pageSize, pageIndex, generateSql());
            }

            IEnumerable <TEntity>   entitiesOfPage = PopulateEntitiesByEntityIds(peic.GetPagingEntityIds(pageSize, pageIndex));
            PagingDataSet <TEntity> pagingEntities = new PagingDataSet <TEntity>(entitiesOfPage)
            {
                PageIndex    = pageIndex,
                PageSize     = pageSize,
                TotalRecords = peic.TotalRecords
            };

            return(pagingEntities);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 获取分页查询数据
        /// </summary>
        /// <param name="pageSize">每页记录数</param>
        /// <param name="pageIndex">当前页码(从1开始)</param>
        /// <param name="sql">获取当前页码的数据的<see cref="PetaPoco.Sql">PetaPoco.Sql</see></param>
        /// <returns></returns>
        protected virtual PagingDataSet <TEntity> GetPagingEntities(int pageSize, int pageIndex, PetaPoco.Sql sql)
        {
            PagingEntityIdCollection peic           = CreateDAO().FetchPagingPrimaryKeys <TEntity>(PrimaryMaxRecords, pageSize, pageIndex, sql);
            IEnumerable <TEntity>    entitiesOfPage = PopulateEntitiesByEntityIds(peic.GetPagingEntityIds(pageSize, pageIndex));
            PagingDataSet <TEntity>  pagingEntities = new PagingDataSet <TEntity>(entitiesOfPage)
            {
                PageIndex    = pageIndex,
                PageSize     = pageSize,
                TotalRecords = peic.TotalRecords
            };

            return(pagingEntities);
        }
Exemplo n.º 3
0
        /// <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;
            }

            Database 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);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 根据收藏对象获取收藏了此对象的用户Id分页集合
        /// </summary>
        /// <param name="objectId">对象Id</param>
        /// <param name="tenantTypeId">租户类型Id</param>
        /// <param name="pageIndex">页码</param>
        /// <returns></returns>
        public PagingDataSet <long> GetPagingUserIdsOfObject(long objectId, string tenantTypeId, int pageIndex)
        {
            Database dao = CreateDAO();
            PagingEntityIdCollection peic = null;

            Sql sql = Sql.Builder;

            sql.Select("UserId")
            .From("tn_Favorites")
            .Where("ObjectId = @0", objectId)
            .Where("TenantTypeId = @0", tenantTypeId)
            .OrderBy("UserId desc");

            if (pageIndex < CacheablePageCount)
            {
                string cacheKey = RealTimeCacheHelper.GetListCacheKeyPrefix(CacheVersionType.AreaVersion, "ObjectId", objectId) + string.Format("PagingUserIdsOfObjectId:tenantTypeId-{0}", tenantTypeId);

                peic = cacheService.Get <PagingEntityIdCollection>(cacheKey);
                if (peic == null)
                {
                    peic = dao.FetchPagingPrimaryKeys(PrimaryMaxRecords, pageSize * CacheablePageCount, 1, "UserId", sql);
                    peic.IsContainsMultiplePages = true;
                    cacheService.Add(cacheKey, peic, CachingExpirationType.ObjectCollection);
                }
            }
            else
            {
                peic = dao.FetchPagingPrimaryKeys(PrimaryMaxRecords, pageSize, pageIndex, "UserId", sql);
            }

            if (peic != null)
            {
                PagingDataSet <long> pds = new PagingDataSet <long>(peic.GetPagingEntityIds(pageSize, pageIndex).Cast <long>());
                pds.PageSize     = pageSize;
                pds.PageIndex    = pageIndex;
                pds.TotalRecords = peic.TotalRecords;
                return(pds);
            }

            return(null);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 空间瀑布流局部页(最新相册)
        /// </summary>
        /// <param name="spaceKey">用户标识</param>
        /// <param name="tagName">标签名</param>
        /// <param name="isFavorite">是否是“我的喜欢”</param>
        /// <param name="showMore">是否显示更多链接</param>
        /// <param name="pageIndex">页码</param>
        /// <returns></returns>
        public ActionResult _NewWaterFall(string spaceKey, string tagName = null, bool isFavorite = false, bool showMore = false, int pageIndex = 1)
        {
            IUser user = userService.GetUser(spaceKey);
            bool  ignoreAuditAndPricy    = false;
            PagingDataSet <Photo> photos = new PagingDataSet <Photo>(new List <Photo>());

            if (user == null)
            {
                return(HttpNotFound());
            }
            if (UserContext.CurrentUser != null && user.UserId == UserContext.CurrentUser.UserId)
            {
                ignoreAuditAndPricy = true;
            }
            if (!string.IsNullOrEmpty(tagName))
            {
                tagName = WebUtility.UrlDecode(tagName);
            }
            if (!isFavorite)
            {
                if (!showMore)
                {
                    photos = photoService.GetUserPhotos(TenantTypeIds.Instance().User(), user.UserId, ignoreAuditAndPricy, tagName, null, SortBy_Photo.DateCreated_Desc, 20, pageIndex);
                }
                else
                {
                    if (pageIndex <= maxPageIndex)
                    {
                        photos = photoService.GetUserPhotos(TenantTypeIds.Instance().User(), user.UserId, ignoreAuditAndPricy, tagName, null, SortBy_Photo.DateCreated_Desc, 20, pageIndex);
                    }
                }
            }
            else
            {
                PagingEntityIdCollection EntityIdCollection = attitudeService.GetPageObjectIdsByUserId(user.UserId, pageSize, pageIndex);
                IEnumerable <long>       ids       = EntityIdCollection.GetPagingEntityIds(pageSize, pageIndex).Select(n => (long)n);
                IEnumerable <Photo>      favorites = photoService.GetPhotos(ids);
                photos = new PagingDataSet <Photo>(favorites);
            }
            return(View(photos));
        }
Exemplo n.º 6
0
        public PagingDataSet <OperationLogEntry> GetLogs(OperationLogQuery query, int pageSize, int pageIndex)
        {
            Sql builder = Sql.Builder;

            if (query.ApplicationId.HasValue)
            {
                builder.Where("ApplicationId = @0", new object[]
                {
                    query.ApplicationId
                });
            }
            if (!string.IsNullOrEmpty(query.Keyword))
            {
                builder.Where("OperationObjectName like @0 or Description like @0", new object[]
                {
                    '%' + query.Keyword + '%'
                });
            }
            if (!string.IsNullOrEmpty(query.OperationType))
            {
                builder.Where("OperationType = @0", new object[]
                {
                    query.OperationType
                });
            }
            if (!string.IsNullOrEmpty(query.Operator))
            {
                builder.Where("Operator like @0", new object[]
                {
                    "%" + query.Operator + "%"
                });
            }
            if (query.StartDateTime.HasValue)
            {
                builder.Where("DateCreated >= @0", new object[]
                {
                    query.StartDateTime.Value
                });
            }
            if (query.EndDateTime.HasValue)
            {
                builder.Where("DateCreated <= @0", new object[]
                {
                    query.EndDateTime.Value
                });
            }
            if (query.OperatorUserId.HasValue)
            {
                builder.Where("OperatorUserId = @0", new object[]
                {
                    query.OperatorUserId.Value
                });
            }
            if (!string.IsNullOrEmpty(query.Source))
            {
                builder.Where("Source like @0", new object[]
                {
                    "%" + query.Source + "%"
                });
            }
            builder.OrderBy(new object[]
            {
                "Id desc"
            });
            PagingEntityIdCollection pagingEntityIdCollection = this.CreateDAO().FetchPagingPrimaryKeys <OperationLogEntry>((long)this.PrimaryMaxRecords, pageSize, pageIndex, builder);

            System.Collections.Generic.IEnumerable <OperationLogEntry> entities = this.PopulateEntitiesByEntityIds <object>(pagingEntityIdCollection.GetPagingEntityIds(pageSize, pageIndex));
            return(new PagingDataSet <OperationLogEntry>(entities)
            {
                PageIndex = pageIndex,
                PageSize = pageSize,
                TotalRecords = pagingEntityIdCollection.TotalRecords
            });
        }
Exemplo n.º 7
0
        /// <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);
        }
Exemplo n.º 8
0
        protected virtual PagingDataSet <TEntity> GetPagingEntities(int pageSize, int pageIndex, Sql sql)
        {
            PagingEntityIdCollection pagingEntityIdCollection = this.CreateDAO().FetchPagingPrimaryKeys <TEntity>((long)this.PrimaryMaxRecords, pageSize, pageIndex, sql);

            System.Collections.Generic.IEnumerable <TEntity> entities = this.PopulateEntitiesByEntityIds <object>(pagingEntityIdCollection.GetPagingEntityIds(pageSize, pageIndex));
            return(new PagingDataSet <TEntity>(entities)
            {
                PageIndex = pageIndex,
                PageSize = pageSize,
                TotalRecords = pagingEntityIdCollection.TotalRecords
            });
        }
Exemplo n.º 9
0
        /// <summary>
        /// 根据DiscussQuestionQuery查询获取可分页的数据集合
        /// </summary>
        /// <param name="query">OperationLog查询对象</param>
        /// <param name="pageSize">每页记录数</param>
        /// <param name="pageIndex">当前页码(从1开始)</param>
        public PagingDataSet <OperationLogEntry> GetLogs(OperationLogQuery query, int pageSize, int pageIndex)
        {
            var sql = PetaPoco.Sql.Builder;

            if (query.ApplicationId.HasValue)
            {
                sql.Where("ApplicationId = @0", query.ApplicationId);
            }
            if (!string.IsNullOrEmpty(query.Keyword))
            {
                sql.Where("OperationObjectName like @0 or Description like @0", '%' + query.Keyword + '%');
            }
            if (!string.IsNullOrEmpty(query.OperationType))
            {
                sql.Where("OperationType = @0", query.OperationType);
            }
            if (!string.IsNullOrEmpty(query.Operator))
            {
                sql.Where("Operator like @0", "%" + query.Operator + "%");
            }
            if (query.StartDateTime.HasValue)
            {
                sql.Where("DateCreated >= @0", query.StartDateTime.Value);
            }
            if (query.EndDateTime.HasValue)
            {
                sql.Where("DateCreated <= @0", query.EndDateTime.Value);
            }
            if (query.OperatorUserId.HasValue)
            {
                sql.Where("OperatorUserId = @0", query.OperatorUserId.Value);
            }
            if (!string.IsNullOrEmpty(query.Source))
            {
                sql.Where("Source like @0", "%" + query.Source + "%");
            }

            sql.OrderBy("Id desc");

            PagingEntityIdCollection peic = CreateDAO().FetchPagingPrimaryKeys <OperationLogEntry>(PrimaryMaxRecords, pageSize, pageIndex, sql);

            IEnumerable <OperationLogEntry>   entitiesOfPage = PopulateEntitiesByEntityIds(peic.GetPagingEntityIds(pageSize, pageIndex));
            PagingDataSet <OperationLogEntry> pagingEntities = new PagingDataSet <OperationLogEntry>(entitiesOfPage)
            {
                PageIndex    = pageIndex,
                PageSize     = pageSize,
                TotalRecords = peic.TotalRecords
            };

            return(pagingEntities);
        }
Exemplo n.º 10
0
        public virtual PagingDataSet <TEntity> GetPagingEntities(int pageSize, int pageIndex, CachingExpirationType cachingExpirationTypes, Func <string> getCacheKey, Func <Sql> generateSql)
        {
            PagingEntityIdCollection ids = null;

            if ((pageIndex < this.CacheablePageCount) && (pageSize <= this.SecondaryMaxRecords))
            {
                string cacheKey = getCacheKey.Invoke();
                ids = this.cacheService.Get <PagingEntityIdCollection>(cacheKey);
                if (ids == null)
                {
                    ids = this.CreateDAO().FetchPagingPrimaryKeys <TEntity>((long)this.PrimaryMaxRecords, pageSize * this.CacheablePageCount, 1, generateSql.Invoke());
                    ids.IsContainsMultiplePages = true;
                    this.cacheService.Add(cacheKey, ids, cachingExpirationTypes);
                }
            }
            else
            {
                ids = this.CreateDAO().FetchPagingPrimaryKeys <TEntity>((long)this.PrimaryMaxRecords, pageSize, pageIndex, generateSql.Invoke());
            }
            return(new PagingDataSet <TEntity>(this.PopulateEntitiesByEntityIds <object>(ids.GetPagingEntityIds(pageSize, pageIndex)))
            {
                PageIndex = pageIndex, PageSize = pageSize, TotalRecords = ids.TotalRecords
            });
        }
Exemplo n.º 11
0
        public virtual PagingDataSet <TEntity> GetPagingEntities(int pageSize, int pageIndex, Sql sql)
        {
            PagingEntityIdCollection ids = this.CreateDAO().FetchPagingPrimaryKeys <TEntity>((long)this.PrimaryMaxRecords, pageSize, pageIndex, sql);

            return(new PagingDataSet <TEntity>(this.PopulateEntitiesByEntityIds <object>(ids.GetPagingEntityIds(pageSize, pageIndex)))
            {
                PageIndex = pageIndex, PageSize = pageSize, TotalRecords = ids.TotalRecords
            });
        }
Exemplo n.º 12
0
        /// <summary>
        /// 根据用户获取可排序的微博集合
        /// </summary>
        /// <param name="userId">用户Id</param>
        /// <param name="mediaType"><see cref="MediaType"/></param>
        /// <param name="isOriginal">是否为原创</param>
        /// <param name="pageIndex">页码</param>
        ///<param name="tenantTypeId">租户类型Id</param>
        /// <returns></returns>
        public PagingDataSet <long> GetPagingIds(long userId, MediaType?mediaType, bool?isOriginal, int pageIndex, string tenantTypeId = "")
        {
            Sql sql = Sql.Builder;

            sql.Select("MicroblogId")
            .From("spb_Microblogs")
            .Where("UserId = @0 and OwnerId = @0", userId);

            if (!string.IsNullOrEmpty(tenantTypeId))
            {
                sql.Where("TenantTypeId = @0", tenantTypeId);
            }

            if (isOriginal.HasValue && isOriginal.Value)
            {
                sql.Where("OriginalMicroblogId = 0");
            }
            else if (mediaType.HasValue)
            {
                switch (mediaType)
                {
                case MediaType.Image:
                    sql.Where("HasPhoto = 1");
                    break;

                case MediaType.Video:
                    sql.Where("HasVideo = 1");
                    break;

                case MediaType.Audio:
                    sql.Where("HasMusic = 1");
                    break;
                }
            }

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

            sql.OrderBy("MicroblogId desc");

            PagingEntityIdCollection peic = null;

            if (pageIndex < CacheablePageCount)
            {
                StringBuilder cacheKey = new StringBuilder(RealTimeCacheHelper.GetListCacheKeyPrefix(CacheVersionType.AreaVersion, "UserId", userId));
                cacheKey.AppendFormat("PagingsByUser::Type-{0}:isOriginal-{1}:TenantTypeId-{2}", mediaType, isOriginal, tenantTypeId);

                peic = cacheService.Get <PagingEntityIdCollection>(cacheKey.ToString());
                if (peic == null)
                {
                    peic = CreateDAO().FetchPagingPrimaryKeys <MicroblogEntity>(PrimaryMaxRecords, pageSize * CacheablePageCount, 1, sql);
                    peic.IsContainsMultiplePages = true;
                    cacheService.Add(cacheKey.ToString(), peic, CachingExpirationType.ObjectCollection);
                }
            }
            else
            {
                peic = CreateDAO().FetchPagingPrimaryKeys <MicroblogEntity>(PrimaryMaxRecords, pageSize, pageIndex, sql);
            }

            IEnumerable <long>   ids = peic.GetPagingEntityIds(pageSize, pageIndex).Cast <long>();
            PagingDataSet <long> pds = new PagingDataSet <long>(ids);

            pds.PageSize     = pageSize;
            pds.PageIndex    = pageIndex;
            pds.TotalRecords = peic.TotalRecords;

            return(pds);
        }
Exemplo n.º 13
0
        /// <summary>
        /// 根据多个话题名称(标签)分页查询微博列表
        /// </summary>
        /// <param name="tagNames">话题名称列表</param>
        /// <param name="pageSize">分页大小</param>
        /// <param name="pageIndex">页码</param>
        /// <returns></returns>
        public PagingDataSet <MicroblogEntity> GetMicroblogsByTagNames(IEnumerable <string> tagNames, int pageSize, int pageIndex)
        {
            PagingEntityIdCollection pec = tagService.GetItemIds(tagNames, null, pageSize, pageIndex);

            IEnumerable <MicroblogEntity> microblogEntitysList = microblogRepository.PopulateEntitiesByEntityIds(pec.GetPagingEntityIds(pageSize, pageIndex));

            //组装分页对象
            PagingDataSet <MicroblogEntity> microblogEntitysPage = new PagingDataSet <MicroblogEntity>(microblogEntitysList)
            {
                TotalRecords = pec.TotalRecords,
                PageSize     = pageSize,
                PageIndex    = pageIndex
            };

            return(microblogEntitysPage);
        }