Просмотр исходного кода

😁升级依赖及代码调整

zuohuaijun 2 лет назад
Родитель
Сommit
ae3d563de0

+ 2 - 2
Admin.NET/Admin.NET.Application/Configuration/App.json

@@ -33,10 +33,10 @@
     "SignalRSupport": true // 启用 SignalR 跨域支持
   },
   "SnowId": {
-    "CachePrefix": "adminnet:workerId:",
     "WorkerId": 1, // 机器码 全局唯一
     "WorkerIdBitLength": 2, // 机器码位长 默认值6,取值范围 [1, 19]
-    "SeqBitLength": 6 // 序列数位长 默认值6,取值范围 [3, 21](建议不小于4,值越大性能越高、Id位数也更长)
+    "SeqBitLength": 6, // 序列数位长 默认值6,取值范围 [3, 21](建议不小于4,值越大性能越高、Id位数也更长)
+    "WorkerPrefix": "adminnet_" // 缓存前缀
   },
   "Cryptogram": {
     "CryptoType": "SM2", // 密码加密算法:MD5、SM2、SM4

+ 0 - 0
Admin.NET/Admin.NET.Application/Configuration/OSS.json → Admin.NET/Admin.NET.Application/Configuration/Upload.json


+ 4 - 4
Admin.NET/Admin.NET.Core/Admin.NET.Core.csproj

@@ -22,9 +22,9 @@
     <PackageReference Include="AspNet.Security.OAuth.Weixin" Version="6.0.15" />
     <PackageReference Include="AspNetCoreRateLimit" Version="5.0.0" />
     <PackageReference Include="FluentEmail.Smtp" Version="3.0.2" />
-    <PackageReference Include="Furion.Extras.Authentication.JwtBearer" Version="4.9.1" />
-    <PackageReference Include="Furion.Extras.ObjectMapper.Mapster" Version="4.9.1" />
-    <PackageReference Include="Furion.Pure" Version="4.9.1" />
+    <PackageReference Include="Furion.Extras.Authentication.JwtBearer" Version="4.9.1.3" />
+    <PackageReference Include="Furion.Extras.ObjectMapper.Mapster" Version="4.9.1.3" />
+    <PackageReference Include="Furion.Pure" Version="4.9.1.3" />
     <PackageReference Include="IPTools.China" Version="1.6.0" />
     <PackageReference Include="Lazy.Captcha.Core" Version="2.0.6" />
     <PackageReference Include="Magicodes.IE.Excel" Version="2.7.4.5" />
@@ -37,7 +37,7 @@
     <PackageReference Include="OnceMi.AspNetCore.OSS" Version="1.1.9" />
     <PackageReference Include="SKIT.FlurlHttpClient.Wechat.Api" Version="2.34.0" />
     <PackageReference Include="SKIT.FlurlHttpClient.Wechat.TenpayV3" Version="2.20.1" />
-    <PackageReference Include="SqlSugarCore" Version="5.1.4.115" />
+    <PackageReference Include="SqlSugarCore" Version="5.1.4.117" />
     <PackageReference Include="System.Linq.Dynamic.Core" Version="1.3.5" />
     <PackageReference Include="UAParser" Version="3.1.47" />
     <PackageReference Include="Yitter.IdGenerator" Version="1.0.14" />

+ 119 - 119
Admin.NET/Admin.NET.Core/Extension/YitIdHelperExtension.cs

@@ -1,119 +1,119 @@
-using Microsoft.Extensions.Hosting;
-
-namespace Admin.NET.Core;
-
-/// <summary>
-/// YitIdHelper 自动获取WorkId拓展
-/// </summary>
-public static class YitIdHelperExtension
-{
-    private const int MinWorkId = 0;
-    private const int MaxWorkId = 63;
-
-    private const string MainLockName = "IdGen:WorkerId:Lock";
-    private const string MainValueKey = "IdGen:WorkerId:Value";
-
-    private static readonly List<string> _workIds = new();
-    private static SnowIdOptions _options;
-
-    public static void AddYitIdHelper(this IServiceCollection services, SnowIdOptions options)
-    {
-        _options = options;
-
-        // 排除开发环境和Windows服务器
-        if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || App.WebHostEnvironment.IsDevelopment())
-        {
-            YitIdHelper.SetIdGenerator(_options);
-            return;
-        }
-
-        var maxLength = Math.Pow(2, _options.WorkerIdBitLength.ParseToDouble());
-
-        for (int i = 0; i < maxLength; i++)
-        {
-            _workIds.Add(i.ToString());
-        }
-
-        Random ran = new();
-        int milliseconds = ran.Next(10, 1000);
-        Thread.Sleep(milliseconds);
-
-        SetWorkId();
-    }
-
-    private static void SetWorkId()
-    {
-        var lockName = $"{_options.CachePrefix}{MainLockName}";
-        var valueKey = $"{_options.CachePrefix}{MainValueKey}"; ;
-
-        var client = App.GetService<ICache>();
-        var redisLock = client.AcquireLock(lockName, 10000, 15000, true);
-        var keys = client.Keys.Where(o => o.Contains($"{_options.CachePrefix}{valueKey}:*"));
-
-        var tempWorkIds = _workIds;
-        foreach (var key in keys)
-        {
-            var tempWorkId = key[key.LastIndexOf(":", StringComparison.Ordinal)..];
-            tempWorkIds.Remove(tempWorkId);
-        }
-
-        try
-        {
-            string workIdKey = "";
-            foreach (var item in tempWorkIds)
-            {
-                string workIdStr = "";
-
-                workIdStr = item;
-                workIdKey = $"{valueKey}:{workIdStr}";
-                var exist = client.Get<bool>(workIdKey);
-
-                if (exist)
-                {
-                    workIdKey = "";
-                    continue;
-                }
-
-                Console.WriteLine($"###########当前应用WorkId:【{workIdStr}】###########");
-
-                long workId = workIdStr.ParseToLong();
-
-                if (workId is < MinWorkId or > MaxWorkId)
-                    continue;
-
-                // 设置雪花Id算法机器码
-                YitIdHelper.SetIdGenerator(new IdGeneratorOptions
-                {
-                    WorkerId = (ushort)workId,
-                    WorkerIdBitLength = _options.WorkerIdBitLength,
-                    SeqBitLength = _options.SeqBitLength
-                });
-
-                client.Set(workIdKey, true, TimeSpan.FromSeconds(15));
-
-                break;
-            }
-
-            if (string.IsNullOrWhiteSpace(workIdKey)) throw Oops.Oh("未设置有效的机器码,启动失败");
-
-            // 开一个任务设置当前workId过期时间
-            Task.Run(() =>
-            {
-                while (true)
-                {
-                    client.SetExpire(workIdKey, TimeSpan.FromSeconds(15));
-                    //Task.Delay(5000);
-                    Thread.Sleep(10000);
-                }
-            });
-        }
-        catch (Exception e)
-        {
-            throw Oops.Oh($"{e.Message};{e.StackTrace};{e.StackTrace}");
-        }
-        finally
-        {
-            redisLock?.Dispose();
-        }
-    }
-}
+//// 麻省理工学院许可证
+////
+//// 版权所有 (c) 2021-2023 zuohuaijun,大名科技(天津)有限公司  联系电话/微信:18020030720  QQ:515096995
+////
+//// 特此免费授予获得本软件的任何人以处理本软件的权利,但须遵守以下条件:在所有副本或重要部分的软件中必须包括上述版权声明和本许可声明。
+////
+//// 软件按“原样”提供,不提供任何形式的明示或暗示的保证,包括但不限于对适销性、适用性和非侵权的保证。
+//// 在任何情况下,作者或版权持有人均不对任何索赔、损害或其他责任负责,无论是因合同、侵权或其他方式引起的,与软件或其使用或其他交易有关。
+
+//namespace Admin.NET.Core;
+
+///// <summary>
+///// 雪花Id自动获取机器码WorkId拓展
+///// </summary>
+//public static class YitIdHelperExtension
+//{
+//    private const int MinWorkId = 0;
+//    private const int MaxWorkId = 63;
+
+//    private const string MainLockName = "WorkerId_Lock";
+//    private const string MainValueKey = "WorkerId_Value";
+
+//    private static readonly List<string> _workIds = new();
+//    private static SnowIdOptions _options;
+
+//    public static void AddYitIdHelper(this IServiceCollection services, SnowIdOptions options)
+//    {
+//        _options = options;
+
+//        // 排除开发环境和Windows服务器
+//        if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || App.WebHostEnvironment.IsDevelopment())
+//        {
+//            YitIdHelper.SetIdGenerator(_options);
+//            return;
+//        }
+
+//        var maxLength = Math.Pow(2, _options.WorkerIdBitLength.ParseToDouble());
+//        for (int i = 0; i < maxLength; i++)
+//        {
+//            _workIds.Add(i.ToString());
+//        }
+
+//        Random ran = new();
+//        Thread.Sleep(ran.Next(10, 1000));
+
+//        SetWorkId();
+//    }
+
+//    private static void SetWorkId()
+//    {
+//        var lockName = $"{_options.CachePrefix}{MainLockName}";
+//        var valueKey = $"{_options.CachePrefix}{MainValueKey}";
+
+//        var client = App.GetService<ICache>();
+//        var redisLock = client.AcquireLock(lockName, 10000, 15000, true);
+//        var keys = client.Keys.Where(o => o.Contains($"{_options.CachePrefix}{valueKey}:*"));
+
+//        var tempWorkIds = _workIds;
+//        foreach (var key in keys)
+//        {
+//            var tempWorkId = key[key.LastIndexOf(":", StringComparison.Ordinal)..];
+//            tempWorkIds.Remove(tempWorkId);
+//        }
+
+//        try
+//        {
+//            string workIdKey = "";
+//            foreach (var item in tempWorkIds)
+//            {
+//                workIdKey = $"{valueKey}:{item}";
+//                var exist = client.Get<bool>(workIdKey);
+//                if (exist)
+//                {
+//                    workIdKey = "";
+//                    continue;
+//                }
+
+//                Console.WriteLine($"########## 当前应用机器码WorkId:【{item}】##########");
+
+//                long workId = item.ParseToLong();
+//                if (workId is < MinWorkId or > MaxWorkId)
+//                    continue;
+
+//                // 设置雪花Id算法机器码
+//                YitIdHelper.SetIdGenerator(new IdGeneratorOptions
+//                {
+//                    WorkerId = (ushort)workId,
+//                    WorkerIdBitLength = _options.WorkerIdBitLength,
+//                    SeqBitLength = _options.SeqBitLength
+//                });
+
+//                client.Set(workIdKey, true, TimeSpan.FromSeconds(15));
+
+//                break;
+//            }
+
+//            if (string.IsNullOrWhiteSpace(workIdKey)) throw Oops.Oh("未设置有效的机器码,启动失败");
+
+//            // 开一个任务设置当前workId过期时间
+//            Task.Run(() =>
+//            {
+//                while (true)
+//                {
+//                    client.SetExpire(workIdKey, TimeSpan.FromSeconds(15));
+//                    // Task.Delay(5000);
+//                    Thread.Sleep(10000);
+//                }
+//            });
+//        }
+//        catch (Exception e)
+//        {
+//            throw Oops.Oh($"{e.Message};{e.StackTrace};{e.StackTrace}");
+//        }
+//        finally
+//        {
+//            redisLock?.Dispose();
+//        }
+//    }
+//}

