338 lines
9.2 KiB
Go
338 lines
9.2 KiB
Go
package dto
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"git.huangwc.com/pig/pig-farm-controller/internal/infra/models"
|
|
)
|
|
|
|
// 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,
|
|
},
|
|
}
|
|
}
|
|
|
|
// 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,
|
|
},
|
|
}
|
|
}
|
|
|
|
// NewListPlanExecutionLogResponse 从模型数据创建列表响应 DTO
|
|
func NewListPlanExecutionLogResponse(data []models.PlanExecutionLog, total int64, page, pageSize int) *ListPlanExecutionLogResponse {
|
|
dtos := make([]PlanExecutionLogDTO, len(data))
|
|
for i, item := range data {
|
|
dtos[i] = PlanExecutionLogDTO{
|
|
ID: item.ID,
|
|
CreatedAt: item.CreatedAt,
|
|
UpdatedAt: item.UpdatedAt,
|
|
PlanID: item.PlanID,
|
|
Status: item.Status,
|
|
StartedAt: item.StartedAt,
|
|
EndedAt: item.EndedAt,
|
|
Error: item.Error,
|
|
}
|
|
}
|
|
|
|
return &ListPlanExecutionLogResponse{
|
|
List: dtos,
|
|
Pagination: PaginationDTO{
|
|
Total: total,
|
|
Page: page,
|
|
PageSize: pageSize,
|
|
},
|
|
}
|
|
}
|
|
|
|
// NewListTaskExecutionLogResponse 从模型数据创建列表响应 DTO
|
|
func NewListTaskExecutionLogResponse(data []models.TaskExecutionLog, total int64, page, pageSize int) *ListTaskExecutionLogResponse {
|
|
dtos := make([]TaskExecutionLogDTO, len(data))
|
|
for i, item := range data {
|
|
dtos[i] = TaskExecutionLogDTO{
|
|
ID: item.ID,
|
|
CreatedAt: item.CreatedAt,
|
|
UpdatedAt: item.UpdatedAt,
|
|
PlanExecutionLogID: item.PlanExecutionLogID,
|
|
TaskID: item.TaskID,
|
|
Task: TaskDTO{
|
|
ID: uint(item.Task.ID),
|
|
Name: item.Task.Name,
|
|
Description: item.Task.Description,
|
|
},
|
|
Status: item.Status,
|
|
Output: item.Output,
|
|
StartedAt: item.StartedAt,
|
|
EndedAt: item.EndedAt,
|
|
}
|
|
}
|
|
|
|
return &ListTaskExecutionLogResponse{
|
|
List: dtos,
|
|
Pagination: PaginationDTO{
|
|
Total: total,
|
|
Page: page,
|
|
PageSize: pageSize,
|
|
},
|
|
}
|
|
}
|
|
|
|
// NewListPendingCollectionResponse 从模型数据创建列表响应 DTO
|
|
func NewListPendingCollectionResponse(data []models.PendingCollection, total int64, page, pageSize int) *ListPendingCollectionResponse {
|
|
dtos := make([]PendingCollectionDTO, len(data))
|
|
for i, item := range data {
|
|
dtos[i] = PendingCollectionDTO{
|
|
CorrelationID: item.CorrelationID,
|
|
DeviceID: item.DeviceID,
|
|
CommandMetadata: item.CommandMetadata,
|
|
Status: item.Status,
|
|
FulfilledAt: item.FulfilledAt,
|
|
CreatedAt: item.CreatedAt,
|
|
}
|
|
}
|
|
|
|
return &ListPendingCollectionResponse{
|
|
List: dtos,
|
|
Pagination: PaginationDTO{
|
|
Total: total,
|
|
Page: page,
|
|
PageSize: pageSize,
|
|
},
|
|
}
|
|
}
|
|
|
|
// NewListUserActionLogResponse 从模型数据创建列表响应 DTO
|
|
func NewListUserActionLogResponse(data []models.UserActionLog, total int64, page, pageSize int) *ListUserActionLogResponse {
|
|
dtos := make([]UserActionLogDTO, len(data))
|
|
for i, item := range data {
|
|
dtos[i] = UserActionLogDTO{
|
|
ID: item.ID,
|
|
Time: item.Time,
|
|
UserID: item.UserID,
|
|
Username: item.Username,
|
|
SourceIP: item.SourceIP,
|
|
ActionType: item.ActionType,
|
|
TargetResource: json.RawMessage(item.TargetResource),
|
|
Description: item.Description,
|
|
Status: item.Status,
|
|
HTTPPath: item.HTTPPath,
|
|
HTTPMethod: item.HTTPMethod,
|
|
ResultDetails: item.ResultDetails,
|
|
}
|
|
}
|
|
|
|
return &ListUserActionLogResponse{
|
|
List: dtos,
|
|
Pagination: PaginationDTO{
|
|
Total: total,
|
|
Page: page,
|
|
PageSize: pageSize,
|
|
},
|
|
}
|
|
}
|
|
|
|
// NewListRawMaterialPurchaseResponse 从模型数据创建列表响应 DTO
|
|
func NewListRawMaterialPurchaseResponse(data []models.RawMaterialPurchase, total int64, page, pageSize int) *ListRawMaterialPurchaseResponse {
|
|
dtos := make([]RawMaterialPurchaseDTO, len(data))
|
|
for i, item := range data {
|
|
dtos[i] = RawMaterialPurchaseDTO{
|
|
ID: item.ID,
|
|
RawMaterialID: item.RawMaterialID,
|
|
RawMaterial: RawMaterialDTO{
|
|
ID: item.RawMaterial.ID,
|
|
Name: item.RawMaterial.Name,
|
|
},
|
|
Supplier: item.Supplier,
|
|
Amount: item.Amount,
|
|
UnitPrice: item.UnitPrice,
|
|
TotalPrice: item.TotalPrice,
|
|
PurchaseDate: item.PurchaseDate,
|
|
CreatedAt: item.CreatedAt,
|
|
}
|
|
}
|
|
|
|
return &ListRawMaterialPurchaseResponse{
|
|
List: dtos,
|
|
Pagination: PaginationDTO{
|
|
Total: total,
|
|
Page: page,
|
|
PageSize: pageSize,
|
|
},
|
|
}
|
|
}
|
|
|
|
// NewListRawMaterialStockLogResponse 从模型数据创建列表响应 DTO
|
|
func NewListRawMaterialStockLogResponse(data []models.RawMaterialStockLog, total int64, page, pageSize int) *ListRawMaterialStockLogResponse {
|
|
dtos := make([]RawMaterialStockLogDTO, len(data))
|
|
for i, item := range data {
|
|
dtos[i] = RawMaterialStockLogDTO{
|
|
ID: item.ID,
|
|
RawMaterialID: item.RawMaterialID,
|
|
ChangeAmount: item.ChangeAmount,
|
|
SourceType: item.SourceType,
|
|
SourceID: item.SourceID,
|
|
HappenedAt: item.HappenedAt,
|
|
Remarks: item.Remarks,
|
|
}
|
|
}
|
|
|
|
return &ListRawMaterialStockLogResponse{
|
|
List: dtos,
|
|
Pagination: PaginationDTO{
|
|
Total: total,
|
|
Page: page,
|
|
PageSize: pageSize,
|
|
},
|
|
}
|
|
}
|
|
|
|
// 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,
|
|
},
|
|
}
|
|
}
|
|
|
|
// 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,
|
|
},
|
|
}
|
|
}
|
|
|
|
// 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,
|
|
},
|
|
}
|
|
}
|
|
|
|
// NewListWeighingBatchResponse 从模型数据创建列表响应 DTO
|
|
func NewListWeighingBatchResponse(data []models.WeighingBatch, total int64, page, pageSize int) *ListWeighingBatchResponse {
|
|
dtos := make([]WeighingBatchDTO, len(data))
|
|
for i, item := range data {
|
|
dtos[i] = WeighingBatchDTO{
|
|
ID: item.ID,
|
|
CreatedAt: item.CreatedAt,
|
|
UpdatedAt: item.UpdatedAt,
|
|
WeighingTime: item.WeighingTime,
|
|
Description: item.Description,
|
|
PigBatchID: item.PigBatchID,
|
|
}
|
|
}
|
|
|
|
return &ListWeighingBatchResponse{
|
|
List: dtos,
|
|
Pagination: PaginationDTO{
|
|
Total: total,
|
|
Page: page,
|
|
PageSize: pageSize,
|
|
},
|
|
}
|
|
}
|