ListPigSales

This commit is contained in:
2025-10-19 15:53:19 +08:00
parent 0038f20334
commit 4cbb4bb859
5 changed files with 171 additions and 1 deletions

View File

@@ -2,7 +2,6 @@ package dto
import (
"encoding/json"
"time"
"git.huangwc.com/pig/pig-farm-controller/internal/infra/models"
)
@@ -453,3 +452,32 @@ func NewListPigPurchaseResponse(data []models.PigPurchase, total int64, page, pa
},
}
}
// NewListPigSaleResponse 从模型数据创建列表响应 DTO
func NewListPigSaleResponse(data []models.PigSale, total int64, page, pageSize int) *ListPigSaleResponse {
dtos := make([]PigSaleDTO, len(data))
for i, item := range data {
dtos[i] = PigSaleDTO{
ID: item.ID,
CreatedAt: item.CreatedAt,
UpdatedAt: item.UpdatedAt,
PigBatchID: item.PigBatchID,
SaleDate: item.SaleDate,
Buyer: item.Buyer,
Quantity: item.Quantity,
UnitPrice: item.UnitPrice,
TotalPrice: item.TotalPrice,
Remarks: item.Remarks,
OperatorID: item.OperatorID,
}
}
return &ListPigSaleResponse{
List: dtos,
Pagination: PaginationDTO{
Total: total,
Page: page,
PageSize: pageSize,
},
}
}

View File

@@ -571,3 +571,38 @@ type ListPigPurchaseResponse struct {
List []PigPurchaseDTO `json:"list"`
Pagination PaginationDTO `json:"pagination"`
}
// --- PigSale ---
// ListPigSaleRequest 定义了获取猪只销售记录列表的请求参数
type ListPigSaleRequest struct {
Page int `form:"page,default=1"`
PageSize int `form:"pageSize,default=10"`
PigBatchID *uint `form:"pig_batch_id"`
Buyer *string `form:"buyer"`
OperatorID *uint `form:"operator_id"`
StartTime *time.Time `form:"start_time" time_format:"rfc3339"`
EndTime *time.Time `form:"end_time" time_format:"rfc3339"`
OrderBy string `form:"order_by"`
}
// PigSaleDTO 是用于API响应的猪只销售记录结构
type PigSaleDTO struct {
ID uint `json:"id"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
PigBatchID uint `json:"pig_batch_id"`
SaleDate time.Time `json:"sale_date"`
Buyer string `json:"buyer"`
Quantity int `json:"quantity"`
UnitPrice float64 `json:"unit_price"`
TotalPrice float64 `json:"total_price"`
Remarks string `json:"remarks"`
OperatorID uint `json:"operator_id"`
}
// ListPigSaleResponse 是获取猪只销售记录列表的响应结构
type ListPigSaleResponse struct {
List []PigSaleDTO `json:"list"`
Pagination PaginationDTO `json:"pagination"`
}