ListRawMaterialPurchases
This commit is contained in:
@@ -367,3 +367,71 @@ func NewListUserActionLogResponse(data []models.UserActionLog, total int64, page
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// --- RawMaterialPurchase ---
|
||||
|
||||
// ListRawMaterialPurchaseRequest 定义了获取原料采购列表的请求参数
|
||||
type ListRawMaterialPurchaseRequest struct {
|
||||
Page int `form:"page,default=1"`
|
||||
PageSize int `form:"pageSize,default=10"`
|
||||
RawMaterialID *uint `form:"raw_material_id"`
|
||||
Supplier *string `form:"supplier"`
|
||||
StartTime *time.Time `form:"start_time" time_format:"rfc3339"`
|
||||
EndTime *time.Time `form:"end_time" time_format:"rfc3339"`
|
||||
OrderBy string `form:"order_by"`
|
||||
}
|
||||
|
||||
// RawMaterialDTO 是用于API响应的简化版原料结构
|
||||
type RawMaterialDTO struct {
|
||||
ID uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
// RawMaterialPurchaseDTO 是用于API响应的原料采购结构
|
||||
type RawMaterialPurchaseDTO struct {
|
||||
ID uint `json:"id"`
|
||||
RawMaterialID uint `json:"raw_material_id"`
|
||||
RawMaterial RawMaterialDTO `json:"raw_material"`
|
||||
Supplier string `json:"supplier"`
|
||||
Amount float64 `json:"amount"`
|
||||
UnitPrice float64 `json:"unit_price"`
|
||||
TotalPrice float64 `json:"total_price"`
|
||||
PurchaseDate time.Time `json:"purchase_date"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
|
||||
// ListRawMaterialPurchaseResponse 是获取原料采购列表的响应结构
|
||||
type ListRawMaterialPurchaseResponse struct {
|
||||
List []RawMaterialPurchaseDTO `json:"list"`
|
||||
Pagination PaginationDTO `json:"pagination"`
|
||||
}
|
||||
|
||||
// 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,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user