Beispiel #1
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());
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns>影响的记录数</returns>
        public override int Delete(SearchedTerm entity)
        {
            int record = base.Delete(entity);

            RealTimeCacheHelper.IncreaseAreaVersion("SearchTypeCode", entity.SearchTypeCode);
            return(record);
        }
        /// <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;
            }
                                     ));
        }
Beispiel #4
0
        /// <summary>
        /// 移动相片
        /// </summary>
        /// <param name="photo">被移动的照片</param>
        /// <param name="targetAlbum">接收的相册</param>
        /// <returns>是否移动成功</returns>
        public bool MovePhoto(Photo photo, Album targetAlbum)
        {
            AlbumRepository albumRepository = new AlbumRepository();

            if (photo.UserId != targetAlbum.UserId || photo.AlbumId == targetAlbum.AlbumId)
            {
                return(false);
            }

            photo.Album.PhotoCount--;

            //更新原相册数据
            if (photo.Album.CoverId == photo.PhotoId)
            {
                photo.Album.CoverId = 0;
            }

            albumRepository.Update(photo.Album);

            RealTimeCacheHelper.IncreaseAreaVersion("AlbumId", photo.AlbumId);

            //更新照片所属相册以及继承属性
            photo.AlbumId       = targetAlbum.AlbumId;
            photo.TenantTypeId  = targetAlbum.TenantTypeId;
            photo.OwnerId       = targetAlbum.OwnerId;
            photo.PrivacyStatus = targetAlbum.PrivacyStatus;
            Update(photo);


            //更新目标相册
            targetAlbum.PhotoCount++;
            albumRepository.Update(targetAlbum);
            return(true);
        }
Beispiel #5
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));
        }
Beispiel #6
0
        /// <summary>
        /// 从用户收件箱移除动态
        /// </summary>
        /// <param name="userId">用户Id</param>
        /// <param name="activityId">动态Id</param>
        public void DeleteFromUserInbox(long userId, long activityId)
        {
            Sql sql = Sql.Builder.Append("delete from tn_ActivityUserInbox where UserId=@0 and ActivityId=@1 ", userId, activityId);

            CreateDAO().Execute(sql);
            RealTimeCacheHelper.IncreaseAreaVersion("UserId", userId);
        }
Beispiel #7
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));
        }
        /// <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());
        }
        /// <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);
        }
        /// <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);
        }
        /// <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);
        }
Beispiel #12
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;
            }
                                     ));
        }
Beispiel #13
0
        /// <summary>
        /// 更新隐私规则
        /// </summary>
        /// <param name="privacyItems">待更新的隐私项目规则集合</param>
        public void UpdatePrivacyItems(IEnumerable <PrivacyItem> privacyItems)
        {
            if (privacyItems == null)
            {
                return;
            }
            List <Sql> sqls = new List <Sql>();

            Database dao = CreateDAO();

            dao.OpenSharedConnection();
            foreach (var privacyItem in privacyItems)
            {
                sqls.Add(Sql.Builder.Append("update tn_PrivacyItems")
                         .Append("set ItemName = @0, Description = @1, DisplayOrder = @2, PrivacyStatus = @3", privacyItem.ItemName, privacyItem.Description, privacyItem.DisplayOrder, privacyItem.PrivacyStatus)
                         .Append("where ItemKey = @0 and ItemGroupId = @1 and ApplicationId = @2", privacyItem.ItemKey, privacyItem.ItemGroupId, privacyItem.ApplicationId));

                RealTimeCacheHelper.IncreaseEntityCacheVersion(privacyItem.ItemKey);
                OnUpdated(privacyItem);
            }
            dao.Execute(sqls);
            //done:zhangp,by zhengw:需要递增全局版本号
            dao.CloseSharedConnection();

            RealTimeCacheHelper.IncreaseGlobalVersion();
        }
Beispiel #14
0
        /// <summary>
        /// 删除分类同内容的关联项
        /// </summary>
        /// <param name="categoryId">分类Id</param>
        /// <param name="itemId">内容项Id</param>
        /// <param name="ownerId">拥有者Id</param>
        public int DeleteItemInCategory(long categoryId, long itemId, long ownerId)
        {
            //声明PetaPoco的SqlBuilder
            var sql = PetaPoco.Sql.Builder;

            //组装sql
            sql.Append("delete tn_ItemsInCategories  where CategoryId=@0 and ItemId=@1", categoryId, itemId);


            //执行语句
            int effectLineCount = CreateDAO().Execute(sql);

            #region 处理缓存

            if (effectLineCount > 0)
            {
                //ItemId分区缓存
                RealTimeCacheHelper.IncreaseAreaVersion("ItemId", itemId);
                //本分区缓存,作用是:供其他服务或者应用来更新缓存
                RealTimeCacheHelper.IncreaseAreaVersion("OwnerId", ownerId);
                //CategoryId分区缓存
                RealTimeCacheHelper.IncreaseAreaVersion("CategoryId", categoryId);
            }
            #endregion

            return(effectLineCount);
        }
Beispiel #15
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;
            }));
        }
        /// <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);
        }
