Эх сурвалжийг харах

修复套餐服务添加租户和移除租户没有清除租户下所有用户权限缓存的问题
修复租户服务修改租户套餐没有清除租户下所有用户权限缓存的问题
废弃权限服务PermissionService.GetTenantPermissionListAsync和SaveTenantPermissionsAsync接口

zhontai 2 жил өмнө
parent
commit
37ae6c8851

+ 3 - 0
src/hosts/ZhonTai.Host/Configs/dbconfig.json

@@ -36,8 +36,11 @@
   "sysUpdateData": false,
   //同步数据地址
   //"SyncDataPath": "InitData/Admin/Vue2",
+  //同步所有表["ad_dict_type", "ad_dict", "ad_user",  "ad_user_staff", "ad_org", "ad_role", "ad_api", "ad_view", "ad_permission", "ad_permission_api", "ad_user_role", "ad_user_org", "ad_role_permission", "ad_tenant", "ad_tenant_permission"]
+  //同步指定表["ad_api", "ad_view", "ad_permission", "ad_permission_api"]
   //同步数据包含表,指定表同步,不填同步所有表
   "syncDataIncludeTables": [],
+  //同步排除表["ad_user"]
   //同步数据排除表,指定表不同步
   "syncDataExcludeTables": [],
 

+ 3 - 2
src/platform/ZhonTai.Admin/Core/Db/Data/SyncData.cs

@@ -104,8 +104,9 @@ public abstract class SyncData
         }
         catch (Exception ex)
         {
-            Console.WriteLine($"table: {tableName} sync data failed.\n{ex.Message}");
-            throw;
+            var msg = $"table: {tableName} sync data failed.\n{ex.Message}";
+            Console.WriteLine(msg);
+            throw new Exception(msg);
         }
     }
 

+ 60 - 59
src/platform/ZhonTai.Admin/Repositories/CustomSyncData.cs

@@ -70,7 +70,7 @@ public class CustomSyncData : SyncData, ISyncData
             }
 
             //修改
-            if (recordList?.Count > 0)
+            if (!dbConfig.SysUpdateData && recordList?.Count > 0)
             {
                 var updateDataList = dataList.Where(a => recordIds.Contains(a.Id));
                 await rep.UpdateAsync(updateDataList);
@@ -80,8 +80,9 @@ public class CustomSyncData : SyncData, ISyncData
         }
         catch (Exception ex)
         {
-            Console.WriteLine($"table: {tableName} sync data failed.\n{ex.Message}");
-            throw;
+            var msg = $"table: {tableName} sync data failed.\n{ex.Message}";
+            Console.WriteLine(msg);
+            throw new Exception(msg);
         }
     }
 
@@ -127,7 +128,7 @@ public class CustomSyncData : SyncData, ISyncData
             }
 
             //修改
-            if (recordList?.Count > 0)
+            if (!dbConfig.SysUpdateData && recordList?.Count > 0)
             {
                 var updateDataList = dataList.Where(a => recordIds.Contains(a.Id));
                 await rep.UpdateAsync(updateDataList);
@@ -137,8 +138,9 @@ public class CustomSyncData : SyncData, ISyncData
         }
         catch (Exception ex)
         {
-            Console.WriteLine($"table: {tableName} sync data failed.\n{ex.Message}");
-            throw;
+            var msg = $"table: {tableName} sync data failed.\n{ex.Message}";
+            Console.WriteLine(msg);
+            throw new Exception(msg);
         }
     }
 
@@ -185,7 +187,7 @@ public class CustomSyncData : SyncData, ISyncData
             }
 
             //修改
