Ejemplo n.º 1
0
        ///<summary>
        /// 获取用户的隐私设置
        /// </summary>
        /// <param name="userId">用户Id</param>
        /// <returns><para>如果用户无设置返回空集合</para><remarks>key=itemKey,value=PrivacyStatus</remarks></returns>
        public Dictionary <string, PrivacyStatus> GetUserPrivacySettings(long userId)
        {
            StringBuilder cacheKey = new StringBuilder(RealTimeCacheHelper.GetListCacheKeyPrefix(CacheVersionType.AreaVersion, "UserId", userId));

            cacheKey.AppendFormat("UserPrivacySetting");

            List <long> ids = cacheService.Get <List <long> >(cacheKey.ToString());

            if (ids == null)
            {
                var sql = Sql.Builder;
                sql.Select("Id")
                .From("tn_UserPrivacySettings")
                .Where("UserId = @0", userId);
                ids = CreateDAO().Fetch <long>(sql);
                cacheService.Add(cacheKey.ToString(), ids, CachingExpirationType.ObjectCollection);
            }
            IEnumerable <UserPrivacySetting>   settings   = PopulateEntitiesByEntityIds <long>(ids);
            Dictionary <string, PrivacyStatus> dictionary = new Dictionary <string, PrivacyStatus>();

            foreach (var item in settings)
            {
                //done:zhangp,by zhengw:建议使用索引器添加值
                //回复:已经修改
                dictionary[item.ItemKey] = item.PrivacyStatus;
            }
            return(dictionary);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 获取拥有者的分页标签列表
        /// </summary>
        /// <param name="ownerId">拥有者Id</param>
        /// <param name="tenantTypeId">租户类型Id</param>
        /// <param name="pageSize">每页显示数</param>
        /// <param name="pageIndex">页码</param>
        public IEnumerable <TagInOwner> GetTagInOwners(long ownerId, string tenantTypeId, int pageSize, int pageIndex)
        {
            return(GetPagingEntities(pageSize, pageIndex, CachingExpirationType.ObjectCollection,
                                     () =>
            {
                StringBuilder cacheKey = new StringBuilder(RealTimeCacheHelper.GetListCacheKeyPrefix(CacheVersionType.AreaVersion, "OwnerId", ownerId));
                cacheKey.Append("TagInOwners");
                if (!string.IsNullOrEmpty(tenantTypeId))
                {
                    cacheKey.AppendFormat("TenantTypeId-{0}", tenantTypeId);
                }
                return cacheKey.ToString();
            },
                                     () =>
            {
                var sql = PetaPoco.Sql.Builder;
                sql.Select("*")
                .From("tn_TagsInOwners")
                .Where("OwnerId = @0", ownerId);

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

                return sql;
            }));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 分页获取搜索词(仅非人工干预)
        /// </summary>
        /// <param name="searchTypeCode">搜索类型编码</param>
        /// <param name="term">搜索词</param>
        /// <param name="startDate">开始日期</param>
        /// <param name="endDate">结束日期</param>
        /// <param name="isRealtime">是否实时缓存</param>
        /// <param name="pageIndex">当前页码</param>
        /// <param name="pageSize">每页条数</param>
        /// <returns>按条件检索的热词</returns>
        public PagingDataSet <SearchedTerm> Gets(string searchTypeCode, string term, DateTime?startDate, DateTime?endDate, bool isRealtime, int pageSize, int pageIndex)
        {
            CountService countService   = new CountService(TenantTypeIds.Instance().Search());
            string       countTableName = countService.GetTableName_Counts();
            string       countType      = CountTypes.Instance().SearchCount();

            StageCountTypeManager stageCountTypeManager = StageCountTypeManager.Instance(TenantTypeIds.Instance().Search());
            int stageCountDays = stageCountTypeManager.GetMaxDayCount(CountTypes.Instance().SearchCount());

            return(GetPagingEntities(pageSize, pageIndex, CachingExpirationType.ObjectCollection,
                                     () =>
            {
                //done:zhangp,by mazq cacheKey应该与查询条件关联
                StringBuilder cacheKey;
                if (isRealtime)
                {
                    cacheKey = new StringBuilder(RealTimeCacheHelper.GetListCacheKeyPrefix(CacheVersionType.GlobalVersion));
                }
                else
                {
                    cacheKey = new StringBuilder(RealTimeCacheHelper.GetListCacheKeyPrefix(CacheVersionType.AreaVersion, "SearchTypeCode", searchTypeCode));
                }

                cacheKey.AppendFormat("SearchTypeCode-{0}::Term-{1}::StartData-{2}::EndData-{3}", searchTypeCode, term, startDate, endDate);
                return cacheKey.ToString();
            },
                                     () =>
            {
                var sql = Sql.Builder;
                sql.Select("*")
                .From("tn_SearchedTerms")
                .InnerJoin(countTableName)
                .On("tn_SearchedTerms.Id = " + countTableName + ".ObjectId")
                .Where("IsAddedByAdministrator = @0", 0)
                .Where("CountType = @0", countType)
                .Where("OwnerId = @0", 0);

                if (!String.IsNullOrEmpty(searchTypeCode))
                {
                    sql.Where("SearchTypeCode = @0", searchTypeCode);
                }

                if (!String.IsNullOrEmpty(term))
                {
                    sql.Where("Term like @0", term + "%");
                }

                if (startDate.HasValue)
                {
                    sql.Where("DateCreated >= @0", startDate);
                }
                if (endDate.HasValue)
                {
                    sql.Where("DateCreated <= @0", endDate);
                }
                sql.OrderBy("StatisticsCount desc");
                return sql;
            }
                                     ));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 获取拥有者一种租户类型的临时附件
        /// </summary>
        /// <param name="tenantTypeId">租户类型Id</param>
        /// <param name="ownerId">拥有者Id</param>
        public IEnumerable <T> GetTemporaryAttachments(long ownerId, string tenantTypeId)
        {
            string cacheKey = RealTimeCacheHelper.GetListCacheKeyPrefix(CacheVersionType.AreaVersion, "OwnerId", ownerId) + "TenantTypeId:" + tenantTypeId + "-TemporaryAttachments";

            ICacheService        cacheService  = DIContainer.Resolve <ICacheService>();
            IEnumerable <object> attachmentIds = cacheService.Get <IEnumerable <object> >(cacheKey);

            if (attachmentIds == null)
            {
                var sql = PetaPoco.Sql.Builder;
                sql.Select("AttachmentId")
                .From("tn_Attachments")
                .Where("OwnerId=@0", ownerId)
                .Where("AssociateId=0");
                if (!string.IsNullOrEmpty(tenantTypeId))
                {
                    sql.Where("TenantTypeId = @0", tenantTypeId);
                }
                sql.OrderBy("AttachmentId desc");

                attachmentIds = CreateDAO().FetchFirstColumn(sql);

                cacheService.Add(cacheKey, attachmentIds, CachingExpirationType.UsualObjectCollection);
            }
            return(PopulateEntitiesByEntityIds(attachmentIds));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 获取我的回复贴分页集合
        /// </summary>
        /// <param name="userId">回复贴作者Id</param>
        /// <param name="tenantTypeId">租户类型Id</param>
        /// <param name="pageIndex">页码</param>
        /// <returns>回复贴列表</returns>
        public PagingDataSet <BarPost> GetMyPosts(long userId, string tenantTypeId = null, int pageIndex = 1)
        {
            //不必筛选审核状态
            //缓存周期:对象集合,需要维护即时性
            //排序:发布时间(倒序)

            return(GetPagingEntities(pageSize, pageIndex, CachingExpirationType.ObjectCollection,
                                     () =>
            {
                StringBuilder cacheKey = new StringBuilder();
                cacheKey.Append(RealTimeCacheHelper.GetListCacheKeyPrefix(CacheVersionType.AreaVersion, "UserId", userId));
                cacheKey.AppendFormat("MyBarPosts::TenantTypeId-{0}", tenantTypeId);
                return cacheKey.ToString();
            },
                                     () =>
            {
                var sql = Sql.Builder;
                sql.Select("*")
                .From("spb_BarPosts")
                .Where("UserId = @0", userId);
                if (!string.IsNullOrEmpty(tenantTypeId))
                {
                    sql.Where("TenantTypeId = @0", tenantTypeId);
                }
                //if (ownerId.HasValue && ownerId.Value > 0)
                //    sql.Where("OwnerId = @0", ownerId.Value);
                sql.OrderBy("PostId desc");
                return sql;
            }));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 获取标签标签与拥有者关系Id集合
        /// </summary>
        /// <param name="itemId">内容项Id</param>
        /// <param name="ownerId">拥有者Id</param>
        /// <param name="tenantTypeId">租户类型Id</param>
        public IEnumerable <long> GetTagInOwnerIdsOfItem(long itemId, long ownerId, string tenantTypeId)
        {
            StringBuilder cacheKey = new StringBuilder(RealTimeCacheHelper.GetListCacheKeyPrefix(CacheVersionType.AreaVersion, "OwnerId", ownerId));

            cacheKey.AppendFormat("GetOwnerTagIdsOfItem-ItemId:{0}-TenantTypeId:{0}", itemId, tenantTypeId);

            IEnumerable <long> tagInOwnerIds = cacheService.Get <IEnumerable <long> >(cacheKey.ToString());

            if (tagInOwnerIds == null)
            {
                var sql = PetaPoco.Sql.Builder;
                sql.Select("TIO.Id")
                .From("tn_TagsInOwners TIO")
                .InnerJoin("tn_ItemsInTags IT")
                .On("IT.TagInOwnerId = TIO.Id")
                .Where("IT.ItemId = @0", itemId)
                .Where("TIO.OwnerId = @0", ownerId);

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

                tagInOwnerIds = CreateDAO().FetchFirstColumn(sql).Cast <long>();
                cacheService.Set(cacheKey.ToString(), tagInOwnerIds, CachingExpirationType.UsualObjectCollection);
            }

            return(tagInOwnerIds);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 获取前topNumber条评论
        /// </summary>
        /// <param name="ownerId">评论拥有者Id</param>
        /// <param name="tenantTypeId">租户类型Id</param>
        /// <param name="topNumber">获取的评论数量</param>
        /// <param name="sortBy">排序字段</param>
        /// <returns></returns>
        public IEnumerable <Comment> GetTopComments(long ownerId, string tenantTypeId, int topNumber, SortBy_Comment sortBy)
        {
            return(GetTopEntities(topNumber, CachingExpirationType.UsualObjectCollection,
                                  () =>
            {
                StringBuilder cacheKey = new StringBuilder(RealTimeCacheHelper.GetListCacheKeyPrefix(CacheVersionType.AreaVersion, "TenantTypeId", tenantTypeId));
                cacheKey.AppendFormat("OwnerId-{0}:SortBy-{1}", ownerId, (int)sortBy);

                return cacheKey.ToString();
            },
                                  () =>
            {
                var sql = PetaPoco.Sql.Builder.Where("TenantTypeId = @0 ", tenantTypeId);

                if (ownerId > 0)
                {
                    sql.Where("OwnerId = @0", ownerId);
                }

                switch (sortBy)
                {
                case SortBy_Comment.DateCreated:
                    sql.OrderBy("Id ASC"); break;

                case SortBy_Comment.DateCreatedDesc:
                    sql.OrderBy("Id DESC"); break;

                default:
                    sql.OrderBy("Id ASC"); break;
                }

                return sql;
            }));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 获取前N个私信会话
        /// </summary>
        /// <param name="userId">用户Id</param>
        /// <param name="topNumber">获取记录条数</param>
        /// <param name="hasUnread">是否仅获取未读会话</param>
        public IEnumerable <MessageSession> GetTopSessions(long userId, int topNumber, bool hasUnread = false)
        {
            return(GetTopEntities(topNumber, CachingExpirationType.ObjectCollection,
                                  () =>
            {
                //获取缓存Key
                StringBuilder cacheKey = new StringBuilder(RealTimeCacheHelper.GetListCacheKeyPrefix(CacheVersionType.AreaVersion, "UserId", userId));
                cacheKey.AppendFormat("TopMessageSessions");
                return cacheKey.ToString();
            },
                                  () =>
            {
                //组装sql语句
                var sql = PetaPoco.Sql.Builder;

                sql.Where("userId = @0", userId);
                if (hasUnread)
                {
                    sql.Where("UnreadMessageCount > 0");
                }

                sql.OrderBy("SessionId desc");

                return sql;
            }
                                  ));
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 获取积分项目集合
        /// </summary>
        /// <param name="applicationId">应用Id</param>
        /// <returns>如果无满足条件的积分项目返回空集合</returns>
        public IEnumerable <PointItem> GetPointItems(int?applicationId)
        {
            //done:zhangp,by zhengw: 怎么没有使用缓存?注意PointItem列表 需要使用CachingExpirationType.RelativelyStable缓存。
            //排序条件:DisplayOrder正序

            //done:zhangp,by zhengw:没有应用Id这个分区版本,应该使用全局版本
            StringBuilder cacheKey = new StringBuilder(RealTimeCacheHelper.GetListCacheKeyPrefix(CacheVersionType.GlobalVersion));

            //done:zhangp,by zhengw:加ApplicationId做什么?选择的关键词应该能表示积分项目才对,建议使用PointItems
            //回复:已修改
            cacheKey.AppendFormat("PointItems");
            List <string> itemKeys = cacheService.Get <List <string> >(cacheKey.ToString());

            if (itemKeys == null)
            {
                var sql = Sql.Builder;
                sql.Select("ItemKey")
                .From("tn_PointItems");
                if (applicationId.HasValue)
                {
                    sql.Where("ApplicationId = @0", applicationId);
                }
                sql.OrderBy("DisplayOrder");
                itemKeys = CreateDAO().Fetch <string>(sql);
                cacheService.Add(cacheKey.ToString(), itemKeys, CachingExpirationType.RelativelyStable);
            }
            return(PopulateEntitiesByEntityIds <string>(itemKeys));
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 获取用户通知的分页集合
        /// </summary>
        /// <param name="userId">用户Id</param>
        /// <param name="status">通知状态</param>
        /// <param name="typeId">通知类型Id</param>
        /// <param name="applicationId">应用Id</param>
        /// <param name="pageIndex">页码</param>
        /// <returns>通知分页集合</returns>
        public PagingDataSet <Notice> Gets(long userId, NoticeStatus?status, int?typeId, int?applicationId, int pageIndex)
        {
            return(GetPagingEntities(PageSize, pageIndex, CachingExpirationType.ObjectCollection,
                                     //获取CacheKey
                                     () =>
            {
                StringBuilder cacheKey = new StringBuilder(RealTimeCacheHelper.GetListCacheKeyPrefix(CacheVersionType.AreaVersion, "UserId", userId));
                cacheKey.AppendFormat("Status-{0}:TypeId-{1}:ApplicationId-{2}", (int?)status, typeId, userId);
                return cacheKey.ToString();
            },
                                     //生成PetaPoco.Sql
                                     () =>
            {
                var sql = PetaPoco.Sql.Builder;
                sql.Where(" UserId = @0", userId);

                if (status.HasValue)
                {
                    sql.Where("Status = @0", (int)status);
                }

                if (typeId.HasValue && typeId.Value > 0)
                {
                    sql.Where("TypeId=@0", typeId.Value);
                }

                sql.OrderBy("Id  DESC");
                return sql;
            }
                                     ));
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 获取私信会话分页数据(后台用)
        /// </summary>
        /// <param name="type">私信类型</param>
        /// <param name="userId">用户Id(用来搜索用户Id相关的私信会话)</param>
        /// <param name="pageIndex">页码</param>
        /// <returns>私信会话分页数据</returns>
        public PagingDataSet <MessageSession> GetSessions(MessageType?type, long?userId, int pageIndex)
        {
            return(GetPagingEntities(pageSize, pageIndex, CachingExpirationType.ObjectCollection,
                                     () =>
            {
                //获取缓存Key
                StringBuilder cacheKey = new StringBuilder(RealTimeCacheHelper.GetListCacheKeyPrefix(CacheVersionType.GlobalVersion));
                cacheKey.AppendFormat("Sessions-Type:{0}-UserId:{0}", (int)type, userId);
                return cacheKey.ToString();
            },
                                     () =>
            {
                //组装sql语句
                var sql = PetaPoco.Sql.Builder;
                if (type.HasValue)
                {
                    sql.Where("MessageType = @0", (int)type);
                }
                if (userId.HasValue && userId.Value > 0)
                {
                    sql.Where("UserId = @0", userId);
                }

                sql.OrderBy("UnreadMessageCount desc");
                sql.OrderBy("LastMessageId desc");

                return sql;
            }
                                     ));
        }
Ejemplo n.º 12
0
        /// <summary>
        /// 获取新的评论(供移动客户端使用)
        /// </summary>
        /// <param name="ownerId"></param>
        /// <param name="oldCommentId"></param>
        /// <returns></returns>
        public IEnumerable <Comment> GetNewComments(long ownerId, long oldCommentId)
        {
            return(GetTopEntities(SecondaryMaxRecords, CachingExpirationType.UsualObjectCollection,
                                  () =>
            {
                StringBuilder cacheKey = new StringBuilder(RealTimeCacheHelper.GetListCacheKeyPrefix(CacheVersionType.AreaVersion, "ownerId", ownerId));
                cacheKey.AppendFormat("OldCommentId-{0}", oldCommentId);

                return cacheKey.ToString();
            },
                                  () =>
            {
                var sql = PetaPoco.Sql.Builder.Where("TenantTypeId in (@0,@1,@2)", 100101, 100201, 100302);

                if (ownerId > 0)
                {
                    sql.Where("OwnerId = @0", ownerId);
                    sql.Where(" OwnerId != UserId  ");
                }
                sql.Where("Id > @0", oldCommentId);

                sql.OrderBy("Id  DESC");

                return sql;
            }));
        }
Ejemplo n.º 13
0
        /// <summary>
        /// 获取微博分页列表的CacheKey
        /// </summary>
        /// <param name="tenantTypeId">租户类型Id</param>
        /// <param name="mediaType">多媒体类型</param>
        /// <param name="isOriginal">是否为原创</param>
        /// <param name="sortBy">排序字段</param>
        /// <returns></returns>
        private string GetCackeKey_PagingMicroblogs(string tenantTypeId, MediaType?mediaType, bool?isOriginal, SortBy_Microblog sortBy)
        {
            StringBuilder cacheKey = new StringBuilder(RealTimeCacheHelper.GetListCacheKeyPrefix(CacheVersionType.GlobalVersion));

            cacheKey.AppendFormat("PagingsMicroblogs::TenantTypeId-{0}:sortBy-{1}:type-{2},isOriginal-{3}", tenantTypeId, ((int)sortBy).ToString(), mediaType, isOriginal);
            return(cacheKey.ToString());
        }
Ejemplo n.º 14
0
        /// <summary>
        /// 查询积分统计列表
        /// </summary>
        /// <param name="userId">用户Id</param>
        /// <param name="PointCategoryKey">积分项目Key</param>
        /// <param name="statisticalYear">统计年份</param>
        /// <param name="statisticalMonth">统计月份</param>
        /// <param name="statisticalDay">统计月份的第几天</param>
        /// <returns>积分统计列表</returns>
        public IEnumerable <PointStatistic> Gets(long userId, string PointCategoryKey, int?statisticalYear = null, int?statisticalMonth = null, int?statisticalDay = null)
        {
            StringBuilder      cacheKey = new StringBuilder(RealTimeCacheHelper.GetListCacheKeyPrefix(CacheVersionType.AreaVersion, "UserId", userId));
            IEnumerable <long> Ids      = cacheService.Get <IEnumerable <long> >(cacheKey.ToString());

            if (Ids == null)
            {
                var sql = Sql.Builder;
                sql.Select("Id")
                .From("tn_PointStatistics")
                .Where("UserId = @0", userId)
                .Where("PointCategoryKey = @0", PointCategoryKey);
                if (statisticalYear.HasValue)
                {
                    sql.Where("StatisticalYear = @0", statisticalYear);
                }
                if (statisticalMonth.HasValue)
                {
                    sql.Where("StatisticalMonth = @0", statisticalMonth);
                }
                if (statisticalDay.HasValue)
                {
                    sql.Where("StatisticalDay = @0", statisticalDay);
                }
                Ids = CreateDAO().Fetch <long>(sql);
                cacheService.Add(cacheKey.ToString(), Ids, CachingExpirationType.ObjectCollection);
            }
            return(PopulateEntitiesByEntityIds <long>(Ids));
        }
Ejemplo n.º 15
0
        /// <summary>
        /// 获取某人的某项(或所有)认证实体
        /// </summary>
        public List <Identification> GetUserIdentifications(long userId, long identificationTypeId)
        {
            //构建cacheKey
            StringBuilder cacheKey       = new StringBuilder();
            string        userIdCacheKey = RealTimeCacheHelper.GetListCacheKeyPrefix(CacheVersionType.AreaVersion, "UserId", userId);

            cacheKey.AppendFormat("Identifications::identificationTypeId-{0}:userIdCacheKey-{1}", identificationTypeId, userIdCacheKey);

            //先从缓存里取归档项目列表,如果缓存里没有就去数据库取
            List <Identification> identifications = cacheService.Get <List <Identification> >(cacheKey.ToString());

            if (identifications == null)
            {
                identifications = new List <Identification>();
                var sql = Sql.Builder.Select("*").From("spb_Identifications");
                sql.Where("UserId=@0", userId);
                if (identificationTypeId > 0)
                {
                    sql.Where("IdentificationTypeId=@0", identificationTypeId);
                }
                identifications = CreateDAO().Fetch <Identification>(sql);

                //加入缓存
                cacheService.Add(cacheKey.ToString(), identifications, CachingExpirationType.ObjectCollection);
            }
            return(identifications);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// 获取类别的内容项集合
        /// </summary>
        /// <param name="categoryId">分类的Id集合</param>
        /// <returns>内容项的ID集合</returns>
        public IEnumerable <long> GetItemIds(long categoryId, IEnumerable <long> categorieIds)
        {
            PetaPocoDatabase dao = CreateDAO();
            //获取缓存
            StringBuilder categoriesIdsStringBuilder = new StringBuilder();

            foreach (long id in categorieIds)
            {
                categoriesIdsStringBuilder.AppendFormat("-{0}", id);
            }
            StringBuilder cacheKey = new StringBuilder(RealTimeCacheHelper.GetListCacheKeyPrefix(CacheVersionType.AreaVersion, "CategoryId", categoryId));

            cacheKey.AppendFormat("allCategoryIds-{0}", categoriesIdsStringBuilder.ToString());

            IEnumerable <long> itemIds = null;

            itemIds = cacheService.Get <IEnumerable <long> >(cacheKey.ToString());
            if (itemIds == null)
            {
                var sql = PetaPoco.Sql.Builder;
                sql.Select("ItemId").From("tn_ItemsInCategories").Where(" CategoryId in (@ids)", new { ids = categorieIds });
                itemIds = dao.FetchFirstColumn(sql).Cast <long>();
                cacheService.Add(cacheKey.ToString(), itemIds, CachingExpirationType.UsualObjectCollection);
            }

            return(itemIds);
        }
Ejemplo n.º 17
0
        /// <summary>
        /// 获取身份认证标识
        /// </summary>
        /// <param name="userId">用户ID</param>
        /// <param name="">是否只获取成功的认证状态</param>
        /// <returns></returns>
        public IEnumerable <IdentificationType> GetIdentificationTypes(long userId, bool status = true)
        {
            //构建cacheKey
            StringBuilder cacheKey       = new StringBuilder();
            string        userIdCacheKey = RealTimeCacheHelper.GetListCacheKeyPrefix(CacheVersionType.AreaVersion, "UserId", userId);

            cacheKey.AppendFormat("IdentificationTypeIcons::userIdCacheKey-{0}:status-{1}", userIdCacheKey, status);

            //先从缓存里取,如果缓存里没有就去数据库取
            IEnumerable <IdentificationType> identificationTypes = cacheService.Get <IEnumerable <IdentificationType> >(cacheKey.ToString());

            if (identificationTypes == null)
            {
                string strSql = @"select a.* from spb_IdentificationTypes a inner join spb_Identifications b on a.IdentificationTypeId=b.IdentificationTypeId and b.UserId=" + userId.ToString() + " and a.Enabled=1 ";
                if (status)
                {
                    strSql += "and b.Status=" + (int)IdentificationStatus.success;
                }
                var sql = Sql.Builder.Append(strSql);
                identificationTypes = CreateDAO().Fetch <IdentificationType>(sql);
                //加入缓存
                cacheService.Add(cacheKey.ToString(), identificationTypes, CachingExpirationType.ObjectCollection);
            }
            return(identificationTypes);
        }
Ejemplo n.º 18
0
        /// <summary>
        /// 获取类别的内容项集合
        /// </summary>
        /// <param name="categoryId">分类的Id集合</param>
        /// <param name="pageSize">页面大小</param>
        /// <param name="pageIndex">当前页码</param>
        /// <param name="totalRecords">输出参数:总记录数</param>
        /// <returns>当页内容项的ID集合</returns>
        public IEnumerable <long> GetItemIds(long categoryId, IEnumerable <long> categorieIds, int pageSize, int pageIndex, out long totalRecords)
        {
            //根据条件获取内容项同分类的对应实体集合
            PagingDataSet <ItemInCategory> itemInCategories =
                GetPagingEntities(pageSize, pageIndex, Caching.CachingExpirationType.UsualObjectCollection,
                                  () =>
            {
                StringBuilder categoriesIdsStringBuilder = new StringBuilder();
                foreach (long id in categorieIds)
                {
                    categoriesIdsStringBuilder.AppendFormat("-{0}", id);
                }

                //获取缓存
                StringBuilder cacheKey = new StringBuilder(RealTimeCacheHelper.GetListCacheKeyPrefix(CacheVersionType.AreaVersion, "CategoryId", categoryId));
                cacheKey.AppendFormat("allCategoryIds-{0}", categoriesIdsStringBuilder.ToString());
                return(cacheKey.ToString());
            },
                                  () =>
            {
                //组装获取实体的sql语句
                var sql = PetaPoco.Sql.Builder;
                sql.Where(" CategoryId in (@ids)", new { ids = categorieIds });
                return(sql);
            }
                                  );

            totalRecords = itemInCategories.TotalRecords;
            //返回CategoryId集合
            return(itemInCategories.Where(n => n != null).Select(n => n.ItemId).ToList());
        }
Ejemplo n.º 19
0
        /// <summary>
        ///获取前N条用户的星级评价记录信息
        /// </summary>
        /// <param name="objectId"> 操作Id</param>
        /// <param name="tentanTypeId">操作类型Id</param>
        /// <param name="rateNumber">等级类型</param>
        /// <param name="topNumber">前N条</param>
        public IEnumerable <RatingRecord> GetTopRatingRecords(long objectId, string tentanTypeId, int?rateNumber, int topNumber)
        {
            return(GetTopEntities(topNumber, CachingExpirationType.ObjectCollection,
                                  () =>
            {
                StringBuilder cacheKey = new StringBuilder(RealTimeCacheHelper.GetListCacheKeyPrefix(CacheVersionType.AreaVersion, "ObjectId", objectId));

                cacheKey.Append("GetTopRatingRecords:");
                if (!string.IsNullOrEmpty(tentanTypeId))
                {
                    cacheKey.AppendFormat("TentanTypeId-{0}:RateNumber-{1}", tentanTypeId, rateNumber);
                }
                return cacheKey.ToString();
            },
                                  () =>
            {
                var sql = Sql.Builder;
                sql.Where("ObjectId = @0 and TenantTypeId = @1 ", objectId, tentanTypeId);
                if (rateNumber.HasValue && rateNumber.Value >= 1 && rateNumber.Value <= 5)
                {
                    sql.Where("RateNumber = @0", rateNumber);
                }

                sql.OrderBy("Id DESC");
                return sql;
            }));
        }
Ejemplo n.º 20
0
        /// <summary>
        /// 获取内容项的所有分类Id集合
        /// </summary>
        /// <param name="itemId">内容项Id</param>
        /// <param name="ownerId">分类所有者</param>
        /// <param name="tenantTypeId">租户Id</param>
        /// <returns>返回内容项的类别Id集合</returns>
        public IEnumerable <long> GetCategoriesOfItem(long itemId, long?ownerId, string tenantTypeId)
        {
            //根据条件获取内容项同分类的对应实体集合
            IEnumerable <ItemInCategory> itemInCategories =
                GetTopEntities(int.MaxValue, Caching.CachingExpirationType.UsualObjectCollection,
                               () =>
            {
                //获取缓存
                StringBuilder cacheKey = new StringBuilder(RealTimeCacheHelper.GetListCacheKeyPrefix(CacheVersionType.AreaVersion, "ItemId", itemId));
                cacheKey.Append("-GetCategoriesOfItem:" + itemId);
                cacheKey.Append("-ownerId:" + (ownerId ?? 0));
                cacheKey.Append("-tenantTypeId:" + tenantTypeId);
                return(cacheKey.ToString());
            },
                               () =>
            {
                //组装获取实体的sql语句
                var sql = PetaPoco.Sql.Builder;
                sql.From("tn_ItemsInCategories")
                .InnerJoin("tn_Categories C").On("tn_ItemsInCategories.CategoryId = C.CategoryId")
                .Where("tn_ItemsInCategories.ItemId = @0", itemId)
                .Where("C.OwnerId = @0 and C.TenantTypeId=@1", ownerId ?? 0, tenantTypeId);

                return(sql);
            }
                               );

            //返回CategoryId集合
            return(itemInCategories.Where(n => n != null).Select(n => n.CategoryId).ToList());
        }
Ejemplo n.º 21
0
        /// <summary>
        /// 获取用户的黑名单
        /// </summary>
        /// <returns><remarks>key=ToUserId,value=StopedUser</remarks></returns>
        public Dictionary <long, StopedUser> GetStopedUsers(long userId)
        {
            StringBuilder cacheKey = new StringBuilder(RealTimeCacheHelper.GetListCacheKeyPrefix(CacheVersionType.AreaVersion, "UserId", userId));

            cacheKey.AppendFormat("StopedUser");
            List <long> ids = cacheService.Get <List <long> >(cacheKey.ToString());

            if (ids == null)
            {
                var sql = Sql.Builder;
                sql.Select("Id")
                .From("tn_StopedUsers")
                .Where("UserId = @0", userId);
                ids = CreateDAO().Fetch <long>(sql);

                cacheService.Add(cacheKey.ToString(), ids, CachingExpirationType.ObjectCollection);
            }

            var stopUsers = PopulateEntitiesByEntityIds <long>(ids);
            Dictionary <long, StopedUser> dictionary = new Dictionary <long, StopedUser>();

            foreach (var stopUser in stopUsers)
            {
                //done:zhangp,by zhengw:建议使用dictionary[stopUser.ToUserId] = stopUser;因为使用Add时如果有重复的Key可能会报错
                //回复:已经修改
                dictionary[stopUser.ToUserId] = stopUser;
            }

            return(dictionary);
        }
Ejemplo n.º 22
0
        /// <summary>
        /// 获取拥有者附件的下载记录分页显示
        /// </summary>
        /// <param name="ownerId">附件拥有者Id</param>
        /// <param name="pageIndex">页码</param>
        /// <param name="needToBuy">是否需要购买</param>
        public PagingDataSet <AttachmentDownloadRecord> GetsByOwnerId(long ownerId, int pageIndex, bool needToBuy = true)
        {
            return(GetPagingEntities(pageSize, pageIndex, CachingExpirationType.ObjectCollection,
                                     () =>
            {
                //组装CacheKey
                StringBuilder cacheKey = new StringBuilder(RealTimeCacheHelper.GetListCacheKeyPrefix(CacheVersionType.AreaVersion, "OwnerId", ownerId));
                cacheKey.Append("GetsByOwnerId-needToBuy:" + needToBuy.ToString());
                return cacheKey.ToString();
            },
                                     () =>
            {
                //组装获取实体的sql语句
                var sql = PetaPoco.Sql.Builder;
                sql.Where("OwnerId = @0", ownerId);
                if (needToBuy)
                {
                    sql.Where("Price > 0");
                }
                else
                {
                    sql.Where("Price = 0");
                }

                return sql;
            }
                                     ));
        }
Ejemplo n.º 23
0
        /// <summary>
        /// 获取用户关注照片
        /// </summary>
        /// <param name="userId">用户ID</param>
        /// <param name="pageSize">分页大小</param>
        /// <param name="pageIndex">页码</param>
        /// <returns></returns>
        public PagingDataSet <Photo> GetPhotosOfFollowedUsers(long userId, int pageSize, int pageIndex)
        {
            return(GetPagingEntities(pageSize, pageIndex, CachingExpirationType.ObjectCollection, () =>
            {
                return string.Format("GetFollowerPhotos-{0}", RealTimeCacheHelper.GetListCacheKeyPrefix(CacheVersionType.AreaVersion, "UserId", userId));
            }, () =>
            {
                Sql sql = Sql.Builder;
                sql.Select("spb_Photos.*")
                .From("spb_Photos");
                var whereSql = Sql.Builder;

                sql.InnerJoin("tn_Follows")
                .On("spb_Photos.UserId = tn_Follows.FollowedUserId");
                whereSql.Where("tn_Follows.UserId=@0", userId);

                //添加权限控制
                switch (this.PubliclyAuditStatus)
                {
                case PubliclyAuditStatus.Again:
                case PubliclyAuditStatus.Fail:
                case PubliclyAuditStatus.Pending:
                case PubliclyAuditStatus.Success:
                    whereSql.Where("(spb_Photos.AuditStatus = @0 and spb_Photos.PrivacyStatus <> @1) or spb_Photos.UserId = @2", this.PubliclyAuditStatus, PrivacyStatus.Private, userId);
                    break;

                case PubliclyAuditStatus.Pending_GreaterThanOrEqual:
                case PubliclyAuditStatus.Again_GreaterThanOrEqual:
                    whereSql.Where("(spb_Photos.AuditStatus > @0 and spb_Photos.PrivacyStatus <> @1) or spb_Photos.UserId = @2", this.PubliclyAuditStatus, PrivacyStatus.Private, userId);
                    break;
                }
                sql.Append(whereSql).OrderBy("PhotoId desc");
                return sql;
            }));
        }
Ejemplo n.º 24
0
        /// <summary>
        /// 获取会话下的某条私信之前的20条私信Id(移动端使用)
        /// </summary>
        /// <param name="sessionId">会话Id</param>
        /// <param name="topNumber">某条私信的Id</param>
        public IEnumerable <object> GetMessageIds(long sessionId, long oldMessageId)
        {
            //获取缓存
            StringBuilder cacheKey = new StringBuilder(RealTimeCacheHelper.GetListCacheKeyPrefix(CacheVersionType.AreaVersion, "SessionId", sessionId));

            cacheKey.AppendFormat("oldMessageId-{0}", oldMessageId);

            List <object> messageIds = cacheService.Get <List <object> >(cacheKey.ToString());

            if (messageIds == null)
            {
                //组装sql语句
                var sql = PetaPoco.Sql.Builder;
                if (oldMessageId == -1)
                {
                    sql.Select("MessageId")
                    .From("tn_MessagesInSessions")
                    .Where("SessionId = @0", sessionId)
                    .OrderBy("MessageId desc");
                }
                else
                {
                    sql.Select("MessageId")
                    .From("tn_MessagesInSessions")
                    .Where("SessionId = @0", sessionId)
                    .Where("MessageId < @0", oldMessageId)
                    .OrderBy("MessageId desc");
                }

                messageIds = CreateDAO().FetchTop <long>(SecondaryMaxRecords, sql).Cast <object>().ToList();
                cacheService.Add(cacheKey.ToString(), messageIds, CachingExpirationType.ObjectCollection);
            }

            return(messageIds.Count() > 20 ? messageIds.Take(20) : messageIds);
        }
Ejemplo n.º 25
0
        /// <summary>
        /// 获取拥有者的标签列表
        /// </summary>
        /// <param name="ownerId">拥有者Id</param>
        /// <param name="tenantTypeId">租户类型Id</param>
        public IEnumerable <TagInOwner> GetTagInOwners(long ownerId, string tenantTypeId)
        {
            StringBuilder cacheKey = new StringBuilder(RealTimeCacheHelper.GetListCacheKeyPrefix(CacheVersionType.AreaVersion, "OwnerId", ownerId));

            if (!string.IsNullOrEmpty(tenantTypeId))
            {
                cacheKey.AppendFormat("TenantTypeId-{0}", tenantTypeId);
            }

            List <object> entityIds = cacheService.Get <List <object> >(cacheKey.ToString());

            if (entityIds == null)
            {
                var sql = PetaPoco.Sql.Builder;
                sql.Select("*")
                .From("tn_TagsInOwners")
                .Where("OwnerId = @0", ownerId);

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

                entityIds = CreateDAO().FetchFirstColumn(sql).ToList();
                cacheService.Add(cacheKey.ToString(), entityIds, CachingExpirationType.ObjectCollection);
            }

            return(PopulateEntitiesByEntityIds(entityIds));
        }
        /// <summary>
        /// 用户获取所有提醒设置
        /// </summary>
        /// <param name="userId">用户Id</param>
        /// <returns>用户提醒设置集合(Key:提醒方式Id,Value:提醒设置实体)</returns>
        public Dictionary <string, IEnumerable <UserReminderSettings> > GetAllUserReminderSettings(long userId)
        {
            StringBuilder cacheKey = new StringBuilder(RealTimeCacheHelper.GetListCacheKeyPrefix(CacheVersionType.AreaVersion, "UserId", userId));

            cacheKey.Append("UserReminderSettings");

            IEnumerable <UserReminderSettings> reminderSettingsList = cacheService.Get <IEnumerable <UserReminderSettings> >(cacheKey.ToString());

            if (reminderSettingsList == null)
            {
                var sql = PetaPoco.Sql.Builder;
                sql.Select("*")
                .From("tn_UserReminderSettings")
                .Where("UserId = @0", userId);

                reminderSettingsList = CreateDAO().Fetch <UserReminderSettings>(sql);

                if (reminderSettingsList != null && reminderSettingsList.Count() > 0)
                {
                    cacheService.Add(cacheKey.ToString(), reminderSettingsList, CachingExpirationType.Stable);
                }
            }

            Dictionary <string, IEnumerable <UserReminderSettings> > userReminderSettings = new Dictionary <string, IEnumerable <UserReminderSettings> >();

            if (reminderSettingsList != null && reminderSettingsList.Count() > 0)
            {
                foreach (int modeId in ReminderMode.GetAll().Select(n => n.ModeId))
                {
                    userReminderSettings.Add(modeId.ToString(), reminderSettingsList.Where(n => n.ReminderModeId == modeId).ToList());
                }
            }

            return(userReminderSettings);
        }
Ejemplo n.º 27
0
        /// <summary>
        /// 获取匹配的前N条最热的搜索词(仅非人工干预)
        /// </summary>
        /// <param name="keyword">要匹配的关键字</param>
        /// <param name="topNumber">获取的数据条数</param>
        /// <param name="searchTypeCode">搜索类型编码</param>
        /// <returns>用户最多搜索的前topNumber的搜索词</returns>
        public IEnumerable <SearchedTerm> GetTops(string keyword, int topNumber, string searchTypeCode)
        {
            CountService          countService          = new CountService(TenantTypeIds.Instance().Search());
            StageCountTypeManager stageCountTypeManager = StageCountTypeManager.Instance(TenantTypeIds.Instance().Search());
            int    stageCountDays = stageCountTypeManager.GetMaxDayCount(CountTypes.Instance().SearchCount());
            string countType      = stageCountTypeManager.GetStageCountType(CountTypes.Instance().SearchCount(), stageCountDays);
            string countTableName = countService.GetTableName_Counts();

            return(GetTopEntities(topNumber, CachingExpirationType.ObjectCollection,
                                  () =>
            {
                StringBuilder cacheKey = new StringBuilder(RealTimeCacheHelper.GetListCacheKeyPrefix(CacheVersionType.None));
                cacheKey.AppendFormat("SearchTypeCode-{0}::CountType-{1}::Keyword-{2}", searchTypeCode, countType, keyword);
                return cacheKey.ToString();
            },
                                  () =>
            {
                var sql = Sql.Builder;
                sql.Select("*")
                .From("tn_SearchedTerms")
                .InnerJoin(countTableName)
                .On("tn_SearchedTerms.Id = " + countTableName + ".ObjectId")
                .Where("tn_SearchedTerms.Term like @0", keyword + "%");
                if (!String.IsNullOrEmpty(searchTypeCode))
                {
                    sql.Where("SearchTypeCode = @0", searchTypeCode);
                }
                sql.Where("IsAddedByAdministrator = @0", 0)
                .Where("CountType = @0", countType)
                .Where("OwnerId = @0", 0)
                .OrderBy("StatisticsCount desc");
                return sql;
            }));
        }
Ejemplo n.º 28
0
        /// <summary>
        /// 获取操作Id集合的CacheKey
        /// </summary>
        /// <param name="tenantTypeId"> 租户类型Id</param>
        /// <param name="sortBy">排序类型</param>
        /// <returns></returns>
        private string GetCacheKey_ObjectIds(string tenantTypeId, long userId, int pageIndex)
        {
            StringBuilder cacheKey = new StringBuilder(RealTimeCacheHelper.GetListCacheKeyPrefix(CacheVersionType.AreaVersion, "TenantTypeId", tenantTypeId));

            cacheKey.AppendFormat("GetObjectIds::UserId-{0}:PageIndex-{1}", userId, pageIndex);
            return(cacheKey.ToString());
        }
Ejemplo n.º 29
0
        //已加
        /// <summary>
        /// 获取专题的加入申请列表
        /// </summary>
        /// <param name="topicId">专题Id</param>
        /// <param name="applyStatus">申请状态</param>
        /// <param name="pageSize">每页记录数</param>
        /// <param name="pageIndex">页码</param>
        /// <returns>加入申请分页数据</returns>
        public PagingDataSet <TopicMemberApply> GetTopicMemberApplies(long topicId, TopicMemberApplyStatus?applyStatus, int pageSize, int pageIndex)
        {
            return(GetPagingEntities(pageSize, pageIndex, CachingExpirationType.UsualObjectCollection,
                                     () =>
            {
                StringBuilder cacheKey = new StringBuilder();
                cacheKey.Append(RealTimeCacheHelper.GetListCacheKeyPrefix(CacheVersionType.AreaVersion, "TopicId", topicId));
                cacheKey.Append("TopicMemberApplies");

                //ok



                return cacheKey.ToString();
            },
                                     () =>
            {
                Sql sql = Sql.Builder;
                sql.Select("*")
                .From("spt_TopicMemberApplies")
                .Where("TopicId = @0", topicId);
                if (applyStatus.HasValue)
                {
                    sql.Where("ApplyStatus = @0", applyStatus.Value);
                }
                sql.OrderBy("ApplyStatus asc").OrderBy("ApplyDate desc");
                return sql;
            }));
        }
Ejemplo n.º 30
0
        /// <summary>
        /// 获取用户的前N条私信
        /// </summary>
        /// <param name="userId">私信拥有者Id</param>
        /// <param name="sortBy">私信排序字段</param>
        /// <param name="topNumber">获取的前N条数据</param>
        public IEnumerable <Message> GetTopMessagesOfUser(long userId, SortBy_Message?sortBy, int topNumber)
        {
            return(GetTopEntities(topNumber, CachingExpirationType.ObjectCollection,
                                  () =>
            {
                //获取缓存
                StringBuilder cacheKey = new StringBuilder(RealTimeCacheHelper.GetListCacheKeyPrefix(CacheVersionType.AreaVersion, "ReceiverUserId", userId));
                cacheKey.AppendFormat("SortBy-{0}", (int)sortBy);

                return cacheKey.ToString();
            },
                                  () =>
            {
                var sql = PetaPoco.Sql.Builder;
                sql.Where("ReceiverUserId = @0", userId);
                switch (sortBy)
                {
                case SortBy_Message.IsRead:
                    sql.OrderBy("IsRead asc");
                    sql.OrderBy("MessageId desc");
                    break;

                case SortBy_Message.DateCreated_Desc:
                    sql.OrderBy("MessageId desc");
                    break;
                }

                return sql;
            }));
        }