feat: ad manager
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"lone-services/pkg/modelbase"
|
||||
"lone-services/pkg/utils"
|
||||
"lone-services/pkg/validate"
|
||||
ad "lone-services/rpc/ad/pb"
|
||||
"lone-services/services/ad/internal/dao"
|
||||
"lone-services/services/ad/internal/model"
|
||||
"lone-services/services/ad/internal/svc"
|
||||
"lone-services/services/ad/validator"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type WebItemsLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewWebItemsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *WebItemsLogic {
|
||||
return &WebItemsLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *WebItemsLogic) WebItems(in *ad.WebItemsReq) (*ad.Response, error) {
|
||||
var req validator.AdWebItemsValidator
|
||||
if msg := validate.ValidateFromProto(in, &req); msg != utils.StringEmpty {
|
||||
return outResponse(utils.ErrorParams, msg), nil
|
||||
}
|
||||
|
||||
types := make([]string, 0)
|
||||
for _, t := range strings.Split(req.Type, utils.DecollatorComma) {
|
||||
t = strings.TrimSpace(t)
|
||||
if t != "" {
|
||||
types = append(types, t)
|
||||
}
|
||||
}
|
||||
if len(types) < 1 {
|
||||
return outResponse(utils.ErrorParams, "请选择类型"), nil
|
||||
}
|
||||
|
||||
w := modelbase.Params{
|
||||
Order: "type asc",
|
||||
In: map[string][]string{"type": types},
|
||||
Eq: map[string]string{"status": utils.StringStatusOk},
|
||||
}
|
||||
|
||||
var info []dao.AdWebInfo
|
||||
if err := (model.AdModel{}.Init().Items(w, &info)); err != nil {
|
||||
l.Errorf("ad web items: %v", err)
|
||||
return failResponse(utils.Fail), nil
|
||||
}
|
||||
|
||||
items := make([]*ad.WebItem, 0, len(info))
|
||||
for _, row := range info {
|
||||
items = append(items, toAdWebItem(row))
|
||||
}
|
||||
|
||||
return okResponse(utils.StructToJson(items)), nil
|
||||
}
|
||||
Reference in New Issue
Block a user