fix(order): 订单导出携带产品查询导出失败,导出链路补齐 stock_query 虚拟筛选

This commit is contained in:
liufumingren 2026-08-27 18:02:49 +08:00
parent f8915a5733
commit a2dce0d520
2 changed files with 24 additions and 1 deletions

View File

@ -619,7 +619,8 @@ class OrderExportService extends OrderBaseService {
});
const { where: sanitizedWhere, expressNumbers } = this.extractOrderListExpressVirtualFilter(where);
const { where: whereAfterBuyerMessage, buyerMessageHas } = this.extractBuyerMessageHasVirtualFilter(sanitizedWhere);
const { where: whereAfterWaveIndex, waveIndexCondition } = this.extractWaveIndexVirtualFilter(whereAfterBuyerMessage);
const { where: whereAfterStockQuery, stockQuery } = this.extractStockQueryVirtualFilter(whereAfterBuyerMessage);
const { where: whereAfterWaveIndex, waveIndexCondition } = this.extractWaveIndexVirtualFilter(whereAfterStockQuery);
const { where: whereAfterWaveScope, waveScope } = this.extractWaveScopeVirtualFilter(whereAfterWaveIndex);
const mergedWhere = this.mergeWhereObjects(
target.defaultWhereModuleName ? this.getDefaultWhere(target.defaultWhereModuleName) : {},
@ -643,6 +644,13 @@ class OrderExportService extends OrderBaseService {
queryWhere = this.appendConditionToWhere(queryWhere, buyerMessageCondition);
}
if (stockQuery) {
// 仅传 table_type 时推导出与当前表类型一致的模块名,保证 order_items 表类型正确
const stockQueryModuleName = target.defaultWhereModuleName || target.sortModuleName || 'order';
const stockOrderIds = await this.findOrderIdsByStockQuery(stockQuery, stockQueryModuleName, warehouseId);
queryWhere = this.appendOrderIdsFilterToWhere(queryWhere, stockOrderIds);
}
if (waveIndexCondition) {
const waveIndexOrderIds = await this.findOrderIdsByWaveIndexCondition(waveIndexCondition, warehouseId);
queryWhere = this.appendOrderIdsFilterToWhere(queryWhere, waveIndexOrderIds);

View File

@ -1,4 +1,19 @@
[
{
"version": "2026.08.27-order-export-stock-query",
"date": "2026-08-27",
"type": "fixed",
"summary": "order.export 修复携带产品查询(where.stock_query)时导出失败(Unknown column ... in where clause):导出链路补齐 stock_query 虚拟筛选提取,按商品编码/名称/ID/条码解析为订单ID集合后注入主查询,与 order.list 语义一致",
"methods": [
"order.export"
],
"notes": [
"app/service/systems/order_export.js exportOrders:在 extractBuyerMessageHasVirtualFilter 之后新增 extractStockQueryVirtualFilter,从 where 提取并移除 stock_query,避免其残留在 where 中经 buildWhere/parseWhereConditions 被当作数据库字段解析,导致 SQL Unknown column 报错",
"stockQuery 非空时调用 findOrderIdsByStockQuery(商品编码/名称/ID/条码模糊匹配 → stock_id 集合 → order_items 关联订单ID),再经 appendOrderIdsFilterToWhere 注入主查询;无匹配商品时导出结果为空,与 order.list 行为一致",
"stockQuery 模块名取 target.defaultWhereModuleName || target.sortModuleName || 'order',保证仅传 table_type 时按表类型推导对应模块(current/history 等)的 order_items 表类型"
],
"module": "order"
},
{
"version": "2026.08.27-storage-entry-get-total-order-lines",
"date": "2026-08-27",