105 lines
3.1 KiB
JavaScript
105 lines
3.1 KiB
JavaScript
import http from '../utils/http';
|
|
import { PaginationDTO, Response, StockLogSourceType } from '../enums';
|
|
|
|
// --- Typedefs for Inventory Management ---
|
|
|
|
/**
|
|
* @typedef {object} StockAdjustmentRequest
|
|
* @property {number} change_amount - 变动数量, 正数为入库, 负数为出库, 单位: g
|
|
* @property {number} raw_material_id - 要调整的原料ID
|
|
* @property {string} [remarks] - 备注
|
|
*/
|
|
|
|
/**
|
|
* @typedef {object} StockLogResponse
|
|
* @property {number} after_quantity
|
|
* @property {number} before_quantity
|
|
* @property {number} change_amount
|
|
* @property {string} happened_at
|
|
* @property {number} id
|
|
* @property {number} raw_material_id
|
|
* @property {string} raw_material_name
|
|
* @property {string} remarks
|
|
* @property {number} source_id
|
|
* @property {StockLogSourceType} source_type
|
|
*/
|
|
|
|
/**
|
|
* @typedef {object} ListStockLogResponse
|
|
* @property {Array<StockLogResponse>} list
|
|
* @property {PaginationDTO} pagination
|
|
*/
|
|
|
|
/**
|
|
* @typedef {object} CurrentStockResponse
|
|
* @property {string} last_updated - 最后更新时间
|
|
* @property {number} raw_material_id - 原料ID
|
|
* @property {string} raw_material_name - 原料名称
|
|
* @property {number} stock - 当前库存量, 单位: g
|
|
*/
|
|
|
|
/**
|
|
* @typedef {object} ListCurrentStockResponse
|
|
* @property {Array<CurrentStockResponse>} list
|
|
* @property {PaginationDTO} pagination
|
|
*/
|
|
|
|
/**
|
|
* @typedef {object} AdjustStockParams
|
|
* @property {StockAdjustmentRequest} request - 库存调整请求
|
|
*/
|
|
|
|
/**
|
|
* @typedef {object} GetCurrentStockListParams
|
|
* @property {string} [order_by] - 排序字段, 例如 "stock DESC"
|
|
* @property {number} [page] - 页码
|
|
* @property {number} [page_size] - 每页数量
|
|
* @property {string} [raw_material_name] - 按原料名称模糊查询
|
|
*/
|
|
|
|
/**
|
|
* @typedef {object} GetStockLogListParams
|
|
* @property {string} [end_time] - 结束时间 (RFC3339格式)
|
|
* @property {string} [order_by] - 排序字段
|
|
* @property {number} [page] - 页码
|
|
* @property {number} [page_size] - 每页数量
|
|
* @property {number} [raw_material_id] - 按原料ID精确查询
|
|
* @property {Array<StockLogSourceType>} [source_types] - 按来源类型查询
|
|
* @property {string} [start_time] - 开始时间 (RFC3339格式, e.g., "2023-01-01T00:00:00Z")
|
|
*/
|
|
|
|
// --- API Functions ---
|
|
|
|
/**
|
|
* 调整原料库存
|
|
* @param {StockAdjustmentRequest} data - 库存调整请求
|
|
* @returns {Promise<Response<StockLogResponse>>}
|
|
*/
|
|
export const adjustStock = (data) => {
|
|
return http.post('/api/v1/inventory/stock/adjust', data);
|
|
};
|
|
|
|
/**
|
|
* 获取当前库存列表
|
|
* @param {GetCurrentStockListParams} params - 查询参数
|
|
* @returns {Promise<Response<ListCurrentStockResponse>>}
|
|
*/
|
|
export const getCurrentStockList = (params) => {
|
|
return http.get('/api/v1/inventory/stock/current', { params });
|
|
};
|
|
|
|
/**
|
|
* 获取库存变动日志
|
|
* @param {GetStockLogListParams} params - 查询参数
|
|
* @returns {Promise<Response<ListStockLogResponse>>}
|
|
*/
|
|
export const getStockLogList = (params) => {
|
|
return http.get('/api/v1/inventory/stock/logs', { params });
|
|
};
|
|
|
|
export const InventoryApi = {
|
|
adjustStock,
|
|
getCurrentStockList,
|
|
getStockLogList,
|
|
};
|