fix
This commit is contained in:
123
server/inventory/internal/logic/getcloudlistlogic.go
Normal file
123
server/inventory/internal/logic/getcloudlistlogic.go
Normal file
@@ -0,0 +1,123 @@
|
||||
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 GetCloudListLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewGetCloudListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetCloudListLogic {
|
||||
return &GetCloudListLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetCloudListLogic) GetCloudList(req *types.GetCloudListReq, 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 > 200 {
|
||||
req.Page = constants.DEFAULT_PAGE_SIZE
|
||||
}
|
||||
//获取个人云仓列表
|
||||
stockList, total, err := l.svcCtx.AllModels.FsUserStock.GetStockList(l.ctx, gmodel.GetStockListReq{
|
||||
UserId: userinfo.UserId,
|
||||
Page: int(req.Page),
|
||||
Limit: int(req.PageSize),
|
||||
})
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get user stock list")
|
||||
}
|
||||
if len(stockList) == 0 {
|
||||
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetCloudListRsp{
|
||||
ListData: []types.ListDataItem{},
|
||||
})
|
||||
}
|
||||
designIds := make([]int64, 0, len(stockList))
|
||||
for _, v := range stockList {
|
||||
designIds = append(designIds, *v.DesignId)
|
||||
}
|
||||
//获取设计数据
|
||||
productDesignList, err := l.svcCtx.AllModels.FsProductDesign.GetAllByIds(l.ctx, designIds)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product design list")
|
||||
}
|
||||
//尺寸ids
|
||||
sizeIds := make([]int64, 0, len(productDesignList))
|
||||
//产品ids
|
||||
productIds := make([]int64, 0, len(productDesignList))
|
||||
//模板ids
|
||||
templateIds := make([]int64, 0, len(productDesignList))
|
||||
//配件ids
|
||||
optionalIds := make([]int64, 0, len(productDesignList))
|
||||
mapProductDesign := make(map[int64]int)
|
||||
for k, v := range productDesignList {
|
||||
sizeIds = append(sizeIds, *v.SizeId)
|
||||
productIds = append(productIds, *v.ProductId)
|
||||
templateIds = append(templateIds, *v.TemplateId)
|
||||
optionalIds = append(optionalIds, *v.OptionalId)
|
||||
mapProductDesign[v.Id] = k
|
||||
}
|
||||
//获取尺寸信息
|
||||
sizeList, err := l.svcCtx.AllModels.FsProductSize.GetAllByProductIdsWithoutStatus(l.ctx, sizeIds, "")
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product size list")
|
||||
}
|
||||
mapSize := make(map[int64]int)
|
||||
for k, v := range sizeList {
|
||||
mapSize[v.Id] = k
|
||||
}
|
||||
//获取产品信息
|
||||
productList, err := l.svcCtx.AllModels.FsProduct.GetProductListByIdsWithoutStatus(l.ctx, productIds, "")
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product list")
|
||||
}
|
||||
mapProduct := make(map[int64]int)
|
||||
for k, v := range productList {
|
||||
mapProduct[v.Id] = k
|
||||
}
|
||||
//获取模板信息
|
||||
productTemplateList, err := l.svcCtx.AllModels.FsProductTemplateV2.FindAllByIdsWithoutStatus(l.ctx, templateIds)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product template list")
|
||||
}
|
||||
mapTemplate := make(map[int64]int)
|
||||
for k, v := range productTemplateList {
|
||||
mapTemplate[v.Id] = k
|
||||
}
|
||||
//获取配件列表
|
||||
productModel3dList, err := l.svcCtx.AllModels.FsProductModel3d.GetAllByIdsWithoutStatus(l.ctx, optionalIds)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product 3d model list")
|
||||
}
|
||||
mapProductModel := make(map[int64]int)
|
||||
for k, v := range productModel3dList {
|
||||
mapProductModel[v.Id] = k
|
||||
}
|
||||
return resp.SetStatus(basic.CodeOK)
|
||||
}
|
||||
Reference in New Issue
Block a user