فهرست منبع

增加及缓存最大角色数据范围

zuohuaijun 3 سال پیش
والد
کامیت
4e746c9911

+ 31 - 0
Admin.NET/Admin.NET.Application/Service/JobTimer.cs

@@ -0,0 +1,31 @@
+using Furion.Logging;
+using Furion.TaskScheduler;
+
+namespace Admin.NET.Application.Serice;
+
+/// <summary>
+/// 任务调度测试
+/// </summary>
+public class JobTimer : ISpareTimeWorker
+{
+    /// <summary>
+    /// 定时器
+    /// </summary>
+    /// <param name="timer"></param>
+    /// <param name="count"></param>
+    [SpareTime(5000, "定时器", StartNow = true, ExecuteType = SpareTimeExecuteTypes.Serial)]
+    public void CollectDeviceChannel(SpareTimer timer, long count)
+    {
+        //// 写日志文件
+        //StringLoggingPart.Default.SetMessage("这是一个日志").LogInformation();
+
+        Scoped.Create(async (_, scope) =>
+        {
+            var services = scope.ServiceProvider;
+            var db = services.GetService<ISqlSugarClient>();
+
+            // 写日志文件
+            StringLoggingPart.Default.SetMessage("【定时器】" + DateTime.Now + "执行次数:" + count).LogInformation();
+        });
+    }
+}

+ 20 - 0
Admin.NET/Admin.NET.Core/Admin.NET.Core.xml

@@ -45,6 +45,11 @@
             机构Id集合缓存
             </summary>
         </member>
+        <member name="F:Admin.NET.Core.CacheConst.KeyMaxDataScopeType">
+            <summary>
+            最大角色数据范围缓存
+            </summary>
+        </member>
         <member name="F:Admin.NET.Core.CacheConst.KeyVerCode">
             <summary>
             验证码缓存
@@ -3410,6 +3415,21 @@
             <param name="permissions"></param>
             <returns></returns>
         </member>
+        <member name="M:Admin.NET.Core.Service.SysCacheService.GetMaxDataScopeType(System.Int64)">
+            <summary>
+            获取最大角色数据范围
+            </summary>
+            <param name="userId"></param>
+            <returns></returns>
+        </member>
+        <member name="M:Admin.NET.Core.Service.SysCacheService.SetMaxDataScopeType(System.Int64,System.Int32)">
+            <summary>
+            缓存最大角色数据范围
+            </summary>
+            <param name="userId"></param>
+            <param name="dataScopeType"></param>
+            <returns></returns>
+        </member>
         <member name="T:Admin.NET.Core.Service.CodeGenConfigService">
             <summary>
             代码生成详细配置服务

+ 2 - 2
Admin.NET/Admin.NET.Core/Const/CacheConst.cs

@@ -28,7 +28,7 @@ public class CacheConst
     /// <summary>
     /// 最大角色数据范围缓存
     /// </summary>
-    public const string KeyStrongerDataScope = "strongerdatascope:";
+    public const string KeyMaxDataScopeType = "maxDataScopeType:";
 
     /// <summary>
     /// 验证码缓存
@@ -58,5 +58,5 @@ public class CacheConst
     /// <summary>
     /// swagger登录缓存
     /// </summary>
-    public const string SwaggerLogin = "swaggerlogin:";
+    public const string SwaggerLogin = "swaggerLogin:";
 }

+ 0 - 4
Admin.NET/Admin.NET.Core/Option/RateLimitOptions.cs

@@ -7,7 +7,6 @@ namespace Admin.NET.Core;
 /// </summary>
 public sealed class IpRateLimitingOptions : IpRateLimitOptions
 {
-
 }
 
 /// <summary>
@@ -15,7 +14,6 @@ public sealed class IpRateLimitingOptions : IpRateLimitOptions
 /// </summary>
 public sealed class IpRateLimitPoliciesOptions : IpRateLimitPolicies, IConfigurableOptions
 {
-
 }
 
 /// <summary>
@@ -23,7 +21,6 @@ public sealed class IpRateLimitPoliciesOptions : IpRateLimitPolicies, IConfigura
 /// </summary>
 public sealed class ClientRateLimitingOptions : ClientRateLimitOptions, IConfigurableOptions
 {
-
 }
 
 /// <summary>
@@ -31,5 +28,4 @@ public sealed class ClientRateLimitingOptions : ClientRateLimitOptions, IConfigu
 /// </summary>
 public sealed class ClientRateLimitPoliciesOptions : ClientRateLimitPolicies, IConfigurableOptions
 {
-
 }

+ 2 - 2
Admin.NET/Admin.NET.Core/Service/Cache/ISysCacheService.cs

@@ -30,7 +30,7 @@ public interface ISysCacheService
 
     Task SetPermission(long userId, List<string> permissions);
 
