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