Example #1
0
        /// <summary>
        /// 从数据库删除实体
        /// </summary>
        /// <param name="entity">标签实体</param>
        /// <returns>影响行数</returns>
        public override int Delete(T entity)
        {
            IList <PetaPoco.Sql> sqls = new List <PetaPoco.Sql>();

            int affectCount      = 0;
            PetaPocoDatabase dao = CreateDAO();

            dao.OpenSharedConnection();

            sqls.Add(PetaPoco.Sql.Builder.Append("delete from tn_Tags where TagId = @0", entity.TagId));
            sqls.Add(PetaPoco.Sql.Builder.Append("delete from tn_ItemsInTags where TagInOwnerId in (Select DISTINCT Id from tn_TagsInOwners where TenantTypeId = @0 and TagName = @1)", entity.TenantTypeId, entity.TagName));
            sqls.Add(PetaPoco.Sql.Builder.Append("delete from tn_TagsInOwners where TenantTypeId = @0 and TagName = @1", entity.TenantTypeId, entity.TagName));
            sqls.Add(PetaPoco.Sql.Builder.Append("delete from tn_TagsInGroups where TenantTypeId = @0 and TagName = @1", entity.TenantTypeId, entity.TagName));

            using (var transaction = dao.GetTransaction())
            {
                affectCount = dao.Execute(sqls);
                transaction.Complete();
            }

            if (affectCount > 0)
            {
                //更新实体缓存
                OnDeleted(entity);
                RealTimeCacheHelper.IncreaseGlobalVersion();
            }

            dao.CloseSharedConnection();

            return(affectCount);
        }
Example #2
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();
        }
Example #3
0
        /// <summary>
        /// 批量更新审核状态
        /// </summary>
        /// <param name="ids">标签Id列表</param>
        /// <param name="isApproved">是否通过审核</param>
        public void UpdateAuditStatus(IEnumerable <long> ids, bool isApproved)
        {
            List <PetaPoco.Sql> sqls = new List <PetaPoco.Sql>();

            foreach (var id in ids)
            {
                var sql = PetaPoco.Sql.Builder;
                sql.Append("UPDATE tn_Tags SET AuditStatus = @0", isApproved ? (int)AuditStatus.Success : (int)AuditStatus.Fail)
                .Where("TagId = @0", id);
                sqls.Add(sql);
            }

            int affectCount = CreateDAO().Execute(sqls);

            //更新缓存版本号
            if (affectCount > 0)
            {
                AuditStatus status = isApproved ? AuditStatus.Success : AuditStatus.Fail;
                foreach (var id in ids)
                {
                    var tag = Get(id);
                    if (tag != null)
                    {
                        tag.AuditStatus = status;
                        RealTimeCacheHelper.IncreaseEntityCacheVersion(id);
                    }
                }

                RealTimeCacheHelper.IncreaseGlobalVersion();
            }
        }
Example #4
0
        /// <summary>
        /// 批量更新审核状态
        /// </summary>
        /// <param name="ids">评论Id列表</param>
        /// <param name="auditingStatus">审核状态</param>
        public void UpdateAuditStatus(IEnumerable <long> ids, AuditStatus auditStatus)
        {
            //声明PetaPoco的SqlBuilder
            var sql = PetaPoco.Sql.Builder;

            //组装sql
            sql.Append("update tn_Categories set AuditStatus =@0", (int)auditStatus)
            .Where("CategoryId in (@ids)", new { ids = ids });

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

            #region 处理缓存

            if (effectLineCount > 0)
            {
                //更新实体缓存
                foreach (long id in ids)
                {
                    T category = Get(id);
                    if (category != null)
                    {
                        category.AuditStatus = auditStatus;
                    }
                    RealTimeCacheHelper.IncreaseEntityCacheVersion(id);
                }

                //处理全局缓存 - 后台管理,需要即时显示
                RealTimeCacheHelper.IncreaseGlobalVersion();
            }
            #endregion
        }
Example #5
0
        /// <summary>
        /// 从站点收件箱移除动态
        /// </summary>
        /// <param name="id"></param>
        public void DeleteFromSiteInbox(long activityId)
        {
            Sql sql = Sql.Builder.Append("delete from tn_ActivitySiteInbox where ActivityId=@0 ", activityId);

            CreateDAO().Execute(sql);

            RealTimeCacheHelper.IncreaseGlobalVersion();
        }
Example #6
0
        /// <summary>
        /// 更新操作
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public bool UpdataCategoryLevel(GoodsCategoryLevel1 entity)
        {
            var result = base.UpdateByCache(entity);

            if (result)
            {
                RealTimeCacheHelper.IncreaseGlobalVersion();
            }
            return(result);
        }
