fix(api): 修复导出字段重复问题并优化本地开发配置

修复导出字段重复过滤逻辑,添加去重校验和日志记录
将API基础URL切换为本地开发环境配置
This commit is contained in:
zhouyonggao 2025-12-12 15:52:22 +08:00
parent ddec621951
commit 249e62029a
2 changed files with 71 additions and 59 deletions

View File

@ -160,13 +160,13 @@ func (a *ExportsAPI) create(w http.ResponseWriter, r *http.Request) {
} }
} }
// DEBUG LOGGING // DEBUG LOGGING
logging.JSON("INFO", map[string]interface{}{ logging.JSON("INFO", map[string]interface{}{
"event": "export_filters_debug", "event": "export_filters_debug",
"filters": p.Filters, "filters": p.Filters,
"has_creator_in": hasNonEmptyIDs(p.Filters["creator_in"]), "has_creator_in": hasNonEmptyIDs(p.Filters["creator_in"]),
"has_merchant_id_in": hasNonEmptyIDs(p.Filters["merchant_id_in"]), "has_merchant_id_in": hasNonEmptyIDs(p.Filters["merchant_id_in"]),
}) })
if ds == "marketing" && (main == "order" || main == "order_info") { if ds == "marketing" && (main == "order" || main == "order_info") {
if v, ok := p.Filters["create_time_between"]; ok { if v, ok := p.Filters["create_time_between"]; ok {
switch t := v.(type) { switch t := v.(type) {
@ -189,56 +189,68 @@ func (a *ExportsAPI) create(w http.ResponseWriter, r *http.Request) {
return return
} }
} }
filtered := make([]string, 0, len(fs)) filtered := make([]string, 0, len(fs))
tv := 0 tv := 0
if v, ok := p.Filters["type_eq"]; ok { if v, ok := p.Filters["type_eq"]; ok {
switch t := v.(type) { switch t := v.(type) {
case float64: case float64:
tv = int(t) tv = int(t)
case int: case int:
tv = t tv = t
case string: case string:
s := strings.TrimSpace(t) s := strings.TrimSpace(t)
for i := 0; i < len(s); i++ { for i := 0; i < len(s); i++ {
c := s[i] c := s[i]
if c >= '0' && c <= '9' { if c >= '0' && c <= '9' {
tv = tv*10 + int(c-'0') tv = tv*10 + int(c-'0')
} }
} }
} }
} }
for _, tf := range fs { for _, tf := range fs {
if ds == "ymt" && strings.HasPrefix(tf, "order_info.") { if ds == "ymt" && strings.HasPrefix(tf, "order_info.") {
tf = strings.Replace(tf, "order_info.", "order.", 1) tf = strings.Replace(tf, "order_info.", "order.", 1)
} }
if ds == "marketing" && tf == "order_voucher.channel_batch_no" { if ds == "marketing" && tf == "order_voucher.channel_batch_no" {
tf = "order_voucher.channel_activity_id" tf = "order_voucher.channel_activity_id"
} }
if ds == "ymt" && tv == 2 { if ds == "ymt" && tv == 2 {
if strings.HasPrefix(tf, "order_voucher.") || strings.HasPrefix(tf, "goods_voucher_batch.") || strings.HasPrefix(tf, "goods_voucher_subject_config.") { if strings.HasPrefix(tf, "order_voucher.") || strings.HasPrefix(tf, "goods_voucher_batch.") || strings.HasPrefix(tf, "goods_voucher_subject_config.") {
continue continue
} }
} }
if wl[tf] { if wl[tf] {
filtered = append(filtered, tf) filtered = append(filtered, tf)
} }
} }
if ds == "ymt" { {
present := map[string]bool{} seen := map[string]bool{}
for _, f := range filtered { out := make([]string, 0, len(filtered))
present[f] = true for _, f := range filtered {
} if seen[f] {
if present["merchant.name"] && present["order.merchant_name"] { continue
out := make([]string, 0, len(filtered)) }
for _, f := range filtered { seen[f] = true
if f == "order.merchant_name" { out = append(out, f)
continue }
} filtered = out
out = append(out, f) }
} // 字段去重与校验
filtered = out {
} cnt := map[string]int{}
} for _, f := range filtered {
cnt[f]++
}
removed := []string{}
for k, n := range cnt {
if n > 1 {
removed = append(removed, k)
}
}
if len(removed) > 0 {
logging.JSON("INFO", map[string]interface{}{"event": "field_dedupe", "removed": removed})
}
}
// relax: creator_in 非必填,若权限中提供其他边界将被合并为等值过滤 // relax: creator_in 非必填,若权限中提供其他边界将被合并为等值过滤
req := exporter.BuildRequest{MainTable: main, Datasource: ds, Fields: filtered, Filters: p.Filters} req := exporter.BuildRequest{MainTable: main, Datasource: ds, Fields: filtered, Filters: p.Filters}
q, args, err := rrepo.Build(req, wl) q, args, err := rrepo.Build(req, wl)

View File

@ -1,3 +1,3 @@
window.__API_BASE__ = 'https://ymtexporttool.cdlsxd.cn/apiv1/' // window.__API_BASE__ = 'https://ymtexporttool.cdlsxd.cn/apiv1/'
// window.__API_BASE__ = 'http://127.0.0.1:8077' window.__API_BASE__ = 'http://127.0.0.1:8077'
window.__ASSET_VERSION__ = window.__ASSET_VERSION__ || String(Date.now()) window.__ASSET_VERSION__ = window.__ASSET_VERSION__ || String(Date.now())