/// <summary> /// 删除垃圾数据 /// </summary> /// <param name="serviceKey">服务标识</param> public void DeleteTrashDatas() { IEnumerable <TenantType> tenantTypes = new TenantTypeService().Gets(MultiTenantServiceKeys.Instance().Attachment()); List <Sql> sqls = new List <Sql>(); sqls.Add(Sql.Builder.Append("delete from tn_AttachmentDownloadRecords where not exists (select 1 from tn_Users where UserId = tn_AttachmentDownloadRecords.UserId)")); sqls.Add(Sql.Builder.Append("update tn_Attachments set AssociateId = 0,UserId = 0,OwnerId = 0") .Where("not exists (select 1 from tn_Users where tn_Attachments.UserId = UserId)")); foreach (var tenantType in tenantTypes) { Type type = Type.GetType(tenantType.ClassType); if (type == null) { continue; } var pd = PetaPoco.Database.PocoData.ForType(type); sqls.Add(Sql.Builder.Append("update tn_Attachments set AssociateId = 0,UserId = 0,OwnerId = 0") .Where("not exists (select 1 from " + pd.TableInfo.TableName + " where tn_Attachments.AssociateId = " + pd.TableInfo.PrimaryKey + ") and TenantTypeId = @0" , tenantType.TenantTypeId)); sqls.Add(Sql.Builder.Append("delete from tn_AttachmentDownloadRecords") .Where("not exists (select 1 from " + pd.TableInfo.TableName + " where AssociateId = " + pd.TableInfo.PrimaryKey + ") and TenantTypeId = @0" , tenantType.TenantTypeId)); } CreateDAO().Execute(sqls); }
/// <summary> /// 删除垃圾数据 /// </summary> /// <param name="serviceKey">服务标识</param> public void DeleteTrashDatas() { IEnumerable <TenantType> tenantTypes = new TenantTypeService().Gets(MultiTenantServiceKeys.Instance().Attitude()); List <Sql> sqls = new List <Sql>(); sqls.Add(Sql.Builder.Append("delete from tn_AttitudeRecords where not exists (select 1 from tn_Users where UserId = tn_AttitudeRecords.UserId)")); foreach (var tenantType in tenantTypes) { Type type = Type.GetType(tenantType.ClassType); if (type == null) { continue; } var pd = TableInfo.FromPoco(type); sqls.Add(Sql.Builder.Append("delete from tn_Attitudes") .Where("not exists (select 1 from " + pd.TableName + " where ObjectId = " + pd.PrimaryKey + ") and TenantTypeId = @0" , tenantType.TenantTypeId)); sqls.Add(Sql.Builder.Append("delete from tn_AttitudeRecords") .Where("not exists (select 1 from " + pd.TableName + " where ObjectId = " + pd.PrimaryKey + ") and TenantTypeId = @0" , tenantType.TenantTypeId)); } CreateDAO().Execute(sqls); }
/// <summary> /// 任务执行的内容 /// </summary> /// <param name="taskDetail">任务配置状态信息</param> public void Execute(TaskDetail taskDetail) { new AttitudeRepository().DeleteTrashDatas(); new FavoriteRepository().DeleteTrashDatas(MultiTenantServiceKeys.Instance().Favorites()); new FavoriteRepository().DeleteTrashDatas(MultiTenantServiceKeys.Instance().Subscribe()); new AttachmentRepository <Attachment>().DeleteTrashDatas(); new AtUserRepository().DeleteTrashDatas(); new TagRepository <Tag>().DeleteTrashDatas(); new CommentRepository().DeleteTrashDatas(); new CountRepository().DeleteTrashCount(); }
/// <summary> /// 删除垃圾数据 /// </summary> public void DeleteTrashCount() { TenantTypeService tenantTypeService = new TenantTypeService(); IEnumerable <TenantType> tenantTypes = tenantTypeService.Gets(MultiTenantServiceKeys.Instance().Count()); List <Sql> sqls = new List <Sql>(); foreach (var tenantType in tenantTypes) { Type type = Type.GetType(tenantType.ClassType); if (type == null) { continue; } var pd = TableInfo.FromPoco(type); sqls.Add(Sql.Builder.Append("delete from " + GetTableName_Counts(tenantType.TenantTypeId)) .Where("not exists (select 1 from " + pd.TableName + " where ObjectId = " + pd.PrimaryKey + ")")); } CreateDAO().Execute(sqls); }