fix: 完成商务迁移复核与接口优化并清理历史资料

This commit is contained in:
Yvan
2026-11-04 14:45:02 +08:00
parent 5a96be6a79
commit 297e80827d
176 changed files with 6803 additions and 6002 deletions
+51
View File
@@ -3,6 +3,8 @@ package business
import (
"context"
"fmt"
"math/big"
"sort"
"testing"
"time"
)
@@ -13,6 +15,52 @@ type workbenchRepoFake struct {
window WorkbenchWindow
filter AnalyticsFilter
scope AnalyticsScope
named []*WorkbenchRankRow
}
func TestWorkbenchTopTenMatchesFullStableSort(t *testing.T) {
for _, kind := range []WorkbenchRankKind{WorkbenchPayHigh, WorkbenchPayLow} {
uc, repo := workbenchFixture()
for i := 0; i < 3000; i++ {
repo.data.Rows = append(repo.data.Rows, &WorkbenchRankRow{AnalyticsKey: AnalyticsKey{ID: int64(i%11 + 1), SourceDB: []string{"lx", "hw", "yq"}[i%3]}, Name: fmt.Sprintf("candidate-%04d", i), Value: big.NewRat(int64(i%7-2), 100).FloatString(2)})
}
expected := make([]*WorkbenchRankRow, 0, len(repo.data.Rows))
for _, row := range repo.data.Rows {
n, _ := new(big.Rat).SetString(row.Value)
if kind == WorkbenchPayLow || n.Sign() > 0 {
expected = append(expected, row)
}
}
sort.SliceStable(expected, func(i, j int) bool {
a, b := expected[i], expected[j]
av, _ := new(big.Rat).SetString(a.Value)
bv, _ := new(big.Rat).SetString(b.Value)
if order := av.Cmp(bv); order != 0 {
if kind == WorkbenchPayLow {
return order < 0
}
return order > 0
}
if a.ID != b.ID {
return a.ID < b.ID
}
return a.SourceDB < b.SourceDB
})
actual, err := uc.Ranks(accountContext(7, 901), []string{"lx", "hw", "yq"}, "last30", kind)
if err != nil || len(actual) != 10 {
t.Fatalf("rank failed: %v", err)
}
for i, row := range actual {
if row.AnalyticsKey != expected[i].AnalyticsKey || row.Value != expected[i].Value || row.Name != expected[i].Name || row.Rank != i+1 {
t.Fatalf("%s rank %d differs from full stable sort: %+v vs %+v", kind, i, row, expected[i])
}
}
}
}
func (r *workbenchRepoFake) FillRankNames(_ context.Context, rows []*WorkbenchRankRow) error {
r.named = rows
return nil
}
func (r *workbenchRepoFake) Summary(_ context.Context, s AnalyticsScope, _ []string, w WorkbenchWindow) (*WorkbenchTotals, error) {
@@ -64,6 +112,9 @@ func TestWorkbenchRankLimitsExactSortDefaultsAndUnlogin(t *testing.T) {
if err != nil || len(rows) != 10 || rows[0].ID != 13 || rows[9].Rank != 10 {
t.Fatal("榜单排序或 TOP10 截断错误")
}
if len(r.named) != 10 {
t.Fatal("仅应补充已入选 TOP10 的渠道名称")
}
rows, err = uc.Ranks(ctx, []string{"lx"}, "", WorkbenchPayLow)
if err != nil || rows[0].ID != 0 || rows[0].Value != "0.00" || rows[0].Name != "官方渠道" || r.filter.Begin != "2026-03-02" {
t.Fatal("最低榜应包含零值,默认近30天")