Ver código fonte

🐛修复用户登录后没有触发过GetUserOrgIdList,导致maxDataScope一直为0的问题

Signed-off-by: KaneLeung <kk.xiaolan@gmail.com>
KaneLeung 2 anos atrás
pai
commit
ab38176a48
1 arquivos alterados com 12 adições e 1 exclusões
  1. 12 1
      Admin.NET/Admin.NET.Core/SqlSugar/SqlSugarFilter.cs

+ 12 - 1
Admin.NET/Admin.NET.Core/SqlSugar/SqlSugarFilter.cs

@@ -55,7 +55,7 @@ public static class SqlSugarFilter
             Scoped.Create((factory, scope) =>
             Scoped.Create((factory, scope) =>
             {
             {
                 var services = scope.ServiceProvider;
                 var services = scope.ServiceProvider;
-                orgIds = services.GetService<SysOrgService>().GetUserOrgIdList().GetAwaiter().GetResult();
+                orgIds = services.GetRequiredService<SysOrgService>().GetUserOrgIdList().GetAwaiter().GetResult();
             });
             });
             if (orgIds == null || orgIds.Count == 0) return;
             if (orgIds == null || orgIds.Count == 0) return;
 
 
@@ -100,6 +100,17 @@ public static class SqlSugarFilter
 
 
         // 获取用户最大数据范围---仅本人数据
         // 获取用户最大数据范围---仅本人数据
         maxDataScope = App.GetRequiredService<SysCacheService>().Get<int>(CacheConst.KeyRoleMaxDataScope + userId);
         maxDataScope = App.GetRequiredService<SysCacheService>().Get<int>(CacheConst.KeyRoleMaxDataScope + userId);
+        // 如果为0,则调用GetUserOrgIdList,建立KeyRoleMaxDataScope缓存
+        if (maxDataScope == 0)
+        {
+            // 获取用户所属机构,保证同一作用域
+            Scoped.Create((factory, scope) =>
+            {
+                var services = scope.ServiceProvider;
+                services.GetRequiredService<SysOrgService>().GetUserOrgIdList().GetAwaiter().GetResult();
+                maxDataScope = services.GetRequiredService<SysCacheService>().Get<int>(CacheConst.KeyRoleMaxDataScope + userId);
+            });
+        }
         if (maxDataScope != (int)DataScopeEnum.Self) return maxDataScope;
         if (maxDataScope != (int)DataScopeEnum.Self) return maxDataScope;
 
 
         // 配置用户数据范围缓存
         // 配置用户数据范围缓存