Explorar el Código

😎代码整理(细节优化)

zuohuaijun hace 1 año
padre
commit
af33d52e17

+ 2 - 2
Admin.NET/Admin.NET.Core/Extension/ObjectExtension.cs

@@ -333,8 +333,8 @@ public static partial class ObjectExtension
     {
         if (!email.TryValidate(ValidationTypes.EmailAddress).IsValid) return email;
 
-        var masks = mask.ToString().PadLeft(4, mask);
-        return email.Replace(@"^([^\.]+)\.?", $"$1{masks}$2");
+        var pos = email.IndexOf("@");
+        return Mask(email[..pos], mask) + email[pos..];
     }
 
     /// <summary>

+ 9 - 7
Admin.NET/Admin.NET.Core/Hub/OnlineUserHub.cs

@@ -47,6 +47,7 @@ public class OnlineUserHub : Hub<IOnlineUserHub>
         var account = httpContext.User.FindFirst(ClaimConst.Account)?.Value;
         var realName = httpContext.User.FindFirst(ClaimConst.RealName)?.Value;
         var tenantId = (httpContext.User.FindFirst(ClaimConst.TenantId)?.Value).ToLong();
+        var device = httpContext.GetClientDeviceInfo().Trim();
 
         if (userId < 0 || string.IsNullOrWhiteSpace(account)) return;
         var user = new SysOnlineUser
@@ -66,12 +67,11 @@ public class OnlineUserHub : Hub<IOnlineUserHub>
         // 是否开启单用户登录
         if (await _sysConfigService.GetConfigValue<bool>(ConfigConst.SysSingleLogin))
         {
-            _sysCacheService.Set(CacheConst.KeyUserOnline + user.UserId, user);
+            _sysCacheService.HashAdd(CacheConst.KeyUserOnline, "" + user.UserId, user);
         }
-        else
+        else  // 非单用户登录则绑定用户设备信息
         {
-            var device = httpContext.GetClientDeviceInfo().Trim();
-            _sysCacheService.Set(CacheConst.KeyUserOnline + user.UserId + device, user);
+            _sysCacheService.HashAdd(CacheConst.KeyUserOnline, user.UserId + device, user);
         }
 
         // 以租户Id进行分组
@@ -102,17 +102,19 @@ public class OnlineUserHub : Hub<IOnlineUserHub>
         var user = await _sysOnlineUerRep.AsQueryable().Filter("", true).FirstAsync(u => u.ConnectionId == Context.ConnectionId);
         if (user == null) return;
 
-        await _sysOnlineUerRep.DeleteAsync(u => u.Id == user.Id);
+        await _sysOnlineUerRep.DeleteByIdAsync(user.Id);
 
         // 是否开启单用户登录
         if (await _sysConfigService.GetConfigValue<bool>(ConfigConst.SysSingleLogin))
         {
-            _sysCacheService.Remove(CacheConst.KeyUserOnline + user.UserId);
+            _sysCacheService.HashDel<SysOnlineUser>(CacheConst.KeyUserOnline, "" + user.UserId);
+            // _sysCacheService.Remove(CacheConst.KeyUserOnline + user.UserId);
         }
         else
         {
             var device = httpContext.GetClientDeviceInfo().Trim();
-            _sysCacheService.Remove(CacheConst.KeyUserOnline + user.UserId + device);
+            _sysCacheService.HashDel<SysOnlineUser>(CacheConst.KeyUserOnline, user.UserId + device);
+            // _sysCacheService.Remove(CacheConst.KeyUserOnline + user.UserId + device);
         }
 
         // 通知当前组用户变动

+ 4 - 6
Admin.NET/Admin.NET.Core/Job/LogJob.cs

