feat: 租户账单公告通知接口
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
using MediatR;
|
||||
using TakeoutSaaS.Application.App.Tenants.Commands;
|
||||
using TakeoutSaaS.Application.App.Tenants.Dto;
|
||||
using TakeoutSaaS.Domain.Tenants.Entities;
|
||||
using TakeoutSaaS.Domain.Tenants.Repositories;
|
||||
using TakeoutSaaS.Shared.Abstractions.Constants;
|
||||
using TakeoutSaaS.Shared.Abstractions.Exceptions;
|
||||
|
||||
namespace TakeoutSaaS.Application.App.Tenants.Handlers;
|
||||
|
||||
/// <summary>
|
||||
/// 创建租户账单处理器。
|
||||
/// </summary>
|
||||
public sealed class CreateTenantBillingCommandHandler(ITenantBillingRepository billingRepository)
|
||||
: IRequestHandler<CreateTenantBillingCommand, TenantBillingDto>
|
||||
{
|
||||
public async Task<TenantBillingDto> Handle(CreateTenantBillingCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(request.StatementNo))
|
||||
{
|
||||
throw new BusinessException(ErrorCodes.BadRequest, "账单编号不能为空");
|
||||
}
|
||||
|
||||
var bill = new TenantBillingStatement
|
||||
{
|
||||
TenantId = request.TenantId,
|
||||
StatementNo = request.StatementNo.Trim(),
|
||||
PeriodStart = request.PeriodStart,
|
||||
PeriodEnd = request.PeriodEnd,
|
||||
AmountDue = request.AmountDue,
|
||||
AmountPaid = request.AmountPaid,
|
||||
Status = request.Status,
|
||||
DueDate = request.DueDate,
|
||||
LineItemsJson = request.LineItemsJson
|
||||
};
|
||||
|
||||
await billingRepository.AddAsync(bill, cancellationToken);
|
||||
await billingRepository.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return bill.ToDto();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user