fix(stockTransaction): keyword 无匹配商品时条件置空防全表查询流水,货主模式列表补充 mode=store 入参
This commit is contained in:
parent
4259628396
commit
6354a6d8dc
@ -166,6 +166,7 @@ class StockTransactionMethodService extends MainService {
|
|||||||
orderId,
|
orderId,
|
||||||
sort: sortOption,
|
sort: sortOption,
|
||||||
pagination,
|
pagination,
|
||||||
|
mode: 'store',
|
||||||
});
|
});
|
||||||
|
|
||||||
return this.success('ok', result);
|
return this.success('ok', result);
|
||||||
|
|||||||
@ -433,18 +433,27 @@ class StockTransactionService extends Service {
|
|||||||
? rawStockIds.map(item => Number(item)).filter(item => Number.isInteger(item) && item > 0)
|
? rawStockIds.map(item => Number(item)).filter(item => Number.isInteger(item) && item > 0)
|
||||||
: [];
|
: [];
|
||||||
const normalizedKeyword = String(keyword || '').trim();
|
const normalizedKeyword = String(keyword || '').trim();
|
||||||
|
let keywordResolvedEmpty = false;
|
||||||
if (normalizedKeyword && resolvedStockIds.length === 0) {
|
if (normalizedKeyword && resolvedStockIds.length === 0) {
|
||||||
const isStoreMode = mode === 'store';
|
const isStoreMode = mode === 'store';
|
||||||
const primaryDimCol = isStoreMode ? 'store_id' : 'warehouse_id';
|
const primaryDimCol = isStoreMode ? 'store_id' : 'warehouse_id';
|
||||||
const primaryDimVal = isStoreMode ? Number(storeId) : Number(warehouseId);
|
const primaryDimVal = isStoreMode ? Number(storeId) : Number(warehouseId);
|
||||||
if (primaryDimVal > 0) {
|
if (primaryDimVal > 0) {
|
||||||
resolvedStockIds = await this._resolveKeywordToStockIds(normalizedKeyword, primaryDimCol, primaryDimVal);
|
resolvedStockIds = await this._resolveKeywordToStockIds(normalizedKeyword, primaryDimCol, primaryDimVal);
|
||||||
|
if (resolvedStockIds.length === 0) {
|
||||||
|
// keyword 无匹配商品,避免退化为查询全部流水
|
||||||
|
keywordResolvedEmpty = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const whereClauses = [];
|
const whereClauses = [];
|
||||||
const replacements = {};
|
const replacements = {};
|
||||||
|
|
||||||
|
if (keywordResolvedEmpty) {
|
||||||
|
whereClauses.push('1 = 0');
|
||||||
|
}
|
||||||
|
|
||||||
// 数据范围限定:仓库侧或货主侧
|
// 数据范围限定:仓库侧或货主侧
|
||||||
if (warehouseId !== undefined && warehouseId !== null) {
|
if (warehouseId !== undefined && warehouseId !== null) {
|
||||||
whereClauses.push('t.warehouse_id = :warehouseId');
|
whereClauses.push('t.warehouse_id = :warehouseId');
|
||||||
@ -686,12 +695,17 @@ class StockTransactionService extends Service {
|
|||||||
? rawStockIds.map(item => Number(item)).filter(item => Number.isInteger(item) && item > 0)
|
? rawStockIds.map(item => Number(item)).filter(item => Number.isInteger(item) && item > 0)
|
||||||
: [];
|
: [];
|
||||||
const normalizedKeyword = String(keyword || '').trim();
|
const normalizedKeyword = String(keyword || '').trim();
|
||||||
|
let keywordResolvedEmpty = false;
|
||||||
if (normalizedKeyword && resolvedStockIds.length === 0) {
|
if (normalizedKeyword && resolvedStockIds.length === 0) {
|
||||||
const isStoreMode = mode === 'store';
|
const isStoreMode = mode === 'store';
|
||||||
const primaryDimCol = isStoreMode ? 'store_id' : 'warehouse_id';
|
const primaryDimCol = isStoreMode ? 'store_id' : 'warehouse_id';
|
||||||
const primaryDimVal = isStoreMode ? Number(storeId) : Number(warehouseId);
|
const primaryDimVal = isStoreMode ? Number(storeId) : Number(warehouseId);
|
||||||
if (primaryDimVal > 0) {
|
if (primaryDimVal > 0) {
|
||||||
resolvedStockIds = await this._resolveKeywordToStockIds(normalizedKeyword, primaryDimCol, primaryDimVal);
|
resolvedStockIds = await this._resolveKeywordToStockIds(normalizedKeyword, primaryDimCol, primaryDimVal);
|
||||||
|
if (resolvedStockIds.length === 0) {
|
||||||
|
// keyword 无匹配商品,避免退化为导出全部流水
|
||||||
|
keywordResolvedEmpty = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -699,6 +713,10 @@ class StockTransactionService extends Service {
|
|||||||
const whereClauses = [];
|
const whereClauses = [];
|
||||||
const replacements = {};
|
const replacements = {};
|
||||||
|
|
||||||
|
if (keywordResolvedEmpty) {
|
||||||
|
whereClauses.push('1 = 0');
|
||||||
|
}
|
||||||
|
|
||||||
// 数据范围限定
|
// 数据范围限定
|
||||||
if (warehouseId !== undefined && warehouseId !== null) {
|
if (warehouseId !== undefined && warehouseId !== null) {
|
||||||
whereClauses.push('t.warehouse_id = :warehouseId');
|
whereClauses.push('t.warehouse_id = :warehouseId');
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user