first commit

This commit is contained in:
yanpeng200212
2026-10-08 10:43:59 +08:00
commit 8430ba0452
288 changed files with 29595 additions and 0 deletions
@@ -0,0 +1,31 @@
using F9WebAiTest.Application.Common.Exceptions;
using F9WebAiTest.Domain.Interfaces.SYS.RBAC.Menus;
using MediatR;
namespace F9WebAiTest.Application.CQRS.SYS.RBAC.Menus.Commands;
/// <summary>命令定义</summary>
public record Menu_ActiveOrDeactivateCommand(long Id, bool Active) : IRequest<bool>;
/// <summary>命令处理器</summary>
public class ActiveOrDeactivateMenuCommandHandler(
IMenuWriteRepository menuWriteRepository,
IPublisher eventBus) : IRequestHandler<Menu_ActiveOrDeactivateCommand, bool>
{
public async Task<bool> Handle(Menu_ActiveOrDeactivateCommand command, CancellationToken cancellationToken)
{
var menu = await menuWriteRepository.GetByIdAsync(command.Id);
if (menu == null) throw new F9NotFoundException("菜单", command.Id);
if (command.Active) menu.Activate();
else menu.Deactivate();
var result = await menuWriteRepository.ActiveOrDeactive(command.Id, menu.IsActive);
if (result == false) throw new F9OperationException("启用/禁用", "操作");
foreach (var de in menu.DomainEvents) await eventBus.Publish(de, cancellationToken);
menu.ClearDomainEvents();
return result;
}
}
@@ -0,0 +1,34 @@
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;
/// <summary>命令定义</summary>
public record Menu_CreateCommand(string Name, string IconSvg, MenuType_Enum MenuType, string AssemblyName, string TypeFullName, long ParentId, int SortOrder) : IRequest<long>;
/// <summary>命令处理器</summary>
public class CreateMenuCommandHandler(
IMenuWriteRepository menuRepository,
ISnowflakeIdGenerator snowflakeIdGenerator,
IPublisher eventBus) : IRequestHandler<Menu_CreateCommand, long>
{
public async Task<long> Handle(Menu_CreateCommand command, CancellationToken cancellationToken)
{
if (string.IsNullOrWhiteSpace(command.Name)) throw new F9OperationException("菜单名称不能为空");
var menu = new Menu(snowflakeIdGenerator.CreateId(), command.Name, command.IconSvg,
command.MenuType, command.AssemblyName, command.TypeFullName, command.ParentId, command.SortOrder);
var result = await menuRepository.AddAsync(menu);
if (result == false) throw new F9OperationException("菜单", "新增");
foreach (var de in menu.DomainEvents) await eventBus.Publish(de, cancellationToken);
menu.ClearDomainEvents();
return menu.Id;
}
}
@@ -0,0 +1,22 @@
using F9WebAiTest.Application.Common.Exceptions;
using F9WebAiTest.Domain.Interfaces.SYS.RBAC.Menus;
using MediatR;
namespace F9WebAiTest.Application.CQRS.SYS.RBAC.Menus.Commands;
/// <summary>命令定义</summary>
public record Menu_DelCommand(long Id) : IRequest<bool>;
/// <summary>命令处理器</summary>
public class DelMenuCommandHandler(
IMenuWriteRepository menuWriteRepository) : IRequestHandler<Menu_DelCommand, bool>
{
public async Task<bool> Handle(Menu_DelCommand command, CancellationToken cancellationToken)
{
if (command.Id <= 0) throw new F9OperationException("菜单ID不能为空");
var result = await menuWriteRepository.SoftDeleteAsync(command.Id);
if (result == false) throw new F9OperationException("菜单", "删除");
return result;
}
}
@@ -0,0 +1,28 @@
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;
/// <summary>命令定义</summary>
public record Menu_UpdateCommand(long Id, string Name, string IconSvg, MenuType_Enum MenuType, string AssemblyName, string TypeFullName, long ParentId, int SortOrder) : IRequest<bool>;
/// <summary>命令处理器</summary>
public class UpdateMenuCommandHandler(
IMenuWriteRepository menuRepository) : IRequestHandler<Menu_UpdateCommand, bool>
{
public async Task<bool> 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;
}
}