fusenapi/server/inventory/internal/logic/getpickuplistlogic.go
laodaming f09e1b8f93 fix
2023-06-29 13:59:55 +08:00

72 lines
1.9 KiB
Go

package logic
import (
"fusenapi/constants"
"fusenapi/model/gmodel"
"fusenapi/utils/auth"
"fusenapi/utils/basic"
"context"
"fusenapi/server/inventory/internal/svc"
"fusenapi/server/inventory/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type GetPickupListLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewGetPickupListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetPickupListLogic {
return &GetPickupListLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *GetPickupListLogic) GetPickupList(req *types.GetPickupListReq, userinfo *auth.UserInfo) (resp *basic.Response) {
if userinfo.GetIdType() != auth.IDTYPE_User {
return resp.SetStatusWithMessage(basic.CodeServiceErr, "please login first")
}
if req.Page <= 0 {
req.Page = constants.DEFAULT_PAGE
}
if req.PageSize <= 0 || req.PageSize > constants.MAX_PAGE_SIZE {
req.PageSize = constants.DEFAULT_PAGE_SIZE
}
//获取列表
pickListReq := gmodel.GetPickupListByParamReq{
UserId: &userinfo.UserId,
Page: req.Page,
Limit: req.PageSize,
}
//状态筛选
if req.Status != -1 {
pickListReq.Status = &req.Status
}
pickupList, total, err := l.svcCtx.AllModels.FsCloudPickUp.GetPickupListByParam(l.ctx, pickListReq)
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get pickup list")
}
if len(pickupList) == 0 {
return resp.SetStatus(basic.CodeOK)
}
pickupIds := make([]int64, 0, len(pickupList))
for _, v := range pickupList {
pickupIds = append(pickupIds, v.Id)
}
//获取详情数据
pickupDetailList, err := l.svcCtx.AllModels.FsCloudPickUpDetail.GetAllByIds(l.ctx, pickupIds)
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get pickup detail list")
}
stockIds := make([]int64, 0, len(pickupList))
return resp.SetStatus(basic.CodeOK)
}