package dto import ( "encoding/json" "time" "git.huangwc.com/pig/pig-farm-controller/internal/infra/models" ) // --- General --- // PaginationDTO 定义了分页信息的标准结构 type PaginationDTO struct { Total int64 `json:"total"` Page int `json:"page"` PageSize int `json:"pageSize"` } // --- SensorData --- // ListSensorDataRequest 定义了获取传感器数据列表的请求参数 type ListSensorDataRequest struct { Page int `form:"page,default=1"` PageSize int `form:"pageSize,default=10"` DeviceID *uint `form:"device_id"` SensorType *string `form:"sensor_type"` StartTime *time.Time `form:"start_time" time_format:"rfc3339"` EndTime *time.Time `form:"end_time" time_format:"rfc3339"` OrderBy string `form:"order_by"` } // SensorDataDTO 是用于API响应的传感器数据结构 type SensorDataDTO struct { Time time.Time `json:"time"` DeviceID uint `json:"device_id"` RegionalControllerID uint `json:"regional_controller_id"` SensorType models.SensorType `json:"sensor_type"` Data json.RawMessage `json:"data"` } // ListSensorDataResponse 是获取传感器数据列表的响应结构 type ListSensorDataResponse struct { List []SensorDataDTO `json:"list"` Pagination PaginationDTO `json:"pagination"` } // NewListSensorDataResponse 从模型数据创建列表响应 DTO func NewListSensorDataResponse(data []models.SensorData, total int64, page, pageSize int) *ListSensorDataResponse { dtos := make([]SensorDataDTO, len(data)) for i, item := range data { dtos[i] = SensorDataDTO{ Time: item.Time, DeviceID: item.DeviceID, RegionalControllerID: item.RegionalControllerID, SensorType: item.SensorType, Data: json.RawMessage(item.Data), } } return &ListSensorDataResponse{ List: dtos, Pagination: PaginationDTO{ Total: total, Page: page, PageSize: pageSize, }, } } // --- DeviceCommandLog --- // ListDeviceCommandLogRequest 定义了获取设备命令日志列表的请求参数 type ListDeviceCommandLogRequest struct { Page int `form:"page,default=1"` PageSize int `form:"pageSize,default=10"` DeviceID *uint `form:"device_id"` ReceivedSuccess *bool `form:"received_success"` StartTime *time.Time `form:"start_time" time_format:"rfc3339"` EndTime *time.Time `form:"end_time" time_format:"rfc3339"` OrderBy string `form:"order_by"` } // DeviceCommandLogDTO 是用于API响应的设备命令日志结构 type DeviceCommandLogDTO struct { MessageID string `json:"message_id"` DeviceID uint `json:"device_id"` SentAt time.Time `json:"sent_at"` AcknowledgedAt *time.Time `json:"acknowledged_at"` ReceivedSuccess bool `json:"received_success"` } // ListDeviceCommandLogResponse 是获取设备命令日志列表的响应结构 type ListDeviceCommandLogResponse struct { List []DeviceCommandLogDTO `json:"list"` Pagination PaginationDTO `json:"pagination"` } // NewListDeviceCommandLogResponse 从模型数据创建列表响应 DTO func NewListDeviceCommandLogResponse(data []models.DeviceCommandLog, total int64, page, pageSize int) *ListDeviceCommandLogResponse { dtos := make([]DeviceCommandLogDTO, len(data)) for i, item := range data { dtos[i] = DeviceCommandLogDTO{ MessageID: item.MessageID, DeviceID: item.DeviceID, SentAt: item.SentAt, AcknowledgedAt: item.AcknowledgedAt, ReceivedSuccess: item.ReceivedSuccess, } } return &ListDeviceCommandLogResponse{ List: dtos, Pagination: PaginationDTO{ Total: total, Page: page, PageSize: pageSize, }, } }