using TakeoutSaaS.Application.App.Merchants.Dto; using TakeoutSaaS.Domain.Merchants.Entities; using TakeoutSaaS.Domain.Stores.Entities; namespace TakeoutSaaS.Application.App.Merchants; /// /// 商户 DTO 映射工具。 /// internal static class MerchantMapping { /// /// 将商户实体映射为 DTO。 /// /// 商户实体。 /// 商户 DTO。 public static MerchantDto ToDto(Merchant merchant) => new() { Id = merchant.Id, TenantId = merchant.TenantId, BrandName = merchant.BrandName, BrandAlias = merchant.BrandAlias, LogoUrl = merchant.LogoUrl, Category = merchant.Category, ContactPhone = merchant.ContactPhone, ContactEmail = merchant.ContactEmail, Status = merchant.Status, JoinedAt = merchant.JoinedAt, CreatedAt = merchant.CreatedAt }; /// /// 将商户实体映射为列表项 DTO。 /// public static MerchantListItemDto ToListItemDto(Merchant merchant, string? tenantName, int storeCount) => new() { Id = merchant.Id, TenantId = merchant.TenantId, TenantName = tenantName, Name = merchant.BrandName, OperatingMode = merchant.OperatingMode, LicenseNumber = merchant.BusinessLicenseNumber, Status = merchant.Status, IsFrozen = merchant.IsFrozen, StoreCount = storeCount, CreatedAt = merchant.CreatedAt, UpdatedAt = merchant.UpdatedAt }; /// /// 将商户实体映射为详情 DTO。 /// public static MerchantDetailDto ToDetailDto(Merchant merchant, string? tenantName, IReadOnlyList stores) => new() { Id = merchant.Id, TenantId = merchant.TenantId, TenantName = tenantName, Name = merchant.BrandName, OperatingMode = merchant.OperatingMode, LicenseNumber = merchant.BusinessLicenseNumber, LegalRepresentative = merchant.LegalPerson, RegisteredAddress = merchant.Address, ContactPhone = merchant.ContactPhone, ContactEmail = merchant.ContactEmail, Status = merchant.Status, IsFrozen = merchant.IsFrozen, FrozenReason = merchant.FrozenReason, FrozenAt = merchant.FrozenAt, ApprovedBy = merchant.ApprovedBy, ApprovedAt = merchant.ApprovedAt, Stores = stores, RowVersion = merchant.RowVersion, CreatedAt = merchant.CreatedAt, CreatedBy = merchant.CreatedBy, UpdatedAt = merchant.UpdatedAt, UpdatedBy = merchant.UpdatedBy }; /// /// 将商户证照实体映射为 DTO。 /// /// 证照实体。 /// 证照 DTO。 public static MerchantDocumentDto ToDto(MerchantDocument document) => new() { Id = document.Id, MerchantId = document.MerchantId, DocumentType = document.DocumentType, Status = document.Status, FileUrl = document.FileUrl, DocumentNumber = document.DocumentNumber, IssuedAt = document.IssuedAt, ExpiresAt = document.ExpiresAt, Remarks = document.Remarks, CreatedAt = document.CreatedAt }; /// /// 将商户合同实体映射为 DTO。 /// /// 合同实体。 /// 合同 DTO。 public static MerchantContractDto ToDto(MerchantContract contract) => new() { Id = contract.Id, MerchantId = contract.MerchantId, ContractNumber = contract.ContractNumber, Status = contract.Status, StartDate = contract.StartDate, EndDate = contract.EndDate, FileUrl = contract.FileUrl, SignedAt = contract.SignedAt, TerminatedAt = contract.TerminatedAt, TerminationReason = contract.TerminationReason }; /// /// 将商户审核日志实体映射为 DTO。 /// /// 审核日志实体。 /// 审核日志 DTO。 public static MerchantAuditLogDto ToDto(MerchantAuditLog log) => new() { Id = log.Id, MerchantId = log.MerchantId, Action = log.Action, OperatorId = log.OperatorId, Title = log.Title, Description = log.Description, OperatorName = log.OperatorName, IpAddress = log.IpAddress, CreatedAt = log.CreatedAt }; /// /// 将商户变更日志实体映射为 DTO。 /// public static MerchantChangeLogDto ToDto(MerchantChangeLog log) => new() { Id = log.Id, FieldName = log.FieldName, OldValue = log.OldValue, NewValue = log.NewValue, ChangedBy = log.ChangedBy, ChangedByName = log.ChangedByName, ChangedAt = log.CreatedAt, ChangeReason = log.ChangeReason }; /// /// 将门店实体映射为 DTO。 /// public static MerchantStoreDto ToStoreDto(Store store) => new() { Id = store.Id, Name = store.Name, LicenseNumber = store.BusinessLicenseNumber, ContactPhone = store.Phone, Address = store.Address, Status = store.Status }; /// /// 将商户分类实体映射为 DTO。 /// /// 分类实体。 /// 分类 DTO。 public static MerchantCategoryDto ToDto(MerchantCategory category) => new() { Id = category.Id, Name = category.Name, DisplayOrder = category.DisplayOrder, IsActive = category.IsActive, CreatedAt = category.CreatedAt }; /// /// 将证照集合映射为 DTO 集合。 /// /// 证照集合。 /// 证照 DTO 列表。 public static IReadOnlyList ToDocumentDtos(IEnumerable documents) => documents.Select(ToDto).ToList(); /// /// 将合同集合映射为 DTO 集合。 /// /// 合同集合。 /// 合同 DTO 列表。 public static IReadOnlyList ToContractDtos(IEnumerable contracts) => contracts.Select(ToDto).ToList(); /// /// 将分类集合映射为 DTO 集合。 /// /// 分类集合。 /// 分类 DTO 列表。 public static IReadOnlyList ToCategoryDtos(IEnumerable categories) => categories.Select(ToDto).ToList(); /// /// 将门店集合映射为 DTO 集合。 /// public static IReadOnlyList ToStoreDtos(IEnumerable stores) => stores.Select(ToStoreDto).ToList(); }