Files
qnc-server-v3/app/main/api/internal/logic/agent/getwhitelistfeatureslogic.go
2026-03-02 12:46:26 +08:00

46 lines
1.3 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"
"github.com/zeromicro/go-zero/core/logx"
"qnc-server/app/main/api/internal/svc"
"qnc-server/app/main/api/internal/types"
"qnc-server/common/xerr"
"github.com/pkg/errors"
)
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,
}
}
// GetWhitelistFeatures 返回支持白名单屏蔽的 feature 列表whitelist_price > 0
func (l *GetWhitelistFeaturesLogic) GetWhitelistFeatures(req *types.GetWhitelistFeaturesReq) (resp *types.GetWhitelistFeaturesResp, err error) {
builder := l.svcCtx.FeatureModel.SelectBuilder().Where("whitelist_price > ?", 0)
list, err := l.svcCtx.FeatureModel.FindAll(l.ctx, builder, "id ASC")
if err != nil {
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "查询功能列表失败, %v", err)
}
items := make([]types.WhitelistFeatureItem, 0, len(list))
for _, f := range list {
items = append(items, types.WhitelistFeatureItem{
FeatureId: f.Id,
FeatureApiId: f.ApiId,
FeatureName: f.Name,
WhitelistPrice: f.WhitelistPrice,
})
}
return &types.GetWhitelistFeaturesResp{List: items}, nil
}