ListPigPurchases

This commit is contained in:
2025-10-19 14:54:13 +08:00
parent 197af0181c
commit 0038f20334
5 changed files with 177 additions and 0 deletions

View File

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

View File

@@ -536,3 +536,38 @@ type ListPigSickLogResponse struct {
List []PigSickLogDTO `json:"list"`
Pagination PaginationDTO `json:"pagination"`
}
// --- PigPurchase ---
// ListPigPurchaseRequest 定义了获取猪只采购记录列表的请求参数
type ListPigPurchaseRequest struct {
Page int `form:"page,default=1"`
PageSize int `form:"pageSize,default=10"`
PigBatchID *uint `form:"pig_batch_id"`
Supplier *string `form:"supplier"`
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"`
}
// PigPurchaseDTO 是用于API响应的猪只采购记录结构
type PigPurchaseDTO struct {
ID uint `json:"id"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
PigBatchID uint `json:"pig_batch_id"`
PurchaseDate time.Time `json:"purchase_date"`
Supplier string `json:"supplier"`
Quantity int `json:"quantity"`
UnitPrice float64 `json:"unit_price"`
TotalPrice float64 `json:"total_price"`
Remarks string `json:"remarks"`
OperatorID uint `json:"operator_id"`
}
// ListPigPurchaseResponse 是获取猪只采购记录列表的响应结构
type ListPigPurchaseResponse struct {
List []PigPurchaseDTO `json:"list"`
Pagination PaginationDTO `json:"pagination"`
}