-            if (recordList?.Count > 0)
+            if (!dbConfig.SysUpdateData && recordList?.Count > 0)
             {
                 var updateDataList = dataList.Where(a => recordIds.Contains(a.Id));
                 await rep.UpdateAsync(updateDataList);
@@ -195,8 +197,9 @@ public class CustomSyncData : SyncData, ISyncData
         }
         catch (Exception ex)
         {
-            Console.WriteLine($"table: {tableName} sync data failed.\n{ex.Message}");
-            throw;
+            var msg = $"table: {tableName} sync data failed.\n{ex.Message}";
+            Console.WriteLine(msg);
+            throw new Exception(msg);
         }
     }
 
@@ -243,7 +246,7 @@ public class CustomSyncData : SyncData, ISyncData
             }
 
             //修改
-            if (recordList?.Count > 0)
+            if (!dbConfig.SysUpdateData && recordList?.Count > 0)
             {
                 var updateDataList = dataList.Where(a => recordIds.Contains(a.Id));
                 await rep.UpdateAsync(updateDataList);
@@ -253,8 +256,9 @@ public class CustomSyncData : SyncData, ISyncData
         }
         catch (Exception ex)
         {
-            Console.WriteLine($"table: {tableName} sync data failed.\n{ex.Message}");
-            throw;
+            var msg = $"table: {tableName} sync data failed.\n{ex.Message}";
+            Console.WriteLine(msg);
+            throw new Exception(msg);
         }
     }
 
@@ -302,7 +306,7 @@ public class CustomSyncData : SyncData, ISyncData
             }
 
             //修改
-            if (recordList?.Count > 0)
+            if (!dbConfig.SysUpdateData && recordList?.Count > 0)
             {
                 var updateDataList = dataList.Where(a => recordIds.Contains(a.Id));
                 await rep.UpdateAsync(updateDataList);
@@ -312,8 +316,9 @@ public class CustomSyncData : SyncData, ISyncData
         }
         catch (Exception ex)
         {
-            Console.WriteLine($"table: {tableName} sync data failed.\n{ex.Message}");
-            throw;
+            var msg = $"table: {tableName} sync data failed.\n{ex.Message}";
+            Console.WriteLine(msg);
+            throw new Exception(msg);
         }
     }
 
@@ -360,7 +365,7 @@ public class CustomSyncData : SyncData, ISyncData
             }
 
             //修改
-            if (recordList?.Count > 0)
+            if (!dbConfig.SysUpdateData && recordList?.Count > 0)
             {
                 var updateDataList = dataList.Where(a => recordIds.Contains(a.Id));
                 await rep.UpdateAsync(updateDataList);
@@ -370,8 +375,9 @@ public class CustomSyncData : SyncData, ISyncData
         }
         catch (Exception ex)
         {
-            Console.WriteLine($"table: {tableName} sync data failed.\n{ex.Message}");
-            throw;
+            var msg = $"table: {tableName} sync data failed.\n{ex.Message}";
+            Console.WriteLine(msg);
+            throw new Exception(msg);
         }
     }
 
@@ -418,7 +424,7 @@ public class CustomSyncData : SyncData, ISyncData
             }
 
             //修改
-            if (recordList?.Count > 0)
+            if (!dbConfig.SysUpdateData && recordList?.Count > 0)
             {
                 var updateDataList = dataList.Where(a => recordIds.Contains(a.Id));
                 await rep.UpdateAsync(updateDataList);
@@ -428,8 +434,9 @@ public class CustomSyncData : SyncData, ISyncData
         }
         catch (Exception ex)
         {
-            Console.WriteLine($"table: {tableName} sync data failed.\n{ex.Message}");
-            throw;
+            var msg = $"table: {tableName} sync data failed.\n{ex.Message}";
+            Console.WriteLine(msg);
+            throw new Exception(msg);
         }
     }
 
@@ -476,7 +483,7 @@ public class CustomSyncData : SyncData, ISyncData
             }
 
             //修改
