using AgriculturalPlatform.Api.Models; namespace AgriculturalPlatform.Api.Dtos; public record PurchaseWeighDto( int Id, int SortNo, string Grade, string PriceType, decimal UnitPrice, decimal GrossWeight, decimal TareWeight, decimal NetWeight, int BoxCount, decimal Amount, DateTime CreatedAt); public record PurchaseTransferDto( int Id, string TransferNo, string FromFarmer, string ToFarmer, string ToIdCard, string Reason, string? OperatorName, DateTime CreatedAt); public record PurchaseDto( int Id, string OrderNo, int FarmerId, string FarmerName, string? FarmerPhone, int ProductId, string ProductName, string Category, int PurchaserOrgId, string PurchaserOrgName, string Grade, string Unit, decimal UnitPrice, decimal GrossWeight, decimal TareWeight, decimal NetWeight, decimal Amount, int WeighCount, string Status, string? OperatorName, DateTime WeighInAt, DateTime? WeighOutAt, string Notes, DateTime CreatedAt, List Weighs, int BoxCount); /// 新建收购单(第一次过磅:称毛重) public record PurchaseCreateRequest( int FarmerId, int ProductId, int PurchaserOrgId, string Grade, decimal GrossWeight, string Unit = "公斤", decimal UnitPrice = 0, string Notes = ""); /// 多磅收购单保存请求(一单多磅、多等级) public record PurchaseMultiCreateRequest( int FarmerId, int ProductId, int PurchaserOrgId, string Unit, string? Notes, List Weighs); public record PurchaseWeighSaveRequest( string Grade, string PriceType, decimal UnitPrice, decimal GrossWeight, decimal TareWeight, int BoxCount, decimal? NetWeight); /// 回皮完成(第二次过磅:称皮重,计算净重与金额) public record PurchaseTareRequest(decimal TareWeight); /// 票据过户请求 public record PurchaseTransferRequest(string ToFarmer, string ToIdCard, string Reason); /// 收购单统计(多维汇总) public record PurchaseSummaryDto( int OrderCount, decimal TotalNetWeight, decimal AvgPrice, decimal TotalAmount, int FarmerCount, int TodayOrderCount); public static class PurchaseMappers { public static PurchaseWeighDto ToDto(this PurchaseWeigh w) => new( w.Id, w.SortNo, w.Grade, w.PriceType, w.UnitPrice, w.GrossWeight, w.TareWeight, w.NetWeight, w.BoxCount, w.Amount, w.CreatedAt); public static PurchaseDto ToDto(this PurchaseOrder p) => new( p.Id, p.OrderNo, p.FarmerId, p.Farmer?.Name ?? "", p.Farmer?.Phone ?? "", p.ProductId, p.Product?.Name ?? "", p.Product?.Category ?? "", p.PurchaserOrgId, p.PurchaserOrg?.Name ?? "", p.Grade, p.Unit, p.UnitPrice, p.GrossWeight, p.TareWeight, p.NetWeight, p.Amount, p.WeighCount, p.Status.ToString(), p.Operator?.RealName ?? "", p.WeighInAt, p.WeighOutAt, p.Notes, p.CreatedAt, p.Weighs?.OrderBy(w => w.SortNo).Select(w => w.ToDto()).ToList() ?? new List(), p.BoxCount); public static PurchaseDto[] ToDtos(this IEnumerable items) => items.Select(ToDto).ToArray(); }