All checks were successful
Build docker and publish / build (20.15.1) (push) Successful in 7m28s
- UserSubscribe/UserSubscribeDetail 新增 node_group_id/node_group_name 字段 - 管理员查询用户订阅列表批量填充分组名 - 管理员查询单个订阅详情填充分组名 - ThrottleResult/UserSubscribeDetail 新增 throttle_start/throttle_end 字段 - 限速时返回限速窗口起止时间(秒级 Unix 时间戳) Co-Authored-By: claude-flow <ruv@ruv.net>
73 lines
2.1 KiB
Go
73 lines
2.1 KiB
Go
package user
|
||
|
||
import (
|
||
"context"
|
||
|
||
"github.com/perfect-panel/server/internal/model/group"
|
||
"github.com/perfect-panel/server/internal/svc"
|
||
"github.com/perfect-panel/server/internal/types"
|
||
"github.com/perfect-panel/server/pkg/logger"
|
||
"github.com/perfect-panel/server/pkg/tool"
|
||
"github.com/perfect-panel/server/pkg/xerr"
|
||
"github.com/pkg/errors"
|
||
)
|
||
|
||
type GetUserSubscribeLogic struct {
|
||
logger.Logger
|
||
ctx context.Context
|
||
svcCtx *svc.ServiceContext
|
||
}
|
||
|
||
// Get user subcribe
|
||
func NewGetUserSubscribeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUserSubscribeLogic {
|
||
return &GetUserSubscribeLogic{
|
||
Logger: logger.WithContext(ctx),
|
||
ctx: ctx,
|
||
svcCtx: svcCtx,
|
||
}
|
||
}
|
||
|
||
func (l *GetUserSubscribeLogic) GetUserSubscribe(req *types.GetUserSubscribeListRequest) (resp *types.GetUserSubscribeListResponse, err error) {
|
||
data, err := l.svcCtx.UserModel.QueryUserSubscribe(l.ctx, req.UserId, 0, 1, 2, 3, 4)
|
||
if err != nil {
|
||
l.Errorw("[GetUserSubscribeLogs] Get User Subscribe Error:", logger.Field("err", err.Error()))
|
||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "Get User Subscribe Error")
|
||
}
|
||
|
||
resp = &types.GetUserSubscribeListResponse{
|
||
List: make([]types.UserSubscribe, 0),
|
||
Total: int64(len(data)),
|
||
}
|
||
|
||
// 收集所有 node_group_id,批量查分组名
|
||
groupIdSet := make(map[int64]struct{})
|
||
for _, item := range data {
|
||
if item.NodeGroupId > 0 {
|
||
groupIdSet[item.NodeGroupId] = struct{}{}
|
||
}
|
||
}
|
||
groupNames := make(map[int64]string)
|
||
if len(groupIdSet) > 0 {
|
||
ids := make([]int64, 0, len(groupIdSet))
|
||
for id := range groupIdSet {
|
||
ids = append(ids, id)
|
||
}
|
||
var groups []group.NodeGroup
|
||
if err := l.svcCtx.DB.WithContext(l.ctx).Where("id IN ?", ids).Find(&groups).Error; err == nil {
|
||
for _, g := range groups {
|
||
groupNames[g.Id] = g.Name
|
||
}
|
||
}
|
||
}
|
||
|
||
for _, item := range data {
|
||
var sub types.UserSubscribe
|
||
tool.DeepCopy(&sub, item)
|
||
sub.Short, _ = tool.FixedUniqueString(item.Token, 8, "")
|
||
sub.NodeGroupId = item.NodeGroupId
|
||
sub.NodeGroupName = groupNames[item.NodeGroupId]
|
||
resp.List = append(resp.List, sub)
|
||
}
|
||
return
|
||
}
|