-            if (recordList?.Count > 0)
+            if (!dbConfig.SysUpdateData && recordList?.Count > 0)
             {
                 var updateDataList = dataList.Where(a => recordIds.Contains(a.Id));
                 await rep.UpdateAsync(updateDataList);
@@ -486,8 +493,9 @@ public class CustomSyncData : SyncData, ISyncData
         }
         catch (Exception ex)
         {
-            Console.WriteLine($"table: {tableName} sync data failed.\n{ex.Message}");
-            throw;
+            var msg = $"table: {tableName} sync data failed.\n{ex.Message}";
+            Console.WriteLine(msg);
+            throw new Exception(msg);
         }
     }
 
@@ -534,7 +542,7 @@ public class CustomSyncData : SyncData, ISyncData
             }
 
             //修改
-            if (recordList?.Count > 0)
+            if (!dbConfig.SysUpdateData && recordList?.Count > 0)
             {
                 var updateDataList = dataList.Where(a => recordIds.Contains(a.Id));
                 await rep.UpdateAsync(updateDataList);
@@ -544,8 +552,9 @@ public class CustomSyncData : SyncData, ISyncData
         }
         catch (Exception ex)
         {
-            Console.WriteLine($"table: {tableName} sync data failed.\n{ex.Message}");
-            throw;
+            var msg = $"table: {tableName} sync data failed.\n{ex.Message}";
+            Console.WriteLine(msg);
+            throw new Exception(msg);
         }
     }
 
@@ -582,7 +591,7 @@ public class CustomSyncData : SyncData, ISyncData
             var recordList = await rep.Where(a => rep.Select.WithMemory(dataList).Where(b => b.PermissionId == a.PermissionId && b.ApiId == a.ApiId).Any()).ToListAsync();
 
             //新增
-            var insertDataList = dataList.Where(a => !recordList.Where(b => a.PermissionId == b.PermissionId && a.ApiId == b.ApiId).Any()).ToList();
+            var insertDataList = dataList.Where(a => !(recordList.Where(b => a.PermissionId == b.PermissionId && a.ApiId == b.ApiId).Any())).ToList();
             if (insertDataList.Any())
             {
                 await rep.InsertAsync(insertDataList);
@@ -592,8 +601,9 @@ public class CustomSyncData : SyncData, ISyncData
         }
         catch (Exception ex)
         {
-            Console.WriteLine($"table: {tableName} sync data failed.\n{ex.Message}");
-            throw;
+            var msg = $"table: {tableName} sync data failed.\n{ex.Message}";
+            Console.WriteLine(msg);
+            throw new Exception(msg);
         }
     }
 
@@ -638,7 +648,7 @@ public class CustomSyncData : SyncData, ISyncData
             var recordList = await rep.Where(a => rep.Orm.Select<UserRoleRecord>().WithMemory(userRoleRecordList).Where(b => b.UserId == a.UserId && b.RoleId == a.RoleId).Any()).ToListAsync();
 
             //新增
-            var insertDataList = dataList.Where(a => !recordList.Where(b => a.UserId == b.UserId && a.RoleId == b.RoleId).Any()).ToList();
+            var insertDataList = dataList.Where(a => !(recordList.Where(b => a.UserId == b.UserId && a.RoleId == b.RoleId).Any())).ToList();
             if (insertDataList.Any())
             {
                 await rep.InsertAsync(insertDataList);
@@ -648,8 +658,9 @@ public class CustomSyncData : SyncData, ISyncData
         }
         catch (Exception ex)
         {
-            Console.WriteLine($"table: {tableName} sync data failed.\n{ex.Message}");
-            throw;
+            var msg = $"table: {tableName} sync data failed.\n{ex.Message}";
+            Console.WriteLine(msg);
+            throw new Exception(msg);
         }
     }
 
@@ -694,7 +705,7 @@ public class CustomSyncData : SyncData, ISyncData
             var recordList = await rep.Where(a => rep.Orm.Select<UserOrgRecord>().WithMemory(userOrgRecordList).Where(b => b.UserId == a.UserId && b.OrgId == a.OrgId).Any()).ToListAsync();
 
             //新增
