using F9WebAiTest.Application.Common.Exceptions; using F9WebAiTest.Application.Interfaces.SnowflakeID; using F9WebAiTest.Domain.Entities.SYS.RBAC; using F9WebAiTest.Domain.Enums.SYS.RBAC; using F9WebAiTest.Domain.Interfaces.SYS.RBAC.Menus; using MediatR; namespace F9WebAiTest.Application.CQRS.SYS.RBAC.Menus.Commands; /// 命令定义 public record Menu_UpdateCommand(long Id, string Name, string IconSvg, MenuType_Enum MenuType, string AssemblyName, string TypeFullName, long ParentId, int SortOrder) : IRequest; /// 命令处理器 public class UpdateMenuCommandHandler( IMenuWriteRepository menuRepository) : IRequestHandler { public async Task Handle(Menu_UpdateCommand command, CancellationToken cancellationToken) { if (string.IsNullOrWhiteSpace(command.Name)) throw new F9OperationException("菜单名称不能为空"); var menu = new Menu(command.Id, command.Name, command.IconSvg, command.MenuType, command.AssemblyName, command.TypeFullName, command.ParentId, command.SortOrder); var result = await menuRepository.UpdateAsync(menu); if (result == false) throw new F9OperationException("菜单", "修改"); return result; } }