@@ -26,15 +26,13 @@ public class LogJob : IJob
     {
         using var serviceScope = _scopeFactory.CreateScope();
 
-        var logVisRep = serviceScope.ServiceProvider.GetRequiredService<SqlSugarRepository<SysLogVis>>();
-        var logOpRep = serviceScope.ServiceProvider.GetRequiredService<SqlSugarRepository<SysLogOp>>();
-        var logDiffRep = serviceScope.ServiceProvider.GetRequiredService<SqlSugarRepository<SysLogDiff>>();
+        var db = serviceScope.ServiceProvider.GetRequiredService<ISqlSugarClient>().CopyNew();
         var sysConfigService = serviceScope.ServiceProvider.GetRequiredService<SysConfigService>();
 
         var daysAgo = await sysConfigService.GetConfigValue<int>(ConfigConst.SysLogRetentionDays); // 日志保留天数
-        await logVisRep.CopyNew().AsDeleteable().Where(u => u.CreateTime < DateTime.Now.AddDays(-daysAgo)).ExecuteCommandAsync(stoppingToken); // 删除访问日志
-        await logOpRep.CopyNew().AsDeleteable().Where(u => u.CreateTime < DateTime.Now.AddDays(-daysAgo)).ExecuteCommandAsync(stoppingToken); // 删除操作日志
-        await logDiffRep.CopyNew().AsDeleteable().Where(u => u.CreateTime < DateTime.Now.AddDays(-daysAgo)).ExecuteCommandAsync(stoppingToken); // 删除差异日志
+        await db.Deleteable<SysLogVis>().Where(u => u.CreateTime < DateTime.Now.AddDays(-daysAgo)).ExecuteCommandAsync(stoppingToken); // 删除访问日志
+        await db.Deleteable<SysLogOp>().Where(u => u.CreateTime < DateTime.Now.AddDays(-daysAgo)).ExecuteCommandAsync(stoppingToken); // 删除操作日志
+        await db.Deleteable<SysLogDiff>().Where(u => u.CreateTime < DateTime.Now.AddDays(-daysAgo)).ExecuteCommandAsync(stoppingToken); // 删除差异日志
 
         string msg = $"【{DateTime.Now}】清理系统日志成功,删除 {daysAgo} 天前的日志数据!";
         var originColor = Console.ForegroundColor;

+ 5 - 5
Admin.NET/Admin.NET.Core/Job/OnlineUserJob.cs

@@ -28,11 +28,8 @@ public class OnlineUserJob : IJob
     {
         using var serviceScope = _scopeFactory.CreateScope();
 
-        var rep = serviceScope.ServiceProvider.GetRequiredService<SqlSugarRepository<SysOnlineUser>>();
-        await rep.CopyNew().AsDeleteable().ExecuteCommandAsync(stoppingToken);
-
-        // 缓存租户列表
-        await serviceScope.ServiceProvider.GetRequiredService<SysTenantService>().CacheTenant();
+        var db = serviceScope.ServiceProvider.GetRequiredService<ISqlSugarClient>().CopyNew();
+        await db.Deleteable<SysOnlineUser>().ExecuteCommandAsync(stoppingToken);
 
         string msg = $"【{DateTime.Now}】清理在线用户成功!服务已重启...";
         var originColor = Console.ForegroundColor;
@@ -42,5 +39,8 @@ public class OnlineUserJob : IJob
 
         // 自定义日志
         _logger.LogInformation(msg);
+
+        // 缓存租户列表
+        await serviceScope.ServiceProvider.GetRequiredService<SysTenantService>().CacheTenant();
     }
 }

+ 3 - 4
Admin.NET/Admin.NET.Core/Service/Dict/SysDictDataService.cs

@@ -42,7 +42,6 @@ public class SysDictDataService : IDynamicApiController, ITransient
     /// 获取字典值列表 🔖
     /// </summary>
     /// <returns></returns>
