ListPigSickLogs

This commit is contained in:
2025-10-19 14:34:22 +08:00
parent 1830fcd43e
commit 197af0181c
5 changed files with 197 additions and 0 deletions

View File

@@ -392,3 +392,34 @@ func NewListPigTransferLogResponse(data []models.PigTransferLog, total int64, pa
},
}
}
// NewListPigSickLogResponse 从模型数据创建列表响应 DTO
func NewListPigSickLogResponse(data []models.PigSickLog, total int64, page, pageSize int) *ListPigSickLogResponse {
dtos := make([]PigSickLogDTO, len(data))
for i, item := range data {
dtos[i] = PigSickLogDTO{
ID: item.ID,
CreatedAt: item.CreatedAt,
UpdatedAt: item.UpdatedAt,
PigBatchID: item.PigBatchID,
PenID: item.PenID,
ChangeCount: item.ChangeCount,
Reason: item.Reason,
BeforeCount: item.BeforeCount,
AfterCount: item.AfterCount,
Remarks: item.Remarks,
TreatmentLocation: item.TreatmentLocation,
OperatorID: item.OperatorID,
HappenedAt: item.HappenedAt,
}
}
return &ListPigSickLogResponse{
List: dtos,
Pagination: PaginationDTO{
Total: total,
Page: page,
PageSize: pageSize,
},
}
}

View File

@@ -497,3 +497,42 @@ type ListPigTransferLogResponse struct {
List []PigTransferLogDTO `json:"list"`
Pagination PaginationDTO `json:"pagination"`
}
// --- PigSickLog ---
// ListPigSickLogRequest 定义了获取病猪日志列表的请求参数
type ListPigSickLogRequest struct {
Page int `form:"page,default=1"`
PageSize int `form:"pageSize,default=10"`
PigBatchID *uint `form:"pig_batch_id"`
PenID *uint `form:"pen_id"`
Reason *string `form:"reason"`
TreatmentLocation *string `form:"treatment_location"`
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"`
}
// PigSickLogDTO 是用于API响应的病猪日志结构
type PigSickLogDTO struct {
ID uint `json:"id"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
PigBatchID uint `json:"pig_batch_id"`
PenID uint `json:"pen_id"`
ChangeCount int `json:"change_count"`
Reason models.PigBatchSickPigReasonType `json:"reason"`
BeforeCount int `json:"before_count"`
AfterCount int `json:"after_count"`
Remarks string `json:"remarks"`
TreatmentLocation models.PigBatchSickPigTreatmentLocation `json:"treatment_location"`
OperatorID uint `json:"operator_id"`
HappenedAt time.Time `json:"happened_at"`
}
// ListPigSickLogResponse 是获取病猪日志列表的响应结构
type ListPigSickLogResponse struct {
List []PigSickLogDTO `json:"list"`
Pagination PaginationDTO `json:"pagination"`
}