Browse Source

!1389 修复用户登录后没有触发过GetUserOrgIdList,导致maxDataScope一直为0的问题
Merge pull request !1389 from KaneLeung/next

zuohuaijun 2 years ago
parent
commit
647f6d58b6
1 changed files with 12 additions and 1 deletions
  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) =>
             {
                 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;
 
@@ -100,6 +100,17 @@ public static class SqlSugarFilter
 
         // 获取用户最大数据范围---仅本人数据
         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;
 
         // 配置用户数据范围缓存