feat(order): 波次/拣货/复核透传货主信息 + 取消订单过滤
- wave: 透传 store_id/owner_code/store_remark - recheckOrder: 波次视图新增 store_id/store_remark,批量查询货主备注 - pick: 分组聚合透传 store_id/owner_code/store_remark/stock - order_storage_allocation: 储位分配注入 stock_id + 回传排除取消订单 - order_async: 标记异常排除取消状态订单
This commit is contained in:
parent
888d026145
commit
b2ae5683e1
@ -46,7 +46,7 @@ module.exports = {
|
||||
|
||||
for (const warehouseId of warehouseIds) {
|
||||
try {
|
||||
const submitPayload = await ctx.service.systemMethods.order.wave.submitWaveStrategyQuickScanForWarehouse(warehouseId, { wait: true });
|
||||
const submitPayload = await ctx.service.systemMethods.order.wave.submitWaveStrategyQuickScanForWarehouse(warehouseId, { wait: true, forceRescan: true });
|
||||
const submitMessage = String(submitPayload && submitPayload.message || '').trim();
|
||||
const submitState = String(submitPayload && submitPayload.state || '').trim();
|
||||
const isReusedRunningTask = submitMessage.includes('已有快速扫描任务在运行中')
|
||||
|
||||
@ -751,6 +751,9 @@ class RecheckOrderService extends OrderBaseService {
|
||||
images: Array.isArray(item.images) ? [ ...item.images ] : [],
|
||||
has_shared_barcode: Boolean(item.has_shared_barcode),
|
||||
plan_qty: Number(item.plan_qty || 0),
|
||||
store_id: item.store_id != null ? Number(item.store_id) : 0,
|
||||
owner_code: String(item.owner_code || '').trim(),
|
||||
store_remark: String(item.store_remark || '').trim(),
|
||||
}));
|
||||
|
||||
// 构建拦截订单列表
|
||||
@ -761,9 +764,6 @@ class RecheckOrderService extends OrderBaseService {
|
||||
intercept_status: String(order.intercept_status || '').trim(),
|
||||
}));
|
||||
|
||||
// 提取正常(非拦截)订单的 ID 列表
|
||||
const orderIds = normalOrders.map(order => Number(order.order_id || 0)).filter(id => id > 0);
|
||||
|
||||
// 计算波次内复核统计(基于非拦截订单的 recheck_status 实时聚合)
|
||||
const reviewedCount = normalOrders.filter(o => String(o.recheck_status || '').trim() === 'fin').length;
|
||||
const unreviewedCount = normalOrders.length - reviewedCount;
|
||||
@ -786,8 +786,9 @@ class RecheckOrderService extends OrderBaseService {
|
||||
update_time: waveView.update_time,
|
||||
order_count: waveView.order_count,
|
||||
box_no: Number(tw.box_no || 0),
|
||||
order_ids: orderIds,
|
||||
stocks,
|
||||
store_id: sampleOrder ? Number(sampleOrder.store_id || 0) : 0,
|
||||
store_remark: sampleOrder ? String(sampleOrder.store_remark || '').trim() : '',
|
||||
reviewed_count: reviewedCount,
|
||||
unreviewed_count: unreviewedCount,
|
||||
printed_count: printedCount,
|
||||
@ -1118,6 +1119,7 @@ class RecheckOrderService extends OrderBaseService {
|
||||
order_type: String(row.order_type || '').trim(),
|
||||
status: Number(row.status || 0),
|
||||
logistics_name: String(row.logistics_name || '').trim(),
|
||||
store_id: Number(row.store_id || 0),
|
||||
store_remark: storeRemarkMap.has(Number(row.store_id || 0))
|
||||
? storeRemarkMap.get(Number(row.store_id || 0))
|
||||
: '',
|
||||
@ -1257,7 +1259,7 @@ class RecheckOrderService extends OrderBaseService {
|
||||
where: {
|
||||
order_id: { [this.app.Sequelize.Op.in]: orderIds },
|
||||
},
|
||||
attributes: [ 'order_id', 'stock_id', 'item_code', 'item_name', 'plan_qty', 'item_snapshot' ],
|
||||
attributes: [ 'order_id', 'stock_id', 'item_code', 'item_name', 'plan_qty', 'item_snapshot', 'owner_code' ],
|
||||
order: [[ 'id', 'ASC' ]],
|
||||
raw: true,
|
||||
});
|
||||
@ -1297,6 +1299,32 @@ class RecheckOrderService extends OrderBaseService {
|
||||
}
|
||||
}
|
||||
|
||||
// 4. 批量查询货主备注名(wms_store_warehouse.store_remask),按 store_id 映射
|
||||
const storeRemarkMapByStock = new Map();
|
||||
if (stockMap.size > 0 && this.ctx.model && this.ctx.model.StoreWarehouse) {
|
||||
const storeIdsForRemark = [ ...new Set(
|
||||
[ ...stockMap.values() ]
|
||||
.map(detail => Number(detail.store_id || 0))
|
||||
.filter(id => id > 0)
|
||||
) ];
|
||||
if (storeIdsForRemark.length > 0) {
|
||||
const swRows = await this.ctx.model.StoreWarehouse.findAll({
|
||||
where: {
|
||||
store_id: { [this.app.Sequelize.Op.in]: storeIdsForRemark },
|
||||
warehouse_id: warehouseId,
|
||||
},
|
||||
attributes: [ 'store_id', 'store_remask' ],
|
||||
raw: true,
|
||||
});
|
||||
for (const sw of (Array.isArray(swRows) ? swRows : [])) {
|
||||
const sid = Number(sw.store_id || 0);
|
||||
if (sid > 0 && !storeRemarkMapByStock.has(sid)) {
|
||||
storeRemarkMapByStock.set(sid, String(sw.store_remask || '').trim());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 5. 检测共享条码:查询当前所有条码是否也出现在其他 stock_id 中
|
||||
const sharedBarcodeSet = new Set();
|
||||
if (barcodeMap.size > 0) {
|
||||
@ -1369,6 +1397,9 @@ class RecheckOrderService extends OrderBaseService {
|
||||
images,
|
||||
has_shared_barcode: hasSharedBarcode,
|
||||
plan_qty: Number(item.plan_qty || 0),
|
||||
store_id: stockInfo.store_id != null ? Number(stockInfo.store_id) : 0,
|
||||
owner_code: String(item.owner_code || '').trim(),
|
||||
store_remark: storeRemarkMapByStock.get(stockInfo.store_id != null ? Number(stockInfo.store_id) : 0) || '',
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
@ -21,7 +21,7 @@ const BATCH_ALLOCATE_EXPRESS_TASK_CACHE_TTL_SECONDS = 60 * 60 * 24;
|
||||
const BATCH_ALLOCATE_STORAGE_TASK_CACHE_KEY_PREFIX = 'wave:batch-allocate-storage:';
|
||||
const BATCH_ALLOCATE_STORAGE_TASK_CACHE_TTL_SECONDS = 60 * 60 * 24;
|
||||
const WAVE_STRATEGY_QUICK_SCAN_TASK_CACHE_KEY_PREFIX = 'wave:quick-scan:task:';
|
||||
const WAVE_STRATEGY_QUICK_SCAN_TASK_CACHE_TTL_SECONDS = 60 * 60 * 24;
|
||||
const WAVE_STRATEGY_QUICK_SCAN_TASK_CACHE_TTL_SECONDS = 60 * 5;
|
||||
const WAVE_STRATEGY_QUICK_SCAN_WAREHOUSE_LOCK_CACHE_KEY_PREFIX = 'wave:quick-scan:lock:';
|
||||
const WAVE_STRATEGY_QUICK_SCAN_WAREHOUSE_LOCK_TTL_SECONDS = 60 * 60 * 2;
|
||||
const WAVE_STRATEGY_LIST_CACHE_KEY_PREFIX = 'wave:strategy-list:';
|
||||
@ -5244,6 +5244,7 @@ class WaveService extends OrderBaseService {
|
||||
const normalizedOptions = this.isPlainObject(options) ? options : {};
|
||||
const orderIds = this.normalizeIdsInput(normalizedOptions.orderIds);
|
||||
const wait = this.normalizeBoolean(normalizedOptions.wait, false);
|
||||
const forceRescan = this.normalizeBoolean(normalizedOptions.forceRescan, false);
|
||||
|
||||
const runningTask = await this.getWaveStrategyQuickScanWarehouseLock(normalizedWarehouseId);
|
||||
if (runningTask && runningTask.task_id) {
|
||||
@ -5282,6 +5283,7 @@ class WaveService extends OrderBaseService {
|
||||
error: '',
|
||||
error_code: '',
|
||||
result: null,
|
||||
...(forceRescan ? { force_rescan: true } : {}),
|
||||
});
|
||||
|
||||
await this.setWaveStrategyQuickScanWarehouseLock(normalizedWarehouseId, taskId, {
|
||||
@ -5294,6 +5296,7 @@ class WaveService extends OrderBaseService {
|
||||
taskId,
|
||||
warehouseId: normalizedWarehouseId,
|
||||
...(orderIds.length > 0 ? { orderIds } : {}),
|
||||
...(forceRescan ? { forceRescan } : {}),
|
||||
});
|
||||
|
||||
const finalProgress = await this.getWaveStrategyQuickScanTaskProgress(taskId) || {};
|
||||
@ -5310,6 +5313,7 @@ class WaveService extends OrderBaseService {
|
||||
taskId,
|
||||
warehouseId: normalizedWarehouseId,
|
||||
...(orderIds.length > 0 ? { orderIds } : {}),
|
||||
...(forceRescan ? { forceRescan } : {}),
|
||||
}).catch(error => {
|
||||
this.ctx.logger.error('[wave.waveStrategyQuickScan] 后台任务异常', {
|
||||
taskId,
|
||||
@ -5396,9 +5400,10 @@ class WaveService extends OrderBaseService {
|
||||
* @param {number} warehouseId 仓库ID。
|
||||
* @param {number} strategyVersion 当前策略版本号。
|
||||
* @param {Array<number|string>} [orderIds=[]] 限定扫描订单ID数组。
|
||||
* @param {boolean} [forceRescan=false] 是否强制全量重扫(忽略版本号条件)。
|
||||
* @return {Object} 订单查询 where 条件。
|
||||
*/
|
||||
buildWaveStrategyQuickScanOrderWhere(warehouseId, strategyVersion, orderIds = []) {
|
||||
buildWaveStrategyQuickScanOrderWhere(warehouseId, strategyVersion, orderIds = [], forceRescan = false) {
|
||||
const normalizedOrderIds = this.normalizeIdsInput(orderIds);
|
||||
const where = {
|
||||
warehouse_id: warehouseId,
|
||||
@ -5407,11 +5412,14 @@ class WaveService extends OrderBaseService {
|
||||
intercept_status: 'none',
|
||||
lock_status: 'none',
|
||||
print_status: { [Op.ne]: 'fin' },
|
||||
[Op.or]: [
|
||||
};
|
||||
|
||||
if (!forceRescan) {
|
||||
where[Op.or] = [
|
||||
{ wave_strategy_version: { [Op.ne]: strategyVersion } },
|
||||
{ wave_strategy_version: { [Op.is]: null } },
|
||||
],
|
||||
};
|
||||
];
|
||||
}
|
||||
|
||||
if (normalizedOrderIds.length > 0) {
|
||||
where.id = {
|
||||
@ -5704,6 +5712,7 @@ class WaveService extends OrderBaseService {
|
||||
const strategyVersion = this.normalizeWaveStrategyQuickScanVersion(normalizedOptions.strategyVersion);
|
||||
const taskId = String(normalizedOptions.taskId || '').trim();
|
||||
const orderIds = this.normalizeIdsInput(normalizedOptions.orderIds);
|
||||
const forceRescan = this.normalizeBoolean(normalizedOptions.forceRescan, false);
|
||||
|
||||
const strategyRows = await this.getWaveStrategyQuickScanStrategyRows(warehouseId);
|
||||
const strategyList = this.normalizeWaveStrategyQuickScanList(strategyRows);
|
||||
@ -5724,7 +5733,7 @@ class WaveService extends OrderBaseService {
|
||||
'sys_platform_code',
|
||||
'source_platform_code',
|
||||
],
|
||||
where: this.buildWaveStrategyQuickScanOrderWhere(warehouseId, strategyVersion, orderIds),
|
||||
where: this.buildWaveStrategyQuickScanOrderWhere(warehouseId, strategyVersion, orderIds, forceRescan),
|
||||
raw: true,
|
||||
});
|
||||
|
||||
@ -5874,6 +5883,10 @@ class WaveService extends OrderBaseService {
|
||||
? normalizedParams.order_ids
|
||||
: normalizedParams.ids;
|
||||
const orderIds = this.normalizeIdsInput(rawOrderIds);
|
||||
const forceRescan = this.normalizeBoolean(
|
||||
normalizedParams.forceRescan ?? normalizedParams.force_rescan,
|
||||
false
|
||||
);
|
||||
|
||||
const subjectConfig = await this.getWarehouseSubjectConfig(warehouseId);
|
||||
const strategyVersion = this.normalizeWaveStrategyQuickScanVersion(
|
||||
@ -5885,6 +5898,7 @@ class WaveService extends OrderBaseService {
|
||||
strategyVersion,
|
||||
orderIds,
|
||||
taskId: normalizedTaskId,
|
||||
forceRescan,
|
||||
});
|
||||
|
||||
if (scanResult.totalOrderCount === 0) {
|
||||
|
||||
@ -483,6 +483,9 @@ async function markPendingExceptionInternal(service, orderModel, orderId, wareho
|
||||
where: {
|
||||
id: orderId,
|
||||
warehouse_id: warehouseId,
|
||||
status: {
|
||||
[Op.ne]: 'cancel',
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@ -1187,6 +1187,7 @@ class OrderStorageAllocationService extends MainService {
|
||||
order_item_id: toNumber(orderItem.id, 0),
|
||||
warehouse_id: warehouseId,
|
||||
storage_id: storageRow.id,
|
||||
stock_id: toNumber(storageRow.stock_id, 0) || null,
|
||||
quantity: allocationQuantity,
|
||||
space_id: toNumber(storageRow.space_id, 0) || null,
|
||||
space_name: String(storageRow.space_name || '').trim(),
|
||||
@ -1656,6 +1657,10 @@ class OrderStorageAllocationService extends MainService {
|
||||
sync_status: {
|
||||
[ctx.app.Sequelize.Op.notIn]: [ 'fin' ],
|
||||
},
|
||||
// 排除已取消的订单,防止已取消订单被回传
|
||||
status: {
|
||||
[ctx.app.Sequelize.Op.notIn]: [ 'cancel' ],
|
||||
},
|
||||
},
|
||||
transaction,
|
||||
lock: transaction.LOCK.UPDATE,
|
||||
|
||||
@ -137,7 +137,7 @@ class PickSystemService extends Service {
|
||||
[this.app.Sequelize.Op.in]: orderItemIds,
|
||||
},
|
||||
},
|
||||
attributes: [ 'id', 'item_code', 'item_name', 'stock_id', 'plan_qty', 'item_snapshot' ],
|
||||
attributes: [ 'id', 'item_code', 'item_name', 'stock_id', 'plan_qty', 'item_snapshot', 'owner_code' ],
|
||||
raw: true,
|
||||
});
|
||||
|
||||
@ -323,6 +323,10 @@ class PickSystemService extends Service {
|
||||
total_qty: 0,
|
||||
box_allocations: [],
|
||||
details: [],
|
||||
store_id: detail.store_id != null ? Number(detail.store_id) : 0,
|
||||
owner_code: String(detail.owner_code || '').trim(),
|
||||
store_remark: String(detail.store_remark || '').trim(),
|
||||
stock: detail.stock || null,
|
||||
});
|
||||
}
|
||||
const groupItem = groupMap.get(groupKey);
|
||||
@ -495,6 +499,9 @@ class PickSystemService extends Service {
|
||||
stock_id: Number(groupItem && groupItem.stock_id || 0),
|
||||
total_qty: Number(groupItem && groupItem.total_qty || 0),
|
||||
box_allocations: boxAllocations,
|
||||
store_id: groupItem.store_id != null ? Number(groupItem.store_id) : 0,
|
||||
owner_code: String(groupItem.owner_code || '').trim(),
|
||||
store_remark: String(groupItem.store_remark || '').trim(),
|
||||
};
|
||||
});
|
||||
|
||||
@ -1196,6 +1203,36 @@ class PickSystemService extends Service {
|
||||
}
|
||||
}
|
||||
|
||||
// 批量查询货主备注名(wms_store_warehouse.store_remask),按 store_id 映射
|
||||
const storeRemarkMap = new Map();
|
||||
if (stockDetailMap.size > 0 && ctx.model && ctx.model.StoreWarehouse) {
|
||||
const storeIdsForRemark = [ ...new Set(
|
||||
[ ...stockDetailMap.values() ]
|
||||
.map(detail => Number(detail.store_id || 0))
|
||||
.filter(id => id > 0)
|
||||
) ];
|
||||
if (storeIdsForRemark.length > 0) {
|
||||
try {
|
||||
const swRows = await ctx.model.StoreWarehouse.findAll({
|
||||
where: {
|
||||
store_id: { [this.app.Sequelize.Op.in]: storeIdsForRemark },
|
||||
warehouse_id: warehouseId,
|
||||
},
|
||||
attributes: [ 'store_id', 'store_remask' ],
|
||||
raw: true,
|
||||
});
|
||||
for (const sw of (Array.isArray(swRows) ? swRows : [])) {
|
||||
const sid = Number(sw.store_id || 0);
|
||||
if (sid > 0 && !storeRemarkMap.has(sid)) {
|
||||
storeRemarkMap.set(sid, String(sw.store_remask || '').trim());
|
||||
}
|
||||
}
|
||||
} catch (remarkError) {
|
||||
ctx.logger.warn(`[pick.wavePickTaskDetail] 查询货主备注失败: ${remarkError.message}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const normalizedBoxRows = Array.isArray(boxRows) ? boxRows : [];
|
||||
const boxMapByNo = new Map(normalizedBoxRows
|
||||
.map(row => [ Number(row && row.box_no || 0), row ])
|
||||
@ -1221,7 +1258,17 @@ class PickSystemService extends Service {
|
||||
stock_unit: String(itemSnapshot.stock_unit || '').trim(),
|
||||
barcodes: [],
|
||||
image_url: [],
|
||||
store_id: 0,
|
||||
};
|
||||
// 确保 owner_code 在 stock 对象上(getStockDetails 不含此字段,需从 order_items 补)
|
||||
if (!stock.owner_code) {
|
||||
stock.owner_code = String(orderItemRow.owner_code || '').trim();
|
||||
}
|
||||
// 确保 store_remark 在 stock 对象上(getStockDetails 不含此字段,需从 wms_store_warehouse 补)
|
||||
const stockStoreId = stock.store_id != null ? Number(stock.store_id) : 0;
|
||||
if (!stock.store_remark) {
|
||||
stock.store_remark = storeRemarkMap.get(stockStoreId) || '';
|
||||
}
|
||||
|
||||
return {
|
||||
order_id: Number(row && row.order_id || 0),
|
||||
@ -1243,6 +1290,9 @@ class PickSystemService extends Service {
|
||||
stock_id: stockId,
|
||||
plan_qty: Number(orderItemRow.plan_qty || 0),
|
||||
item_snapshot: orderItemRow.item_snapshot || null,
|
||||
store_id: stockStoreId,
|
||||
owner_code: String(stock.owner_code || '').trim(),
|
||||
store_remark: String(stock.store_remark || '').trim(),
|
||||
stock,
|
||||
};
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user