fix(导出): 修复导出列名冲突问题并更新字段映射文档
调整 order_digit.order_type 的显示名从"订单类型"为"商品类型"以避免歧义 添加列名去重逻辑,当不同表存在相同列名时自动添加表名前缀 新增字段映射文档说明去重策略和兼容性影响
This commit is contained in:
parent
582a5daeea
commit
d17ae70ea9
|
|
@ -0,0 +1,29 @@
|
|||
# 字段映射与去重策略
|
||||
|
||||
## 目标
|
||||
- 避免导出的 Excel 中出现同名列导致语义冲突
|
||||
- 当不同表存在语义不同但中文名相同的字段时,消除歧义
|
||||
- 保证从主表提取的核心字段只出现一次
|
||||
|
||||
## 关键变更
|
||||
- 将 `ymt` 数据源中 `order_digit.order_type` 的中文列名从“订单类型”调整为“商品类型”
|
||||
- 当同一导出模板中不同表出现相同列名时,对非主表字段自动添加前缀:`<表显示名>.<列名>`,例如:
|
||||
- `order.type` → `订单类型`
|
||||
- `order_digit.order_type` → `直充卡密订单.商品类型`
|
||||
|
||||
## 表显示名
|
||||
- `order` → 订单主表
|
||||
- `order_detail` → 订单详情
|
||||
- `order_cash` → 红包订单
|
||||
- `order_voucher` → 立减金订单
|
||||
- `order_digit` → 直充卡密订单
|
||||
- 其他参见后端 `tableLabel` 定义
|
||||
|
||||
## 使用建议
|
||||
- 如需仅导出“订单类型”,请选择主表字段 `order.type`
|
||||
- 如需区分直充/卡密的商品类型,可额外选择 `order_digit.order_type`,导出列名为“直充卡密订单.商品类型”
|
||||
|
||||
## 兼容性
|
||||
- 该变更仅影响导出列头的中文显示,不影响 SQL 字段来源与数据准确性
|
||||
- 现有模板无需修改;若模板包含两列“订单类型”,修复后其中一列会显示为带前缀的“直充卡密订单.商品类型`
|
||||
|
||||
|
|
@ -280,6 +280,20 @@ func (a *ExportsAPI) create(w http.ResponseWriter, r *http.Request) {
|
|||
hdrs[i] = tf
|
||||
}
|
||||
}
|
||||
{
|
||||
cnt := map[string]int{}
|
||||
for _, h := range hdrs {
|
||||
cnt[h]++
|
||||
}
|
||||
for i := range hdrs {
|
||||
if cnt[hdrs[i]] > 1 {
|
||||
parts := strings.Split(filtered[i], ".")
|
||||
if len(parts) == 2 && parts[0] != "order" {
|
||||
hdrs[i] = tableLabel(parts[0]) + "." + hdrs[i]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// owner from query userId if provided
|
||||
owner := uint64(0)
|
||||
if uidStr := r.URL.Query().Get("userId"); uidStr != "" {
|
||||
|
|
|
|||
|
|
@ -377,7 +377,7 @@ func AllLabels() map[string]string {
|
|||
"order_digit.user_id": "创建者ID",
|
||||
"order_digit.success_time": "到账时间",
|
||||
"order_digit.supplier_product_no": "供应商产品编码",
|
||||
"order_digit.order_type": "订单类型",
|
||||
"order_digit.order_type": "商品类型",
|
||||
"order_digit.end_time": "卡密有效期",
|
||||
"order_digit.create_time": "创建时间",
|
||||
"order_digit.update_time": "更新时间",
|
||||
|
|
|
|||
Loading…
Reference in New Issue