140 lines
5.3 KiB
C#
140 lines
5.3 KiB
C#
using TakeoutSaaS.Application.App.Tenants.Dto;
|
|
using TakeoutSaaS.Domain.Tenants.Entities;
|
|
|
|
namespace TakeoutSaaS.Application.App.Tenants;
|
|
|
|
/// <summary>
|
|
/// 租户 DTO 映射助手。
|
|
/// </summary>
|
|
internal static class TenantMapping
|
|
{
|
|
public static TenantDto ToDto(Tenant tenant, TenantSubscription? subscription, TenantVerificationProfile? verification)
|
|
=> new()
|
|
{
|
|
Id = tenant.Id,
|
|
Code = tenant.Code,
|
|
Name = tenant.Name,
|
|
ShortName = tenant.ShortName,
|
|
ContactName = tenant.ContactName,
|
|
ContactPhone = tenant.ContactPhone,
|
|
ContactEmail = tenant.ContactEmail,
|
|
Status = tenant.Status,
|
|
VerificationStatus = verification?.Status ?? Domain.Tenants.Enums.TenantVerificationStatus.Draft,
|
|
CurrentPackageId = subscription?.TenantPackageId,
|
|
EffectiveFrom = subscription?.EffectiveFrom ?? tenant.EffectiveFrom,
|
|
EffectiveTo = subscription?.EffectiveTo ?? tenant.EffectiveTo,
|
|
AutoRenew = subscription?.AutoRenew ?? false
|
|
};
|
|
|
|
public static TenantVerificationDto? ToVerificationDto(this TenantVerificationProfile? profile)
|
|
=> profile == null
|
|
? null
|
|
: new TenantVerificationDto
|
|
{
|
|
Id = profile.Id,
|
|
TenantId = profile.TenantId,
|
|
Status = profile.Status,
|
|
BusinessLicenseNumber = profile.BusinessLicenseNumber,
|
|
BusinessLicenseUrl = profile.BusinessLicenseUrl,
|
|
LegalPersonName = profile.LegalPersonName,
|
|
LegalPersonIdNumber = profile.LegalPersonIdNumber,
|
|
BankAccountNumber = profile.BankAccountNumber,
|
|
BankName = profile.BankName,
|
|
ReviewRemarks = profile.ReviewRemarks,
|
|
ReviewedByName = profile.ReviewedByName,
|
|
ReviewedAt = profile.ReviewedAt
|
|
};
|
|
|
|
public static TenantSubscriptionDto? ToSubscriptionDto(this TenantSubscription? subscription)
|
|
=> subscription == null
|
|
? null
|
|
: new TenantSubscriptionDto
|
|
{
|
|
Id = subscription.Id,
|
|
TenantId = subscription.TenantId,
|
|
TenantPackageId = subscription.TenantPackageId,
|
|
Status = subscription.Status,
|
|
EffectiveFrom = subscription.EffectiveFrom,
|
|
EffectiveTo = subscription.EffectiveTo,
|
|
NextBillingDate = subscription.NextBillingDate,
|
|
AutoRenew = subscription.AutoRenew
|
|
};
|
|
|
|
public static TenantAuditLogDto ToDto(this TenantAuditLog log)
|
|
=> new()
|
|
{
|
|
Id = log.Id,
|
|
TenantId = log.TenantId,
|
|
Action = log.Action,
|
|
Title = log.Title,
|
|
Description = log.Description,
|
|
OperatorName = log.OperatorName,
|
|
PreviousStatus = log.PreviousStatus,
|
|
CurrentStatus = log.CurrentStatus,
|
|
CreatedAt = log.CreatedAt
|
|
};
|
|
|
|
public static TenantPackageDto ToDto(this TenantPackage package)
|
|
=> new()
|
|
{
|
|
Id = package.Id,
|
|
Name = package.Name,
|
|
Description = package.Description,
|
|
PackageType = package.PackageType,
|
|
MonthlyPrice = package.MonthlyPrice,
|
|
YearlyPrice = package.YearlyPrice,
|
|
MaxStoreCount = package.MaxStoreCount,
|
|
MaxAccountCount = package.MaxAccountCount,
|
|
MaxStorageGb = package.MaxStorageGb,
|
|
MaxSmsCredits = package.MaxSmsCredits,
|
|
MaxDeliveryOrders = package.MaxDeliveryOrders,
|
|
FeaturePoliciesJson = package.FeaturePoliciesJson,
|
|
IsActive = package.IsActive
|
|
};
|
|
|
|
public static TenantBillingDto ToDto(this TenantBillingStatement bill)
|
|
=> new()
|
|
{
|
|
Id = bill.Id,
|
|
TenantId = bill.TenantId,
|
|
StatementNo = bill.StatementNo,
|
|
PeriodStart = bill.PeriodStart,
|
|
PeriodEnd = bill.PeriodEnd,
|
|
AmountDue = bill.AmountDue,
|
|
AmountPaid = bill.AmountPaid,
|
|
Status = bill.Status,
|
|
DueDate = bill.DueDate,
|
|
LineItemsJson = bill.LineItemsJson
|
|
};
|
|
|
|
public static TenantAnnouncementDto ToDto(this TenantAnnouncement announcement, bool isRead, DateTime? readAt)
|
|
=> new()
|
|
{
|
|
Id = announcement.Id,
|
|
TenantId = announcement.TenantId,
|
|
Title = announcement.Title,
|
|
Content = announcement.Content,
|
|
AnnouncementType = announcement.AnnouncementType,
|
|
Priority = announcement.Priority,
|
|
EffectiveFrom = announcement.EffectiveFrom,
|
|
EffectiveTo = announcement.EffectiveTo,
|
|
IsActive = announcement.IsActive,
|
|
IsRead = isRead,
|
|
ReadAt = readAt
|
|
};
|
|
|
|
public static TenantNotificationDto ToDto(this TenantNotification notification)
|
|
=> new()
|
|
{
|
|
Id = notification.Id,
|
|
TenantId = notification.TenantId,
|
|
Title = notification.Title,
|
|
Message = notification.Message,
|
|
Channel = notification.Channel,
|
|
Severity = notification.Severity,
|
|
SentAt = notification.SentAt,
|
|
ReadAt = notification.ReadAt,
|
|
MetadataJson = notification.MetadataJson
|
|
};
|
|
}
|