refactor(api): 取消字段白名单过滤和去重逻辑

- server/internal/api/exports.go中remove字段白名单过滤和完全重复字段去重步骤
- 直接使用所有字段,无需过滤并简化字段处理流程
- 修正countValidFields函数说明,改为计算不去重、不过滤的有效字段数
- 维护对易码通立减金特殊字段处理逻辑,避免“领取时间”为空问题
This commit is contained in:
zhouyonggao 2025-12-18 11:32:15 +08:00
parent a2840d3ae8
commit b442209bfa
2 changed files with 5 additions and 60 deletions

View File

@ -231,38 +231,9 @@ func (a *ExportsAPI) create(w http.ResponseWriter, r *http.Request) {
}
normalized = tmp
}
// whitelist validation & soft removal of disallowed fields
bad := []string{}
filtered = make([]string, 0, len(normalized))
for _, tf := range normalized {
if !wl[tf] {
bad = append(bad, tf)
continue
}
filtered = append(filtered, tf)
}
if len(bad) > 0 {
logging.JSON("ERROR", map[string]interface{}{"event": "fields_not_whitelisted", "removed": bad})
}
// 字段去重:移除完全重复的字段(包括主表自身的重复)
{
seen := make(map[string]bool)
deduped := make([]string, 0, len(filtered))
removed := []string{}
for _, tf := range filtered {
if seen[tf] {
removed = append(removed, tf)
continue
}
seen[tf] = true
deduped = append(deduped, tf)
}
if len(removed) > 0 {
logging.JSON("INFO", map[string]interface{}{"event": "fields_deduplicated_exact", "removed": removed, "reason": "移除完全重复的字段"})
}
filtered = deduped
}
// 易码通立减金:保留 order_voucher.grant_time移除红包领取时间列避免“领取时间”为空
// 不再使用白名单过滤,直接使用所有字段
filtered = normalized
// 易码通立减金:保留 order_voucher.grant_time移除红包领取时间列避免"领取时间"为空
if ds == "ymt" && tv == 3 {
deduped := make([]string, 0, len(filtered))
removed := []string{}

View File

@ -232,35 +232,9 @@ func (api *TemplatesAPI) listTemplates(w http.ResponseWriter, r *http.Request) {
ok(w, r, templates)
}
// countValidFields 计算有效字段数(去重)
// countValidFields 计算有效字段数(去重,不过滤白名单
func countValidFields(datasource, mainTable string, fields []string, whitelist map[string]bool) int64 {
seen := map[string]struct{}{}
for _, field := range fields {
// YMT系统的order_info映射为order
if datasource == "ymt" && strings.HasPrefix(field, "order_info.") {
field = strings.Replace(field, "order_info.", "order.", 1)
}
// 检查白名单
if !whitelist[field] {
continue
}
// YMT系统客户名称去重
if datasource == "ymt" && field == "order.merchant_name" {
if _, exists := seen["merchant.name"]; exists {
continue
}
}
if _, exists := seen[field]; exists {
continue
}
seen[field] = struct{}{}
}
return int64(len(seen))
return int64(len(fields))
}
// getTemplate 获取单个模板详情