-            var insertDataList = dataList.Where(a => !recordList.Where(b => a.UserId == b.UserId && a.OrgId == b.OrgId).Any()).ToList();
+            var insertDataList = dataList.Where(a => !(recordList.Where(b => a.UserId == b.UserId && a.OrgId == b.OrgId).Any())).ToList();
             if (insertDataList.Any())
             {
                 await rep.InsertAsync(insertDataList);
@@ -704,8 +715,9 @@ public class CustomSyncData : SyncData, ISyncData
         }
         catch (Exception ex)
         {
-            Console.WriteLine($"table: {tableName} sync data failed.\n{ex.Message}");
-            throw;
+            var msg = $"table: {tableName} sync data failed.\n{ex.Message}";
+            Console.WriteLine(msg);
+            throw new Exception(msg);
         }
     }
 
@@ -750,7 +762,7 @@ public class CustomSyncData : SyncData, ISyncData
             var recordList = await rep.Where(a => rep.Orm.Select<RolePermissionRecord>().WithMemory(rolePermissionRecordList).Where(b => b.RoleId == a.RoleId && b.PermissionId == a.PermissionId).Any()).ToListAsync();
 
             //新增
-            var insertDataList = dataList.Where(a => !recordList.Where(b => a.RoleId == b.RoleId && a.PermissionId == b.PermissionId).Any()).ToList();
+            var insertDataList = dataList.Where(a => !(recordList.Where(b => a.RoleId == b.RoleId && a.PermissionId == b.PermissionId).Any())).ToList();
             if (insertDataList.Any())
             {
                 await rep.InsertAsync(insertDataList);
@@ -760,8 +772,9 @@ public class CustomSyncData : SyncData, ISyncData
         }
         catch (Exception ex)
         {
-            Console.WriteLine($"table: {tableName} sync data failed.\n{ex.Message}");
-            throw;
+            var msg = $"table: {tableName} sync data failed.\n{ex.Message}";
+            Console.WriteLine(msg);
+            throw new Exception(msg);
         }
     }
 
@@ -807,7 +820,7 @@ public class CustomSyncData : SyncData, ISyncData
             }
 
             //修改
-            if (recordList?.Count > 0)
+            if (!dbConfig.SysUpdateData && recordList?.Count > 0)
             {
                 var updateDataList = dataList.Where(a => recordIds.Contains(a.Id));
                 await rep.UpdateAsync(updateDataList);
@@ -817,8 +830,9 @@ public class CustomSyncData : SyncData, ISyncData
         }
         catch (Exception ex)
         {
-            Console.WriteLine($"table: {tableName} sync data failed.\n{ex.Message}");
-            throw;
+            var msg = $"table: {tableName} sync data failed.\n{ex.Message}";
+            Console.WriteLine(msg);
+            throw new Exception(msg);
         }
     }
 
@@ -863,7 +877,7 @@ public class CustomSyncData : SyncData, ISyncData
             var recordList = await rep.Where(a => rep.Orm.Select<TenantPermissionRecord>().WithMemory(tenantPermissionRecordList).Where(b => b.TenantId == a.TenantId && b.PermissionId == a.PermissionId).Any()).ToListAsync();
 
             //新增
-            var insertDataList = dataList.Where(a => !recordList.Where(b => a.TenantId == b.TenantId && a.PermissionId == b.PermissionId).Any()).ToList();
+            var insertDataList = dataList.Where(a => !(recordList.Where(b => a.TenantId == b.TenantId && a.PermissionId == b.PermissionId).Any())).ToList();
             if (insertDataList.Any())
             {
                 await rep.InsertAsync(insertDataList);
@@ -873,8 +887,9 @@ public class CustomSyncData : SyncData, ISyncData
         }
         catch (Exception ex)
         {
-            Console.WriteLine($"table: {tableName} sync data failed.\n{ex.Message}");
-            throw;
+            var msg = $"table: {tableName} sync data failed.\n{ex.Message}";
+            Console.WriteLine(msg);
+            throw new Exception(msg);
         }
     }
 
