From dadef5c62c413589eb3562fd7654747234250f70 Mon Sep 17 00:00:00 2001 From: colin Date: Sat, 26 Apr 2025 10:42:35 +0800 Subject: [PATCH] =?UTF-8?q?feat(platform):=20=E4=BC=98=E5=8C=96=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E8=A7=92=E8=89=B2=E5=A4=9A=E6=A1=86=E6=9E=B6=E8=8F=9C?= =?UTF-8?q?=E5=8D=95=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Platform/Datas/Dto/DataCreateDto.cs | 2 ++ .../Platform/Menus/Dto/RoleMenuInput.cs | 9 ++++- .../Menus/Dto/RoleMenuStartupInput.cs | 7 +++- .../Platform/Menus/Dto/UserMenuInput.cs | 10 +++++- .../Menus/Dto/UserMenuStartupInput.cs | 8 ++++- .../LINGYUN/Platform/Menus/MenuAppService.cs | 20 ++++++----- .../Platform/Localization/Resources/en.json | 3 ++ .../Localization/Resources/zh-Hans.json | 7 +++- .../Platform/Menus/IRoleMenuRepository.cs | 4 ++- .../Platform/Menus/IUserMenuRepository.cs | 4 ++- .../LINGYUN/Platform/Menus/MenuManager.cs | 20 +++++------ .../Menus/EfCoreRoleMenuRepository.cs | 34 ++++++++++++++++--- .../Menus/EfCoreUserMenuRepository.cs | 28 ++++++++++++--- 13 files changed, 121 insertions(+), 35 deletions(-) diff --git a/aspnet-core/modules/platform/LINGYUN.Platform.Application.Contracts/LINGYUN/Platform/Datas/Dto/DataCreateDto.cs b/aspnet-core/modules/platform/LINGYUN.Platform.Application.Contracts/LINGYUN/Platform/Datas/Dto/DataCreateDto.cs index 6f6a7fee5..db7cd4341 100644 --- a/aspnet-core/modules/platform/LINGYUN.Platform.Application.Contracts/LINGYUN/Platform/Datas/Dto/DataCreateDto.cs +++ b/aspnet-core/modules/platform/LINGYUN.Platform.Application.Contracts/LINGYUN/Platform/Datas/Dto/DataCreateDto.cs @@ -1,8 +1,10 @@ using System; +using System.ComponentModel; namespace LINGYUN.Platform.Datas; public class DataCreateDto : DataCreateOrUpdateDto { + [DisplayName("DisplayName:ParentData")] public Guid? ParentId { get; set; } } diff --git a/aspnet-core/modules/platform/LINGYUN.Platform.Application.Contracts/LINGYUN/Platform/Menus/Dto/RoleMenuInput.cs b/aspnet-core/modules/platform/LINGYUN.Platform.Application.Contracts/LINGYUN/Platform/Menus/Dto/RoleMenuInput.cs index 6329d3766..d35fa7121 100644 --- a/aspnet-core/modules/platform/LINGYUN.Platform.Application.Contracts/LINGYUN/Platform/Menus/Dto/RoleMenuInput.cs +++ b/aspnet-core/modules/platform/LINGYUN.Platform.Application.Contracts/LINGYUN/Platform/Menus/Dto/RoleMenuInput.cs @@ -1,6 +1,8 @@ -using System; +using LINGYUN.Platform.Routes; +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; +using Volo.Abp.Validation; namespace LINGYUN.Platform.Menus; @@ -10,6 +12,11 @@ public class RoleMenuInput [StringLength(80)] public string RoleName { get; set; } + [DynamicStringLength(typeof(LayoutConsts), nameof(LayoutConsts.MaxFrameworkLength))] + public string Framework { get; set; } + + public Guid? StartupMenuId { get; set; } + [Required] public List MenuIds { get; set; } = new List(); } diff --git a/aspnet-core/modules/platform/LINGYUN.Platform.Application.Contracts/LINGYUN/Platform/Menus/Dto/RoleMenuStartupInput.cs b/aspnet-core/modules/platform/LINGYUN.Platform.Application.Contracts/LINGYUN/Platform/Menus/Dto/RoleMenuStartupInput.cs index f9c04fe23..f2294dfb4 100644 --- a/aspnet-core/modules/platform/LINGYUN.Platform.Application.Contracts/LINGYUN/Platform/Menus/Dto/RoleMenuStartupInput.cs +++ b/aspnet-core/modules/platform/LINGYUN.Platform.Application.Contracts/LINGYUN/Platform/Menus/Dto/RoleMenuStartupInput.cs @@ -1,4 +1,6 @@ -using System.ComponentModel.DataAnnotations; +using LINGYUN.Platform.Routes; +using System.ComponentModel.DataAnnotations; +using Volo.Abp.Validation; namespace LINGYUN.Platform.Menus; @@ -7,4 +9,7 @@ public class RoleMenuStartupInput [Required] [StringLength(80)] public string RoleName { get; set; } + + [DynamicStringLength(typeof(LayoutConsts), nameof(LayoutConsts.MaxFrameworkLength))] + public string Framework { get; set; } } diff --git a/aspnet-core/modules/platform/LINGYUN.Platform.Application.Contracts/LINGYUN/Platform/Menus/Dto/UserMenuInput.cs b/aspnet-core/modules/platform/LINGYUN.Platform.Application.Contracts/LINGYUN/Platform/Menus/Dto/UserMenuInput.cs index 4ad6fe864..2ede9ae62 100644 --- a/aspnet-core/modules/platform/LINGYUN.Platform.Application.Contracts/LINGYUN/Platform/Menus/Dto/UserMenuInput.cs +++ b/aspnet-core/modules/platform/LINGYUN.Platform.Application.Contracts/LINGYUN/Platform/Menus/Dto/UserMenuInput.cs @@ -1,6 +1,8 @@ -using System; +using LINGYUN.Platform.Routes; +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; +using Volo.Abp.Validation; namespace LINGYUN.Platform.Menus; @@ -9,6 +11,12 @@ public class UserMenuInput [Required] public Guid UserId { get; set; } + + [DynamicStringLength(typeof(LayoutConsts), nameof(LayoutConsts.MaxFrameworkLength))] + public string Framework { get; set; } + + public Guid? StartupMenuId { get; set; } + [Required] public List MenuIds { get; set; } = new List(); } diff --git a/aspnet-core/modules/platform/LINGYUN.Platform.Application.Contracts/LINGYUN/Platform/Menus/Dto/UserMenuStartupInput.cs b/aspnet-core/modules/platform/LINGYUN.Platform.Application.Contracts/LINGYUN/Platform/Menus/Dto/UserMenuStartupInput.cs index c498f168e..16bc7337a 100644 --- a/aspnet-core/modules/platform/LINGYUN.Platform.Application.Contracts/LINGYUN/Platform/Menus/Dto/UserMenuStartupInput.cs +++ b/aspnet-core/modules/platform/LINGYUN.Platform.Application.Contracts/LINGYUN/Platform/Menus/Dto/UserMenuStartupInput.cs @@ -1,8 +1,14 @@ -using System; +using LINGYUN.Platform.Routes; +using System; +using Volo.Abp.Validation; namespace LINGYUN.Platform.Menus; public class UserMenuStartupInput { public Guid UserId { get; set; } + + + [DynamicStringLength(typeof(LayoutConsts), nameof(LayoutConsts.MaxFrameworkLength))] + public string Framework { get; set; } } diff --git a/aspnet-core/modules/platform/LINGYUN.Platform.Application/LINGYUN/Platform/Menus/MenuAppService.cs b/aspnet-core/modules/platform/LINGYUN.Platform.Application/LINGYUN/Platform/Menus/MenuAppService.cs index c7be98b84..dcfa16f85 100644 --- a/aspnet-core/modules/platform/LINGYUN.Platform.Application/LINGYUN/Platform/Menus/MenuAppService.cs +++ b/aspnet-core/modules/platform/LINGYUN.Platform.Application/LINGYUN/Platform/Menus/MenuAppService.cs @@ -52,12 +52,12 @@ public class MenuAppService : PlatformApplicationServiceBase, IMenuAppService var menus = ObjectMapper.Map, List>(myMenus); - var startupMenu = await UserMenuRepository.GetStartupMenuAsync( + var startupMenu = await UserMenuRepository.FindStartupMenuAsync( CurrentUser.GetId()); if (startupMenu == null && CurrentUser.Roles.Any()) { - startupMenu = await RoleMenuRepository.GetStartupMenuAsync(CurrentUser.Roles); + startupMenu = await RoleMenuRepository.FindStartupMenuAsync(CurrentUser.Roles); } if (startupMenu != null) @@ -240,11 +240,11 @@ public class MenuAppService : PlatformApplicationServiceBase, IMenuAppService var menuDtos = ObjectMapper.Map, List>(menus); - var startupMenu = await UserMenuRepository.GetStartupMenuAsync(input.UserId); + var startupMenu = await UserMenuRepository.FindStartupMenuAsync(input.UserId, input.Framework); if (startupMenu == null) { - startupMenu = await RoleMenuRepository.GetStartupMenuAsync(input.Roles); + startupMenu = await RoleMenuRepository.FindStartupMenuAsync(input.Roles, input.Framework); } if (startupMenu != null) @@ -263,25 +263,27 @@ public class MenuAppService : PlatformApplicationServiceBase, IMenuAppService [Authorize(PlatformPermissions.Menu.ManageUsers)] public async virtual Task SetUserMenusAsync(UserMenuInput input) { - await MenuManager.SetUserMenusAsync(input.UserId, input.MenuIds); + await MenuManager.SetUserMenusAsync(input.UserId, input.MenuIds, input.Framework); + await MenuManager.SetUserStartupMenuAsync(input.UserId, input.StartupMenuId, input.Framework); } [Authorize(PlatformPermissions.Menu.ManageUsers)] public async virtual Task SetUserStartupAsync(Guid id, UserMenuStartupInput input) { - await MenuManager.SetUserStartupMenuAsync(input.UserId, id); + await MenuManager.SetUserStartupMenuAsync(input.UserId, id, input.Framework); } [Authorize(PlatformPermissions.Menu.ManageRoles)] public async virtual Task SetRoleMenusAsync(RoleMenuInput input) { - await MenuManager.SetRoleMenusAsync(input.RoleName, input.MenuIds); + await MenuManager.SetRoleMenusAsync(input.RoleName, input.MenuIds, input.Framework); + await MenuManager.SetRoleStartupMenuAsync(input.RoleName, input.StartupMenuId, input.Framework); } [Authorize(PlatformPermissions.Menu.ManageRoles)] public async virtual Task SetRoleStartupAsync(Guid id, RoleMenuStartupInput input) { - await MenuManager.SetRoleStartupMenuAsync(input.RoleName, id); + await MenuManager.SetRoleStartupMenuAsync(input.RoleName, id, input.Framework); } [Authorize(PlatformPermissions.Menu.ManageRoles)] @@ -291,7 +293,7 @@ public class MenuAppService : PlatformApplicationServiceBase, IMenuAppService var menuDtos = ObjectMapper.Map, List>(menus); - var startupMenu = await RoleMenuRepository.GetStartupMenuAsync(new string[] { input.Role }); + var startupMenu = await RoleMenuRepository.FindStartupMenuAsync(new string[] { input.Role }, input.Framework); if (startupMenu != null) { diff --git a/aspnet-core/modules/platform/LINGYUN.Platform.Domain.Shared/LINGYUN/Platform/Localization/Resources/en.json b/aspnet-core/modules/platform/LINGYUN.Platform.Domain.Shared/LINGYUN/Platform/Localization/Resources/en.json index 2ace5ac72..06bdbfa79 100644 --- a/aspnet-core/modules/platform/LINGYUN.Platform.Domain.Shared/LINGYUN/Platform/Localization/Resources/en.json +++ b/aspnet-core/modules/platform/LINGYUN.Platform.Domain.Shared/LINGYUN/Platform/Localization/Resources/en.json @@ -76,6 +76,9 @@ "DisplayName:BlobName": "Blob Name", "DisplayName:Key": "Key", "DisplayName:Value": "Value", + "DisplayName:ParentData": "Parent Data", + "DisplayName:ParentMenu": "Parent Menu", + "DisplayName:LayoutConstraint": "Layout Constraint", "MailPriority:Normal": "Normal", "MailPriority:Low": "Low", "MailPriority:High": "High", diff --git a/aspnet-core/modules/platform/LINGYUN.Platform.Domain.Shared/LINGYUN/Platform/Localization/Resources/zh-Hans.json b/aspnet-core/modules/platform/LINGYUN.Platform.Domain.Shared/LINGYUN/Platform/Localization/Resources/zh-Hans.json index b35fa0ad7..a44775103 100644 --- a/aspnet-core/modules/platform/LINGYUN.Platform.Domain.Shared/LINGYUN/Platform/Localization/Resources/zh-Hans.json +++ b/aspnet-core/modules/platform/LINGYUN.Platform.Domain.Shared/LINGYUN/Platform/Localization/Resources/zh-Hans.json @@ -76,6 +76,9 @@ "DisplayName:BlobName": "存储名称", "DisplayName:Key": "键名", "DisplayName:Value": "键值", + "DisplayName:ParentData": "上级字典", + "DisplayName:ParentMenu": "上级菜单", + "DisplayName:LayoutConstraint": "布局约束", "MailPriority:Normal": "普通", "MailPriority:Low": "低", "MailPriority:High": "高", @@ -115,6 +118,8 @@ "SmsMessages": "短信消息", "SendMessage": "发送消息", "MessageWillBeReSendWarningMessage": "将重新发送选择的消息.", - "SuccessfullySent": "发送成功,请稍后在消息中心查看状态!" + "SuccessfullySent": "发送成功,请稍后在消息中心查看状态!", + "PreStep": "上一步", + "NextStep": "下一步" } } \ No newline at end of file diff --git a/aspnet-core/modules/platform/LINGYUN.Platform.Domain/LINGYUN/Platform/Menus/IRoleMenuRepository.cs b/aspnet-core/modules/platform/LINGYUN.Platform.Domain/LINGYUN/Platform/Menus/IRoleMenuRepository.cs index 10c8af0bd..6beb9c1a4 100644 --- a/aspnet-core/modules/platform/LINGYUN.Platform.Domain/LINGYUN/Platform/Menus/IRoleMenuRepository.cs +++ b/aspnet-core/modules/platform/LINGYUN.Platform.Domain/LINGYUN/Platform/Menus/IRoleMenuRepository.cs @@ -22,9 +22,11 @@ public interface IRoleMenuRepository : IBasicRepository Task> GetListByRoleNameAsync( string roleName, + string framework = null, CancellationToken cancellationToken = default); - Task GetStartupMenuAsync( + Task FindStartupMenuAsync( IEnumerable roleNames, + string framework = null, CancellationToken cancellationToken = default); } diff --git a/aspnet-core/modules/platform/LINGYUN.Platform.Domain/LINGYUN/Platform/Menus/IUserMenuRepository.cs b/aspnet-core/modules/platform/LINGYUN.Platform.Domain/LINGYUN/Platform/Menus/IUserMenuRepository.cs index 57650845f..90fe60826 100644 --- a/aspnet-core/modules/platform/LINGYUN.Platform.Domain/LINGYUN/Platform/Menus/IUserMenuRepository.cs +++ b/aspnet-core/modules/platform/LINGYUN.Platform.Domain/LINGYUN/Platform/Menus/IUserMenuRepository.cs @@ -22,9 +22,11 @@ public interface IUserMenuRepository : IBasicRepository Task> GetListByUserIdAsync( Guid userId, + string framework = null, CancellationToken cancellationToken = default); - Task GetStartupMenuAsync( + Task FindStartupMenuAsync( Guid userId, + string framework = null, CancellationToken cancellationToken = default); } diff --git a/aspnet-core/modules/platform/LINGYUN.Platform.Domain/LINGYUN/Platform/Menus/MenuManager.cs b/aspnet-core/modules/platform/LINGYUN.Platform.Domain/LINGYUN/Platform/Menus/MenuManager.cs index 8f062ad1f..0772e163e 100644 --- a/aspnet-core/modules/platform/LINGYUN.Platform.Domain/LINGYUN/Platform/Menus/MenuManager.cs +++ b/aspnet-core/modules/platform/LINGYUN.Platform.Domain/LINGYUN/Platform/Menus/MenuManager.cs @@ -126,16 +126,16 @@ public class MenuManager : DomainService return false; } - public async virtual Task SetUserStartupMenuAsync(Guid userId, Guid menuId) + public async virtual Task SetUserStartupMenuAsync(Guid userId, Guid? menuId = null, string framework = null) { using (var unitOfWork = UnitOfWorkManager.Begin()) { - var userMenus = await UserMenuRepository.GetListByUserIdAsync(userId); + var userMenus = await UserMenuRepository.GetListByUserIdAsync(userId, framework); foreach (var menu in userMenus) { menu.Startup = false; - if (menu.MenuId.Equals(menuId)) + if (menuId.HasValue && menu.MenuId.Equals(menuId)) { menu.Startup = true; } @@ -147,11 +147,11 @@ public class MenuManager : DomainService } } - public async virtual Task SetUserMenusAsync(Guid userId, IEnumerable menuIds) + public async virtual Task SetUserMenusAsync(Guid userId, IEnumerable menuIds, string framework = null) { using (var unitOfWork = UnitOfWorkManager.Begin()) { - var userMenus = await UserMenuRepository.GetListByUserIdAsync(userId); + var userMenus = await UserMenuRepository.GetListByUserIdAsync(userId, framework); // 移除不存在的菜单 // TODO: 升级框架版本解决未能删除不需要菜单的问题 @@ -173,16 +173,16 @@ public class MenuManager : DomainService } } - public async virtual Task SetRoleStartupMenuAsync(string roleName, Guid menuId) + public async virtual Task SetRoleStartupMenuAsync(string roleName, Guid? menuId = null, string framework = null) { using (var unitOfWork = UnitOfWorkManager.Begin()) { - var roleMenus = await RoleMenuRepository.GetListByRoleNameAsync(roleName); + var roleMenus = await RoleMenuRepository.GetListByRoleNameAsync(roleName, framework); foreach (var menu in roleMenus) { menu.Startup = false; - if (menu.MenuId.Equals(menuId)) + if (menuId.HasValue && menu.MenuId.Equals(menuId)) { menu.Startup = true; } @@ -194,11 +194,11 @@ public class MenuManager : DomainService } } - public async virtual Task SetRoleMenusAsync(string roleName, IEnumerable menuIds) + public async virtual Task SetRoleMenusAsync(string roleName, IEnumerable menuIds, string framework = null) { using (var unitOfWork = UnitOfWorkManager.Begin()) { - var roleMenus = await RoleMenuRepository.GetListByRoleNameAsync(roleName); + var roleMenus = await RoleMenuRepository.GetListByRoleNameAsync(roleName, framework); // 移除不存在的菜单 // TODO: 升级框架版本解决未能删除不需要菜单的问题 diff --git a/aspnet-core/modules/platform/LINGYUN.Platform.EntityFrameworkCore/LINGYUN/Platform/Menus/EfCoreRoleMenuRepository.cs b/aspnet-core/modules/platform/LINGYUN.Platform.EntityFrameworkCore/LINGYUN/Platform/Menus/EfCoreRoleMenuRepository.cs index ba9de1489..468b56f40 100644 --- a/aspnet-core/modules/platform/LINGYUN.Platform.EntityFrameworkCore/LINGYUN/Platform/Menus/EfCoreRoleMenuRepository.cs +++ b/aspnet-core/modules/platform/LINGYUN.Platform.EntityFrameworkCore/LINGYUN/Platform/Menus/EfCoreRoleMenuRepository.cs @@ -3,6 +3,7 @@ using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using System.Linq; +using System.Linq.Dynamic.Core; using System.Threading; using System.Threading.Tasks; using Volo.Abp.Domain.Repositories.EntityFrameworkCore; @@ -18,10 +19,31 @@ public class EfCoreRoleMenuRepository : EfCoreRepository> GetListByRoleNameAsync(string roleName, CancellationToken cancellationToken = default) + public async virtual Task> GetListByRoleNameAsync( + string roleName, + string framework = null, + CancellationToken cancellationToken = default) { - return await (await GetDbSetAsync()).Where(x => x.RoleName.Equals(roleName)) - .ToListAsync(GetCancellationToken(cancellationToken)); + var dbContext = await GetDbContextAsync(); + + var menus = dbContext.Set(); + var roleMenus = dbContext.Set().Where(x => x.RoleName == roleName); + + IQueryable queryable; + if (!framework.IsNullOrWhiteSpace()) + { + queryable = from menu in menus + join roleMenu in roleMenus + on menu.Id equals roleMenu.MenuId + where menu.Framework == framework + select roleMenu; + } + else + { + queryable = roleMenus; + } + + return await queryable.ToListAsync(GetCancellationToken(cancellationToken)); } public async virtual Task RoleHasInMenuAsync( @@ -40,8 +62,9 @@ public class EfCoreRoleMenuRepository : EfCoreRepository GetStartupMenuAsync( - IEnumerable roleNames, + public async virtual Task FindStartupMenuAsync( + IEnumerable roleNames, + string framework = null, CancellationToken cancellationToken = default) { var dbContext = await GetDbContextAsync(); @@ -54,6 +77,7 @@ public class EfCoreRoleMenuRepository : EfCoreRepository() on roleMenu.MenuId equals menu.Id select menu) + .WhereIf(!framework.IsNullOrWhiteSpace(), x => x.Framework == framework) .OrderByDescending(x => x.CreationTime) .FirstOrDefaultAsync(GetCancellationToken(cancellationToken)); } diff --git a/aspnet-core/modules/platform/LINGYUN.Platform.EntityFrameworkCore/LINGYUN/Platform/Menus/EfCoreUserMenuRepository.cs b/aspnet-core/modules/platform/LINGYUN.Platform.EntityFrameworkCore/LINGYUN/Platform/Menus/EfCoreUserMenuRepository.cs index f73aaa747..fbe61f832 100644 --- a/aspnet-core/modules/platform/LINGYUN.Platform.EntityFrameworkCore/LINGYUN/Platform/Menus/EfCoreUserMenuRepository.cs +++ b/aspnet-core/modules/platform/LINGYUN.Platform.EntityFrameworkCore/LINGYUN/Platform/Menus/EfCoreUserMenuRepository.cs @@ -37,15 +37,34 @@ public class EfCoreUserMenuRepository : EfCoreRepository> GetListByUserIdAsync( Guid userId, + string framework = null, CancellationToken cancellationToken = default) { - var dbSet = await GetDbSetAsync(); - return await dbSet.Where(x => x.UserId.Equals(userId)) - .ToListAsync(GetCancellationToken(cancellationToken)); + var dbContext = await GetDbContextAsync(); + + var menus = dbContext.Set(); + var userMenus = dbContext.Set().Where(x => x.UserId == userId); + + IQueryable queryable; + if (!framework.IsNullOrWhiteSpace()) + { + queryable = from menu in menus + join userMenu in userMenus + on menu.Id equals userMenu.MenuId + where menu.Framework == framework + select userMenu; + } + else + { + queryable = userMenus; + } + + return await queryable.ToListAsync(GetCancellationToken(cancellationToken)); } - public async virtual Task GetStartupMenuAsync( + public async virtual Task FindStartupMenuAsync( Guid userId, + string framework = null, CancellationToken cancellationToken = default) { var dbContext = await GetDbContextAsync(); @@ -58,6 +77,7 @@ public class EfCoreUserMenuRepository : EfCoreRepository() on userMenu.MenuId equals menu.Id select menu) + .WhereIf(!framework.IsNullOrWhiteSpace(), x => x.Framework == framework) .OrderByDescending(x => x.CreationTime) .FirstOrDefaultAsync(GetCancellationToken(cancellationToken)); }