完善基础数据

This commit is contained in:
yanpeng200212
2026-10-08 15:44:07 +08:00
parent 8430ba0452
commit 2ffb83830c
95 changed files with 37759 additions and 5 deletions
@@ -0,0 +1,112 @@
using F9WebAiTest.Application.Common.Exceptions;
using F9WebAiTest.Application.Interfaces.SnowflakeID;
using F9WebAiTest.Domain.Entities.SYS.Zq;
using F9WebAiTest.Domain.Interfaces.SYS.Zq;
using MediatR;
namespace F9WebAiTest.Application.CQRS.SYS.Zq.Commands;
/// <summary>新增账期</summary>
public record Zhangqi_CreateCommand(int Year, int Month, DateTime StartDate, DateTime EndDate) : IRequest<long>;
public class CreateZhangqiCommandHandler(
IZhangqiWriteRepository zhangqiRepository,
ISnowflakeIdGenerator snowflakeIdGenerator,
IPublisher eventBus) : IRequestHandler<Zhangqi_CreateCommand, long>
{
public async Task<long> Handle(Zhangqi_CreateCommand command, CancellationToken cancellationToken)
{
if (command.StartDate > command.EndDate) throw new F9OperationException("开始日期不能大于截止日期");
var entity = new Zhangqi(snowflakeIdGenerator.CreateId(), command.Year, command.Month,
command.StartDate, command.EndDate);
var result = await zhangqiRepository.AddAsync(entity);
if (result == false) throw new F9OperationException("账期", "新增");
foreach (var de in entity.DomainEvents) await eventBus.Publish(de, cancellationToken);
entity.ClearDomainEvents();
return entity.Id;
}
}
/// <summary>修改账期</summary>
public record Zhangqi_UpdateCommand(long Id, int Year, int Month, DateTime StartDate, DateTime EndDate) : IRequest<bool>;
public class UpdateZhangqiCommandHandler(
IZhangqiWriteRepository zhangqiRepository,
IPublisher eventBus) : IRequestHandler<Zhangqi_UpdateCommand, bool>
{
public async Task<bool> Handle(Zhangqi_UpdateCommand command, CancellationToken cancellationToken)
{
if (command.StartDate > command.EndDate) throw new F9OperationException("开始日期不能大于截止日期");
var entity = await zhangqiRepository.GetByIdAsync(command.Id, cancellationToken)
?? throw new F9NotFoundException("账期不存在");
if (entity.IsZhaZhang) throw new F9OperationException("账期已扎帐,请先取消扎帐后再修改");
entity.Update(command.Year, command.Month, command.StartDate, command.EndDate);
var result = await zhangqiRepository.UpdateAsync(entity);
if (result == false) throw new F9OperationException("账期", "修改");
foreach (var de in entity.DomainEvents) await eventBus.Publish(de, cancellationToken);
entity.ClearDomainEvents();
return true;
}
}
/// <summary>删除账期</summary>
public record Zhangqi_DelCommand(long Id) : IRequest<bool>;
public class DelZhangqiCommandHandler(
IZhangqiWriteRepository zhangqiRepository,
IPublisher eventBus) : IRequestHandler<Zhangqi_DelCommand, bool>
{
public async Task<bool> Handle(Zhangqi_DelCommand command, CancellationToken cancellationToken)
{
var entity = await zhangqiRepository.GetByIdAsync(command.Id, cancellationToken)
?? throw new F9NotFoundException("账期不存在");
if (entity.IsZhaZhang) throw new F9OperationException("账期已扎帐,请先取消扎帐后再删除");
var result = await zhangqiRepository.SoftDeleteAsync(command.Id);
if (result == false) throw new F9OperationException("账期", "删除");
entity.Deleted();
foreach (var de in entity.DomainEvents) await eventBus.Publish(de, cancellationToken);
entity.ClearDomainEvents();
return true;
}
}
/// <summary>扎帐 / 取消扎帐(扎帐后账期内业务数据禁止修改)</summary>
public record Zhangqi_ZhaZhangCommand(long Id, bool IsZhaZhang) : IRequest<bool>;
public class ZhaZhangCommandHandler(
IZhangqiWriteRepository zhangqiRepository,
IPublisher eventBus) : IRequestHandler<Zhangqi_ZhaZhangCommand, bool>
{
public async Task<bool> Handle(Zhangqi_ZhaZhangCommand command, CancellationToken cancellationToken)
{
var entity = await zhangqiRepository.GetByIdAsync(command.Id, cancellationToken)
?? throw new F9NotFoundException("账期不存在");
if (entity.IsZhaZhang == command.IsZhaZhang)
throw new F9OperationException(command.IsZhaZhang ? "该账期已扎帐" : "该账期未扎帐");
entity.SetZhaZhang(command.IsZhaZhang);
var result = await zhangqiRepository.SetZhaZhangAsync(command.Id, command.IsZhaZhang);
if (result == false) throw new F9OperationException(command.IsZhaZhang ? "扎帐" : "取消扎帐", "操作");
foreach (var de in entity.DomainEvents) await eventBus.Publish(de, cancellationToken);
entity.ClearDomainEvents();
return true;
}
}