fix: 优化列表切片长度处理逻辑

This commit is contained in:
renzhiyuan 2026-03-06 13:37:29 +08:00
parent c7b35f8dcd
commit 777f86b152
1 changed files with 8 additions and 2 deletions

View File

@ -368,7 +368,13 @@ func (b *BbxtTools) GetProfitRankingSum(now time.Time) (report *ReportRes, err e
if err != nil {
return
}
if len(data.List) == 0 {
return nil, nil
}
maxLen := 20
if len(data.List) < maxLen {
maxLen = len(data.List)
}
//排序
sort.Slice(data.List, func(i, j int) bool {
return data.List[i].HistoryOneDiff > data.List[j].HistoryOneDiff
@ -376,7 +382,7 @@ func (b *BbxtTools) GetProfitRankingSum(now time.Time) (report *ReportRes, err e
//取前20和后20
var (
total [][]string
top = data.List[:20]
top = data.List[:maxLen]
bottom = data.List[len(data.List)-20:]
)
//合并前20和后20