Files
ycc-proxy-server/app/main/api/internal/logic/agent/getwhitelistfeatureslogic.go
2026-01-12 16:43:08 +08:00

58 lines
1.5 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package agent
import (
"context"
"ycc-server/common/xerr"
"github.com/pkg/errors"
"ycc-server/app/main/api/internal/svc"
"ycc-server/app/main/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type GetWhitelistFeaturesLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewGetWhitelistFeaturesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetWhitelistFeaturesLogic {
return &GetWhitelistFeaturesLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *GetWhitelistFeaturesLogic) GetWhitelistFeatures(req *types.GetWhitelistFeaturesReq) (resp *types.GetWhitelistFeaturesResp, err error) {
// 使用SelectBuilder查询所有feature然后筛选whitelist_price > 0的
// 注意系统会自动处理del_state不需要手动添加
builder := l.svcCtx.FeatureModel.SelectBuilder().
Where("whitelist_price > 0").
OrderBy("name ASC")
features, err := l.svcCtx.FeatureModel.FindAll(l.ctx, builder, "")
if err != nil {
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "查询feature列表失败, %v", err)
}
// 组装响应直接使用feature的WhitelistPrice字段
list := make([]types.WhitelistFeatureItem, 0, len(features))
for _, f := range features {
if f.WhitelistPrice > 0 {
list = append(list, types.WhitelistFeatureItem{
FeatureId: f.Id,
FeatureApiId: f.ApiId,
FeatureName: f.Name,
WhitelistPrice: f.WhitelistPrice,
})
}
}
return &types.GetWhitelistFeaturesResp{
List: list,
}, nil
}