@@ -894,33 +909,19 @@ public class CustomSyncData : SyncData, ISyncData
             var isTenant = appConfig.Tenant;
 
             await InitDictTypeAsync(db, unitOfWork, dbConfig);
-
             await InitDictAsync(db, unitOfWork, dbConfig);
-
             await InitUserAsync(db, unitOfWork, dbConfig, isTenant);
-
             await InitUserStaffAsync(db, unitOfWork, dbConfig, isTenant);
-
             await InitOrgAsync(db, unitOfWork, dbConfig, isTenant);
-
             await InitRoleAsync(db, unitOfWork, dbConfig, isTenant);
-
             await InitApiAsync(db, unitOfWork, dbConfig);
-
             await InitViewAsync(db, unitOfWork, dbConfig);
-
             await InitPermissionAsync(db, unitOfWork, dbConfig);
-
             await InitPermissionApiAsync(db, unitOfWork, dbConfig);
-
             await InitUserRoleAsync(db, unitOfWork, dbConfig);
-
             await InitUserOrgAsync(db, unitOfWork, dbConfig);
-
             await InitRolePermissionAsync(db, unitOfWork, dbConfig);
-
             await InitTenantAsync(db, unitOfWork, dbConfig);
-
             await InitTenantPermissionAsync(db, unitOfWork, dbConfig);
 
             unitOfWork.Commit();

+ 3 - 1
src/platform/ZhonTai.Admin/Services/Permission/PermissionService.cs

@@ -191,7 +191,8 @@ public class PermissionService : BaseService, IPermissionService, IDynamicApi
     /// </summary>
     /// <param name="tenantId"></param>
     /// <returns></returns>
-    public async Task<List<long>> GetTenantPermissionList(long tenantId)
+    [Obsolete("请使用查询套餐权限列表PkgService.GetPkgPermissionListAsync")]
+    public async Task<List<long>> GetTenantPermissionListAsync(long tenantId)
     {
         var permissionIds = await _tenantPermissionRepository
             .Select.Where(d => d.TenantId == tenantId)
@@ -467,6 +468,7 @@ public class PermissionService : BaseService, IPermissionService, IDynamicApi
     /// <param name="input"></param>
     /// <returns></returns>
     [AdminTransaction]
+    [Obsolete("请使用设置套餐权限PkgService.SetPkgPermissionsAsync")]
     public virtual async Task SaveTenantPermissionsAsync(PermissionSaveTenantPermissionsInput input)
     {
         //查询租户权限

+ 37 - 37
src/platform/ZhonTai.Admin/Services/Pkg/PkgService.cs

@@ -36,6 +36,24 @@ public class PkgService : BaseService, IDynamicApi
     {
     }
 
+    /// <summary>
+    /// 清除租户下所有用户权限缓存
+    /// </summary>
+    /// <param name="tenantIds"></param>
+    [NonAction]
+    public async Task ClearUserPermissionsAsync(List<long> tenantIds)
+    {
+        using var _ = _userRepository.DataFilter.Disable(FilterNames.Tenant);
+        var userIds = await _userRepository.Select.Where(a => tenantIds.Contains(a.TenantId.Value)).ToListAsync(a => a.Id);
+        if (userIds.Any())
+        {
+            foreach (var userId in userIds)
+            {
+                await Cache.DelAsync(CacheKeys.UserPermissions + userId);
+            }
+        }
+    }
+
     /// <summary>
     /// 查询
     /// </summary>
@@ -144,7 +162,7 @@ public class PkgService : BaseService, IDynamicApi
     /// </summary>
     /// <param name="pkgId">套餐编号</param>
     /// <returns></returns>
-    public async Task<List<long>> GetPkgPermissionList(long pkgId)
+    public async Task<List<long>> GetPkgPermissionListAsync(long pkgId)
     {
         var permissionIds = await _pkgPermissionRepository
             .Select.Where(d => d.PkgId == pkgId)
@@ -190,17 +208,10 @@ public class PkgService : BaseService, IDynamicApi
             await _pkgPermissionRepository.InsertAsync(pkgPermissions);
         }
 
-        //清除套餐下所有用户权限缓存
+        
         var tenantIds = await _tenantPkgRepository.Select.Where(a => a.PkgId == input.PkgId).ToListAsync(a => a.TenantId);
-        using var _ = _userRepository.DataFilter.Disable(FilterNames.Tenant);
-        var userIds = await _userRepository.Select.Where(a => tenantIds.Contains(a.TenantId.Value)).ToListAsync(a => a.Id);
-        if (userIds.Any())
-        {
-            foreach (var userId in userIds)
-            {
-                await Cache.DelAsync(CacheKeys.UserPermissions + userId);
-            }
-        }
+        //清除租户下所有用户权限缓存
+        await ClearUserPermissionsAsync(tenantIds);
     }
 
     /// <summary>
@@ -221,12 +232,9 @@ public class PkgService : BaseService, IDynamicApi
                 PkgId = pkgId 
             }).ToList();
             await _tenantPkgRepository.InsertAsync(tenantPkgList);
