实现库存管理相关逻辑

This commit is contained in:
2025-11-25 18:10:28 +08:00
parent ae27eb142d
commit 44ff3b19d6
15 changed files with 1531 additions and 22 deletions

View File

@@ -3267,6 +3267,205 @@ const docTemplate = `{
}
}
},
"/api/v1/inventory/stock/adjust": {
"post": {
"security": [
{
"BearerAuth": []
}
],
"description": "手动调整指定原料的库存量。",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"库存管理"
],
"summary": "调整原料库存",
"parameters": [
{
"description": "库存调整请求",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/dto.StockAdjustmentRequest"
}
}
],
"responses": {
"200": {
"description": "业务码为200代表调整成功",
"schema": {
"allOf": [
{
"$ref": "#/definitions/controller.Response"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/dto.StockLogResponse"
}
}
}
]
}
}
}
}
},
"/api/v1/inventory/stock/current": {
"get": {
"security": [
{
"BearerAuth": []
}
],
"description": "获取所有原料的当前库存列表,支持分页和过滤。",
"produces": [
"application/json"
],
"tags": [
"库存管理"
],
"summary": "获取当前库存列表",
"parameters": [
{
"type": "string",
"description": "排序字段, 例如 \"stock DESC\"",
"name": "order_by",
"in": "query"
},
{
"type": "integer",
"description": "页码",
"name": "page",
"in": "query"
},
{
"type": "integer",
"description": "每页数量",
"name": "page_size",
"in": "query"
},
{
"type": "string",
"description": "按原料名称模糊查询",
"name": "raw_material_name",
"in": "query"
}
],
"responses": {
"200": {
"description": "业务码为200代表成功获取列表",
"schema": {
"allOf": [
{
"$ref": "#/definitions/controller.Response"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/dto.ListCurrentStockResponse"
}
}
}
]
}
}
}
}
},
"/api/v1/inventory/stock/logs": {
"get": {
"security": [
{
"BearerAuth": []
}
],
"description": "获取原料库存变动历史记录,支持分页、过滤和时间范围查询。",
"produces": [
"application/json"
],
"tags": [
"库存管理"
],
"summary": "获取库存变动日志",
"parameters": [
{
"type": "string",
"description": "结束时间 (RFC3339格式)",
"name": "end_time",
"in": "query"
},
{
"type": "string",
"description": "排序字段",
"name": "order_by",
"in": "query"
},
{
"type": "integer",
"description": "页码",
"name": "page",
"in": "query"
},
{
"type": "integer",
"description": "每页数量",
"name": "page_size",
"in": "query"
},
{
"type": "integer",
"description": "按原料ID精确查询",
"name": "raw_material_id",
"in": "query"
},
{
"type": "array",
"items": {
"type": "string"
},
"collectionFormat": "csv",
"description": "按来源类型查询",
"name": "source_types",
"in": "query"
},
{
"type": "string",
"description": "开始时间 (RFC3339格式, e.g., \"2023-01-01T00:00:00Z\")",
"name": "start_time",
"in": "query"
}
],
"responses": {
"200": {
"description": "业务码为200代表成功获取列表",
"schema": {
"allOf": [
{
"$ref": "#/definitions/controller.Response"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/dto.ListStockLogResponse"
}
}
}
]
}
}
}
}
},
"/api/v1/monitor/device-command-logs": {
"get": {
"security": [
@@ -3448,6 +3647,7 @@ const docTemplate = `{
},
{
"enum": [
7,
-1,
0,
1,
@@ -3457,12 +3657,12 @@ const docTemplate = `{
5,
-1,
5,
6,
7
6
],
"type": "integer",
"format": "int32",
"x-enum-varnames": [
"_numLevels",
"DebugLevel",
"InfoLevel",
"WarnLevel",
@@ -3472,8 +3672,7 @@ const docTemplate = `{
"FatalLevel",
"_minLevel",
"_maxLevel",
"InvalidLevel",
"_numLevels"
"InvalidLevel"
],
"name": "level",
"in": "query"
@@ -7062,6 +7261,27 @@ const docTemplate = `{
}
}
},
"dto.CurrentStockResponse": {
"type": "object",
"properties": {
"last_updated": {
"description": "最后更新时间",
"type": "string"
},
"raw_material_id": {
"description": "原料ID",
"type": "integer"
},
"raw_material_name": {
"description": "原料名称",
"type": "string"
},
"stock": {
"description": "当前库存量, 单位: g",
"type": "number"
}
}
},
"dto.DeleteDeviceThresholdAlarmDTO": {
"type": "object",
"required": [
@@ -7259,6 +7479,20 @@ const docTemplate = `{
}
}
},
"dto.ListCurrentStockResponse": {
"type": "object",
"properties": {
"list": {
"type": "array",
"items": {
"$ref": "#/definitions/dto.CurrentStockResponse"
}
},
"pagination": {
"$ref": "#/definitions/dto.PaginationDTO"
}
}
},
"dto.ListDeviceCommandLogResponse": {
"type": "object",
"properties": {
@@ -7540,6 +7774,20 @@ const docTemplate = `{
}
}
},
"dto.ListStockLogResponse": {
"type": "object",
"properties": {
"list": {
"type": "array",
"items": {
"$ref": "#/definitions/dto.StockLogResponse"
}
},
"pagination": {
"$ref": "#/definitions/dto.PaginationDTO"
}
}
},
"dto.ListTaskExecutionLogResponse": {
"type": "object",
"properties": {
@@ -8852,6 +9100,63 @@ const docTemplate = `{
}
}
},
"dto.StockAdjustmentRequest": {
"type": "object",
"required": [
"change_amount",
"raw_material_id"
],
"properties": {
"change_amount": {
"description": "变动数量, 正数为入库, 负数为出库, 单位: g",
"type": "number"
},
"raw_material_id": {
"description": "要调整的原料ID",
"type": "integer"
},
"remarks": {
"description": "备注",
"type": "string",
"maxLength": 255
}
}
},
"dto.StockLogResponse": {
"type": "object",
"properties": {
"after_quantity": {
"type": "number"
},
"before_quantity": {
"type": "number"
},
"change_amount": {
"type": "number"
},
"happened_at": {
"type": "string"
},
"id": {
"type": "integer"
},
"raw_material_id": {
"type": "integer"
},
"raw_material_name": {
"type": "string"
},
"remarks": {
"type": "string"
},
"source_id": {
"type": "integer"
},
"source_type": {
"type": "string"
}
}
},
"dto.SubPlanResponse": {
"type": "object",
"properties": {
@@ -10147,6 +10452,7 @@ const docTemplate = `{
"type": "integer",
"format": "int32",
"enum": [
7,
-1,
0,
1,
@@ -10156,10 +10462,10 @@ const docTemplate = `{
5,
-1,
5,
6,
7
6
],
"x-enum-varnames": [
"_numLevels",
"DebugLevel",
"InfoLevel",
"WarnLevel",
@@ -10169,8 +10475,7 @@ const docTemplate = `{
"FatalLevel",
"_minLevel",
"_maxLevel",
"InvalidLevel",
"_numLevels"
"InvalidLevel"
]
}
},

View File

@@ -3259,6 +3259,205 @@
}
}
},
"/api/v1/inventory/stock/adjust": {
"post": {
"security": [
{
"BearerAuth": []
}
],
"description": "手动调整指定原料的库存量。",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"库存管理"
],
"summary": "调整原料库存",
"parameters": [
{
"description": "库存调整请求",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/dto.StockAdjustmentRequest"
}
}
],
"responses": {
"200": {
"description": "业务码为200代表调整成功",
"schema": {
"allOf": [
{
"$ref": "#/definitions/controller.Response"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/dto.StockLogResponse"
}
}
}
]
}
}
}
}
},
"/api/v1/inventory/stock/current": {
"get": {
"security": [
{
"BearerAuth": []
}
],
"description": "获取所有原料的当前库存列表,支持分页和过滤。",
"produces": [
"application/json"
],
"tags": [
"库存管理"
],
"summary": "获取当前库存列表",
"parameters": [
{
"type": "string",
"description": "排序字段, 例如 \"stock DESC\"",
"name": "order_by",
"in": "query"
},
{
"type": "integer",
"description": "页码",
"name": "page",
"in": "query"
},
{
"type": "integer",
"description": "每页数量",
"name": "page_size",
"in": "query"
},
{
"type": "string",
"description": "按原料名称模糊查询",
"name": "raw_material_name",
"in": "query"
}
],
"responses": {
"200": {
"description": "业务码为200代表成功获取列表",
"schema": {
"allOf": [
{
"$ref": "#/definitions/controller.Response"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/dto.ListCurrentStockResponse"
}
}
}
]
}
}
}
}
},
"/api/v1/inventory/stock/logs": {
"get": {
"security": [
{
"BearerAuth": []
}
],
"description": "获取原料库存变动历史记录,支持分页、过滤和时间范围查询。",
"produces": [
"application/json"
],
"tags": [
"库存管理"
],
"summary": "获取库存变动日志",
"parameters": [
{
"type": "string",
"description": "结束时间 (RFC3339格式)",
"name": "end_time",
"in": "query"
},
{
"type": "string",
"description": "排序字段",
"name": "order_by",
"in": "query"
},
{
"type": "integer",
"description": "页码",
"name": "page",
"in": "query"
},
{
"type": "integer",
"description": "每页数量",
"name": "page_size",
"in": "query"
},
{
"type": "integer",
"description": "按原料ID精确查询",
"name": "raw_material_id",
"in": "query"
},
{
"type": "array",
"items": {
"type": "string"
},
"collectionFormat": "csv",
"description": "按来源类型查询",
"name": "source_types",
"in": "query"
},
{
"type": "string",
"description": "开始时间 (RFC3339格式, e.g., \"2023-01-01T00:00:00Z\")",
"name": "start_time",
"in": "query"
}
],
"responses": {
"200": {
"description": "业务码为200代表成功获取列表",
"schema": {
"allOf": [
{
"$ref": "#/definitions/controller.Response"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/dto.ListStockLogResponse"
}
}
}
]
}
}
}
}
},
"/api/v1/monitor/device-command-logs": {
"get": {
"security": [
@@ -3440,6 +3639,7 @@
},
{
"enum": [
7,
-1,
0,
1,
@@ -3449,12 +3649,12 @@
5,
-1,
5,
6,
7
6
],
"type": "integer",
"format": "int32",
"x-enum-varnames": [
"_numLevels",
"DebugLevel",
"InfoLevel",
"WarnLevel",
@@ -3464,8 +3664,7 @@
"FatalLevel",
"_minLevel",
"_maxLevel",
"InvalidLevel",
"_numLevels"
"InvalidLevel"
],
"name": "level",
"in": "query"
@@ -7054,6 +7253,27 @@
}
}
},
"dto.CurrentStockResponse": {
"type": "object",
"properties": {
"last_updated": {
"description": "最后更新时间",
"type": "string"
},
"raw_material_id": {
"description": "原料ID",
"type": "integer"
},
"raw_material_name": {
"description": "原料名称",
"type": "string"
},
"stock": {
"description": "当前库存量, 单位: g",
"type": "number"
}
}
},
"dto.DeleteDeviceThresholdAlarmDTO": {
"type": "object",
"required": [
@@ -7251,6 +7471,20 @@
}
}
},
"dto.ListCurrentStockResponse": {
"type": "object",
"properties": {
"list": {
"type": "array",
"items": {
"$ref": "#/definitions/dto.CurrentStockResponse"
}
},
"pagination": {
"$ref": "#/definitions/dto.PaginationDTO"
}
}
},
"dto.ListDeviceCommandLogResponse": {
"type": "object",
"properties": {
@@ -7532,6 +7766,20 @@
}
}
},
"dto.ListStockLogResponse": {
"type": "object",
"properties": {
"list": {
"type": "array",
"items": {
"$ref": "#/definitions/dto.StockLogResponse"
}
},
"pagination": {
"$ref": "#/definitions/dto.PaginationDTO"
}
}
},
"dto.ListTaskExecutionLogResponse": {
"type": "object",
"properties": {
@@ -8844,6 +9092,63 @@
}
}
},
"dto.StockAdjustmentRequest": {
"type": "object",
"required": [
"change_amount",
"raw_material_id"
],
"properties": {
"change_amount": {
"description": "变动数量, 正数为入库, 负数为出库, 单位: g",
"type": "number"
},
"raw_material_id": {
"description": "要调整的原料ID",
"type": "integer"
},
"remarks": {
"description": "备注",
"type": "string",
"maxLength": 255
}
}
},
"dto.StockLogResponse": {
"type": "object",
"properties": {
"after_quantity": {
"type": "number"
},
"before_quantity": {
"type": "number"
},
"change_amount": {
"type": "number"
},
"happened_at": {
"type": "string"
},
"id": {
"type": "integer"
},
"raw_material_id": {
"type": "integer"
},
"raw_material_name": {
"type": "string"
},
"remarks": {
"type": "string"
},
"source_id": {
"type": "integer"
},
"source_type": {
"type": "string"
}
}
},
"dto.SubPlanResponse": {
"type": "object",
"properties": {
@@ -10139,6 +10444,7 @@
"type": "integer",
"format": "int32",
"enum": [
7,
-1,
0,
1,
@@ -10148,10 +10454,10 @@
5,
-1,
5,
6,
7
6
],
"x-enum-varnames": [
"_numLevels",
"DebugLevel",
"InfoLevel",
"WarnLevel",
@@ -10161,8 +10467,7 @@
"FatalLevel",
"_minLevel",
"_maxLevel",
"InvalidLevel",
"_numLevels"
"InvalidLevel"
]
}
},

View File

@@ -462,6 +462,21 @@ definitions:
example: newuser
type: string
type: object
dto.CurrentStockResponse:
properties:
last_updated:
description: 最后更新时间
type: string
raw_material_id:
description: 原料ID
type: integer
raw_material_name:
description: 原料名称
type: string
stock:
description: '当前库存量, 单位: g'
type: number
type: object
dto.DeleteDeviceThresholdAlarmDTO:
properties:
sensor_type:
@@ -590,6 +605,15 @@ definitions:
pagination:
$ref: '#/definitions/dto.PaginationDTO'
type: object
dto.ListCurrentStockResponse:
properties:
list:
items:
$ref: '#/definitions/dto.CurrentStockResponse'
type: array
pagination:
$ref: '#/definitions/dto.PaginationDTO'
type: object
dto.ListDeviceCommandLogResponse:
properties:
list:
@@ -771,6 +795,15 @@ definitions:
pagination:
$ref: '#/definitions/dto.PaginationDTO'
type: object
dto.ListStockLogResponse:
properties:
list:
items:
$ref: '#/definitions/dto.StockLogResponse'
type: array
pagination:
$ref: '#/definitions/dto.PaginationDTO'
type: object
dto.ListTaskExecutionLogResponse:
properties:
list:
@@ -1654,6 +1687,45 @@ definitions:
required:
- duration_minutes
type: object
dto.StockAdjustmentRequest:
properties:
change_amount:
description: '变动数量, 正数为入库, 负数为出库, 单位: g'
type: number
raw_material_id:
description: 要调整的原料ID
type: integer
remarks:
description: 备注
maxLength: 255
type: string
required:
- change_amount
- raw_material_id
type: object
dto.StockLogResponse:
properties:
after_quantity:
type: number
before_quantity:
type: number
change_amount:
type: number
happened_at:
type: string
id:
type: integer
raw_material_id:
type: integer
raw_material_name:
type: string
remarks:
type: string
source_id:
type: integer
source_type:
type: string
type: object
dto.SubPlanResponse:
properties:
child_plan:
@@ -2606,6 +2678,7 @@ definitions:
- PlanTypeFilterSystem
zapcore.Level:
enum:
- 7
- -1
- 0
- 1
@@ -2616,10 +2689,10 @@ definitions:
- -1
- 5
- 6
- 7
format: int32
type: integer
x-enum-varnames:
- _numLevels
- DebugLevel
- InfoLevel
- WarnLevel
@@ -2630,7 +2703,6 @@ definitions:
- _minLevel
- _maxLevel
- InvalidLevel
- _numLevels
info:
contact:
email: divano@example.com
@@ -4601,6 +4673,124 @@ paths:
summary: 更新配方
tags:
- 饲料管理-配方
/api/v1/inventory/stock/adjust:
post:
consumes:
- application/json
description: 手动调整指定原料的库存量。
parameters:
- description: 库存调整请求
in: body
name: request
required: true
schema:
$ref: '#/definitions/dto.StockAdjustmentRequest'
produces:
- application/json
responses:
"200":
description: 业务码为200代表调整成功
schema:
allOf:
- $ref: '#/definitions/controller.Response'
- properties:
data:
$ref: '#/definitions/dto.StockLogResponse'
type: object
security:
- BearerAuth: []
summary: 调整原料库存
tags:
- 库存管理
/api/v1/inventory/stock/current:
get:
description: 获取所有原料的当前库存列表,支持分页和过滤。
parameters:
- description: 排序字段, 例如 "stock DESC"
in: query
name: order_by
type: string
- description: 页码
in: query
name: page
type: integer
- description: 每页数量
in: query
name: page_size
type: integer
- description: 按原料名称模糊查询
in: query
name: raw_material_name
type: string
produces:
- application/json
responses:
"200":
description: 业务码为200代表成功获取列表
schema:
allOf:
- $ref: '#/definitions/controller.Response'
- properties:
data:
$ref: '#/definitions/dto.ListCurrentStockResponse'
type: object
security:
- BearerAuth: []
summary: 获取当前库存列表
tags:
- 库存管理
/api/v1/inventory/stock/logs:
get:
description: 获取原料库存变动历史记录,支持分页、过滤和时间范围查询。
parameters:
- description: 结束时间 (RFC3339格式)
in: query
name: end_time
type: string
- description: 排序字段
in: query
name: order_by
type: string
- description: 页码
in: query
name: page
type: integer
- description: 每页数量
in: query
name: page_size
type: integer
- description: 按原料ID精确查询
in: query
name: raw_material_id
type: integer
- collectionFormat: csv
description: 按来源类型查询
in: query
items:
type: string
name: source_types
type: array
- description: 开始时间 (RFC3339格式, e.g., "2023-01-01T00:00:00Z")
in: query
name: start_time
type: string
produces:
- application/json
responses:
"200":
description: 业务码为200代表成功获取列表
schema:
allOf:
- $ref: '#/definitions/controller.Response'
- properties:
data:
$ref: '#/definitions/dto.ListStockLogResponse'
type: object
security:
- BearerAuth: []
summary: 获取库存变动日志
tags:
- 库存管理
/api/v1/monitor/device-command-logs:
get:
description: 根据提供的过滤条件,分页获取设备命令日志
@@ -4699,6 +4889,7 @@ paths:
name: end_time
type: string
- enum:
- 7
- -1
- 0
- 1
@@ -4709,12 +4900,12 @@ paths:
- -1
- 5
- 6
- 7
format: int32
in: query
name: level
type: integer
x-enum-varnames:
- _numLevels
- DebugLevel
- InfoLevel
- WarnLevel
@@ -4725,7 +4916,6 @@ paths:
- _minLevel
- _maxLevel
- InvalidLevel
- _numLevels
- enum:
- 邮件
- 企业微信