From 724f4a13c6fce922009136c0df193e59a33510e2 Mon Sep 17 00:00:00 2001 From: liufumingren Date: Sun, 13 Sep 2026 15:31:02 +0800 Subject: [PATCH] =?UTF-8?q?feat(packing):=20=E5=A4=8D=E6=A0=B8=E5=88=97?= =?UTF-8?q?=E8=A1=A8=20waybill=5Fcode/wave=5Fno=20=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E6=93=8D=E4=BD=9C=E7=AC=A6=E4=B8=8E=E5=A4=9A=E5=80=BC=E6=95=B0?= =?UTF-8?q?=E7=BB=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - systems/order_packing.js:waybill_code 支持 {operator,value} 且 value 可为字符串数组; operator=contains/like 按 LIKE '%值%' 模糊匹配(可命中 '主体-1-1-' 分片单号), 缺省/eq 保持「完整单号 + 剥离分片后缀主体 + 主体前缀」精确匹配, 不落入 %短串% 模糊分支(保留「不完整短串不得命中订单」的业务约束) - wave_no 支持 eq/in 精确、ne 不等、contains/like 与缺省模糊匹配 - systemMethods/order/packing.js 同步 jsdoc 参数说明 --- app/service/systemMethods/order/packing.js | 3 + app/service/systems/order_packing.js | 91 ++++++++++++++++------ 2 files changed, 70 insertions(+), 24 deletions(-) diff --git a/app/service/systemMethods/order/packing.js b/app/service/systemMethods/order/packing.js index 9819759..ba567cb 100644 --- a/app/service/systemMethods/order/packing.js +++ b/app/service/systemMethods/order/packing.js @@ -34,6 +34,9 @@ class OrderPackingMethodService extends MainService { * order_id(订单ID)、workbench_id(工作台ID)、quickWhere(快捷搜索:波次号直接匹配 + 运单号通过express→order→wave链路解析)、 * start_time(开始打包时间范围,{operator:'between', value:[start,end]})、end_time(结束打包时间范围)、create_time(创建时间范围); * start_time_start / start_time_end 为开始时间范围的兼容旧写法。 + * 运单号与波次号字段支持 {operator, value} 标准结构且 value 支持数组: + * operator=contains/like 时按 LIKE '%值%' 模糊匹配(waybill_code 可命中 '主体-1-1-' 等分段单号),wave_no 另支持 eq/in 精确、ne 不等; + * waybill_code 缺省/eq 时为「完整单号等值 + 剥离分段后缀主体等值 + 主体前缀」精确匹配。 * @param {Object} [data.sort] 排序参数 { sortField, sortOrder } * @return {Promise} 统一成功包装响应 */ diff --git a/app/service/systems/order_packing.js b/app/service/systems/order_packing.js index 399f4b5..76b9da2 100644 --- a/app/service/systems/order_packing.js +++ b/app/service/systems/order_packing.js @@ -104,28 +104,49 @@ class OrderPackingService extends Service { } } - // 运单号筛选:通过 wms_order_express 表解析 order_id,再按 order_id 过滤(wms_pack_task.waybill_code 通常为空) - // 业务规则:先剥离一单多件包裹序号后缀(如 -1-1-),剩余主体运单号必须等值匹配,不得落入模糊 like 分支 + // 运单号筛选:通过 wms_order_express 表解析 order_id,再按 order_id 过滤(wms_pack_task.waybill_code 通常为空)。 + // 支持 {operator,value} 标准结构,value 支持字符串或字符串数组(多单号取并集): + // - operator=contains/like:按下发单号模糊匹配 LIKE '%单号%'(通配符已转义),可命中 '主体-1-1-' 等分段单号; + // - 其他(缺省/eq):完整单号等值 + 剥离 -1-1- 分段后缀主体等值 + 主体前缀 LIKE '主体-%', + // 不落入 %短串% 模糊分支(保持「不完整短串不得命中订单」的业务约束)。 if (where.waybill_code) { const waybillValue = where.waybill_code?.value ?? where.waybill_code; - if (waybillValue && String(waybillValue).trim()) { - const trimmedValue = String(waybillValue).trim(); - // 剥离分段后缀得到主体运单号(JDX057941864338-1-1- → JDX057941864338) - const baseWaybill = stripWaybillSegmentSuffix(trimmedValue); - const escapedBase = escapeLikeWildcards(baseWaybill); - // 等值匹配集合:完整单号等值 + 主体单号等值 + 主体单号前缀段(主体相同、分段序号不同) - const waybillConditions = [ - { waybill_code: trimmedValue }, - ...(baseWaybill !== trimmedValue ? [{ waybill_code: baseWaybill }] : []), - ...(escapedBase ? [{ waybill_code: { [Op.like]: `${escapedBase}-%` } }] : []), - ]; - const expressWhere = { - warehouse_id: warehouseId, - delete_at: null, - [Op.or]: waybillConditions, - }; + const waybillOperator = String(where.waybill_code?.operator || '').trim().toLowerCase(); + const waybillList = (Array.isArray(waybillValue) ? waybillValue : [ waybillValue ]) + .map(item => (item === undefined || item === null ? '' : String(item).trim())) + .filter(Boolean); + + if (waybillList.length > 0) { + const isContainsWaybill = waybillOperator === 'contains' || waybillOperator === 'like'; + const waybillConditions = []; + + for (const waybillCode of waybillList) { + if (isContainsWaybill) { + waybillConditions.push({ + waybill_code: { [Op.like]: `%${escapeLikeWildcards(waybillCode)}%` }, + }); + continue; + } + + // 剥离分段后缀得到主体运单号(JDX057941864338-1-1- → JDX057941864338) + const baseWaybill = stripWaybillSegmentSuffix(waybillCode); + const escapedBase = escapeLikeWildcards(baseWaybill); + // 等值匹配集合:完整单号等值 + 主体单号等值 + 主体单号前缀段(主体相同、分段序号不同) + waybillConditions.push({ waybill_code: waybillCode }); + if (baseWaybill !== waybillCode) { + waybillConditions.push({ waybill_code: baseWaybill }); + } + if (escapedBase) { + waybillConditions.push({ waybill_code: { [Op.like]: `${escapedBase}-%` } }); + } + } + const expressRecords = await ctx.model.OrderExpress.findAll({ - where: expressWhere, + where: { + warehouse_id: warehouseId, + delete_at: null, + [Op.or]: waybillConditions, + }, attributes: [ 'order_id' ], raw: true, }); @@ -139,11 +160,32 @@ class OrderPackingService extends Service { } } - // 波次号模糊匹配 + // 波次号筛选:支持 {operator,value} 标准结构,value 支持字符串或字符串数组(多值取并集)。 + // - operator=eq / in:精确匹配(单值等值,多值 Op.in); + // - operator=ne:不等于; + // - operator=contains / like 与缺省:模糊匹配 LIKE '%值%'(通配符已转义,缺省保持历史模糊行为)。 if (where.wave_no) { const waveNoValue = where.wave_no?.value ?? where.wave_no; - if (waveNoValue && String(waveNoValue).trim()) { - queryWhere.wave_no = { [Op.like]: `%${String(waveNoValue).trim()}%` }; + const waveNoOperator = String(where.wave_no?.operator || '').trim().toLowerCase(); + const waveNoList = (Array.isArray(waveNoValue) ? waveNoValue : [ waveNoValue ]) + .map(item => (item === undefined || item === null ? '' : String(item).trim())) + .filter(Boolean); + + if (waveNoList.length > 0) { + if (waveNoOperator === 'eq' || waveNoOperator === 'in') { + queryWhere.wave_no = waveNoList.length === 1 ? waveNoList[0] : { [Op.in]: waveNoList }; + } else if (waveNoOperator === 'ne') { + queryWhere.wave_no = { [Op.ne]: waveNoList[0] }; + } else if (waveNoList.length === 1) { + queryWhere.wave_no = { [Op.like]: `%${escapeLikeWildcards(waveNoList[0])}%` }; + } else { + const likeConditions = waveNoList.map( + item => ({ wave_no: { [Op.like]: `%${escapeLikeWildcards(item)}%` } }) + ); + queryWhere[Op.and] = [ ...(queryWhere[Op.and] || []), + { [Op.or]: likeConditions }, + ]; + } } } @@ -397,8 +439,9 @@ class OrderPackingService extends Service { * @param {Object} where 筛选条件对象 * @param {Object} [where.status] 任务状态:0=待处理 1=打包中 2=已完成 3=异常 * @param {Object} [where.pack_mode] 打包模式:1=散单 2=团购 - * @param {Object} [where.waybill_code] 运单号(通过 wms_order_express 解析 order_id 后过滤;先剥离一单多件分段后缀,主体运单号等值匹配) - * @param {Object} [where.wave_no] 波次号(模糊匹配) + * @param {Object} [where.waybill_code] 运单号(通过 wms_order_express 解析 order_id 后过滤)。支持 {operator,value} 标准结构,value 支持字符串或数组: + * operator=contains/like 时按 LIKE '%单号%' 模糊匹配(可命中分段单号);缺省/eq 时先剥离一单多件分段后缀、主体单号等值匹配 + 主体前缀匹配 + * @param {Object} [where.wave_no] 波次号。支持 {operator,value} 标准结构,value 支持字符串或数组:eq/in 精确、ne 不等、contains/like 与缺省为模糊匹配 * @param {Object} [where.order_id] 订单ID(精确匹配) * @param {Object} [where.workbench_id] 工作台ID(精确匹配) * @param {Object} [where.quickWhere] 快捷搜索:支持波次号模糊匹配;运单号通过 express→order→wave 链路解析(团购按波次号查、散单按订单ID查;运单号先剥离分段后缀等值匹配,精确未命中且关键词长度≥4 时才降级模糊,短词禁止降级避免误命中)