68 lines
1.5 KiB
Go
68 lines
1.5 KiB
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
"lone-services/pkg/modelbase"
|
|
"lone-services/pkg/utils"
|
|
lonelog "lone-services/rpc/lonelog/pb"
|
|
"lone-services/services/lonelog/internal/dao"
|
|
"lone-services/services/lonelog/internal/model"
|
|
"lone-services/services/lonelog/internal/svc"
|
|
"strconv"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type ItemsLogic struct {
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
logx.Logger
|
|
BaseLogic
|
|
}
|
|
|
|
func NewItemsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ItemsLogic {
|
|
return &ItemsLogic{
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
Logger: logx.WithContext(ctx),
|
|
}
|
|
}
|
|
|
|
func (l *ItemsLogic) Items(in *lonelog.ItemsRequest) (*lonelog.Response, error) {
|
|
modelObj := model.ActionModel{}.Init()
|
|
w := modelbase.Params{
|
|
Page: int(in.Page),
|
|
Size: int(in.Size),
|
|
Order: "id desc",
|
|
}
|
|
w.Like = make(map[string]string)
|
|
eq := make(map[string]string)
|
|
w.Other = make(map[string]string)
|
|
if in.AdminId > utils.NumberZero {
|
|
eq["admin_id"] = strconv.FormatInt(in.AdminId, utils.NumberTen)
|
|
}
|
|
|
|
if len(in.Ip) > utils.NumberZero {
|
|
w.Like["ip LIKE ? "] = "%%" + in.Ip + "%%"
|
|
}
|
|
|
|
if in.Type > utils.NumberZero {
|
|
eq["type"] = string(in.Type)
|
|
}
|
|
|
|
if len(in.Time) > utils.NumberZero {
|
|
w.Other["create_time > ?"] = in.Time[utils.NumberZero]
|
|
w.Other["create_time < ?"] = in.Time[utils.NumberOne]
|
|
}
|
|
|
|
w.Eq = eq
|
|
var data []dao.ActionLog
|
|
items, err := modelObj.Page(w, &data)
|
|
if err != nil {
|
|
l.Logger.Error(err)
|
|
return l.fail(utils.Fail)
|
|
}
|
|
|
|
return l.ok(items)
|
|
}
|