Example #7
0
        /// <summary>
        /// 批量添加敏感词
        /// </summary>
        /// <param name="sensitiveWords">敏感词集合</param>
        public void BatchInsert(List <SensitiveWord> sensitiveWords)
        {
            CreateDAO().OpenSharedConnection();

            IList <Sql> sqls = new List <Sql>();

            IEnumerable <string> existWords = CreateDAO().Fetch <string>(Sql.Builder.Append("select Word from tn_SensitiveWords where Word in (@0)", sensitiveWords.Select(n => n.Word)));

            sensitiveWords = sensitiveWords.Where(n => !existWords.Contains(n.Word)).ToList();
            foreach (var sensitiveWord in sensitiveWords)
            {
                sqls.Add(Sql.Builder.Append("insert into tn_SensitiveWords(Word,Replacement,TypeId) values (@0,@1,@2)", sensitiveWord.Word, sensitiveWord.Replacement, sensitiveWord.TypeId));
            }

            CreateDAO().Execute(sqls);
            RealTimeCacheHelper.IncreaseGlobalVersion();
            CreateDAO().CloseSharedConnection();
        }
 /// <summary>
 /// 添加公告
 /// </summary>
 /// <param name="entity">公告实体</param>
 /// <returns></returns>
 public override object Insert(Announcement entity)
 {
     RealTimeCacheHelper.IncreaseGlobalVersion();
     return(base.Insert(entity));
 }
 /// <summary>
 /// 更新公告
 /// </summary>
 /// <param name="entity">公告实体</param>
 public override void Update(Announcement entity)
 {
     RealTimeCacheHelper.IncreaseGlobalVersion();
     base.Update(entity);
 }
Example #10
0
        /// <summary>
        /// 把fromCategoryId移动到toCategoryId
        /// </summary>
        /// <remarks>
        /// 将一个分类移动到另一个分类,并作为另一个分类的子分类
        /// </remarks>
        /// <param name="fromCategoryId">被移动类别</param>
        /// <param name="toCategoryId">目标类别</param>
        public void Move(long fromCategoryId, long toCategoryId)
        {
            //初始分类实体
            T fromCategory = Get(fromCategoryId);

            //目标分类实体
            T toCategory = Get(toCategoryId);

            IList <PetaPoco.Sql> sqls = new List <PetaPoco.Sql>();

            //1 修改本分类的ParentID
            var sql_UpdateFromCategory = PetaPoco.Sql.Builder;

            sql_UpdateFromCategory.Append("update tn_Categories set ParentId = @0", toCategoryId).Where("CategoryId=@0", fromCategoryId);
            sqls.Add(sql_UpdateFromCategory);

            //2 更新本分类及所有后代分类的Depth
            //获得所有fromCategory的后代Category
            IList <T>       fromChildCategories = new List <T>();
            IEnumerable <T> ownerCategories     = GetOwnerCategories(toCategory.OwnerId, toCategory.TenantTypeId);

            this.RecurseGetChildren(fromCategory, fromChildCategories, ownerCategories.ToList());

            //更新fromCategory的Depth
            int fromCategoryDepth = toCategory.Depth + 1;

            var sql_UpdateFromCategoryDepth = PetaPoco.Sql.Builder;

            sql_UpdateFromCategoryDepth.Append("update tn_Categories set Depth = @0", fromCategoryDepth).Where("CategoryId=@0", fromCategory.CategoryId);
            sqls.Add(sql_UpdateFromCategoryDepth);

            //循环更新fromCategory每一个后代Category的Depth
            foreach (T fromChildCategory in fromChildCategories)
            {
                int fromChildCategoryDepth = fromCategoryDepth + fromChildCategory.Depth - fromCategory.Depth;
                fromChildCategory.Depth = fromChildCategoryDepth;
                var sql_UpdateFromChildCategoryDepth = PetaPoco.Sql.Builder;
                sql_UpdateFromChildCategoryDepth.Append("update tn_Categories set Depth = @0", fromChildCategoryDepth).Where("CategoryId=@0", fromChildCategory.CategoryId);
                sqls.Add(sql_UpdateFromChildCategoryDepth);
            }

            //3 toCategory的ChildCount+1
            var sql_UpdateToCategory = PetaPoco.Sql.Builder;

            sql_UpdateToCategory.Append("update tn_Categories set ChildCount = ChildCount+1 ").Where("CategoryId=@0", toCategoryId);
            sqls.Add(sql_UpdateToCategory);

            //4 fromCategory的Parent的ChildCount-1
            var sql_UpdateFromParentCategory = PetaPoco.Sql.Builder;

            if (fromCategory.ParentId > 0)
            {
                sql_UpdateFromParentCategory.Append("update tn_Categories set ChildCount = ChildCount-1 ").Where("ChildCount > 0 and CategoryId = @0", fromCategory.ParentId);
                sqls.Add(sql_UpdateFromParentCategory);
            }

            //影响的行数
            int effectLineCount = 0;

            PetaPocoDatabase dao = CreateDAO();

            //使用事务
            using (var scope = dao.GetTransaction())
            {
                effectLineCount = dao.Execute(sqls);

                //事务结束
                scope.Complete();
            }

            #region 处理缓存

            if (effectLineCount > 0)
            {
                //单体缓存fromCategory,toCategory,fromParentCategory
                RealTimeCacheHelper.IncreaseEntityCacheVersion(fromCategoryId);
                RealTimeCacheHelper.IncreaseEntityCacheVersion(toCategoryId);
                if (fromCategory.ParentId > 0)
                {
                    RealTimeCacheHelper.IncreaseEntityCacheVersion(fromCategory.ParentId);
                }
                fromCategory.ParentId = toCategory.CategoryId;
                fromCategory.Depth    = toCategory.Depth + 1;

                //列表缓存
                RealTimeCacheHelper.IncreaseAreaVersion("OwnerId", toCategory.OwnerId);     //该用户的缓存
                RealTimeCacheHelper.IncreaseAreaVersion("ParentId", toCategory.ParentId);   //父级分类列表缓存
                RealTimeCacheHelper.IncreaseAreaVersion("ParentId", toCategory.CategoryId); //本级分类列表缓存
                RealTimeCacheHelper.IncreaseAreaVersion("ParentId", fromCategory.CategoryId);

                if (ownerCategories.Count() > 1)
                {
                    foreach (var ownerCategory in ownerCategories)
                    {
                        RealTimeCacheHelper.IncreaseEntityCacheVersion(ownerCategory.CategoryId);
                    }
                }


                //全局缓存
                RealTimeCacheHelper.IncreaseGlobalVersion();

                //处理内容项对应的缓存
                //toCategory以及父级
                List <long> toCategoryParentsIds = new List <long>();
                RecurseGetParents(toCategoryId, toCategoryParentsIds);
                toCategoryParentsIds.Add(toCategoryId);
                foreach (long categoryId in toCategoryParentsIds)
                {
                    EntityData.ForType(typeof(ItemInCategory)).RealTimeCacheHelper.IncreaseAreaVersion("CategoryId", toCategoryId);
                }

                //fromCategory父级
                List <long> fromCategoryParentsIds = new List <long>();
                RecurseGetParents(fromCategoryId, fromCategoryParentsIds);
                foreach (long categoryId in fromCategoryParentsIds)
                {
                    EntityData.ForType(typeof(ItemInCategory)).RealTimeCacheHelper.IncreaseAreaVersion("CategoryId", toCategoryId);
                }
            }
            #endregion
        }
