63 lines
1.5 KiB
Go
Raw Permalink Normal View History

package supplier
import (
"context"
"muyu-apiserver/gateway/internal/svc"
"muyu-apiserver/gateway/internal/types"
"muyu-apiserver/rpc/purchase/purchaseservice"
"github.com/zeromicro/go-zero/core/logx"
)
type ListSupplierLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewListSupplierLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListSupplierLogic {
return &ListSupplierLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *ListSupplierLogic) ListSupplier(req *types.ListSupplierReq) (*types.ListSupplierResp, error) {
rpcResp, err := l.svcCtx.PurchaseRpc.ListSupplier(l.ctx, &purchaseservice.ListSupplierReq{
Page: req.Page,
PageSize: req.PageSize,
SupplierName: req.SupplierName,
Status: req.Status,
})
if err != nil {
return nil, err
}
list := make([]types.SupplierInfo, 0, len(rpcResp.List))
for _, s := range rpcResp.List {
list = append(list, *supplierInfoFromPB(s))
}
return &types.ListSupplierResp{Total: rpcResp.Total, List: list}, nil
}
func supplierInfoFromPB(s *purchaseservice.SupplierInfo) *types.SupplierInfo {
if s == nil {
return &types.SupplierInfo{}
}
return &types.SupplierInfo{
SupplierId: s.SupplierId,
SupplierName: s.SupplierName,
Phone: s.Phone,
PurchaseCount: s.PurchaseCount,
DeliveredQty: s.DeliveredQty,
PayableAmount: s.PayableAmount,
PaidAmount: s.PaidAmount,
Status: s.Status,
Remark: s.Remark,
CreatedAt: s.CreatedAt,
UpdatedAt: s.UpdatedAt,
}
}