feat(order): 订单拦截全链路阻断与作业排除
- 新增 app/lib/intercept_guard 共享守卫:除 none 外所有拦截状态一律视为已拦截 - 分配波次(singleFetchByIds)/抓取波次(createWavePickTask) 排除拦截订单并回传清单 - 分配储位(allocatePicking)/分配快递(createWaybillCodePipeline、batchAllocateExpress) 跳过拦截订单并回报 - 打印组装(getWavePlatformPrintData/getOrderPrintData/getPrintDataByWaybillCodes) 剔除拦截订单,打印回写/波次反查/标记均排除 - 拣货完成(wavePickTaskComplete) 拦截报错;复核(assertOrderCanRecheck/批量快捷复核) 补全拦截状态 - 打包/称重(workbench、order.updateExpressWeighingWeight) 拦截阻断,波次批量操作排除拦截单 - 绑定包材(order_express) 拦截阻断,波次批量绑定排除拦截单
This commit is contained in:
parent
d0621dd4ec
commit
a8200a3a35
31
app/lib/intercept_guard.js
Normal file
31
app/lib/intercept_guard.js
Normal file
@ -0,0 +1,31 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* 订单拦截状态共享定义。
|
||||
*
|
||||
* wms_order_delivery.intercept_status 枚举(order_delivery.js / order_delivery_factory.js)实际取值为:
|
||||
* none / requesting / requested / intercepting / intercepted_in_transit / intercepted_at_warehouse /
|
||||
* returning / returned / delivered_by_mistake / timeout / cancelled / failed / exception。
|
||||
*
|
||||
* 业务约定:拦截状态只要不是 'none'(即任意进入拦截流程/拦截结果的状态),一律视为"已拦截",
|
||||
* 禁止继续执行仓储作业(分配波次/分配储位/分配快递/打印/抓取波次/拣货/复核/打包/称重/绑定包材等),
|
||||
* 被拦截订单一律跳过。
|
||||
*/
|
||||
const INTERCEPT_STATUS_NONE = 'none';
|
||||
|
||||
/**
|
||||
* 判断订单拦截状态是否属于"已拦截"。
|
||||
* 空值/NULL 归一化为 none 处理;除此之外任何非 none 状态(含 requested/intercepting/intercepted_*、
|
||||
* returning/returned/cancelled/failed/exception 等)均视为已拦截。
|
||||
* @param {*} status 拦截状态值。
|
||||
* @return {boolean} 是否已拦截。
|
||||
*/
|
||||
function isInterceptedOrderStatus(status) {
|
||||
const normalizedStatus = String(status || '').trim() || INTERCEPT_STATUS_NONE;
|
||||
return normalizedStatus !== INTERCEPT_STATUS_NONE;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
INTERCEPT_STATUS_NONE,
|
||||
isInterceptedOrderStatus,
|
||||
};
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
const MainService = require('../../main');
|
||||
const { parseWhereConditions } = require('../../../lib/query_condition_parser');
|
||||
const { isInterceptedOrderStatus } = require('../../../lib/intercept_guard');
|
||||
|
||||
const DEFAULT_PAGE_SIZE = 20;
|
||||
const MAX_PAGE_SIZE = 500;
|
||||
@ -194,6 +195,36 @@ class OrderBaseService extends MainService {
|
||||
return `${chars[0]}***${chars[chars.length - 1]}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断订单拦截状态是否属于"已进入拦截流程"的状态。
|
||||
*
|
||||
* requested/requesting/intercepting 为拦截发起中,intercepted_in_transit 为途中拦截成功,
|
||||
* intercepted_at_warehouse 为仓库拦截成功;intercepted 为历史遗留值,一并兼容。
|
||||
*
|
||||
* @param {*} status 拦截状态值。
|
||||
* @return {boolean} 是否已进入拦截流程。
|
||||
*/
|
||||
isInterceptedOrderStatus(status = '') {
|
||||
return isInterceptedOrderStatus(status);
|
||||
}
|
||||
|
||||
/**
|
||||
* 断言订单未进入拦截流程,否则抛出阻断异常。
|
||||
*
|
||||
* @param {Object} orderRow 订单行(需含 intercept_status 字段)。
|
||||
* @param {string} [actionText='继续作业'] 被阻断的作业文案。
|
||||
* @return {void} 无返回值。
|
||||
*/
|
||||
assertOrderNotIntercepted(orderRow = {}, actionText = '继续作业') {
|
||||
if (!this.isPlainObject(orderRow)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.isInterceptedOrderStatus(orderRow.intercept_status)) {
|
||||
throw new Error(`订单已被拦截,无法${actionText}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前请求对应的仓库ID。
|
||||
* @return {number|string|null} 仓库ID。
|
||||
|
||||
@ -1205,8 +1205,14 @@ class PendingOrderService extends OrderBaseService {
|
||||
const resultData = result && result.data ? result.data : (result || {});
|
||||
const allocatedIds = Array.isArray(resultData.allocated_order_ids) ? resultData.allocated_order_ids : [];
|
||||
const shortageIds = Array.isArray(resultData.shortage_order_ids) ? resultData.shortage_order_ids : [];
|
||||
const skippedList = Array.isArray(resultData.skipped_orders) ? resultData.skipped_orders : [];
|
||||
const allocatedSet = new Set(allocatedIds.map(Number));
|
||||
const shortageSet = new Set(shortageIds.map(Number));
|
||||
const skippedMap = new Map(
|
||||
skippedList
|
||||
.filter(item => Number(item && item.order_id) > 0)
|
||||
.map(item => [ Number(item.order_id), item ])
|
||||
);
|
||||
|
||||
if (orderIds.length > 0 && this.ctx.model && this.ctx.model.OperationLog) {
|
||||
const operatorInfo = operator || {};
|
||||
@ -1218,16 +1224,23 @@ class PendingOrderService extends OrderBaseService {
|
||||
const oid = Number(orderId);
|
||||
const allocated = allocatedSet.has(oid);
|
||||
const shortage = shortageSet.has(oid);
|
||||
const skippedItem = skippedMap.get(oid) || null;
|
||||
const skippedReason = skippedItem ? String(skippedItem.skipped_reason || '').trim() : '';
|
||||
const skippedMessage = skippedReason === 'intercepted'
|
||||
? '储位分配跳过:订单已拦截'
|
||||
: (skippedReason ? `储位分配跳过:${skippedReason}` : '');
|
||||
const operationCode = allocated
|
||||
? 'ORDER_STORAGE_ALLOCATE_SUCCESS'
|
||||
: shortage
|
||||
? 'ORDER_STORAGE_ALLOCATE_FAILED'
|
||||
: 'ORDER_STORAGE_ALLOCATE_SUCCESS';
|
||||
: skippedItem
|
||||
? 'ORDER_STORAGE_ALLOCATE_FAILED'
|
||||
: 'ORDER_STORAGE_ALLOCATE_SUCCESS';
|
||||
const msg = allocated
|
||||
? '储位分配成功'
|
||||
: shortage
|
||||
? '储位分配失败:库存不足'
|
||||
: '储位分配完成';
|
||||
: skippedMessage || '储位分配完成';
|
||||
return {
|
||||
business_type: 'order',
|
||||
business_id: String(oid),
|
||||
|
||||
@ -671,28 +671,6 @@ class RecheckOrderService extends OrderBaseService {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断订单拦截状态是否属于"已进入拦截流程"的状态。
|
||||
* 拦截状态枚举(wms_order_delivery.intercept_status)实际取值为:
|
||||
* none / requesting / requested / intercepting / intercepted_in_transit / intercepted_at_warehouse /
|
||||
* returning / returned / delivered_by_mistake / timeout / cancelled / failed / exception。
|
||||
* 其中 requested/requesting/intercepting 为拦截发起中,intercepted_in_transit 为途中拦截成功,
|
||||
* intercepted_at_warehouse 为仓库拦截成功;intercepted 为历史遗留值,一并兼容。
|
||||
* @param {string} status 拦截状态。
|
||||
* @return {boolean} 是否为拦截流程状态。
|
||||
*/
|
||||
isInterceptedOrderStatus(status = '') {
|
||||
const normalizedStatus = String(status || '').trim();
|
||||
return [
|
||||
'intercepted',
|
||||
'requested',
|
||||
'requesting',
|
||||
'intercepting',
|
||||
'intercepted_in_transit',
|
||||
'intercepted_at_warehouse',
|
||||
].includes(normalizedStatus);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建团购波次列表视图(团单模式)。
|
||||
* 根据拣货任务ID查找关联的所有波次,每个波次展开为一项。
|
||||
@ -3201,8 +3179,7 @@ class RecheckOrderService extends OrderBaseService {
|
||||
if (String(order.pick_status || '') === 'none') {
|
||||
throw new Error('订单未拣货,不允许复核。');
|
||||
}
|
||||
const interceptStatus = String(order.intercept_status || '').trim();
|
||||
if (interceptStatus === 'intercepted' || interceptStatus === 'intercepted_at_warehouse') {
|
||||
if (this.isInterceptedOrderStatus(order.intercept_status)) {
|
||||
throw new Error('订单已被拦截,无法提交复核');
|
||||
}
|
||||
}
|
||||
@ -3926,7 +3903,7 @@ class RecheckOrderService extends OrderBaseService {
|
||||
* 1. 未分配储位:storage_status 不等于 'fin'
|
||||
* 2. 未分配快递:post_status 不等于 'fin'
|
||||
* 3. 未同步:status 不等于 'created'
|
||||
* 4. 已拦截:intercept_status 为 'intercepted' 或 'intercepted_at_warehouse'
|
||||
* 4. 已拦截:intercept_status 处于拦截流程状态(requested/requesting/intercepting/intercepted_in_transit/intercepted_at_warehouse,历史值 intercepted 兼容)
|
||||
*
|
||||
* 核心流程(每个满足条件的订单在独立事务中执行):
|
||||
* 1. 若 pick_status 不等于 'fin',先完成拣货:
|
||||
@ -3983,8 +3960,7 @@ class RecheckOrderService extends OrderBaseService {
|
||||
continue;
|
||||
}
|
||||
|
||||
const interceptStatus = String(order.intercept_status || '').trim();
|
||||
if (interceptStatus === 'intercepted' || interceptStatus === 'intercepted_at_warehouse') {
|
||||
if (this.isInterceptedOrderStatus(order.intercept_status)) {
|
||||
failedOrders.push({
|
||||
order_id: orderId,
|
||||
delivery_order_code: String(order.delivery_order_code || order.pre_delivery_order_code || '').trim(),
|
||||
@ -4172,8 +4148,7 @@ class RecheckOrderService extends OrderBaseService {
|
||||
for (const order of waveOrders) {
|
||||
const orderId = Number(order.id);
|
||||
|
||||
const interceptStatus = String(order.intercept_status || '').trim();
|
||||
if (interceptStatus === 'intercepted' || interceptStatus === 'intercepted_at_warehouse') {
|
||||
if (this.isInterceptedOrderStatus(order.intercept_status)) {
|
||||
allFailedOrders.push({
|
||||
order_id: orderId,
|
||||
wave_id: waveId,
|
||||
|
||||
@ -6800,7 +6800,7 @@ class WaveService extends OrderBaseService {
|
||||
|
||||
try {
|
||||
const orderRows = await orderModel.findAll({
|
||||
attributes: [ 'id', 'wave_id', 'wave_no', 'step', 'status', 'outbound_status', 'items_hash', 'items', 'logistics_name' ],
|
||||
attributes: [ 'id', 'wave_id', 'wave_no', 'step', 'status', 'outbound_status', 'items_hash', 'items', 'logistics_name', 'intercept_status' ],
|
||||
where: {
|
||||
id: { [Op.in]: normalizedIds },
|
||||
},
|
||||
@ -6819,6 +6819,11 @@ class WaveService extends OrderBaseService {
|
||||
.map(row => Number(row && row.id || 0))
|
||||
.filter(id => Number.isInteger(id) && id > 0)) ]
|
||||
.sort((a, b) => a - b);
|
||||
const excludedInterceptedOrderIds = [ ...new Set(normalizedOrderRows
|
||||
.filter(row => this.isInterceptedOrderStatus(row && row.intercept_status))
|
||||
.map(row => Number(row && row.id || 0))
|
||||
.filter(id => Number.isInteger(id) && id > 0)) ]
|
||||
.sort((a, b) => a - b);
|
||||
|
||||
const fetchableRows = normalizedOrderRows.filter(row => {
|
||||
const orderId = Number(row && row.id || 0);
|
||||
@ -6832,6 +6837,11 @@ class WaveService extends OrderBaseService {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 拦截流程中的订单不允许分配波次
|
||||
if (this.isInterceptedOrderStatus(row && row.intercept_status)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
@ -6851,6 +6861,7 @@ class WaveService extends OrderBaseService {
|
||||
fetched_order_ids: [],
|
||||
fetched_order_count: 0,
|
||||
excluded_existing_wave_order_ids: excludedExistingWaveOrderIds,
|
||||
excluded_intercepted_order_ids: excludedInterceptedOrderIds,
|
||||
skipped_order_ids: skippedOrderIds,
|
||||
not_found_order_ids: notFoundOrderIds,
|
||||
});
|
||||
@ -6964,6 +6975,7 @@ class WaveService extends OrderBaseService {
|
||||
fetched_order_ids: grabbedOrderIds,
|
||||
fetched_order_count: grabbedOrderIds.length,
|
||||
excluded_existing_wave_order_ids: excludedExistingWaveOrderIds,
|
||||
excluded_intercepted_order_ids: excludedInterceptedOrderIds,
|
||||
skipped_order_ids: skippedOrderIds,
|
||||
not_found_order_ids: notFoundOrderIds,
|
||||
});
|
||||
@ -8792,7 +8804,7 @@ class WaveService extends OrderBaseService {
|
||||
|
||||
try {
|
||||
orderRows = await orderModel.findAll({
|
||||
attributes: [ 'id', 'business_key' ],
|
||||
attributes: [ 'id', 'business_key', 'intercept_status' ],
|
||||
where: baseOrderWhere,
|
||||
raw: true,
|
||||
});
|
||||
@ -8808,7 +8820,7 @@ class WaveService extends OrderBaseService {
|
||||
warehouseId,
|
||||
});
|
||||
orderRows = await orderModel.findAll({
|
||||
attributes: [ 'id' ],
|
||||
attributes: [ 'id', 'intercept_status' ],
|
||||
where: baseOrderWhere,
|
||||
raw: true,
|
||||
});
|
||||
@ -8823,10 +8835,25 @@ class WaveService extends OrderBaseService {
|
||||
matchedOrderCount: Array.isArray(orderRows) ? orderRows.length : 0,
|
||||
});
|
||||
|
||||
const skippedInterceptedOrderIds = [ ...new Set((Array.isArray(orderRows) ? orderRows : [])
|
||||
.filter(row => this.isInterceptedOrderStatus(row && row.intercept_status))
|
||||
.map(row => Number(row && row.id || 0))
|
||||
.filter(orderId => Number.isInteger(orderId) && orderId > 0)) ]
|
||||
.sort((a, b) => a - b);
|
||||
const skippedInterceptedOrderIdSet = new Set(skippedInterceptedOrderIds);
|
||||
if (skippedInterceptedOrderIds.length > 0) {
|
||||
this.ctx.logger.info('[wave.batchAllocateExpress] 跳过拦截订单', {
|
||||
traceId,
|
||||
taskId: normalizedTaskId,
|
||||
warehouseId,
|
||||
skippedInterceptedOrderIds,
|
||||
});
|
||||
}
|
||||
|
||||
const normalizedOrders = (Array.isArray(orderRows) ? orderRows : [])
|
||||
.map(row => {
|
||||
const orderId = Number(row && row.id || 0);
|
||||
if (!Number.isInteger(orderId) || orderId <= 0) {
|
||||
if (!Number.isInteger(orderId) || orderId <= 0 || skippedInterceptedOrderIdSet.has(orderId)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -8844,6 +8871,7 @@ class WaveService extends OrderBaseService {
|
||||
taskId: normalizedTaskId,
|
||||
warehouseId,
|
||||
waveIds,
|
||||
skippedInterceptedOrderIds,
|
||||
});
|
||||
const durationMs = Date.now() - startTime;
|
||||
await this.setBatchAllocateExpressTaskProgress(normalizedTaskId, 'success', {
|
||||
@ -8853,14 +8881,18 @@ class WaveService extends OrderBaseService {
|
||||
processed_order_count: 0,
|
||||
success_order_count: 0,
|
||||
failed_order_count: 0,
|
||||
skipped_intercepted_order_ids: skippedInterceptedOrderIds,
|
||||
progress_percent: 100,
|
||||
end_time: Date.now(),
|
||||
duration_ms: durationMs,
|
||||
result: {
|
||||
wave_ids: waveIds,
|
||||
allocated_order_count: 0,
|
||||
skipped_intercepted_order_ids: skippedInterceptedOrderIds,
|
||||
duration_ms: durationMs,
|
||||
message: '未找到可分配快递号的订单',
|
||||
message: skippedInterceptedOrderIds.length > 0
|
||||
? `拦截订单已跳过,未找到可分配快递号的订单(跳过 ${skippedInterceptedOrderIds.length} 单)`
|
||||
: '未找到可分配快递号的订单',
|
||||
},
|
||||
trace_id: traceId,
|
||||
});
|
||||
@ -8902,12 +8934,14 @@ class WaveService extends OrderBaseService {
|
||||
processed_order_count: normalizedOrders.length,
|
||||
success_order_count: normalizedOrders.length,
|
||||
failed_order_count: 0,
|
||||
skipped_intercepted_order_ids: skippedInterceptedOrderIds,
|
||||
progress_percent: 100,
|
||||
end_time: Date.now(),
|
||||
duration_ms: durationMs,
|
||||
result: {
|
||||
wave_ids: waveIds,
|
||||
allocated_order_count: normalizedOrders.length,
|
||||
skipped_intercepted_order_ids: skippedInterceptedOrderIds,
|
||||
duration_ms: durationMs,
|
||||
message: String(pipelineResult && pipelineResult.message || '分配快递任务已提交').trim(),
|
||||
},
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const MainService = require('../main');
|
||||
const { isInterceptedOrderStatus } = require('../../lib/intercept_guard');
|
||||
|
||||
class PickService extends MainService {
|
||||
/**
|
||||
@ -132,9 +133,26 @@ class PickService extends MainService {
|
||||
[this.app.Sequelize.Op.in]: normalizedOrderIds,
|
||||
},
|
||||
},
|
||||
attributes: [ 'id' ],
|
||||
attributes: [ 'id', 'intercept_status' ],
|
||||
raw: true,
|
||||
});
|
||||
|
||||
// 拦截流程中的订单不允许抓取波次,直接剔除
|
||||
const interceptedOrderIds = new Set((Array.isArray(orderRows) ? orderRows : [])
|
||||
.filter(row => isInterceptedOrderStatus(row && row.intercept_status))
|
||||
.map(row => Number(row && row.id || 0))
|
||||
.filter(id => Number.isInteger(id) && id > 0));
|
||||
if (interceptedOrderIds.size > 0) {
|
||||
const excludedIds = normalizedOrderIds.filter(id => interceptedOrderIds.has(id));
|
||||
if (excludedIds.length > 0) {
|
||||
ctx.logger.info('[pick.createWavePickTask] 剔除拦截订单: %s', excludedIds.join(','));
|
||||
}
|
||||
}
|
||||
const activeOrderIds = normalizedOrderIds.filter(id => !interceptedOrderIds.has(id));
|
||||
if (activeOrderIds.length <= 0) {
|
||||
throw Object.assign(new Error('波次下订单均已被拦截,无法创建任务'), { code: 400 });
|
||||
}
|
||||
|
||||
const orderNoMap = new Map((Array.isArray(orderRows) ? orderRows : [])
|
||||
.map(row => [ Number(row && row.id || 0), '' ]));
|
||||
|
||||
@ -182,7 +200,7 @@ class PickService extends MainService {
|
||||
waveId,
|
||||
pickMode,
|
||||
source,
|
||||
orderCount: normalizedOrderIds.length,
|
||||
orderCount: activeOrderIds.length,
|
||||
operatorId,
|
||||
operatorName,
|
||||
remark,
|
||||
@ -257,10 +275,10 @@ class PickService extends MainService {
|
||||
}
|
||||
);
|
||||
|
||||
if (normalizedOrderIds.length > 0) {
|
||||
if (activeOrderIds.length > 0) {
|
||||
// 按库位排序并按 stock_id 分组,同 stock_id 的订单共享同一篮号
|
||||
const stockGroups = await this.resolveLocationSortedOrderIds(
|
||||
normalizedOrderIds,
|
||||
activeOrderIds,
|
||||
warehouseId,
|
||||
transaction
|
||||
);
|
||||
@ -418,7 +436,7 @@ class PickService extends MainService {
|
||||
&& this.ctx.service.systems
|
||||
&& this.ctx.service.systems.operationLog;
|
||||
if (operationLogService && typeof operationLogService.createOperationLogs === 'function') {
|
||||
const logPayloads = normalizedOrderIds.map(orderId => ({
|
||||
const logPayloads = activeOrderIds.map(orderId => ({
|
||||
businessType: 'order',
|
||||
businessId: `${orderId}`,
|
||||
operationCode: 'ORDER_WAVE_GRAB',
|
||||
@ -437,7 +455,7 @@ class PickService extends MainService {
|
||||
} catch (e) {
|
||||
ctx.logger.warn('[pick.createWavePickTask] 写入 order_operation_log 失败,不影响主流程', {
|
||||
error: e && e.message,
|
||||
normalizedOrderIds,
|
||||
activeOrderIds,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -348,6 +348,7 @@ class PrintService extends MainService {
|
||||
: { print_status: 'error' };
|
||||
const where = {
|
||||
id: orderIds,
|
||||
intercept_status: 'none',
|
||||
};
|
||||
if (callbackResult === 'failed') {
|
||||
where.print_status = 'none';
|
||||
@ -1614,6 +1615,7 @@ class PrintService extends MainService {
|
||||
wave_id: waveId,
|
||||
warehouse_id: warehouseId,
|
||||
status: { [this.app.Sequelize.Op.ne]: 'cancel' },
|
||||
intercept_status: 'none',
|
||||
},
|
||||
raw: true,
|
||||
});
|
||||
@ -1764,6 +1766,7 @@ class PrintService extends MainService {
|
||||
}, {
|
||||
where: {
|
||||
id: orderIds,
|
||||
intercept_status: 'none',
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@ -2,6 +2,8 @@
|
||||
|
||||
const { Service } = require('egg');
|
||||
|
||||
const { isInterceptedOrderStatus } = require('../../lib/intercept_guard');
|
||||
|
||||
const DEFAULT_CACHE_TTL_SECONDS = 600;
|
||||
const DEFAULT_EXPRESS_PRODUCT_TYPE_CACHE_TTL_SECONDS = 60 * 60;
|
||||
const DEFAULT_WAYBILL_BATCH_SIZE = 10;
|
||||
@ -2514,7 +2516,7 @@ class ExpressService extends Service {
|
||||
[Op.ne]: 'cancel',
|
||||
},
|
||||
},
|
||||
attributes: [ 'id', 'sys_platform_code', 'logistics_code', 'sys_platform_name', 'logistics_name', 'store_id', 'pay_no', 'from_key' ],
|
||||
attributes: [ 'id', 'sys_platform_code', 'logistics_code', 'sys_platform_name', 'logistics_name', 'store_id', 'pay_no', 'from_key', 'intercept_status' ],
|
||||
raw: true,
|
||||
});
|
||||
|
||||
@ -2538,13 +2540,27 @@ class ExpressService extends Service {
|
||||
[Op.ne]: 'cancel',
|
||||
},
|
||||
},
|
||||
attributes: [ 'id', 'sys_platform_code', 'logistics_code', 'sys_platform_name', 'logistics_name', 'store_id', 'pay_no', 'from_key' ],
|
||||
attributes: [ 'id', 'sys_platform_code', 'logistics_code', 'sys_platform_name', 'logistics_name', 'store_id', 'pay_no', 'from_key', 'intercept_status' ],
|
||||
raw: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const orders_arr = [ ...(Array.isArray(currentOrders) ? currentOrders : []), ...dispatchOrders ];
|
||||
// 拦截订单跳过(除 none 外一律视为已拦截)
|
||||
const mergedOrders = [ ...(Array.isArray(currentOrders) ? currentOrders : []), ...dispatchOrders ];
|
||||
const interceptedOrderIdSet = new Set(mergedOrders
|
||||
.filter(order => isInterceptedOrderStatus(order && order.intercept_status))
|
||||
.map(order => Number(order && order.id || 0))
|
||||
.filter(orderId => Number.isInteger(orderId) && orderId > 0));
|
||||
const skippedInterceptedOrderIds = Array.from(interceptedOrderIdSet);
|
||||
const orders_arr = mergedOrders.filter(order => !interceptedOrderIdSet.has(Number(order && order.id || 0)));
|
||||
if (skippedInterceptedOrderIds.length > 0) {
|
||||
this.ctx.logger.info('[ExpressService.createWaybillCodePipeline] 跳过拦截订单', {
|
||||
traceId,
|
||||
warehouseId,
|
||||
skippedInterceptedOrderIds,
|
||||
});
|
||||
}
|
||||
this.ctx.logger.info('[ExpressService.createWaybillCodePipeline] 订单筛选结果', {
|
||||
traceId,
|
||||
warehouseId,
|
||||
@ -2552,6 +2568,7 @@ class ExpressService extends Service {
|
||||
currentCount: (Array.isArray(currentOrders) ? currentOrders : []).length,
|
||||
dispatchCount: dispatchOrders.length,
|
||||
matchedOrderCount: orders_arr.length,
|
||||
skippedInterceptedOrderIds,
|
||||
});
|
||||
|
||||
// 【step1.5】过滤已分配运单号(status=1)且传入 business_key=1 的订单,避免重复分配。
|
||||
@ -2600,7 +2617,10 @@ class ExpressService extends Service {
|
||||
|
||||
if (filteredOrdersArr.length === 0) {
|
||||
this.ctx.logger.info('[ExpressService.createWaybillCodePipeline] 所有订单均已分配运单号,无需处理', { traceId });
|
||||
return { message: '所有订单均已分配运单号,无需处理' };
|
||||
return {
|
||||
message: '所有订单均已分配运单号,无需处理',
|
||||
skipped_intercepted_order_ids: skippedInterceptedOrderIds,
|
||||
};
|
||||
}
|
||||
|
||||
// orders_arr和orderList合并:同一 order_id 在 orderList 中可能有多条(不同 business_key),
|
||||
@ -2702,7 +2722,10 @@ class ExpressService extends Service {
|
||||
traceId,
|
||||
groupedCount: groupedOrders.length,
|
||||
});
|
||||
return { message: '分配快递任务已提交' };
|
||||
return {
|
||||
message: '分配快递任务已提交',
|
||||
skipped_intercepted_order_ids: skippedInterceptedOrderIds,
|
||||
};
|
||||
}
|
||||
/**
|
||||
* 异步执行订单快递分配任务。错误订单转异常,并记录失败订单列表。
|
||||
|
||||
@ -2,6 +2,8 @@
|
||||
|
||||
const Service = require('egg').Service;
|
||||
|
||||
const { isInterceptedOrderStatus } = require('../../lib/intercept_guard');
|
||||
|
||||
/**
|
||||
* 订单快递业务服务。
|
||||
*
|
||||
@ -196,6 +198,55 @@ class OrderExpressService extends Service {
|
||||
return orderExpressRow;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询订单拦截状态(依次查询 current → dispatch 分表)。
|
||||
* @param {number} orderId 订单 ID。
|
||||
* @param {number} warehouseId 仓库 ID。
|
||||
* @return {Promise<string>} 拦截状态,查询失败时返回 'none'。
|
||||
*/
|
||||
async findOrderInterceptStatus(orderId, warehouseId) {
|
||||
const orderDeliveryFactory = this.ctx.model && this.ctx.model.OrderDeliveryFactory;
|
||||
if (!orderDeliveryFactory || typeof orderDeliveryFactory.getCurrentModel !== 'function') {
|
||||
return 'none';
|
||||
}
|
||||
|
||||
const tableOrders = [
|
||||
{ label: 'current', getModel: () => orderDeliveryFactory.getCurrentModel(warehouseId) },
|
||||
{ label: 'dispatch', getModel: () => orderDeliveryFactory.getDispatchModel(warehouseId) },
|
||||
];
|
||||
|
||||
for (const entry of tableOrders) {
|
||||
try {
|
||||
const model = await entry.getModel();
|
||||
if (!model || typeof model.findOne !== 'function') continue;
|
||||
const row = await model.findOne({
|
||||
where: { id: orderId, warehouse_id: warehouseId },
|
||||
attributes: [ 'id', 'intercept_status' ],
|
||||
raw: true,
|
||||
});
|
||||
if (row) {
|
||||
return String(row.intercept_status || '').trim() || 'none';
|
||||
}
|
||||
} catch (_err) { continue; }
|
||||
}
|
||||
|
||||
return 'none';
|
||||
}
|
||||
|
||||
/**
|
||||
* 断言订单未进入拦截流程,否则抛出业务异常。
|
||||
* @param {number} orderId 订单 ID。
|
||||
* @param {number} warehouseId 仓库 ID。
|
||||
* @param {string} [actionText='继续作业'] 被阻断的作业文案。
|
||||
* @return {Promise<void>} 无返回值。
|
||||
*/
|
||||
async assertOrderNotIntercepted(orderId, warehouseId, actionText = '继续作业') {
|
||||
const interceptStatus = await this.findOrderInterceptStatus(orderId, warehouseId);
|
||||
if (isInterceptedOrderStatus(interceptStatus)) {
|
||||
throw this.createBusinessError(`订单已被拦截,无法${actionText}`, 400);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 规范化并校验称重重量。
|
||||
*
|
||||
@ -306,6 +357,9 @@ class OrderExpressService extends Service {
|
||||
throw this.createBusinessError('运单号不存在', 404);
|
||||
}
|
||||
|
||||
// 拦截流程中的订单不允许称重
|
||||
await this.assertOrderNotIntercepted(normalizedOrderId, warehouseId, '称重');
|
||||
|
||||
// 依次查询多个订单表获取波次信息:current → history → dispatch
|
||||
const orderDeliveryFactory = this.ctx.model && this.ctx.model.OrderDeliveryFactory;
|
||||
if (!orderDeliveryFactory || typeof orderDeliveryFactory.getCurrentModel !== 'function') {
|
||||
@ -438,6 +492,9 @@ class OrderExpressService extends Service {
|
||||
|
||||
const orderId = Number(expressRow.order_id || 0);
|
||||
|
||||
// 拦截流程中的订单不允许称重
|
||||
await this.assertOrderNotIntercepted(orderId, warehouseId, '称重');
|
||||
|
||||
// 依次查询多个订单表获取波次信息:current → history → dispatch
|
||||
const orderDeliveryFactory = this.ctx.model && this.ctx.model.OrderDeliveryFactory;
|
||||
if (!orderDeliveryFactory || typeof orderDeliveryFactory.getCurrentModel !== 'function') {
|
||||
@ -546,7 +603,7 @@ class OrderExpressService extends Service {
|
||||
// 查询波次下所有订单
|
||||
const waveOrders = await orderDeliveryModel.findAll({
|
||||
where: { wave_id: waveId, warehouse_id: warehouseId },
|
||||
attributes: [ 'id' ],
|
||||
attributes: [ 'id', 'intercept_status' ],
|
||||
raw: true,
|
||||
});
|
||||
|
||||
@ -554,7 +611,18 @@ class OrderExpressService extends Service {
|
||||
throw this.createBusinessError('波次下未找到订单', 404);
|
||||
}
|
||||
|
||||
const orderIds = waveOrders.map(o => Number(o.id));
|
||||
// 波次内拦截订单不参与批量称重
|
||||
const interceptedWaveOrderIds = (Array.isArray(waveOrders) ? waveOrders : [])
|
||||
.filter(o => isInterceptedOrderStatus(o && o.intercept_status))
|
||||
.map(o => Number(o.id));
|
||||
const orderIds = (Array.isArray(waveOrders) ? waveOrders : [])
|
||||
.filter(o => !isInterceptedOrderStatus(o && o.intercept_status))
|
||||
.map(o => Number(o.id));
|
||||
if (interceptedWaveOrderIds.length > 0) {
|
||||
this.ctx.logger.info(
|
||||
`[order_express._updateWaveAllOrdersWeight] 波次内拦截订单不参与称重: ${interceptedWaveOrderIds.join(',')}`
|
||||
);
|
||||
}
|
||||
|
||||
// 批量更新波次下全部运单的称重重量
|
||||
const orderExpressModel = this.ctx.model && this.ctx.model.OrderExpress;
|
||||
@ -880,7 +948,7 @@ class OrderExpressService extends Service {
|
||||
// 查询波次下所有订单
|
||||
const waveOrders = await orderDeliveryModel.findAll({
|
||||
where: { wave_id: waveId, warehouse_id: warehouseId },
|
||||
attributes: [ 'id' ],
|
||||
attributes: [ 'id', 'intercept_status' ],
|
||||
raw: true,
|
||||
});
|
||||
|
||||
@ -888,7 +956,18 @@ class OrderExpressService extends Service {
|
||||
throw this.createBusinessError('波次下未找到订单', 404);
|
||||
}
|
||||
|
||||
const orderIds = waveOrders.map(o => Number(o.id));
|
||||
// 波次内拦截订单不参与批量称重
|
||||
const interceptedWaveOrderIds = (Array.isArray(waveOrders) ? waveOrders : [])
|
||||
.filter(o => isInterceptedOrderStatus(o && o.intercept_status))
|
||||
.map(o => Number(o.id));
|
||||
const orderIds = (Array.isArray(waveOrders) ? waveOrders : [])
|
||||
.filter(o => !isInterceptedOrderStatus(o && o.intercept_status))
|
||||
.map(o => Number(o.id));
|
||||
if (interceptedWaveOrderIds.length > 0) {
|
||||
this.ctx.logger.info(
|
||||
`[order_express._updateWaveOrderWeight] 波次内拦截订单不参与称重: ${interceptedWaveOrderIds.join(',')}`
|
||||
);
|
||||
}
|
||||
const totalCount = orderIds.length;
|
||||
|
||||
// 批量更新所有订单的运单称重重量
|
||||
@ -1295,6 +1374,9 @@ class OrderExpressService extends Service {
|
||||
const materialRow = await this.findActivePackageMaterialByCode(normalizedPackageMaterialCode, warehouseId);
|
||||
const orderExpressRow = await this.findValidOrderExpressByOrderAndWaybill(normalizedOrderId, normalizedWaybillCode, warehouseId);
|
||||
|
||||
// 拦截流程中的订单不允许绑定包材
|
||||
await this.assertOrderNotIntercepted(Number(orderExpressRow.order_id), warehouseId, '绑定包材');
|
||||
|
||||
const orderExpressModel = this.ctx.model && this.ctx.model.OrderExpress;
|
||||
const updateResult = await orderExpressModel.update({
|
||||
package_material_id: Number(materialRow.id),
|
||||
@ -1383,6 +1465,9 @@ class OrderExpressService extends Service {
|
||||
throw this.createBusinessError('运单号不存在', 404);
|
||||
}
|
||||
|
||||
// 拦截流程中的订单不允许绑定包材
|
||||
await this.assertOrderNotIntercepted(Number(orderExpressRow.order_id), warehouseId, '绑定包材');
|
||||
|
||||
// 查询启用中的包材
|
||||
const materialRow = await this.findActivePackageMaterialById(normalizedPackageMaterialId, warehouseId);
|
||||
|
||||
@ -1581,21 +1666,35 @@ class OrderExpressService extends Service {
|
||||
];
|
||||
|
||||
const orderIdSet = new Set();
|
||||
const excludedInterceptedOrderIds = [];
|
||||
for (const entry of tableOrders) {
|
||||
try {
|
||||
const model = await entry.getModel();
|
||||
if (!model || typeof model.findAll !== 'function') continue;
|
||||
const rows = await model.findAll({
|
||||
where: { wave_id: waveId, warehouse_id: warehouseId },
|
||||
attributes: [ 'id' ],
|
||||
attributes: [ 'id', 'intercept_status' ],
|
||||
raw: true,
|
||||
});
|
||||
if (Array.isArray(rows)) {
|
||||
rows.forEach(r => orderIdSet.add(Number(r.id)));
|
||||
rows.forEach(r => {
|
||||
const orderId = Number(r.id);
|
||||
if (isInterceptedOrderStatus(r && r.intercept_status)) {
|
||||
excludedInterceptedOrderIds.push(orderId);
|
||||
return;
|
||||
}
|
||||
orderIdSet.add(orderId);
|
||||
});
|
||||
}
|
||||
} catch (_err) { continue; }
|
||||
}
|
||||
|
||||
if (excludedInterceptedOrderIds.length > 0) {
|
||||
this.ctx.logger.info(
|
||||
`[bindExpressPackageMaterialByWaybill] 波次内拦截订单不参与批量绑定: ${excludedInterceptedOrderIds.join(',')}`
|
||||
);
|
||||
}
|
||||
|
||||
if (orderIdSet.size === 0) {
|
||||
throw this.createBusinessError('波次下未找到订单', 404);
|
||||
}
|
||||
|
||||
@ -489,12 +489,15 @@ class OrderPrintSystemService extends OrderBaseService {
|
||||
total_platforms: 0,
|
||||
locked_count: 0,
|
||||
total_locked_orders: 0,
|
||||
intercepted_count: 0,
|
||||
},
|
||||
waveGroups: [],
|
||||
locked_wave_groups: [],
|
||||
wave_ids: [],
|
||||
locked_count: 0,
|
||||
locked_orders: [],
|
||||
intercepted_count: 0,
|
||||
intercepted_orders: [],
|
||||
ext: {
|
||||
missing_wave_ids: normalizedWaveIds,
|
||||
filtered_wave_ids: [],
|
||||
@ -512,8 +515,24 @@ class OrderPrintSystemService extends OrderBaseService {
|
||||
} = this.filterFullyAssignedExpressWaves(hitWaveIds, orderRows);
|
||||
const validWaveIdSet = new Set(validWaveIds);
|
||||
const validOrderRows = orderRows.filter(order => validWaveIdSet.has(Number(order && order.wave_id || 0)));
|
||||
const interceptedOrderRows = validOrderRows.filter(
|
||||
orderRow => this.isInterceptedOrderStatus(orderRow && orderRow.intercept_status)
|
||||
);
|
||||
const lockedOrderRows = validOrderRows.filter(orderRow => this.isOrderLocked(orderRow));
|
||||
const unlockedOrderRows = validOrderRows.filter(orderRow => !this.isOrderLocked(orderRow));
|
||||
const unlockedOrderRows = validOrderRows.filter(
|
||||
orderRow => !this.isOrderLocked(orderRow)
|
||||
&& !this.isInterceptedOrderStatus(orderRow && orderRow.intercept_status)
|
||||
);
|
||||
const interceptedOrders = interceptedOrderRows
|
||||
.map(orderRow => ({
|
||||
order_id: Number(orderRow && orderRow.id || 0),
|
||||
order_no: String(orderRow && (orderRow.delivery_order_code || orderRow.source_order_codes) || '').trim(),
|
||||
wave_id: Number(orderRow && orderRow.wave_id || 0),
|
||||
wave_no: String(orderRow && orderRow.wave_no || '').trim(),
|
||||
intercept_status: String(orderRow && orderRow.intercept_status || '').trim() || 'none',
|
||||
status: 'intercepted',
|
||||
status_text: '已拦截',
|
||||
}));
|
||||
const lockedOrders = lockedOrderRows
|
||||
.map(orderRow => ({
|
||||
order_id: Number(orderRow && orderRow.id || 0),
|
||||
@ -553,12 +572,15 @@ class OrderPrintSystemService extends OrderBaseService {
|
||||
total_platforms: 0,
|
||||
locked_count: lockedOrders.length,
|
||||
total_locked_orders: lockedOrders.length,
|
||||
intercepted_count: interceptedOrders.length,
|
||||
},
|
||||
waveGroups: [],
|
||||
locked_wave_groups: lockedWaveGroups,
|
||||
wave_ids: validWaveIds,
|
||||
locked_count: lockedOrders.length,
|
||||
locked_orders: lockedOrders,
|
||||
intercepted_count: interceptedOrders.length,
|
||||
intercepted_orders: interceptedOrders,
|
||||
ext: {
|
||||
missing_wave_ids: missingWaveIds,
|
||||
filtered_wave_ids: filteredWaveIds,
|
||||
@ -653,12 +675,15 @@ class OrderPrintSystemService extends OrderBaseService {
|
||||
total_platforms: totalPlatforms,
|
||||
locked_count: lockedOrders.length,
|
||||
total_locked_orders: lockedOrders.length,
|
||||
intercepted_count: interceptedOrders.length,
|
||||
},
|
||||
waveGroups,
|
||||
locked_wave_groups: lockedWaveGroups,
|
||||
wave_ids: validWaveIds,
|
||||
locked_count: lockedOrders.length,
|
||||
locked_orders: lockedOrders,
|
||||
intercepted_count: interceptedOrders.length,
|
||||
intercepted_orders: interceptedOrders,
|
||||
ext: {
|
||||
missing_wave_ids: missingWaveIds,
|
||||
filtered_wave_ids: filteredWaveIds,
|
||||
@ -697,9 +722,12 @@ class OrderPrintSystemService extends OrderBaseService {
|
||||
total_waves: 0,
|
||||
total_orders: 0,
|
||||
total_platforms: 0,
|
||||
intercepted_count: 0,
|
||||
},
|
||||
waveGroups: [],
|
||||
wave_ids: [],
|
||||
intercepted_count: 0,
|
||||
intercepted_orders: [],
|
||||
ext: {
|
||||
missing_order_ids: normalizedOrderIds,
|
||||
filtered_order_ids: [],
|
||||
@ -711,13 +739,33 @@ class OrderPrintSystemService extends OrderBaseService {
|
||||
const missingOrderIds = normalizedOrderIds.filter(orderId => !hitOrderIdSet.has(orderId));
|
||||
|
||||
// 订单级过滤:仅保留 post_status === 'fin' 的订单(等价于波次级的快递完全分配检查)
|
||||
const validOrderRows = orderRows.filter(row => String(row && row.post_status || '').trim() === 'fin');
|
||||
const postFinOrderRows = orderRows.filter(row => String(row && row.post_status || '').trim() === 'fin');
|
||||
// 拦截订单从打印清单中剔除
|
||||
const interceptedOrderRows = postFinOrderRows.filter(
|
||||
row => this.isInterceptedOrderStatus(row && row.intercept_status)
|
||||
);
|
||||
const interceptedOrders = interceptedOrderRows.map(row => ({
|
||||
order_id: Number(row && row.id || 0),
|
||||
order_no: String(row && (row.delivery_order_code || row.source_order_codes) || '').trim(),
|
||||
wave_id: Number(row && row.wave_id || 0),
|
||||
wave_no: String(row && row.wave_no || '').trim(),
|
||||
intercept_status: String(row && row.intercept_status || '').trim() || 'none',
|
||||
status: 'intercepted',
|
||||
status_text: '已拦截',
|
||||
}));
|
||||
const validOrderRows = postFinOrderRows.filter(
|
||||
row => !this.isInterceptedOrderStatus(row && row.intercept_status)
|
||||
);
|
||||
const filteredOrderIds = orderRows
|
||||
.filter(row => String(row && row.post_status || '').trim() !== 'fin')
|
||||
.map(row => ({
|
||||
order_id: Number(row && row.id || 0),
|
||||
reason: '快递未完全分配',
|
||||
}));
|
||||
}))
|
||||
.concat(interceptedOrderRows.map(row => ({
|
||||
order_id: Number(row && row.id || 0),
|
||||
reason: '已拦截',
|
||||
})));
|
||||
|
||||
if (validOrderRows.length === 0) {
|
||||
return {
|
||||
@ -725,9 +773,12 @@ class OrderPrintSystemService extends OrderBaseService {
|
||||
total_waves: 0,
|
||||
total_orders: 0,
|
||||
total_platforms: 0,
|
||||
intercepted_count: interceptedOrders.length,
|
||||
},
|
||||
waveGroups: [],
|
||||
wave_ids: [],
|
||||
intercepted_count: interceptedOrders.length,
|
||||
intercepted_orders: interceptedOrders,
|
||||
ext: {
|
||||
missing_order_ids: missingOrderIds,
|
||||
filtered_order_ids: filteredOrderIds,
|
||||
@ -826,9 +877,12 @@ class OrderPrintSystemService extends OrderBaseService {
|
||||
total_waves: waveGroups.length,
|
||||
total_orders: orderPrintList.length,
|
||||
total_platforms: totalPlatforms,
|
||||
intercepted_count: interceptedOrders.length,
|
||||
},
|
||||
waveGroups,
|
||||
wave_ids: validOrderWaveIds,
|
||||
intercepted_count: interceptedOrders.length,
|
||||
intercepted_orders: interceptedOrders,
|
||||
ext: {
|
||||
missing_order_ids: missingOrderIds,
|
||||
filtered_order_ids: filteredOrderIds,
|
||||
@ -881,9 +935,16 @@ class OrderPrintSystemService extends OrderBaseService {
|
||||
const waybillRows = await this.queryWaybillsByCodes(normalizedWaybillCodes, normalizedWarehouseId);
|
||||
if (waybillRows.length === 0) {
|
||||
return {
|
||||
summary: { total_waves: 0, total_orders: 0, total_platforms: 0 },
|
||||
summary: {
|
||||
total_waves: 0,
|
||||
total_orders: 0,
|
||||
total_platforms: 0,
|
||||
intercepted_count: 0,
|
||||
},
|
||||
waveGroups: [],
|
||||
wave_ids: [],
|
||||
intercepted_count: 0,
|
||||
intercepted_orders: [],
|
||||
ext: {
|
||||
missing_waybill_codes: normalizedWaybillCodes,
|
||||
filtered_waybill_codes: [],
|
||||
@ -911,9 +972,16 @@ class OrderPrintSystemService extends OrderBaseService {
|
||||
|
||||
if (validWaybillRows.length === 0) {
|
||||
return {
|
||||
summary: { total_waves: 0, total_orders: 0, total_platforms: 0 },
|
||||
summary: {
|
||||
total_waves: 0,
|
||||
total_orders: 0,
|
||||
total_platforms: 0,
|
||||
intercepted_count: 0,
|
||||
},
|
||||
waveGroups: [],
|
||||
wave_ids: [],
|
||||
intercepted_count: 0,
|
||||
intercepted_orders: [],
|
||||
ext: {
|
||||
missing_waybill_codes: missingWaybillCodes,
|
||||
filtered_waybill_codes: invalidWaybillCodes,
|
||||
@ -921,10 +989,24 @@ class OrderPrintSystemService extends OrderBaseService {
|
||||
};
|
||||
}
|
||||
|
||||
// 3. 过滤 post_status !== 'fin' 的订单
|
||||
// 3. 过滤 post_status !== 'fin' 或进入拦截流程的订单
|
||||
const interceptedOrderRows = orderRows.filter(
|
||||
row => this.isInterceptedOrderStatus(row && row.intercept_status)
|
||||
);
|
||||
const interceptedOrderIdSet = new Set(interceptedOrderRows.map(row => Number(row.id)));
|
||||
const interceptedOrders = interceptedOrderRows.map(row => ({
|
||||
order_id: Number(row && row.id || 0),
|
||||
order_no: String(row && (row.delivery_order_code || row.source_order_codes) || '').trim(),
|
||||
wave_id: Number(row && row.wave_id || 0),
|
||||
wave_no: String(row && row.wave_no || '').trim(),
|
||||
intercept_status: String(row && row.intercept_status || '').trim() || 'none',
|
||||
status: 'intercepted',
|
||||
status_text: '已拦截',
|
||||
}));
|
||||
const validOrderIdSet = new Set(
|
||||
orderRows
|
||||
.filter(row => String(row.post_status || '').trim() === 'fin')
|
||||
.filter(row => String(row.post_status || '').trim() === 'fin'
|
||||
&& !this.isInterceptedOrderStatus(row && row.intercept_status))
|
||||
.map(row => Number(row.id))
|
||||
);
|
||||
const finalWaybillRows = validWaybillRows.filter(row => validOrderIdSet.has(Number(row.order_id)));
|
||||
@ -932,14 +1014,23 @@ class OrderPrintSystemService extends OrderBaseService {
|
||||
.filter(row => !validOrderIdSet.has(Number(row.order_id)))
|
||||
.map(row => ({
|
||||
waybill_code: String(row.waybill_code || '').trim(),
|
||||
reason: '关联订单快递未完全分配',
|
||||
reason: interceptedOrderIdSet.has(Number(row.order_id))
|
||||
? '关联订单已被拦截'
|
||||
: '关联订单快递未完全分配',
|
||||
}));
|
||||
|
||||
if (finalWaybillRows.length === 0) {
|
||||
return {
|
||||
summary: { total_waves: 0, total_orders: 0, total_platforms: 0 },
|
||||
summary: {
|
||||
total_waves: 0,
|
||||
total_orders: 0,
|
||||
total_platforms: 0,
|
||||
intercepted_count: interceptedOrders.length,
|
||||
},
|
||||
waveGroups: [],
|
||||
wave_ids: [],
|
||||
intercepted_count: interceptedOrders.length,
|
||||
intercepted_orders: interceptedOrders,
|
||||
ext: {
|
||||
missing_waybill_codes: missingWaybillCodes,
|
||||
filtered_waybill_codes: [ ...invalidWaybillCodes, ...filteredWaybillCodes ],
|
||||
@ -1079,9 +1170,12 @@ class OrderPrintSystemService extends OrderBaseService {
|
||||
total_waves: waveGroups.length,
|
||||
total_orders: orderPrintList.length,
|
||||
total_platforms: totalPlatforms,
|
||||
intercepted_count: interceptedOrders.length,
|
||||
},
|
||||
waveGroups,
|
||||
wave_ids: validOrderWaveIds,
|
||||
intercepted_count: interceptedOrders.length,
|
||||
intercepted_orders: interceptedOrders,
|
||||
ext: {
|
||||
missing_waybill_codes: missingWaybillCodes,
|
||||
filtered_waybill_codes: [ ...invalidWaybillCodes, ...filteredWaybillCodes ],
|
||||
@ -1681,6 +1775,7 @@ class OrderPrintSystemService extends OrderBaseService {
|
||||
'print_status',
|
||||
'lock_status',
|
||||
'print_lock_status',
|
||||
'intercept_status',
|
||||
'items_count',
|
||||
'items_total',
|
||||
'items_weight',
|
||||
@ -1746,6 +1841,7 @@ class OrderPrintSystemService extends OrderBaseService {
|
||||
'print_status',
|
||||
'lock_status',
|
||||
'print_lock_status',
|
||||
'intercept_status',
|
||||
'items_count',
|
||||
'items_total',
|
||||
'items_weight',
|
||||
|
||||
@ -44,12 +44,12 @@ class OrderReviewService extends OrderBaseService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否为拦截状态。
|
||||
* 判断是否为拦截状态(除 none 外一律视为已拦截)。
|
||||
* @param {string} interceptStatus 拦截状态。
|
||||
* @return {boolean} 是否拦截。
|
||||
*/
|
||||
isInterceptStatus(interceptStatus) {
|
||||
return String(interceptStatus || '').trim() !== 'none';
|
||||
return this.isInterceptedOrderStatus(interceptStatus);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -2,6 +2,8 @@
|
||||
|
||||
const MainService = require('../main');
|
||||
|
||||
const { isInterceptedOrderStatus } = require('../../lib/intercept_guard');
|
||||
|
||||
const STORAGE_STATUS_FIN = 'fin';
|
||||
const STORAGE_STATUS_ERROR = 'error';
|
||||
const ORDER_STATUS_CANCEL = 'cancel';
|
||||
@ -628,6 +630,21 @@ class OrderStorageAllocationService extends MainService {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isInterceptedOrderStatus(orderRow && orderRow.intercept_status)) {
|
||||
skippedOrders.push({
|
||||
order_id: orderId,
|
||||
status: 'skipped',
|
||||
intercept_status: orderRow.intercept_status,
|
||||
skipped_reason: 'intercepted',
|
||||
});
|
||||
writeAllocationTextLog('[OrderStorageAllocationService.allocatePicking] 过滤订单结果', {
|
||||
orderId,
|
||||
interceptStatus: orderRow.intercept_status,
|
||||
skippedReason: 'intercepted',
|
||||
});
|
||||
continue;
|
||||
}
|
||||
|
||||
if (String(orderRow.storage_status || 'none') === STORAGE_STATUS_FIN) {
|
||||
skippedOrders.push({
|
||||
order_id: orderId,
|
||||
|
||||
@ -2,6 +2,8 @@
|
||||
|
||||
const Service = require('egg').Service;
|
||||
|
||||
const { INTERCEPT_STATUS_NONE } = require('../../lib/intercept_guard');
|
||||
|
||||
const REVIEWED_INSPECTION_STATUS = 'fin';
|
||||
const PICK_MODE_VIEW_META_MAP = {
|
||||
1: {
|
||||
@ -1945,6 +1947,35 @@ class PickSystemService extends Service {
|
||||
}
|
||||
}
|
||||
|
||||
// 检查目标订单是否进入拦截流程,拦截订单不允许完成拣货
|
||||
if (targetOrderIds.length > 0) {
|
||||
const interceptCheckModel = await this.getOrderModel(warehouseId);
|
||||
const interceptedOrderRows = await interceptCheckModel.findAll({
|
||||
where: {
|
||||
warehouse_id: warehouseId,
|
||||
id: {
|
||||
[this.app.Sequelize.Op.in]: targetOrderIds,
|
||||
},
|
||||
intercept_status: {
|
||||
[this.app.Sequelize.Op.ne]: INTERCEPT_STATUS_NONE,
|
||||
},
|
||||
},
|
||||
attributes: [ 'id', 'intercept_status' ],
|
||||
raw: true,
|
||||
transaction,
|
||||
});
|
||||
|
||||
if (interceptedOrderRows && interceptedOrderRows.length > 0) {
|
||||
const detailList = interceptedOrderRows.map(
|
||||
orderRow => `订单${orderRow.id}(intercept_status=${orderRow.intercept_status})`
|
||||
).join(';');
|
||||
throw this.createBusinessError(
|
||||
`以下订单已被拦截,无法完成拣货:${detailList}`,
|
||||
400
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// 检查目标订单是否已分配储位(storage_status='fin'),防止订单在波次中被取消储位分配后仍然完成拣货
|
||||
if (targetOrderIds.length > 0) {
|
||||
const orderModel = await this.getOrderModel(warehouseId);
|
||||
|
||||
@ -2,6 +2,8 @@
|
||||
|
||||
const Service = require('egg').Service;
|
||||
|
||||
const { isInterceptedOrderStatus } = require('../../lib/intercept_guard');
|
||||
|
||||
class WorkbenchService extends Service {
|
||||
/**
|
||||
* 查询工作台列表(仓库隔离 + 软删除过滤)
|
||||
@ -474,6 +476,11 @@ class WorkbenchService extends Service {
|
||||
|
||||
if (!orderRow) throw new Error(`未找到发货单 [${deliveryOrderCode}]`);
|
||||
|
||||
// 拦截流程中的订单不允许打包
|
||||
if (isInterceptedOrderStatus(orderRow.intercept_status)) {
|
||||
throw new Error(`订单已被拦截,无法打包 [${deliveryOrderCode}]`);
|
||||
}
|
||||
|
||||
const orderId = orderRow.id;
|
||||
const waveId = orderRow.wave_id || 0;
|
||||
const actualWaveNo = waveNo || orderRow.wave_no || '';
|
||||
@ -617,13 +624,13 @@ class WorkbenchService extends Service {
|
||||
} catch (_err) { continue; }
|
||||
}
|
||||
} else if (waveId > 0) {
|
||||
// 团购:批量更新波次下所有订单
|
||||
// 团购:批量更新波次下所有订单(拦截订单不更新)
|
||||
for (const entry of tableOrders) {
|
||||
try {
|
||||
const model = await entry.getModel();
|
||||
if (!model) continue;
|
||||
const affected = await model.update(orderUpdateData, {
|
||||
where: { wave_id: waveId, warehouse_id: warehouseId },
|
||||
where: { wave_id: waveId, warehouse_id: warehouseId, intercept_status: 'none' },
|
||||
});
|
||||
if (affected[0] > 0) {
|
||||
ctx.logger.info('[Workbench._packOrder] 团购批量更新订单打包状态 waveId=%d pack_status=%s table=%s affected=%d',
|
||||
@ -925,7 +932,7 @@ class WorkbenchService extends Service {
|
||||
if (!model || typeof model.findOne !== 'function') continue;
|
||||
const row = await model.findOne({
|
||||
where: { id: orderId, warehouse_id: warehouseId },
|
||||
attributes: [ 'id', 'wave_id', 'wave_no', 'items_weight' ],
|
||||
attributes: [ 'id', 'wave_id', 'wave_no', 'items_weight', 'intercept_status' ],
|
||||
raw: true,
|
||||
});
|
||||
if (row) {
|
||||
@ -943,6 +950,11 @@ class WorkbenchService extends Service {
|
||||
throw new Error(`未找到运单对应的订单 [id=${orderId}, warehouse=${warehouseId}]`);
|
||||
}
|
||||
|
||||
// 拦截流程中的订单不允许称重
|
||||
if (isInterceptedOrderStatus(orderRow.intercept_status)) {
|
||||
throw new Error(`订单已被拦截,无法称重 [${normalizedBarcode}]`);
|
||||
}
|
||||
|
||||
const waveId = Number(orderRow.wave_id || 0);
|
||||
|
||||
// 步骤3:散单(wave_id=0)→ 仅更新该运单的称重重量
|
||||
@ -1014,7 +1026,7 @@ class WorkbenchService extends Service {
|
||||
const { Op } = ctx.app.Sequelize;
|
||||
const waveOrders = await orderDeliveryModel.findAll({
|
||||
where: { wave_id: waveId, warehouse_id: warehouseId },
|
||||
attributes: [ 'id' ],
|
||||
attributes: [ 'id', 'intercept_status' ],
|
||||
raw: true,
|
||||
});
|
||||
|
||||
@ -1022,7 +1034,17 @@ class WorkbenchService extends Service {
|
||||
throw new Error('波次下未找到订单');
|
||||
}
|
||||
|
||||
const orderIds = waveOrders.map(o => Number(o.id));
|
||||
// 波次内拦截订单不参与批量称重
|
||||
const interceptedWaveOrderIds = (Array.isArray(waveOrders) ? waveOrders : [])
|
||||
.filter(o => isInterceptedOrderStatus(o && o.intercept_status))
|
||||
.map(o => Number(o.id));
|
||||
const orderIds = (Array.isArray(waveOrders) ? waveOrders : [])
|
||||
.filter(o => !isInterceptedOrderStatus(o && o.intercept_status))
|
||||
.map(o => Number(o.id));
|
||||
if (interceptedWaveOrderIds.length > 0) {
|
||||
ctx.logger.info('[Workbench._sendWeight] 波次内拦截订单不参与称重 waveId=%d orderIds=%s',
|
||||
waveId, interceptedWaveOrderIds.join(','));
|
||||
}
|
||||
const totalCount = orderIds.length;
|
||||
|
||||
await ctx.model.OrderExpress.update(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user