From 78b9b984ec3fd32bc14829602201f2683734ae66 Mon Sep 17 00:00:00 2001 From: zuohuaijun Date: Mon, 6 Jan 2025 13:40:19 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=98=8E1=E3=80=81=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E5=BA=93=E8=A1=A8=E5=88=9D=E5=A7=8B=E5=8C=96=E9=80=9F=E5=BA=A6?= =?UTF-8?q?=20=202=E3=80=81=E9=BB=98=E8=AE=A4=E5=BC=80=E5=90=AF=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E6=96=87=E4=BB=B6=E6=97=A5=E5=BF=97=20=203=E3=80=81?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81=E5=8D=87=E7=BA=A7=E4=BE=9D?= =?UTF-8?q?=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Configuration/Logging.json | 4 +- .../SeedData/SysConfigSeedData.cs | 2 +- .../SeedData/SysMenuSeedData.cs | 3 +- .../Service/App/Auth/AppAuthService.cs | 2 +- .../Admin.NET.Core/Admin.NET.Core.csproj | 4 +- .../Extension/ConsoleLogoSetup.cs | 3 +- Admin.NET/Admin.NET.Core/Job/EnumToDictJob.cs | 11 ++-- Admin.NET/Admin.NET.Core/Job/LogJob.cs | 10 ++-- Admin.NET/Admin.NET.Core/Job/OnlineUserJob.cs | 12 ++-- .../Logging/DatabaseLoggingWriter.cs | 14 +++-- .../Admin.NET.Core/Logging/LoggingSetup.cs | 4 +- .../Admin.NET.Core/SeedData/SysAppSeedData.cs | 6 +- .../SeedData/SysCodeGenTemplateSeedData.cs | 6 +- .../Admin.NET.Core/SeedData/SysOrgSeedData.cs | 6 +- .../Admin.NET.Core/SeedData/SysPosSeedData.cs | 6 +- .../SeedData/SysRoleMenuSeedData.cs | 6 +- .../SeedData/SysRoleSeedData.cs | 6 +- .../SeedData/SysTenantSeedData.cs | 6 +- .../SeedData/SysUserExtOrgSeedData.cs | 6 +- .../SeedData/SysUserRoleSeedData.cs | 6 +- .../SeedData/SysUserSeedData.cs | 6 +- .../Admin.NET.Core/Service/Job/JobMonitor.cs | 24 ++++---- .../Admin.NET.Core/SqlSugar/SqlSugarSetup.cs | 57 ++++++++++++------- Admin.NET/Admin.NET.Web.Core/Startup.cs | 12 ++-- Web/package.json | 12 ++-- Web/src/layout/navBars/topBar/user.vue | 6 +- .../system/config/component/editConfig.vue | 2 +- 27 files changed, 132 insertions(+), 110 deletions(-) diff --git a/Admin.NET/Admin.NET.Application/Configuration/Logging.json b/Admin.NET/Admin.NET.Application/Configuration/Logging.json index 428cccc2..c320fda8 100644 --- a/Admin.NET/Admin.NET.Application/Configuration/Logging.json +++ b/Admin.NET/Admin.NET.Application/Configuration/Logging.json @@ -10,10 +10,10 @@ "System.Net.Http.HttpClient": "Warning" }, "File": { - "Enabled": false, // 启用文件日志 + "Enabled": true, // 启用文件日志 "FileName": "logs/{0:yyyyMMdd}_{1}.log", // 日志文件 "Append": true, // 追加覆盖 - // "MinimumLevel": "Information", // 日志级别 + "MinimumLevel": "Error", // 日志级别 "FileSizeLimitBytes": 10485760, // 10M=10*1024*1024 "MaxRollingFiles": 30 // 只保留30个文件 }, diff --git a/Admin.NET/Admin.NET.Application/SeedData/SysConfigSeedData.cs b/Admin.NET/Admin.NET.Application/SeedData/SysConfigSeedData.cs index 20619a8f..07d93f1d 100644 --- a/Admin.NET/Admin.NET.Application/SeedData/SysConfigSeedData.cs +++ b/Admin.NET/Admin.NET.Application/SeedData/SysConfigSeedData.cs @@ -4,7 +4,7 @@ // // 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任! -namespace Dilon.SmartElder.Application; +namespace Admin.NET.Application; /// /// 系统配置表种子数据 diff --git a/Admin.NET/Admin.NET.Application/SeedData/SysMenuSeedData.cs b/Admin.NET/Admin.NET.Application/SeedData/SysMenuSeedData.cs index f141981f..57686deb 100644 --- a/Admin.NET/Admin.NET.Application/SeedData/SysMenuSeedData.cs +++ b/Admin.NET/Admin.NET.Application/SeedData/SysMenuSeedData.cs @@ -4,11 +4,12 @@ // // 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任! -namespace Dilon.SmartElder.Application; +namespace Admin.NET.Application; /// /// 系统菜单表种子数据 /// +[SeedData(500)] [IncreSeed] public class SysMenuSeedData : ISqlSugarEntitySeedData { diff --git a/Admin.NET/Admin.NET.Application/Service/App/Auth/AppAuthService.cs b/Admin.NET/Admin.NET.Application/Service/App/Auth/AppAuthService.cs index 2cff5250..d1fa0790 100644 --- a/Admin.NET/Admin.NET.Application/Service/App/Auth/AppAuthService.cs +++ b/Admin.NET/Admin.NET.Application/Service/App/Auth/AppAuthService.cs @@ -145,7 +145,7 @@ public class AppAuthService : IDynamicApiController, ITransient throw Oops.Oh("验证码错误!"); // 账号是否存在 - var user = await _sysUserRep.AsQueryable().Includes(t => t.SysOrg).ClearFilter().FirstAsync(u => u.Phone.Equals(input.Phone)); + var user = await _sysUserRep.AsQueryable().Includes(u => u.SysOrg).ClearFilter().FirstAsync(u => u.Phone.Equals(input.Phone)); _ = user ?? throw Oops.Oh(ErrorCodeEnum.D0009); return await CreateToken(user, input.LoginMode); diff --git a/Admin.NET/Admin.NET.Core/Admin.NET.Core.csproj b/Admin.NET/Admin.NET.Core/Admin.NET.Core.csproj index 5ad586f5..5ba81758 100644 --- a/Admin.NET/Admin.NET.Core/Admin.NET.Core.csproj +++ b/Admin.NET/Admin.NET.Core/Admin.NET.Core.csproj @@ -13,7 +13,7 @@ - + @@ -35,7 +35,7 @@ - + diff --git a/Admin.NET/Admin.NET.Core/Extension/ConsoleLogoSetup.cs b/Admin.NET/Admin.NET.Core/Extension/ConsoleLogoSetup.cs index be20e972..e654c839 100644 --- a/Admin.NET/Admin.NET.Core/Extension/ConsoleLogoSetup.cs +++ b/Admin.NET/Admin.NET.Core/Extension/ConsoleLogoSetup.cs @@ -22,6 +22,7 @@ public static class ConsoleLogoSetup / ____ \ (_| | | | | | | | | | |_| |\ | |____ | | /_/ \_\__,_|_| |_| |_|_|_| |_(_)_| \_|______| |_| "); Console.ForegroundColor = ConsoleColor.Yellow; - Console.WriteLine(@"让.NET更简单、更通用、更流行!"); + Console.WriteLine("让 .NET 开发更简单、更通用、更流行!"); + Console.WriteLine("https://gitee.com/zuohuaijun/Admin.NET"); } } \ No newline at end of file diff --git a/Admin.NET/Admin.NET.Core/Job/EnumToDictJob.cs b/Admin.NET/Admin.NET.Core/Job/EnumToDictJob.cs index 8aaa5b69..4efd478b 100644 --- a/Admin.NET/Admin.NET.Core/Job/EnumToDictJob.cs +++ b/Admin.NET/Admin.NET.Core/Job/EnumToDictJob.cs @@ -13,18 +13,18 @@ namespace Admin.NET.Core; [PeriodSeconds(1, TriggerId = "trigger_EnumToDictJob", Description = "枚举转字典", MaxNumberOfRuns = 1, RunOnStart = true)] public class EnumToDictJob : IJob { - private readonly IServiceScopeFactory _scopeFactory; + private readonly IServiceScopeFactory _serviceScopeFactory; private const int OrderOffset = 10; private const string DefaultTagType = "info"; - public EnumToDictJob(IServiceScopeFactory scopeFactory) + public EnumToDictJob(IServiceScopeFactory serviceScopeFactory) { - _scopeFactory = scopeFactory; + _serviceScopeFactory = serviceScopeFactory; } public async Task ExecuteAsync(JobExecutingContext context, CancellationToken stoppingToken) { - using var serviceScope = _scopeFactory.CreateScope(); + using var serviceScope = _serviceScopeFactory.CreateScope(); var sysEnumService = serviceScope.ServiceProvider.GetRequiredService(); // 获取数据库连接 var db = serviceScope.ServiceProvider.GetRequiredService().CopyNew(); @@ -85,9 +85,10 @@ public class EnumToDictJob : IJob Log.Error($"系统枚举转换字典操作错误:{error.Message}\n堆栈跟踪:{error.StackTrace}", error); throw; } + var msg = $"【{DateTime.Now}】系统枚举转换字典。【定时任务】"; var originColor = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Green; - Console.WriteLine($"【{DateTime.Now}】系统枚举转换字典"); + Console.WriteLine(msg); Console.ForegroundColor = originColor; } diff --git a/Admin.NET/Admin.NET.Core/Job/LogJob.cs b/Admin.NET/Admin.NET.Core/Job/LogJob.cs index e3d8b9b0..a1b10b1f 100644 --- a/Admin.NET/Admin.NET.Core/Job/LogJob.cs +++ b/Admin.NET/Admin.NET.Core/Job/LogJob.cs @@ -13,18 +13,18 @@ namespace Admin.NET.Core; [Daily(TriggerId = "trigger_log", Description = "清理操作日志")] public class LogJob : IJob { - private readonly IServiceScopeFactory _scopeFactory; + private readonly IServiceScopeFactory _serviceScopeFactory; private readonly ILogger _logger; - public LogJob(IServiceScopeFactory scopeFactory, ILoggerFactory loggerFactory) + public LogJob(IServiceScopeFactory serviceScopeFactory, ILoggerFactory loggerFactory) { - _scopeFactory = scopeFactory; + _serviceScopeFactory = serviceScopeFactory; _logger = loggerFactory.CreateLogger(CommonConst.SysLogCategoryName); } public async Task ExecuteAsync(JobExecutingContext context, CancellationToken stoppingToken) { - using var serviceScope = _scopeFactory.CreateScope(); + using var serviceScope = _serviceScopeFactory.CreateScope(); var db = serviceScope.ServiceProvider.GetRequiredService().CopyNew(); var sysConfigService = serviceScope.ServiceProvider.GetRequiredService(); @@ -35,7 +35,7 @@ public class LogJob : IJob await db.Deleteable().Where(u => u.CreateTime < DateTime.Now.AddDays(-daysAgo)).ExecuteCommandAsync(stoppingToken); // 删除差异日志 await db.Deleteable().Where(u => u.CreatedTime < DateTime.Now.AddDays(-daysAgo)).ExecuteCommandAsync(stoppingToken); // 删除作业触发器运行记录 - string msg = $"【{DateTime.Now}】清理系统日志成功,删除 {daysAgo} 天前的日志数据!"; + var msg = $"【{DateTime.Now}】清理系统日志成功,删除 {daysAgo} 天前的日志数据。【定时任务】"; var originColor = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine(msg); diff --git a/Admin.NET/Admin.NET.Core/Job/OnlineUserJob.cs b/Admin.NET/Admin.NET.Core/Job/OnlineUserJob.cs index 90c07696..d0a64f0e 100644 --- a/Admin.NET/Admin.NET.Core/Job/OnlineUserJob.cs +++ b/Admin.NET/Admin.NET.Core/Job/OnlineUserJob.cs @@ -15,25 +15,25 @@ namespace Admin.NET.Core; [PeriodSeconds(1, TriggerId = "trigger_onlineUser", Description = "清理在线用户", MaxNumberOfRuns = 1, RunOnStart = true)] public class OnlineUserJob : IJob { - private readonly IServiceScopeFactory _scopeFactory; + private readonly IServiceScopeFactory _serviceScopeFactory; private readonly ILogger _logger; - public OnlineUserJob(IServiceScopeFactory scopeFactory, ILoggerFactory loggerFactory) + public OnlineUserJob(IServiceScopeFactory serviceScopeFactory, ILoggerFactory loggerFactory) { - _scopeFactory = scopeFactory; + _serviceScopeFactory = serviceScopeFactory; _logger = loggerFactory.CreateLogger(CommonConst.SysLogCategoryName); } public async Task ExecuteAsync(JobExecutingContext context, CancellationToken stoppingToken) { - using var serviceScope = _scopeFactory.CreateScope(); + using var serviceScope = _serviceScopeFactory.CreateScope(); var db = serviceScope.ServiceProvider.GetRequiredService().CopyNew(); await db.Deleteable().ExecuteCommandAsync(stoppingToken); - string msg = $"【{DateTime.Now}】清理在线用户成功!服务已重启..."; + var msg = $"【{DateTime.Now}】清理系统在线用户。【定时任务】"; var originColor = Console.ForegroundColor; - Console.ForegroundColor = ConsoleColor.Yellow; + Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine(msg); Console.ForegroundColor = originColor; diff --git a/Admin.NET/Admin.NET.Core/Logging/DatabaseLoggingWriter.cs b/Admin.NET/Admin.NET.Core/Logging/DatabaseLoggingWriter.cs index 87209906..e45f1f81 100644 --- a/Admin.NET/Admin.NET.Core/Logging/DatabaseLoggingWriter.cs +++ b/Admin.NET/Admin.NET.Core/Logging/DatabaseLoggingWriter.cs @@ -12,15 +12,17 @@ namespace Admin.NET.Core; public class DatabaseLoggingWriter : IDatabaseLoggingWriter, IDisposable { private readonly IServiceScope _serviceScope; - private readonly SqlSugarScopeProvider _db; - private readonly SysConfigService _sysConfigService; + private readonly IEventPublisher _eventPublisher; private readonly ILogger _logger; + private readonly SysConfigService _sysConfigService; + private readonly SqlSugarScopeProvider _db; - public DatabaseLoggingWriter(IServiceScopeFactory scopeFactory) + public DatabaseLoggingWriter(IServiceScopeFactory serviceScopeFactory, IEventPublisher eventPublisher, ILogger logger) { - _serviceScope = scopeFactory.CreateScope(); + _serviceScope = serviceScopeFactory.CreateScope(); _sysConfigService = _serviceScope.ServiceProvider.GetRequiredService(); - _logger = _serviceScope.ServiceProvider.GetRequiredService>(); + _eventPublisher = eventPublisher; + _logger = logger; // 切换日志独立数据库 _db = SqlSugarSetup.ITenant.IsAnyConnection(SqlSugarConst.LogConfigId) @@ -149,7 +151,7 @@ public class DatabaseLoggingWriter : IDatabaseLoggingWriter, IDisposable // 将异常日志发送到邮件 if (await _sysConfigService.GetConfigValueByCode(ConfigConst.SysErrorMail)) { - await App.GetRequiredService().PublishAsync(CommonConst.SendErrorMail, logMsg.Exception ?? loggingMonitor.exception); + await _eventPublisher.PublishAsync(CommonConst.SendErrorMail, logMsg.Exception ?? loggingMonitor.exception); } return; diff --git a/Admin.NET/Admin.NET.Core/Logging/LoggingSetup.cs b/Admin.NET/Admin.NET.Core/Logging/LoggingSetup.cs index b56f1d0b..e673dcb3 100644 --- a/Admin.NET/Admin.NET.Core/Logging/LoggingSetup.cs +++ b/Admin.NET/Admin.NET.Core/Logging/LoggingSetup.cs @@ -45,7 +45,7 @@ public static class LoggingSetup options.WithTraceId = true; // 显示线程Id options.WithStackFrame = true; // 显示程序集 options.FileNameRule = fileName => string.Format(fileName, DateTime.Now, logLevel.ToString()); // 每天创建一个文件 - options.WriteFilter = logMsg => logMsg.LogLevel >= logLevel; // 日志级别 + options.WriteFilter = logMsg => logMsg.LogLevel == logLevel; // 日志级别 options.HandleWriteError = (writeError) => // 写入失败时启用备用文件 { writeError.UseRollbackFileName(Path.GetFileNameWithoutExtension(writeError.CurrentFileName) + "-oops" + Path.GetExtension(writeError.CurrentFileName)); @@ -96,7 +96,7 @@ public static class LoggingSetup }; options.WriteFilter = (logMsg) => { - return logMsg.LogName == CommonConst.SysLogCategoryName; // 只写LoggingMonitor日志 + return logMsg.LogName == CommonConst.SysLogCategoryName; // 只记录 LoggingMonitor 分组名称的日志 }; }); } diff --git a/Admin.NET/Admin.NET.Core/SeedData/SysAppSeedData.cs b/Admin.NET/Admin.NET.Core/SeedData/SysAppSeedData.cs index a16f34af..e17086ae 100644 --- a/Admin.NET/Admin.NET.Core/SeedData/SysAppSeedData.cs +++ b/Admin.NET/Admin.NET.Core/SeedData/SysAppSeedData.cs @@ -17,9 +17,9 @@ public class SysAppSeedData : ISqlSugarEntitySeedData /// public IEnumerable HasData() { - return new[] - { + return + [ new SysApp{ Id=SqlSugarConst.DefaultAppId, Name="默认应用", Logo="/upload/logo.png", Title="Admin.NET", ViceTitle="Admin.NET", ViceDesc="站在巨人肩膀上的 .NET 通用权限开发框架", Watermark="Admin.NET", Copyright="Copyright \u00a9 2021-present Admin.NET All rights reserved.", Icp="省ICP备12345678号", Remark="系统默认应用", CreateTime=DateTime.Parse("2022-02-10 00:00:00") }, - }; + ]; } } \ No newline at end of file diff --git a/Admin.NET/Admin.NET.Core/SeedData/SysCodeGenTemplateSeedData.cs b/Admin.NET/Admin.NET.Core/SeedData/SysCodeGenTemplateSeedData.cs index 004f8cae..e231de7b 100644 --- a/Admin.NET/Admin.NET.Core/SeedData/SysCodeGenTemplateSeedData.cs +++ b/Admin.NET/Admin.NET.Core/SeedData/SysCodeGenTemplateSeedData.cs @@ -17,8 +17,8 @@ public class SysCodeGenTemplateSeedData : ISqlSugarEntitySeedData public IEnumerable HasData() { - return new[] - { + return + [ new SysCodeGenTemplate{ Id=36036980201001, SysFlag=YesNoEnum.Y, Type=CodeGenTypeEnum.Frontend, Name="web_api.ts.vm", OutputFile="api/{PagePath}/{TableNameLower}.ts", Describe ="(WEB)接口",IsDefault=true}, new SysCodeGenTemplate{ Id=36036980201002, SysFlag=YesNoEnum.Y, Type=CodeGenTypeEnum.Frontend, Name="web_views_index.vue.vm", OutputFile="views/{PagePath}/{TableNameLower}/index.vue", Describe ="(WEB)列表页面",IsDefault=true}, new SysCodeGenTemplate{ Id=36036980201003, SysFlag=YesNoEnum.Y, Type=CodeGenTypeEnum.Frontend, Name="web_views_editDialog.vue.vm", OutputFile="views/{PagePath}/{TableNameLower}/component/editDialog.vue", Describe ="(WEB)编辑对话框",IsDefault=true}, @@ -29,6 +29,6 @@ public class SysCodeGenTemplateSeedData : ISqlSugarEntitySeedData /// public IEnumerable HasData() { - return new[] - { + return + [ new SysOrg{ Id=SqlSugarConst.DefaultTenantId, Pid=0, Name="系统默认", Code="1001", Type="101", Level=1, CreateTime=DateTime.Parse("2022-02-10 00:00:00"), Remark="系统默认", TenantId=SqlSugarConst.DefaultTenantId }, new SysOrg{ Id=SqlSugarConst.DefaultTenantId + 1, Pid=SqlSugarConst.DefaultTenantId, Name="市场部", Code="100101", Level=2, CreateTime=DateTime.Parse("2022-02-10 00:00:00"), Remark="市场部", TenantId=SqlSugarConst.DefaultTenantId }, new SysOrg{ Id=SqlSugarConst.DefaultTenantId + 2, Pid=SqlSugarConst.DefaultTenantId, Name="开发部", Code="100102", Level=2, CreateTime=DateTime.Parse("2022-02-10 00:00:00"), Remark="开发部", TenantId=SqlSugarConst.DefaultTenantId }, new SysOrg{ Id=SqlSugarConst.DefaultTenantId + 3, Pid=SqlSugarConst.DefaultTenantId, Name="售后部", Code="100103", Level=2, CreateTime=DateTime.Parse("2022-02-10 00:00:00"), Remark="售后部", TenantId=SqlSugarConst.DefaultTenantId }, new SysOrg{ Id=SqlSugarConst.DefaultTenantId + 4, Pid=SqlSugarConst.DefaultTenantId, Name="其他", Code="10010301", Level=3, CreateTime=DateTime.Parse("2022-02-10 00:00:00"), Remark="其他", TenantId=SqlSugarConst.DefaultTenantId }, - }; + ]; } } \ No newline at end of file diff --git a/Admin.NET/Admin.NET.Core/SeedData/SysPosSeedData.cs b/Admin.NET/Admin.NET.Core/SeedData/SysPosSeedData.cs index 64b62e65..bbd5a5a5 100644 --- a/Admin.NET/Admin.NET.Core/SeedData/SysPosSeedData.cs +++ b/Admin.NET/Admin.NET.Core/SeedData/SysPosSeedData.cs @@ -17,8 +17,8 @@ public class SysPosSeedData : ISqlSugarEntitySeedData /// public IEnumerable HasData() { - return new[] - { + return + [ new SysPos{ Id=1300000000101, Name="党委书记", Code="dwsj", CreateTime=DateTime.Parse("2022-02-10 00:00:00"), Remark="党委书记", TenantId=SqlSugarConst.DefaultTenantId }, new SysPos{ Id=1300000000102, Name="董事长", Code="dsz", CreateTime=DateTime.Parse("2022-02-10 00:00:00"), Remark="董事长", TenantId=SqlSugarConst.DefaultTenantId }, new SysPos{ Id=1300000000103, Name="副董事长", Code="fdsz", CreateTime=DateTime.Parse("2022-02-10 00:00:00"), Remark="副董事长", TenantId=SqlSugarConst.DefaultTenantId }, @@ -35,6 +35,6 @@ public class SysPosSeedData : ISqlSugarEntitySeedData new SysPos{ Id=1300000000114, Name="财务", Code="cw", CreateTime=DateTime.Parse("2022-02-10 00:00:00"), Remark="财务", TenantId=SqlSugarConst.DefaultTenantId }, new SysPos{ Id=1300000000115, Name="职员", Code="zy", CreateTime=DateTime.Parse("2022-02-10 00:00:00"), Remark="职员", TenantId=SqlSugarConst.DefaultTenantId }, new SysPos{ Id=1300000000116, Name="其他", Code="qt", CreateTime=DateTime.Parse("2022-02-10 00:00:00"), Remark="其他", TenantId=SqlSugarConst.DefaultTenantId }, - }; + ]; } } \ No newline at end of file diff --git a/Admin.NET/Admin.NET.Core/SeedData/SysRoleMenuSeedData.cs b/Admin.NET/Admin.NET.Core/SeedData/SysRoleMenuSeedData.cs index 60ff929d..87b0720f 100644 --- a/Admin.NET/Admin.NET.Core/SeedData/SysRoleMenuSeedData.cs +++ b/Admin.NET/Admin.NET.Core/SeedData/SysRoleMenuSeedData.cs @@ -17,8 +17,8 @@ public class SysRoleMenuSeedData : ISqlSugarEntitySeedData /// public IEnumerable HasData() { - return new[] - { + return + [ ////// 数据面板【admin/1300000000101】 new SysRoleMenu{ Id=1300000000101, RoleId=1300000000101, MenuId=1300000000101 }, new SysRoleMenu{ Id=1300000000102, RoleId=1300000000101, MenuId=1300000000111 }, @@ -237,6 +237,6 @@ public class SysRoleMenuSeedData : ISqlSugarEntitySeedData new SysRoleMenu{ Id=1300000000823, RoleId=1300000000105, MenuId=1310000000163 }, new SysRoleMenu{ Id=1300000000824, RoleId=1300000000105, MenuId=1310000000164 }, new SysRoleMenu{ Id=1300000000825, RoleId=1300000000105, MenuId=1310000000165 }, - }; + ]; } } \ No newline at end of file diff --git a/Admin.NET/Admin.NET.Core/SeedData/SysRoleSeedData.cs b/Admin.NET/Admin.NET.Core/SeedData/SysRoleSeedData.cs index 5dc8c8fe..f2abaf1a 100644 --- a/Admin.NET/Admin.NET.Core/SeedData/SysRoleSeedData.cs +++ b/Admin.NET/Admin.NET.Core/SeedData/SysRoleSeedData.cs @@ -17,13 +17,13 @@ public class SysRoleSeedData : ISqlSugarEntitySeedData /// public IEnumerable HasData() { - return new[] - { + return + [ new SysRole{ Id=1300000000101, Name="系统管理员", DataScope=DataScopeEnum.All, Code="sys_admin", CreateTime=DateTime.Parse("2022-02-10 00:00:00"), Remark="系统管理员", TenantId=SqlSugarConst.DefaultTenantId }, new SysRole{ Id=1300000000102, Name="本部门及以下数据", DataScope=DataScopeEnum.DeptChild, Code="sys_deptChild", CreateTime=DateTime.Parse("2022-02-10 00:00:00"), Remark="本部门及以下数据", TenantId=SqlSugarConst.DefaultTenantId }, new SysRole{ Id=1300000000103, Name="本部门数据", DataScope=DataScopeEnum.Dept, Code="sys_dept", CreateTime=DateTime.Parse("2022-02-10 00:00:00"), Remark="本部门数据", TenantId=SqlSugarConst.DefaultTenantId }, new SysRole{ Id=1300000000104, Name="仅本人数据", DataScope=DataScopeEnum.Self, Code="sys_self", CreateTime=DateTime.Parse("2022-02-10 00:00:00"), Remark="仅本人数据", TenantId=SqlSugarConst.DefaultTenantId }, new SysRole{ Id=1300000000105, Name="自定义数据", DataScope=DataScopeEnum.Define, Code="sys_define", CreateTime=DateTime.Parse("2022-02-10 00:00:00"), Remark="自定义数据", TenantId=SqlSugarConst.DefaultTenantId }, - }; + ]; } } \ No newline at end of file diff --git a/Admin.NET/Admin.NET.Core/SeedData/SysTenantSeedData.cs b/Admin.NET/Admin.NET.Core/SeedData/SysTenantSeedData.cs index 449de3e2..7e96bb7c 100644 --- a/Admin.NET/Admin.NET.Core/SeedData/SysTenantSeedData.cs +++ b/Admin.NET/Admin.NET.Core/SeedData/SysTenantSeedData.cs @@ -19,9 +19,9 @@ public class SysTenantSeedData : ISqlSugarEntitySeedData { var defaultDbConfig = App.GetOptions().ConnectionConfigs[0]; - return new[] - { + return + [ new SysTenant{ Id=SqlSugarConst.DefaultTenantId, AppId=SqlSugarConst.DefaultTenantId, OrgId=SqlSugarConst.DefaultTenantId, UserId=1300000000111, Host=SqlSugarConst.DefaultTenantHost, TenantType=TenantTypeEnum.Id, DbType=defaultDbConfig.DbType, Connection=defaultDbConfig.ConnectionString, ConfigId=SqlSugarConst.MainConfigId, Remark="系统默认", CreateTime=DateTime.Parse("2022-02-10 00:00:00") }, - }; + ]; } } \ No newline at end of file diff --git a/Admin.NET/Admin.NET.Core/SeedData/SysUserExtOrgSeedData.cs b/Admin.NET/Admin.NET.Core/SeedData/SysUserExtOrgSeedData.cs index c3f4bbdf..3b105f49 100644 --- a/Admin.NET/Admin.NET.Core/SeedData/SysUserExtOrgSeedData.cs +++ b/Admin.NET/Admin.NET.Core/SeedData/SysUserExtOrgSeedData.cs @@ -17,10 +17,10 @@ public class SysUserExtOrgSeedData : ISqlSugarEntitySeedData /// public IEnumerable HasData() { - return new[] - { + return + [ new SysUserExtOrg{ Id=1300000000101, UserId=1300000000111, OrgId=1300000000202, PosId=1300000000106 }, new SysUserExtOrg{ Id=1300000000102, UserId=1300000000114, OrgId=1300000000302, PosId=1300000000108 } - }; + ]; } } \ No newline at end of file diff --git a/Admin.NET/Admin.NET.Core/SeedData/SysUserRoleSeedData.cs b/Admin.NET/Admin.NET.Core/SeedData/SysUserRoleSeedData.cs index 8f34bd0e..8e26525d 100644 --- a/Admin.NET/Admin.NET.Core/SeedData/SysUserRoleSeedData.cs +++ b/Admin.NET/Admin.NET.Core/SeedData/SysUserRoleSeedData.cs @@ -17,13 +17,13 @@ public class SysUserRoleSeedData : ISqlSugarEntitySeedData /// public IEnumerable HasData() { - return new[] - { + return + [ new SysUserRole{ Id=1300000000101, UserId=1300000000111, RoleId=1300000000101 }, new SysUserRole{ Id=1300000000102, UserId=1300000000112, RoleId=1300000000102 }, new SysUserRole{ Id=1300000000103, UserId=1300000000113, RoleId=1300000000103 }, new SysUserRole{ Id=1300000000104, UserId=1300000000114, RoleId=1300000000104 }, new SysUserRole{ Id=1300000000105, UserId=1300000000115, RoleId=1300000000105 }, - }; + ]; } } \ No newline at end of file diff --git a/Admin.NET/Admin.NET.Core/SeedData/SysUserSeedData.cs b/Admin.NET/Admin.NET.Core/SeedData/SysUserSeedData.cs index cd386603..fa47631f 100644 --- a/Admin.NET/Admin.NET.Core/SeedData/SysUserSeedData.cs +++ b/Admin.NET/Admin.NET.Core/SeedData/SysUserSeedData.cs @@ -20,14 +20,14 @@ public class SysUserSeedData : ISqlSugarEntitySeedData { var encryptPassword = CryptogramUtil.Encrypt("Admin.NET++010101"); - return new[] - { + return + [ new SysUser{ Id=1300000000101, Account="superadmin", Password=encryptPassword, NickName="超级管理员", RealName="超级管理员", Phone="18012345678", Birthday=DateTime.Parse("2000-01-01"), Sex=GenderEnum.Male, AccountType=AccountTypeEnum.SuperAdmin, Remark="超级管理员", CreateTime=DateTime.Parse("2022-02-10 00:00:00"), TenantId=SqlSugarConst.DefaultTenantId }, new SysUser{ Id=1300000000111, Account="admin", Password=encryptPassword, NickName="系统管理员", RealName="系统管理员", Phone="18012345678", Birthday=DateTime.Parse("2000-01-01"), Sex=GenderEnum.Male, AccountType=AccountTypeEnum.SysAdmin, Remark="系统管理员", CreateTime=DateTime.Parse("2022-02-10 00:00:00"), OrgId=SqlSugarConst.DefaultTenantId, PosId=1300000000102, TenantId=SqlSugarConst.DefaultTenantId }, new SysUser{ Id=1300000000112, Account="user1", Password=encryptPassword, NickName="部门主管", RealName="部门主管", Phone="18012345678", Birthday=DateTime.Parse("2000-01-01"), Sex=GenderEnum.Female, AccountType=AccountTypeEnum.NormalUser, Remark="部门主管", CreateTime=DateTime.Parse("2022-02-10 00:00:00"), OrgId=SqlSugarConst.DefaultTenantId + 1, PosId=1300000000108, TenantId=SqlSugarConst.DefaultTenantId }, new SysUser{ Id=1300000000113, Account="user2", Password=encryptPassword, NickName="部门职员", RealName="部门职员", Phone="18012345678", Birthday=DateTime.Parse("2000-01-01"), Sex=GenderEnum.Female, AccountType=AccountTypeEnum.NormalUser, Remark="部门职员", CreateTime=DateTime.Parse("2022-02-10 00:00:00"), OrgId=SqlSugarConst.DefaultTenantId + 2, PosId=1300000000110, TenantId=SqlSugarConst.DefaultTenantId }, new SysUser{ Id=1300000000114, Account="user3", Password=encryptPassword, NickName="普通用户", RealName="普通用户", Phone="18012345678", Birthday=DateTime.Parse("2000-01-01"), Sex=GenderEnum.Female, AccountType=AccountTypeEnum.NormalUser, Remark="普通用户", CreateTime=DateTime.Parse("2022-02-10 00:00:00"), OrgId=SqlSugarConst.DefaultTenantId + 3, PosId=1300000000115, TenantId=SqlSugarConst.DefaultTenantId }, new SysUser{ Id=1300000000115, Account="user4", Password=encryptPassword, NickName="其他", RealName="其他", Phone="18012345678", Birthday=DateTime.Parse("2000-01-01"), Sex=GenderEnum.Female, AccountType=AccountTypeEnum.Member, Remark="会员", CreateTime=DateTime.Parse("2022-02-10 00:00:00"), OrgId=SqlSugarConst.DefaultTenantId + 4, PosId=1300000000116, TenantId=SqlSugarConst.DefaultTenantId }, - }; + ]; } } \ No newline at end of file diff --git a/Admin.NET/Admin.NET.Core/Service/Job/JobMonitor.cs b/Admin.NET/Admin.NET.Core/Service/Job/JobMonitor.cs index 3edb7753..ac525c4d 100644 --- a/Admin.NET/Admin.NET.Core/Service/Job/JobMonitor.cs +++ b/Admin.NET/Admin.NET.Core/Service/Job/JobMonitor.cs @@ -11,16 +11,16 @@ namespace Admin.NET.Core.Service; /// public class JobMonitor : IJobMonitor { - private readonly IEventPublisher _eventPublisher; private readonly SysConfigService _sysConfigService; + private readonly IEventPublisher _eventPublisher; private readonly ILogger _logger; - public JobMonitor(IServiceScopeFactory scopeFactory) + public JobMonitor(IServiceScopeFactory serviceScopeFactory, IEventPublisher eventPublisher, ILogger logger) { - var serviceScope = scopeFactory.CreateScope(); + var serviceScope = serviceScopeFactory.CreateScope(); _sysConfigService = serviceScope.ServiceProvider.GetRequiredService(); - _eventPublisher = serviceScope.ServiceProvider.GetRequiredService(); - _logger = serviceScope.ServiceProvider.GetRequiredService>(); + _eventPublisher = eventPublisher; + _logger = logger; } public Task OnExecutingAsync(JobExecutingContext context, CancellationToken stoppingToken) @@ -32,16 +32,14 @@ public class JobMonitor : IJobMonitor { if (context.Exception == null) return; - var errorInfo = $"【{context.Trigger.Description}】定时任务错误:{context.Exception}"; + var exception = $"定时任务【{context.Trigger.Description}】错误:{context.Exception}"; + // 将作业异常信息记录到本地 + _logger.LogError(exception); + if (await _sysConfigService.GetConfigValueByCode(ConfigConst.SysErrorMail)) { - // 将异常作业发送到邮件 - await _eventPublisher.PublishAsync(CommonConst.SendErrorMail, errorInfo, stoppingToken); - } - else - { - // 将异常信息存储本地记录 - _logger.LogError(errorInfo); + // 将作业异常信息发送到邮件 + await _eventPublisher.PublishAsync(CommonConst.SendErrorMail, exception, stoppingToken); } } } \ No newline at end of file diff --git a/Admin.NET/Admin.NET.Core/SqlSugar/SqlSugarSetup.cs b/Admin.NET/Admin.NET.Core/SqlSugar/SqlSugarSetup.cs index 1898b3d0..6ead6997 100644 --- a/Admin.NET/Admin.NET.Core/SqlSugar/SqlSugarSetup.cs +++ b/Admin.NET/Admin.NET.Core/SqlSugar/SqlSugarSetup.cs @@ -389,15 +389,27 @@ public static class SqlSugarSetup else entityTypes = entityTypes.Where(u => u.GetCustomAttribute()?.configId.ToString() == config.ConfigId.ToString()).ToList(); // 自定义的库 - int count = 0, sum = entityTypes.Count; - foreach (var entityType in entityTypes) + int taskIndex = 0, entityTypeCount = entityTypes.Count; + var taskList = entityTypes.Select(entityType => Task.Run(() => { - Console.WriteLine($"创建表 {entityType} ({config.ConfigId} - {++count}/{sum})"); + Console.ForegroundColor = ConsoleColor.Green; + Console.WriteLine($"初始化表 {entityType,-64} ({config.ConfigId} - {Interlocked.Increment(ref taskIndex):D003}/{entityTypeCount:D003})"); + + // 将不存在实体中的字段改为可空 + var entityInfo = dbProvider.EntityMaintenance.GetEntityInfo(entityType); + var dbColumnInfos = dbProvider.DbMaintenance.GetColumnInfosByTableName(entityInfo.DbTableName) ?? []; + foreach (var dbColumnInfo in dbColumnInfos.Where(dbColumnInfo => entityInfo.Columns.All(u => u.DbColumnName != dbColumnInfo.DbColumnName))) + { + dbColumnInfo.IsNullable = true; + dbProvider.DbMaintenance.UpdateColumn(entityInfo.DbTableName, dbColumnInfo); + } + if (entityType.GetCustomAttribute() == null) dbProvider.CodeFirst.InitTables(entityType); else dbProvider.CodeFirst.SplitTables().InitTables(entityType); - } + })); + Task.WaitAll(taskList.ToArray()); } // 初始化种子数据 @@ -420,35 +432,33 @@ public static class SqlSugarSetup .WhereIF(config.SeedSettings.EnableIncreSeed, u => u.IsDefined(typeof(IncreSeedAttribute), false)) .OrderBy(u => u.GetCustomAttributes(typeof(SeedDataAttribute), false).Length > 0 ? ((SeedDataAttribute)u.GetCustomAttributes(typeof(SeedDataAttribute), false)[0]).Order : 0).ToList(); - int count = 0, sum = seedDataTypes.Count; + int taskIndex = 0, seedDataTypeCount = seedDataTypes.Count; foreach (var seedType in seedDataTypes) { var entityType = seedType.GetInterfaces().First().GetGenericArguments().First(); if (config.ConfigId.ToString() == SqlSugarConst.MainConfigId) // 默认库(有系统表特性、没有日志表和租户表特性) { if (entityType.GetCustomAttribute() == null && (entityType.GetCustomAttribute() != null || entityType.GetCustomAttribute() != null)) - continue; + return; } else if (config.ConfigId.ToString() == SqlSugarConst.LogConfigId) // 日志库 { if (entityType.GetCustomAttribute() == null) - continue; + return; } else { var att = entityType.GetCustomAttribute(); // 自定义的库 - if (att == null || att.configId.ToString() != config.ConfigId.ToString()) continue; + if (att == null || att.configId.ToString() != config.ConfigId.ToString()) return; } var instance = Activator.CreateInstance(seedType); var hasDataMethod = seedType.GetMethod("HasData"); var seedData = ((IEnumerable)hasDataMethod?.Invoke(instance, null))?.Cast(); - if (seedData == null) continue; - - var entityInfo = dbProvider.EntityMaintenance.GetEntityInfo(entityType); - Console.WriteLine($"添加数据 {entityInfo.DbTableName} ({config.ConfigId} - {++count}/{sum},数据量:{seedData.Count()})"); + if (seedData == null) return; // 若实体包含Id字段,则设置为当前租户Id递增1 + var entityInfo = dbProvider.EntityMaintenance.GetEntityInfo(entityType); if (entityInfo.Columns.Any(u => u.PropertyName == nameof(EntityBaseId.Id))) { var seedId = config.ConfigId.ToLong(); @@ -470,26 +480,31 @@ public static class SqlSugarSetup } else { + var seedDataList = seedData.ToList(); + int updateCount = 0, insertCount = 0; + // 按主键进行批量增加和更新 if (entityInfo.Columns.Any(u => u.IsPrimarykey)) { - // 按主键进行批量增加和更新 - var storage = dbProvider.StorageableByObject(seedData.ToList()).ToStorage(); - // 先修改再插入,否则会更新修改时间字段 + var storage = dbProvider.StorageableByObject(seedDataList).ToStorage(); if (seedType.GetCustomAttribute() == null) // 有忽略更新种子特性时则不更新 { - int updateCount = storage.AsUpdateable.IgnoreColumns(entityInfo.Columns.Where(u => u.PropertyInfo.GetCustomAttribute() != null).Select(u => u.PropertyName).ToArray()).ExecuteCommand(); - Console.WriteLine($" 修改 {updateCount}/{seedData.Count()} 条记录"); + updateCount = storage.AsUpdateable.IgnoreColumns(entityInfo.Columns.Where(u => u.PropertyInfo.GetCustomAttribute() != null) + .Select(u => u.PropertyName).ToArray()).ExecuteCommand(); } - int insertCount = storage.AsInsertable.ExecuteCommand(); - Console.WriteLine($" 插入 {insertCount}/{seedData.Count()} 条记录"); + insertCount = storage.AsInsertable.ExecuteCommand(); } + // 无主键则只进行插入 else { - // 无主键则只进行插入 if (!dbProvider.Queryable(entityInfo.DbTableName, entityInfo.DbTableName).Any()) - dbProvider.InsertableByObject(seedData.ToList()).ExecuteCommand(); + { + insertCount = seedDataList.Count; + dbProvider.InsertableByObject(seedDataList).ExecuteCommand(); + } } + Console.ForegroundColor = ConsoleColor.Green; + Console.WriteLine($"初始化种子数据 {seedType.FullName,-58} ({config.ConfigId} - {Interlocked.Increment(ref taskIndex):D003}/{seedDataTypeCount:D003},数据量:{seedDataList.Count:D003},新增 {insertCount:D003} 条记录,更新 {updateCount:D003} 条记录)"); } } diff --git a/Admin.NET/Admin.NET.Web.Core/Startup.cs b/Admin.NET/Admin.NET.Web.Core/Startup.cs index fb5b249b..5e2876f6 100644 --- a/Admin.NET/Admin.NET.Web.Core/Startup.cs +++ b/Admin.NET/Admin.NET.Web.Core/Startup.cs @@ -78,14 +78,14 @@ public class Startup : AppStartup { if (App.GetConfig("JobSchedule:Enabled", true)) { + options.LogEnabled = false; // 是否输出作业调度器日志 options.AddPersistence(); // 添加作业持久化器 options.AddMonitor(); // 添加作业执行监视器 - // 定义未捕获的异常 - options.UnobservedTaskExceptionHandler = (obj, args) => - { - if (args.Exception?.Message != null) - Log.Error($"JobSchedule 有未处理异常:{args.Exception?.Message}", args.Exception); - }; + //// 定义未捕获的异常 + //options.UnobservedTaskExceptionHandler = (obj, args) => + //{ + // Log.Error($"作业调度异常:{args.Exception?.Message}", args.Exception); + //}; } }); // 脱敏检测 diff --git a/Web/package.json b/Web/package.json index 5d950c52..4af16902 100644 --- a/Web/package.json +++ b/Web/package.json @@ -2,7 +2,7 @@ "name": "admin.net.pro", "type": "module", "version": "2.4.33", - "lastBuildTime": "2025.01.04", + "lastBuildTime": "2025.01.06", "description": "Admin.NET 站在巨人肩膀上的 .NET 通用权限开发框架", "author": "zuohuaijun", "license": "MIT", @@ -74,18 +74,18 @@ "vue-router": "^4.5.0", "vue-signature-pad": "^3.0.2", "vue3-tree-org": "^4.2.2", - "vxe-pc-ui": "^4.3.61", - "vxe-table": "^4.10.0", + "vxe-pc-ui": "^4.3.65", + "vxe-table": "^4.10.1", "vxe-table-plugin-element": "^4.0.4", "vxe-table-plugin-export-xlsx": "^4.0.7", "xe-utils": "^3.7.0", "xlsx-js-style": "^1.2.0" }, "devDependencies": { - "@iconify/vue": "^4.2.0", + "@iconify/vue": "^4.3.0", "@plugin-web-update-notification/vite": "^1.7.1", "@types/lodash-es": "^4.17.12", - "@types/node": "^20.17.10", + "@types/node": "^20.17.11", "@types/nprogress": "^0.2.3", "@types/sortablejs": "^1.15.8", "@typescript-eslint/eslint-plugin": "^8.19.0", @@ -100,7 +100,7 @@ "less": "^4.2.1", "prettier": "^3.4.2", "rollup-plugin-visualizer": "^5.13.1", - "sass": "^1.83.0", + "sass": "^1.83.1", "terser": "^5.37.0", "typescript": "^5.7.2", "vite": "^6.0.7", diff --git a/Web/src/layout/navBars/topBar/user.vue b/Web/src/layout/navBars/topBar/user.vue index d5ba47e8..c51e2629 100644 --- a/Web/src/layout/navBars/topBar/user.vue +++ b/Web/src/layout/navBars/topBar/user.vue @@ -187,7 +187,11 @@ const onHandleCommandClick = (path: string) => { if (action === 'confirm') { instance.confirmButtonLoading = true; instance.confirmButtonText = t('message.user.logOutExit'); - await getAPI(SysAuthApi).apiSysAuthLogoutPost(); + try { + await getAPI(SysAuthApi).apiSysAuthLogoutPost(); + } catch (error) { + console.error(error); + } instance.confirmButtonLoading = false; done(); } else { diff --git a/Web/src/views/system/config/component/editConfig.vue b/Web/src/views/system/config/component/editConfig.vue index 81031ef7..9d88af42 100644 --- a/Web/src/views/system/config/component/editConfig.vue +++ b/Web/src/views/system/config/component/editConfig.vue @@ -41,7 +41,7 @@ } " > - 选项 + 选项