+ 1 - 0
Admin.NET/Admin.NET.Core/GlobalUsings.cs

@@ -34,6 +34,7 @@ global using Microsoft.AspNetCore.Mvc;
 global using Microsoft.AspNetCore.Mvc.Filters;
 global using Microsoft.Extensions.Configuration;
 global using Microsoft.Extensions.DependencyInjection;
+global using Microsoft.Extensions.Hosting;
 global using Microsoft.Extensions.Logging;
 global using Microsoft.Extensions.Options;
 global using NewLife;

+ 1 - 2
Admin.NET/Admin.NET.Core/Option/DbConnectionOptions.cs

@@ -28,8 +28,7 @@ public sealed class DbConnectionOptions : IConfigurableOptions<DbConnectionOptio
     {
         foreach (var dbConfig in options.ConnectionConfigs)
         {
-            if (string.IsNullOrWhiteSpace(dbConfig.ConfigId))
-                dbConfig.ConfigId = SqlSugarConst.MainConfigId;
+            dbConfig.ConfigId ??= SqlSugarConst.MainConfigId;
         }
     }
 }

+ 0 - 29
Admin.NET/Admin.NET.Core/Option/OSSProviderOptions.cs

@@ -1,29 +0,0 @@
-// 麻省理工学院许可证
-//
-// 版权所有 (c) 2021-2023 zuohuaijun,大名科技(天津)有限公司  联系电话/微信:18020030720  QQ:515096995
-//
-// 特此免费授予获得本软件的任何人以处理本软件的权利,但须遵守以下条件:在所有副本或重要部分的软件中必须包括上述版权声明和本许可声明。
-//
-// 软件按“原样”提供,不提供任何形式的明示或暗示的保证,包括但不限于对适销性、适用性和非侵权的保证。
-// 在任何情况下,作者或版权持有人均不对任何索赔、损害或其他责任负责,无论是因合同、侵权或其他方式引起的,与软件或其使用或其他交易有关。
-
-using OnceMi.AspNetCore.OSS;
-
-namespace Admin.NET.Core;
-
-/// <summary>
-/// 对象存储配置选项
-/// </summary>
-public sealed class OSSProviderOptions : OSSOptions, IConfigurableOptions
-{
-    /// <summary>
-    /// 是否启用OSS存储
-    /// </summary>
-    public bool IsEnable { get; set; }
-
-    /// <summary>
-    /// 自定义桶名称 不能直接使用Provider来替代桶名称
-    /// 例:阿里云 1.只能包括小写字母,数字,短横线(-)2.必须以小写字母或者数字开头 3.长度必须在3-63字节之间
-    /// </summary>
-    public string Bucket { get; set; }
-}

