From 249e62029afc948283eb119678872e3d5054c533 Mon Sep 17 00:00:00 2001 From: zhouyonggao <1971162852@qq.com> Date: Fri, 12 Dec 2025 15:52:22 +0800 Subject: [PATCH] =?UTF-8?q?fix(api):=20=E4=BF=AE=E5=A4=8D=E5=AF=BC?= =?UTF-8?q?=E5=87=BA=E5=AD=97=E6=AE=B5=E9=87=8D=E5=A4=8D=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E5=B9=B6=E4=BC=98=E5=8C=96=E6=9C=AC=E5=9C=B0=E5=BC=80=E5=8F=91?= =?UTF-8?q?=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复导出字段重复过滤逻辑,添加去重校验和日志记录 将API基础URL切换为本地开发环境配置 --- server/internal/api/exports.go | 126 ++++++++++++++++++--------------- web/config.js | 4 +- 2 files changed, 71 insertions(+), 59 deletions(-) diff --git a/server/internal/api/exports.go b/server/internal/api/exports.go index c2e5d06..04925b2 100644 --- a/server/internal/api/exports.go +++ b/server/internal/api/exports.go @@ -160,13 +160,13 @@ func (a *ExportsAPI) create(w http.ResponseWriter, r *http.Request) { } } - // DEBUG LOGGING - logging.JSON("INFO", map[string]interface{}{ - "event": "export_filters_debug", - "filters": p.Filters, - "has_creator_in": hasNonEmptyIDs(p.Filters["creator_in"]), - "has_merchant_id_in": hasNonEmptyIDs(p.Filters["merchant_id_in"]), - }) + // DEBUG LOGGING + logging.JSON("INFO", map[string]interface{}{ + "event": "export_filters_debug", + "filters": p.Filters, + "has_creator_in": hasNonEmptyIDs(p.Filters["creator_in"]), + "has_merchant_id_in": hasNonEmptyIDs(p.Filters["merchant_id_in"]), + }) if ds == "marketing" && (main == "order" || main == "order_info") { if v, ok := p.Filters["create_time_between"]; ok { switch t := v.(type) { @@ -189,56 +189,68 @@ func (a *ExportsAPI) create(w http.ResponseWriter, r *http.Request) { return } } - filtered := make([]string, 0, len(fs)) - tv := 0 - if v, ok := p.Filters["type_eq"]; ok { - switch t := v.(type) { - case float64: - tv = int(t) - case int: - tv = t - case string: - s := strings.TrimSpace(t) - for i := 0; i < len(s); i++ { - c := s[i] - if c >= '0' && c <= '9' { - tv = tv*10 + int(c-'0') - } - } - } - } - for _, tf := range fs { - if ds == "ymt" && strings.HasPrefix(tf, "order_info.") { - tf = strings.Replace(tf, "order_info.", "order.", 1) - } - if ds == "marketing" && tf == "order_voucher.channel_batch_no" { - tf = "order_voucher.channel_activity_id" - } - if ds == "ymt" && tv == 2 { - if strings.HasPrefix(tf, "order_voucher.") || strings.HasPrefix(tf, "goods_voucher_batch.") || strings.HasPrefix(tf, "goods_voucher_subject_config.") { - continue - } - } - if wl[tf] { - filtered = append(filtered, tf) - } - } - if ds == "ymt" { - present := map[string]bool{} - for _, f := range filtered { - present[f] = true - } - if present["merchant.name"] && present["order.merchant_name"] { - out := make([]string, 0, len(filtered)) - for _, f := range filtered { - if f == "order.merchant_name" { - continue - } - out = append(out, f) - } - filtered = out - } - } + filtered := make([]string, 0, len(fs)) + tv := 0 + if v, ok := p.Filters["type_eq"]; ok { + switch t := v.(type) { + case float64: + tv = int(t) + case int: + tv = t + case string: + s := strings.TrimSpace(t) + for i := 0; i < len(s); i++ { + c := s[i] + if c >= '0' && c <= '9' { + tv = tv*10 + int(c-'0') + } + } + } + } + for _, tf := range fs { + if ds == "ymt" && strings.HasPrefix(tf, "order_info.") { + tf = strings.Replace(tf, "order_info.", "order.", 1) + } + if ds == "marketing" && tf == "order_voucher.channel_batch_no" { + tf = "order_voucher.channel_activity_id" + } + if ds == "ymt" && tv == 2 { + if strings.HasPrefix(tf, "order_voucher.") || strings.HasPrefix(tf, "goods_voucher_batch.") || strings.HasPrefix(tf, "goods_voucher_subject_config.") { + continue + } + } + if wl[tf] { + filtered = append(filtered, tf) + } + } + { + seen := map[string]bool{} + out := make([]string, 0, len(filtered)) + for _, f := range filtered { + if seen[f] { + continue + } + seen[f] = true + 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 非必填,若权限中提供其他边界将被合并为等值过滤 req := exporter.BuildRequest{MainTable: main, Datasource: ds, Fields: filtered, Filters: p.Filters} q, args, err := rrepo.Build(req, wl) diff --git a/web/config.js b/web/config.js index a28ab44..cece760 100644 --- a/web/config.js +++ b/web/config.js @@ -1,3 +1,3 @@ -window.__API_BASE__ = 'https://ymtexporttool.cdlsxd.cn/apiv1/' -// window.__API_BASE__ = 'http://127.0.0.1:8077' +// window.__API_BASE__ = 'https://ymtexporttool.cdlsxd.cn/apiv1/' +window.__API_BASE__ = 'http://127.0.0.1:8077' window.__ASSET_VERSION__ = window.__ASSET_VERSION__ || String(Date.now())