Pull latest changes from upstream/main (GitHub) including: - Purchase RPC service (proto, server, logic, models) - Gateway route updates for purchase endpoints - SQL migration and config updates Excludes deploy/bin/ pre-compiled arm64 binaries (builds use multi-stage Dockerfiles targeting amd64).
66 lines
2.0 KiB
Go
66 lines
2.0 KiB
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"muyu-apiserver/pkg/tenantctx"
|
|
"muyu-apiserver/rpc/purchase/internal/svc"
|
|
"muyu-apiserver/rpc/purchase/pb"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type ListPurchaseOrderLogic struct {
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
logx.Logger
|
|
}
|
|
|
|
func NewListPurchaseOrderLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListPurchaseOrderLogic {
|
|
return &ListPurchaseOrderLogic{ctx: ctx, svcCtx: svcCtx, Logger: logx.WithContext(ctx)}
|
|
}
|
|
|
|
func (l *ListPurchaseOrderLogic) ListPurchaseOrder(in *pb.ListPurchaseOrderReq) (*pb.ListPurchaseOrderResp, error) {
|
|
tenantId := tenantctx.ExtractTenantId(l.ctx)
|
|
status := in.Status
|
|
if status == 0 {
|
|
status = -1
|
|
}
|
|
list, total, err := l.svcCtx.OrderModel.FindList(l.ctx, tenantId, in.Page, in.PageSize, in.SupplierId, status, in.StartDate, in.EndDate)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
// Build supplier name cache
|
|
supplierNames := map[string]string{}
|
|
items := make([]*pb.PurchaseOrderInfo, 0, len(list))
|
|
for _, o := range list {
|
|
if _, ok := supplierNames[o.SupplierId]; !ok {
|
|
if s, err := l.svcCtx.SupplierModel.FindOneBySupplierId(l.ctx, o.SupplierId); err == nil {
|
|
supplierNames[o.SupplierId] = s.SupplierName
|
|
}
|
|
}
|
|
items = append(items, &pb.PurchaseOrderInfo{
|
|
OrderId: o.OrderId,
|
|
OrderNo: o.OrderNo,
|
|
SupplierId: o.SupplierId,
|
|
SupplierName: supplierNames[o.SupplierId],
|
|
OrderDate: o.OrderDate.Format("2006-01-02"),
|
|
ContractAmount: fmt.Sprintf("%.2f", o.ContractAmount),
|
|
ReceivedQty: fmt.Sprintf("%.2f", o.ReceivedQty),
|
|
PaidAmount: fmt.Sprintf("%.2f", o.PaidAmount),
|
|
PaymentStatus: o.PaymentStatus,
|
|
ReceiptStatus: o.ReceiptStatus,
|
|
PurchaseBy: o.PurchaseBy,
|
|
Creator: o.Creator,
|
|
Operator: o.Operator,
|
|
Status: o.Status,
|
|
Remark: o.Remark.String,
|
|
CreatedAt: o.CreatedAt.Format("2006-01-02 15:04:05"),
|
|
UpdatedAt: o.UpdatedAt.Format("2006-01-02 15:04:05"),
|
|
})
|
|
}
|
|
return &pb.ListPurchaseOrderResp{Total: total, List: items}, nil
|
|
}
|