Пример #1
0
        /// <summary>
        /// 获取最新微博
        /// </summary>
        ///<param name="lastMicroblogId">用户当前浏览的最新一条微博Id</param>
        ///<param name="tenantTypeId">租户类型Id</param>
        /// <returns></returns>
        public int GetNewerCount(long lastMicroblogId, string tenantTypeId)
        {
            ICacheService cacheService = DIContainer.Resolve <ICacheService>();

            string cacheKey = GetCackeKey_PagingMicroblogs(tenantTypeId, null, null, SortBy_Microblog.DateCreated);

            PagingEntityIdCollection peic = cacheService.Get <PagingEntityIdCollection>(cacheKey);

            if (peic == null)
            {
                Sql sql = GenerateSql_Paging_Top(0, tenantTypeId, null, null, SortBy_Microblog.DateCreated);
                peic = CreateDAO().FetchPagingPrimaryKeys <MicroblogEntity>(PrimaryMaxRecords, pageSize * CacheablePageCount, 1, sql);
                peic.IsContainsMultiplePages = true;
                cacheService.Add(cacheKey, peic, Tunynet.Caching.CachingExpirationType.ObjectCollection);
            }

            IEnumerable <long> ids = peic.GetTopEntityIds(1000).Cast <long>();
            int count = 0;

            if (ids != null && ids.Count() > 0 && ids.Contains(lastMicroblogId))
            {
                count = ids.ToList().IndexOf(lastMicroblogId);
            }

            return(count);
        }
Пример #2
0
        /// <summary>
        /// 获取操作对象的Id集合
        /// </summary>
        /// <param name="tenantTypeId">租户类型Id</param>
        ///<param name="sortBy">顶踩排序字段</param>
        ///<param name="pageSize">每页的内容数</param>
        ///<param name="pageIndex">页码</param>
        public PagingEntityIdCollection GetObjectIds(string tenantTypeId, SortBy_Attitude sortBy, int pageSize, int pageIndex)
        {
            var sql = Sql.Builder;

            sql.Select("ObjectId")
            .From("tn_Attitudes")
            .Where("TenantTypeId = @0", tenantTypeId);

            //是否按综合评价取倒序列表
            if (sortBy == SortBy_Attitude.Comprehensive_Desc)
            {
                sql.OrderBy("Comprehensive DESC ");
            }
            else
            {
                sql.OrderBy("SupportCount DESC ");
            }

            PagingEntityIdCollection objectIds = null;
            string cacheKey = GetCacheKey_ObjectIds(tenantTypeId, sortBy);

            objectIds = cacheService.Get <PagingEntityIdCollection>(cacheKey);
            if (objectIds == null)
            {
                objectIds = CreateDAO().FetchPagingPrimaryKeys(PrimaryMaxRecords, pageSize, pageIndex, "ObjectId", sql);
                cacheService.Add(cacheKey, objectIds, CachingExpirationType.ObjectCollection);
            }
            return(objectIds);
        }
Пример #3
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);
        }
Пример #4
0
        //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);
        }
Пример #5
0
        /// <summary>
        /// 获取前N条操作对象Id
        /// </summary>
        /// <param name="topNumber">获取前N条</param>
        /// <param name="tenantTypeId">租户类型Id</param>
        /// <param name="ownerId">拥有者Id</param>
        public IEnumerable <long> GetTopObjectIds(int topNumber, string tenantTypeId, long ownerId = 0)
        {
            //从评价信息表中查询并按综合评价倒序

            PagingEntityIdCollection peic = null;
            string cacheKey = GetCacheKey_ObjectIds(tenantTypeId, ownerId);

            peic = cacheService.Get <PagingEntityIdCollection>(cacheKey);
            if (peic == null)
            {
                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");
                IEnumerable <object> entityIds = CreateDAO().FetchTopPrimaryKeys(SecondaryMaxRecords, "ObjectId", sql);
                peic = new PagingEntityIdCollection(entityIds);
                cacheService.Add(cacheKey, peic, CachingExpirationType.ObjectCollection);
            }
            IEnumerable <object> topEntityIds = peic.GetTopEntityIds(topNumber);

            return(topEntityIds.Cast <long>());
        }
