ListPigBatchLogs

This commit is contained in:
2025-10-19 12:41:13 +08:00
parent e150969ee3
commit 89fbbbb75f
4 changed files with 181 additions and 4 deletions

View File

@@ -191,7 +191,7 @@ type ListTaskExecutionLogRequest struct {
// TaskDTO 是用于API响应的简化版任务结构
type TaskDTO struct {
ID int `json:"id"`
ID uint `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
}
@@ -227,7 +227,7 @@ func NewListTaskExecutionLogResponse(data []models.TaskExecutionLog, total int64
PlanExecutionLogID: item.PlanExecutionLogID,
TaskID: item.TaskID,
Task: TaskDTO{
ID: item.Task.ID,
ID: uint(item.Task.ID),
Name: item.Task.Name,
Description: item.Task.Description,
},
@@ -641,3 +641,67 @@ func NewListMedicationLogResponse(data []models.MedicationLog, total int64, page
},
}
}
// --- PigBatchLog ---
// ListPigBatchLogRequest 定义了获取猪批次日志列表的请求参数
type ListPigBatchLogRequest struct {
Page int `form:"page,default=1"`
PageSize int `form:"pageSize,default=10"`
PigBatchID *uint `form:"pig_batch_id"`
ChangeType *string `form:"change_type"`
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"`
}
// PigBatchLogDTO 是用于API响应的猪批次日志结构
type PigBatchLogDTO struct {
ID uint `json:"id"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
PigBatchID uint `json:"pig_batch_id"`
ChangeType models.LogChangeType `json:"change_type"`
ChangeCount int `json:"change_count"`
Reason string `json:"reason"`
BeforeCount int `json:"before_count"`
AfterCount int `json:"after_count"`
OperatorID uint `json:"operator_id"`
HappenedAt time.Time `json:"happened_at"`
}
// ListPigBatchLogResponse 是获取猪批次日志列表的响应结构
type ListPigBatchLogResponse struct {
List []PigBatchLogDTO `json:"list"`
Pagination PaginationDTO `json:"pagination"`
}
// NewListPigBatchLogResponse 从模型数据创建列表响应 DTO
func NewListPigBatchLogResponse(data []models.PigBatchLog, total int64, page, pageSize int) *ListPigBatchLogResponse {
dtos := make([]PigBatchLogDTO, len(data))
for i, item := range data {
dtos[i] = PigBatchLogDTO{
ID: item.ID,
CreatedAt: item.CreatedAt,
UpdatedAt: item.UpdatedAt,
PigBatchID: item.PigBatchID,
ChangeType: item.ChangeType,
ChangeCount: item.ChangeCount,
Reason: item.Reason,
BeforeCount: item.BeforeCount,
AfterCount: item.AfterCount,
OperatorID: item.OperatorID,
HappenedAt: item.HappenedAt,
}
}
return &ListPigBatchLogResponse{
List: dtos,
Pagination: PaginationDTO{
Total: total,
Page: page,
PageSize: pageSize,
},
}
}