Beispiel #17
0
        /// <summary>
        /// 取消关注后更新缓存
        /// </summary>
        /// <param name="sender">关注实体</param>
        /// <param name="eventArgs">事件参数</param>
        void CancelFollowEventModule_After(FollowEntity sender, CommonEventArgs eventArgs)
        {
            if (eventArgs.EventOperationType == EventOperationType.Instance().Delete())
            {
                CategoryService service = new CategoryService();
                service.ClearCategoriesFromItem(sender.Id, sender.UserId, TenantTypeIds.Instance().User());

                //更新用户缓存
                ICacheService       cacheService        = DIContainer.Resolve <ICacheService>();
                RealTimeCacheHelper realTimeCacheHelper = EntityData.ForType(typeof(User)).RealTimeCacheHelper;
                if (cacheService.EnableDistributedCache)
                {
                    realTimeCacheHelper.IncreaseEntityCacheVersion(sender.UserId);
                }
                else
                {
                    string cacheKey = realTimeCacheHelper.GetCacheKeyOfEntity(sender.UserId);
                    User   user     = cacheService.Get <User>(cacheKey);
                    if (user != null && user.FollowedCount > 0)
                    {
                        user.FollowedCount--;
                    }
                }
            }
        }
Beispiel #18
0
        /// <summary>
        /// 创建ContentItem
        /// </summary>
        /// <param name="contentItem"></param>
        /// <returns></returns>
        public override object Insert(ContentItem contentItem)
        {
            base.Insert(contentItem);

            ContentTypeDefinition contentType = contentItem.ContentType;

            if (contentType != null)
            {
                List <Sql> sqls = new List <Sql>();

                StringBuilder sqlBuilder = new StringBuilder();
                List <object> values     = new List <object>();

                sqlBuilder.AppendFormat("INSERT INTO {0} (", contentType.TableName);

                int columnIndex = 0;

                sqlBuilder.Append(contentType.ForeignKey);
                values.Add(contentItem.ContentItemId);

                foreach (var column in contentType.Columns)
                {
                    if (contentType.ForeignKey == column.ColumnName)
                    {
                        continue;
                    }

                    if (contentItem.AdditionalProperties.Keys.Contains(column.ColumnName))
                    {
                        columnIndex++;
                        sqlBuilder.Append("," + column.ColumnName);
                        if (contentItem.AdditionalProperties[column.ColumnName] == null)
                        {
                            values.Add(column.DefaultValue);
                        }
                        else
                        {
                            values.Add(contentItem.AdditionalProperties[column.ColumnName]);
                        }
                    }
                    else
                    {
                        sqlBuilder.Append("," + column.ColumnName);
                        values.Add(column.DefaultValue);
                    }
                }
                sqlBuilder.Append(")");

                sqls.Add(Sql.Builder.Append(sqlBuilder.Append("values (@0)").ToString(), values));
                sqls.Add(Sql.Builder.Append("UPDATE spb_cms_ContentFolders SET ContentItemCount=ContentItemCount+1 WHERE ContentFolderId=@0", contentItem.ContentFolderId));

                CreateDAO().Execute(sqls);
            }

            string cacheKey = "ContentItemAP:" + RealTimeCacheHelper.GetCacheKeyOfEntity(contentItem.ContentItemId);

            cacheService.Remove(cacheKey);

            return(contentItem.ContentItemId);
        }
Beispiel #19
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);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public override object Insert(RecommendItemType entity)
        {
            object typeId = base.Insert(entity);

            RealTimeCacheHelper.IncreaseAreaVersion("TenantTypeId", string.Empty);
            return(typeId);
        }
Beispiel #21
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;
            }));
        }
Beispiel #22
0
        /// <summary>
        /// 删除标签与成员的关系实体
        /// </summary>
        /// <param name="entity">待处理的实体</param>
        /// <returns></returns>
        public override int Delete(ItemInTag entity)
        {
            PetaPocoDatabase dao = CreateDAO();

            dao.OpenSharedConnection();

            int affectCount = base.Delete(entity);

            if (entity != null && affectCount > 0)
            {
                List <Sql> sqls = new List <Sql>();
                sqls.Add(Sql.Builder.Append("update tn_TagsInOwners set ItemCount = ItemCount - 1")
                         .Where("ItemCount > 0 and Id = @0", entity.TagInOwnerId));
                sqls.Add(Sql.Builder.Append("update tn_Tags set ItemCount = ItemCount - 1")
                         .Where("ItemCount > 0 and TagName = @0 and TenantTypeId = @1", entity.TagName, entity.TenantTypeId));

                affectCount = dao.Execute(sqls);

                RealTimeCacheHelper.IncreaseAreaVersion("TagName", entity.TagName);
                RealTimeCacheHelper.IncreaseAreaVersion("ItemId", entity.ItemId);
            }

            dao.CloseSharedConnection();

            return(affectCount);
        }
Beispiel #23
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;
            }));
        }
Beispiel #24
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);
        }
Beispiel #25
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;
            }));
        }
Beispiel #26
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;
            }));
        }
        /// <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;
            }));
        }
Beispiel #28
0
        /// <summary>
        ///  删除用户发布的评论
        /// </summary>
        /// <remarks>
        /// 供用户删除时处理用户相关信息时调用
        /// </remarks>
        /// <param name="userId">UserId</param>
        /// <param name="reserveCommnetsAsAnonymous">true=保留用户发布的评论,但是修改为匿名用户;false=直接删除评论</param>
        /// <returns></returns>
        public int DeleteUserComments(long userId, bool reserveCommnetsAsAnonymous)
        {
            var sql = PetaPoco.Sql.Builder;

            if (reserveCommnetsAsAnonymous)
            {
                sql.Append("UPDATE tn_Comments  SET UserId=0");
            }
            else
            {
                sql.Append("DELETE FROM tn_Comments ");
            }

            sql.Where("UserId=@0", userId);
            int rows = CreateDAO().Execute(sql);

            #region 处理缓存
            if (rows > 0)
            {
                RealTimeCacheHelper.IncreaseAreaVersion("UserId", userId);
            }
            #endregion

            return(rows);
        }
Beispiel #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;
            }));
        }
Beispiel #30
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());
        }