diff --git a/src/ThingsGateway.Application/EventSubscriber/AuthEventSubscriber.cs b/src/ThingsGateway.Application/EventSubscriber/AuthEventSubscriber.cs index 22ead1a2e..244944a9f 100644 --- a/src/ThingsGateway.Application/EventSubscriber/AuthEventSubscriber.cs +++ b/src/ThingsGateway.Application/EventSubscriber/AuthEventSubscriber.cs @@ -49,7 +49,6 @@ { _sysCacheService.Set(CacheConst.Cache_SysUser, sysUser.Id.ToString(), sysUser); //更新Cache信息 } - await Task.CompletedTask; } } } \ No newline at end of file diff --git a/src/ThingsGateway.Application/EventSubscriber/UserEventSubscriber.cs b/src/ThingsGateway.Application/EventSubscriber/UserEventSubscriber.cs index 1a7ee8bc4..cab85ce6d 100644 --- a/src/ThingsGateway.Application/EventSubscriber/UserEventSubscriber.cs +++ b/src/ThingsGateway.Application/EventSubscriber/UserEventSubscriber.cs @@ -33,7 +33,7 @@ if (relations.Count > 0) { var userIds = relations.Select(it => it.ObjectId).ToList();//用户ID列表 - // 解析用户服务 + // 解析用户服务 var userService = scope.ServiceProvider.GetRequiredService(); //从缓存中删除 userService.DeleteUserFromCache(userIds); diff --git a/src/ThingsGateway.Application/OpenApi/EventSubscriber/OpenApiAuthEventSubscriber.cs b/src/ThingsGateway.Application/OpenApi/EventSubscriber/OpenApiAuthEventSubscriber.cs index 52c283fb7..81b581c47 100644 --- a/src/ThingsGateway.Application/OpenApi/EventSubscriber/OpenApiAuthEventSubscriber.cs +++ b/src/ThingsGateway.Application/OpenApi/EventSubscriber/OpenApiAuthEventSubscriber.cs @@ -45,7 +45,6 @@ { _sysCacheService.Set(CacheConst.Cache_OpenApiUser, openApiUser.Id.ToString(), openApiUser); //更新Cache信息 } - await Task.CompletedTask; } } } \ No newline at end of file diff --git a/src/ThingsGateway.Core/Entity/System/SysResource.cs b/src/ThingsGateway.Core/Entity/System/SysResource.cs index 5207efad8..dbc9cfb83 100644 --- a/src/ThingsGateway.Core/Entity/System/SysResource.cs +++ b/src/ThingsGateway.Core/Entity/System/SysResource.cs @@ -1,4 +1,6 @@ -namespace ThingsGateway.Core +using SqlSugar.DbConvert; + +namespace ThingsGateway.Core { /// /// 资源 @@ -36,7 +38,7 @@ /// /// 分类 /// - [SugarColumn(ColumnName = "Category", ColumnDescription = "分类", Length = 200)] + [SugarColumn(ColumnDataType = "varchar(50)", ColumnName = "Category", ColumnDescription = "分类", SqlParameterDbType = typeof(EnumToStringConvert))] public MenuCategoryEnum Category { get; set; } [SugarColumn(IsIgnore = true)] @@ -65,7 +67,7 @@ /// /// 跳转类型 /// - [SugarColumn(ColumnName = "TargetType", ColumnDescription = "跳转类型", Length = 200, IsNullable = true)] + [SugarColumn(ColumnDataType = "varchar(50)", ColumnName = "TargetType", ColumnDescription = "跳转类型", SqlParameterDbType = typeof(EnumToStringConvert), IsNullable = true)] public virtual TargetTypeEnum TargetType { get; set; } } diff --git a/src/ThingsGateway.Core/Sqlsugar/Db/DbContext.cs b/src/ThingsGateway.Core/Sqlsugar/Db/DbContext.cs index a02d6f9cf..ec7718080 100644 --- a/src/ThingsGateway.Core/Sqlsugar/Db/DbContext.cs +++ b/src/ThingsGateway.Core/Sqlsugar/Db/DbContext.cs @@ -38,7 +38,7 @@ namespace ThingsGateway.Core }); }); //注入sqlsugar服务 - SqlsugarSetup.AddSqlSugar(); + SqlSugarSetup.InitSqlSugar(); } /// diff --git a/src/ThingsGateway.Core/Sqlsugar/SqlsugarSetup.cs b/src/ThingsGateway.Core/Sqlsugar/SqlsugarSetup.cs index f59aa00b7..06b1293ab 100644 --- a/src/ThingsGateway.Core/Sqlsugar/SqlsugarSetup.cs +++ b/src/ThingsGateway.Core/Sqlsugar/SqlsugarSetup.cs @@ -7,13 +7,13 @@ namespace ThingsGateway.Core /// /// SqlSugar设置启动 /// - public static class SqlsugarSetup + public static class SqlSugarSetup { /// /// 注入Sqlsugar /// /// - public static void AddSqlSugar() + public static void InitSqlSugar() { //services.AddSingleton(DbContext.Db); // 单例注册,不用工作单元不需要注入 //services.AddUnitOfWork(); // 事务与工作单元注册 diff --git a/src/ThingsGateway.Web.Core/Configuration/Database.json b/src/ThingsGateway.Web.Core/Configuration/Database.json index 7aff3ae8a..b522afe06 100644 --- a/src/ThingsGateway.Web.Core/Configuration/Database.json +++ b/src/ThingsGateway.Web.Core/Configuration/Database.json @@ -23,6 +23,32 @@ "IsSeedData": true, //是否初始化种子数据 "IsUpdateSeedData": false } + ] + + + //"Sqlsugar": [ + // { + // "ConfigId": "Default", //租户ID + // "ConnectionString": "Data Source=./Default1.db;", //连接字符串 + // "DbType": "Sqlite", //数据库类型 + // "IsAutoCloseConnection": false, //是否自动释放 + // "IsInitDb": true, //是否初始化数据库,适用于codefirst + // "IsUnderLine": false, //是否驼峰转下划线 + // "IsSeedData": true, //是否初始化种子数据 + // "IsUpdateSeedData": false + // }, + // { + // "ConfigId": "ThingsGateway", //租户ID + // "ConnectionString": "Data Source=./ThingsGateway1.db", //连接字符串 + // "DbType": "Sqlite", //数据库类型 + // "IsAutoCloseConnection": true, //是否自动释放 + // "IsInitDb": true, //是否初始化数据库,适用于codefirst + // "IsUnderLine": false, //是否驼峰转下划线 + // "IsSeedData": true, //是否初始化种子数据 + // "IsUpdateSeedData": false + // } + + //] } } \ No newline at end of file diff --git a/src/ThingsGateway.Web.Core/Handlers/BlazorAuthorizeHandler.cs b/src/ThingsGateway.Web.Core/Handlers/BlazorAuthorizeHandler.cs index 5219eaf05..275873cd6 100644 --- a/src/ThingsGateway.Web.Core/Handlers/BlazorAuthorizeHandler.cs +++ b/src/ThingsGateway.Web.Core/Handlers/BlazorAuthorizeHandler.cs @@ -2,20 +2,19 @@ using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Components; +using Microsoft.Extensions.DependencyInjection; + namespace ThingsGateway.Web.Core { public class BlazorAuthorizeHandler : AppAuthorizeHandler { - private IOpenApiUserService _openApiUserService; private SysCacheService _sysCacheService; - private ISysUserService _sysUserService; - - public BlazorAuthorizeHandler(SysCacheService sysCacheService, ISysUserService sysUserService, IOpenApiUserService openApiUserService) + private IServiceScope _serviceScope; + public BlazorAuthorizeHandler(SysCacheService sysCacheService,IServiceScopeFactory serviceScopeFactory) { _sysCacheService = sysCacheService; - _openApiUserService = openApiUserService; - _sysUserService = sysUserService; + _serviceScope = serviceScopeFactory.CreateScope(); } public override async Task HandleAsync(AuthorizationHandlerContext context) @@ -56,11 +55,14 @@ namespace ThingsGateway.Web.Core /// public override async Task PipelineAsync(AuthorizationHandlerContext context, DefaultHttpContext httpContext) { - //这里鉴别密码是否改变 - var userId = context.User.Claims.FirstOrDefault(it => it.Type == ClaimConst.UserId).Value.ToLong(); + + //这里鉴别密码是否改变 + var userId = context.User.Claims.FirstOrDefault(it => it.Type == ClaimConst.UserId).Value.ToLong(); var isOpenApi = context.User.Claims.FirstOrDefault(it => it.Type == ClaimConst.IsOpenApi)?.Value?.ToBoolean(false) == true; if (isOpenApi) { + + var _openApiUserService = _serviceScope.ServiceProvider.GetService(); var user = await _openApiUserService.GetUsertById(userId); if (user == null) { return false; } // 此处已经自动验证 Jwt Verificat的有效性了,无需手动验证 @@ -71,10 +73,12 @@ namespace ThingsGateway.Web.Core if (isRolePermission == null || user.PermissionCodeList?.Contains(routeName) == true)//如果当前路由信息不包含在角色授权路由列表中则认证失败 return true; else + return false; } else { + var _sysUserService = _serviceScope.ServiceProvider.GetService(); var user = await _sysUserService.GetUsertById(userId); if (user == null) { return false; } diff --git a/src/ThingsGateway.Web.Core/ThingsGateway.Web.Core.csproj b/src/ThingsGateway.Web.Core/ThingsGateway.Web.Core.csproj index c0b317cfc..dff1a66fa 100644 --- a/src/ThingsGateway.Web.Core/ThingsGateway.Web.Core.csproj +++ b/src/ThingsGateway.Web.Core/ThingsGateway.Web.Core.csproj @@ -10,6 +10,7 @@ + @@ -23,6 +24,11 @@ true PreserveNewest + + PreserveNewest + true + PreserveNewest + PreserveNewest true diff --git a/src/ThingsGateway.Web.Foundation/Entity/DriverPlugin.cs b/src/ThingsGateway.Web.Foundation/Entity/DriverPlugin.cs index e71a041ad..dfefa20e8 100644 --- a/src/ThingsGateway.Web.Foundation/Entity/DriverPlugin.cs +++ b/src/ThingsGateway.Web.Foundation/Entity/DriverPlugin.cs @@ -1,4 +1,6 @@ -using ThingsGateway.Core; +using SqlSugar.DbConvert; + +using ThingsGateway.Core; namespace ThingsGateway.Web.Foundation; /// @@ -21,7 +23,7 @@ public class DriverPlugin : BaseEntity /// /// 插件类型 /// - [SugarColumn(ColumnName = "DriverTypeEnum", ColumnDescription = "插件类型")] + [SugarColumn(ColumnDataType = "varchar(50)", ColumnName = "DriverTypeEnum", ColumnDescription = "插件类型", SqlParameterDbType = typeof(EnumToStringConvert))] public DriverEnum DriverTypeEnum { get; set; } /// diff --git a/src/ThingsGateway.Web.Foundation/Entity/RuntimeLog.cs b/src/ThingsGateway.Web.Foundation/Entity/RuntimeLog.cs index ac527677e..5cb5b78db 100644 --- a/src/ThingsGateway.Web.Foundation/Entity/RuntimeLog.cs +++ b/src/ThingsGateway.Web.Foundation/Entity/RuntimeLog.cs @@ -1,5 +1,7 @@ using Microsoft.Extensions.Logging; +using SqlSugar.DbConvert; + using ThingsGateway.Core; namespace ThingsGateway.Web.Foundation @@ -19,7 +21,7 @@ namespace ThingsGateway.Web.Foundation /// /// 日志级别 /// - [SugarColumn(ColumnName = "LogLevel", ColumnDescription = "日志级别", IsNullable = false)] + [SugarColumn(ColumnDataType = "varchar(50)", ColumnName = "LogLevel", ColumnDescription = "日志级别", SqlParameterDbType = typeof(EnumToStringConvert), IsNullable = false)] public LogLevel LogLevel { get; set; } /// /// 日志来源 diff --git a/src/ThingsGateway.Web.Rcl.Core/Shared/Auth/Login.razor b/src/ThingsGateway.Web.Rcl.Core/Shared/Auth/Login.razor index 354c0f13f..f74caf839 100644 --- a/src/ThingsGateway.Web.Rcl.Core/Shared/Auth/Login.razor +++ b/src/ThingsGateway.Web.Rcl.Core/Shared/Auth/Login.razor @@ -19,7 +19,7 @@ else
- @SYS_DEFAULT_TITLE.GetNameLen2() + @SYS_DEFAULT_TITLE?.GetNameLen2()

@SYS_DEFAULT_TITLE