增加最后一次操作类型
This commit is contained in:
23
docs/docs.go
23
docs/docs.go
@@ -7346,6 +7346,14 @@ const docTemplate = `{
|
|||||||
"dto.CurrentStockResponse": {
|
"dto.CurrentStockResponse": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
"last_operation_source_type": {
|
||||||
|
"description": "上次库存变动的来源类型",
|
||||||
|
"allOf": [
|
||||||
|
{
|
||||||
|
"$ref": "#/definitions/models.StockLogSourceType"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
"last_updated": {
|
"last_updated": {
|
||||||
"description": "最后更新时间",
|
"description": "最后更新时间",
|
||||||
"type": "string"
|
"type": "string"
|
||||||
@@ -9211,7 +9219,8 @@ const docTemplate = `{
|
|||||||
"type": "object",
|
"type": "object",
|
||||||
"required": [
|
"required": [
|
||||||
"change_amount",
|
"change_amount",
|
||||||
"raw_material_id"
|
"raw_material_id",
|
||||||
|
"source_type"
|
||||||
],
|
],
|
||||||
"properties": {
|
"properties": {
|
||||||
"change_amount": {
|
"change_amount": {
|
||||||
@@ -9226,6 +9235,18 @@ const docTemplate = `{
|
|||||||
"description": "备注",
|
"description": "备注",
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"maxLength": 255
|
"maxLength": 255
|
||||||
|
},
|
||||||
|
"source_id": {
|
||||||
|
"description": "来源ID, 例如: 配方ID, 采购单ID等",
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"source_type": {
|
||||||
|
"description": "库存变动来源类型",
|
||||||
|
"allOf": [
|
||||||
|
{
|
||||||
|
"$ref": "#/definitions/models.StockLogSourceType"
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -7338,6 +7338,14 @@
|
|||||||
"dto.CurrentStockResponse": {
|
"dto.CurrentStockResponse": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
"last_operation_source_type": {
|
||||||
|
"description": "上次库存变动的来源类型",
|
||||||
|
"allOf": [
|
||||||
|
{
|
||||||
|
"$ref": "#/definitions/models.StockLogSourceType"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
"last_updated": {
|
"last_updated": {
|
||||||
"description": "最后更新时间",
|
"description": "最后更新时间",
|
||||||
"type": "string"
|
"type": "string"
|
||||||
@@ -9203,7 +9211,8 @@
|
|||||||
"type": "object",
|
"type": "object",
|
||||||
"required": [
|
"required": [
|
||||||
"change_amount",
|
"change_amount",
|
||||||
"raw_material_id"
|
"raw_material_id",
|
||||||
|
"source_type"
|
||||||
],
|
],
|
||||||
"properties": {
|
"properties": {
|
||||||
"change_amount": {
|
"change_amount": {
|
||||||
@@ -9218,6 +9227,18 @@
|
|||||||
"description": "备注",
|
"description": "备注",
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"maxLength": 255
|
"maxLength": 255
|
||||||
|
},
|
||||||
|
"source_id": {
|
||||||
|
"description": "来源ID, 例如: 配方ID, 采购单ID等",
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"source_type": {
|
||||||
|
"description": "库存变动来源类型",
|
||||||
|
"allOf": [
|
||||||
|
{
|
||||||
|
"$ref": "#/definitions/models.StockLogSourceType"
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -470,6 +470,10 @@ definitions:
|
|||||||
type: object
|
type: object
|
||||||
dto.CurrentStockResponse:
|
dto.CurrentStockResponse:
|
||||||
properties:
|
properties:
|
||||||
|
last_operation_source_type:
|
||||||
|
allOf:
|
||||||
|
- $ref: '#/definitions/models.StockLogSourceType'
|
||||||
|
description: 上次库存变动的来源类型
|
||||||
last_updated:
|
last_updated:
|
||||||
description: 最后更新时间
|
description: 最后更新时间
|
||||||
type: string
|
type: string
|
||||||
@@ -1723,9 +1727,17 @@ definitions:
|
|||||||
description: 备注
|
description: 备注
|
||||||
maxLength: 255
|
maxLength: 255
|
||||||
type: string
|
type: string
|
||||||
|
source_id:
|
||||||
|
description: '来源ID, 例如: 配方ID, 采购单ID等'
|
||||||
|
type: integer
|
||||||
|
source_type:
|
||||||
|
allOf:
|
||||||
|
- $ref: '#/definitions/models.StockLogSourceType'
|
||||||
|
description: 库存变动来源类型
|
||||||
required:
|
required:
|
||||||
- change_amount
|
- change_amount
|
||||||
- raw_material_id
|
- raw_material_id
|
||||||
|
- source_type
|
||||||
type: object
|
type: object
|
||||||
dto.StockLogResponse:
|
dto.StockLogResponse:
|
||||||
properties:
|
properties:
|
||||||
|
|||||||
@@ -14,10 +14,12 @@ func ConvertCurrentStockToDTO(material *models.RawMaterial, latestLog *models.Ra
|
|||||||
|
|
||||||
stock := float32(0)
|
stock := float32(0)
|
||||||
lastUpdated := material.CreatedAt.Format(time.RFC3339) // 默认使用创建时间
|
lastUpdated := material.CreatedAt.Format(time.RFC3339) // 默认使用创建时间
|
||||||
|
var lastOperationSourceType models.StockLogSourceType
|
||||||
|
|
||||||
if latestLog != nil {
|
if latestLog != nil {
|
||||||
stock = latestLog.AfterQuantity
|
stock = latestLog.AfterQuantity
|
||||||
lastUpdated = latestLog.HappenedAt.Format(time.RFC3339)
|
lastUpdated = latestLog.HappenedAt.Format(time.RFC3339)
|
||||||
|
lastOperationSourceType = latestLog.SourceType
|
||||||
}
|
}
|
||||||
|
|
||||||
return &CurrentStockResponse{
|
return &CurrentStockResponse{
|
||||||
@@ -25,6 +27,7 @@ func ConvertCurrentStockToDTO(material *models.RawMaterial, latestLog *models.Ra
|
|||||||
RawMaterialName: material.Name,
|
RawMaterialName: material.Name,
|
||||||
Stock: stock,
|
Stock: stock,
|
||||||
LastUpdated: lastUpdated,
|
LastUpdated: lastUpdated,
|
||||||
|
LastOperationSourceType: lastOperationSourceType,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ import (
|
|||||||
type StockAdjustmentRequest struct {
|
type StockAdjustmentRequest struct {
|
||||||
RawMaterialID uint32 `json:"raw_material_id" validate:"required"` // 要调整的原料ID
|
RawMaterialID uint32 `json:"raw_material_id" validate:"required"` // 要调整的原料ID
|
||||||
ChangeAmount float32 `json:"change_amount" validate:"required,ne=0"` // 变动数量, 正数为入库, 负数为出库, 单位: g
|
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"` // 备注
|
Remarks string `json:"remarks" validate:"max=255"` // 备注
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -23,6 +25,7 @@ type CurrentStockResponse struct {
|
|||||||
RawMaterialName string `json:"raw_material_name"` // 原料名称
|
RawMaterialName string `json:"raw_material_name"` // 原料名称
|
||||||
Stock float32 `json:"stock"` // 当前库存量, 单位: g
|
Stock float32 `json:"stock"` // 当前库存量, 单位: g
|
||||||
LastUpdated string `json:"last_updated"` // 最后更新时间
|
LastUpdated string `json:"last_updated"` // 最后更新时间
|
||||||
|
LastOperationSourceType models.StockLogSourceType `json:"last_operation_source_type"` // 上次库存变动的来源类型
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListCurrentStockRequest 定义了获取当前库存列表的请求参数
|
// ListCurrentStockRequest 定义了获取当前库存列表的请求参数
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ func (s *inventoryServiceImpl) AdjustStock(ctx context.Context, req *dto.StockAd
|
|||||||
serviceCtx := logs.AddFuncName(ctx, s.ctx, "AdjustStock")
|
serviceCtx := logs.AddFuncName(ctx, s.ctx, "AdjustStock")
|
||||||
|
|
||||||
// 调用领域服务执行核心业务逻辑
|
// 调用领域服务执行核心业务逻辑
|
||||||
log, err := s.invSvc.AdjustStock(serviceCtx, req.RawMaterialID, req.ChangeAmount, models.StockLogSourceManual, nil, req.Remarks)
|
log, err := s.invSvc.AdjustStock(serviceCtx, req.RawMaterialID, req.ChangeAmount, req.SourceType, req.SourceID, req.Remarks)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, inventory.ErrRawMaterialNotFound) {
|
if errors.Is(err, inventory.ErrRawMaterialNotFound) {
|
||||||
return nil, ErrInventoryRawMaterialNotFound
|
return nil, ErrInventoryRawMaterialNotFound
|
||||||
|
|||||||
Reference in New Issue
Block a user