64 lines
1.4 KiB
Go
64 lines
1.4 KiB
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
"lone-services/pkg/modelbase"
|
|
"lone-services/pkg/utils"
|
|
"lone-services/services/factory/internal/dao"
|
|
"lone-services/services/factory/internal/model"
|
|
"lone-services/services/factory/validator"
|
|
|
|
"lone-services/rpc/factory/pb"
|
|
"lone-services/services/factory/internal/svc"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type WorkerItemsLogic struct {
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
logx.Logger
|
|
BaseLogic
|
|
}
|
|
|
|
func NewWorkerItemsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *WorkerItemsLogic {
|
|
return &WorkerItemsLogic{
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
Logger: logx.WithContext(ctx),
|
|
}
|
|
}
|
|
|
|
func (l *WorkerItemsLogic) WorkerItems(in *factory.WorkerItemsRequest) (*factory.Response, error) {
|
|
var v validator.WorkerItemsValidator
|
|
if fail := l.checkParams(in, &v); fail != nil {
|
|
return fail, nil
|
|
}
|
|
adminInfo := utils.GetUserFromCtx(l.ctx)
|
|
if adminInfo.ID < utils.NumberOne {
|
|
return l.fail(utils.ErrorNoLoginInfo)
|
|
}
|
|
var info []dao.WorkerInfo
|
|
w := modelbase.Params{
|
|
Page: int(in.Page),
|
|
Size: int(in.Size),
|
|
Order: "id desc",
|
|
}
|
|
|
|
w.Like = make(map[string]string)
|
|
w.Other = make(map[string]string)
|
|
w.Eq = make(map[string]string)
|
|
|
|
if len(in.Name) > utils.NumberZero {
|
|
w.Like["name LIKE ? "] = "%%" + in.Name + "%%"
|
|
}
|
|
|
|
items, err := model.WorkerModel{}.Init().Page(w, &info)
|
|
if err != nil {
|
|
l.Logger.Error(err)
|
|
return l.fail(utils.ErrorNotFund)
|
|
}
|
|
|
|
return l.ok(items)
|
|
}
|