+ 1 - 1
Admin.NET/Admin.NET.Core/Option/SnowIdOptions.cs

@@ -17,5 +17,5 @@ public sealed class SnowIdOptions : IdGeneratorOptions, IConfigurableOptions
     /// <summary>
     /// 缓存前缀
     /// </summary>
-    public string CachePrefix { get; set; }
+    public string WorkerPrefix { get; set; }
 }

+ 19 - 0
Admin.NET/Admin.NET.Core/Option/UploadOptions.cs

@@ -7,6 +7,8 @@
 // 软件按“原样”提供,不提供任何形式的明示或暗示的保证,包括但不限于对适销性、适用性和非侵权的保证。
 // 在任何情况下,作者或版权持有人均不对任何索赔、损害或其他责任负责,无论是因合同、侵权或其他方式引起的,与软件或其使用或其他交易有关。
 
+using OnceMi.AspNetCore.OSS;
+
 namespace Admin.NET.Core;
 
 /// <summary>
@@ -34,4 +36,21 @@ public sealed class UploadOptions : IConfigurableOptions
     /// </summary>
     /// <remarks>防止重复上传</remarks>
     public bool EnableMd5 { get; set; }
+}
+
+/// <summary>
+/// 对象存储配置选项
+/// </summary>
+public sealed class OSSProviderOptions : OSSOptions, IConfigurableOptions
+{
+    /// <summary>
+    /// 是否启用OSS存储
+    /// </summary>
+    public bool IsEnable { get; set; }
+
+    /// <summary>
+    /// 自定义桶名称 不能直接使用Provider来替代桶名称
+    /// 例:阿里云 1.只能包括小写字母,数字,短横线(-)2.必须以小写字母或者数字开头 3.长度必须在3-63字节之间
+    /// </summary>
+    public string Bucket { get; set; }
 }

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

