liufumingren abf2c4d94a 1
2026-05-29 16:47:38 +08:00

154 lines
5.1 KiB
JavaScript

'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';
const _noNeedLog = 'getWavePrintData,getWavePlatformPrintData,unlockWavePlatformPrintDataByGroup';
const _noNeedAuth = 'getWavePrintData,getWavePlatformPrintData,unlockWavePlatformPrintDataByGroup';
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,
});
}
/**
* 按分组解锁波次平台打印锁。
*
* 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;