问题:
1. 准确性 bug: 前端用 getStockList({pageSize:10, keyword}) 模糊搜索 + find()
当 SKU 前缀相同、目标不在前10条时,误报'未找到该物料库存'
2. 性能: 每次扫码全表 ilike %x% 搜索 3 张表,不走索引
修复:
- 后端 get_stock_info 改为精确匹配(==)优先,未命中再回退模糊搜索
- 新增 GET /inbound/stock/scan 扫码精确匹配接口,返回唯一命中
- 前端 onScanSuccess/handleManualInput 改用 scanStockByBarcode
一次请求直接命中,不再依赖 pageSize:10 + find()
117 lines
2.8 KiB
TypeScript
117 lines
2.8 KiB
TypeScript
import request from '@/utils/request'
|
||
|
||
// 获取全量库存
|
||
// 修改前: url: '/api/v1/inbound/stock/all'
|
||
// 修改后: url: '/v1/inbound/stock/all'
|
||
export function getAllStock() {
|
||
return request({
|
||
url: '/v1/inbound/stock/all',
|
||
method: 'get'
|
||
})
|
||
}
|
||
|
||
// 分页库存列表(服务端分页,支持关键字搜索)
|
||
export function getStockList(params: { page?: number; pageSize?: number; keyword?: string }) {
|
||
return request({
|
||
url: '/v1/inbound/stock/list',
|
||
method: 'get',
|
||
params
|
||
})
|
||
}
|
||
|
||
// 扫码精确匹配库存(盘库/出库/借库通用,替代模糊搜索漏匹配问题)
|
||
export function scanStockByBarcode(barcode: string) {
|
||
return request({
|
||
url: '/v1/inbound/stock/scan',
|
||
method: 'get',
|
||
params: { barcode }
|
||
})
|
||
}
|
||
|
||
// 打印出库选单
|
||
// 修改后: 去掉开头的 /api
|
||
export function printSelectionList(items: any[]) {
|
||
return request({
|
||
url: '/v1/inbound/stock/print/selection',
|
||
method: 'post',
|
||
data: { items }
|
||
})
|
||
}
|
||
|
||
// 打印盘点报告
|
||
// 修改后: 去掉开头的 /api
|
||
export function printStocktakeReport(data: any) {
|
||
return request({
|
||
url: '/v1/inbound/stock/print/stocktake',
|
||
method: 'post',
|
||
data
|
||
})
|
||
}
|
||
|
||
// 保存 BOM 结构
|
||
export function saveBom(data: { parent_id: number; children: any[] }) {
|
||
return request({
|
||
url: '/v1/bom',
|
||
method: 'post',
|
||
data
|
||
})
|
||
}
|
||
|
||
// 获取基础物料列表
|
||
export function getMaterialBaseList(params?: any) {
|
||
return request({
|
||
url: '/v1/bom/base/list',
|
||
method: 'get',
|
||
params
|
||
})
|
||
}
|
||
|
||
// 获取 BOM 父件列表
|
||
export function getBomParents() {
|
||
return request({
|
||
url: '/v1/bom/parents',
|
||
method: 'get'
|
||
})
|
||
}
|
||
|
||
// 获取指定BOM详情
|
||
export function getBom(parentId: number) {
|
||
return request({
|
||
url: `/v1/bom/${parentId}`,
|
||
method: 'get'
|
||
})
|
||
}
|
||
|
||
// 盘点物资合并列表(服务端 JOIN draft + stock,替代前端全量加载+find)
|
||
export function getDraftMergedList(params: {
|
||
session_id: string
|
||
keyword?: string
|
||
status_filter?: string
|
||
page?: number
|
||
pageSize?: number
|
||
}) {
|
||
return request({
|
||
url: '/v1/inbound/stock/draft/merged-list',
|
||
method: 'get',
|
||
params
|
||
})
|
||
}
|
||
|
||
// 获取应盘物资清单(盘点基数)
|
||
export function getAllStocktakeItems(params?: { keyword?: string; session_id?: string }) {
|
||
return request({
|
||
url: '/v1/inbound/stock/stocktake/all-items',
|
||
method: 'get',
|
||
params
|
||
})
|
||
}
|
||
|
||
// 更新盘点实盘数(手动修改)
|
||
export function updateStocktakeQuantity(data: { stock_id: number; source_table: string; quantity: number }) {
|
||
return request({
|
||
url: '/v1/inbound/stock/stocktake/update-quantity',
|
||
method: 'post',
|
||
data
|
||
})
|
||
}
|