All checks were successful
Build and Deploy / deploy (push) Successful in 1m13s
支持按 box/sku 模板生成 PDF;待支付前可改产品并自动重排货重算费。 Co-authored-by: Cursor <cursoragent@cursor.com>
89 lines
3.2 KiB
C#
89 lines
3.2 KiB
C#
using System.Globalization;
|
||
using Oms.Domain.WarehouseAggregate.Entities;
|
||
|
||
namespace Oms.Application.Labeling;
|
||
|
||
/// <summary>
|
||
/// 库内 SKU 标签 PrintData(camelCase,与 hiprint 字段对齐)。
|
||
/// </summary>
|
||
public static class SkuLabelPrintDataBuilder
|
||
{
|
||
public static IReadOnlyDictionary<string, object?> 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<string, object?>(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
|
||
};
|
||
}
|
||
|
||
/// <summary>
|
||
/// 设计预览用 Mock PrintData。
|
||
/// </summary>
|
||
public static IReadOnlyDictionary<string, object?> BuildMock() =>
|
||
new Dictionary<string, object?>(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}";
|
||
}
|
||
}
|