@@ -246,7 +246,7 @@ public class SysOrgService : IDynamicApiController, ITransient
                 if (userOrgs.Contains(orgId) || userOrgs.Contains(orgPid))
                 {
                     var userId = long.Parse(userOrgKey.Substring(CacheConst.KeyUserOrg));
-                    SqlSugarFilter.DeleteUserOrgCache(userId, _sysOrgRep.Context.CurrentConnectionConfig.ConfigId);
+                    SqlSugarFilter.DeleteUserOrgCache(userId, _sysOrgRep.Context.CurrentConnectionConfig.ConfigId.ToString());
                 }
             }
         }

+ 1 - 1
Admin.NET/Admin.NET.Core/Service/Role/SysRoleService.cs

@@ -175,7 +175,7 @@ public class SysRoleService : IDynamicApiController, ITransient
         var userIdList = await _sysUserRoleService.GetUserIdList(input.Id);
         foreach (var userId in userIdList)
         {
-            SqlSugarFilter.DeleteUserOrgCache(userId, _sysRoleRep.Context.CurrentConnectionConfig.ConfigId);
+            SqlSugarFilter.DeleteUserOrgCache(userId, _sysRoleRep.Context.CurrentConnectionConfig.ConfigId.ToString());
         }
 
         var role = await _sysRoleRep.GetFirstAsync(u => u.Id == input.Id);