Пример #6
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
            });
        }
Пример #7
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
            });
        }
Пример #8
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);
        }
Пример #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);
        }
Пример #10
0
        protected virtual System.Collections.Generic.IEnumerable <TEntity> GetTopEntities(int topNumber, CachingExpirationType cachingExpirationTypes, Func <string> getCacheKey, Func <Sql> generateSql)
        {
            string cacheKey = getCacheKey();
            PagingEntityIdCollection pagingEntityIdCollection = this.cacheService.Get <PagingEntityIdCollection>(cacheKey);

            if (pagingEntityIdCollection == null)
            {
                System.Collections.Generic.IEnumerable <object> entityIds = this.CreateDAO().FetchTopPrimaryKeys <TEntity>(this.SecondaryMaxRecords, generateSql());
                pagingEntityIdCollection = new PagingEntityIdCollection(entityIds);
                this.cacheService.Add(cacheKey, pagingEntityIdCollection, cachingExpirationTypes);
            }
            System.Collections.Generic.IEnumerable <object> topEntityIds = pagingEntityIdCollection.GetTopEntityIds(topNumber);
            return(this.PopulateEntitiesByEntityIds <object>(topEntityIds));
        }
Пример #11
0
        public int GetPageIndexForCommentInParentCommens(long commentId, long parentId, SortBy_Comment sortBy)
        {
            int    pageIndex = 1;
            string cacheKey  = GetCacheKey_GetChildren(parentId, sortBy);

            PagingEntityIdCollection peic = cacheService.Get <PagingEntityIdCollection>(cacheKey);

            if (peic == null)
            {
                peic = CreateDAO().FetchPagingPrimaryKeys <Comment>(PrimaryMaxRecords, PageSize * CacheablePageCount, 1, GetSql_CommentPageIndexInParentComments(parentId, sortBy));
                peic.IsContainsMultiplePages = true;
                cacheService.Add(cacheKey, peic, CachingExpirationType.ObjectCollection);
            }
            if (peic != null)
            {
                IList <long> commentIds   = peic.GetTopEntityIds(peic.Count).Cast <long>().ToList();
                int          commentIndex = commentIds.IndexOf(commentId);
                if (commentIndex > 0)
                {
                    pageIndex = commentIndex / ChildPageSize + 1;
                }
                else
                {
                    PetaPoco.Sql sql = PetaPoco.Sql.Builder
                                       .Select("Count(Id)")
                                       .From("tn_Comments")
                                       .Where("ParentId=@0", parentId);
                    switch (sortBy)
                    {
                    case SortBy_Comment.DateCreated:
                        sql.Where("Id<@0", commentId);
                        break;

                    case SortBy_Comment.DateCreatedDesc:
                        sql.Where("Id>@0", commentId);
                        break;

                    default:
                        sql.Where("Id<@0", commentId);
                        break;
                    }
                    commentIndex = CreateDAO().FirstOrDefault <int>(sql);
                    if (commentIndex > 0)
                    {
                        pageIndex = commentIndex / ChildPageSize + 1;
                    }
                }
            }
            return(pageIndex);
        }
Пример #12
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);
        }