-    Task<int?> GetStrongerDataScopeType(long userId);
+    Task<int?> GetMaxDataScopeType(long userId);
 
-    Task SetStrongerDataScopeType(long userId, int dataScope);
+    Task SetMaxDataScopeType(long userId, int dataScopeType);
 }

+ 6 - 6
Admin.NET/Admin.NET.Core/Service/Cache/SysCacheService.cs

@@ -248,9 +248,9 @@ public class SysCacheService : ISysCacheService, IDynamicApiController, ISinglet
     /// <param name="userId"></param>
     /// <returns></returns>
     [NonAction]
-    public async Task<int?> GetStrongerDataScopeType(long userId)
+    public async Task<int?> GetMaxDataScopeType(long userId)
     {
-        var cacheKey = CacheConst.KeyStrongerDataScope + userId;
+        var cacheKey = CacheConst.KeyMaxDataScopeType + userId;
         var res = await _cache.GetStringAsync(cacheKey);
         return string.IsNullOrWhiteSpace(res) ? null : int.Parse(res);
     }
@@ -259,13 +259,13 @@ public class SysCacheService : ISysCacheService, IDynamicApiController, ISinglet
     /// 缓存最大角色数据范围
     /// </summary>
     /// <param name="userId"></param>
-    /// <param name="dataScope"></param>
+    /// <param name="dataScopeType"></param>
     /// <returns></returns>
     [NonAction]
-    public async Task SetStrongerDataScopeType(long userId, int dataScope)
+    public async Task SetMaxDataScopeType(long userId, int dataScopeType)
     {
-        var cacheKey = CacheConst.KeyStrongerDataScope + userId;
-        await _cache.SetStringAsync(cacheKey, dataScope.ToString());
+        var cacheKey = CacheConst.KeyMaxDataScopeType + userId;
+        await _cache.SetStringAsync(cacheKey, dataScopeType.ToString());
 
         await AddCacheKey(cacheKey);
     }

+ 2 - 2
Admin.NET/Admin.NET.Core/Service/DataResources/SysDataResourceService.cs

@@ -42,8 +42,8 @@ public class SysDataResourceService : IDynamicApiController, ITransient
             }
         }
 
-        if (rootDataTree == null)        
-            return null;        
+        if (rootDataTree == null)
+            return null;
 
         var idList = rootDataTree.Id > 0 ? await GetChildIdListWithSelfById(rootDataTree.Id) : new List<long>();
         var iSugarQueryable = _sysDataResourceRep.AsQueryable()

+ 3 - 3
Admin.NET/Admin.NET.Core/Service/Org/SysOrgService.cs

@@ -246,9 +246,9 @@ public class SysOrgService : IDynamicApiController, ITransient
         // 根据数据范围获取机构集合
         var orgIdList2 = await GetOrgIdListByDataScope(strongerDataScopeType);
 
-        var userId = _userManager.UserId;
-        //缓存当前用户最大范围策略设定权限值
-        await _sysCacheService.SetStrongerDataScopeType(userId, strongerDataScopeType); // 存缓存
+        // 缓存当前用户最大角色数据范围
+        await _sysCacheService.SetMaxDataScopeType(_userManager.UserId, strongerDataScopeType);
+
         // 并集机构集合
         return orgIdList1.Concat(orgIdList2).Distinct().ToList();
     }

+ 1 - 1
Admin.NET/Admin.NET.Core/Service/User/SysUserService.cs

@@ -43,7 +43,7 @@ public class SysUserService : IDynamicApiController, ITransient
 
         return await _sysUserRep.AsQueryable()
             .WhereIF(!_userManager.SuperAdmin, u => u.UserType != UserTypeEnum.SuperAdmin)
-            .WhereIF(input.OrgId > 0, u => orgList.Contains(u.OrgId))            
+            .WhereIF(input.OrgId > 0, u => orgList.Contains(u.OrgId))
             .WhereIF(!string.IsNullOrWhiteSpace(input.UserName), u => u.UserName.Contains(input.UserName))
             .WhereIF(!string.IsNullOrWhiteSpace(input.Phone), u => u.Phone.Contains(input.Phone))
             .ToPagedListAsync(input.Page, input.PageSize);

+ 1 - 3
Admin.NET/Admin.NET.Core/SqlSugar/SqlSugarSetup.cs

@@ -228,9 +228,7 @@ public static class SqlSugarSetup
 
         // 获取用户机构Id集合
         var orgIds = await App.GetService<SysCacheService>().GetOrgIdList(long.Parse(userId));
-        if (orgIds == null) return;
-        //如果不判断orgIds.Count==0,生成的sql语句条件中会出现1=2的bug
-        if (orgIds.Count == 0) return;
+        if (orgIds == null || orgIds.Count == 0) return;
 
         foreach (var dataEntityType in dataEntityTypes)
         {