使用枚举

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

View File

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

View File

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

View File

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

View File

@@ -1,6 +1,10 @@
package dto package dto
import "time" import (
"time"
"git.huangwc.com/pig/pig-farm-controller/internal/infra/models"
)
// ============================================================================================================= // =============================================================================================================
// 库存 (Inventory) 相关 DTO // 库存 (Inventory) 相关 DTO
@@ -37,27 +41,27 @@ type ListCurrentStockResponse struct {
// StockLogResponse 库存变动历史记录的响应体 // StockLogResponse 库存变动历史记录的响应体
type StockLogResponse struct { type StockLogResponse struct {
ID uint32 `json:"id"` ID uint32 `json:"id"`
RawMaterialID uint32 `json:"raw_material_id"` RawMaterialID uint32 `json:"raw_material_id"`
RawMaterialName string `json:"raw_material_name"` RawMaterialName string `json:"raw_material_name"`
ChangeAmount float32 `json:"change_amount"` ChangeAmount float32 `json:"change_amount"`
BeforeQuantity float32 `json:"before_quantity"` BeforeQuantity float32 `json:"before_quantity"`
AfterQuantity float32 `json:"after_quantity"` AfterQuantity float32 `json:"after_quantity"`
SourceType string `json:"source_type"` SourceType models.StockLogSourceType `json:"source_type"`
SourceID *uint32 `json:"source_id,omitempty"` SourceID *uint32 `json:"source_id,omitempty"`
HappenedAt time.Time `json:"happened_at"` HappenedAt time.Time `json:"happened_at"`
Remarks string `json:"remarks"` Remarks string `json:"remarks"`
} }
// ListStockLogRequest 定义了获取库存变动历史的请求参数 // ListStockLogRequest 定义了获取库存变动历史的请求参数
type ListStockLogRequest struct { type ListStockLogRequest struct {
Page int `json:"page" query:"page"` // 页码 Page int `json:"page" query:"page"` // 页码
PageSize int `json:"page_size" query:"page_size"` // 每页数量 PageSize int `json:"page_size" query:"page_size"` // 每页数量
RawMaterialID *uint32 `json:"raw_material_id" query:"raw_material_id"` // 按原料ID精确查询 RawMaterialID *uint32 `json:"raw_material_id" query:"raw_material_id"` // 按原料ID精确查询
SourceTypes []string `json:"source_types" query:"source_types"` // 按来源类型查询 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") 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格式) EndTime *string `json:"end_time" query:"end_time"` // 结束时间 (RFC3339格式)
OrderBy string `json:"order_by" query:"order_by"` // 排序字段 OrderBy string `json:"order_by" query:"order_by"` // 排序字段
} }
// ListStockLogResponse 是获取库存变动历史列表的响应结构 // ListStockLogResponse 是获取库存变动历史列表的响应结构