-    [UnitOfWork]
     [DisplayName("获取字典值列表")]
     public async Task<List<SysDictData>> GetList([FromQuery] GetDataDictDataInput input)
     {
@@ -99,7 +98,7 @@ public class SysDictDataService : IDynamicApiController, ITransient
     [DisplayName("删除字典值")]
     public async Task DeleteDictData(DeleteDictDataInput input)
     {
-        var dictData = await _sysDictDataRep.GetFirstAsync(u => u.Id == input.Id) ?? throw Oops.Oh(ErrorCodeEnum.D3004);
+        var dictData = await _sysDictDataRep.GetByIdAsync(input.Id) ?? throw Oops.Oh(ErrorCodeEnum.D3004);
 
         var dictTypeCode = await _sysDictDataRep.AsQueryable().Where(u => u.DictTypeId == dictData.Id).Select(u => u.DictType.Code).FirstAsync();
         _sysCacheService.Remove($"{CacheConst.KeyDict}{dictTypeCode}");
@@ -115,7 +114,7 @@ public class SysDictDataService : IDynamicApiController, ITransient
     [DisplayName("获取字典值详情")]
     public async Task<SysDictData> GetDetail([FromQuery] DictDataInput input)
     {
-        return await _sysDictDataRep.GetFirstAsync(u => u.Id == input.Id);
+        return await _sysDictDataRep.GetByIdAsync(input.Id);
     }
 
     /// <summary>
@@ -127,7 +126,7 @@ public class SysDictDataService : IDynamicApiController, ITransient
     [DisplayName("修改字典值状态")]
     public async Task SetStatus(DictDataInput input)
     {
-        var dictData = await _sysDictDataRep.GetFirstAsync(u => u.Id == input.Id) ?? throw Oops.Oh(ErrorCodeEnum.D3004);
+        var dictData = await _sysDictDataRep.GetByIdAsync(input.Id) ?? throw Oops.Oh(ErrorCodeEnum.D3004);
 
         var dictTypeCode = await _sysDictDataRep.AsQueryable().Where(u => u.DictTypeId == dictData.Id).Select(u => u.DictType.Code).FirstAsync();
         _sysCacheService.Remove($"{CacheConst.KeyDict}{dictTypeCode}");

+ 4 - 3
Admin.NET/Admin.NET.Core/Service/Dict/SysDictTypeService.cs

@@ -54,6 +54,7 @@ public class SysDictTypeService : IDynamicApiController, ITransient
     /// </summary>
     /// <param name="input"></param>
     /// <returns></returns>
+    [UnitOfWork]
     [DisplayName("获取字典类型-值列表")]
     public async Task<List<SysDictData>> GetDataList([FromQuery] GetDataDictTypeInput input)
     {
@@ -106,7 +107,7 @@ public class SysDictTypeService : IDynamicApiController, ITransient
     [DisplayName("删除字典类型")]
     public async Task DeleteDictType(DeleteDictTypeInput input)
     {
-        var dictType = await _sysDictTypeRep.GetFirstAsync(u => u.Id == input.Id) ?? throw Oops.Oh(ErrorCodeEnum.D3000);
+        var dictType = await _sysDictTypeRep.GetByIdAsync(input.Id) ?? throw Oops.Oh(ErrorCodeEnum.D3000);
 
         // 删除字典值
         await _sysDictTypeRep.DeleteAsync(dictType);
@@ -121,7 +122,7 @@ public class SysDictTypeService : IDynamicApiController, ITransient
     [DisplayName("获取字典类型详情")]
     public async Task<SysDictType> GetDetail([FromQuery] DictTypeInput input)
     {
-        return await _sysDictTypeRep.GetFirstAsync(u => u.Id == input.Id);
+        return await _sysDictTypeRep.GetByIdAsync(input.Id);
     }
 
     /// <summary>
@@ -133,7 +134,7 @@ public class SysDictTypeService : IDynamicApiController, ITransient
     [DisplayName("修改字典类型状态")]
     public async Task SetStatus(DictTypeInput input)
     {
-        var dictType = await _sysDictTypeRep.GetFirstAsync(u => u.Id == input.Id) ?? throw Oops.Oh(ErrorCodeEnum.D3000);
+        var dictType = await _sysDictTypeRep.GetByIdAsync(input.Id) ?? throw Oops.Oh(ErrorCodeEnum.D3000);
 
         _sysCacheService.Remove($"{CacheConst.KeyDict}{dictType.Code}");
 

+ 1 - 1
Admin.NET/Admin.NET.Web.Entry/wwwroot/template/Service.cs.vm

@@ -109,7 +109,7 @@ if (@column.QueryWhether == "Y"){
 } else {
             @:.Select<@(@Model.ClassName)Output>();
 }
-		return await query.OrderBuilder(input, "u.").ToPagedListAsync(input.Page, input.PageSize);
+		return await query.OrderBuilder(input).ToPagedListAsync(input.Page, input.PageSize);
     }
 
     /// <summary>

+ 1 - 0
Admin.NET/Plugins/Admin.NET.Plugin.ReZero/Admin.NET.Plugin.ReZero.csproj

@@ -24,6 +24,7 @@
   </ItemGroup>
 
   <ItemGroup>
+    <PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="4.11.0" />
     <PackageReference Include="Rezero.Api" Version="1.7.9" />
   </ItemGroup>
 

+ 2 - 2
Web/package.json

@@ -26,7 +26,7 @@
 		"@wangeditor/editor-for-vue": "^5.1.12",
 		"animate.css": "^4.1.1",
 		"async-validator": "^4.2.5",
-		"axios": "^1.7.6",
+		"axios": "^1.7.7",
 		"countup.js": "^2.8.0",
 		"cropperjs": "^1.6.2",
 		"echarts": "^5.5.1",
@@ -80,7 +80,7 @@
 		"@vitejs/plugin-vue": "^5.1.3",
 		"@vitejs/plugin-vue-jsx": "^4.0.1",
 		"@vue/compiler-sfc": "^3.4.38",
-		"code-inspector-plugin": "^0.16.0",
+		"code-inspector-plugin": "^0.16.1",
 		"eslint": "^9.9.1",
 		"eslint-plugin-vue": "^9.27.0",
 		"globals": "^15.9.0",