All checks were successful
Build and Deploy / deploy (push) Successful in 1m3s
- t_order_declaration 新增 ProductId、NonStdProductId、StdProductId(迁移 migrate_order_declaration_product_ids_20261019.sql) - 下单/改单/开放接口/Excel 模板入参、订单详情出参、下游 createOrderOne 报文同步字段 - 自动触发公式目录增加三个字段
240 lines
15 KiB
C#
240 lines
15 KiB
C#
namespace Oms.Application.Services.Orders.Templates;
|
||
|
||
public static class OrderTemplateKeys
|
||
{
|
||
/// <summary>专线小包标准版(含扩展字段)。</summary>
|
||
public const string DedicatedSmallParcelStandard = "dedicated_small_parcel_v1";
|
||
|
||
/// <summary>专线小包精简版(日常批量推荐)。</summary>
|
||
public const string DedicatedSmallParcelSimple = "dedicated_small_parcel_simple_v1";
|
||
|
||
/// <summary>自定义模板字段映射默认对齐标准版字段集。</summary>
|
||
public const string DedicatedSmallParcel = DedicatedSmallParcelStandard;
|
||
}
|
||
|
||
public static class OrderTemplateMappingStatus
|
||
{
|
||
public const string Draft = "draft";
|
||
public const string Ready = "ready";
|
||
}
|
||
|
||
public sealed class OrderTemplateFieldDefinition
|
||
{
|
||
public string FieldKey { get; init; } = string.Empty;
|
||
public string Label { get; init; } = string.Empty;
|
||
public bool Required { get; init; }
|
||
public string DataType { get; init; } = "string";
|
||
public string? DictType { get; init; }
|
||
public string Group { get; init; } = string.Empty;
|
||
public string Example { get; init; } = string.Empty;
|
||
public string Hint { get; init; } = string.Empty;
|
||
public int Sort { get; init; }
|
||
}
|
||
|
||
public static class OrderTemplateFieldRegistry
|
||
{
|
||
private static readonly IReadOnlyList<OrderTemplateFieldDefinition> SimpleFields = BuildDedicatedSmallParcelSimpleFields();
|
||
private static readonly IReadOnlyList<OrderTemplateFieldDefinition> StandardFields = BuildDedicatedSmallParcelStandardFields();
|
||
|
||
public static string GetTemplateDisplayName(string? templateKey)
|
||
{
|
||
var key = NormalizeTemplateKey(templateKey);
|
||
return key switch
|
||
{
|
||
OrderTemplateKeys.DedicatedSmallParcelSimple => "专线小包模板(精简版)",
|
||
OrderTemplateKeys.DedicatedSmallParcelStandard => "专线小包模板(标准版)",
|
||
_ => key,
|
||
};
|
||
}
|
||
|
||
public static bool IsSimpleTemplate(string? templateKey) =>
|
||
string.Equals(NormalizeTemplateKey(templateKey), OrderTemplateKeys.DedicatedSmallParcelSimple, StringComparison.OrdinalIgnoreCase);
|
||
|
||
public static IReadOnlyList<OrderTemplateFieldDefinition> GetFields(string? templateKey)
|
||
{
|
||
var key = NormalizeTemplateKey(templateKey);
|
||
return key switch
|
||
{
|
||
OrderTemplateKeys.DedicatedSmallParcelSimple => SimpleFields,
|
||
OrderTemplateKeys.DedicatedSmallParcelStandard => StandardFields,
|
||
_ => StandardFields,
|
||
};
|
||
}
|
||
|
||
public static OrderTemplateFieldDefinition? TryGetField(string? templateKey, string fieldKey)
|
||
{
|
||
if (string.IsNullOrWhiteSpace(fieldKey))
|
||
{
|
||
return null;
|
||
}
|
||
|
||
return GetFields(templateKey).FirstOrDefault(x =>
|
||
string.Equals(x.FieldKey, fieldKey.Trim(), StringComparison.OrdinalIgnoreCase));
|
||
}
|
||
|
||
private static string NormalizeTemplateKey(string? templateKey) =>
|
||
string.IsNullOrWhiteSpace(templateKey) ? OrderTemplateKeys.DedicatedSmallParcelStandard : templateKey.Trim();
|
||
|
||
private static IReadOnlyList<OrderTemplateFieldDefinition> BuildDedicatedSmallParcelSimpleFields()
|
||
{
|
||
var list = new List<OrderTemplateFieldDefinition>();
|
||
var sort = 0;
|
||
void Add(
|
||
string key,
|
||
string label,
|
||
bool required,
|
||
string dataType = "string",
|
||
string? dictType = null,
|
||
string group = "basic",
|
||
string example = "",
|
||
string hint = "")
|
||
{
|
||
sort += 10;
|
||
list.Add(new OrderTemplateFieldDefinition
|
||
{
|
||
FieldKey = key,
|
||
Label = label,
|
||
Required = required,
|
||
DataType = dataType,
|
||
DictType = dictType,
|
||
Group = group,
|
||
Example = example,
|
||
Hint = hint,
|
||
Sort = sort,
|
||
});
|
||
}
|
||
|
||
Add("clientNo", "客户单号", true, example: "C202604230001", hint: "您自己的订单编号,同一客户不可重复");
|
||
Add("productCode", "运输方式", true, "select", "sales_product", "basic", "PROD001", hint: "从下拉选择产品编码(与查价一致)");
|
||
Add("cargoAttribute", "货物属性", true, "select", "cargo_attribute", "basic", "general", hint: "普货选 general,带电/敏感品选对应用编码");
|
||
Add("warehouseId", "发货仓库", true, "select", "warehouse", "basic", "1", hint: "从下拉选择发货仓库 ID");
|
||
Add("actualWeight", "实重(kg)", true, "number", example: "1.2", hint: "包裹实际重量,单位千克");
|
||
Add("quantity", "包裹件数", true, "number", example: "1", hint: "一般为 1");
|
||
Add("length", "长(cm)", true, "number", example: "10", hint: "必填,用于材积计费");
|
||
Add("width", "宽(cm)", true, "number", example: "10", hint: "必填,用于材积计费");
|
||
Add("height", "高(cm)", true, "number", example: "10", hint: "必填,用于材积计费");
|
||
Add("exportCustomsMode", "出口报关", false, "select", "export_customs_mode", "basic", "9610Simple", hint: "不选则按简易申报;填 9610Summary 时需有默认出口资质或填备案Id,并填电商平台");
|
||
Add("exportQualificationId", "出口资质备案Id", false, "number", example: "1", hint: "9610汇总申报时填写;留空则用客户默认备案");
|
||
Add("platformCode", "电商平台", false, example: "Amazon", hint: "9610汇总申报时必填,写入海关申报电商平台");
|
||
|
||
Add("receiver.recipientsName", "收件人姓名", true, group: "receiver", example: "John Smith", hint: "必填");
|
||
Add("receiver.phone", "收件人手机", true, group: "receiver", example: "13900139000", hint: "必填");
|
||
Add("receiver.countryCode", "目的国代码", true, group: "receiver", example: "US", hint: "二字码,如 US、GB");
|
||
Add("receiver.province", "省/州", false, group: "receiver", example: "California", hint: "建议填写");
|
||
Add("receiver.city", "城市", false, group: "receiver", example: "Los Angeles", hint: "建议填写");
|
||
Add("receiver.streetAddress1", "详细地址", true, group: "receiver", example: "100 Main St", hint: "街道门牌等主地址");
|
||
Add("receiver.zipCode", "邮编", true, group: "receiver", example: "90001", hint: "必填");
|
||
Add("receiver.companyName", "收件公司", false, group: "receiver", example: "Demo LLC", hint: "选填");
|
||
|
||
Add("declaredCurrency", "申报币种", true, "select", "currency", "declaration", "USD", hint: "默认 USD");
|
||
Add("items[0].cnName", "申报品名(中文)", false, group: "declaration", example: "手机壳", hint: "选填");
|
||
Add("items[0].enName", "申报品名(英文)", true, group: "declaration", example: "Phone Case", hint: "必填,用于清关");
|
||
Add("items[0].unitPrice", "申报单价", true, "number", group: "declaration", example: "12.5", hint: "与申报币种一致");
|
||
Add("items[0].unitWeight", "单品重量(kg)", true, "number", group: "declaration", example: "0.3", hint: "单个 SKU 重量");
|
||
Add("items[0].quantity", "申报数量", true, "number", group: "declaration", example: "1", hint: "必填");
|
||
|
||
return list;
|
||
}
|
||
|
||
private static IReadOnlyList<OrderTemplateFieldDefinition> BuildDedicatedSmallParcelStandardFields()
|
||
{
|
||
var list = new List<OrderTemplateFieldDefinition>();
|
||
var sort = 0;
|
||
void Add(
|
||
string key,
|
||
string label,
|
||
bool required,
|
||
string dataType = "string",
|
||
string? dictType = null,
|
||
string group = "basic",
|
||
string example = "",
|
||
string hint = "")
|
||
{
|
||
sort += 10;
|
||
list.Add(new OrderTemplateFieldDefinition
|
||
{
|
||
FieldKey = key,
|
||
Label = label,
|
||
Required = required,
|
||
DataType = dataType,
|
||
DictType = dictType,
|
||
Group = group,
|
||
Example = example,
|
||
Hint = hint,
|
||
Sort = sort,
|
||
});
|
||
}
|
||
|
||
Add("requestId", "幂等请求ID", false, example: "可选", hint: "防重复提交,一般留空");
|
||
Add("clientNo", "客户单号", true, example: "C202604230001", hint: "您自己的订单编号,同一客户不可重复");
|
||
Add("productCode", "运输方式", true, "select", "sales_product", "basic", "PROD001", hint: "从下拉选择产品编码");
|
||
Add("cargoAttribute", "货物属性", true, "select", "cargo_attribute", "basic", "general", hint: "普货选 general");
|
||
Add("exportCustomsMode", "出口报关方式", false, "select", "export_customs_mode", "basic", "9610Simple", hint: "不选则简易申报;填 9610Summary 时需有默认出口资质或填备案Id,并填电商平台");
|
||
Add("exportQualificationId", "出口资质备案Id", false, "number", example: "1", hint: "9610汇总申报时填写;留空则用客户默认备案");
|
||
Add("platformCode", "电商平台", false, example: "Amazon", hint: "9610汇总申报时必填,写入海关申报电商平台");
|
||
Add("warehouseId", "发货仓库", true, "select", "warehouse", "basic", "1", hint: "从下拉选择仓库 ID");
|
||
Add("length", "长(cm)", true, "number", example: "10", hint: "必填,材积计费用");
|
||
Add("width", "宽(cm)", true, "number", example: "10", hint: "必填,材积计费用");
|
||
Add("height", "高(cm)", true, "number", example: "10", hint: "必填,材积计费用");
|
||
Add("actualWeight", "实重(kg)", true, "number", example: "1.2", hint: "必填");
|
||
Add("isCod", "是否COD", false, "boolean", example: "false", hint: "货到付款填 true");
|
||
Add("codCurrency", "COD币种", false, "select", "currency", example: "USD", hint: "COD 订单填写");
|
||
Add("codSum", "COD金额", false, "number", example: "0", hint: "COD 订单填写");
|
||
Add("quantity", "包裹件数", true, "number", example: "1", hint: "一般为 1");
|
||
|
||
Add("receiver.recipientsName", "收件人姓名", true, group: "receiver", example: "Demo Receiver", hint: "必填");
|
||
Add("receiver.companyName", "收件公司", false, group: "receiver", example: "Demo LLC", hint: "选填");
|
||
Add("receiver.phone", "收件人手机", true, group: "receiver", example: "13900139000", hint: "必填");
|
||
Add("receiver.telePhone", "收件人电话", false, group: "receiver", hint: "选填");
|
||
Add("receiver.email", "收件人邮箱", false, group: "receiver", example: "receiver@example.com", hint: "选填");
|
||
Add("receiver.countryCode", "目的国代码", true, group: "receiver", example: "US", hint: "二字码");
|
||
Add("receiver.province", "省/州", false, group: "receiver", example: "California", hint: "建议填写");
|
||
Add("receiver.city", "城市", false, group: "receiver", example: "Los Angeles", hint: "建议填写");
|
||
Add("receiver.streetNumber", "门牌号", false, group: "receiver", example: "1001", hint: "选填");
|
||
Add("receiver.streetAddress1", "地址1", true, group: "receiver", example: "Sunset Blvd", hint: "主地址,必填");
|
||
Add("receiver.streetAddress2", "地址2", false, group: "receiver", hint: "选填");
|
||
Add("receiver.streetAddress3", "地址3", false, group: "receiver", hint: "选填");
|
||
Add("receiver.zipCode", "邮编", true, group: "receiver", example: "90001", hint: "必填");
|
||
Add("receiver.taxType", "税号类型", false, group: "receiver", example: "0", hint: "欧盟等场景选填");
|
||
Add("receiver.taxNo", "税号", false, group: "receiver", hint: "选填");
|
||
Add("receiver.certificateType", "证件类型", false, group: "receiver", example: "0", hint: "选填");
|
||
Add("receiver.certificateNo", "证件号码", false, group: "receiver", hint: "选填");
|
||
Add("receiver.eori", "EORI", false, group: "receiver", hint: "选填");
|
||
Add("receiver.vat", "VAT", false, group: "receiver", hint: "选填");
|
||
|
||
Add("declaredCurrency", "申报币种", true, "select", "currency", "declaration", "USD", hint: "默认 USD");
|
||
Add("declaredSum", "申报总金额", false, "number", group: "declaration", example: "可选", hint: "不填则按明细汇总");
|
||
Add("items[0].cnName", "申报品名(中)", false, group: "declaration", example: "手机壳", hint: "选填");
|
||
Add("items[0].enName", "申报品名(英)", true, group: "declaration", example: "Phone Case", hint: "必填");
|
||
Add("items[0].sku", "SKU", false, group: "declaration", example: "SKU001", hint: "选填");
|
||
Add("items[0].unit", "单位", false, group: "declaration", example: "pcs", hint: "选填");
|
||
Add("items[0].unitPrice", "单价", true, "number", group: "declaration", example: "12.5", hint: "与申报币种一致");
|
||
Add("items[0].unitWeight", "单重(kg)", true, "number", group: "declaration", example: "0.3", hint: "必填");
|
||
Add("items[0].quantity", "申报数量", true, "number", group: "declaration", example: "1", hint: "必填");
|
||
Add("items[0].amount", "总金额", false, "number", group: "declaration", example: "自动计算", hint: "不填=单价×数量");
|
||
Add("items[0].weight", "总重量(kg)", false, "number", group: "declaration", example: "自动计算", hint: "不填=单重×数量");
|
||
Add("items[0].imHsCode", "进口HsCode", false, group: "declaration", hint: "选填");
|
||
Add("items[0].exHsCode", "出口HsCode", false, group: "declaration", hint: "选填");
|
||
Add("items[0].productId", "产品标识编码", false, group: "declaration", hint: "选填");
|
||
Add("items[0].nonStdProductId", "非标产品标识编码", false, group: "declaration", hint: "选填");
|
||
Add("items[0].stdProductId", "标准产品标识编码", false, group: "declaration", hint: "选填");
|
||
Add("items[0].skuImage", "商品图片URL", false, group: "declaration", hint: "选填");
|
||
Add("items[0].category", "类别", false, group: "declaration", example: "Accessories", hint: "选填");
|
||
Add("items[0].brand", "品牌", false, group: "declaration", example: "DemoBrand", hint: "选填");
|
||
Add("items[0].brandType", "品牌类型", false, group: "declaration", hint: "选填");
|
||
Add("items[0].isMagnetic", "是否带磁带电", false, "boolean", group: "declaration", example: "false", hint: "选填");
|
||
Add("items[0].distribution", "配货信息", false, group: "declaration", hint: "选填");
|
||
Add("items[0].material", "材质", false, group: "declaration", example: "plastic", hint: "选填");
|
||
Add("items[0].enMaterial", "英文材质", false, group: "declaration", example: "plastic", hint: "选填");
|
||
Add("items[0].purpose", "用途", false, group: "declaration", example: "protection", hint: "选填");
|
||
Add("items[0].attributes", "属性", false, group: "declaration", hint: "选填");
|
||
Add("items[0].originCountry", "原产国", false, group: "declaration", example: "CN", hint: "选填");
|
||
Add("items[0].salesLink", "销售链接", false, group: "declaration", hint: "选填");
|
||
Add("items[0].model", "型号", false, group: "declaration", example: "Model-X", hint: "选填");
|
||
Add("items[0].specifications", "规格", false, group: "declaration", example: "Standard", hint: "选填");
|
||
Add("items[0].comment", "备注", false, group: "declaration", example: "示例", hint: "选填");
|
||
|
||
return list;
|
||
}
|
||
}
|