using System.Globalization; using Oms.Domain.WarehouseAggregate.Entities; namespace Oms.Application.Labeling; /// /// 库内 SKU 标签 PrintData(camelCase,与 hiprint 字段对齐)。 /// public static class SkuLabelPrintDataBuilder { public static IReadOnlyDictionary Build( CSku sku, string? customerName = null, string? customerCode = null, string? warehouseName = null, string? operatorName = null, DateTime? printTime = null) { var barcode = string.IsNullOrWhiteSpace(sku.SkuCode) ? $"SKU-{sku.Id}" : sku.SkuCode.Trim(); return new Dictionary(StringComparer.OrdinalIgnoreCase) { ["skuId"] = sku.Id, ["skuCode"] = sku.SkuCode, ["skuName"] = sku.SkuName, ["skuNameEn"] = sku.SkuNameEn, ["barcode"] = barcode, ["skuImageUrl"] = sku.SkuImageUrl, ["unitPrice"] = sku.UnitPrice, ["exHsCode"] = sku.ExHsCode, ["imHsCode"] = sku.ImHsCode, ["declareElement"] = sku.DeclareElement, ["weightG"] = sku.WeightG, ["lengthCm"] = sku.LengthCm, ["widthCm"] = sku.WidthCm, ["heightCm"] = sku.HeightCm, ["dimensions"] = FormatDimensions(sku.LengthCm, sku.WidthCm, sku.HeightCm), ["remark"] = sku.Remark, ["weightUnit"] = "G", ["dimUnit"] = "CM", ["customerCode"] = customerCode, ["customerName"] = customerName, ["warehouseName"] = warehouseName, ["printTime"] = (printTime ?? DateTime.Now).ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture), ["operatorName"] = operatorName }; } /// /// 设计预览用 Mock PrintData。 /// public static IReadOnlyDictionary BuildMock() => new Dictionary(StringComparer.OrdinalIgnoreCase) { ["skuId"] = 1, ["skuCode"] = "SKU001", ["skuName"] = "T-Shirt", ["skuNameEn"] = "T-Shirt", ["barcode"] = "SKU001", ["skuImageUrl"] = null, ["unitPrice"] = 9.9m, ["exHsCode"] = "610910", ["imHsCode"] = "610910", ["declareElement"] = "棉质 T 恤", ["weightG"] = 200m, ["lengthCm"] = 30m, ["widthCm"] = 20m, ["heightCm"] = 2m, ["dimensions"] = "30×20×2", ["remark"] = null, ["weightUnit"] = "G", ["dimUnit"] = "CM", ["customerCode"] = "AF0A1", ["customerName"] = "Demo Customer", ["warehouseName"] = "SZ-01", ["printTime"] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture), ["operatorName"] = "preview" }; private static string? FormatDimensions(decimal? length, decimal? width, decimal? height) { if (length is null && width is null && height is null) { return null; } return $"{length ?? 0}×{width ?? 0}×{height ?? 0}"; } }