Пример #13
0
        /// <summary>
        /// 获取前topNumber条Entity(启用缓存)
        /// </summary>
        /// <remarks>
        /// 一次性取出前SecondaryMaxRecords条记录
        /// </remarks>
        /// <param name="topNumber"></param>
        /// <param name="cachingExpirationTypes">缓存策略</param>
        /// <param name="getCacheKey">生成cacheKey的委托(CacheKey不要与topNumber相关)</param>
        /// <param name="generateSql">生成PetaPoco.Sql的委托</param>
        /// <returns></returns>
        protected virtual IEnumerable <TEntity> GetTopEntities(int topNumber, CachingExpirationType cachingExpirationTypes, Func <string> getCacheKey, Func <PetaPoco.Sql> generateSql)
        {
            PagingEntityIdCollection peic = null;
            string cacheKey = getCacheKey();

            peic = cacheService.Get <PagingEntityIdCollection>(cacheKey);
            if (peic == null)
            {
                IEnumerable <object> entityIds = CreateDAO().FetchTopPrimaryKeys <TEntity>(SecondaryMaxRecords, generateSql());
                peic = new PagingEntityIdCollection(entityIds);
                cacheService.Add(cacheKey, peic, cachingExpirationTypes);
            }

            IEnumerable <object> topEntityIds = peic.GetTopEntityIds(topNumber);

            return(PopulateEntitiesByEntityIds(topEntityIds));
        }
Пример #14
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);
        }
Пример #15
0
        /// <summary>
        /// 获取前N个用户Id数据
        /// </summary>
        /// <param name="dataKey">dataKey</param>
        /// <param name="tenantTypeId">租户类型Id</param>
        /// <param name="topNumber">获取记录的个数</param>
        /// <param name="sortBy">排序字段</param>
        /// <returns></returns>
        public IEnumerable <long> GetTopOwnerIds(string dataKey, string tenantTypeId, int topNumber, 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;
                }
            }

            string cacheKey = string.Format("TopOwnerIdsFromOwnerData::DataKey:{0}-SortBy:{1}-TenantTypeId:{2}", dataKey, sortBy, tenantTypeId);

            peic = cacheService.Get <PagingEntityIdCollection>(cacheKey);

            if (peic == null)
            {
                IEnumerable <object> ownerIds = CreateDAO().FetchTopPrimaryKeys(SecondaryMaxRecords, "OwnerId", sql);
                peic = new PagingEntityIdCollection(ownerIds);
                cacheService.Add(cacheKey, peic, CachingExpirationType.ObjectCollection);
            }

            return(peic.GetTopEntityIds(topNumber).Select(n => Convert.ToInt64(n)));
        }
Пример #16
0
        /// <summary>
        /// 计算子级回帖在子回帖的第几页
        /// </summary>
        /// <param name="parentId"></param>
        /// <param name="postId"></param>
        /// <returns></returns>
        public int GetPageIndexForChildrenPost(long parentId, long postId)
        {
            int pageIndex = 1;

            //和实际获取的时候使用一个缓存
            string cacheKey = GetCacheKey_GetChildren(SortBy_BarPost.DateCreated_Desc, parentId);

            PagingEntityIdCollection peic = cacheService.Get <PagingEntityIdCollection>(cacheKey);

            if (peic == null)
            {
                var sql = Sql.Builder;
                sql.Select("PostId")
                .From("spb_BarPosts")
                .Where("ParentId = @0", parentId)
                .OrderBy("PostId desc");
                peic = CreateDAO().FetchPagingPrimaryKeys <BarPost>(PrimaryMaxRecords, childrenPageSize * CacheablePageCount, 1, sql);
                peic.IsContainsMultiplePages = true;
                cacheService.Set(cacheKey, peic, CachingExpirationType.ObjectCollection);
            }

            if (peic != null)
            {
                IList <long> postIds   = peic.GetTopEntityIds(peic.Count).Cast <long>().ToList();
                int          postIndex = postIds.IndexOf(postId);
                if (postIndex > 0)
                {
                    pageIndex = postIndex / childrenPageSize + 1;
                }
                else
                {
                    Sql sql = Sql.Builder;
                    sql.Select("count(PostId)")
                    .From("spb_BarPosts")
                    .Where("ParentId = @0", parentId)
                    .Where("PostId>@0", postId);
                    postIndex = CreateDAO().FirstOrDefault <int>(sql);
                    if (postIndex > 0)
                    {
                        pageIndex = postIndex / childrenPageSize + 1;
                    }
                }
            }
            return(pageIndex);
        }
