From 59bd1128931bd690e13e66d85675e465449fbe8d Mon Sep 17 00:00:00 2001 From: liufumingren Date: Sun, 2 Aug 2026 17:15:12 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E7=A7=BB=E9=99=A4=20order.print.ge?= =?UTF-8?q?tWavePrintData=20=E6=8E=A5=E5=8F=A3=EF=BC=88=E5=B7=B2=E8=A2=AB?= =?UTF-8?q?=20getWavePlatformPrintData=20=E6=9B=BF=E4=BB=A3=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/service/systemMethods/order/print.js | 43 +--- app/service/systems/order_print.js | 176 ---------------- methods/changes/system.json | 12 -- methods/system.json | 245 ----------------------- 4 files changed, 3 insertions(+), 473 deletions(-) diff --git a/app/service/systemMethods/order/print.js b/app/service/systemMethods/order/print.js index 952ff73..4c34b93 100644 --- a/app/service/systemMethods/order/print.js +++ b/app/service/systemMethods/order/print.js @@ -11,49 +11,12 @@ class OrderPrintService extends OrderBaseService { constructor(ctx) { super(ctx); const _noNeedLogin = ''; - const _noNeedRight = 'getWavePrintData,getWavePlatformPrintData,unlockWavePlatformPrintDataByGroup,getOrderPrintData,getPrintDataByWaybillCodes'; - const _noNeedLog = 'getWavePrintData,unlockWavePlatformPrintDataByGroup,getOrderPrintData,getPrintDataByWaybillCodes'; - const _noNeedAuth = 'getWavePrintData,getWavePlatformPrintData,unlockWavePlatformPrintDataByGroup,getOrderPrintData,getPrintDataByWaybillCodes'; + const _noNeedRight = 'getWavePlatformPrintData,unlockWavePlatformPrintDataByGroup,getOrderPrintData,getPrintDataByWaybillCodes'; + const _noNeedLog = 'unlockWavePlatformPrintDataByGroup,getOrderPrintData,getPrintDataByWaybillCodes'; + const _noNeedAuth = 'getWavePlatformPrintData,unlockWavePlatformPrintDataByGroup,getOrderPrintData,getPrintDataByWaybillCodes'; this.systemInit(_noNeedLogin, _noNeedRight, _noNeedLog, _noNeedAuth); } - /** - * 获取波次打印数据。 - * - * method 层仅负责参数解构与边界校验,具体业务查询由 systems 层实现。 - * 返回结果中的 ext 会同时包含 missing_wave_ids 与 filtered_wave_ids。 - * - * @param {Object} data 请求体。 - * @param {Array} data.wave_ids 波次ID数组。 - * @param {number|string} data.warehouse_id 仓库ID。 - * @return {Promise} 统一 success 包装的打印数据结果。 - */ - async getWavePrintData(data = {}) { - const requestData = this.isPlainObject(data) ? data : {}; - const { - wave_ids: waveIds, - warehouse_id: warehouseId, - } = requestData; - - if (!Array.isArray(waveIds) || waveIds.length === 0) { - throw new Error('wave_ids 必填,且必须为非空数组'); - } - - if (warehouseId === undefined || warehouseId === null || String(warehouseId).trim() === '') { - throw new Error('warehouse_id 必填'); - } - - const result = await this.service.systems.orderPrint.getWavePrintData({ - waveIds, - warehouseId, - }); - - return this.success('ok', { - data: result, - code: 200, - }); - } - /** * 获取波次平台打印中间态数据。 * diff --git a/app/service/systems/order_print.js b/app/service/systems/order_print.js index 86d833a..4ae1b69 100644 --- a/app/service/systems/order_print.js +++ b/app/service/systems/order_print.js @@ -456,50 +456,6 @@ class OrderPrintSystemService extends OrderBaseService { return {}; } - /** - * 获取波次打印数据。 - * - * @param {Object} params 请求参数。 - * @param {Array} params.waveIds 波次ID数组。 - * @param {number|string} params.warehouseId 仓库ID。 - * @return {Promise} 通用打印数据结构。 - */ - async getWavePrintData(params = {}) { - const requestParams = this.isPlainObject(params) ? params : {}; - const { - waveIds, - warehouseId, - } = requestParams; - - const normalizedWaveIds = this.normalizeWaveIds(waveIds); - if (normalizedWaveIds.length === 0) { - throw new Error('wave_ids 必填,且必须为非空数组'); - } - - const normalizedWarehouseId = this.resolveWarehouseId(warehouseId); - const waveRows = await this.queryWavesByIds(normalizedWarehouseId, normalizedWaveIds); - if (waveRows.length === 0) { - return this.buildEmptyResult(normalizedWaveIds); - } - - const hitWaveIdSet = new Set(waveRows.map(row => Number(row.wave_id))); - const missingWaveIds = normalizedWaveIds.filter(waveId => !hitWaveIdSet.has(waveId)); - const hitWaveIds = normalizedWaveIds.filter(waveId => hitWaveIdSet.has(waveId)); - const orderRows = await this.queryOrdersByWaveIds(hitWaveIds, normalizedWarehouseId); - const { - validWaveIds, - filteredWaveIds, - } = this.filterFullyAssignedExpressWaves(hitWaveIds, orderRows); - - return this.buildWavePrintResult({ - waveRows, - orderRows, - hitWaveIds: validWaveIds, - missingWaveIds, - filteredWaveIds, - }); - } - /** * 获取波次平台打印数据中间态。 * @@ -3324,138 +3280,6 @@ ${waveFilterSql} }; } - /** - * 生成空结果结构。 - * - * @param {Array} normalizedWaveIds 规范化后的波次ID数组。 - * @return {Object} 空结果。 - */ - buildEmptyResult(normalizedWaveIds = []) { - return { - summary: { - total_waves: 0, - total_orders: 0, - }, - wave_list: [], - ext: { - missing_wave_ids: normalizedWaveIds, - filtered_wave_ids: [], - }, - }; - } - - /** - * 组装通用波次打印返回结构。 - * - * @param {Object} payload 聚合输入。 - * @param {Array} payload.waveRows 波次列表。 - * @param {Array} payload.orderRows 订单列表。 - * @param {Array} payload.hitWaveIds 命中的波次ID数组。 - * @param {Array} payload.missingWaveIds 未命中的波次ID数组。 - * @param {Array} payload.filteredWaveIds 被过滤的波次及原因。 - * @return {Object} 波次打印返回结果。 - */ - buildWavePrintResult(payload = {}) { - const { - waveRows = [], - orderRows = [], - hitWaveIds = [], - missingWaveIds = [], - filteredWaveIds = [], - } = this.isPlainObject(payload) ? payload : {}; - - const waveMetaMap = new Map(); - for (const row of waveRows) { - const waveId = Number(row && row.wave_id || 0); - if (!Number.isInteger(waveId) || waveId <= 0) { - continue; - } - - waveMetaMap.set(waveId, { - wave_id: waveId, - wave_no: String(row && row.wave_no || '').trim(), - }); - } - - const groupedWaveMap = new Map(); - for (const waveId of hitWaveIds) { - const waveMeta = waveMetaMap.get(waveId); - if (!waveMeta) { - continue; - } - - groupedWaveMap.set(waveId, { - wave_id: waveMeta.wave_id, - wave_no: waveMeta.wave_no, - order_count: 0, - orders: [], - }); - } - - for (const order of orderRows) { - const waveId = Number(order && order.wave_id || 0); - const groupedWave = groupedWaveMap.get(waveId); - if (!groupedWave) { - continue; - } - - groupedWave.orders.push({ - order_id: Number(order && order.id || 0), - order_no: String(order && (order.delivery_order_code || order.source_order_codes) || '').trim(), - wave_id: waveId, - wave_no: String(order && order.wave_no || '').trim() || groupedWave.wave_no, - receiver: { - name: String(order && order.name || '').trim(), - mobile: String(order && order.mobile || '').trim(), - tel: String(order && order.tel || '').trim(), - province: String(order && order.province || '').trim(), - city: String(order && order.city || '').trim(), - area: String(order && order.area || '').trim(), - town: String(order && order.town || '').trim(), - detail_address: String(order && order.detail_address || '').trim(), - }, - channel: { - sys_platform_code: String(order && order.sys_platform_code || '').trim(), - sys_platform_name: String(order && order.sys_platform_name || '').trim(), - logistics_name: String(order && order.logistics_name || '').trim(), - }, - status: { - order_status: String(order && order.status || '').trim(), - outbound_status: String(order && order.outbound_status || '').trim(), - print_status: String(order && order.print_status || '').trim(), - }, - metrics: { - items_count: Number(order && order.items_count || 0), - items_total: Number(order && order.items_total || 0), - items_weight: Number(order && order.items_weight || 0), - }, - times: { - create_at: order && order.create_at || null, - pay_time: order && order.pay_time || null, - }, - }); - } - - const waveList = Array.from(groupedWaveMap.values()); - waveList.sort((a, b) => String(a.wave_no || '').localeCompare(String(b.wave_no || ''))); - let totalOrders = 0; - for (const wave of waveList) { - wave.order_count = wave.orders.length; - totalOrders += wave.order_count; - } - - return { - summary: { - total_waves: waveList.length, - total_orders: totalOrders, - }, - wave_list: waveList, - ext: { - missing_wave_ids: missingWaveIds, - filtered_wave_ids: filteredWaveIds, - }, - }; - } } module.exports = OrderPrintSystemService; diff --git a/methods/changes/system.json b/methods/changes/system.json index 495587d..e2f76a4 100644 --- a/methods/changes/system.json +++ b/methods/changes/system.json @@ -970,18 +970,6 @@ ], "type": "modified" }, - { - "version": "2026.05.04-system-03", - "date": "2026-05-04", - "summary": "新增订单打印模块:按波次IDs获取打印数据并自动过滤未完全分配波次", - "methods": [ - "order.print.getWavePrintData" - ], - "notes": [ - "按波次IDs获取订单打印数据,内部去重并规范化 wave_ids,自动过滤快递未完全分配的波次;返回通过过滤的波次订单明细,按 wave_no 排序分组,并在 ext 中返回 missing_wave_ids 与 filtered_wave_ids。" - ], - "type": "added" - }, { "version": "2026.05.04-system-02", "date": "2026-05-04", diff --git a/methods/system.json b/methods/system.json index 78e4c99..62dc192 100644 --- a/methods/system.json +++ b/methods/system.json @@ -11055,251 +11055,6 @@ "groupName": "打印模块", "module": "order.print", "list": [ - { - "method": "order.print.getWavePrintData", - "description": "按波次 IDs 获取订单打印数据,自动过滤快递未完全分配的波次,返回通过过滤的波次订单明细,按波次号分组", - "isNeedAuth": false, - "isNeedLogin": true, - "headers": [ - { - "name": "Authorization", - "type": "string", - "required": true, - "description": "Bearer token" - } - ], - "params": [ - { - "name": "warehouse_id", - "type": "number", - "required": true, - "source": "body", - "description": "仓库ID" - }, - { - "name": "wave_ids", - "type": "array", - "required": true, - "source": "body", - "description": "波次ID列表(支持数字或字符串,内部自动去重与归一化)" - } - ], - "response": [ - { - "name": "summary", - "type": "object", - "description": "汇总信息", - "children": [ - { - "name": "total_waves", - "type": "number", - "description": "通过过滤的波次总数" - }, - { - "name": "total_orders", - "type": "number", - "description": "通过过滤的波次下订单总数" - } - ] - }, - { - "name": "wave_list", - "type": "array", - "description": "波次列表(按 wave_no 排序)", - "children": [ - { - "name": "wave_id", - "type": "number", - "description": "波次ID" - }, - { - "name": "wave_no", - "type": "string", - "description": "波次号" - }, - { - "name": "order_count", - "type": "number", - "description": "该波次订单数" - }, - { - "name": "orders", - "type": "array", - "description": "订单明细列表(含 order_id、order_no、收件信息等字段)", - "children": [ - { - "name": "order_id", - "type": "number", - "description": "订单ID" - }, - { - "name": "order_no", - "type": "string", - "description": "订单号(delivery_order_code 或 source_order_codes)" - }, - { - "name": "receiver", - "type": "object", - "description": "收件信息", - "children": [ - { - "name": "name", - "type": "string", - "description": "收件人姓名" - }, - { - "name": "mobile", - "type": "string", - "description": "手机号" - }, - { - "name": "tel", - "type": "string", - "description": "电话" - }, - { - "name": "province", - "type": "string", - "description": "省" - }, - { - "name": "city", - "type": "string", - "description": "市" - }, - { - "name": "area", - "type": "string", - "description": "区/县" - }, - { - "name": "town", - "type": "string", - "description": "镇/街道" - }, - { - "name": "detail_address", - "type": "string", - "description": "详细地址" - } - ] - }, - { - "name": "channel", - "type": "object", - "description": "渠道信息", - "children": [ - { - "name": "sys_platform_code", - "type": "string", - "description": "平台编码" - }, - { - "name": "sys_platform_name", - "type": "string", - "description": "平台名称" - }, - { - "name": "logistics_name", - "type": "string", - "description": "快递名称" - } - ] - }, - { - "name": "status", - "type": "object", - "description": "订单状态简要", - "children": [ - { - "name": "order_status", - "type": "string", - "description": "订单状态" - }, - { - "name": "outbound_status", - "type": "string", - "description": "出库状态" - }, - { - "name": "print_status", - "type": "string", - "description": "打印状态" - } - ] - }, - { - "name": "metrics", - "type": "object", - "description": "数量度量", - "children": [ - { - "name": "items_count", - "type": "number", - "description": "商品种类数" - }, - { - "name": "items_total", - "type": "number", - "description": "商品总件数" - }, - { - "name": "items_weight", - "type": "number", - "description": "重量(单位 g)" - } - ] - }, - { - "name": "times", - "type": "object", - "description": "时间字段", - "children": [ - { - "name": "create_at", - "type": "string", - "description": "创建时间" - }, - { - "name": "pay_time", - "type": "string", - "description": "支付时间" - } - ] - } - ] - } - ] - }, - { - "name": "ext", - "type": "object", - "description": "扩展字段", - "children": [ - { - "name": "missing_wave_ids", - "type": "array", - "description": "传入但不存在的 wave_id 列表" - }, - { - "name": "filtered_wave_ids", - "type": "array", - "description": "被过滤掉的波次(快递未完全分配),每项含 wave_id、wave_no、reason" - } - ] - } - ], - "errors": [ - { - "code": "400", - "description": "warehouse_id 或 wave_ids 缺失或格式错误" - }, - { - "code": "500", - "description": "查询失败" - } - ] - }, { "method": "order.print.getWavePlatformPrintData", "description": "按波次 IDs 获取平台打印中间态数据,自动过滤快递未完全分配的波次,返回 waveGroups(波次 -> 平台 -> 订单)结构",