54 lines
1.4 KiB
Go
54 lines
1.4 KiB
Go
|
|
package logic
|
||
|
|
|
||
|
|
import (
|
||
|
|
"context"
|
||
|
|
"fmt"
|
||
|
|
|
||
|
|
"muyu-apiserver/pkg/tenantctx"
|
||
|
|
"muyu-apiserver/rpc/inventory/internal/svc"
|
||
|
|
"muyu-apiserver/rpc/inventory/pb"
|
||
|
|
|
||
|
|
"github.com/zeromicro/go-zero/core/logx"
|
||
|
|
"google.golang.org/grpc/codes"
|
||
|
|
"google.golang.org/grpc/status"
|
||
|
|
)
|
||
|
|
|
||
|
|
type ListBoltViewLogic struct {
|
||
|
|
ctx context.Context
|
||
|
|
svcCtx *svc.ServiceContext
|
||
|
|
logx.Logger
|
||
|
|
}
|
||
|
|
|
||
|
|
func NewListBoltViewLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListBoltViewLogic {
|
||
|
|
return &ListBoltViewLogic{
|
||
|
|
ctx: ctx,
|
||
|
|
svcCtx: svcCtx,
|
||
|
|
Logger: logx.WithContext(ctx),
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func (l *ListBoltViewLogic) ListBoltView(in *pb.ListBoltViewReq) (*pb.ListBoltViewResp, error) {
|
||
|
|
tenantId := tenantctx.ExtractTenantId(l.ctx)
|
||
|
|
list, total, err := l.svcCtx.BoltModel.FindBoltList(l.ctx, tenantId, in.Page, in.PageSize, in.ProductName, in.Position)
|
||
|
|
if err != nil {
|
||
|
|
return nil, status.Error(codes.Internal, err.Error())
|
||
|
|
}
|
||
|
|
|
||
|
|
pbList := make([]*pb.BoltListItem, 0, len(list))
|
||
|
|
for _, item := range list {
|
||
|
|
pbList = append(pbList, &pb.BoltListItem{
|
||
|
|
BoltId: item.BoltId,
|
||
|
|
PanId: item.PanId,
|
||
|
|
LengthM: fmt.Sprintf("%.2f", item.LengthM),
|
||
|
|
Color: item.Color,
|
||
|
|
SortOrder: item.SortOrder,
|
||
|
|
PanName: item.PanName,
|
||
|
|
Position: item.Position,
|
||
|
|
ProductId: item.ProductId,
|
||
|
|
ProductName: item.ProductName,
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
return &pb.ListBoltViewResp{Total: total, List: pbList}, nil
|
||
|
|
}
|