fix: 补齐渠道全量合计筛选导出及有效端目标遗漏

This commit is contained in:
Yvan
2026-11-05 10:57:06 +08:00
parent 297a892518
commit 1aa15d3dc8
22 changed files with 545 additions and 88 deletions
+35
View File
@@ -1,7 +1,9 @@
package main
import (
"bytes"
"encoding/json"
"io"
"net/http"
"net/http/httptest"
"path/filepath"
@@ -10,6 +12,7 @@ import (
"github.com/gin-gonic/gin"
"github.com/glebarez/sqlite"
"github.com/xuri/excelize/v2"
"gorm.io/gorm"
businessbiz "kra/internal/biz/business"
"kra/internal/biz/system"
@@ -120,6 +123,38 @@ func TestChannelAndGameAnalyticsHTTP(t *testing.T) {
if first["busierName"] != "SDK账号" || first["newRegisterCount"] != float64(1) {
t.Fatal("渠道树去重或商务展示未保留")
}
t.Run("export includes every authorized row and all totals", func(t *testing.T) {
req, _ := http.NewRequest("GET", server.URL+"/sw/channelData/list?export=true&sourceDb=lx,hw&beginTime=2026-11-04&endTime=2026-11-04&pageSize=1&pageNum=99", nil)
req.Header.Set("X-Test-User", "7")
res, err := server.Client().Do(req)
if err != nil {
t.Fatal(err)
}
defer res.Body.Close()
body, err := io.ReadAll(res.Body)
if err != nil {
t.Fatal(err)
}
if res.Header.Get("success") != "true" {
t.Fatalf("export failed: %s", body)
}
book, err := excelize.OpenReader(bytes.NewReader(body))
if err != nil {
t.Fatal(err)
}
defer book.Close()
rows, err := book.GetRows("渠道数据统计")
if err != nil {
t.Fatal(err)
}
if len(rows) != 4 || rows[1][0] != "龙翔" || rows[2][0] != "龙翔" || rows[3][0] != "全部" || rows[3][1] != "合计(有效端 0)" || rows[3][9] != "66.67%" {
t.Fatalf("导出必须包含可见全量及完整合计,不受分页影响: %+v", rows)
}
amount, _ := book.GetCellValue("渠道数据统计", "G4", excelize.Options{RawCellValue: true})
if amount != "60.00" {
t.Fatalf("export amount=%s", amount)
}
})
data = call(1, "channelData", "sourceDb=lx,hw", 0)
if data["total"] != float64(5) || data["totalRegisterCount"] != float64(3) || data["totalPayAmount"] != "112.00" || data["avgPayRate"] != "75.00" {
t.Fatalf("超管应全局去重并包含官方/未知渠道: %+v", data)