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,
},
}
}