Пример #17
0
        /// <summary>
        /// 获取计数对象Id集合
        /// </summary>
        /// <remarks>
        /// 一次性取出前SecondaryMaxRecords条记录
        /// </remarks>
        /// <param name="topNumber">准备获取的条数</param>
        /// <param name="tenantTypeId">租户类型Id</param>
        /// <param name="countType">计数类型</param>
        /// <param name="ownerId">拥有者Id</param>
        /// <returns>计数对象Id集合</returns>
        public IEnumerable <long> GetTops(int topNumber, string tenantTypeId, string countType, long?ownerId = null)
        {
            //从计数表中查询,并按统计数倒序排序
            PagingEntityIdCollection peic = null;
            string cacheKey = GetCacheKey_Counts(tenantTypeId, countType, ownerId);

            peic = cacheService.Get <PagingEntityIdCollection>(cacheKey);
            if (peic == null)
            {
                IEnumerable <object> entityIds = CreateDAO().FetchTop <long>(SecondaryMaxRecords, GetsSql(tenantTypeId, countType, ownerId)).Cast <object>();
                peic = new PagingEntityIdCollection(entityIds);
                cacheService.Add(cacheKey, peic, CachingExpirationType.ObjectCollection);
            }

            IEnumerable <object> topEntityIds = peic.GetTopEntityIds(topNumber);

            return(topEntityIds.Cast <long>());
        }
Пример #18
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);
        }
Пример #19
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));
        }
Пример #20
0
        /// <summary>
        /// 计算回帖在帖子的哪一页
        /// </summary>
        /// <param name="threadId"></param>
        /// <param name="postId"></param>
        /// <returns></returns>
        public int GetPageIndexForPostInThread(long threadId, long postId)
        {
            int    pageIndex = 1;
            string cacheKey  = GetCacheKey_PostIdsOfThread(threadId, false, SortBy_BarPost.DateCreated);
            PagingEntityIdCollection peic = cacheService.Get <PagingEntityIdCollection>(cacheKey);

            if (peic == null)
            {
                peic = CreateDAO().FetchPagingPrimaryKeys <BarPost>(PrimaryMaxRecords, pageSize * CacheablePageCount, 1, GetSql_Posts(threadId, false, 0, SortBy_BarPost.DateCreated));
                peic.IsContainsMultiplePages = true;
                cacheService.Add(cacheKey, peic, CachingExpirationType.ObjectCollection);
            }

            if (peic != null)
            {
                IList <long> postIds   = peic.GetTopEntityIds(peic.Count).Cast <long>().ToList();
                int          postIndex = postIds.IndexOf(postId);
                if (postIndex > 0)
                {
                    pageIndex = postIndex / pageSize + 1;
                }
                else
                {
                    Sql sql = Sql.Builder
                              .Select("count(PostId)")
                              .From("spb_BarPosts")
                              .Where("ParentId=0")
                              .Where("ThreadId=@0", threadId)
                              .Where("PostId<@0", postId);
                    postIndex = CreateDAO().FirstOrDefault <int>(sql);

                    if (postIndex > 0)
                    {
                        pageIndex = postIndex / pageSize + 1;
                    }
                }
            }
            return(pageIndex);
        }
Пример #21
0
        /// <summary>
        /// 获取用户在某一租户下顶过的内容
        /// </summary>
        /// <param name="tenantTypeId">租户类型Id</param>
        ///<param name="userId">用户Id</param>
        ///<param name="pageSize">每页的内容数</param>
        ///<param name="pageIndex">页码</param>
        public PagingEntityIdCollection GetObjectIds(string tenantTypeId, long userId, int pageSize, int pageIndex)
        {
            var sql = Sql.Builder;

            sql.Select("ObjectId")
            .From("tn_AttitudeRecords")
            .Where("TenantTypeId = @0", tenantTypeId)
            .Where("UserId=@0", userId)
            .Where("IsSupport =1");

            sql.OrderBy("Id DESC");

            PagingEntityIdCollection objectIds = null;
            string cacheKey = GetCacheKey_ObjectIds(tenantTypeId, userId, pageIndex);

            objectIds = cacheService.Get <PagingEntityIdCollection>(cacheKey);
            if (objectIds == null)
            {
                objectIds = CreateDAO().FetchPagingPrimaryKeys(PrimaryMaxRecords, pageSize, pageIndex, "ObjectId", sql);
                cacheService.Add(cacheKey, objectIds, CachingExpirationType.ObjectCollection);
            }
            return(objectIds);
        }
