feat(订阅查询): 添加节点数量计算逻辑
Some checks failed
Build docker and publish / build (20.15.1) (push) Failing after 41s
Some checks failed
Build docker and publish / build (20.15.1) (push) Failing after 41s
在查询订阅列表时,解析节点ID和标签并计算对应的节点数量
This commit is contained in:
parent
267582c6a4
commit
ea1ef3527b
@ -3,6 +3,7 @@ package subscribe
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/perfect-panel/server/internal/model/subscribe"
|
"github.com/perfect-panel/server/internal/model/subscribe"
|
||||||
"github.com/perfect-panel/server/internal/svc"
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
@ -53,8 +54,35 @@ func (l *QuerySubscribeListLogic) QuerySubscribeList(req *types.QuerySubscribeLi
|
|||||||
var discount []types.SubscribeDiscount
|
var discount []types.SubscribeDiscount
|
||||||
_ = json.Unmarshal([]byte(item.Discount), &discount)
|
_ = json.Unmarshal([]byte(item.Discount), &discount)
|
||||||
sub.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
|
list[i] = sub
|
||||||
}
|
}
|
||||||
resp.List = list
|
resp.List = list
|
||||||
|
|||||||
BIN
ppanel-server
BIN
ppanel-server
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user