feat(wave): 波次抓取不抓取 B2B 订单(is_b2b=Y 排除)
- 所有抓取候选与统计查询统一排除 B2B 订单(口径:is_b2b IS NULL OR is_b2b='N',
NULL 视为非 B2B,兼容存量行):
1) buildFetchWhere(团购/散单结构抓取共用 where)
2) groupOrderFetchList / singleOrderFetchList / fetchableOrderCount 候选列表与统计
3) buildWaveStrategyQuickScanOrderWhere + 扫描遗漏检查(策略扫描池,B2B 不进策略匹配)
4) 散单同结构计数候选
5) 策略候选/统计 SQL 5 块(调试候选、matched_count_filtered、count_total、
next_fetch 预演、同结构取出)o 侧与 src 侧同步加条件
6) singleFetchByIds 显式抓单:B2B 订单计入新增返回字段 excluded_b2b_order_ids
7) createWaveBatchByOrderIdsInTransaction 建波落库 lockRows 尾部兜底再排除
- 验证:临时集成测试 3/3 PASS(buildFetchWhere/buildWaveStrategyQuickScanOrderWhere
含 is_b2b 条件;fetchableOrderCount 真实库执行成功);ESLint 0 error
This commit is contained in:
parent
0ced089599
commit
4223b6882a
@ -986,6 +986,8 @@ class WaveService extends OrderBaseService {
|
||||
intercept_status: 'none',
|
||||
lock_status: 'none',
|
||||
wave_id: 0,
|
||||
// 波次抓取不抓取 B2B 订单(NULL 视为非 B2B,兼容存量行)
|
||||
is_b2b: { [Op.or]: [{ [Op.is]: null }, 'N' ] },
|
||||
};
|
||||
|
||||
const itemPartType = String(structure.item_part_type || '').trim();
|
||||
@ -2913,6 +2915,8 @@ class WaveService extends OrderBaseService {
|
||||
intercept_status: 'none',
|
||||
lock_status: 'none',
|
||||
wave_id: 0,
|
||||
// 波次抓取不抓取 B2B 订单(NULL 视为非 B2B,兼容存量行)
|
||||
is_b2b: { [Op.or]: [{ [Op.is]: null }, 'N' ] },
|
||||
};
|
||||
|
||||
if (storeId > 0) {
|
||||
@ -3167,6 +3171,8 @@ class WaveService extends OrderBaseService {
|
||||
intercept_status: 'none',
|
||||
lock_status: 'none',
|
||||
wave_id: 0,
|
||||
// 波次抓取不抓取 B2B 订单(NULL 视为非 B2B,兼容存量行)
|
||||
is_b2b: { [Op.or]: [{ [Op.is]: null }, 'N' ] },
|
||||
};
|
||||
|
||||
if (storeId > 0) {
|
||||
@ -3431,6 +3437,8 @@ class WaveService extends OrderBaseService {
|
||||
intercept_status: 'none',
|
||||
lock_status: 'none',
|
||||
wave_id: 0,
|
||||
// 波次抓取不抓取 B2B 订单(NULL 视为非 B2B,兼容存量行)
|
||||
is_b2b: { [Op.or]: [{ [Op.is]: null }, 'N' ] },
|
||||
};
|
||||
|
||||
if (storeId > 0) {
|
||||
@ -3734,6 +3742,7 @@ class WaveService extends OrderBaseService {
|
||||
AND o.outbound_status != 'padding'
|
||||
AND o.intercept_status = 'none'
|
||||
AND o.lock_status = 'none'
|
||||
AND (o.is_b2b IS NULL OR o.is_b2b = 'N')
|
||||
WHERE m.warehouse_id = :warehouseId
|
||||
AND m.strategy_id = :strategyId
|
||||
ORDER BY o.id ASC
|
||||
@ -3975,6 +3984,7 @@ class WaveService extends OrderBaseService {
|
||||
AND o.outbound_status != 'padding'
|
||||
AND o.intercept_status = 'none'
|
||||
AND o.lock_status = 'none'
|
||||
AND (o.is_b2b IS NULL OR o.is_b2b = 'N')
|
||||
INNER JOIN (
|
||||
SELECT
|
||||
src.items_hash AS structure_key${groupKeyExtra},
|
||||
@ -3990,6 +4000,7 @@ class WaveService extends OrderBaseService {
|
||||
AND src.outbound_status != 'padding'
|
||||
AND src.intercept_status = 'none'
|
||||
AND src.lock_status = 'none'
|
||||
AND (src.is_b2b IS NULL OR src.is_b2b = 'N')
|
||||
GROUP BY src.items_hash${requireSameExpress ? `, ${expressExpr('src')}` : ''}
|
||||
) same_structure
|
||||
ON same_structure.structure_key = o.items_hash${joinKeyExtra}
|
||||
@ -4077,6 +4088,7 @@ class WaveService extends OrderBaseService {
|
||||
AND o.outbound_status != 'padding'
|
||||
AND o.intercept_status = 'none'
|
||||
AND o.lock_status = 'none'
|
||||
AND (o.is_b2b IS NULL OR o.is_b2b = 'N')
|
||||
INNER JOIN (
|
||||
SELECT
|
||||
src.items_hash AS structure_key${groupKeyExtra},
|
||||
@ -4092,6 +4104,7 @@ class WaveService extends OrderBaseService {
|
||||
AND src.outbound_status != 'padding'
|
||||
AND src.intercept_status = 'none'
|
||||
AND src.lock_status = 'none'
|
||||
AND (src.is_b2b IS NULL OR src.is_b2b = 'N')
|
||||
GROUP BY src.items_hash${requireSameExpress ? `, ${expressExpr('src')}` : ''}
|
||||
) same_structure
|
||||
ON same_structure.structure_key = o.items_hash${joinKeyExtra}
|
||||
@ -6943,6 +6956,8 @@ class WaveService extends OrderBaseService {
|
||||
intercept_status: 'none',
|
||||
lock_status: 'none',
|
||||
print_status: { [Op.ne]: 'fin' },
|
||||
// 波次策略扫描不扫描 B2B 订单(NULL 视为非 B2B,兼容存量行)
|
||||
is_b2b: { [Op.or]: [{ [Op.is]: null }, 'N' ] },
|
||||
};
|
||||
|
||||
if (!forceRescan) {
|
||||
@ -7502,6 +7517,7 @@ class WaveService extends OrderBaseService {
|
||||
intercept_status: 'none',
|
||||
lock_status: 'none',
|
||||
print_status: { [Op.ne]: 'fin' },
|
||||
is_b2b: { [Op.or]: [{ [Op.is]: null }, 'N' ] },
|
||||
[Op.or]: [
|
||||
{ wave_strategy_version: { [Op.ne]: currentVersion } },
|
||||
{ wave_strategy_version: { [Op.is]: null } },
|
||||
@ -8188,6 +8204,8 @@ class WaveService extends OrderBaseService {
|
||||
step: { [Op.in]: [ 1, 2, 3 ] },
|
||||
status: { [Op.ne]: 'cancel' },
|
||||
outbound_status: { [Op.ne]: 'padding' },
|
||||
// 波次抓取不抓取 B2B 订单(NULL 视为非 B2B,兼容存量行)
|
||||
is_b2b: { [Op.or]: [{ [Op.is]: null }, 'N' ] },
|
||||
[Op.or]: candidateWhereList,
|
||||
},
|
||||
raw: true,
|
||||
@ -8276,7 +8294,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', 'intercept_status', 'lock_status' ],
|
||||
attributes: [ 'id', 'wave_id', 'wave_no', 'step', 'status', 'outbound_status', 'items_hash', 'items', 'logistics_name', 'intercept_status', 'lock_status', 'is_b2b' ],
|
||||
where: {
|
||||
id: { [Op.in]: normalizedIds },
|
||||
},
|
||||
@ -8305,6 +8323,12 @@ class WaveService extends OrderBaseService {
|
||||
.map(row => Number(row && row.id || 0))
|
||||
.filter(id => Number.isInteger(id) && id > 0)) ]
|
||||
.sort((a, b) => a - b);
|
||||
// B2B 订单不参与波次抓取(NULL 视为非 B2B,兼容存量行)
|
||||
const excludedB2bOrderIds = [ ...new Set(normalizedOrderRows
|
||||
.filter(row => String(row && row.is_b2b || '').trim() === 'Y')
|
||||
.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);
|
||||
@ -8328,6 +8352,11 @@ class WaveService extends OrderBaseService {
|
||||
return false;
|
||||
}
|
||||
|
||||
// B2B 订单不允许抓取波次
|
||||
if (String(row && row.is_b2b || '').trim() === 'Y') {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
@ -8349,6 +8378,7 @@ class WaveService extends OrderBaseService {
|
||||
excluded_existing_wave_order_ids: excludedExistingWaveOrderIds,
|
||||
excluded_intercepted_order_ids: excludedInterceptedOrderIds,
|
||||
excluded_locked_order_ids: excludedLockedOrderIds,
|
||||
excluded_b2b_order_ids: excludedB2bOrderIds,
|
||||
skipped_order_ids: skippedOrderIds,
|
||||
not_found_order_ids: notFoundOrderIds,
|
||||
});
|
||||
@ -8467,6 +8497,7 @@ class WaveService extends OrderBaseService {
|
||||
excluded_existing_wave_order_ids: excludedExistingWaveOrderIds,
|
||||
excluded_intercepted_order_ids: excludedInterceptedOrderIds,
|
||||
excluded_locked_order_ids: excludedLockedOrderIds,
|
||||
excluded_b2b_order_ids: excludedB2bOrderIds,
|
||||
skipped_order_ids: skippedOrderIds,
|
||||
not_found_order_ids: notFoundOrderIds,
|
||||
});
|
||||
@ -11858,6 +11889,7 @@ class WaveService extends OrderBaseService {
|
||||
AND o.outbound_status != 'padding'
|
||||
AND o.intercept_status = 'none'
|
||||
AND o.lock_status = 'none'
|
||||
AND (o.is_b2b IS NULL OR o.is_b2b = 'N')
|
||||
AND (:createdBefore IS NULL OR o.create_at < :createdBefore)
|
||||
INNER JOIN (
|
||||
SELECT
|
||||
@ -11874,6 +11906,7 @@ class WaveService extends OrderBaseService {
|
||||
AND src.outbound_status != 'padding'
|
||||
AND src.intercept_status = 'none'
|
||||
AND src.lock_status = 'none'
|
||||
AND (src.is_b2b IS NULL OR src.is_b2b = 'N')
|
||||
GROUP BY ${structureExpr('src')}${groupKeyExtra}
|
||||
) same_structure
|
||||
ON same_structure.structure_key = ${structureExpr('o')}${joinKeyExtra}
|
||||
@ -12152,6 +12185,8 @@ class WaveService extends OrderBaseService {
|
||||
step: { [Op.ne]: 0 },
|
||||
status: { [Op.ne]: 'cancel' },
|
||||
outbound_status: { [Op.ne]: 'padding' },
|
||||
// 尾部兜底:候选筛选后再次排除 B2B 订单(NULL 视为非 B2B,兼容存量行)
|
||||
is_b2b: { [Op.or]: [{ [Op.is]: null }, 'N' ] },
|
||||
},
|
||||
raw: true,
|
||||
transaction,
|
||||
@ -12402,6 +12437,7 @@ class WaveService extends OrderBaseService {
|
||||
AND o.outbound_status != 'padding'
|
||||
AND o.intercept_status = 'none'
|
||||
AND o.lock_status = 'none'
|
||||
AND (o.is_b2b IS NULL OR o.is_b2b = 'N')
|
||||
AND ${structureExpr('o')} IN (:structureKeys)${expressCondition}
|
||||
ORDER BY o.id ASC
|
||||
`, {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user