Example #11
0
        /// <summary>
        /// 从fromCategoryId并入到toCategoryId
        /// </summary>
        /// <remarks>
        /// 例如:将分类fromCategoryId合并到分类toCategoryId,那么fromCategoryId分类下的所有子分类和实体全部归到toCategoryId分类,同时删除fromCategoryId分类
        /// </remarks>
        /// <param name="fromCategoryId">源类别</param>
        /// <param name="toCategoryId">目标类别</param>
        public void Merge(long fromCategoryId, long toCategoryId)
        {
            //为处理缓存做准备
            T fromCategory = Get(fromCategoryId);

            #region 组装sql

            //1 将所有的子分类合并到toCategoryId下
            var sql_ChildCategoryUpdate = PetaPoco.Sql.Builder;
            sql_ChildCategoryUpdate.Append("update tn_Categories set ParentId = @0", toCategoryId).Where("ParentId = @0", fromCategoryId);

            //2 将fromCategoryId下的所有直属实体类合并到toCategoryId下
            var sql_ChildItemsUpdate = PetaPoco.Sql.Builder;
            sql_ChildItemsUpdate.Append("update tn_ItemsInCategories set CategoryId = @0", toCategoryId).Where("CategoryId = @0", fromCategoryId);

            //3 更新后代分类深度
            //获得所有fromCategory的后代Category
            T               toCategory          = Get(toCategoryId);
            IList <T>       fromChildCategories = new List <T>();
            IEnumerable <T> ownerCategories     = GetOwnerCategories(toCategory.OwnerId, toCategory.TenantTypeId);
            this.RecurseGetChildren(fromCategory, fromChildCategories, ownerCategories.ToList());

            //循环更新fromCategory每一个后代Category的Depth
            IList <Sql> sql_UpdateFromChildCategoryDepths = new List <Sql>();
            foreach (T fromChildCategory in fromChildCategories)
            {
                int fromChildCategoryDepth = toCategory.Depth + fromChildCategory.Depth - fromCategory.Depth;
                fromChildCategory.Depth = fromChildCategoryDepth;
                sql_UpdateFromChildCategoryDepths.Add(Sql.Builder.Append("update tn_Categories set Depth = @0", fromChildCategoryDepth).Where("CategoryId=@0", fromChildCategory.CategoryId));
            }

            //4 修改toCategory 的属性:ChildCount,ItemCount
            //见下:sql_ToCategoryChildCountUpdate

            //5 最后删除fromCategory
            var sql_FromCategoryDelete = PetaPoco.Sql.Builder;
            sql_FromCategoryDelete.Append("delete tn_Categories").Where("CategoryId = @0", fromCategoryId);

            //6 修改原先from的父级分类的子分类数减一
            var sql_FromParentCategoryChildCountUpdate = PetaPoco.Sql.Builder;
            if (fromCategory.ParentId > 0)
            {
                sql_FromParentCategoryChildCountUpdate.Append("update tn_Categories set ChildCount = ChildCount-1 ").Where("ChildCount > 0 and CategoryId = @0", fromCategory.ParentId);
            }

            #endregion

            int childCategoryCount    = 0 /*子分类数*/,
                childItemCount        = 0 /*内容数*/,
                updateToCategoryCount = 0,
                deleteEffectLineCount = 0,
                affectCount           = 0,
                updateDepthCount      = 0;

            PetaPocoDatabase dao = CreateDAO();
            //在同一个事务中执行
            using (var scope = dao.GetTransaction())
            {
                //1
                childCategoryCount = dao.Execute(sql_ChildCategoryUpdate);
                //2
                childItemCount = dao.Execute(sql_ChildItemsUpdate);
                //3
                var sql_ToCategoryChildCountUpdate = PetaPoco.Sql.Builder;
                sql_ToCategoryChildCountUpdate.Append("update tn_Categories set ChildCount =ChildCount + @0,ItemCount=ItemCount + @1", childCategoryCount, childItemCount).Where("CategoryId = @0", toCategoryId);
                updateToCategoryCount = dao.Execute(sql_ToCategoryChildCountUpdate);
                //4
                updateDepthCount = dao.Execute(sql_UpdateFromChildCategoryDepths);
                //5
                deleteEffectLineCount = dao.Execute(sql_FromCategoryDelete);
                //6
                if (fromCategory.ParentId > 0)
                {
                    affectCount = dao.Execute(sql_FromParentCategoryChildCountUpdate);
                }

                //事务结束
                scope.Complete();
            }

            #region 缓存处理

            //标记删除
            if (deleteEffectLineCount > 0)
            {
                RealTimeCacheHelper.MarkDeletion(fromCategory);
            }

            if (updateToCategoryCount > 0)
            {
                //实体缓存,toCategory
                RealTimeCacheHelper.IncreaseEntityCacheVersion(toCategoryId);

                //处理所有的列表缓存toCategory 相关的列表
                RealTimeCacheHelper.IncreaseAreaVersion("OwnerId", toCategory.OwnerId);
                RealTimeCacheHelper.IncreaseAreaVersion("ParentId", toCategory.CategoryId);

                //处理全局缓存(后台管理)
                RealTimeCacheHelper.IncreaseGlobalVersion();
            }

            if (updateDepthCount > 0 && ownerCategories.Count() > 1)
            {
                foreach (var ownerCategory in ownerCategories)
                {
                    if (ownerCategory.ParentId == fromCategoryId)
                    {
                        ownerCategory.ParentId = toCategoryId;
                    }

                    RealTimeCacheHelper.IncreaseEntityCacheVersion(ownerCategory.CategoryId);
                }
            }

            //处理分类下的内容项的缓存
            if (childItemCount > 0)
            {
                //toCategory以及父级
                List <long> toCategoryParentsIds = new List <long>();
                RecurseGetParents(toCategoryId, toCategoryParentsIds);
                toCategoryParentsIds.Add(toCategoryId);
                foreach (long categoryId in toCategoryParentsIds)
                {
                    EntityData.ForType(typeof(ItemInCategory)).RealTimeCacheHelper.IncreaseAreaVersion("CategoryId", toCategoryId);
                }

                //fromCategory父级
                List <long> fromCategoryParentsIds = new List <long>();
                RecurseGetParents(fromCategoryId, fromCategoryParentsIds);
                foreach (long categoryId in fromCategoryParentsIds)
                {
                    EntityData.ForType(typeof(ItemInCategory)).RealTimeCacheHelper.IncreaseAreaVersion("CategoryId", toCategoryId);
                }
            }

            #endregion
        }