43 lines
1.2 KiB
Go
43 lines
1.2 KiB
Go
|
|
package logic
|
||
|
|
|
||
|
|
import (
|
||
|
|
"context"
|
||
|
|
|
||
|
|
"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 ListYarnLogic struct {
|
||
|
|
ctx context.Context
|
||
|
|
svcCtx *svc.ServiceContext
|
||
|
|
logx.Logger
|
||
|
|
}
|
||
|
|
|
||
|
|
func NewListYarnLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListYarnLogic {
|
||
|
|
return &ListYarnLogic{ctx: ctx, svcCtx: svcCtx, Logger: logx.WithContext(ctx)}
|
||
|
|
}
|
||
|
|
|
||
|
|
func (l *ListYarnLogic) ListYarn(in *pb.ListYarnReq) (*pb.ListYarnResp, error) {
|
||
|
|
tenantId := tenantctx.ExtractTenantId(l.ctx)
|
||
|
|
list, total, err := l.svcCtx.YarnModel.FindList(l.ctx, tenantId, in.Page, in.PageSize, in.YarnName, in.SupplierId, in.Status)
|
||
|
|
if err != nil {
|
||
|
|
return nil, status.Error(codes.Internal, err.Error())
|
||
|
|
}
|
||
|
|
|
||
|
|
pbList := make([]*pb.YarnInfo, 0, len(list))
|
||
|
|
for _, y := range list {
|
||
|
|
supplierName := ""
|
||
|
|
if supplier, err := l.svcCtx.SupplierModel.FindOneBySupplierId(l.ctx, y.SupplierId); err == nil {
|
||
|
|
supplierName = supplier.SupplierName
|
||
|
|
}
|
||
|
|
pbList = append(pbList, yarnToPb(y, supplierName))
|
||
|
|
}
|
||
|
|
|
||
|
|
return &pb.ListYarnResp{Total: total, List: pbList}, nil
|
||
|
|
}
|