使用枚举

This commit is contained in:
2025-11-25 20:22:38 +08:00
parent 566f2d9a15
commit d7e2777c13
5 changed files with 232 additions and 28 deletions

View File

@@ -2727,6 +2727,18 @@ const docTemplate = `{
],
"summary": "获取原料列表",
"parameters": [
{
"type": "number",
"description": "参考价格最大值",
"name": "max_reference_price",
"in": "query"
},
{
"type": "number",
"description": "参考价格最小值",
"name": "min_reference_price",
"in": "query"
},
{
"type": "string",
"description": "按原料名称模糊查询",
@@ -2798,7 +2810,7 @@ const docTemplate = `{
"summary": "创建原料",
"parameters": [
{
"description": "原料信息",
"description": "原料信息,包含名称、描述和参考价格",
"name": "rawMaterial",
"in": "body",
"required": true,
@@ -2900,7 +2912,7 @@ const docTemplate = `{
"required": true
},
{
"description": "更新后的原料信息",
"description": "更新后的原料信息,包含名称、描述和参考价格",
"name": "rawMaterial",
"in": "body",
"required": true,
@@ -3430,6 +3442,16 @@ const docTemplate = `{
{
"type": "array",
"items": {
"enum": [
"采购入库",
"饲喂出库",
"变质出库",
"售卖出库",
"杂用领取",
"手动盘点",
"发酵出库",
"发酵入库"
],
"type": "string"
},
"collectionFormat": "csv",
@@ -7203,6 +7225,10 @@ const docTemplate = `{
"description": "原料名称",
"type": "string",
"maxLength": 100
},
"reference_price": {
"description": "参考价格(kg/元)",
"type": "number"
}
}
},
@@ -8744,6 +8770,10 @@ const docTemplate = `{
"items": {
"$ref": "#/definitions/dto.RawMaterialNutrientDTO"
}
},
"reference_price": {
"description": "参考价格(kg/元)",
"type": "number"
}
}
},
@@ -9153,7 +9183,7 @@ const docTemplate = `{
"type": "integer"
},
"source_type": {
"type": "string"
"$ref": "#/definitions/models.StockLogSourceType"
}
}
},
@@ -9775,6 +9805,10 @@ const docTemplate = `{
"description": "原料名称",
"type": "string",
"maxLength": 100
},
"reference_price": {
"description": "参考价格(kg/元)",
"type": "number"
}
}
},
@@ -10376,6 +10410,43 @@ const docTemplate = `{
"FatalLevel"
]
},
"models.StockLogSourceType": {
"type": "string",
"enum": [
"采购入库",
"饲喂出库",
"变质出库",
"售卖出库",
"杂用领取",
"手动盘点",
"发酵出库",
"发酵入库"
],
"x-enum-comments": {
"StockLogSourceFermentEnd": "发酵料产出,作为新原料计入库存",
"StockLogSourceFermentStart": "原料投入发酵,从库存中扣除"
},
"x-enum-descriptions": [
"",
"",
"",
"",
"",
"",
"原料投入发酵,从库存中扣除",
"发酵料产出,作为新原料计入库存"
],
"x-enum-varnames": [
"StockLogSourcePurchase",
"StockLogSourceFeeding",
"StockLogSourceDeteriorate",
"StockLogSourceSale",
"StockLogSourceMiscellaneous",
"StockLogSourceManual",
"StockLogSourceFermentStart",
"StockLogSourceFermentEnd"
]
},
"models.TaskType": {
"type": "string",
"enum": [

View File

@@ -2719,6 +2719,18 @@
],
"summary": "获取原料列表",
"parameters": [
{
"type": "number",
"description": "参考价格最大值",
"name": "max_reference_price",
"in": "query"
},
{
"type": "number",
"description": "参考价格最小值",
"name": "min_reference_price",
"in": "query"
},
{
"type": "string",
"description": "按原料名称模糊查询",
@@ -2790,7 +2802,7 @@
"summary": "创建原料",
"parameters": [
{
"description": "原料信息",
"description": "原料信息,包含名称、描述和参考价格",
"name": "rawMaterial",
"in": "body",
"required": true,
@@ -2892,7 +2904,7 @@
"required": true
},
{
"description": "更新后的原料信息",
"description": "更新后的原料信息,包含名称、描述和参考价格",
"name": "rawMaterial",
"in": "body",
"required": true,
@@ -3422,6 +3434,16 @@
{
"type": "array",
"items": {
"enum": [
"采购入库",
"饲喂出库",
"变质出库",
"售卖出库",
"杂用领取",
"手动盘点",
"发酵出库",
"发酵入库"
],
"type": "string"
},
"collectionFormat": "csv",
@@ -7195,6 +7217,10 @@
"description": "原料名称",
"type": "string",
"maxLength": 100
},
"reference_price": {
"description": "参考价格(kg/元)",
"type": "number"
}
}
},
@@ -8736,6 +8762,10 @@
"items": {
"$ref": "#/definitions/dto.RawMaterialNutrientDTO"
}
},
"reference_price": {
"description": "参考价格(kg/元)",
"type": "number"
}
}
},
@@ -9145,7 +9175,7 @@
"type": "integer"
},
"source_type": {
"type": "string"
"$ref": "#/definitions/models.StockLogSourceType"
}
}
},
@@ -9767,6 +9797,10 @@
"description": "原料名称",
"type": "string",
"maxLength": 100
},
"reference_price": {
"description": "参考价格(kg/元)",
"type": "number"
}
}
},
@@ -10368,6 +10402,43 @@
"FatalLevel"
]
},
"models.StockLogSourceType": {
"type": "string",
"enum": [
"采购入库",
"饲喂出库",
"变质出库",
"售卖出库",
"杂用领取",
"手动盘点",
"发酵出库",
"发酵入库"
],
"x-enum-comments": {
"StockLogSourceFermentEnd": "发酵料产出,作为新原料计入库存",
"StockLogSourceFermentStart": "原料投入发酵,从库存中扣除"
},
"x-enum-descriptions": [
"",
"",
"",
"",
"",
"",
"原料投入发酵,从库存中扣除",
"发酵料产出,作为新原料计入库存"
],
"x-enum-varnames": [
"StockLogSourcePurchase",
"StockLogSourceFeeding",
"StockLogSourceDeteriorate",
"StockLogSourceSale",
"StockLogSourceMiscellaneous",
"StockLogSourceManual",
"StockLogSourceFermentStart",
"StockLogSourceFermentEnd"
]
},
"models.TaskType": {
"type": "string",
"enum": [

View File

@@ -420,6 +420,9 @@ definitions:
description: 原料名称
maxLength: 100
type: string
reference_price:
description: 参考价格(kg/元)
type: number
required:
- name
type: object
@@ -1438,6 +1441,9 @@ definitions:
items:
$ref: '#/definitions/dto.RawMaterialNutrientDTO'
type: array
reference_price:
description: 参考价格(kg/元)
type: number
type: object
dto.RecipeIngredientDto:
properties:
@@ -1724,7 +1730,7 @@ definitions:
source_id:
type: integer
source_type:
type: string
$ref: '#/definitions/models.StockLogSourceType'
type: object
dto.SubPlanResponse:
properties:
@@ -2146,6 +2152,9 @@ definitions:
description: 原料名称
maxLength: 100
type: string
reference_price:
description: 参考价格(kg/元)
type: number
required:
- name
type: object
@@ -2617,6 +2626,38 @@ definitions:
- DPanicLevel
- PanicLevel
- FatalLevel
models.StockLogSourceType:
enum:
- 采购入库
- 饲喂出库
- 变质出库
- 售卖出库
- 杂用领取
- 手动盘点
- 发酵出库
- 发酵入库
type: string
x-enum-comments:
StockLogSourceFermentEnd: 发酵料产出,作为新原料计入库存
StockLogSourceFermentStart: 原料投入发酵,从库存中扣除
x-enum-descriptions:
- ""
- ""
- ""
- ""
- ""
- ""
- 原料投入发酵,从库存中扣除
- 发酵料产出,作为新原料计入库存
x-enum-varnames:
- StockLogSourcePurchase
- StockLogSourceFeeding
- StockLogSourceDeteriorate
- StockLogSourceSale
- StockLogSourceMiscellaneous
- StockLogSourceManual
- StockLogSourceFermentStart
- StockLogSourceFermentEnd
models.TaskType:
enum:
- 计划分析
@@ -4351,6 +4392,14 @@ paths:
get:
description: 获取所有原料的列表,支持分页和过滤。
parameters:
- description: 参考价格最大值
in: query
name: max_reference_price
type: number
- description: 参考价格最小值
in: query
name: min_reference_price
type: number
- description: 按原料名称模糊查询
in: query
name: name
@@ -4393,7 +4442,7 @@ paths:
- application/json
description: 创建一个新的原料。
parameters:
- description: 原料信息
- description: 原料信息,包含名称、描述和参考价格
in: body
name: rawMaterial
required: true
@@ -4472,7 +4521,7 @@ paths:
name: id
required: true
type: integer
- description: 更新后的原料信息
- description: 更新后的原料信息,包含名称、描述和参考价格
in: body
name: rawMaterial
required: true
@@ -4767,6 +4816,15 @@ paths:
description: 按来源类型查询
in: query
items:
enum:
- 采购入库
- 饲喂出库
- 变质出库
- 售卖出库
- 杂用领取
- 手动盘点
- 发酵出库
- 发酵入库
type: string
name: source_types
type: array

View File

@@ -41,7 +41,7 @@ func ConvertStockLogToDTO(log *models.RawMaterialStockLog) *StockLogResponse {
ChangeAmount: log.ChangeAmount,
BeforeQuantity: log.BeforeQuantity,
AfterQuantity: log.AfterQuantity,
SourceType: string(log.SourceType),
SourceType: log.SourceType,
SourceID: log.SourceID,
HappenedAt: log.HappenedAt,
Remarks: log.Remarks,

View File

@@ -1,6 +1,10 @@
package dto
import "time"
import (
"time"
"git.huangwc.com/pig/pig-farm-controller/internal/infra/models"
)
// =============================================================================================================
// 库存 (Inventory) 相关 DTO
@@ -37,27 +41,27 @@ type ListCurrentStockResponse struct {
// StockLogResponse 库存变动历史记录的响应体
type StockLogResponse struct {
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 string `json:"source_type"`
SourceID *uint32 `json:"source_id,omitempty"`
HappenedAt time.Time `json:"happened_at"`
Remarks string `json:"remarks"`
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"`
}
// ListStockLogRequest 定义了获取库存变动历史的请求参数
type ListStockLogRequest struct {
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 []string `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"` // 排序字段
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"` // 排序字段
}
// ListStockLogResponse 是获取库存变动历史列表的响应结构