From f09e1b8f9340cc749dd9db064f6ebaec90784416 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Thu, 29 Jun 2023 13:59:55 +0800 Subject: [PATCH] fix --- constants/paging.go | 3 ++ model/gmodel/fs_cloud_pick_up_detail_logic.go | 13 ++++++- model/gmodel/fs_cloud_pick_up_logic.go | 29 ++++++++++++++ .../internal/logic/getcloudlistlogic.go | 2 +- .../internal/logic/getpickuplistlogic.go | 38 ++++++++++++++++++- server/inventory/internal/types/types.go | 2 +- server_api/inventory.api | 2 +- 7 files changed, 84 insertions(+), 5 deletions(-) diff --git a/constants/paging.go b/constants/paging.go index 001a1923..638a38de 100644 --- a/constants/paging.go +++ b/constants/paging.go @@ -5,3 +5,6 @@ const DEFAULT_PAGE = 1 // 默认每页数量 const DEFAULT_PAGE_SIZE = 20 + +// 最大每页显示数量 +const MAX_PAGE_SIZE = 300 diff --git a/model/gmodel/fs_cloud_pick_up_detail_logic.go b/model/gmodel/fs_cloud_pick_up_detail_logic.go index e68225aa..3f8ccf13 100644 --- a/model/gmodel/fs_cloud_pick_up_detail_logic.go +++ b/model/gmodel/fs_cloud_pick_up_detail_logic.go @@ -1,2 +1,13 @@ package gmodel -// TODO: 使用model的属性做你想做的 \ No newline at end of file + +import "context" + +// TODO: 使用model的属性做你想做的 + +func (p *FsCloudPickUpDetailModel) GetAllByIds(ctx context.Context, ids []int64) (resp []FsCloudPickUpDetail, err error) { + if len(ids) == 0 { + return + } + err = p.db.WithContext(ctx).Model(&FsCloudPickUpDetail{}).Where("`id` in (?)", ids).Find(&resp).Error + return resp, err +} diff --git a/model/gmodel/fs_cloud_pick_up_logic.go b/model/gmodel/fs_cloud_pick_up_logic.go index c6fd862b..e9f1d70e 100644 --- a/model/gmodel/fs_cloud_pick_up_logic.go +++ b/model/gmodel/fs_cloud_pick_up_logic.go @@ -35,3 +35,32 @@ func (p *FsCloudPickUpModel) GetCloudPickUpByIDAndUserID(ctx context.Context, us return cloudOrder, err } + +type GetPickupListByParamReq struct { + UserId *int64 + Status *int64 + Ids []int64 + Page int + Limit int +} + +func (p *FsCloudPickUpModel) GetPickupListByParam(ctx context.Context, req GetPickupListByParamReq) (resp []FsCloudPickUp, total int64, err error) { + db := p.db.WithContext(ctx).Model(&FsCloudPickUp{}) + if req.UserId != nil { + db = db.Where("`user_id` = ?", *req.UserId) + } + if req.Status != nil { + db = db.Where("`status` = ?", *req.Status) + } + if len(req.Ids) > 0 { + db = db.Where("`id` in (?)", req.Ids) + } + if err = db.Limit(1).Count(&total).Error; err != nil { + return nil, 0, err + } + offset := (req.Page - 1) * req.Limit + if err = db.Offset(offset).Limit(req.Limit).Order("id desc").Find(&resp).Error; err != nil { + return nil, 0, err + } + return +} diff --git a/server/inventory/internal/logic/getcloudlistlogic.go b/server/inventory/internal/logic/getcloudlistlogic.go index 82c06abf..450c327c 100644 --- a/server/inventory/internal/logic/getcloudlistlogic.go +++ b/server/inventory/internal/logic/getcloudlistlogic.go @@ -41,7 +41,7 @@ func (l *GetCloudListLogic) GetCloudList(req *types.GetCloudListReq, userinfo *a if req.Page <= 0 { req.Page = constants.DEFAULT_PAGE } - if req.PageSize <= 0 || req.PageSize > 200 { + if req.PageSize <= 0 || req.PageSize > constants.MAX_PAGE_SIZE { req.PageSize = constants.DEFAULT_PAGE_SIZE } sizeFlag := false diff --git a/server/inventory/internal/logic/getpickuplistlogic.go b/server/inventory/internal/logic/getpickuplistlogic.go index 28d20a81..8b4ec004 100644 --- a/server/inventory/internal/logic/getpickuplistlogic.go +++ b/server/inventory/internal/logic/getpickuplistlogic.go @@ -1,6 +1,8 @@ package logic import ( + "fusenapi/constants" + "fusenapi/model/gmodel" "fusenapi/utils/auth" "fusenapi/utils/basic" @@ -30,6 +32,40 @@ func (l *GetPickupListLogic) GetPickupList(req *types.GetPickupListReq, userinfo 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) } diff --git a/server/inventory/internal/types/types.go b/server/inventory/internal/types/types.go index 338666eb..d2178002 100644 --- a/server/inventory/internal/types/types.go +++ b/server/inventory/internal/types/types.go @@ -64,7 +64,7 @@ type SupplementRsp struct { } type GetPickupListReq struct { - Status int64 `form:"status,options=0|1|2|3|4"` + Status int64 `form:"status,options=-1|1|2|3|4"` Page int `form:"page"` PageSize int `form:"page_size"` Size int `form:"size"` diff --git a/server_api/inventory.api b/server_api/inventory.api index 38047062..3e10eb7c 100644 --- a/server_api/inventory.api +++ b/server_api/inventory.api @@ -80,7 +80,7 @@ type SupplementRsp { //提货列表 type GetPickupListReq { - Status int64 `form:"status,options=0|1|2|3|4"` + Status int64 `form:"status,options=-1|1|2|3|4"` Page int `form:"page"` PageSize int `form:"page_size"` Size int `form:"size"`