ListMedicationLogs
This commit is contained in:
@@ -191,7 +191,7 @@ type ListTaskExecutionLogRequest struct {
|
||||
|
||||
// TaskDTO 是用于API响应的简化版任务结构
|
||||
type TaskDTO struct {
|
||||
ID uint `json:"id"`
|
||||
ID int `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: uint(item.Task.ID),
|
||||
ID: item.Task.ID,
|
||||
Name: item.Task.Name,
|
||||
Description: item.Task.Description,
|
||||
},
|
||||
@@ -569,3 +569,75 @@ func NewListFeedUsageRecordResponse(data []models.FeedUsageRecord, total int64,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// --- MedicationLog ---
|
||||
|
||||
// ListMedicationLogRequest 定义了获取用药记录列表的请求参数
|
||||
type ListMedicationLogRequest struct {
|
||||
Page int `form:"page,default=1"`
|
||||
PageSize int `form:"pageSize,default=10"`
|
||||
PigBatchID *uint `form:"pig_batch_id"`
|
||||
MedicationID *uint `form:"medication_id"`
|
||||
Reason *string `form:"reason"`
|
||||
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"`
|
||||
}
|
||||
|
||||
// MedicationDTO 是用于API响应的简化版药品结构
|
||||
type MedicationDTO struct {
|
||||
ID uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
// MedicationLogDTO 是用于API响应的用药记录结构
|
||||
type MedicationLogDTO struct {
|
||||
ID uint `json:"id"`
|
||||
PigBatchID uint `json:"pig_batch_id"`
|
||||
MedicationID uint `json:"medication_id"`
|
||||
Medication MedicationDTO `json:"medication"`
|
||||
DosageUsed float64 `json:"dosage_used"`
|
||||
TargetCount int `json:"target_count"`
|
||||
Reason models.MedicationReasonType `json:"reason"`
|
||||
Description string `json:"description"`
|
||||
OperatorID uint `json:"operator_id"`
|
||||
HappenedAt time.Time `json:"happened_at"`
|
||||
}
|
||||
|
||||
// ListMedicationLogResponse 是获取用药记录列表的响应结构
|
||||
type ListMedicationLogResponse struct {
|
||||
List []MedicationLogDTO `json:"list"`
|
||||
Pagination PaginationDTO `json:"pagination"`
|
||||
}
|
||||
|
||||
// NewListMedicationLogResponse 从模型数据创建列表响应 DTO
|
||||
func NewListMedicationLogResponse(data []models.MedicationLog, total int64, page, pageSize int) *ListMedicationLogResponse {
|
||||
dtos := make([]MedicationLogDTO, len(data))
|
||||
for i, item := range data {
|
||||
dtos[i] = MedicationLogDTO{
|
||||
ID: item.ID,
|
||||
PigBatchID: item.PigBatchID,
|
||||
MedicationID: item.MedicationID,
|
||||
Medication: MedicationDTO{
|
||||
ID: item.Medication.ID,
|
||||
Name: item.Medication.Name,
|
||||
},
|
||||
DosageUsed: item.DosageUsed,
|
||||
TargetCount: item.TargetCount,
|
||||
Reason: item.Reason,
|
||||
Description: item.Description,
|
||||
OperatorID: item.OperatorID,
|
||||
HappenedAt: item.HappenedAt,
|
||||
}
|
||||
}
|
||||
|
||||
return &ListMedicationLogResponse{
|
||||
List: dtos,
|
||||
Pagination: PaginationDTO{
|
||||
Total: total,
|
||||
Page: page,
|
||||
PageSize: pageSize,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user