48 lines
1.0 KiB
Go
48 lines
1.0 KiB
Go
|
|
package stock
|
||
|
|
|
||
|
|
import (
|
||
|
|
"context"
|
||
|
|
|
||
|
|
"muyu-apiserver/gateway/internal/svc"
|
||
|
|
"muyu-apiserver/gateway/internal/types"
|
||
|
|
"muyu-apiserver/rpc/inventory/pb"
|
||
|
|
|
||
|
|
"github.com/zeromicro/go-zero/core/logx"
|
||
|
|
)
|
||
|
|
|
||
|
|
type GetStockByLocationLogic struct {
|
||
|
|
logx.Logger
|
||
|
|
ctx context.Context
|
||
|
|
svcCtx *svc.ServiceContext
|
||
|
|
}
|
||
|
|
|
||
|
|
func NewGetStockByLocationLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetStockByLocationLogic {
|
||
|
|
return &GetStockByLocationLogic{
|
||
|
|
Logger: logx.WithContext(ctx),
|
||
|
|
ctx: ctx,
|
||
|
|
svcCtx: svcCtx,
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func (l *GetStockByLocationLogic) GetStockByLocation() (resp *types.StockGroupResp, err error) {
|
||
|
|
rpcResp, err := l.svcCtx.InventoryRpc.GetStockGroup(l.ctx, &pb.StockGroupReq{
|
||
|
|
GroupBy: "location",
|
||
|
|
})
|
||
|
|
if err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
|
||
|
|
list := make([]types.StockGroupItem, 0, len(rpcResp.List))
|
||
|
|
for _, item := range rpcResp.List {
|
||
|
|
list = append(list, types.StockGroupItem{
|
||
|
|
Name: item.Name,
|
||
|
|
Count: item.Count,
|
||
|
|
Quantity: item.Quantity,
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
return &types.StockGroupResp{
|
||
|
|
List: list,
|
||
|
|
}, nil
|
||
|
|
}
|