65 lines
3.1 KiB
C#
65 lines
3.1 KiB
C#
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<PurchaseWeighDto> Weighs, int BoxCount);
|
|
|
|
/// <summary>新建收购单(第一次过磅:称毛重)</summary>
|
|
public record PurchaseCreateRequest(
|
|
int FarmerId, int ProductId, int PurchaserOrgId, string Grade,
|
|
decimal GrossWeight, string Unit = "公斤", decimal UnitPrice = 0, string Notes = "");
|
|
|
|
/// <summary>多磅收购单保存请求(一单多磅、多等级)</summary>
|
|
public record PurchaseMultiCreateRequest(
|
|
int FarmerId, int ProductId, int PurchaserOrgId, string Unit,
|
|
string? Notes, List<PurchaseWeighSaveRequest> Weighs);
|
|
|
|
public record PurchaseWeighSaveRequest(
|
|
string Grade, string PriceType, decimal UnitPrice, decimal GrossWeight,
|
|
decimal TareWeight, int BoxCount, decimal? NetWeight);
|
|
|
|
/// <summary>回皮完成(第二次过磅:称皮重,计算净重与金额)</summary>
|
|
public record PurchaseTareRequest(decimal TareWeight);
|
|
|
|
/// <summary>票据过户请求</summary>
|
|
public record PurchaseTransferRequest(string ToFarmer, string ToIdCard, string Reason);
|
|
|
|
/// <summary>收购单统计(多维汇总)</summary>
|
|
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<PurchaseWeighDto>(),
|
|
p.BoxCount);
|
|
|
|
public static PurchaseDto[] ToDtos(this IEnumerable<PurchaseOrder> items) => items.Select(ToDto).ToArray();
|
|
}
|