fix: 补齐渠道全量合计筛选导出及有效端目标遗漏
This commit is contained in:
@@ -3,7 +3,9 @@ package business
|
||||
import (
|
||||
"context"
|
||||
"math/big"
|
||||
"strconv"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"kra/internal/biz/business"
|
||||
@@ -40,6 +42,42 @@ func prepareChannels(t *testing.T) (*gorm.DB, business.ChannelRepo) {
|
||||
return db, NewChannelRepo(testData{db})
|
||||
}
|
||||
|
||||
func TestChannelMetadataFiltersSortingAndFullStatusCounts(t *testing.T) {
|
||||
db, repo := prepareChannels(t)
|
||||
day := time.Date(2026, 11, 1, 0, 0, 0, 0, time.FixedZone("Asia/Shanghai", 8*3600))
|
||||
for _, sql := range []string{"ALTER TABLE tab_promote ADD COLUMN mobile_phone TEXT", "ALTER TABLE tab_promote ADD COLUMN settlement_day_period INTEGER", "ALTER TABLE tab_promote ADD COLUMN last_login_time INTEGER"} {
|
||||
if err := db.Exec(sql).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
for i, status := range []int{0, -1, -2} {
|
||||
if err := db.Exec("UPDATE tab_promote SET create_time=?,last_login_time=?,mobile_phone=?,settlement_day_period=7,lock_status=? WHERE source_db='lx' AND id=?", day.Unix()+int64(i+1)*100, day.Unix()+1000, "1381234001"+strconv.Itoa(i), status, 100+i).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
scope := business.UserScope{SelfID: 9, OnlySelf: true}
|
||||
seven := 7
|
||||
filter := business.ChannelFilter{Phone: "4001", SettlementDays: &seven, CreatedBegin: &day, CreatedEnd: &day, LoginBegin: &day, LoginEnd: &day, SortField: "createdAt", Ascending: true}
|
||||
page, err := repo.List(context.Background(), scope, filter, business.ListLimit(1))
|
||||
if err != nil || page.Total != 3 || len(page.Rows) != 1 || page.Rows[0].ID != 100 || page.Rows[0].Phone != "13812340010" || page.Rows[0].SettlementDays == nil || *page.Rows[0].SettlementDays != 7 || page.Rows[0].LastLoginUnix == nil {
|
||||
t.Fatalf("筛选、排序或元数据遗漏: %+v %v", page, err)
|
||||
}
|
||||
if page.StatusCounts.Normal != 1 || page.StatusCounts.Locked != 1 || page.StatusCounts.Terminated != 1 {
|
||||
t.Fatalf("状态汇总必须覆盖全量三条而非当前页: %+v", page.StatusCounts)
|
||||
}
|
||||
filter.Ascending = false
|
||||
page, err = repo.List(context.Background(), scope, filter, business.ListLimit(1))
|
||||
if err != nil || page.Rows[0].ID != 102 {
|
||||
t.Fatalf("降序必须作用于所有页: %+v %v", page, err)
|
||||
}
|
||||
locked := -1
|
||||
filter.LockStatus = &locked
|
||||
page, err = repo.List(context.Background(), scope, filter)
|
||||
if err != nil || page.Total != 1 || page.StatusCounts.Normal != 0 || page.StatusCounts.Locked != 1 || page.StatusCounts.Terminated != 0 {
|
||||
t.Fatalf("筛选变化应同步刷新汇总: %+v %v", page, err)
|
||||
}
|
||||
}
|
||||
|
||||
func channelTestScope() business.UserScope {
|
||||
return business.UserScope{SelfID: 8, IncludeSelf: true, DescendantPath: "0,7,8"}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user