拣货拉取明细字段补充调整
This commit is contained in:
parent
7d92522c2f
commit
897328a4f4
@ -149,6 +149,36 @@ class PickSystemService extends Service {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析订单商品快照 JSON。
|
||||
*
|
||||
* item_snapshot 是下单时从 wms_stock_warehouse 抓取的库存快照,
|
||||
* 其 item_code / item_name 代表下单时的商品信息,比 order_items 列更准确。
|
||||
*
|
||||
* @param {*} rawSnapshot 原始快照数据。
|
||||
* @return {Object} 解析后的快照对象。
|
||||
*/
|
||||
parseItemSnapshot(rawSnapshot) {
|
||||
if (!rawSnapshot) {
|
||||
return {};
|
||||
}
|
||||
|
||||
if (typeof rawSnapshot === 'string') {
|
||||
try {
|
||||
const parsed = JSON.parse(rawSnapshot);
|
||||
return parsed && typeof parsed === 'object' && !Array.isArray(parsed) ? parsed : {};
|
||||
} catch (_) {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof rawSnapshot === 'object' && !Array.isArray(rawSnapshot)) {
|
||||
return rawSnapshot;
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成拣货明细汇总信息。
|
||||
*
|
||||
@ -1143,6 +1173,29 @@ class PickSystemService extends Service {
|
||||
warehouseId,
|
||||
orderItemIds,
|
||||
});
|
||||
|
||||
// 通过 stock_warehouse 带缓存的公用链路(getStockDetails)批量查询商品资料,
|
||||
// 以 stock_id 为准获取 item_code / item_name,与 order/base.js 等链路保持一致。
|
||||
const stockIdsForDetail = [ ...new Set(
|
||||
[ ...orderItemMap.values() ]
|
||||
.map(row => Number(row && row.stock_id || 0))
|
||||
.filter(sid => Number.isInteger(sid) && sid > 0)
|
||||
) ];
|
||||
const stockDetailMap = new Map();
|
||||
if (stockIdsForDetail.length > 0) {
|
||||
try {
|
||||
const stockWarehouseSvc = ctx.service && ctx.service.systems && ctx.service.systems.stockWarehouse;
|
||||
if (stockWarehouseSvc && typeof stockWarehouseSvc.getStockDetails === 'function') {
|
||||
const stockDetails = await stockWarehouseSvc.getStockDetails(stockIdsForDetail, { warehouseId });
|
||||
for (const detail of (Array.isArray(stockDetails) ? stockDetails : [])) {
|
||||
stockDetailMap.set(Number(detail && detail.id || 0), detail);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
ctx.logger.warn(`[pick.wavePickTaskDetail] getStockDetails 查询失败,将降级使用 order_items 列值: ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
const normalizedBoxRows = Array.isArray(boxRows) ? boxRows : [];
|
||||
const boxMapByNo = new Map(normalizedBoxRows
|
||||
.map(row => [ Number(row && row.box_no || 0), row ])
|
||||
@ -1153,6 +1206,22 @@ class PickSystemService extends Service {
|
||||
const currentSpaceId = Number(row && row.space_id || 0);
|
||||
const locationRow = locationMap.get(currentSpaceId) || {};
|
||||
const orderItemRow = orderItemMap.get(orderItemId) || {};
|
||||
const stockId = Number(orderItemRow.stock_id || 0);
|
||||
const stockDetail = stockDetailMap.get(stockId) || null;
|
||||
const itemSnapshot = this.parseItemSnapshot(orderItemRow.item_snapshot);
|
||||
|
||||
// 构建 stock 字段:优先 getStockDetails 完整对象,兜底用 item_snapshot + order_items 拼装
|
||||
const stock = stockDetail
|
||||
? { ...stockDetail }
|
||||
: {
|
||||
id: stockId || null,
|
||||
item_code: String(itemSnapshot.item_code || orderItemRow.item_code || '').trim(),
|
||||
item_name: String(itemSnapshot.item_name || orderItemRow.item_name || '').trim(),
|
||||
sku_property: String(itemSnapshot.sku_property || '').trim(),
|
||||
stock_unit: String(itemSnapshot.stock_unit || '').trim(),
|
||||
barcodes: [],
|
||||
image_url: [],
|
||||
};
|
||||
|
||||
return {
|
||||
order_id: Number(row && row.order_id || 0),
|
||||
@ -1168,11 +1237,13 @@ class PickSystemService extends Service {
|
||||
pick_sequence: Number(locationRow.pick_sequence || 0),
|
||||
pick_priority: Number(locationRow.pick_priority || 0),
|
||||
},
|
||||
item_code: String(orderItemRow.item_code || '').trim(),
|
||||
item_name: String(orderItemRow.item_name || '').trim(),
|
||||
stock_id: Number(orderItemRow.stock_id || 0),
|
||||
// 优先 stock_warehouse(getStockDetails),兜底 item_snapshot,最终 order_items 列
|
||||
item_code: stock.item_code,
|
||||
item_name: stock.item_name,
|
||||
stock_id: stockId,
|
||||
plan_qty: Number(orderItemRow.plan_qty || 0),
|
||||
item_snapshot: orderItemRow.item_snapshot || null,
|
||||
stock,
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user