移除 AutoMapper 依赖
This commit is contained in:
@@ -1,66 +0,0 @@
|
||||
using AutoMapper;
|
||||
using System.Text.Json;
|
||||
using TakeoutSaaS.Application.App.Billings.Dto;
|
||||
using TakeoutSaaS.Domain.Tenants.Entities;
|
||||
using TakeoutSaaS.Domain.Tenants.Enums;
|
||||
|
||||
namespace TakeoutSaaS.Application.App.Billings.Mappings;
|
||||
|
||||
/// <summary>
|
||||
/// 账单模块 AutoMapper Profile。
|
||||
/// </summary>
|
||||
public sealed class BillingProfile : Profile
|
||||
{
|
||||
/// <summary>
|
||||
/// 初始化映射配置。
|
||||
/// </summary>
|
||||
public BillingProfile()
|
||||
{
|
||||
// 1. 账单实体 -> 列表 DTO
|
||||
CreateMap<TenantBillingStatement, BillingListDto>()
|
||||
.ForMember(x => x.TenantName, opt => opt.Ignore())
|
||||
.ForMember(x => x.TotalAmount, opt => opt.MapFrom(src => src.CalculateTotalAmount()))
|
||||
.ForMember(x => x.IsOverdue, opt => opt.MapFrom(src =>
|
||||
src.Status == TenantBillingStatus.Overdue
|
||||
|| (src.Status == TenantBillingStatus.Pending && src.DueDate < DateTime.UtcNow)))
|
||||
.ForMember(x => x.OverdueDays, opt => opt.MapFrom(src =>
|
||||
src.DueDate < DateTime.UtcNow ? (int)(DateTime.UtcNow - src.DueDate).TotalDays : 0));
|
||||
|
||||
// 2. (空行后) 账单实体 -> 详情 DTO
|
||||
CreateMap<TenantBillingStatement, BillingDetailDto>()
|
||||
.ForMember(x => x.TenantName, opt => opt.Ignore())
|
||||
.ForMember(x => x.TotalAmount, opt => opt.MapFrom(src => src.CalculateTotalAmount()))
|
||||
.ForMember(x => x.LineItemsJson, opt => opt.MapFrom(src => src.LineItemsJson))
|
||||
.ForMember(x => x.LineItems, opt => opt.MapFrom(src => DeserializeLineItems(src.LineItemsJson)))
|
||||
.ForMember(x => x.Payments, opt => opt.Ignore());
|
||||
|
||||
// 3. (空行后) 账单实体 -> 导出 DTO
|
||||
CreateMap<TenantBillingStatement, BillingExportDto>()
|
||||
.ForMember(x => x.TenantName, opt => opt.Ignore())
|
||||
.ForMember(x => x.TotalAmount, opt => opt.MapFrom(src => src.CalculateTotalAmount()))
|
||||
.ForMember(x => x.LineItems, opt => opt.MapFrom(src => DeserializeLineItems(src.LineItemsJson)));
|
||||
|
||||
// 4. (空行后) 支付实体 -> 支付记录 DTO
|
||||
CreateMap<TenantPayment, PaymentRecordDto>()
|
||||
.ForMember(x => x.BillingId, opt => opt.MapFrom(src => src.BillingStatementId))
|
||||
.ForMember(x => x.IsVerified, opt => opt.MapFrom(src => src.VerifiedAt.HasValue));
|
||||
}
|
||||
|
||||
private static IReadOnlyList<BillingLineItemDto> DeserializeLineItems(string? json)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(json))
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return JsonSerializer.Deserialize<List<BillingLineItemDto>>(json) ?? [];
|
||||
}
|
||||
catch
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,9 +20,6 @@ public static class AppApplicationServiceCollectionExtensions
|
||||
{
|
||||
services.AddMediatR(cfg => cfg.RegisterServicesFromAssembly(Assembly.GetExecutingAssembly()));
|
||||
services.AddValidatorsFromAssembly(Assembly.GetExecutingAssembly());
|
||||
|
||||
// (空行后) 注册 AutoMapper Profile
|
||||
services.AddAutoMapper(Assembly.GetExecutingAssembly());
|
||||
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(ValidationBehavior<,>));
|
||||
|
||||
return services;
|
||||
|
||||
@@ -9,8 +9,6 @@
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user