增加最后一次操作类型
This commit is contained in:
@@ -14,17 +14,20 @@ func ConvertCurrentStockToDTO(material *models.RawMaterial, latestLog *models.Ra
|
||||
|
||||
stock := float32(0)
|
||||
lastUpdated := material.CreatedAt.Format(time.RFC3339) // 默认使用创建时间
|
||||
var lastOperationSourceType models.StockLogSourceType
|
||||
|
||||
if latestLog != nil {
|
||||
stock = latestLog.AfterQuantity
|
||||
lastUpdated = latestLog.HappenedAt.Format(time.RFC3339)
|
||||
lastOperationSourceType = latestLog.SourceType
|
||||
}
|
||||
|
||||
return &CurrentStockResponse{
|
||||
RawMaterialID: material.ID,
|
||||
RawMaterialName: material.Name,
|
||||
Stock: stock,
|
||||
LastUpdated: lastUpdated,
|
||||
RawMaterialID: material.ID,
|
||||
RawMaterialName: material.Name,
|
||||
Stock: stock,
|
||||
LastUpdated: lastUpdated,
|
||||
LastOperationSourceType: lastOperationSourceType,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,17 +12,20 @@ import (
|
||||
|
||||
// StockAdjustmentRequest 手动调整库存的请求体
|
||||
type StockAdjustmentRequest struct {
|
||||
RawMaterialID uint32 `json:"raw_material_id" validate:"required"` // 要调整的原料ID
|
||||
ChangeAmount float32 `json:"change_amount" validate:"required,ne=0"` // 变动数量, 正数为入库, 负数为出库, 单位: g
|
||||
Remarks string `json:"remarks" validate:"max=255"` // 备注
|
||||
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"` // 备注
|
||||
}
|
||||
|
||||
// CurrentStockResponse 单个原料及其当前库存的响应体
|
||||
type CurrentStockResponse struct {
|
||||
RawMaterialID uint32 `json:"raw_material_id"` // 原料ID
|
||||
RawMaterialName string `json:"raw_material_name"` // 原料名称
|
||||
Stock float32 `json:"stock"` // 当前库存量, 单位: g
|
||||
LastUpdated string `json:"last_updated"` // 最后更新时间
|
||||
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"` // 上次库存变动的来源类型
|
||||
}
|
||||
|
||||
// ListCurrentStockRequest 定义了获取当前库存列表的请求参数
|
||||
|
||||
@@ -47,7 +47,7 @@ func (s *inventoryServiceImpl) AdjustStock(ctx context.Context, req *dto.StockAd
|
||||
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 errors.Is(err, inventory.ErrRawMaterialNotFound) {
|
||||
return nil, ErrInventoryRawMaterialNotFound
|
||||
|
||||
Reference in New Issue
Block a user