feat(订阅查询): 添加节点数量计算逻辑
Some checks failed
Build docker and publish / build (20.15.1) (push) Failing after 41s

在查询订阅列表时,解析节点ID和标签并计算对应的节点数量
This commit is contained in:
shanshanzhong 2025-10-22 04:25:31 -07:00
parent 267582c6a4
commit ea1ef3527b
3 changed files with 29 additions and 1 deletions

View File

@ -3,6 +3,7 @@ package subscribe
import (
"context"
"encoding/json"
"strings"
"github.com/perfect-panel/server/internal/model/subscribe"
"github.com/perfect-panel/server/internal/svc"
@ -53,8 +54,35 @@ func (l *QuerySubscribeListLogic) QuerySubscribeList(req *types.QuerySubscribeLi
var discount []types.SubscribeDiscount
_ = json.Unmarshal([]byte(item.Discount), &discount)
sub.Discount = discount
list[i] = sub
}
// 计算节点数量
var nodeIds []int64
var tags []string
// 解析节点ID
if item.Nodes != "" {
nodeIds = tool.StringToInt64Slice(item.Nodes)
}
// 解析标签
if item.NodeTags != "" {
tagStrs := strings.Split(item.NodeTags, ",")
for _, tag := range tagStrs {
if tag != "" {
tags = append(tags, tag)
}
}
}
// 获取节点数量
nodeCount, err := l.svcCtx.NodeModel.CountNodesByIdsAndTags(l.ctx, nodeIds, tags)
if err != nil {
l.Errorw("[QuerySubscribeListLogic] Count nodes failed", logger.Field("error", err.Error()), logger.Field("subscribeId", item.Id))
nodeCount = 0 // 出错时设置为0
}
sub.NodeCount = nodeCount
list[i] = sub
}
resp.List = list

Binary file not shown.

BIN
server

Binary file not shown.