Пример #22
0
        /// <summary>
        /// 获取计数
        /// </summary>
        /// <param name="tenantTypeId">租户类型Id</param>
        /// <param name="countType">计数类型</param>
        /// <param name="ownerId">拥有者Id</param>
        /// <param name="pageIndex">页码数</param>
        public PagingEntityIdCollection Gets(string tenantTypeId, string countType, long?ownerId = null, int pageIndex = 1)
        {
            //从计数表中查询,并按统计数倒序排序
            PagingEntityIdCollection peic = null;

            if (pageIndex < CacheablePageCount)
            {
                string cacheKey = GetCacheKey_Counts(tenantTypeId, countType, ownerId);
                peic = cacheService.Get <PagingEntityIdCollection>(cacheKey);
                if (peic == null)
                {
                    peic = CreateDAO().FetchPagingPrimaryKeys(PrimaryMaxRecords, pageSize * CacheablePageCount, 1, "ObjectId", GetsSql(tenantTypeId, countType, ownerId));
                    peic.IsContainsMultiplePages = true;
                    cacheService.Add(cacheKey, peic, CachingExpirationType.ObjectCollection);
                }
            }
            else
            {
                peic = CreateDAO().FetchPagingPrimaryKeys(PrimaryMaxRecords, pageSize, pageIndex, "ObjectId", GetsSql(tenantTypeId, countType, ownerId));
            }

            return(peic);
        }
Пример #23
0
        /// <summary>
        /// 获取参与用户的Id集合
        /// </summary>
        /// <param name="objectId">操作对象Id</param>
        /// <param name="tenantTypeId">租户类型Id</param>
        /// <param name="IsSupport">用户是否支持(true为支持,false为反对)</param>
        /// <param name="topNumber">获取条数</param>
        public IEnumerable <long> GetTopOperatedUserIds(long objectId, string tenantTypeId, bool IsSupport, int topNumber)
        {
            StringBuilder cacheKey = new StringBuilder(RealTimeCacheHelper.GetListCacheKeyPrefix(CacheVersionType.AreaVersion, "ObjectId", objectId));

            cacheKey.AppendFormat("TenantTypeId-{0}:IsSupport-{1}", tenantTypeId, Convert.ToInt32(IsSupport));
            PagingEntityIdCollection topOperatedUserIds = cacheService.Get <PagingEntityIdCollection>(cacheKey.ToString());

            if (topOperatedUserIds == null)
            {
                var sql = PetaPoco.Sql.Builder;
                sql.Select("UserId")
                .From("tn_AttitudeRecords")
                .Where("ObjectId =@0", objectId)
                .Where("TenantTypeId=@0", tenantTypeId)
                .Where("IsSupport = @0", IsSupport);
                IEnumerable <object> entityIds = CreateDAO().FetchTopPrimaryKeys(SecondaryMaxRecords, "UserId", sql);
                topOperatedUserIds = new PagingEntityIdCollection(entityIds);
                cacheService.Add(cacheKey.ToString(), topOperatedUserIds, CachingExpirationType.ObjectCollection);
            }
            IEnumerable <long> topEntityIds = topOperatedUserIds.GetTopEntityIds(topNumber).Cast <long>();

            return(topEntityIds);
        }
Пример #24
0
        /// <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);
        }
Пример #25
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
            });
        }
Пример #26
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);
        }
Пример #27
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);
        }
Пример #28
0
        /// <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);
        }
Пример #29
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
            });
        }