liufumingren 5378fcd137 refactor(print): 打印模块重构
- 新增 systems/order_print.js 订单打印业务层(getPrintDataByWaybillCodes 等)
- print.js 删除 retry 补偿相关代码(normalizeRetrySendPayload/getRetryEligibility)
- order/print.js 新增 getPrintDataByWaybillCodes 方法
- printer_data_builder.js 新增 appendExtraCustomLines + extraCustomLines 参数支持
- polo_api_client.js 添加调试缓存
- 删除 print_retry_compensation 定时任务测试
2026-08-01 03:44:53 +08:00

214 lines
7.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use strict';
const OrderBaseService = require('./base');
class OrderPrintService extends OrderBaseService {
/**
* 初始化订单打印模块的免登录、免权限、免日志和免鉴权配置。
*
* @param {Egg.Context} ctx 请求上下文。
*/
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';
this.systemInit(_noNeedLogin, _noNeedRight, _noNeedLog, _noNeedAuth);
}
/**
* 获取波次打印数据。
*
* method 层仅负责参数解构与边界校验,具体业务查询由 systems 层实现。
* 返回结果中的 ext 会同时包含 missing_wave_ids 与 filtered_wave_ids。
*
* @param {Object} data 请求体。
* @param {Array<number|string>} data.wave_ids 波次ID数组。
* @param {number|string} data.warehouse_id 仓库ID。
* @return {Promise<Object>} 统一 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,
});
}
/**
* 获取波次平台打印中间态数据。
*
* method 层仅负责参数解构与边界校验,具体业务查询与打印数据组装由 systems 层实现。
*
* @param {Object} data 请求体。
* @param {Array<number|string>} data.wave_ids 波次ID数组。
* @param {number|string} data.warehouse_id 仓库ID。
* @return {Promise<Object>} 统一 success 包装的平台打印中间态结果。
*/
async getWavePlatformPrintData(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.getWavePlatformPrintData({
waveIds,
warehouseId,
});
return this.success('ok', {
data: result,
code: 200,
});
}
/**
* 按订单ID拉取平台打印中间态数据。
*
* method 层仅负责参数解构与边界校验,具体业务查询与打印数据组装由 systems 层实现。
* 仓库ID统一从当前上下文获取,无需调用方传入。
*
* @param {Object} data 请求体。
* @param {Array<number|string>} data.order_ids 订单ID数组。
* @return {Promise<Object>} 统一 success 包装的平台打印中间态结果。
*/
async getOrderPrintData(data = {}) {
const requestData = this.isPlainObject(data) ? data : {};
const {
order_ids: orderIds,
} = requestData;
if (!Array.isArray(orderIds) || orderIds.length === 0) {
throw new Error('order_ids 必填,且必须为非空数组');
}
const result = await this.service.systems.orderPrint.getOrderPrintData({
orderIds,
});
return this.success('ok', {
data: result,
code: 200,
});
}
/**
* 按运单号数组拉取平台打印中间态数据。
*
* method 层仅负责参数解构与边界校验,具体业务查询与打印数据组装由 systems 层实现。
* 仓库ID统一从当前上下文获取,无需调用方传入。
*
* @param {Object} data 请求体。
* @param {Array<string>} data.waybill_codes 运单号数组。
* @return {Promise<Object>} 统一 success 包装的平台打印中间态结果。
*/
async getPrintDataByWaybillCodes(data = {}) {
const requestData = this.isPlainObject(data) ? data : {};
const {
waybill_codes: waybillCodes,
} = requestData;
if (!Array.isArray(waybillCodes) || waybillCodes.length === 0) {
throw new Error('waybill_codes 必填,且必须为非空数组');
}
const result = await this.service.systems.orderPrint.getPrintDataByWaybillCodes({
waybillCodes,
});
return this.success('ok', {
data: result,
code: 200,
});
}
/**
* 按分组解锁波次平台打印锁。
*
* method 层仅负责参数解构与边界校验,具体解锁逻辑由 systems 层实现。
*
* @param {Object} data 请求体。
* @param {Array<number|string>} data.wave_ids 波次ID数组。
* @param {number|string} data.warehouse_id 仓库ID。
* @param {string} [data.group_type='platform_express'] 分组类型,支持 platform、platform_express、order。
* @param {string} [data.unlock_scope='group'] 解锁范围,支持 group、wave。
* @param {Array<Object>} data.groups 分组条件列表。
* @return {Promise<Object>} 统一 success 包装的解锁结果。
*/
async unlockWavePlatformPrintDataByGroup(data = {}) {
const requestData = this.isPlainObject(data) ? data : {};
const {
wave_ids: waveIds,
warehouse_id: warehouseId,
group_type: groupType = 'platform_express',
unlock_scope: unlockScope = 'group',
groups,
} = 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 normalizedGroupType = String(groupType || '').trim();
if (![ 'platform', 'platform_express', 'order' ].includes(normalizedGroupType)) {
throw new Error('group_type 仅支持 platform、platform_express、order');
}
const normalizedUnlockScope = String(unlockScope || '').trim();
if (![ 'group', 'wave' ].includes(normalizedUnlockScope)) {
throw new Error('unlock_scope 仅支持 group、wave');
}
if (!Array.isArray(groups) || groups.length === 0) {
throw new Error('groups 必填,且必须为非空数组');
}
const result = await this.service.systems.orderPrint.unlockWavePlatformPrintDataByGroup({
waveIds,
warehouseId,
groupType: normalizedGroupType,
unlockScope: normalizedUnlockScope,
groups,
});
return this.success('ok', {
data: result,
code: 200,
});
}
}
module.exports = OrderPrintService;