+ 0 - 1
Admin.NET/Admin.NET.Core/Service/Server/SysServerService.cs

@@ -12,7 +12,6 @@ using AspNetCoreRateLimit;
 using FluentEmail.Core;
 using Lazy.Captcha.Core;
 using Magicodes.ExporterAndImporter.Pdf;
-using Microsoft.Extensions.Hosting;
 using Nest;
 using OnceMi.AspNetCore.OSS;
 

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

@@ -111,7 +111,7 @@ public class SysUserService : IDynamicApiController, ITransient
         await UpdateRoleAndExtOrg(input);
 
         // 删除用户机构缓存
-        SqlSugarFilter.DeleteUserOrgCache(input.Id, _sysUserRep.Context.CurrentConnectionConfig.ConfigId);
+        SqlSugarFilter.DeleteUserOrgCache(input.Id, _sysUserRep.Context.CurrentConnectionConfig.ConfigId.ToString());
     }
 
     /// <summary>

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

@@ -20,6 +20,9 @@ public static class SqlSugarSetup
         // 注册雪花Id
         YitIdHelper.SetIdGenerator(App.GetOptions<SnowIdOptions>());
 
+        //// 注册雪花Id-支持分布式
+        //services.AddYitIdHelper(App.GetOptions<SnowIdOptions>());
+
         // 自定义 SqlSugar 雪花ID算法
         SnowFlakeSingle.WorkId = App.GetOptions<SnowIdOptions>().WorkerId;
         StaticConfig.CustomSnowFlakeFunc = () =>

+ 0 - 3
Admin.NET/Admin.NET.Web.Core/Startup.cs

@@ -144,9 +144,6 @@ public class Startup : AppStartup
         // 验证码
         services.AddCaptcha();
 
-        // 分布式环境-机器码设置
-        services.AddYitIdHelper(App.GetOptions<SnowIdOptions>());
-
         // 控制台logo
         services.AddConsoleLogo();
     }