-        }
 
-        var clearTenantIds = tenantIds.Concat(input.TenantIds).Distinct();
-        foreach (var tenantId in clearTenantIds)
-        {
-            await Cache.DelAsync(CacheKeys.DataPermission + tenantId);
+            //清除租户下所有用户权限缓存
+            await ClearUserPermissionsAsync(insertTenantIds.ToList());
         }
     }
 
@@ -242,11 +250,9 @@ public class PkgService : BaseService, IDynamicApi
         if (tenantIds != null && tenantIds.Any())
         {
             await _tenantPkgRepository.Where(a => a.PkgId == input.PkgId && input.TenantIds.Contains(a.TenantId)).ToDelete().ExecuteAffrowsAsync();
-        }
 
-        foreach (var tenantId in tenantIds)
-        {
-            await Cache.DelAsync(CacheKeys.DataPermission + tenantId);
+            //清除租户下所有用户权限缓存
+            await ClearUserPermissionsAsync(tenantIds.ToList());
         }
     }
 
@@ -329,11 +335,9 @@ public class PkgService : BaseService, IDynamicApi
         await _pkgPermissionRepository.DeleteAsync(a => pkgIdList.Contains(a.PkgId));
         //删除套餐
         await _pkgRepository.DeleteAsync(a => pkgIdList.Contains(a.Id));
-        
-        foreach (var tenantId in tenantIds)
-        {
-            await Cache.DelAsync(CacheKeys.DataPermission + tenantId);
-        }
+
+        //清除租户下所有用户权限缓存
+        await ClearUserPermissionsAsync(tenantIds);
     }
 
     /// <summary>
@@ -354,10 +358,8 @@ public class PkgService : BaseService, IDynamicApi
         //删除套餐
         await _pkgRepository.Where(a => pkgIdList.Contains(a.Id)).AsTreeCte().ToDelete().ExecuteAffrowsAsync();
 
-        foreach (var tenantId in tenantIds)
-        {
-            await Cache.DelAsync(CacheKeys.DataPermission + tenantId);
-        }
+        //清除租户下所有用户权限缓存
+        await ClearUserPermissionsAsync(tenantIds);
     }
 
     /// <summary>
@@ -373,10 +375,9 @@ public class PkgService : BaseService, IDynamicApi
         await _tenantPkgRepository.DeleteAsync(a => pkgIdList.Contains(a.PkgId));
         await _pkgPermissionRepository.DeleteAsync(a => pkgIdList.Contains(a.PkgId));
         await _pkgRepository.SoftDeleteRecursiveAsync(a => pkgIdList.Contains(a.Id));
