feat(订阅): 添加节点数量统计功能
Build docker and publish / build (20.15.1) (push) Failing after 33s

在订阅数据结构中新增node_count字段,用于统计符合条件的节点数量
实现根据节点ID和标签计算启用节点数量的逻辑
This commit is contained in:
2025-10-22 04:08:28 -07:00
parent b0a03401b8
commit 267582c6a4
3 changed files with 51 additions and 1 deletions
@@ -3,6 +3,7 @@ package portal
import (
"context"
"encoding/json"
"strings"
"github.com/perfect-panel/server/internal/model/subscribe"
"github.com/perfect-panel/server/internal/svc"
@@ -52,8 +53,28 @@ func (l *GetSubscriptionLogic) GetSubscription(req *types.GetSubscriptionRequest
var discount []types.SubscribeDiscount
_ = json.Unmarshal([]byte(item.Discount), &discount)
sub.Discount = discount
list[i] = sub
}
// 计算节点数量
nodeIds := tool.StringToInt64Slice(item.Nodes)
var nodeTags []string
if item.NodeTags != "" {
tags := strings.Split(item.NodeTags, ",")
for _, tag := range tags {
if strings.TrimSpace(tag) != "" {
nodeTags = append(nodeTags, strings.TrimSpace(tag))
}
}
}
nodeCount, err := l.svcCtx.NodeModel.CountNodesByIdsAndTags(l.ctx, nodeIds, nodeTags)
if err != nil {
l.Logger.Error("[GetSubscription] count nodes failed: ", logger.Field("error", err.Error()))
sub.NodeCount = 0
} else {
sub.NodeCount = nodeCount
}
list[i] = sub
}
resp.List = list