ListFeedUsageRecords
This commit is contained in:
@@ -491,3 +491,81 @@ func NewListRawMaterialStockLogResponse(data []models.RawMaterialStockLog, total
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// --- FeedUsageRecord ---
|
||||
|
||||
// ListFeedUsageRecordRequest 定义了获取饲料使用记录列表的请求参数
|
||||
type ListFeedUsageRecordRequest struct {
|
||||
Page int `form:"page,default=1"`
|
||||
PageSize int `form:"pageSize,default=10"`
|
||||
PenID *uint `form:"pen_id"`
|
||||
FeedFormulaID *uint `form:"feed_formula_id"`
|
||||
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"`
|
||||
}
|
||||
|
||||
// PenDTO 是用于API响应的简化版猪栏结构
|
||||
type PenDTO struct {
|
||||
ID uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
// FeedFormulaDTO 是用于API响应的简化版饲料配方结构
|
||||
type FeedFormulaDTO struct {
|
||||
ID uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
// FeedUsageRecordDTO 是用于API响应的饲料使用记录结构
|
||||
type FeedUsageRecordDTO struct {
|
||||
ID uint `json:"id"`
|
||||
PenID uint `json:"pen_id"`
|
||||
Pen PenDTO `json:"pen"`
|
||||
FeedFormulaID uint `json:"feed_formula_id"`
|
||||
FeedFormula FeedFormulaDTO `json:"feed_formula"`
|
||||
Amount float64 `json:"amount"`
|
||||
RecordedAt time.Time `json:"recorded_at"`
|
||||
OperatorID uint `json:"operator_id"`
|
||||
Remarks string `json:"remarks"`
|
||||
}
|
||||
|
||||
// ListFeedUsageRecordResponse 是获取饲料使用记录列表的响应结构
|
||||
type ListFeedUsageRecordResponse struct {
|
||||
List []FeedUsageRecordDTO `json:"list"`
|
||||
Pagination PaginationDTO `json:"pagination"`
|
||||
}
|
||||
|
||||
// NewListFeedUsageRecordResponse 从模型数据创建列表响应 DTO
|
||||
func NewListFeedUsageRecordResponse(data []models.FeedUsageRecord, total int64, page, pageSize int) *ListFeedUsageRecordResponse {
|
||||
dtos := make([]FeedUsageRecordDTO, len(data))
|
||||
for i, item := range data {
|
||||
dtos[i] = FeedUsageRecordDTO{
|
||||
ID: item.ID,
|
||||
PenID: item.PenID,
|
||||
Pen: PenDTO{
|
||||
ID: item.Pen.ID,
|
||||
Name: item.Pen.PenNumber,
|
||||
},
|
||||
FeedFormulaID: item.FeedFormulaID,
|
||||
FeedFormula: FeedFormulaDTO{
|
||||
ID: item.FeedFormula.ID,
|
||||
Name: item.FeedFormula.Name,
|
||||
},
|
||||
Amount: item.Amount,
|
||||
RecordedAt: item.RecordedAt,
|
||||
OperatorID: item.OperatorID,
|
||||
Remarks: item.Remarks,
|
||||
}
|
||||
}
|
||||
|
||||
return &ListFeedUsageRecordResponse{
|
||||
List: dtos,
|
||||
Pagination: PaginationDTO{
|
||||
Total: total,
|
||||
Page: page,
|
||||
PageSize: pageSize,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user