-        foreach (var tenantId in tenantIds)
-        {
-            await Cache.DelAsync(CacheKeys.DataPermission + tenantId);
-        }
+
+        //清除租户下所有用户权限缓存
+        await ClearUserPermissionsAsync(tenantIds);
     }
 
     /// <summary>
@@ -392,9 +393,8 @@ public class PkgService : BaseService, IDynamicApi
         await _tenantPkgRepository.DeleteAsync(a => pkgIdList.Contains(a.PkgId));
         await _pkgPermissionRepository.DeleteAsync(a => pkgIdList.Contains(a.PkgId));
         await _pkgRepository.SoftDeleteRecursiveAsync(a => pkgIdList.Contains(a.Id));
-        foreach (var tenantId in tenantIds)
-        {
-            await Cache.DelAsync(CacheKeys.DataPermission + tenantId);
-        }
+
+        //清除租户下所有用户权限缓存
+        await ClearUserPermissionsAsync(tenantIds);
     }
 }

+ 14 - 0
src/platform/ZhonTai.Admin/Services/Tenant/TenantService.cs

@@ -25,6 +25,8 @@ using System.Collections.Generic;
 using Yitter.IdGenerator;
 using ZhonTai.Admin.Domain.Pkg;
 using ZhonTai.Admin.Domain.TenantPkg;
+using ZhonTai.Admin.Services.Pkg;
+using ZhonTai.Admin.Core.Entities;
 
 namespace ZhonTai.Admin.Services.Tenant;
 
@@ -403,6 +405,9 @@ public class TenantService : BaseService, ITenantService, IDynamicApi
                 }).ToList();
 
                 await _tenantPkgRepository.InsertAsync(pkgs);
+
+                //清除租户下所有用户权限缓存
+                await LazyGetRequiredService<PkgService>().ClearUserPermissionsAsync(new List<long> { tenant.Id });
             }
         }
     }
@@ -449,6 +454,9 @@ public class TenantService : BaseService, ITenantService, IDynamicApi
 
             //删除租户
             await _tenantRepository.DeleteAsync(id);
+
+            //清除租户下所有用户权限缓存
+            await LazyGetRequiredService<PkgService>().ClearUserPermissionsAsync(new List<long> { id });
         }
     }
 
@@ -479,6 +487,9 @@ public class TenantService : BaseService, ITenantService, IDynamicApi
 
             //删除租户
             var result = await _tenantRepository.SoftDeleteAsync(id);
+
+            //清除租户下所有用户权限缓存
+            await LazyGetRequiredService<PkgService>().ClearUserPermissionsAsync(new List<long> { id });
         }
     }
 
@@ -509,6 +520,9 @@ public class TenantService : BaseService, ITenantService, IDynamicApi
 
             //删除租户
             var result = await _tenantRepository.SoftDeleteAsync(ids);
+
+            //清除租户下所有用户权限缓存
+            await LazyGetRequiredService<PkgService>().ClearUserPermissionsAsync(ids.ToList());
         }
     }
 

+ 7 - 1
src/platform/ZhonTai.Admin/ZhonTai.Admin.xml

@@ -6353,6 +6353,12 @@
             套餐服务
             </summary>
         </member>
+        <member name="M:ZhonTai.Admin.Services.Pkg.PkgService.ClearUserPermissionsAsync(System.Collections.Generic.List{System.Int64})">
+            <summary>
+            清除租户下所有用户权限缓存
+            </summary>
+            <param name="tenantIds"></param>
+        </member>
         <member name="M:ZhonTai.Admin.Services.Pkg.PkgService.GetAsync(System.Int64)">
             <summary>
             查询
@@ -6388,7 +6394,7 @@
             <param name="input"></param>
             <returns></returns>
         </member>
-        <member name="M:ZhonTai.Admin.Services.Pkg.PkgService.GetPkgPermissionList(System.Int64)">
+        <member name="M:ZhonTai.Admin.Services.Pkg.PkgService.GetPkgPermissionListAsync(System.Int64)">
             <summary>
             查询套餐权限列表
             </summary>