fix
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user