'use strict'; const OrderBaseService = require('./base'); class OrderPrintService extends OrderBaseService { /** * 初始化订单打印模块的免登录、免权限、免日志和免鉴权配置。 * * @param {Egg.Context} ctx 请求上下文。 */ constructor(ctx) { super(ctx); const _noNeedLogin = ''; 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 层实现。 * * @param {Object} data 请求体。 * @param {Array} data.wave_ids 波次ID数组。 * @param {number|string} data.warehouse_id 仓库ID。 * @return {Promise} 统一 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} data.order_ids 订单ID数组。 * @return {Promise} 统一 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} data.waybill_codes 运单号数组。 * @return {Promise} 统一 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} 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} data.groups 分组条件列表。 * @return {Promise} 统一 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;