From c13b47a3ea0eb6ec40bc16134f2c192b2f6a2830 Mon Sep 17 00:00:00 2001 From: Johnec Who Date: Tue, 4 Nov 2025 09:57:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8=E9=9B=86=E5=90=88=E8=A1=A8?= =?UTF-8?q?=E8=BE=BE=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Extension/RepositoryExtension.cs | 2 +- .../Option/ElasticSearchOptions.cs | 2 +- .../Service/APIJSON/SelectTable.cs | 2 +- .../Service/Auth/SysAuthService.cs | 2 +- .../Service/CodeGen/SysCodeGenService.cs | 30 ++++++++----------- .../Service/DataBase/SysDatabaseService.cs | 2 +- .../Service/File/SysFileProviderService.cs | 2 +- .../Service/Menu/SysMenuService.cs | 2 +- .../Service/OAuth/SysOAuthService.cs | 2 +- .../Service/Org/SysOrgService.cs | 6 ++-- .../Service/Role/SysRoleOrgService.cs | 2 +- .../Service/Role/SysRoleService.cs | 8 ++--- .../Admin.NET.Core/SqlSugar/SqlSugarFilter.cs | 2 +- .../Admin.NET.Core/Utils/DateTimeUtil.cs | 5 ++-- .../Utils/TenantHeaderOperationFilter.cs | 13 +++----- 15 files changed, 35 insertions(+), 47 deletions(-) diff --git a/Admin.NET/Admin.NET.Core/Extension/RepositoryExtension.cs b/Admin.NET/Admin.NET.Core/Extension/RepositoryExtension.cs index e52918ed0..11ba3c41b 100644 --- a/Admin.NET/Admin.NET.Core/Extension/RepositoryExtension.cs +++ b/Admin.NET/Admin.NET.Core/Extension/RepositoryExtension.cs @@ -370,7 +370,7 @@ public static class RepositoryExtension public static IUpdateable OnlyUpdateColumn(this IUpdateable updateable) where T : EntityBase, new() where R : class, new() { if (updateable.UpdateBuilder.UpdateColumns == null) - updateable.UpdateBuilder.UpdateColumns = new List(); + updateable.UpdateBuilder.UpdateColumns = []; foreach (PropertyInfo info in typeof(R).GetProperties()) { diff --git a/Admin.NET/Admin.NET.Core/Option/ElasticSearchOptions.cs b/Admin.NET/Admin.NET.Core/Option/ElasticSearchOptions.cs index 1e6f73af2..20cea5121 100644 --- a/Admin.NET/Admin.NET.Core/Option/ElasticSearchOptions.cs +++ b/Admin.NET/Admin.NET.Core/Option/ElasticSearchOptions.cs @@ -55,7 +55,7 @@ public class ElasticSearchOptions /// /// 地址 /// - public List ServerUris { get; set; } = new List(); + public List ServerUris { get; set; } = []; /// /// 索引 diff --git a/Admin.NET/Admin.NET.Core/Service/APIJSON/SelectTable.cs b/Admin.NET/Admin.NET.Core/Service/APIJSON/SelectTable.cs index 8b83cb9de..7c9ada676 100644 --- a/Admin.NET/Admin.NET.Core/Service/APIJSON/SelectTable.cs +++ b/Admin.NET/Admin.NET.Core/Service/APIJSON/SelectTable.cs @@ -335,7 +335,7 @@ public class SelectTable : ISingleton var query = jb["query"] == null ? 2 : int.Parse(jb["query"].ToString()); // 默认输出数据和数量 jb.Remove("page"); jb.Remove("count"); jb.Remove("query"); var htt = new JArray(); - List tables = new List(), where = new List(); + List tables = [], where = []; foreach (var t in jb) { tables.Add(t.Key); where.Add(t.Value.ToString()); diff --git a/Admin.NET/Admin.NET.Core/Service/Auth/SysAuthService.cs b/Admin.NET/Admin.NET.Core/Service/Auth/SysAuthService.cs index f2f0bc225..a8c9ced54 100644 --- a/Admin.NET/Admin.NET.Core/Service/Auth/SysAuthService.cs +++ b/Admin.NET/Admin.NET.Core/Service/Auth/SysAuthService.cs @@ -441,7 +441,7 @@ public class SysAuthService : IDynamicApiController, ITransient OrgId = regWay.OrgId, PosId = regWay.PosId, TenantId = input.TenantId, - RoleIdList = new List { regWay.RoleId }, + RoleIdList = [regWay.RoleId], }; addUserInput.Copy(input); await _sysUserService.RegisterUser(addUserInput); diff --git a/Admin.NET/Admin.NET.Core/Service/CodeGen/SysCodeGenService.cs b/Admin.NET/Admin.NET.Core/Service/CodeGen/SysCodeGenService.cs index 40917cea2..6fc92ceca 100644 --- a/Admin.NET/Admin.NET.Core/Service/CodeGen/SysCodeGenService.cs +++ b/Admin.NET/Admin.NET.Core/Service/CodeGen/SysCodeGenService.cs @@ -713,28 +713,25 @@ public class SysCodeGenService : IDynamicApiController, ITransient if (input.GenerateType!.Substring(1, 1).Contains('1')) { // 生成到本项目(前端) - return new List - { + return [ indexPath, formModalPath, apiJsPath - }; + ]; } if (input.GenerateType.Substring(1, 1).Contains('2')) { // 生成到本项目(后端) - return new List - { + return [ servicePath, inputPath, outputPath, viewPath, - }; + ]; } // 前后端同时生成到本项目 - return new List - { + return [ servicePath, inputPath, outputPath, @@ -742,7 +739,7 @@ public class SysCodeGenService : IDynamicApiController, ITransient indexPath, formModalPath, apiJsPath - }; + ]; } /// @@ -767,27 +764,24 @@ public class SysCodeGenService : IDynamicApiController, ITransient var apiJsPath = Path.Combine(zipPath, _codeGenOptions.FrontRootPath, "src", "api", input.PagePath, firstLowerTableName + ".ts"); if (input.GenerateType!.StartsWith("11")) { - return new List - { + return [ indexPath, formModalPath, apiJsPath - }; + ]; } if (input.GenerateType.StartsWith("12")) { - return new List - { + return [ servicePath, inputPath, outputPath, viewPath - }; + ]; } - return new List - { + return [ servicePath, inputPath, outputPath, @@ -795,6 +789,6 @@ public class SysCodeGenService : IDynamicApiController, ITransient indexPath, formModalPath, apiJsPath - }; + ]; } } \ No newline at end of file diff --git a/Admin.NET/Admin.NET.Core/Service/DataBase/SysDatabaseService.cs b/Admin.NET/Admin.NET.Core/Service/DataBase/SysDatabaseService.cs index 9d9e38a73..189fb754f 100644 --- a/Admin.NET/Admin.NET.Core/Service/DataBase/SysDatabaseService.cs +++ b/Admin.NET/Admin.NET.Core/Service/DataBase/SysDatabaseService.cs @@ -109,7 +109,7 @@ public class SysDatabaseService : IDynamicApiController, ITransient public List GetColumnList(string tableName, string configId = SqlSugarConst.MainConfigId) { var db = _db.AsTenant().GetConnectionScope(configId); - return string.IsNullOrWhiteSpace(tableName) ? new List() : db.DbMaintenance.GetColumnInfosByTableName(tableName, false).Adapt>(); + return string.IsNullOrWhiteSpace(tableName) ? [] : db.DbMaintenance.GetColumnInfosByTableName(tableName, false).Adapt>(); } /// diff --git a/Admin.NET/Admin.NET.Core/Service/File/SysFileProviderService.cs b/Admin.NET/Admin.NET.Core/Service/File/SysFileProviderService.cs index 87ea6e3d1..8592f060a 100644 --- a/Admin.NET/Admin.NET.Core/Service/File/SysFileProviderService.cs +++ b/Admin.NET/Admin.NET.Core/Service/File/SysFileProviderService.cs @@ -377,7 +377,7 @@ public class SysFileProviderService : IDynamicApiController, ITransient { if (!mapping.TryGetValue(provider.BucketName, out List value)) { - value = new List(); + value = []; mapping[provider.BucketName] = value; } diff --git a/Admin.NET/Admin.NET.Core/Service/Menu/SysMenuService.cs b/Admin.NET/Admin.NET.Core/Service/Menu/SysMenuService.cs index feb5e8bfc..964485a02 100644 --- a/Admin.NET/Admin.NET.Core/Service/Menu/SysMenuService.cs +++ b/Admin.NET/Admin.NET.Core/Service/Menu/SysMenuService.cs @@ -103,7 +103,7 @@ public class SysMenuService : IDynamicApiController, ITransient public async Task> GetList([FromQuery] MenuInput input) { var langCode = _userManager.LangCode; - var menuIdList = _userManager.SuperAdmin || _userManager.SysAdmin ? new List() : await GetMenuIdList(); + var menuIdList = _userManager.SuperAdmin || _userManager.SysAdmin ? [] : await GetMenuIdList(); var (query, _) = GetSugarQueryableAndTenantId(input.TenantId); // 有条件直接查询菜单列表(带 Title、Type 过滤) diff --git a/Admin.NET/Admin.NET.Core/Service/OAuth/SysOAuthService.cs b/Admin.NET/Admin.NET.Core/Service/OAuth/SysOAuthService.cs index 99d962108..20e59330d 100644 --- a/Admin.NET/Admin.NET.Core/Service/OAuth/SysOAuthService.cs +++ b/Admin.NET/Admin.NET.Core/Service/OAuth/SysOAuthService.cs @@ -97,7 +97,7 @@ public class SysOAuthService : IDynamicApiController, ITransient Avatar = avatarUrl, Phone = mobilePhone, OrgId = 1300000000101, // 根组织架构 - RoleIdList = new List { 1300000000104 } // 仅本人数据角色 + RoleIdList = [1300000000104] // 仅本人数据角色 }); await _sysWechatUserRep.InsertAsync(new SysWechatUser() diff --git a/Admin.NET/Admin.NET.Core/Service/Org/SysOrgService.cs b/Admin.NET/Admin.NET.Core/Service/Org/SysOrgService.cs index 0c64e6095..f90011bcf 100644 --- a/Admin.NET/Admin.NET.Core/Service/Org/SysOrgService.cs +++ b/Admin.NET/Admin.NET.Core/Service/Org/SysOrgService.cs @@ -71,7 +71,7 @@ public class SysOrgService : IDynamicApiController, ITransient if (sysOrg == null) return orgTree; sysOrg.Children = orgTree; - orgTree = new List { sysOrg }; + orgTree = [sysOrg]; return orgTree; } @@ -118,7 +118,7 @@ public class SysOrgService : IDynamicApiController, ITransient if (sysOrg == null) return orgTree; sysOrg.Children = orgTree; - orgTree = new List { sysOrg }; + orgTree = [sysOrg]; return orgTree; } @@ -396,7 +396,7 @@ public class SysOrgService : IDynamicApiController, ITransient var roleList = await _sysUserRoleService.GetUserRoleList(userId); if (roleList != null && roleList.Exists(r => r.Code == role.Code) == true) return true; - roleList = new List { role }; + roleList = [role]; var orgIds = await GetUserOrgIdList(roleList, userId, userOrgId); return orgIds.Contains(userOrgId); } diff --git a/Admin.NET/Admin.NET.Core/Service/Role/SysRoleOrgService.cs b/Admin.NET/Admin.NET.Core/Service/Role/SysRoleOrgService.cs index fe0774478..ad35f62c8 100644 --- a/Admin.NET/Admin.NET.Core/Service/Role/SysRoleOrgService.cs +++ b/Admin.NET/Admin.NET.Core/Service/Role/SysRoleOrgService.cs @@ -50,7 +50,7 @@ public class SysRoleOrgService : ITransient .Where(u => roleIdList.Contains(u.RoleId)) .Select(u => u.OrgId).ToListAsync(); } - else return new List(); + else return []; } /// diff --git a/Admin.NET/Admin.NET.Core/Service/Role/SysRoleService.cs b/Admin.NET/Admin.NET.Core/Service/Role/SysRoleService.cs index 409ec2068..b4b6b029f 100644 --- a/Admin.NET/Admin.NET.Core/Service/Role/SysRoleService.cs +++ b/Admin.NET/Admin.NET.Core/Service/Role/SysRoleService.cs @@ -46,7 +46,7 @@ public class SysRoleService : IDynamicApiController, ITransient public async Task> Page(PageRoleInput input) { // 当前用户已拥有的角色集合 - var roleIdList = _userManager.SuperAdmin ? new List() : await _sysUserRoleService.GetUserRoleIdList(_userManager.UserId); + var roleIdList = _userManager.SuperAdmin ? [] : await _sysUserRoleService.GetUserRoleIdList(_userManager.UserId); return await _sysRoleRep.AsQueryable() .WhereIF(_userManager.SuperAdmin && input.TenantId > 0, u => u.TenantId == input.TenantId) .WhereIF(!_userManager.SuperAdmin, u => u.TenantId == _userManager.TenantId) // 若非超管,则只能操作本租户的角色 @@ -65,7 +65,7 @@ public class SysRoleService : IDynamicApiController, ITransient public async Task> GetList() { // 当前用户已拥有的角色集合 - var roleIdList = _userManager.SuperAdmin ? new List() : await _sysUserRoleService.GetUserRoleIdList(_userManager.UserId); + var roleIdList = _userManager.SuperAdmin ? [] : await _sysUserRoleService.GetUserRoleIdList(_userManager.UserId); return await _sysRoleRep.AsQueryable() .WhereIF(!_userManager.SuperAdmin, u => u.TenantId == _userManager.TenantId) // 若非超管,则只能操作本租户的角色 @@ -221,7 +221,7 @@ public class SysRoleService : IDynamicApiController, ITransient [DisplayName("根据角色Id获取菜单Id集合")] public async Task> GetOwnMenuList([FromQuery] RoleInput input) { - var menuIds = await _sysRoleMenuService.GetRoleMenuIdList(new List { input.Id }); + var menuIds = await _sysRoleMenuService.GetRoleMenuIdList([input.Id]); return await _sysMenuService.ExcludeParentMenuOfFullySelected(menuIds); } @@ -233,7 +233,7 @@ public class SysRoleService : IDynamicApiController, ITransient [DisplayName("根据角色Id获取机构Id集合")] public async Task> GetOwnOrgList([FromQuery] RoleInput input) { - return await _sysRoleOrgService.GetRoleOrgIdList(new List { input.Id }); + return await _sysRoleOrgService.GetRoleOrgIdList([input.Id]); } /// diff --git a/Admin.NET/Admin.NET.Core/SqlSugar/SqlSugarFilter.cs b/Admin.NET/Admin.NET.Core/SqlSugar/SqlSugarFilter.cs index 78c41ba9a..3544abc2e 100644 --- a/Admin.NET/Admin.NET.Core/SqlSugar/SqlSugarFilter.cs +++ b/Admin.NET/Admin.NET.Core/SqlSugar/SqlSugarFilter.cs @@ -109,7 +109,7 @@ public static class SqlSugarFilter //var lambda = DynamicExpressionParser.ParseLambda(new[] { // Expression.Parameter(entityType, "u") }, typeof(bool), $"u.{nameof(EntityBaseData.CreateUserId)}=@0", userId); - var lambda = entityType.GetConditionExpression(new List { userId }); + var lambda = entityType.GetConditionExpression([userId]); db.QueryFilter.AddTableFilter(entityType, lambda); dataScopeFilter.TryAdd(entityType, lambda); diff --git a/Admin.NET/Admin.NET.Core/Utils/DateTimeUtil.cs b/Admin.NET/Admin.NET.Core/Utils/DateTimeUtil.cs index e0175ae19..05ec76d38 100644 --- a/Admin.NET/Admin.NET.Core/Utils/DateTimeUtil.cs +++ b/Admin.NET/Admin.NET.Core/Utils/DateTimeUtil.cs @@ -198,11 +198,10 @@ public class DateTimeUtil /// public static List GetTodayTimeList(DateTime time) { - return new List - { + return [ Convert.ToDateTime(time.ToString("D")), Convert.ToDateTime(time.AddDays(1).ToString("D")).AddSeconds(-1) - }; + ]; } /// diff --git a/Admin.NET/Admin.NET.Core/Utils/TenantHeaderOperationFilter.cs b/Admin.NET/Admin.NET.Core/Utils/TenantHeaderOperationFilter.cs index a1cb64c39..7361a28fe 100644 --- a/Admin.NET/Admin.NET.Core/Utils/TenantHeaderOperationFilter.cs +++ b/Admin.NET/Admin.NET.Core/Utils/TenantHeaderOperationFilter.cs @@ -1,11 +1,6 @@ -using Admin.NET.Core; -using Microsoft.OpenApi.Models; +using Microsoft.OpenApi.Models; + using Swashbuckle.AspNetCore.SwaggerGen; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Admin.NET.Core; @@ -19,7 +14,7 @@ public class TenantHeaderOperationFilter : IOperationFilter /// public void Apply(OpenApiOperation operation, OperationFilterContext context) { - operation.Parameters ??= new List(); + operation.Parameters ??= []; operation.Parameters.Add(new OpenApiParameter { @@ -30,4 +25,4 @@ public class TenantHeaderOperationFilter : IOperationFilter Description = "租户ID(留空表示默认租户)" }); } -} +} \ No newline at end of file -- Gitee