Files
pig-farm-controller/internal/app/dto/inventory_dto.go

76 lines
4.4 KiB
Go
Raw Normal View History

2025-11-25 18:10:28 +08:00
package dto
2025-11-25 20:22:38 +08:00
import (
"time"
"git.huangwc.com/pig/pig-farm-controller/internal/infra/models"
)
2025-11-25 18:10:28 +08:00
// =============================================================================================================
// 库存 (Inventory) 相关 DTO
// =============================================================================================================
// StockAdjustmentRequest 手动调整库存的请求体
type StockAdjustmentRequest struct {
2025-11-27 18:32:22 +08:00
RawMaterialID uint32 `json:"raw_material_id" validate:"required"` // 要调整的原料ID
ChangeAmount float32 `json:"change_amount" validate:"required,ne=0"` // 变动数量, 正数为入库, 负数为出库, 单位: g
SourceType models.StockLogSourceType `json:"source_type" validate:"required"` // 库存变动来源类型
SourceID *uint32 `json:"source_id,omitempty"` // 来源ID, 例如: 配方ID, 采购单ID等
Remarks string `json:"remarks" validate:"max=255"` // 备注
2025-11-25 18:10:28 +08:00
}
// CurrentStockResponse 单个原料及其当前库存的响应体
type CurrentStockResponse struct {
2025-11-27 18:32:22 +08:00
RawMaterialID uint32 `json:"raw_material_id"` // 原料ID
RawMaterialName string `json:"raw_material_name"` // 原料名称
Stock float32 `json:"stock"` // 当前库存量, 单位: g
LastUpdated string `json:"last_updated"` // 最后更新时间
LastOperationSourceType models.StockLogSourceType `json:"last_operation_source_type"` // 上次库存变动的来源类型
2025-11-25 18:10:28 +08:00
}
// ListCurrentStockRequest 定义了获取当前库存列表的请求参数
type ListCurrentStockRequest struct {
Page int `json:"page" query:"page"` // 页码
PageSize int `json:"page_size" query:"page_size"` // 每页数量
RawMaterialName *string `json:"raw_material_name" query:"raw_material_name"` // 按原料名称模糊查询
OrderBy string `json:"order_by" query:"order_by"` // 排序字段, 例如 "stock DESC"
2025-11-27 17:33:28 +08:00
HasStock *bool `json:"has_stock" query:"has_stock"` // 只查询有库存的原料
2025-11-25 18:10:28 +08:00
}
// ListCurrentStockResponse 是获取当前库存列表的响应结构
type ListCurrentStockResponse struct {
List []CurrentStockResponse `json:"list"`
Pagination PaginationDTO `json:"pagination"`
}
// StockLogResponse 库存变动历史记录的响应体
type StockLogResponse struct {
2025-11-25 20:22:38 +08:00
ID uint32 `json:"id"`
RawMaterialID uint32 `json:"raw_material_id"`
RawMaterialName string `json:"raw_material_name"`
ChangeAmount float32 `json:"change_amount"`
BeforeQuantity float32 `json:"before_quantity"`
AfterQuantity float32 `json:"after_quantity"`
SourceType models.StockLogSourceType `json:"source_type"`
SourceID *uint32 `json:"source_id,omitempty"`
HappenedAt time.Time `json:"happened_at"`
Remarks string `json:"remarks"`
2025-11-25 18:10:28 +08:00
}
// ListStockLogRequest 定义了获取库存变动历史的请求参数
type ListStockLogRequest struct {
2025-11-25 20:22:38 +08:00
Page int `json:"page" query:"page"` // 页码
PageSize int `json:"page_size" query:"page_size"` // 每页数量
RawMaterialID *uint32 `json:"raw_material_id" query:"raw_material_id"` // 按原料ID精确查询
SourceTypes []models.StockLogSourceType `json:"source_types" query:"source_types"` // 按来源类型查询
StartTime *string `json:"start_time" query:"start_time"` // 开始时间 (RFC3339格式, e.g., "2023-01-01T00:00:00Z")
EndTime *string `json:"end_time" query:"end_time"` // 结束时间 (RFC3339格式)
OrderBy string `json:"order_by" query:"order_by"` // 排序字段
2025-11-25 18:10:28 +08:00
}
// ListStockLogResponse 是获取库存变动历史列表的响应结构
type ListStockLogResponse struct {
List []StockLogResponse `json:"list"`
Pagination PaginationDTO `json:"pagination"`
}