1
This commit is contained in:
parent
9c2b254206
commit
0c3518e65d
1073
app/lib/printer_data_builder.js
Normal file
1073
app/lib/printer_data_builder.js
Normal file
File diff suppressed because it is too large
Load Diff
@ -109,6 +109,11 @@ module.exports = app => {
|
||||
defaultValue: 1,
|
||||
comment: '团购批次最大订单数(相同结构)',
|
||||
},
|
||||
wave_prefix: {
|
||||
type: STRING(5),
|
||||
allowNull: true,
|
||||
comment: '波次前缀(为空时回退仓库前缀)',
|
||||
},
|
||||
allowed_owners: {
|
||||
type: JSON,
|
||||
allowNull: true,
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = app => {
|
||||
const { INTEGER, BIGINT, STRING } = app.Sequelize;
|
||||
const { INTEGER, BIGINT, STRING, DATE } = app.Sequelize;
|
||||
|
||||
const PrintComputer = app.model.define('print_computer', {
|
||||
id: {
|
||||
@ -27,6 +27,11 @@ module.exports = app => {
|
||||
defaultValue: 1,
|
||||
comment: '状态,1-已激活,0-未激活',
|
||||
},
|
||||
last_login_time: {
|
||||
type: DATE,
|
||||
allowNull: true,
|
||||
comment: '上次登录时间',
|
||||
},
|
||||
}, {
|
||||
tableName: 'wms_print_computer',
|
||||
freezeTableName: true,
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
// app/model/print_item.js
|
||||
module.exports = app => {
|
||||
const { STRING, INTEGER, BOOLEAN, JSON, DATE } = app.Sequelize;
|
||||
const SUPPORTED_BUSINESS_TYPES = [ 'STOCK', 'RECEIPT', 'PICKING' ];
|
||||
|
||||
const PrintItem = app.model.define('print_item', {
|
||||
id: {
|
||||
@ -15,6 +16,7 @@ module.exports = app => {
|
||||
comment: '业务类型',
|
||||
validate: {
|
||||
notEmpty: true,
|
||||
isIn: [ SUPPORTED_BUSINESS_TYPES ],
|
||||
},
|
||||
},
|
||||
platform: {
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
|
||||
module.exports = app => {
|
||||
const { BIGINT, STRING, INTEGER, BOOLEAN, JSON, DATE, DATEONLY } = app.Sequelize;
|
||||
const SUPPORTED_BUSINESS_TYPES = [ 'STOCK', 'RECEIPT', 'PICKING' ];
|
||||
|
||||
const PrintTemplate = app.model.define('print_template', {
|
||||
id: {
|
||||
@ -75,6 +76,10 @@ module.exports = app => {
|
||||
type: STRING(10),
|
||||
allowNull: false,
|
||||
comment: '类型',
|
||||
validate: {
|
||||
notEmpty: true,
|
||||
isIn: [ SUPPORTED_BUSINESS_TYPES ],
|
||||
},
|
||||
},
|
||||
delete_at: {
|
||||
type: DATEONLY,
|
||||
|
||||
@ -146,30 +146,13 @@ module.exports = app => {
|
||||
description: '补充说明该货主在仓库内的特殊约束',
|
||||
maxLength: 200,
|
||||
}),
|
||||
Object.freeze({
|
||||
key: 'use_store_sender_info',
|
||||
name: '是否使用货主发货信息',
|
||||
type: 'flag',
|
||||
default: 1,
|
||||
required: false,
|
||||
description: '控制面单分配时是否优先使用货主在当前仓下配置的发件信息',
|
||||
}),
|
||||
Object.freeze({
|
||||
key: 'shop_name',
|
||||
name: '店铺名称',
|
||||
type: 'string',
|
||||
default: '',
|
||||
required: false,
|
||||
description: '货主在当前仓下的店铺名称',
|
||||
maxLength: 100,
|
||||
}),
|
||||
Object.freeze({
|
||||
key: 'sender_name',
|
||||
name: '发件人姓名',
|
||||
type: 'string',
|
||||
default: '',
|
||||
required: false,
|
||||
description: '货主在当前仓下的默认发件人姓名',
|
||||
description: '货主在当前仓下面单的默认发件人姓名',
|
||||
maxLength: 50,
|
||||
}),
|
||||
Object.freeze({
|
||||
@ -178,7 +161,7 @@ module.exports = app => {
|
||||
type: 'string',
|
||||
default: '',
|
||||
required: false,
|
||||
description: '货主在当前仓下的默认发件人联系电话',
|
||||
description: '货主在当前仓下面单的默认发件人联系电话',
|
||||
maxLength: 20,
|
||||
}),
|
||||
Object.freeze({
|
||||
@ -187,7 +170,7 @@ module.exports = app => {
|
||||
type: 'string',
|
||||
default: '',
|
||||
required: false,
|
||||
description: '货主在当前仓下的发件省份',
|
||||
description: '货主在当前仓下面单的发件省份',
|
||||
maxLength: 50,
|
||||
}),
|
||||
Object.freeze({
|
||||
@ -196,7 +179,7 @@ module.exports = app => {
|
||||
type: 'string',
|
||||
default: '',
|
||||
required: false,
|
||||
description: '货主在当前仓下的发件城市',
|
||||
description: '货主在当前仓下面单的发件城市',
|
||||
maxLength: 50,
|
||||
}),
|
||||
Object.freeze({
|
||||
@ -205,7 +188,7 @@ module.exports = app => {
|
||||
type: 'string',
|
||||
default: '',
|
||||
required: false,
|
||||
description: '货主在当前仓下的发件区/县',
|
||||
description: '货主在当前仓下面单的发件区/县',
|
||||
maxLength: 50,
|
||||
}),
|
||||
Object.freeze({
|
||||
@ -214,7 +197,7 @@ module.exports = app => {
|
||||
type: 'string',
|
||||
default: '',
|
||||
required: false,
|
||||
description: '货主在当前仓下的发件镇/街道',
|
||||
description: '货主在当前仓下面单的发件镇/街道',
|
||||
maxLength: 50,
|
||||
}),
|
||||
Object.freeze({
|
||||
@ -223,9 +206,24 @@ module.exports = app => {
|
||||
type: 'string',
|
||||
default: '',
|
||||
required: false,
|
||||
description: '货主在当前仓下的发件详细地址',
|
||||
description: '货主在当前仓下面单的发件详细地址',
|
||||
maxLength: 200,
|
||||
}),
|
||||
Object.freeze({
|
||||
key: 'waybill_custom_display_type',
|
||||
name: '面单自定义显示类型',
|
||||
type: 'enum',
|
||||
default: '1',
|
||||
required: false,
|
||||
description: '控制面单自定义区商品信息展示内容',
|
||||
options: [
|
||||
Object.freeze({ value: '1', label: '隐藏' }),
|
||||
Object.freeze({ value: '2', label: '商品名称和数量' }),
|
||||
Object.freeze({ value: '3', label: '拣货库位和条码和数量' }),
|
||||
Object.freeze({ value: '4', label: '拣货库位和条码后5位和数量' }),
|
||||
Object.freeze({ value: '5', label: '拣货库位商品名称条码和数量' }),
|
||||
],
|
||||
}),
|
||||
]);
|
||||
const POLICY_CONFIG_FIELD_MAP = Object.freeze(POLICY_CONFIG_FIELDS.reduce((result, field) => {
|
||||
result[field.key] = field;
|
||||
|
||||
@ -47,7 +47,7 @@ module.exports = {
|
||||
|
||||
for (const warehouseId of warehouseIds) {
|
||||
try {
|
||||
const submitPayload = await ctx.service.systemMethods.order.wave.submitWaveStrategyQuickScanForWarehouse(warehouseId);
|
||||
const submitPayload = await ctx.service.systemMethods.order.wave.submitWaveStrategyQuickScanForWarehouse(warehouseId, { wait: true });
|
||||
const submitMessage = String(submitPayload && submitPayload.message || '').trim();
|
||||
const submitState = String(submitPayload && submitPayload.state || '').trim();
|
||||
const isReusedRunningTask = submitMessage.includes('已有快速扫描任务在运行中')
|
||||
|
||||
@ -21,6 +21,35 @@ class ArchiveOrderService extends OrderBaseService {
|
||||
async list(data = {}) {
|
||||
return await this.listByModule('archiveOrder', data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询归档订单详情。
|
||||
*
|
||||
* 默认使用 history 表查询;
|
||||
* 若调用方显式传入表位参数,则保持调用方指定值。
|
||||
*
|
||||
* @param {Object} data 请求体。
|
||||
* @return {Promise<Object>} 订单头、商品明细、运单与日志信息。
|
||||
*/
|
||||
async detail(data = {}) {
|
||||
const requestData = this.isPlainObject(data) ? data : {};
|
||||
const tableTypeFields = [ 'tableType', 'tablePosition', 'type', 'moduleName' ];
|
||||
const hasTableTypeInput = tableTypeFields.some(field => {
|
||||
if (!Object.prototype.hasOwnProperty.call(requestData, field)) {
|
||||
return false;
|
||||
}
|
||||
return String(requestData[field] ?? '').trim() !== '';
|
||||
});
|
||||
|
||||
const detailParams = hasTableTypeInput
|
||||
? requestData
|
||||
: {
|
||||
...requestData,
|
||||
tableType: 'history',
|
||||
};
|
||||
|
||||
return await super.detail(detailParams);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ArchiveOrderService;
|
||||
|
||||
@ -21,6 +21,35 @@ class DeliveryExpectionOrderService extends OrderBaseService {
|
||||
return await this.listByModule('deliveryExpectionOrder', data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询配送异常订单详情。
|
||||
*
|
||||
* 默认使用 dispatch 表查询;
|
||||
* 若调用方显式传入表位参数,则保持调用方指定值。
|
||||
*
|
||||
* @param {Object} data 请求体。
|
||||
* @return {Promise<Object>} 订单头、商品明细、运单与日志信息。
|
||||
*/
|
||||
async detail(data = {}) {
|
||||
const requestData = this.isPlainObject(data) ? data : {};
|
||||
const tableTypeFields = [ 'tableType', 'tablePosition', 'type', 'moduleName' ];
|
||||
const hasTableTypeInput = tableTypeFields.some(field => {
|
||||
if (!Object.prototype.hasOwnProperty.call(requestData, field)) {
|
||||
return false;
|
||||
}
|
||||
return String(requestData[field] ?? '').trim() !== '';
|
||||
});
|
||||
|
||||
const detailParams = hasTableTypeInput
|
||||
? requestData
|
||||
: {
|
||||
...requestData,
|
||||
tableType: 'dispatch',
|
||||
};
|
||||
|
||||
return await super.detail(detailParams);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = DeliveryExpectionOrderService;
|
||||
|
||||
@ -21,6 +21,35 @@ class DeliveryOrderService extends OrderBaseService {
|
||||
return await this.listByModule('deliveryOrder', data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询配送订单详情。
|
||||
*
|
||||
* 默认使用 dispatch 表查询;
|
||||
* 若调用方显式传入表位参数,则保持调用方指定值。
|
||||
*
|
||||
* @param {Object} data 请求体。
|
||||
* @return {Promise<Object>} 订单头、商品明细、运单与日志信息。
|
||||
*/
|
||||
async detail(data = {}) {
|
||||
const requestData = this.isPlainObject(data) ? data : {};
|
||||
const tableTypeFields = [ 'tableType', 'tablePosition', 'type', 'moduleName' ];
|
||||
const hasTableTypeInput = tableTypeFields.some(field => {
|
||||
if (!Object.prototype.hasOwnProperty.call(requestData, field)) {
|
||||
return false;
|
||||
}
|
||||
return String(requestData[field] ?? '').trim() !== '';
|
||||
});
|
||||
|
||||
const detailParams = hasTableTypeInput
|
||||
? requestData
|
||||
: {
|
||||
...requestData,
|
||||
tableType: 'dispatch',
|
||||
};
|
||||
|
||||
return await super.detail(detailParams);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = DeliveryOrderService;
|
||||
|
||||
@ -21,6 +21,35 @@ class EntrustOrderService extends OrderBaseService {
|
||||
return await this.listByModule('entrustOrder', data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询委托外仓订单详情。
|
||||
*
|
||||
* 默认使用 outsourced 表查询;
|
||||
* 若调用方显式传入表位参数,则保持调用方指定值。
|
||||
*
|
||||
* @param {Object} data 请求体。
|
||||
* @return {Promise<Object>} 订单头、商品明细、运单与日志信息。
|
||||
*/
|
||||
async detail(data = {}) {
|
||||
const requestData = this.isPlainObject(data) ? data : {};
|
||||
const tableTypeFields = [ 'tableType', 'tablePosition', 'type', 'moduleName' ];
|
||||
const hasTableTypeInput = tableTypeFields.some(field => {
|
||||
if (!Object.prototype.hasOwnProperty.call(requestData, field)) {
|
||||
return false;
|
||||
}
|
||||
return String(requestData[field] ?? '').trim() !== '';
|
||||
});
|
||||
|
||||
const detailParams = hasTableTypeInput
|
||||
? requestData
|
||||
: {
|
||||
...requestData,
|
||||
tableType: 'outsourced',
|
||||
};
|
||||
|
||||
return await super.detail(detailParams);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = EntrustOrderService;
|
||||
|
||||
@ -11,9 +11,9 @@ class OrderPrintService extends OrderBaseService {
|
||||
constructor(ctx) {
|
||||
super(ctx);
|
||||
const _noNeedLogin = '';
|
||||
const _noNeedRight = 'getWavePrintData';
|
||||
const _noNeedLog = 'getWavePrintData';
|
||||
const _noNeedAuth = 'getWavePrintData';
|
||||
const _noNeedRight = 'getWavePrintData,getWavePlatformPrintData';
|
||||
const _noNeedLog = 'getWavePrintData,getWavePlatformPrintData';
|
||||
const _noNeedAuth = 'getWavePrintData,getWavePlatformPrintData';
|
||||
this.systemInit(_noNeedLogin, _noNeedRight, _noNeedLog, _noNeedAuth);
|
||||
}
|
||||
|
||||
@ -53,6 +53,42 @@ class OrderPrintService extends OrderBaseService {
|
||||
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,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = OrderPrintService;
|
||||
|
||||
@ -48,6 +48,41 @@ const WAVE_STRATEGY_FALLBACK_WHERE_FIELD_MAP = Object.freeze({
|
||||
province: 'province',
|
||||
sys_platform_name: 'sys_platform_name',
|
||||
});
|
||||
const BATCH_LIST_ASSIGNMENT_FILTER_SCHEMAS = Object.freeze({
|
||||
storage: Object.freeze({
|
||||
fieldName: 'storage_assignment_status',
|
||||
enumMap: Object.freeze({
|
||||
未分配: 'none',
|
||||
部分分配: 'partial',
|
||||
已分配: 'finished',
|
||||
}),
|
||||
caseInsensitive: false,
|
||||
statsColumnPrefix: 'storage',
|
||||
withErrorStatus: true,
|
||||
}),
|
||||
express: Object.freeze({
|
||||
fieldName: 'express_assignment_status',
|
||||
enumMap: Object.freeze({
|
||||
unassigned: 'none',
|
||||
partially_assigned: 'partial',
|
||||
assigned: 'finished',
|
||||
}),
|
||||
caseInsensitive: true,
|
||||
statsColumnPrefix: 'post',
|
||||
withErrorStatus: true,
|
||||
}),
|
||||
print: Object.freeze({
|
||||
fieldName: 'print_assignment_status',
|
||||
enumMap: Object.freeze({
|
||||
unprinted: 'none',
|
||||
partially_printed: 'partial',
|
||||
printed: 'finished',
|
||||
}),
|
||||
caseInsensitive: true,
|
||||
statsColumnPrefix: 'print',
|
||||
withErrorStatus: false,
|
||||
}),
|
||||
});
|
||||
|
||||
class WaveService extends OrderBaseService {
|
||||
/**
|
||||
@ -58,7 +93,7 @@ class WaveService extends OrderBaseService {
|
||||
constructor(ctx) {
|
||||
super(ctx);
|
||||
const _noNeedLogin = '';
|
||||
const _noNeedRight = 'groupOrderFetchList,singleOrderFetchList,waveStrategyList,waveStrategyFallbackOrderList,waveStrategyFetchPda,waveStrategyFetchAdmin,groupFetch,singleFetch,fetch,fetchTaskProgress,batchList,wavePickTaskList,batchCancel,batchCancelTaskProgress,batchRemoveExceptionOrders,batchRemoveExceptionOrdersTaskProgress,batchAllocateExpress,batchAllocateExpressTaskProgress,batchAllocateStorage,batchAllocateStorageTaskProgress,batchAutoGrouping,batchFinishAutoGrouping,batchRemoveOrders,singleFetchByIds,waveStrategyQuickScan,waveStrategyQuickScanTaskProgress';
|
||||
const _noNeedRight = 'wavePickTaskCancelSelf,groupOrderFetchList,singleOrderFetchList,waveStrategyList,waveStrategyFallbackOrderList,waveStrategyFetchPda,waveStrategyFetchAdmin,groupFetch,singleFetch,fetch,fetchTaskProgress,batchList,wavePickTaskList,batchCancel,batchCancelTaskProgress,batchRemoveExceptionOrders,batchRemoveExceptionOrdersTaskProgress,batchAllocateExpress,batchAllocateExpressTaskProgress,batchAllocateStorage,batchAllocateStorageTaskProgress,batchAutoGrouping,batchFinishAutoGrouping,batchRemoveOrders,singleFetchByIds,waveStrategyQuickScan,waveStrategyQuickScanTaskProgress';
|
||||
const _noNeedLog = 'groupOrderFetchList,singleOrderFetchList,waveStrategyList,waveStrategyFallbackOrderList,waveStrategyFetchPda,waveStrategyFetchAdmin,groupFetch,singleFetch,fetch,fetchTaskProgress,batchList,wavePickTaskList,batchCancel,batchCancelTaskProgress,batchRemoveExceptionOrders,batchRemoveExceptionOrdersTaskProgress,batchAllocateExpress,batchAllocateExpressTaskProgress,batchAllocateStorage,batchAllocateStorageTaskProgress,batchAutoGrouping,batchFinishAutoGrouping,batchRemoveOrders,singleFetchByIds,waveStrategyQuickScan,waveStrategyQuickScanTaskProgress';
|
||||
const _noNeedAuth = 'groupOrderFetchList,singleOrderFetchList,waveStrategyList,waveStrategyFallbackOrderList,waveStrategyFetchPda,waveStrategyFetchAdmin,groupFetch,singleFetch,fetch,fetchTaskProgress,batchList,wavePickTaskList,batchCancel,batchCancelTaskProgress,batchRemoveExceptionOrders,batchRemoveExceptionOrdersTaskProgress,batchAllocateExpress,batchAllocateExpressTaskProgress,batchAllocateStorage,batchAllocateStorageTaskProgress,batchAutoGrouping,batchFinishAutoGrouping,batchRemoveOrders,singleFetchByIds,waveStrategyQuickScan,waveStrategyQuickScanTaskProgress';
|
||||
this.systemInit(_noNeedLogin, _noNeedRight, _noNeedLog, _noNeedAuth);
|
||||
@ -1177,6 +1212,64 @@ class WaveService extends OrderBaseService {
|
||||
* @return {string} 规范化后的筛选值,未传时返回空字符串。
|
||||
*/
|
||||
normalizeBatchListStorageAssignmentStatusFilter(value) {
|
||||
return this.normalizeBatchListAssignmentStatusFilterByType(value, 'storage');
|
||||
}
|
||||
|
||||
/**
|
||||
* 规范化波次列表快递分配状态筛选值(英文枚举)。
|
||||
*
|
||||
* @param {string} value 入参筛选值。
|
||||
* @return {string} 规范化后的筛选值,未传时返回空字符串。
|
||||
*/
|
||||
normalizeBatchListExpressAssignmentStatusFilter(value) {
|
||||
return this.normalizeBatchListAssignmentStatusFilterByType(value, 'express');
|
||||
}
|
||||
|
||||
/**
|
||||
* 规范化波次列表打印状态筛选值(英文枚举)。
|
||||
*
|
||||
* @param {string} value 入参筛选值。
|
||||
* @return {string} 规范化后的筛选值,未传时返回空字符串。
|
||||
*/
|
||||
normalizeBatchListPrintAssignmentStatusFilter(value) {
|
||||
return this.normalizeBatchListAssignmentStatusFilterByType(value, 'print');
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据类型获取波次分配状态筛选配置。
|
||||
*
|
||||
* @param {'storage'|'express'|'print'} type 筛选类型。
|
||||
* @return {{ fieldName: string, enumMap: Object, caseInsensitive: boolean, statsColumnPrefix: string, withErrorStatus: boolean }} 筛选配置。
|
||||
*/
|
||||
getBatchListAssignmentFilterSchema(type) {
|
||||
const normalizedType = String(type || '').trim();
|
||||
const schema = BATCH_LIST_ASSIGNMENT_FILTER_SCHEMAS[normalizedType];
|
||||
if (!schema) {
|
||||
throw new Error(`不支持的分配状态筛选类型: ${normalizedType}`);
|
||||
}
|
||||
return schema;
|
||||
}
|
||||
|
||||
/**
|
||||
* 按类型规范化波次列表分配状态筛选值。
|
||||
*
|
||||
* @param {string} value 入参筛选值。
|
||||
* @param {'storage'|'express'|'print'} type 筛选类型。
|
||||
* @return {string} 规范化后的筛选值,未传时返回空字符串。
|
||||
*/
|
||||
normalizeBatchListAssignmentStatusFilterByType(value, type) {
|
||||
const schema = this.getBatchListAssignmentFilterSchema(type);
|
||||
return this.normalizeBatchListAssignmentStatusFilter(value, schema);
|
||||
}
|
||||
|
||||
/**
|
||||
* 规范化波次列表分配状态筛选值。
|
||||
*
|
||||
* @param {string} value 入参筛选值。
|
||||
* @param {{ fieldName: string, enumMap: Object, caseInsensitive: boolean }} schema 筛选配置。
|
||||
* @return {string} 规范化后的筛选标识(none/partial/finished)。
|
||||
*/
|
||||
normalizeBatchListAssignmentStatusFilter(value, schema) {
|
||||
if (value === undefined || value === null || value === '') {
|
||||
return '';
|
||||
}
|
||||
@ -1186,12 +1279,23 @@ class WaveService extends OrderBaseService {
|
||||
return '';
|
||||
}
|
||||
|
||||
const allowedValues = [ '未分配', '部分分配', '已分配' ];
|
||||
if (!allowedValues.includes(normalizedValue)) {
|
||||
throw new Error(`storage_assignment_status 参数不合法,仅支持: ${allowedValues.join('、')}`);
|
||||
const enumMap = this.isPlainObject(schema && schema.enumMap) ? schema.enumMap : {};
|
||||
const allowedValues = Object.keys(enumMap);
|
||||
const isCaseInsensitive = Boolean(schema && schema.caseInsensitive);
|
||||
const lookupValue = isCaseInsensitive ? normalizedValue.toLowerCase() : normalizedValue;
|
||||
const normalizedEnumMap = isCaseInsensitive
|
||||
? Object.fromEntries(
|
||||
Object.entries(enumMap).map(([ key, mappedValue ]) => [ String(key).toLowerCase(), mappedValue ])
|
||||
)
|
||||
: enumMap;
|
||||
const matchedValue = normalizedEnumMap[lookupValue];
|
||||
|
||||
if (!matchedValue) {
|
||||
const fieldName = String(schema && schema.fieldName || 'assignment_status');
|
||||
throw new Error(`${fieldName} 参数不合法,仅支持: ${allowedValues.join('、')}`);
|
||||
}
|
||||
|
||||
return normalizedValue;
|
||||
return matchedValue;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1235,7 +1339,50 @@ class WaveService extends OrderBaseService {
|
||||
* @return {{ sql: string, replacements: Object }} SQL 条件片段与参数。
|
||||
*/
|
||||
buildBatchListStorageAssignmentFilterClause(statusFilter = '') {
|
||||
const normalizedStatusFilter = this.normalizeBatchListStorageAssignmentStatusFilter(statusFilter);
|
||||
return this.buildBatchListAssignmentStatusFilterClauseByType(statusFilter, 'storage');
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建波次列表快递分配状态筛选 SQL 条件。
|
||||
*
|
||||
* @param {string} statusFilter 快递分配状态筛选值(none/partial/finished)。
|
||||
* @return {{ sql: string, replacements: Object }} SQL 条件片段与参数。
|
||||
*/
|
||||
buildBatchListExpressAssignmentFilterClause(statusFilter = '') {
|
||||
return this.buildBatchListAssignmentStatusFilterClauseByType(statusFilter, 'express');
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建波次列表打印状态筛选 SQL 条件。
|
||||
*
|
||||
* @param {string} statusFilter 打印状态筛选值(none/partial/finished)。
|
||||
* @return {{ sql: string, replacements: Object }} SQL 条件片段与参数。
|
||||
*/
|
||||
buildBatchListPrintAssignmentFilterClause(statusFilter = '') {
|
||||
return this.buildBatchListAssignmentStatusFilterClauseByType(statusFilter, 'print');
|
||||
}
|
||||
|
||||
/**
|
||||
* 按类型构建波次列表分配状态筛选 SQL 条件。
|
||||
*
|
||||
* @param {string} statusFilter 分配状态筛选值(none/partial/finished)。
|
||||
* @param {'storage'|'express'|'print'} type 筛选类型。
|
||||
* @return {{ sql: string, replacements: Object }} SQL 条件片段与参数。
|
||||
*/
|
||||
buildBatchListAssignmentStatusFilterClauseByType(statusFilter = '', type = 'storage') {
|
||||
const schema = this.getBatchListAssignmentFilterSchema(type);
|
||||
return this.buildBatchListAssignmentStatusFilterClause(statusFilter, schema);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建波次列表分配状态筛选 SQL 条件(通用)。
|
||||
*
|
||||
* @param {string} statusFilter 分配状态筛选值(none/partial/finished)。
|
||||
* @param {{ statsColumnPrefix: string, withErrorStatus: boolean }} schema 筛选配置。
|
||||
* @return {{ sql: string, replacements: Object }} SQL 条件片段与参数。
|
||||
*/
|
||||
buildBatchListAssignmentStatusFilterClause(statusFilter = '', schema = {}) {
|
||||
const normalizedStatusFilter = String(statusFilter || '').trim();
|
||||
if (!normalizedStatusFilter) {
|
||||
return {
|
||||
sql: '',
|
||||
@ -1243,47 +1390,54 @@ class WaveService extends OrderBaseService {
|
||||
};
|
||||
}
|
||||
|
||||
const totalExpr = 'COALESCE(wave_order_stats.order_total, 0)';
|
||||
const storageNoneExpr = 'COALESCE(wave_order_stats.storage_none_count, 0)';
|
||||
const storageFinExpr = 'COALESCE(wave_order_stats.storage_fin_count, 0)';
|
||||
const storageErrorExpr = 'COALESCE(wave_order_stats.storage_error_count, 0)';
|
||||
let whereClause = '';
|
||||
const statsPrefix = String(schema && schema.statsColumnPrefix || '').trim();
|
||||
if (!statsPrefix) {
|
||||
throw new Error('分配状态筛选配置不完整,缺少统计字段前缀');
|
||||
}
|
||||
|
||||
if (normalizedStatusFilter === '已分配') {
|
||||
whereClause = `
|
||||
${storageFinExpr} = ${totalExpr}
|
||||
AND ${totalExpr} > 0
|
||||
`;
|
||||
} else if (normalizedStatusFilter === '部分分配') {
|
||||
whereClause = `
|
||||
${storageErrorExpr} = 0
|
||||
AND ${storageNoneExpr} <> ${totalExpr}
|
||||
AND ${storageFinExpr} <> ${totalExpr}
|
||||
`;
|
||||
} else if (normalizedStatusFilter === '未分配') {
|
||||
const totalExpr = 'COALESCE(wave_order_stats.order_total, 0)';
|
||||
const noneExpr = `COALESCE(wave_order_stats.${statsPrefix}_none_count, 0)`;
|
||||
const finExpr = `COALESCE(wave_order_stats.${statsPrefix}_fin_count, 0)`;
|
||||
const withErrorStatus = Boolean(schema && schema.withErrorStatus);
|
||||
const errorExpr = withErrorStatus ? `COALESCE(wave_order_stats.${statsPrefix}_error_count, 0)` : '';
|
||||
|
||||
if (normalizedStatusFilter === 'finished') {
|
||||
return {
|
||||
sql: `
|
||||
AND ${finExpr} = ${totalExpr}
|
||||
AND ${totalExpr} > 0`,
|
||||
replacements: {},
|
||||
};
|
||||
}
|
||||
|
||||
if (normalizedStatusFilter === 'partial') {
|
||||
return {
|
||||
sql: `
|
||||
AND ${withErrorStatus ? `${errorExpr} = 0\n AND ` : ''}${noneExpr} <> ${totalExpr}
|
||||
AND ${finExpr} <> ${totalExpr}`,
|
||||
replacements: {},
|
||||
};
|
||||
}
|
||||
|
||||
if (normalizedStatusFilter === 'none') {
|
||||
return {
|
||||
sql: `
|
||||
AND (
|
||||
${totalExpr} = 0
|
||||
OR ${storageErrorExpr} > 0
|
||||
OR ${storageNoneExpr} = ${totalExpr}
|
||||
${withErrorStatus ? `OR ${errorExpr} > 0\n ` : ''}OR ${noneExpr} = ${totalExpr}
|
||||
)`,
|
||||
replacements: {},
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
sql: `
|
||||
AND ${whereClause}`,
|
||||
replacements: {},
|
||||
};
|
||||
throw new Error(`不支持的分配状态筛选值: ${normalizedStatusFilter}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建波次列表 where 条件(白名单字段)。
|
||||
*
|
||||
* @param {Object} whereData 查询 where 入参。
|
||||
* @return {{ sql: string, replacements: Object, storageAssignmentStatus: string }} SQL 条件片段、参数与库位分配状态筛选值。
|
||||
* @param {Object} whereData 查询 where 入参。
|
||||
* @return {{ sql: string, replacements: Object, storageAssignmentStatus: string, expressAssignmentStatus: string, printAssignmentStatus: string }} SQL 条件片段、参数与分配状态筛选值。
|
||||
*/
|
||||
buildBatchListWhereClause(whereData = {}) {
|
||||
const normalizedWhere = this.isPlainObject(whereData) ? whereData : {};
|
||||
@ -1311,6 +1465,8 @@ class WaveService extends OrderBaseService {
|
||||
'processed_orders_min',
|
||||
'processed_orders_max',
|
||||
'storage_assignment_status',
|
||||
'express_assignment_status',
|
||||
'print_assignment_status',
|
||||
];
|
||||
|
||||
const invalidFields = whereKeys.filter(key => !allowedFields.includes(key));
|
||||
@ -1438,11 +1594,19 @@ class WaveService extends OrderBaseService {
|
||||
const storageAssignmentStatus = this.normalizeBatchListStorageAssignmentStatusFilter(
|
||||
normalizedWhere.storage_assignment_status
|
||||
);
|
||||
const expressAssignmentStatus = this.normalizeBatchListExpressAssignmentStatusFilter(
|
||||
normalizedWhere.express_assignment_status
|
||||
);
|
||||
const printAssignmentStatus = this.normalizeBatchListPrintAssignmentStatusFilter(
|
||||
normalizedWhere.print_assignment_status
|
||||
);
|
||||
|
||||
return {
|
||||
sql: conditions.length > 0 ? `\n AND ${conditions.join('\n AND ')}` : '',
|
||||
replacements,
|
||||
storageAssignmentStatus,
|
||||
expressAssignmentStatus,
|
||||
printAssignmentStatus,
|
||||
};
|
||||
}
|
||||
|
||||
@ -3087,6 +3251,9 @@ class WaveService extends OrderBaseService {
|
||||
if (Object.prototype.hasOwnProperty.call(requestData, 'description')) {
|
||||
payload.description = String(requestData.description || '').trim();
|
||||
}
|
||||
if (mode === 'create' || Object.prototype.hasOwnProperty.call(requestData, 'wave_prefix')) {
|
||||
payload.wave_prefix = this.normalizeWaveStrategyWavePrefix(requestData.wave_prefix);
|
||||
}
|
||||
if (Object.prototype.hasOwnProperty.call(requestData, 'allowed_provinces')) {
|
||||
payload.allowed_provinces = this.normalizeWaveStrategyQuickScanStringList(requestData.allowed_provinces);
|
||||
}
|
||||
@ -3115,6 +3282,71 @@ class WaveService extends OrderBaseService {
|
||||
return payload;
|
||||
}
|
||||
|
||||
/**
|
||||
* 归一化波次策略波次前缀。
|
||||
*
|
||||
* 规则:
|
||||
* 1. 允许为空字符串(表示回退仓库前缀);
|
||||
* 2. 非空时统一转大写;
|
||||
* 3. 非空时仅允许 A-Z0-9,长度 1-5。
|
||||
*
|
||||
* @param {*} rawWavePrefix 原始波次前缀入参。
|
||||
* @return {string} 归一化后的波次前缀。
|
||||
*/
|
||||
normalizeWaveStrategyWavePrefix(rawWavePrefix) {
|
||||
if (rawWavePrefix === undefined || rawWavePrefix === null) {
|
||||
return '';
|
||||
}
|
||||
|
||||
const normalizedWavePrefix = String(rawWavePrefix).trim()
|
||||
.toUpperCase();
|
||||
if (!normalizedWavePrefix) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if (normalizedWavePrefix.length < 1 || normalizedWavePrefix.length > 5) {
|
||||
throw new Error('wave_prefix 非空时长度必须为 1-5 个字符');
|
||||
}
|
||||
|
||||
if (!/^[A-Z0-9]+$/.test(normalizedWavePrefix)) {
|
||||
throw new Error('wave_prefix 非空时仅支持 A-Z0-9');
|
||||
}
|
||||
|
||||
return normalizedWavePrefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析策略抓取建波使用的前缀(策略优先,仓库前缀兜底)。
|
||||
*
|
||||
* @param {Object} params 解析参数。
|
||||
* @param {number|string} params.warehouseId 仓库ID。
|
||||
* @param {number|string} params.strategyType 策略类型(1-散单,2-团购)。
|
||||
* @param {Object} [params.strategyRow={}] 策略行。
|
||||
* @return {Promise<{ wavePrefix: string, source: string }>} 前缀及来源。
|
||||
*/
|
||||
async resolveWaveStrategyFetchWavePrefix(params = {}) {
|
||||
const warehouseId = this.normalizeRequiredPositiveInteger(params.warehouseId, 'warehouse_id');
|
||||
const strategyType = Number(params.strategyType || 0);
|
||||
const strategyRow = this.isPlainObject(params.strategyRow) ? params.strategyRow : {};
|
||||
const strategyWavePrefix = this.normalizeWaveStrategyWavePrefix(strategyRow.wave_prefix);
|
||||
|
||||
if (strategyWavePrefix) {
|
||||
return {
|
||||
wavePrefix: strategyWavePrefix,
|
||||
source: 'strategy',
|
||||
};
|
||||
}
|
||||
|
||||
const warehouseWavePrefix = strategyType === 2
|
||||
? await this.getGroupWavePrefix(warehouseId)
|
||||
: await this.getSingleFetchByIdsWavePrefix(warehouseId);
|
||||
|
||||
return {
|
||||
wavePrefix: String(warehouseWavePrefix || '').trim() || (strategyType === 2 ? 'B' : 'A'),
|
||||
source: 'warehouse_fallback',
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 按字段补丁方式归一化波次策略正整数参数。
|
||||
*
|
||||
@ -3608,6 +3840,8 @@ class WaveService extends OrderBaseService {
|
||||
const orderTableName = this.getModelTableSqlName(orderModel);
|
||||
const whereClause = this.buildBatchListWhereClause(requestData.where);
|
||||
const storageAssignmentFilterClause = this.buildBatchListStorageAssignmentFilterClause(whereClause.storageAssignmentStatus);
|
||||
const expressAssignmentFilterClause = this.buildBatchListExpressAssignmentFilterClause(whereClause.expressAssignmentStatus);
|
||||
const printAssignmentFilterClause = this.buildBatchListPrintAssignmentFilterClause(whereClause.printAssignmentStatus);
|
||||
const baseBatchWhereSql = `
|
||||
warehouse_id = :warehouseId
|
||||
AND wave_status IN (:waveStatusList)
|
||||
@ -3639,7 +3873,12 @@ class WaveService extends OrderBaseService {
|
||||
COUNT(od.wave_id) AS order_total,
|
||||
SUM(CASE WHEN od.storage_status = 'none' THEN 1 ELSE 0 END) AS storage_none_count,
|
||||
SUM(CASE WHEN od.storage_status = 'fin' THEN 1 ELSE 0 END) AS storage_fin_count,
|
||||
SUM(CASE WHEN od.storage_status = 'error' THEN 1 ELSE 0 END) AS storage_error_count
|
||||
SUM(CASE WHEN od.storage_status = 'error' THEN 1 ELSE 0 END) AS storage_error_count,
|
||||
SUM(CASE WHEN od.post_status = 'none' THEN 1 ELSE 0 END) AS post_none_count,
|
||||
SUM(CASE WHEN od.post_status = 'fin' THEN 1 ELSE 0 END) AS post_fin_count,
|
||||
SUM(CASE WHEN od.post_status = 'error' THEN 1 ELSE 0 END) AS post_error_count,
|
||||
SUM(CASE WHEN od.print_status = 'none' THEN 1 ELSE 0 END) AS print_none_count,
|
||||
SUM(CASE WHEN od.print_status = 'fin' THEN 1 ELSE 0 END) AS print_fin_count
|
||||
FROM (
|
||||
SELECT wave_id
|
||||
FROM wms_wave_batch
|
||||
@ -3650,6 +3889,8 @@ class WaveService extends OrderBaseService {
|
||||
) wave_order_stats ON wave_order_stats.wave_id = wb.wave_id
|
||||
WHERE 1 = 1
|
||||
${storageAssignmentFilterClause.sql}
|
||||
${expressAssignmentFilterClause.sql}
|
||||
${printAssignmentFilterClause.sql}
|
||||
`;
|
||||
|
||||
const listSql = `
|
||||
@ -3667,7 +3908,16 @@ class WaveService extends OrderBaseService {
|
||||
wb.warehouse_id,
|
||||
wb.creator,
|
||||
wb.create_time,
|
||||
wb.update_time
|
||||
wb.update_time,
|
||||
COALESCE(wave_order_stats.order_total, 0) AS order_total,
|
||||
COALESCE(wave_order_stats.storage_none_count, 0) AS storage_none_count,
|
||||
COALESCE(wave_order_stats.storage_fin_count, 0) AS storage_fin_count,
|
||||
COALESCE(wave_order_stats.storage_error_count, 0) AS storage_error_count,
|
||||
COALESCE(wave_order_stats.post_none_count, 0) AS post_none_count,
|
||||
COALESCE(wave_order_stats.post_fin_count, 0) AS post_fin_count,
|
||||
COALESCE(wave_order_stats.post_error_count, 0) AS post_error_count,
|
||||
COALESCE(wave_order_stats.print_none_count, 0) AS print_none_count,
|
||||
COALESCE(wave_order_stats.print_fin_count, 0) AS print_fin_count
|
||||
${batchListFromSql}
|
||||
ORDER BY wb.total_orders DESC, wb.wave_id DESC
|
||||
LIMIT :limit OFFSET :offset
|
||||
@ -3685,6 +3935,8 @@ class WaveService extends OrderBaseService {
|
||||
waveStatusList,
|
||||
...whereClause.replacements,
|
||||
...storageAssignmentFilterClause.replacements,
|
||||
...expressAssignmentFilterClause.replacements,
|
||||
...printAssignmentFilterClause.replacements,
|
||||
limit: pageSize,
|
||||
offset,
|
||||
},
|
||||
@ -3695,6 +3947,8 @@ class WaveService extends OrderBaseService {
|
||||
waveStatusList,
|
||||
...whereClause.replacements,
|
||||
...storageAssignmentFilterClause.replacements,
|
||||
...expressAssignmentFilterClause.replacements,
|
||||
...printAssignmentFilterClause.replacements,
|
||||
},
|
||||
}),
|
||||
]);
|
||||
@ -3718,82 +3972,17 @@ class WaveService extends OrderBaseService {
|
||||
});
|
||||
}
|
||||
|
||||
const waveIds = rawList
|
||||
.map(item => Number(item && item.wave_id || 0))
|
||||
.filter(id => Number.isInteger(id) && id > 0);
|
||||
|
||||
const orderRows = waveIds.length > 0
|
||||
? await orderModel.findAll({
|
||||
where: {
|
||||
wave_id: { [Op.in]: waveIds },
|
||||
},
|
||||
attributes: [ 'wave_id', 'storage_status', 'post_status', 'print_status' ],
|
||||
raw: true,
|
||||
})
|
||||
: [];
|
||||
|
||||
const waveOrderStatsMap = new Map();
|
||||
for (const row of orderRows) {
|
||||
const waveId = Number(row && row.wave_id || 0);
|
||||
if (!Number.isInteger(waveId) || waveId <= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!waveOrderStatsMap.has(waveId)) {
|
||||
waveOrderStatsMap.set(waveId, {
|
||||
orderCount: 0,
|
||||
storageNoneCount: 0,
|
||||
storageFinCount: 0,
|
||||
storageErrorCount: 0,
|
||||
expressNoneCount: 0,
|
||||
expressFinCount: 0,
|
||||
expressErrorCount: 0,
|
||||
printNoneCount: 0,
|
||||
printFinCount: 0,
|
||||
});
|
||||
}
|
||||
|
||||
const stats = waveOrderStatsMap.get(waveId);
|
||||
const storageStatus = String(row && row.storage_status || '').trim();
|
||||
const expressStatus = String(row && row.post_status || '').trim();
|
||||
const printStatus = String(row && row.print_status || '').trim();
|
||||
|
||||
stats.orderCount += 1;
|
||||
if (storageStatus === 'none') {
|
||||
stats.storageNoneCount += 1;
|
||||
} else if (storageStatus === 'fin') {
|
||||
stats.storageFinCount += 1;
|
||||
} else if (storageStatus === 'error') {
|
||||
stats.storageErrorCount += 1;
|
||||
}
|
||||
|
||||
if (expressStatus === 'none') {
|
||||
stats.expressNoneCount += 1;
|
||||
} else if (expressStatus === 'fin') {
|
||||
stats.expressFinCount += 1;
|
||||
} else if (expressStatus === 'error') {
|
||||
stats.expressErrorCount += 1;
|
||||
}
|
||||
|
||||
if (printStatus === 'none') {
|
||||
stats.printNoneCount += 1;
|
||||
} else if (printStatus === 'fin') {
|
||||
stats.printFinCount += 1;
|
||||
}
|
||||
}
|
||||
|
||||
const list = rawList.map(batch => {
|
||||
const waveId = Number(batch && batch.wave_id || 0);
|
||||
const stats = waveOrderStatsMap.get(waveId) || {};
|
||||
const orderCount = Number(stats.orderCount || 0);
|
||||
const storageNoneCount = Number(stats.storageNoneCount || 0);
|
||||
const storageFinCount = Number(stats.storageFinCount || 0);
|
||||
const storageErrorCount = Number(stats.storageErrorCount || 0);
|
||||
const expressNoneCount = Number(stats.expressNoneCount || 0);
|
||||
const expressFinCount = Number(stats.expressFinCount || 0);
|
||||
const expressErrorCount = Number(stats.expressErrorCount || 0);
|
||||
const printNoneCount = Number(stats.printNoneCount || 0);
|
||||
const printFinCount = Number(stats.printFinCount || 0);
|
||||
const orderCount = Number(batch && batch.order_total || 0);
|
||||
const storageNoneCount = Number(batch && batch.storage_none_count || 0);
|
||||
const storageFinCount = Number(batch && batch.storage_fin_count || 0);
|
||||
const storageErrorCount = Number(batch && batch.storage_error_count || 0);
|
||||
const expressNoneCount = Number(batch && batch.post_none_count || 0);
|
||||
const expressFinCount = Number(batch && batch.post_fin_count || 0);
|
||||
const expressErrorCount = Number(batch && batch.post_error_count || 0);
|
||||
const printNoneCount = Number(batch && batch.print_none_count || 0);
|
||||
const printFinCount = Number(batch && batch.print_fin_count || 0);
|
||||
|
||||
return {
|
||||
wave_id: waveId,
|
||||
@ -4570,6 +4759,7 @@ class WaveService extends OrderBaseService {
|
||||
* @param {number|string} [warehouseId=0] 仓库ID,未传时优先使用上下文仓库ID。
|
||||
* @param {Object} [options={}] 提交选项。
|
||||
* @param {Array<number|string>|number|string} [options.orderIds] 可选订单ID数组。
|
||||
* @param {boolean} [options.wait=false] 是否等待任务执行完成后再返回最终进度快照。
|
||||
* @return {Promise<Object>} 任务受理结果(plain object)。
|
||||
*/
|
||||
async submitWaveStrategyQuickScanForWarehouse(warehouseId = 0, options = {}) {
|
||||
@ -4579,6 +4769,7 @@ class WaveService extends OrderBaseService {
|
||||
}
|
||||
const normalizedOptions = this.isPlainObject(options) ? options : {};
|
||||
const orderIds = this.normalizeIdsInput(normalizedOptions.orderIds);
|
||||
const wait = this.normalizeBoolean(normalizedOptions.wait, false);
|
||||
|
||||
const runningTask = await this.getWaveStrategyQuickScanWarehouseLock(normalizedWarehouseId);
|
||||
if (runningTask && runningTask.task_id) {
|
||||
@ -4624,6 +4815,22 @@ class WaveService extends OrderBaseService {
|
||||
accepted_at: acceptedAt,
|
||||
});
|
||||
|
||||
if (wait) {
|
||||
await this.runWaveStrategyQuickScanTask({
|
||||
taskId,
|
||||
warehouseId: normalizedWarehouseId,
|
||||
...(orderIds.length > 0 ? { orderIds } : {}),
|
||||
});
|
||||
|
||||
const finalProgress = await this.getWaveStrategyQuickScanTaskProgress(taskId) || {};
|
||||
return {
|
||||
...finalProgress,
|
||||
task_id: taskId,
|
||||
warehouse_id: normalizedWarehouseId,
|
||||
accepted_at: acceptedAt,
|
||||
};
|
||||
}
|
||||
|
||||
setImmediate(() => {
|
||||
this.runWaveStrategyQuickScanTask({
|
||||
taskId,
|
||||
@ -9604,8 +9811,18 @@ class WaveService extends OrderBaseService {
|
||||
removed_order_ids: [],
|
||||
candidate_count: candidateCount,
|
||||
grouped_count: groupedRows.length,
|
||||
wave_prefix: '',
|
||||
wave_prefix_source: '',
|
||||
};
|
||||
|
||||
const wavePrefixResolution = await this.resolveWaveStrategyFetchWavePrefix({
|
||||
warehouseId,
|
||||
strategyType,
|
||||
strategyRow,
|
||||
});
|
||||
result.wave_prefix = wavePrefixResolution.wavePrefix;
|
||||
result.wave_prefix_source = wavePrefixResolution.source;
|
||||
|
||||
if (strategyType === 2) {
|
||||
const groupLimitRaw = Number(strategyRow.group_batch_max_orders || plan.box_limit || 0);
|
||||
const groupLimit = Number.isInteger(groupLimitRaw) && groupLimitRaw > 0 ? groupLimitRaw : 1;
|
||||
@ -9615,13 +9832,12 @@ class WaveService extends OrderBaseService {
|
||||
throw new Error('团购策略未找到可创建波次的同结构分组');
|
||||
}
|
||||
|
||||
const groupWavePrefix = await this.getGroupWavePrefix(warehouseId);
|
||||
for (const group of selectedGroups) {
|
||||
const created = await this.createWaveBatchByOrderIdsInTransaction({
|
||||
warehouseId,
|
||||
orderIds: group.order_ids,
|
||||
waveType: 1,
|
||||
wavePrefix: groupWavePrefix,
|
||||
wavePrefix: wavePrefixResolution.wavePrefix,
|
||||
source: waveBatchSource,
|
||||
transaction,
|
||||
});
|
||||
@ -9677,12 +9893,11 @@ class WaveService extends OrderBaseService {
|
||||
throw new Error('散单策略筛选后无可用订单(batch_max_orders 限制导致为空)');
|
||||
}
|
||||
|
||||
const singleWavePrefix = await this.getSingleFetchByIdsWavePrefix(warehouseId);
|
||||
const createdWave = await this.createWaveBatchByOrderIdsInTransaction({
|
||||
warehouseId,
|
||||
orderIds: limitedOrderIds,
|
||||
waveType: 2,
|
||||
wavePrefix: singleWavePrefix,
|
||||
wavePrefix: wavePrefixResolution.wavePrefix,
|
||||
source: waveBatchSource,
|
||||
transaction,
|
||||
});
|
||||
@ -9703,6 +9918,9 @@ class WaveService extends OrderBaseService {
|
||||
strategy_id: strategyId,
|
||||
warehouse_id: warehouseId,
|
||||
pick_mode: pickMode,
|
||||
strategy_type: strategyType,
|
||||
wave_prefix: result.wave_prefix,
|
||||
wave_prefix_source: result.wave_prefix_source,
|
||||
candidate_count: result.candidate_count,
|
||||
removed_count: result.removed_order_ids.length,
|
||||
selected_count: result.selected_order_ids.length,
|
||||
@ -9712,6 +9930,140 @@ class WaveService extends OrderBaseService {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 按策略直接抓取候选订单并创建波次(不创建拣货任务)。
|
||||
*
|
||||
* 在一个事务内完成候选查询、分组与建波:
|
||||
* - 团购策略(strategy_type=2):每个结构分组创建一个波次;
|
||||
* - 散单策略(strategy_type=1):合并全部候选订单后创建一个散单波次。
|
||||
*
|
||||
* @param {Object} params 执行参数。
|
||||
* @param {Object} params.plan 预处理计划。
|
||||
* @param {Object} [params.strategyRow={}] 策略行(可选,默认取 plan.strategy_row)。
|
||||
* @param {number|string} [params.waveBatchSource=0] 波次来源:0-普通波次 1-管理后台策略抓取 2-PDA策略抓取。
|
||||
* @return {Promise<Object>} 建波结果汇总。
|
||||
*/
|
||||
async executeWaveStrategyDirectFetch(params = {}) {
|
||||
const plan = this.isPlainObject(params && params.plan) ? params.plan : {};
|
||||
const strategyRow = this.isPlainObject(params && params.strategyRow)
|
||||
? params.strategyRow
|
||||
: (this.isPlainObject(plan.strategy_row) ? plan.strategy_row : {});
|
||||
const waveBatchSourceInput = Number(params && params.waveBatchSource);
|
||||
const waveBatchSource = [ 0, 1, 2 ].includes(waveBatchSourceInput) ? waveBatchSourceInput : 0;
|
||||
|
||||
const warehouseId = this.normalizeRequiredPositiveInteger(plan.warehouse_id, 'warehouse_id');
|
||||
const strategyId = this.normalizeRequiredPositiveInteger(plan.strategy_id, 'strategy_id');
|
||||
const strategyType = Number(strategyRow.strategy_type || plan.strategy_type || 0);
|
||||
const transaction = await this.ctx.model.transaction();
|
||||
|
||||
try {
|
||||
const candidateRows = await this.getWaveStrategyFetchCandidateOrders({
|
||||
warehouseId,
|
||||
strategyId,
|
||||
minSameStructure: strategyRow.min_same_structure,
|
||||
maxSameStructure: strategyRow.max_same_structure,
|
||||
});
|
||||
const candidateCount = candidateRows.length;
|
||||
if (candidateCount <= 0) {
|
||||
throw new Error('未找到符合策略且未分配波次的候选订单');
|
||||
}
|
||||
|
||||
const groupedRows = this.groupWaveStrategyFetchCandidateOrdersByStructure(candidateRows);
|
||||
if (groupedRows.length <= 0) {
|
||||
throw new Error('候选订单缺少有效商品结构,无法创建波次');
|
||||
}
|
||||
|
||||
const wavePrefixResolution = await this.resolveWaveStrategyFetchWavePrefix({
|
||||
warehouseId,
|
||||
strategyType,
|
||||
strategyRow,
|
||||
});
|
||||
|
||||
const createdWaveIds = [];
|
||||
const createdWaveNos = [];
|
||||
const createdOrderIds = [];
|
||||
|
||||
if (strategyType === 2) {
|
||||
for (const group of groupedRows) {
|
||||
const created = await this.createWaveBatchByOrderIdsInTransaction({
|
||||
warehouseId,
|
||||
orderIds: group.order_ids,
|
||||
waveType: 1,
|
||||
wavePrefix: wavePrefixResolution.wavePrefix,
|
||||
source: waveBatchSource,
|
||||
transaction,
|
||||
});
|
||||
createdWaveIds.push(created.waveId);
|
||||
createdWaveNos.push(created.waveNo);
|
||||
createdOrderIds.push(...created.selectedOrderIds);
|
||||
}
|
||||
} else if (strategyType === 1) {
|
||||
const mergedOrderIds = [ ...new Set(groupedRows
|
||||
.flatMap(group => group.order_ids)
|
||||
.map(id => Number(id || 0))
|
||||
.filter(id => Number.isInteger(id) && id > 0)) ]
|
||||
.sort((a, b) => a - b);
|
||||
if (mergedOrderIds.length <= 0) {
|
||||
throw new Error('散单策略无可用候选订单');
|
||||
}
|
||||
|
||||
const createdWave = await this.createWaveBatchByOrderIdsInTransaction({
|
||||
warehouseId,
|
||||
orderIds: mergedOrderIds,
|
||||
waveType: 2,
|
||||
wavePrefix: wavePrefixResolution.wavePrefix,
|
||||
source: waveBatchSource,
|
||||
transaction,
|
||||
});
|
||||
createdWaveIds.push(createdWave.waveId);
|
||||
createdWaveNos.push(createdWave.waveNo);
|
||||
createdOrderIds.push(...createdWave.selectedOrderIds);
|
||||
} else {
|
||||
throw new Error(`不支持的策略类型: ${strategyType}`);
|
||||
}
|
||||
|
||||
const normalizedWaveIds = [ ...new Set(createdWaveIds) ].sort((a, b) => a - b);
|
||||
const normalizedWaveNos = [ ...new Set(createdWaveNos.map(item => String(item || '').trim()).filter(Boolean)) ];
|
||||
const normalizedOrderIds = [ ...new Set(createdOrderIds) ].sort((a, b) => a - b);
|
||||
|
||||
if (normalizedWaveIds.length <= 0 || normalizedOrderIds.length <= 0) {
|
||||
throw new Error('按策略抓取建波失败:未生成有效波次或订单结果');
|
||||
}
|
||||
|
||||
const result = {
|
||||
wave_ids: normalizedWaveIds,
|
||||
wave_nos: normalizedWaveNos,
|
||||
order_ids: normalizedOrderIds,
|
||||
created_wave_count: normalizedWaveIds.length,
|
||||
created_order_count: normalizedOrderIds.length,
|
||||
wave_prefix: wavePrefixResolution.wavePrefix,
|
||||
wave_prefix_source: wavePrefixResolution.source,
|
||||
candidate_count: candidateCount,
|
||||
grouped_count: groupedRows.length,
|
||||
strategy_type: strategyType,
|
||||
};
|
||||
|
||||
await transaction.commit();
|
||||
|
||||
this.ctx.logger.info('[wave.executeWaveStrategyDirectFetch] 按策略直接建波完成', {
|
||||
strategy_id: strategyId,
|
||||
warehouse_id: warehouseId,
|
||||
strategy_type: strategyType,
|
||||
wave_prefix: result.wave_prefix,
|
||||
wave_prefix_source: result.wave_prefix_source,
|
||||
candidate_count: result.candidate_count,
|
||||
grouped_count: result.grouped_count,
|
||||
created_wave_count: result.created_wave_count,
|
||||
created_order_count: result.created_order_count,
|
||||
});
|
||||
|
||||
return result;
|
||||
} catch (error) {
|
||||
await transaction.rollback();
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行按策略抓取任务创建主流程。
|
||||
*
|
||||
@ -11279,11 +11631,11 @@ class WaveService extends OrderBaseService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 按策略抓取任务壳子方法(仅后台管理使用),仅受理请求并返回任务信息。
|
||||
* 后台按策略直接抓取并创建波次。
|
||||
*
|
||||
* @param {Object} [data={}] 请求参数。
|
||||
* @param {number|string} data.strategy_id 波次策略ID(支持 strategyId)。
|
||||
* @return {Promise<Object>} 受理结果。
|
||||
* @return {Promise<Object>} 建波结果。
|
||||
*/
|
||||
async waveStrategyFetchAdmin(data = {}) {
|
||||
const normalizedData = this.isPlainObject(data) ? data : {};
|
||||
@ -11319,9 +11671,7 @@ class WaveService extends OrderBaseService {
|
||||
data: {
|
||||
status: 'failed',
|
||||
fetch_state: 2,
|
||||
tip: '创建失败,请重试',
|
||||
task_id: null,
|
||||
can_enter_pick_flow: false,
|
||||
tip: '建波失败,请重试',
|
||||
warehouse_id: warehouseId,
|
||||
strategy_id: strategyId,
|
||||
source: 'admin',
|
||||
@ -11331,59 +11681,45 @@ class WaveService extends OrderBaseService {
|
||||
}
|
||||
|
||||
try {
|
||||
const createdTask = await this.createWavePickTaskFromPlan({
|
||||
const directFetchResult = await this.executeWaveStrategyDirectFetch({
|
||||
plan,
|
||||
data: normalizedData,
|
||||
waveBatchSource: 1,
|
||||
});
|
||||
|
||||
this.ctx.logger.info('[wave.waveStrategyFetchAdmin] 任务创建成功', {
|
||||
taskId: createdTask.task_id,
|
||||
taskNo: createdTask.task_no,
|
||||
this.ctx.logger.info('[wave.waveStrategyFetchAdmin] 建波成功', {
|
||||
warehouseId,
|
||||
strategyId,
|
||||
strategyType: directFetchResult.strategy_type,
|
||||
createdWaveCount: directFetchResult.created_wave_count,
|
||||
createdOrderCount: directFetchResult.created_order_count,
|
||||
});
|
||||
|
||||
return this.success('ok', {
|
||||
status: 'success',
|
||||
fetch_state: 1,
|
||||
tip: '任务创建成功',
|
||||
task_id: createdTask.task_id,
|
||||
task_no: createdTask.task_no,
|
||||
can_enter_pick_flow: false,
|
||||
tip: '建波成功',
|
||||
warehouse_id: warehouseId,
|
||||
strategy_id: strategyId,
|
||||
source: 'admin',
|
||||
state: createdTask.state,
|
||||
plan,
|
||||
plan_summary: createdTask.plan_summary,
|
||||
wave_ids: directFetchResult.wave_ids,
|
||||
wave_nos: directFetchResult.wave_nos,
|
||||
order_ids: directFetchResult.order_ids,
|
||||
created_wave_count: directFetchResult.created_wave_count,
|
||||
created_order_count: directFetchResult.created_order_count,
|
||||
wave_prefix: directFetchResult.wave_prefix,
|
||||
wave_prefix_source: directFetchResult.wave_prefix_source,
|
||||
candidate_count: directFetchResult.candidate_count,
|
||||
grouped_count: directFetchResult.grouped_count,
|
||||
strategy_type: directFetchResult.strategy_type,
|
||||
accepted_at: new Date().toISOString(),
|
||||
});
|
||||
} catch (error) {
|
||||
const errorMessage = String(error && error.message || '');
|
||||
if (errorMessage.includes('当前用户存在未完成任务')) {
|
||||
const existingTaskInfo = this.parseWaveStrategyExistingTaskInfo(errorMessage);
|
||||
return this.success('存在未完成任务', {
|
||||
status: 'failed',
|
||||
fetch_state: 3,
|
||||
tip: '存在未完成任务,已返回任务ID,可继续拣货',
|
||||
task_id: existingTaskInfo.task_id,
|
||||
task_no: existingTaskInfo.task_no,
|
||||
can_enter_pick_flow: true,
|
||||
warehouse_id: warehouseId,
|
||||
strategy_id: strategyId,
|
||||
source: 'admin',
|
||||
plan,
|
||||
});
|
||||
}
|
||||
|
||||
return this.fail(`按策略抓取任务创建失败: ${error.message}`, {
|
||||
return this.fail(`按策略抓取建波失败: ${error.message}`, {
|
||||
data: {
|
||||
status: 'failed',
|
||||
fetch_state: 2,
|
||||
tip: '创建失败,请重试',
|
||||
task_id: null,
|
||||
can_enter_pick_flow: false,
|
||||
tip: '建波失败,请重试',
|
||||
warehouse_id: warehouseId,
|
||||
strategy_id: strategyId,
|
||||
source: 'admin',
|
||||
|
||||
@ -11,9 +11,9 @@ class PickService extends MainService {
|
||||
constructor(ctx) {
|
||||
super(ctx);
|
||||
const _noNeedLogin = '';
|
||||
const _noNeedRight = 'query,wavePickTaskDetail';
|
||||
const _noNeedRight = 'query,wavePickTaskDetail,wavePickTaskCurrent';
|
||||
const _noNeedLog = 'query';
|
||||
const _noNeedAuth = 'query,wavePickTaskDetail';
|
||||
const _noNeedAuth = 'query,wavePickTaskDetail,wavePickTaskCurrent';
|
||||
this.systemInit(_noNeedLogin, _noNeedRight, _noNeedLog, _noNeedAuth);
|
||||
}
|
||||
|
||||
@ -68,31 +68,29 @@ class PickService extends MainService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据快递号查询订单所在波次的拣货汇总信息。
|
||||
*
|
||||
* 入参:
|
||||
* - 快递号:`waybill_code`
|
||||
* - 完整显示开关:`full` / `full_display` / `is_full`
|
||||
*
|
||||
* 仓库上下文仅取当前登录用户 `ctx.user.store_id`(兼容 `ctx.state.user.store_id`),
|
||||
* 不依赖外部传入 `warehouse_id`,用于避免跨仓越界访问。
|
||||
* 按关键字获取或创建波次拣货任务。
|
||||
*
|
||||
* 关键字支持两种命中方式:
|
||||
* - 命中运单号:先定位订单并强校验订单已入波次。
|
||||
* - 命中波次号:直接按波次定位。
|
||||
*
|
||||
* 命中目标波次后按以下规则处理:
|
||||
* - 若波次存在活动任务且创建人为当前用户:直接返回任务ID。
|
||||
* - 若波次存在活动任务但创建人非当前用户:返回冲突失败信息。
|
||||
* - 若波次不存在活动任务:按波次类型创建任务并返回任务ID。
|
||||
*
|
||||
* @param {Object} data 请求参数。
|
||||
* @param {string} data.keyword 运单号或波次号关键字。
|
||||
* @return {Promise<Object>} 统一 success/fail 包装结果。
|
||||
*/
|
||||
async query(data = {}) {
|
||||
const { service, ctx } = this;
|
||||
const requestData = this.isPlainObject(data) ? data : {};
|
||||
const {
|
||||
waybill_code,
|
||||
full,
|
||||
full_display,
|
||||
is_full,
|
||||
} = requestData;
|
||||
const { keyword } = requestData;
|
||||
|
||||
const normalizedWaybillCode = String(waybill_code || '').trim();
|
||||
if (!normalizedWaybillCode) {
|
||||
return this.fail('请传入快递号', {}, 400);
|
||||
const normalizedKeyword = String(keyword || '').trim();
|
||||
if (!normalizedKeyword) {
|
||||
return this.fail('请传入关键字 keyword', {}, 400);
|
||||
}
|
||||
|
||||
const userWarehouseId = ctx && ctx.user ? ctx.user.store_id : undefined;
|
||||
@ -102,69 +100,278 @@ class PickService extends MainService {
|
||||
return this.fail('缺少当前用户仓库上下文 store_id', {}, 400);
|
||||
}
|
||||
|
||||
const stateUser = this.isPlainObject(ctx && ctx.state && ctx.state.user) ? ctx.state.user : null;
|
||||
const ctxUser = this.isPlainObject(ctx && ctx.user) ? ctx.user : null;
|
||||
const operatorSource = stateUser || ctxUser || {};
|
||||
const rawOperatorId = operatorSource.employees_id ?? operatorSource.operator_id ?? operatorSource.id;
|
||||
const operatorId = Number(rawOperatorId || 0);
|
||||
const operatorName = String(
|
||||
operatorSource.operator_name
|
||||
|| operatorSource.employees_name
|
||||
|| operatorSource.name
|
||||
|| ''
|
||||
).trim() || 'system';
|
||||
if (!Number.isInteger(operatorId) || operatorId <= 0) {
|
||||
return this.fail('未获取到操作人上下文', {}, 401);
|
||||
}
|
||||
|
||||
const orderExpress = await ctx.model.OrderExpress.findOne({
|
||||
where: {
|
||||
warehouse_id: normalizedWarehouseId,
|
||||
waybill_code: normalizedWaybillCode,
|
||||
waybill_code: normalizedKeyword,
|
||||
},
|
||||
attributes: [ 'order_id' ],
|
||||
raw: true,
|
||||
});
|
||||
|
||||
let targetWaveId = 0;
|
||||
let targetWaveNo = '';
|
||||
let targetWaveType = 2;
|
||||
let selectedOrderIds = [];
|
||||
|
||||
const orderId = Number(orderExpress && orderExpress.order_id || 0);
|
||||
if (!orderExpress || orderId <= 0) {
|
||||
return this.fail('快递号不存在或不属于当前仓库', {}, 404);
|
||||
if (orderExpress && orderId > 0) {
|
||||
let orderModel = null;
|
||||
try {
|
||||
orderModel = await this.getOrderModelByWarehouse(normalizedWarehouseId);
|
||||
} catch (error) {
|
||||
return this.fail(error && error.message ? error.message : '订单模型不可用', {}, 500);
|
||||
}
|
||||
|
||||
const order = await orderModel.findOne({
|
||||
where: {
|
||||
id: orderId,
|
||||
warehouse_id: normalizedWarehouseId,
|
||||
},
|
||||
attributes: [ 'id', 'wave_no', 'wave_id' ],
|
||||
raw: true,
|
||||
});
|
||||
if (!order) {
|
||||
return this.fail('运单对应订单不存在', {}, 404);
|
||||
}
|
||||
|
||||
const orderWaveId = Number(order.wave_id || 0);
|
||||
const orderWaveNo = String(order.wave_no || '').trim();
|
||||
if (!(orderWaveId > 0 || orderWaveNo)) {
|
||||
return this.fail('运单对应订单未进入波次,无法创建拣货任务', {}, 400);
|
||||
}
|
||||
|
||||
if (orderWaveId > 0) {
|
||||
const waveByIdRows = await ctx.model.query(
|
||||
`
|
||||
SELECT wave_id, wave_no, wave_type
|
||||
FROM wms_wave_batch
|
||||
WHERE warehouse_id = :warehouseId
|
||||
AND wave_id = :waveId
|
||||
LIMIT 1
|
||||
`,
|
||||
{
|
||||
replacements: {
|
||||
warehouseId: normalizedWarehouseId,
|
||||
waveId: orderWaveId,
|
||||
},
|
||||
type: ctx.model.QueryTypes.SELECT,
|
||||
}
|
||||
);
|
||||
const waveRow = Array.isArray(waveByIdRows) && waveByIdRows.length > 0 ? waveByIdRows[0] : null;
|
||||
if (!waveRow) {
|
||||
return this.fail('运单对应波次不存在或不属于当前仓库', {}, 404);
|
||||
}
|
||||
|
||||
targetWaveId = Number(waveRow.wave_id || 0);
|
||||
targetWaveNo = String(waveRow.wave_no || '').trim();
|
||||
targetWaveType = Number(waveRow.wave_type || 2);
|
||||
} else {
|
||||
const waveByNoRows = await ctx.model.query(
|
||||
`
|
||||
SELECT wave_id, wave_no, wave_type
|
||||
FROM wms_wave_batch
|
||||
WHERE warehouse_id = :warehouseId
|
||||
AND wave_no = :waveNo
|
||||
LIMIT 1
|
||||
`,
|
||||
{
|
||||
replacements: {
|
||||
warehouseId: normalizedWarehouseId,
|
||||
waveNo: orderWaveNo,
|
||||
},
|
||||
type: ctx.model.QueryTypes.SELECT,
|
||||
}
|
||||
);
|
||||
const waveRow = Array.isArray(waveByNoRows) && waveByNoRows.length > 0 ? waveByNoRows[0] : null;
|
||||
if (!waveRow) {
|
||||
return this.fail('运单对应波次不存在或不属于当前仓库', {}, 404);
|
||||
}
|
||||
|
||||
targetWaveId = Number(waveRow.wave_id || 0);
|
||||
targetWaveNo = String(waveRow.wave_no || '').trim();
|
||||
targetWaveType = Number(waveRow.wave_type || 2);
|
||||
}
|
||||
} else {
|
||||
const waveRows = await ctx.model.query(
|
||||
`
|
||||
SELECT wave_id, wave_no, wave_type
|
||||
FROM wms_wave_batch
|
||||
WHERE warehouse_id = :warehouseId
|
||||
AND wave_no = :waveNo
|
||||
LIMIT 1
|
||||
`,
|
||||
{
|
||||
replacements: {
|
||||
warehouseId: normalizedWarehouseId,
|
||||
waveNo: normalizedKeyword,
|
||||
},
|
||||
type: ctx.model.QueryTypes.SELECT,
|
||||
}
|
||||
);
|
||||
|
||||
const waveRow = Array.isArray(waveRows) && waveRows.length > 0 ? waveRows[0] : null;
|
||||
if (!waveRow) {
|
||||
return this.fail('关键字未命中运单号或波次号', {}, 404);
|
||||
}
|
||||
|
||||
targetWaveId = Number(waveRow.wave_id || 0);
|
||||
targetWaveNo = String(waveRow.wave_no || '').trim();
|
||||
targetWaveType = Number(waveRow.wave_type || 2);
|
||||
}
|
||||
|
||||
if (!Number.isInteger(targetWaveId) || targetWaveId <= 0 || !targetWaveNo) {
|
||||
return this.fail('目标波次信息不完整', {}, 400);
|
||||
}
|
||||
|
||||
const activeTaskRows = await ctx.model.query(
|
||||
`
|
||||
SELECT t.id AS task_id, t.pick_user_id, t.pick_user_name
|
||||
FROM wms_wave_pick_task_wave tw
|
||||
INNER JOIN wms_wave_pick_task t ON t.id = tw.task_id
|
||||
WHERE tw.wave_id = :waveId
|
||||
AND t.warehouse_id = :warehouseId
|
||||
AND t.status IN (0, 1, 2)
|
||||
ORDER BY t.id DESC
|
||||
LIMIT 1
|
||||
`,
|
||||
{
|
||||
replacements: {
|
||||
waveId: targetWaveId,
|
||||
warehouseId: normalizedWarehouseId,
|
||||
},
|
||||
type: ctx.model.QueryTypes.SELECT,
|
||||
}
|
||||
);
|
||||
const activeTask = Array.isArray(activeTaskRows) && activeTaskRows.length > 0 ? activeTaskRows[0] : null;
|
||||
if (activeTask) {
|
||||
const activeTaskId = Number(activeTask.task_id || 0);
|
||||
const taskOwnerId = Number(activeTask.pick_user_id || 0);
|
||||
const taskOwnerName = String(activeTask.pick_user_name || '').trim() || `${taskOwnerId}`;
|
||||
if (taskOwnerId > 0 && taskOwnerId === operatorId) {
|
||||
return this.success('ok', {
|
||||
data: {
|
||||
task_id: activeTaskId,
|
||||
status: 'existing',
|
||||
tip: '当前波次已有您创建的活动任务,可直接继续',
|
||||
},
|
||||
code: 200,
|
||||
});
|
||||
}
|
||||
|
||||
return this.fail(
|
||||
`当前波次已由其他人创建活动任务,请移交任务创建人处理(创建人: ${taskOwnerName},任务ID: ${activeTaskId})`,
|
||||
{
|
||||
task_id: activeTaskId,
|
||||
task_owner_id: taskOwnerId,
|
||||
task_owner_name: taskOwnerName,
|
||||
},
|
||||
409
|
||||
);
|
||||
}
|
||||
|
||||
const normalizedWaveType = Number(targetWaveType || 2);
|
||||
const isGroupWave = normalizedWaveType === 1;
|
||||
const pickMode = isGroupWave ? 1 : 2;
|
||||
|
||||
if (!isGroupWave && selectedOrderIds.length === 0) {
|
||||
let orderModel = null;
|
||||
try {
|
||||
orderModel = await this.getOrderModelByWarehouse(normalizedWarehouseId);
|
||||
} catch (error) {
|
||||
return this.fail(error && error.message ? error.message : '订单模型不可用', {}, 500);
|
||||
}
|
||||
|
||||
const orderRows = await orderModel.findAll({
|
||||
where: {
|
||||
warehouse_id: normalizedWarehouseId,
|
||||
wave_id: targetWaveId,
|
||||
},
|
||||
attributes: [ 'id' ],
|
||||
raw: true,
|
||||
});
|
||||
selectedOrderIds = [ ...new Set((Array.isArray(orderRows) ? orderRows : [])
|
||||
.map(item => Number(item && item.id || 0))
|
||||
.filter(id => Number.isInteger(id) && id > 0)) ];
|
||||
|
||||
if (selectedOrderIds.length <= 0) {
|
||||
const fallbackRows = await orderModel.findAll({
|
||||
where: {
|
||||
warehouse_id: normalizedWarehouseId,
|
||||
wave_no: targetWaveNo,
|
||||
},
|
||||
attributes: [ 'id' ],
|
||||
raw: true,
|
||||
});
|
||||
selectedOrderIds = [ ...new Set((Array.isArray(fallbackRows) ? fallbackRows : [])
|
||||
.map(item => Number(item && item.id || 0))
|
||||
.filter(id => Number.isInteger(id) && id > 0)) ];
|
||||
}
|
||||
|
||||
if (selectedOrderIds.length <= 0) {
|
||||
return this.fail('散单波次下无可用订单,无法创建任务', {}, 400);
|
||||
}
|
||||
}
|
||||
|
||||
let orderModel = null;
|
||||
try {
|
||||
orderModel = await this.getOrderModelByWarehouse(normalizedWarehouseId);
|
||||
} catch (error) {
|
||||
return this.fail(error && error.message ? error.message : '订单模型不可用', {}, 500);
|
||||
}
|
||||
|
||||
const order = await orderModel.findOne({
|
||||
where: {
|
||||
id: orderId,
|
||||
const plan = {
|
||||
strategy_id: 0,
|
||||
warehouse_id: normalizedWarehouseId,
|
||||
},
|
||||
attributes: [ 'id', 'store_id', 'wave_no', 'wave_id' ],
|
||||
raw: true,
|
||||
});
|
||||
source: 'pda',
|
||||
operator: {
|
||||
operator_id: operatorId,
|
||||
operator_name: operatorName,
|
||||
},
|
||||
pick_mode: pickMode,
|
||||
wave_limit: 1,
|
||||
order_limit: selectedOrderIds.length,
|
||||
sku_limit: 0,
|
||||
box_limit: 0,
|
||||
dynamic_append: false,
|
||||
selected_wave_ids: [ targetWaveId ],
|
||||
};
|
||||
const createData = {
|
||||
keyword: normalizedKeyword,
|
||||
selected_order_ids: pickMode === 2 ? selectedOrderIds : [],
|
||||
};
|
||||
|
||||
if (!order) {
|
||||
return this.fail('订单不存在', {}, 404);
|
||||
}
|
||||
|
||||
const waveNo = String(order.wave_no || '').trim();
|
||||
if (!waveNo) {
|
||||
return this.fail('订单未分配波次号,暂无拣货信息', {}, 400);
|
||||
}
|
||||
|
||||
const fullDisplay = this.normalizeBoolean(full ?? full_display ?? is_full, false);
|
||||
|
||||
try {
|
||||
const result = await service.systems.pick.queryPickingInfo({
|
||||
orderId,
|
||||
waveNo,
|
||||
waveId: Number(order.wave_id || 0),
|
||||
storeId: Number(order.store_id || 0),
|
||||
warehouseId: normalizedWarehouseId,
|
||||
fullDisplay,
|
||||
const createdTask = await service.systemMethods.order.wave.createWavePickTaskFromPlan({
|
||||
plan,
|
||||
data: createData,
|
||||
waveBatchSource: 2,
|
||||
});
|
||||
|
||||
return this.success('ok', {
|
||||
data: result,
|
||||
data: {
|
||||
task_id: createdTask.task_id,
|
||||
status: 'created',
|
||||
tip: '任务创建成功',
|
||||
},
|
||||
code: 200,
|
||||
});
|
||||
} catch (error) {
|
||||
const code = Number(error && error.code);
|
||||
if (Number.isFinite(code) && code >= 400 && code < 600) {
|
||||
return this.fail(error.message || '查询失败', {}, code);
|
||||
return this.fail(error.message || '任务创建失败', {}, code);
|
||||
}
|
||||
|
||||
ctx.logger.error('[PickService.query] 查询波次拣货信息失败: %s', error && error.message ? error.message : error);
|
||||
return this.fail('查询失败', {}, 500);
|
||||
ctx.logger.error('[PickService.query] 获取或创建波次任务失败: %s', error && error.message ? error.message : error);
|
||||
return this.fail('任务创建失败', {}, 500);
|
||||
}
|
||||
}
|
||||
|
||||
@ -216,6 +423,33 @@ class PickService extends MainService {
|
||||
return this.fail('查询失败', {}, 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询当前登录用户正在处理中的拣货任务。
|
||||
*
|
||||
* 仅供 PDA 使用,无需入参;按当前登录用户与仓库上下文返回最新任务ID。
|
||||
*
|
||||
* @return {Promise<Object>} 统一 success/fail 包装结果。
|
||||
*/
|
||||
async wavePickTaskCurrent() {
|
||||
const { service, ctx } = this;
|
||||
|
||||
try {
|
||||
const result = await service.systems.pick.wavePickTaskCurrent();
|
||||
return this.success('ok', {
|
||||
data: result,
|
||||
code: 200,
|
||||
});
|
||||
} catch (error) {
|
||||
const code = Number(error && error.code);
|
||||
if (Number.isInteger(code) && code >= 400 && code < 600) {
|
||||
return this.fail(error.message || '查询失败', {}, code);
|
||||
}
|
||||
|
||||
ctx.logger.error('[PickService.wavePickTaskCurrent] 查询当前拣货任务失败: %s', error && error.message ? error.message : error);
|
||||
return this.fail('查询失败', {}, 500);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = PickService;
|
||||
|
||||
@ -150,6 +150,7 @@ class PrintService extends MainService {
|
||||
break;
|
||||
}
|
||||
case 'express':
|
||||
|
||||
break;
|
||||
default:
|
||||
return this.fail('不支持的打印类型', 1001);
|
||||
@ -172,7 +173,6 @@ class PrintService extends MainService {
|
||||
}
|
||||
await printRecord.update({ status: 'failed', error_message: res.error });
|
||||
return this.fail(res.error, { code: 504, printId: printRecord.id });
|
||||
|
||||
}
|
||||
async getPrintResult(data) {
|
||||
const { ctx } = this;
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const MainService = require('../../main');
|
||||
const SUPPORTED_BUSINESS_TYPES = [ 'STOCK', 'RECEIPT', 'PICKING' ];
|
||||
|
||||
class printTemplateService extends MainService {
|
||||
constructor(ctx) {
|
||||
@ -16,11 +17,55 @@ class printTemplateService extends MainService {
|
||||
const result = await service.systems.setting.printTemplate.getTree();
|
||||
return this.success('ok', { presetTree: result, code: 200 });
|
||||
}
|
||||
|
||||
/**
|
||||
* 规范化并校验业务类型
|
||||
* @param {string} businessType 业务类型
|
||||
* @return {string} 标准化后的业务类型
|
||||
*/
|
||||
normalizeAndValidateBusinessType(businessType) {
|
||||
const normalizedBusinessType = String(businessType || '').trim().toUpperCase();
|
||||
if (!normalizedBusinessType) {
|
||||
throw new Error('business_type 参数不能为空');
|
||||
}
|
||||
if (!SUPPORTED_BUSINESS_TYPES.includes(normalizedBusinessType)) {
|
||||
throw new Error(`business_type 参数非法,仅支持:${SUPPORTED_BUSINESS_TYPES.join('、')}`);
|
||||
}
|
||||
return normalizedBusinessType;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存打印模板
|
||||
* @param {Object} data 入参
|
||||
* @return {Promise<Object>} 保存结果
|
||||
*/
|
||||
async save(data) {
|
||||
const { service } = this;
|
||||
const result = await service.systems.setting.printTemplate.save(data);
|
||||
return this.success('ok', result);
|
||||
const payload = data || {};
|
||||
try {
|
||||
if (payload.business_type !== undefined && payload.business_type !== null && String(payload.business_type).trim() !== '') {
|
||||
payload.business_type = this.normalizeAndValidateBusinessType(payload.business_type);
|
||||
}
|
||||
} catch (error) {
|
||||
return this.fail(error.message, { code: 400 });
|
||||
}
|
||||
try {
|
||||
const result = await service.systems.setting.printTemplate.save(payload);
|
||||
return this.success('ok', result);
|
||||
} catch (error) {
|
||||
const message = error && error.message ? error.message : '保存打印模板失败';
|
||||
if (message.includes('business_type 参数')) {
|
||||
return this.fail(message, { code: 400 });
|
||||
}
|
||||
return this.fail(message, { code: 500 });
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建打印模板
|
||||
* @param {Object} data 入参
|
||||
* @return {Promise<Object>} 创建结果
|
||||
*/
|
||||
async create(data) {
|
||||
const { service } = this;
|
||||
const { template_name, business_type, page_width, page_height } = data || {};
|
||||
@ -28,8 +73,11 @@ class printTemplateService extends MainService {
|
||||
if (!template_name || String(template_name).trim() === '') {
|
||||
return this.fail('template_name 参数不能为空', { code: 400 });
|
||||
}
|
||||
if (!business_type || String(business_type).trim() === '') {
|
||||
return this.fail('business_type 参数不能为空', { code: 400 });
|
||||
let normalizedBusinessType = '';
|
||||
try {
|
||||
normalizedBusinessType = this.normalizeAndValidateBusinessType(business_type);
|
||||
} catch (error) {
|
||||
return this.fail(error.message, { code: 400 });
|
||||
}
|
||||
if (page_width === undefined || page_width === null || page_width === '') {
|
||||
return this.fail('page_width 参数不能为空', { code: 400 });
|
||||
@ -39,15 +87,27 @@ class printTemplateService extends MainService {
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await service.systems.setting.printTemplate.createTemplate(data);
|
||||
const result = await service.systems.setting.printTemplate.createTemplate({
|
||||
...data,
|
||||
business_type: normalizedBusinessType,
|
||||
});
|
||||
return this.success('ok', result);
|
||||
} catch (error) {
|
||||
if (error.message === '同一业务类型和平台下已存在自定义模板') {
|
||||
return this.fail(error.message, { code: 409 });
|
||||
}
|
||||
if (error.message && error.message.includes('business_type 参数')) {
|
||||
return this.fail(error.message, { code: 400 });
|
||||
}
|
||||
return this.fail(error.message || '创建打印模板失败', { code: 500 });
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除打印模板
|
||||
* @param {Object} data 入参
|
||||
* @return {Promise<Object>} 删除结果
|
||||
*/
|
||||
async delete(data) {
|
||||
const { service } = this;
|
||||
const { id } = data || {};
|
||||
@ -67,13 +127,23 @@ class printTemplateService extends MainService {
|
||||
return this.fail(error.message || '删除打印模板失败', { code: 500 });
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 按业务类型查询模板
|
||||
* @param {Object} data 入参
|
||||
* @return {Promise<Object>} 查询结果
|
||||
*/
|
||||
async listTemplatesByType(data) {
|
||||
const { service } = this;
|
||||
const { businessType } = data;
|
||||
if (!businessType) {
|
||||
throw new Error('缺少业务类型参数');
|
||||
const { businessType } = data || {};
|
||||
let normalizedBusinessType = '';
|
||||
try {
|
||||
normalizedBusinessType = this.normalizeAndValidateBusinessType(businessType);
|
||||
} catch (error) {
|
||||
return this.fail(error.message, { code: 400 });
|
||||
}
|
||||
const list = await service.systems.setting.printTemplate.listTemplatesByType(businessType);
|
||||
|
||||
const list = await service.systems.setting.printTemplate.listTemplatesByType(normalizedBusinessType);
|
||||
return this.success('ok', { data: list, code: 200 });
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,7 +1,29 @@
|
||||
'use strict';
|
||||
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
const { Op } = require('sequelize');
|
||||
const OrderBaseService = require('../systemMethods/order/base');
|
||||
const PrinterDataBuilder = require('../../lib/printer_data_builder');
|
||||
|
||||
const SYS_PLATFORM_TO_PRINT_PLATFORM_MAP = Object.freeze({
|
||||
tb: 'cainiao',
|
||||
taobao: 'cainiao',
|
||||
cainiao: 'cainiao',
|
||||
cn: 'cainiao',
|
||||
jd: 'jd',
|
||||
jingdong: 'jd',
|
||||
dy: 'douyin',
|
||||
douyin: 'douyin',
|
||||
ks: 'kuaishou',
|
||||
kuaishou: 'kuaishou',
|
||||
pdd: 'pdd',
|
||||
pinduoduo: 'pdd',
|
||||
sph: 'sph',
|
||||
shipinhao: 'sph',
|
||||
xhs: 'xhs',
|
||||
xiaohongshu: 'xhs',
|
||||
});
|
||||
|
||||
class OrderPrintSystemService extends OrderBaseService {
|
||||
/**
|
||||
@ -48,6 +70,135 @@ class OrderPrintSystemService extends OrderBaseService {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取波次平台打印数据中间态。
|
||||
*
|
||||
* 输出以波次分组为主结构(waveGroups),并在波次内按平台分组,
|
||||
* 便于上游按「波次 -> 平台 -> 订单」层级批量发起打印。
|
||||
*
|
||||
* @param {Object} params 请求参数。
|
||||
* @param {Array<number|string>} params.waveIds 波次ID数组。
|
||||
* @param {number|string} params.warehouseId 仓库ID。
|
||||
* @return {Promise<Object>} 平台打印中间态结果。
|
||||
*/
|
||||
async getWavePlatformPrintData(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 {
|
||||
summary: {
|
||||
total_waves: 0,
|
||||
total_orders: 0,
|
||||
total_platforms: 0,
|
||||
},
|
||||
waveGroups: [],
|
||||
wave_ids: [],
|
||||
ext: {
|
||||
missing_wave_ids: normalizedWaveIds,
|
||||
filtered_wave_ids: [],
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
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);
|
||||
const validWaveIdSet = new Set(validWaveIds);
|
||||
const validOrderRows = orderRows.filter(order => validWaveIdSet.has(Number(order && order.wave_id || 0)));
|
||||
|
||||
if (validOrderRows.length === 0) {
|
||||
const waveGroups = this.groupOrderPrintItemsByWaveAndPlatform({
|
||||
waveRows,
|
||||
hitWaveIds: validWaveIds,
|
||||
orderPrintList: [],
|
||||
});
|
||||
|
||||
return {
|
||||
summary: {
|
||||
total_waves: waveGroups.length,
|
||||
total_orders: 0,
|
||||
total_platforms: 0,
|
||||
},
|
||||
waveGroups,
|
||||
wave_ids: validWaveIds,
|
||||
ext: {
|
||||
missing_wave_ids: missingWaveIds,
|
||||
filtered_wave_ids: filteredWaveIds,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
const orderIds = validOrderRows
|
||||
.map(row => Number(row && row.id || 0))
|
||||
.filter(orderId => Number.isInteger(orderId) && orderId > 0);
|
||||
const orderExpressRows = await this.queryOrderExpressByOrderIds(orderIds);
|
||||
this.assertBusinessWaybillCompleteness(orderIds, orderExpressRows);
|
||||
const orderExpressMap = this.buildOrderExpressMap(orderExpressRows);
|
||||
const policyConfigMap = await this.getPolicyConfigMapByStore(validOrderRows, normalizedWarehouseId);
|
||||
const templateSampleCache = new Map();
|
||||
const orderPrintList = [];
|
||||
|
||||
for (const orderRow of validOrderRows) {
|
||||
const orderId = Number(orderRow && orderRow.id || 0);
|
||||
if (!Number.isInteger(orderId) || orderId <= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const orderExpress = orderExpressMap.get(orderId) || {};
|
||||
const storeId = Number(orderRow && orderRow.store_id || 0);
|
||||
const policyConfig = policyConfigMap.get(storeId) || {};
|
||||
const platformCode = this.resolvePrintPlatformCode(orderRow, orderExpress);
|
||||
const templateSample = this.loadTemplateSampleByPlatform(platformCode, templateSampleCache);
|
||||
|
||||
orderPrintList.push(this.buildOrderPlatformPrintItem({
|
||||
orderRow,
|
||||
orderExpress,
|
||||
policyConfig,
|
||||
platformCode,
|
||||
templateSample,
|
||||
}));
|
||||
}
|
||||
|
||||
const waveGroups = this.groupOrderPrintItemsByWaveAndPlatform({
|
||||
waveRows,
|
||||
hitWaveIds: validWaveIds,
|
||||
orderPrintList,
|
||||
});
|
||||
const totalPlatforms = waveGroups.reduce((sum, waveGroup) => {
|
||||
return sum + Number(waveGroup && waveGroup.platforms && waveGroup.platforms.length || 0);
|
||||
}, 0);
|
||||
|
||||
return {
|
||||
summary: {
|
||||
total_waves: waveGroups.length,
|
||||
total_orders: orderPrintList.length,
|
||||
total_platforms: totalPlatforms,
|
||||
},
|
||||
waveGroups,
|
||||
wave_ids: validWaveIds,
|
||||
ext: {
|
||||
missing_wave_ids: missingWaveIds,
|
||||
filtered_wave_ids: filteredWaveIds,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 规范化波次ID数组(去重与数字化)。
|
||||
*
|
||||
@ -144,6 +295,8 @@ class OrderPrintSystemService extends OrderBaseService {
|
||||
'id',
|
||||
'delivery_order_code',
|
||||
'source_order_codes',
|
||||
'warehouse_id',
|
||||
'store_id',
|
||||
'wave_id',
|
||||
'wave_no',
|
||||
'name',
|
||||
@ -154,8 +307,12 @@ class OrderPrintSystemService extends OrderBaseService {
|
||||
'area',
|
||||
'town',
|
||||
'detail_address',
|
||||
'zip_code',
|
||||
'items',
|
||||
'source_platform_code',
|
||||
'sys_platform_code',
|
||||
'sys_platform_name',
|
||||
'logistics_code',
|
||||
'logistics_name',
|
||||
'post_status',
|
||||
'status',
|
||||
@ -164,6 +321,7 @@ class OrderPrintSystemService extends OrderBaseService {
|
||||
'items_count',
|
||||
'items_total',
|
||||
'items_weight',
|
||||
'freight',
|
||||
'create_at',
|
||||
'pay_time',
|
||||
],
|
||||
@ -179,6 +337,440 @@ class OrderPrintSystemService extends OrderBaseService {
|
||||
return Array.isArray(rows) ? rows : [];
|
||||
}
|
||||
|
||||
/**
|
||||
* 按订单ID批量查询快递单信息。
|
||||
*
|
||||
* @param {Array<number>} orderIds 订单ID数组。
|
||||
* @return {Promise<Array<Object>>} 快递单信息列表。
|
||||
*/
|
||||
async queryOrderExpressByOrderIds(orderIds = []) {
|
||||
if (!Array.isArray(orderIds) || orderIds.length === 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const normalizedOrderIds = Array.from(new Set(orderIds
|
||||
.map(id => Number(id))
|
||||
.filter(id => Number.isInteger(id) && id > 0)));
|
||||
if (normalizedOrderIds.length === 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const rows = await this.ctx.model.OrderExpress.findAll({
|
||||
attributes: [
|
||||
'id',
|
||||
'order_id',
|
||||
'business_key',
|
||||
'waybill_code',
|
||||
'logistics_code',
|
||||
'logistics_name',
|
||||
'platform_code',
|
||||
'warehouse_id',
|
||||
'printinfo',
|
||||
'signature',
|
||||
'encryptprintinfo',
|
||||
],
|
||||
where: {
|
||||
order_id: {
|
||||
[Op.in]: normalizedOrderIds,
|
||||
},
|
||||
business_key: 1,
|
||||
},
|
||||
order: [[ 'order_id', 'ASC' ], [ 'business_key', 'ASC' ], [ 'id', 'ASC' ]],
|
||||
raw: true,
|
||||
});
|
||||
|
||||
return Array.isArray(rows) ? rows : [];
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验业务ID为1的运单号数据完整性。
|
||||
*
|
||||
* @param {Array<number>} orderIds 订单ID数组。
|
||||
* @param {Array<Object>} orderExpressRows 快递单查询结果。
|
||||
*/
|
||||
assertBusinessWaybillCompleteness(orderIds = [], orderExpressRows = []) {
|
||||
const normalizedOrderIds = Array.from(new Set((Array.isArray(orderIds) ? orderIds : [])
|
||||
.map(id => Number(id))
|
||||
.filter(id => Number.isInteger(id) && id > 0)));
|
||||
if (normalizedOrderIds.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const validOrderIdSet = new Set();
|
||||
const rows = Array.isArray(orderExpressRows) ? orderExpressRows : [];
|
||||
for (const row of rows) {
|
||||
const orderId = Number(row && row.order_id || 0);
|
||||
if (!Number.isInteger(orderId) || orderId <= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const waybillCode = String(row && row.waybill_code || '').trim();
|
||||
if (!waybillCode) {
|
||||
continue;
|
||||
}
|
||||
|
||||
validOrderIdSet.add(orderId);
|
||||
}
|
||||
|
||||
const missingOrderIds = normalizedOrderIds.filter(orderId => !validOrderIdSet.has(orderId));
|
||||
if (missingOrderIds.length > 0) {
|
||||
throw new Error(`业务id为1的运单号数据缺失,缺失 order_id: ${missingOrderIds.join(',')}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 按订单ID构建快递信息映射,优先保留带运单号的记录。
|
||||
*
|
||||
* @param {Array<Object>} rows 快递数据行。
|
||||
* @return {Map<number, Object>} 订单到快递信息的映射。
|
||||
*/
|
||||
buildOrderExpressMap(rows = []) {
|
||||
const expressMap = new Map();
|
||||
|
||||
for (const row of rows) {
|
||||
const orderId = Number(row && row.order_id || 0);
|
||||
if (!Number.isInteger(orderId) || orderId <= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const previousRow = expressMap.get(orderId);
|
||||
if (!previousRow) {
|
||||
expressMap.set(orderId, row);
|
||||
continue;
|
||||
}
|
||||
|
||||
const previousWaybillCode = String(previousRow.waybill_code || '').trim();
|
||||
const currentWaybillCode = String(row && row.waybill_code || '').trim();
|
||||
if (!previousWaybillCode && currentWaybillCode) {
|
||||
expressMap.set(orderId, row);
|
||||
}
|
||||
}
|
||||
|
||||
return expressMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取波次订单对应货主的签约策略映射。
|
||||
*
|
||||
* @param {Array<Object>} orderRows 订单行。
|
||||
* @param {number} warehouseId 仓库ID。
|
||||
* @return {Promise<Map<number, Object>>} 货主策略映射。
|
||||
*/
|
||||
async getPolicyConfigMapByStore(orderRows = [], warehouseId) {
|
||||
const storeIds = Array.from(new Set(orderRows
|
||||
.map(row => Number(row && row.store_id || 0))
|
||||
.filter(storeId => Number.isInteger(storeId) && storeId > 0)));
|
||||
const policyMap = new Map();
|
||||
|
||||
if (storeIds.length === 0) {
|
||||
return policyMap;
|
||||
}
|
||||
|
||||
const storeWarehouseService = this.ctx.service
|
||||
&& this.ctx.service.systems
|
||||
&& this.ctx.service.systems.storeWarehouse;
|
||||
if (!storeWarehouseService || typeof storeWarehouseService.getContractConfig !== 'function') {
|
||||
return policyMap;
|
||||
}
|
||||
|
||||
await Promise.all(storeIds.map(async storeId => {
|
||||
try {
|
||||
const contractConfig = await storeWarehouseService.getContractConfig(warehouseId, storeId);
|
||||
const policyConfig = this.isPlainObject(contractConfig && contractConfig.policy_config)
|
||||
? contractConfig.policy_config
|
||||
: {};
|
||||
policyMap.set(storeId, policyConfig);
|
||||
} catch (error) {
|
||||
this.ctx.logger.warn(
|
||||
`[orderPrint.getPolicyConfigMapByStore] 读取签约策略失败 warehouseId=${warehouseId} storeId=${storeId} message=${error.message}`
|
||||
);
|
||||
policyMap.set(storeId, {});
|
||||
}
|
||||
}));
|
||||
|
||||
return policyMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析订单平台编码并转换为打印平台别名。
|
||||
*
|
||||
* @param {Object} orderRow 订单行。
|
||||
* @param {Object} orderExpress 快递行。
|
||||
* @return {string} 打印平台编码。
|
||||
*/
|
||||
resolvePrintPlatformCode(orderRow = {}, orderExpress = {}) {
|
||||
const candidates = [
|
||||
orderRow && orderRow.sys_platform_code,
|
||||
orderRow && orderRow.source_platform_code,
|
||||
orderExpress && orderExpress.platform_code,
|
||||
];
|
||||
|
||||
for (const candidate of candidates) {
|
||||
const normalizedCandidate = String(candidate || '').trim().toLowerCase();
|
||||
if (!normalizedCandidate) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const mappedPlatform = SYS_PLATFORM_TO_PRINT_PLATFORM_MAP[normalizedCandidate] || normalizedCandidate;
|
||||
const normalizedPlatform = PrinterDataBuilder.normalizePlatformAlias(mappedPlatform);
|
||||
if (normalizedPlatform.platform) {
|
||||
return normalizedPlatform.platform;
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* 按平台加载打印模板样例。
|
||||
*
|
||||
* @param {string} platformCode 平台编码。
|
||||
* @param {Map<string, Object>} cache 模板缓存。
|
||||
* @return {Object} 模板样例对象。
|
||||
*/
|
||||
loadTemplateSampleByPlatform(platformCode, cache) {
|
||||
const normalized = PrinterDataBuilder.normalizePlatformAlias(platformCode);
|
||||
const cacheKey = normalized.meta && normalized.meta.template_file
|
||||
? normalized.meta.template_file
|
||||
: `platform:${normalized.platform || 'unknown'}`;
|
||||
if (cache.has(cacheKey)) {
|
||||
return cache.get(cacheKey);
|
||||
}
|
||||
|
||||
if (!normalized.meta || !normalized.meta.template_file) {
|
||||
cache.set(cacheKey, {});
|
||||
return {};
|
||||
}
|
||||
|
||||
const templatePath = path.join(this.app.baseDir, 'printer_data_template', normalized.meta.template_file);
|
||||
try {
|
||||
const fileContent = fs.readFileSync(templatePath, 'utf8');
|
||||
const parsedTemplate = JSON.parse(fileContent);
|
||||
const templateSample = this.isPlainObject(parsedTemplate) ? parsedTemplate : {};
|
||||
cache.set(cacheKey, templateSample);
|
||||
return templateSample;
|
||||
} catch (error) {
|
||||
this.ctx.logger.warn(`[orderPrint.loadTemplateSampleByPlatform] 模板读取失败 template=${templatePath} message=${error.message}`);
|
||||
cache.set(cacheKey, {});
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 组装单订单平台打印中间态结果。
|
||||
*
|
||||
* @param {Object} payload 聚合入参。
|
||||
* @param {Object} payload.orderRow 订单行。
|
||||
* @param {Object} payload.orderExpress 快递行。
|
||||
* @param {Object} payload.policyConfig 策略配置。
|
||||
* @param {string} payload.platformCode 平台编码。
|
||||
* @param {Object} payload.templateSample 模板样例。
|
||||
* @return {Object} 逐单打印中间态。
|
||||
*/
|
||||
buildOrderPlatformPrintItem(payload = {}) {
|
||||
const requestPayload = this.isPlainObject(payload) ? payload : {};
|
||||
const orderRow = this.isPlainObject(requestPayload.orderRow) ? requestPayload.orderRow : {};
|
||||
const orderExpress = this.isPlainObject(requestPayload.orderExpress) ? requestPayload.orderExpress : {};
|
||||
const policyConfig = this.isPlainObject(requestPayload.policyConfig) ? requestPayload.policyConfig : {};
|
||||
const templateSample = this.isPlainObject(requestPayload.templateSample) ? requestPayload.templateSample : {};
|
||||
const platformCode = String(requestPayload.platformCode || '').trim();
|
||||
|
||||
const orderId = Number(orderRow.id || 0);
|
||||
const waveId = Number(orderRow.wave_id || 0);
|
||||
const requestId = `wave_${waveId}_order_${orderId}`;
|
||||
const waybillCode = String(orderExpress.waybill_code || '').trim();
|
||||
const documentId = waybillCode || `doc_${orderId}`;
|
||||
const printPayload = PrinterDataBuilder.buildPlatformRequestSkeleton({
|
||||
platform: platformCode,
|
||||
order_express: orderExpress,
|
||||
order_delivery: orderRow,
|
||||
store_contract: {
|
||||
policy_config: policyConfig,
|
||||
},
|
||||
policy_config: policyConfig,
|
||||
template_sample: templateSample,
|
||||
options: {
|
||||
requestId,
|
||||
taskId: requestId,
|
||||
documentId,
|
||||
},
|
||||
});
|
||||
const printData = this.extractSinglePlatformPrintData(printPayload);
|
||||
|
||||
return {
|
||||
wave_id: waveId,
|
||||
wave_no: String(orderRow.wave_no || '').trim(),
|
||||
order_id: orderId,
|
||||
order_no: String(orderRow.delivery_order_code || orderRow.source_order_codes || '').trim(),
|
||||
store_id: Number(orderRow.store_id || 0),
|
||||
warehouse_id: Number(orderRow.warehouse_id || 0),
|
||||
platform: String(printPayload.platform || '').trim(),
|
||||
platform_name: printPayload.platform_meta && printPayload.platform_meta.name
|
||||
? String(printPayload.platform_meta.name).trim()
|
||||
: '',
|
||||
waybill_code: String(orderExpress.waybill_code || '').trim(),
|
||||
print_data: printData,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 提取单个打印文档对象。
|
||||
*
|
||||
* @param {Object} printPayload 打印载荷。
|
||||
* @return {Object} 单个文档对象;未命中时返回空对象。
|
||||
*/
|
||||
extractSinglePlatformPrintData(printPayload = {}) {
|
||||
const requestSkeleton = this.isPlainObject(printPayload)
|
||||
? printPayload.request_skeleton
|
||||
: null;
|
||||
if (!this.isPlainObject(requestSkeleton)) {
|
||||
return {};
|
||||
}
|
||||
|
||||
const taskDocuments = requestSkeleton.task && Array.isArray(requestSkeleton.task.documents)
|
||||
? requestSkeleton.task.documents
|
||||
: [];
|
||||
if (taskDocuments.length > 0 && this.isPlainObject(taskDocuments[0])) {
|
||||
return taskDocuments[0];
|
||||
}
|
||||
|
||||
if (Array.isArray(requestSkeleton.documents) && this.isPlainObject(requestSkeleton.documents[0])) {
|
||||
return requestSkeleton.documents[0];
|
||||
}
|
||||
|
||||
const taskListEntry = Array.isArray(requestSkeleton.taskList)
|
||||
? requestSkeleton.taskList.find(item => Array.isArray(item && item.documents) && item.documents.length > 0)
|
||||
: null;
|
||||
if (taskListEntry && this.isPlainObject(taskListEntry.documents[0])) {
|
||||
return taskListEntry.documents[0];
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
/**
|
||||
* 将逐单打印中间态按平台分组。
|
||||
*
|
||||
* @param {Array<Object>} orderPrintList 逐单打印中间态列表。
|
||||
* @return {Array<Object>} 平台分组列表。
|
||||
*/
|
||||
groupOrderPrintItemsByPlatform(orderPrintList = []) {
|
||||
const groupedPlatformMap = new Map();
|
||||
|
||||
for (const item of orderPrintList) {
|
||||
const platform = String(item && item.platform || '').trim() || 'unknown';
|
||||
const group = groupedPlatformMap.get(platform) || {
|
||||
platform,
|
||||
platform_name: String(item && item.platform_name || '').trim(),
|
||||
order_count: 0,
|
||||
orders: [],
|
||||
};
|
||||
|
||||
group.orders.push(this.isPlainObject(item && item.print_data) ? item.print_data : {});
|
||||
group.order_count = group.orders.length;
|
||||
groupedPlatformMap.set(platform, group);
|
||||
}
|
||||
|
||||
const groups = Array.from(groupedPlatformMap.values());
|
||||
groups.sort((a, b) => String(a.platform || '').localeCompare(String(b.platform || '')));
|
||||
return groups;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将逐单打印中间态按波次分组,并在波次内按平台分组。
|
||||
*
|
||||
* @param {Object} payload 聚合输入。
|
||||
* @param {Array<Object>} payload.waveRows 波次元数据列表。
|
||||
* @param {Array<number>} payload.hitWaveIds 命中的波次ID数组(已过滤)。
|
||||
* @param {Array<Object>} payload.orderPrintList 逐单打印中间态列表。
|
||||
* @return {Array<Object>} 波次平台分组结果。
|
||||
*/
|
||||
groupOrderPrintItemsByWaveAndPlatform(payload = {}) {
|
||||
const {
|
||||
waveRows = [],
|
||||
hitWaveIds = [],
|
||||
orderPrintList = [],
|
||||
} = 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 waveGroupMap = new Map();
|
||||
const wavePlatformMap = new Map();
|
||||
for (const waveId of hitWaveIds) {
|
||||
const normalizedWaveId = Number(waveId);
|
||||
if (!Number.isInteger(normalizedWaveId) || normalizedWaveId <= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const waveMeta = waveMetaMap.get(normalizedWaveId) || {
|
||||
wave_id: normalizedWaveId,
|
||||
wave_no: '',
|
||||
};
|
||||
waveGroupMap.set(normalizedWaveId, {
|
||||
wave_id: waveMeta.wave_id,
|
||||
wave_no: waveMeta.wave_no,
|
||||
order_count: 0,
|
||||
platforms: [],
|
||||
});
|
||||
wavePlatformMap.set(normalizedWaveId, new Map());
|
||||
}
|
||||
|
||||
for (const item of orderPrintList) {
|
||||
const waveId = Number(item && item.wave_id || 0);
|
||||
const waveGroup = waveGroupMap.get(waveId);
|
||||
if (!waveGroup) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const platform = String(item && item.platform || '').trim() || 'unknown';
|
||||
const platformMap = wavePlatformMap.get(waveId) || new Map();
|
||||
const platformGroup = platformMap.get(platform) || {
|
||||
platform,
|
||||
platform_name: String(item && item.platform_name || '').trim(),
|
||||
order_count: 0,
|
||||
orders: [],
|
||||
};
|
||||
|
||||
platformGroup.orders.push(this.isPlainObject(item && item.print_data) ? item.print_data : {});
|
||||
platformGroup.order_count = platformGroup.orders.length;
|
||||
platformMap.set(platform, platformGroup);
|
||||
wavePlatformMap.set(waveId, platformMap);
|
||||
}
|
||||
|
||||
const waveGroups = Array.from(waveGroupMap.values());
|
||||
for (const waveGroup of waveGroups) {
|
||||
const platformMap = wavePlatformMap.get(Number(waveGroup.wave_id)) || new Map();
|
||||
const platforms = Array.from(platformMap.values());
|
||||
platforms.sort((a, b) => String(a.platform || '').localeCompare(String(b.platform || '')));
|
||||
waveGroup.platforms = platforms;
|
||||
waveGroup.order_count = platforms.reduce((sum, platformGroup) => {
|
||||
return sum + Number(platformGroup && platformGroup.order_count || 0);
|
||||
}, 0);
|
||||
}
|
||||
|
||||
waveGroups.sort((a, b) => {
|
||||
const waveNoCompare = String(a.wave_no || '').localeCompare(String(b.wave_no || ''));
|
||||
if (waveNoCompare !== 0) {
|
||||
return waveNoCompare;
|
||||
}
|
||||
|
||||
return Number(a.wave_id || 0) - Number(b.wave_id || 0);
|
||||
});
|
||||
|
||||
return waveGroups;
|
||||
}
|
||||
|
||||
/**
|
||||
* 过滤快递未完全分配的波次。
|
||||
*
|
||||
|
||||
@ -344,15 +344,18 @@ class PickSystemService extends Service {
|
||||
}
|
||||
}
|
||||
} else if (pickMode === 1) {
|
||||
const taskWaveColumnSet = await this.getTableColumnSet('wms_wave_pick_task_wave');
|
||||
const taskWaveWarehouseFilterSql = taskWaveColumnSet.has('warehouse_id') ? ' AND ptw.warehouse_id = :warehouseId' : '';
|
||||
const taskWaveRows = await ctx.model.query(`
|
||||
SELECT
|
||||
ptw.wave_id,
|
||||
ptw.box_no
|
||||
FROM wms_wave_pick_task_wave ptw
|
||||
WHERE ptw.task_id = :taskId
|
||||
${taskWaveWarehouseFilterSql}
|
||||
ORDER BY ptw.id ASC
|
||||
`, {
|
||||
replacements: { taskId },
|
||||
replacements: { taskId, warehouseId },
|
||||
type: ctx.model.QueryTypes.SELECT,
|
||||
});
|
||||
|
||||
@ -782,6 +785,72 @@ class PickSystemService extends Service {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询当前登录用户正在处理中的拣货任务。
|
||||
*
|
||||
* 仅供 PDA 使用:根据当前登录用户上下文(仓库 + 操作人)查询状态为 0/1/2 的最新任务。
|
||||
*
|
||||
* @param {Object} [params={}] 预留参数(当前无需传入)。
|
||||
* @return {Promise<{task_id: number|null}>} 当前任务ID,无任务则为 null。
|
||||
*/
|
||||
async wavePickTaskCurrent(params = {}) {
|
||||
const { ctx } = this;
|
||||
void params;
|
||||
|
||||
const stateUser = ctx && ctx.state && ctx.state.user && typeof ctx.state.user === 'object'
|
||||
? ctx.state.user
|
||||
: null;
|
||||
const ctxUser = ctx && ctx.user && typeof ctx.user === 'object'
|
||||
? ctx.user
|
||||
: null;
|
||||
const currentUser = stateUser || ctxUser || {};
|
||||
|
||||
const warehouseId = Number(
|
||||
currentUser.store_id
|
||||
|| currentUser.warehouse_id
|
||||
|| (ctxUser && (ctxUser.store_id || ctxUser.warehouse_id))
|
||||
|| 0
|
||||
);
|
||||
if (!Number.isInteger(warehouseId) || warehouseId <= 0) {
|
||||
throw this.createBusinessError('缺少当前用户仓库上下文 store_id', 400);
|
||||
}
|
||||
|
||||
const pickUserId = Number(
|
||||
currentUser.employees_id
|
||||
|| currentUser.operator_id
|
||||
|| currentUser.id
|
||||
|| (ctxUser && (ctxUser.employees_id || ctxUser.operator_id || ctxUser.id))
|
||||
|| 0
|
||||
);
|
||||
if (!Number.isInteger(pickUserId) || pickUserId <= 0) {
|
||||
throw this.createBusinessError('未获取到操作人上下文', 401);
|
||||
}
|
||||
|
||||
const taskRows = await ctx.model.query(`
|
||||
SELECT
|
||||
t.id AS task_id
|
||||
FROM wms_wave_pick_task t
|
||||
WHERE t.warehouse_id = :warehouseId
|
||||
AND t.pick_user_id = :pickUserId
|
||||
AND t.status IN (0, 1, 2)
|
||||
ORDER BY t.id DESC
|
||||
LIMIT 1
|
||||
`, {
|
||||
replacements: {
|
||||
warehouseId,
|
||||
pickUserId,
|
||||
},
|
||||
type: ctx.model.QueryTypes.SELECT,
|
||||
});
|
||||
|
||||
const taskRow = Array.isArray(taskRows) && taskRows.length > 0 ? taskRows[0] : null;
|
||||
const taskId = Number(taskRow && taskRow.task_id || 0);
|
||||
|
||||
return {
|
||||
task_id: Number.isInteger(taskId) && taskId > 0 ? taskId : null,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询拣货任务详情。
|
||||
*
|
||||
@ -835,7 +904,13 @@ class PickSystemService extends Service {
|
||||
}
|
||||
|
||||
const warehouseId = Number(taskRow.warehouse_id || 0);
|
||||
const pickMode = Number(taskRow.pick_mode || 0);
|
||||
const taskOrderColumnSet = await this.getTableColumnSet('wms_wave_pick_task_order');
|
||||
const taskWaveColumnSet = await this.getTableColumnSet('wms_wave_pick_task_wave');
|
||||
const boxColumnSet = await this.getTableColumnSet('wms_wave_pick_task_box');
|
||||
const taskOrderWarehouseFilterSql = taskOrderColumnSet.has('warehouse_id') ? ' AND pto.warehouse_id = :warehouseId' : '';
|
||||
const taskWaveWarehouseFilterSql = taskWaveColumnSet.has('warehouse_id') ? ' AND ptw.warehouse_id = :warehouseId' : '';
|
||||
const boxWarehouseFilterSql = boxColumnSet.has('warehouse_id') ? ' AND b.warehouse_id = :warehouseId' : '';
|
||||
const boxExtraSelect = [];
|
||||
if (boxColumnSet.has('ref_label')) {
|
||||
boxExtraSelect.push('b.ref_label');
|
||||
@ -857,9 +932,10 @@ class PickSystemService extends Service {
|
||||
pto.box_no
|
||||
FROM wms_wave_pick_task_order pto
|
||||
WHERE pto.task_id = :taskId
|
||||
${taskOrderWarehouseFilterSql}
|
||||
ORDER BY pto.id ASC
|
||||
`, {
|
||||
replacements: { taskId },
|
||||
replacements: { taskId, warehouseId },
|
||||
type: ctx.model.QueryTypes.SELECT,
|
||||
}),
|
||||
ctx.model.query(`
|
||||
@ -870,17 +946,63 @@ class PickSystemService extends Service {
|
||||
b.box_status AS status${boxExtraSelect.length > 0 ? `,\n ${boxExtraSelect.join(',\n ')}` : ''}
|
||||
FROM wms_wave_pick_task_box b
|
||||
WHERE b.task_id = :taskId
|
||||
${boxWarehouseFilterSql}
|
||||
ORDER BY b.id ASC
|
||||
`, {
|
||||
replacements: { taskId },
|
||||
replacements: { taskId, warehouseId },
|
||||
type: ctx.model.QueryTypes.SELECT,
|
||||
}),
|
||||
]);
|
||||
|
||||
const normalizedTaskOrderRows = Array.isArray(taskOrderRows) ? taskOrderRows : [];
|
||||
const orderIds = [ ...new Set(normalizedTaskOrderRows
|
||||
let orderIds = [ ...new Set(normalizedTaskOrderRows
|
||||
.map(row => Number(row && row.order_id || 0))
|
||||
.filter(orderIdItem => Number.isInteger(orderIdItem) && orderIdItem > 0)) ];
|
||||
let taskWaveCount = 0;
|
||||
let orderSource = 'task_order';
|
||||
const derivedWaveIds = [];
|
||||
|
||||
if (orderIds.length === 0 && [ 1, 5 ].includes(pickMode)) {
|
||||
const taskWaveRows = await ctx.model.query(`
|
||||
SELECT
|
||||
ptw.wave_id
|
||||
FROM wms_wave_pick_task_wave ptw
|
||||
WHERE ptw.task_id = :taskId
|
||||
${taskWaveWarehouseFilterSql}
|
||||
ORDER BY ptw.id ASC
|
||||
`, {
|
||||
replacements: { taskId, warehouseId },
|
||||
type: ctx.model.QueryTypes.SELECT,
|
||||
});
|
||||
|
||||
const normalizedTaskWaveRows = Array.isArray(taskWaveRows) ? taskWaveRows : [];
|
||||
taskWaveCount = normalizedTaskWaveRows.length;
|
||||
const fallbackWaveIds = [ ...new Set(normalizedTaskWaveRows
|
||||
.map(row => Number(row && row.wave_id || 0))
|
||||
.filter(waveId => Number.isInteger(waveId) && waveId > 0)) ];
|
||||
derivedWaveIds.push(...fallbackWaveIds.slice(0, 5));
|
||||
|
||||
if (fallbackWaveIds.length > 0) {
|
||||
const orderModel = await this.getOrderModel(warehouseId);
|
||||
const fallbackOrderRows = await orderModel.findAll({
|
||||
where: {
|
||||
wave_id: {
|
||||
[this.app.Sequelize.Op.in]: fallbackWaveIds,
|
||||
},
|
||||
warehouse_id: warehouseId,
|
||||
},
|
||||
attributes: [ 'id' ],
|
||||
raw: true,
|
||||
});
|
||||
|
||||
orderIds = [ ...new Set((Array.isArray(fallbackOrderRows) ? fallbackOrderRows : [])
|
||||
.map(row => Number(row && row.id || 0))
|
||||
.filter(orderIdItem => Number.isInteger(orderIdItem) && orderIdItem > 0)) ];
|
||||
if (orderIds.length > 0) {
|
||||
orderSource = 'task_wave_fallback';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const pickingRows = orderIds.length > 0
|
||||
? await ctx.model.Picking.findAll({
|
||||
@ -895,6 +1017,10 @@ class PickSystemService extends Service {
|
||||
})
|
||||
: [];
|
||||
|
||||
ctx.logger.info(
|
||||
`[pick.wavePickTaskDetail] task_id=${taskId} pick_mode=${pickMode} warehouse_id=${warehouseId} task_order_count=${normalizedTaskOrderRows.length} task_wave_count=${taskWaveCount} derived_order_ids_count=${orderIds.length} picking_rows_count=${Array.isArray(pickingRows) ? pickingRows.length : 0} order_source=${orderSource} order_id_samples=${JSON.stringify(orderIds.slice(0, 5))} wave_id_samples=${JSON.stringify(derivedWaveIds)}`
|
||||
);
|
||||
|
||||
const pickingSpaceIds = [ ...new Set((Array.isArray(pickingRows) ? pickingRows : [])
|
||||
.map(row => Number(row && row.space_id || 0))
|
||||
.filter(spaceId => Number.isInteger(spaceId) && spaceId > 0)) ];
|
||||
@ -955,7 +1081,6 @@ class PickSystemService extends Service {
|
||||
});
|
||||
|
||||
const pickingSummary = this.buildPickingSummary(pickingDetails);
|
||||
const pickMode = Number(taskRow.pick_mode || 0);
|
||||
const pickingView = await this.buildPickingView({
|
||||
pickMode,
|
||||
taskId,
|
||||
|
||||
@ -1,15 +1,37 @@
|
||||
'use strict';
|
||||
|
||||
const Service = require('egg').Service;
|
||||
const SUPPORTED_BUSINESS_TYPES = [ 'STOCK', 'RECEIPT', 'PICKING' ];
|
||||
|
||||
class PrintTemplateService extends Service {
|
||||
/**
|
||||
* 标准化并校验业务类型
|
||||
* @param {string} businessType 业务类型
|
||||
* @param {boolean} required 是否必填
|
||||
* @return {string|null} 标准化后的业务类型
|
||||
*/
|
||||
normalizeAndValidateBusinessType(businessType, required = true) {
|
||||
const normalizedBusinessType = String(businessType || '').trim().toUpperCase();
|
||||
if (!normalizedBusinessType) {
|
||||
if (required) {
|
||||
throw new Error('business_type 参数不能为空');
|
||||
}
|
||||
return null;
|
||||
}
|
||||
if (!SUPPORTED_BUSINESS_TYPES.includes(normalizedBusinessType)) {
|
||||
throw new Error(`business_type 参数非法,仅支持:${SUPPORTED_BUSINESS_TYPES.join('、')}`);
|
||||
}
|
||||
return normalizedBusinessType;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定业务类型的模板列表
|
||||
* @param {string} businessType 业务类型
|
||||
* @return {Promise<Array>} 模板列表
|
||||
*/
|
||||
async listTemplatesByType(businessType) {
|
||||
return await this.getTemplatesByType(businessType);
|
||||
const normalizedBusinessType = this.normalizeAndValidateBusinessType(businessType);
|
||||
return await this.getTemplatesByType(normalizedBusinessType);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -24,12 +46,15 @@ class PrintTemplateService extends Service {
|
||||
try {
|
||||
// 1. 获取所有业务类型及打印项
|
||||
const businessTypeItems = await this.getBusinessTypesAndItem();
|
||||
const businessTypes = Object.keys(businessTypeItems);
|
||||
const businessTypes = SUPPORTED_BUSINESS_TYPES;
|
||||
|
||||
// 2. 查询所有打印模板,按业务类型分组
|
||||
const templates = await ctx.model.PrintTemplate.findAll({
|
||||
where: {
|
||||
status: 'ACTIVE',
|
||||
business_type: {
|
||||
[Op.in]: SUPPORTED_BUSINESS_TYPES,
|
||||
},
|
||||
warehouse_id: {
|
||||
[Op.or]: [ warehouseId, null ],
|
||||
},
|
||||
@ -67,7 +92,7 @@ class PrintTemplateService extends Service {
|
||||
type: 'category',
|
||||
businessType,
|
||||
children,
|
||||
printItems: businessTypeItems[businessType].groupList || [],
|
||||
printItems: businessTypeItems[businessType] ? (businessTypeItems[businessType].groupList || []) : [],
|
||||
editable: false,
|
||||
deletable: false,
|
||||
isGeneral: false,
|
||||
@ -89,13 +114,14 @@ class PrintTemplateService extends Service {
|
||||
async getTemplatesByType(businessType) {
|
||||
const { ctx, app } = this;
|
||||
const { Op } = app.Sequelize;
|
||||
const normalizedBusinessType = this.normalizeAndValidateBusinessType(businessType);
|
||||
|
||||
const warehouseId = ctx.user.store_id;
|
||||
try {
|
||||
const templates = await ctx.model.PrintTemplate.findAll({
|
||||
where: {
|
||||
status: 'ACTIVE',
|
||||
business_type: businessType,
|
||||
business_type: normalizedBusinessType,
|
||||
warehouse_id: {
|
||||
[Op.or]: [ warehouseId, null ],
|
||||
},
|
||||
@ -119,10 +145,17 @@ class PrintTemplateService extends Service {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存打印模板(创建或更新)
|
||||
* @param {Object} data 模板数据
|
||||
* @return {Promise<Object>} 保存结果
|
||||
*/
|
||||
async save(data) {
|
||||
const { ctx } = this;
|
||||
const warehouseId = ctx.user.store_id;
|
||||
const { id, template_name, business_type, page_width, page_height, template_content } = data;
|
||||
const normalizedBusinessType = this.normalizeAndValidateBusinessType(business_type, !id);
|
||||
try {
|
||||
if (id) {
|
||||
// 更新现有模板
|
||||
@ -137,20 +170,24 @@ class PrintTemplateService extends Service {
|
||||
throw new Error('模板不存在或无权限');
|
||||
}
|
||||
|
||||
await template.update({
|
||||
const updatePayload = {
|
||||
template_name,
|
||||
business_type,
|
||||
page_width,
|
||||
page_height,
|
||||
template_content,
|
||||
});
|
||||
};
|
||||
if (normalizedBusinessType) {
|
||||
updatePayload.business_type = normalizedBusinessType;
|
||||
}
|
||||
|
||||
await template.update(updatePayload);
|
||||
|
||||
return { message: '模板更新成功', code: 200 };
|
||||
}
|
||||
// 创建新模板
|
||||
await ctx.model.PrintTemplate.create({
|
||||
template_name,
|
||||
business_type,
|
||||
business_type: normalizedBusinessType,
|
||||
page_width,
|
||||
page_height,
|
||||
template_content,
|
||||
@ -166,6 +203,11 @@ class PrintTemplateService extends Service {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建打印模板
|
||||
* @param {Object} data 模板数据
|
||||
* @return {Promise<Object>} 创建结果
|
||||
*/
|
||||
async createTemplate(data = {}) {
|
||||
const { ctx } = this;
|
||||
const warehouseId = ctx.user.store_id;
|
||||
@ -178,13 +220,27 @@ class PrintTemplateService extends Service {
|
||||
template_content = [],
|
||||
is_default = false,
|
||||
} = data;
|
||||
|
||||
if (!String(template_name || '').trim()) {
|
||||
throw new Error('template_name 参数不能为空');
|
||||
}
|
||||
|
||||
if (page_width === undefined || page_width === null || String(page_width).trim() === '') {
|
||||
throw new Error('page_width 参数不能为空');
|
||||
}
|
||||
|
||||
if (page_height === undefined || page_height === null || String(page_height).trim() === '') {
|
||||
throw new Error('page_height 参数不能为空');
|
||||
}
|
||||
|
||||
const normalizedBusinessType = this.normalizeAndValidateBusinessType(business_type);
|
||||
const platform = 'default';
|
||||
const template_type = 'CUSTOM';
|
||||
const template_url = '';
|
||||
|
||||
const existingTemplate = await ctx.model.PrintTemplate.findOne({
|
||||
where: {
|
||||
business_type,
|
||||
business_type: normalizedBusinessType,
|
||||
platform,
|
||||
template_type,
|
||||
warehouse_id: warehouseId,
|
||||
@ -222,7 +278,7 @@ class PrintTemplateService extends Service {
|
||||
try {
|
||||
created = await ctx.model.PrintTemplate.create({
|
||||
template_name,
|
||||
business_type,
|
||||
business_type: normalizedBusinessType,
|
||||
page_width,
|
||||
page_height,
|
||||
template_content,
|
||||
|
||||
@ -0,0 +1,15 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
async up(queryInterface, Sequelize) {
|
||||
await queryInterface.addColumn('wms_wave_strategy', 'wave_prefix', {
|
||||
type: Sequelize.STRING(5),
|
||||
allowNull: true,
|
||||
comment: '策略波次前缀(优先于仓库前缀)',
|
||||
});
|
||||
},
|
||||
|
||||
async down(queryInterface, Sequelize) {
|
||||
await queryInterface.removeColumn('wms_wave_strategy', 'wave_prefix');
|
||||
},
|
||||
};
|
||||
@ -0,0 +1,27 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
/**
|
||||
* 为打印台电脑表新增上次登录时间字段。
|
||||
* @param {import('sequelize').QueryInterface} queryInterface 查询接口
|
||||
* @param {import('sequelize')} Sequelize Sequelize 实例
|
||||
* @returns {Promise<void>} 无返回值
|
||||
*/
|
||||
async up(queryInterface, Sequelize) {
|
||||
await queryInterface.addColumn('wms_print_computer', 'last_login_time', {
|
||||
type: Sequelize.DATE,
|
||||
allowNull: true,
|
||||
comment: '上次登录时间',
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* 回滚删除打印台电脑表的上次登录时间字段。
|
||||
* @param {import('sequelize').QueryInterface} queryInterface 查询接口
|
||||
* @param {import('sequelize')} Sequelize Sequelize 实例
|
||||
* @returns {Promise<void>} 无返回值
|
||||
*/
|
||||
async down(queryInterface, Sequelize) {
|
||||
await queryInterface.removeColumn('wms_print_computer', 'last_login_time');
|
||||
},
|
||||
};
|
||||
17
methods/changes/2026.05.13-system-01.json
Normal file
17
methods/changes/2026.05.13-system-01.json
Normal file
@ -0,0 +1,17 @@
|
||||
[
|
||||
{
|
||||
"version": "2026.05.13-system-01",
|
||||
"date": "2026-05-13",
|
||||
"summary": "完善 print.send 的 API 文档与返回说明",
|
||||
"methods": [
|
||||
"print.send"
|
||||
],
|
||||
"notes": [
|
||||
"补充请求参数说明:computerId、printer、template、data、type 标为必填,count、timestamp 保持可选。",
|
||||
"补充 template 的子字段说明:page_width、page_height、template_content。",
|
||||
"补充响应结构:flag、code、message、printId;其中成功时 code=200。",
|
||||
"补充错误码说明:1001 对应不支持的打印类型,504 对应打印任务发送失败(包含打印机不存在、脱机、通讯失败等场景)。"
|
||||
],
|
||||
"type": "updated"
|
||||
}
|
||||
]
|
||||
File diff suppressed because it is too large
Load Diff
@ -6823,6 +6823,277 @@
|
||||
"description": "查询失败"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"method": "order.print.getWavePlatformPrintData",
|
||||
"description": "按波次 IDs 获取平台打印中间态数据,自动过滤快递未完全分配的波次,返回 waveGroups(波次 -> 平台 -> 订单)结构",
|
||||
"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(必须与当前用户上下文 store_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": "total_platforms",
|
||||
"type": "number",
|
||||
"description": "所有波次内平台分组总数(累加)"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "wave_ids",
|
||||
"type": "array",
|
||||
"description": "通过过滤的波次ID数组"
|
||||
},
|
||||
{
|
||||
"name": "waveGroups",
|
||||
"type": "array",
|
||||
"description": "主返回结构:按波次分组(波次 -> 平台 -> 订单)",
|
||||
"children": [
|
||||
{
|
||||
"name": "wave_id",
|
||||
"type": "number",
|
||||
"description": "波次ID"
|
||||
},
|
||||
{
|
||||
"name": "wave_no",
|
||||
"type": "string",
|
||||
"description": "波次号"
|
||||
},
|
||||
{
|
||||
"name": "order_count",
|
||||
"type": "number",
|
||||
"description": "该波次下订单总数"
|
||||
},
|
||||
{
|
||||
"name": "platforms",
|
||||
"type": "array",
|
||||
"description": "波次下的平台分组",
|
||||
"children": [
|
||||
{
|
||||
"name": "platform",
|
||||
"type": "string",
|
||||
"description": "平台编码"
|
||||
},
|
||||
{
|
||||
"name": "platform_name",
|
||||
"type": "string",
|
||||
"description": "平台名称"
|
||||
},
|
||||
{
|
||||
"name": "order_count",
|
||||
"type": "number",
|
||||
"description": "该平台订单数"
|
||||
},
|
||||
{
|
||||
"name": "orders",
|
||||
"type": "array",
|
||||
"description": "订单列表(逐单中间态)",
|
||||
"children": [
|
||||
{
|
||||
"name": "wave_id",
|
||||
"type": "number",
|
||||
"description": "波次ID"
|
||||
},
|
||||
{
|
||||
"name": "wave_no",
|
||||
"type": "string",
|
||||
"description": "波次号"
|
||||
},
|
||||
{
|
||||
"name": "order_id",
|
||||
"type": "number",
|
||||
"description": "订单ID"
|
||||
},
|
||||
{
|
||||
"name": "order_no",
|
||||
"type": "string",
|
||||
"description": "订单号(delivery_order_code 或 source_order_codes)"
|
||||
},
|
||||
{
|
||||
"name": "store_id",
|
||||
"type": "number",
|
||||
"description": "货主ID"
|
||||
},
|
||||
{
|
||||
"name": "warehouse_id",
|
||||
"type": "number",
|
||||
"description": "仓库ID"
|
||||
},
|
||||
{
|
||||
"name": "platform",
|
||||
"type": "string",
|
||||
"description": "平台编码"
|
||||
},
|
||||
{
|
||||
"name": "platform_name",
|
||||
"type": "string",
|
||||
"description": "平台名称"
|
||||
},
|
||||
{
|
||||
"name": "waybill_code",
|
||||
"type": "string",
|
||||
"description": "运单号"
|
||||
},
|
||||
{
|
||||
"name": "print_data",
|
||||
"type": "object",
|
||||
"description": "打印中间态(详见 printer_data_builder.buildPlatformRequestSkeleton 输出)"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "platform_groups",
|
||||
"type": "array",
|
||||
"description": "兼容字段:按平台分组结果(保留以兼容旧客户端)",
|
||||
"children": [
|
||||
{
|
||||
"name": "platform",
|
||||
"type": "string",
|
||||
"description": "平台编码"
|
||||
},
|
||||
{
|
||||
"name": "platform_name",
|
||||
"type": "string",
|
||||
"description": "平台名称"
|
||||
},
|
||||
{
|
||||
"name": "order_count",
|
||||
"type": "number",
|
||||
"description": "该平台订单数"
|
||||
},
|
||||
{
|
||||
"name": "orders",
|
||||
"type": "array",
|
||||
"description": "逐单中间态(字段同 order_list 元素)"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "order_list",
|
||||
"type": "array",
|
||||
"description": "兼容字段:逐单平台打印中间态明细(保留以兼容旧客户端)",
|
||||
"children": [
|
||||
{
|
||||
"name": "wave_id",
|
||||
"type": "number",
|
||||
"description": "波次ID"
|
||||
},
|
||||
{
|
||||
"name": "wave_no",
|
||||
"type": "string",
|
||||
"description": "波次号"
|
||||
},
|
||||
{
|
||||
"name": "order_id",
|
||||
"type": "number",
|
||||
"description": "订单ID"
|
||||
},
|
||||
{
|
||||
"name": "order_no",
|
||||
"type": "string",
|
||||
"description": "订单号(delivery_order_code 或 source_order_codes)"
|
||||
},
|
||||
{
|
||||
"name": "store_id",
|
||||
"type": "number",
|
||||
"description": "货主ID"
|
||||
},
|
||||
{
|
||||
"name": "warehouse_id",
|
||||
"type": "number",
|
||||
"description": "仓库ID"
|
||||
},
|
||||
{
|
||||
"name": "platform",
|
||||
"type": "string",
|
||||
"description": "平台编码"
|
||||
},
|
||||
{
|
||||
"name": "platform_name",
|
||||
"type": "string",
|
||||
"description": "平台名称"
|
||||
},
|
||||
{
|
||||
"name": "waybill_code",
|
||||
"type": "string",
|
||||
"description": "运单号"
|
||||
},
|
||||
{
|
||||
"name": "print_data",
|
||||
"type": "object",
|
||||
"description": "打印中间态(详见 printer_data_builder.buildPlatformRequestSkeleton 输出)"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "ext",
|
||||
"type": "object",
|
||||
"description": "扩展字段",
|
||||
"children": [
|
||||
{
|
||||
"name": "missing_wave_ids",
|
||||
"type": "array",
|
||||
"description": "传入但不存在的 wave_id 列表"
|
||||
},
|
||||
{
|
||||
"name": "filtered_wave_ids",
|
||||
"type": "array",
|
||||
"description": "被过滤掉的波次,每项含 wave_id、reason"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"errors": [
|
||||
{
|
||||
"code": "400",
|
||||
"description": "warehouse_id 或 wave_ids 缺失或格式错误"
|
||||
},
|
||||
{
|
||||
"code": "500",
|
||||
"description": "查询失败"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
@ -6832,7 +7103,7 @@
|
||||
"list": [
|
||||
{
|
||||
"method": "print.send",
|
||||
"description": "print.send 接口",
|
||||
"description": "发送打印任务到打印电脑,并记录打印单",
|
||||
"isNeedAuth": false,
|
||||
"isNeedLogin": true,
|
||||
"headers": [
|
||||
@ -6847,55 +7118,105 @@
|
||||
{
|
||||
"name": "computerId",
|
||||
"type": "string",
|
||||
"required": false,
|
||||
"required": true,
|
||||
"source": "body",
|
||||
"description": "computerId 参数"
|
||||
"description": "打印电脑 ID"
|
||||
},
|
||||
{
|
||||
"name": "count",
|
||||
"type": "number",
|
||||
"required": false,
|
||||
"source": "body",
|
||||
"description": "count 参数"
|
||||
"description": "打印份数,可选"
|
||||
},
|
||||
{
|
||||
"name": "data",
|
||||
"type": "object",
|
||||
"required": false,
|
||||
"required": true,
|
||||
"source": "body",
|
||||
"description": "data 参数"
|
||||
"description": "打印业务数据对象,字段由模板和 type 决定"
|
||||
},
|
||||
{
|
||||
"name": "printer",
|
||||
"type": "string",
|
||||
"required": false,
|
||||
"required": true,
|
||||
"source": "body",
|
||||
"description": "printer 参数"
|
||||
"description": "打印机名称"
|
||||
},
|
||||
{
|
||||
"name": "template",
|
||||
"type": "object",
|
||||
"required": false,
|
||||
"required": true,
|
||||
"source": "body",
|
||||
"description": "template 参数"
|
||||
"description": "打印模板对象;type=customize 时通常需要包含 page_width、page_height、template_content",
|
||||
"children": [
|
||||
{
|
||||
"name": "page_width",
|
||||
"type": "number",
|
||||
"required": true,
|
||||
"description": "页面宽度(mm)"
|
||||
},
|
||||
{
|
||||
"name": "page_height",
|
||||
"type": "number",
|
||||
"required": true,
|
||||
"description": "页面高度(mm)"
|
||||
},
|
||||
{
|
||||
"name": "template_content",
|
||||
"type": "array",
|
||||
"required": false,
|
||||
"description": "模板内容数组"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "timestamp",
|
||||
"type": "string",
|
||||
"required": false,
|
||||
"source": "body",
|
||||
"description": "timestamp 参数"
|
||||
"description": "业务时间戳,可选"
|
||||
},
|
||||
{
|
||||
"name": "type",
|
||||
"type": "string",
|
||||
"required": false,
|
||||
"required": true,
|
||||
"source": "body",
|
||||
"description": "type 参数"
|
||||
"description": "打印类型;当前实现支持 customize、express"
|
||||
}
|
||||
],
|
||||
"response": [],
|
||||
"errors": []
|
||||
"response": [
|
||||
{
|
||||
"name": "flag",
|
||||
"type": "string",
|
||||
"description": "全局调用结果标识,成功时为 success,失败时为 failure"
|
||||
},
|
||||
{
|
||||
"name": "code",
|
||||
"type": "number",
|
||||
"description": "业务状态码;成功时为 200,失败时通常为 1001 或 504"
|
||||
},
|
||||
{
|
||||
"name": "message",
|
||||
"type": "string",
|
||||
"description": "返回信息"
|
||||
},
|
||||
{
|
||||
"name": "printId",
|
||||
"type": "number",
|
||||
"description": "打印记录 ID;任务入库成功后返回,失败时若已生成记录也会返回"
|
||||
}
|
||||
],
|
||||
"errors": [
|
||||
{
|
||||
"code": "1001",
|
||||
"description": "不支持的打印类型"
|
||||
},
|
||||
{
|
||||
"code": "504",
|
||||
"description": "打印任务发送失败(如打印机不存在、打印机脱机、打印服务通讯失败)"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"method": "print.getPrintResult",
|
||||
@ -13335,7 +13656,7 @@
|
||||
"type": "object",
|
||||
"required": true,
|
||||
"source": "body",
|
||||
"description": "策略配置对象;仅支持 receive_mode、auto_allocate_bin、auto_allocate_express(是否自动分配快递)、auto_allocate_storage(是否自动分配储位)、allow_mix_batch、allow_temp_storage、storage_separation、print_recharge_price(面单充值元/单,支持 2 位小数)、max_daily_inbound、remark"
|
||||
"description": "策略配置对象;仅支持 receive_mode、auto_allocate_bin、auto_allocate_express(是否自动分配快递)、auto_allocate_storage(是否自动分配储位)、allow_mix_batch、allow_temp_storage、storage_separation、print_recharge_price(面单充值元/单,支持 2 位小数)、max_daily_inbound、remark、waybill_custom_display_type(面单自定义显示类型:1=隐藏,2=商品名称和数量,3=拣货库位和条码和数量,4=拣货库位和条码后5位和数量,5=拣货库位商品名称条码和数量)"
|
||||
}
|
||||
],
|
||||
"response": [],
|
||||
@ -14497,7 +14818,7 @@
|
||||
"type": "object",
|
||||
"required": false,
|
||||
"source": "body",
|
||||
"description": "筛选白名单字段(object,可选)。仅支持下列字段过滤,且禁止传入 warehouse_id / warehouseId:\n- wave_id(等值)\n- wave_no(模糊)\n- wave_type(等值)\n- wave_status(等值,接口固定叠加状态 0/1)\n- creator(模糊)\n- logistics_name(模糊)\n- item_part_type(等值)\n- item_part(模糊)\n- item_snapshot_key(模糊)\n- item_detail_machine(模糊)\n- distinguish_express(等值)\n- total_orders_min / total_orders_max(范围)\n- processed_orders_min / processed_orders_max(范围)\n- storage_assignment_status(等值,string,可选,取值:未分配、部分分配、已分配;默认不传不做限制)。过滤语义:已分配=聚合后全部 fin;部分分配=不含 error,且既不是全 none,也不是全 fin;未分配=全 none 或包含 error(异常并入未分配筛选集合)。说明:返回字段 storage_assignment_status 的展示值保持不变,包含 error 时仍可显示“分配异常”;此处 where 的过滤语义会把异常计入“未分配”,以避免把过滤语义与展示值混淆。\n- source(可选,number)来源过滤:0=普通波次(正常后台操作),1=管理后台策略任务,2=PDA策略任务;不传则不过滤。"
|
||||
"description": "筛选白名单字段(object,可选)。仅支持下列字段过滤,且禁止传入 warehouse_id / warehouseId:\n- wave_id(等值)\n- wave_no(模糊)\n- wave_type(等值)\n- wave_status(等值,接口固定叠加状态 0/1)\n- creator(模糊)\n- logistics_name(模糊)\n- item_part_type(等值)\n- item_part(模糊)\n- item_snapshot_key(模糊)\n- item_detail_machine(模糊)\n- distinguish_express(等值)\n- total_orders_min / total_orders_max(范围)\n- processed_orders_min / processed_orders_max(范围)\n- express_assignment_status(等值,string,可选,英文枚举,取值:unassigned、partially_assigned、assigned;语义:按快递分配聚合判断,assigned 表示聚合后全部 fin,partially_assigned 表示部分已分配且不含 error,unassigned 表示全 none 或包含 error(异常并入未分配集合))。\n- print_assignment_status(等值,string,可选,英文枚举,取值:unprinted、partially_printed、printed;语义:按打印分配聚合判断,printed 表示聚合后全部已打印)。\n- storage_assignment_status(等值,string,可选,取值:未分配、部分分配、已分配;默认不传不做限制)。过滤语义:已分配=聚合后全部 fin;部分分配=不含 error,且既不是全 none,也不是全 fin;未分配=全 none 或包含 error(异常并入未分配筛选集合)。说明:返回字段 storage_assignment_status 的展示值保持不变,包含 error 时仍可显示“分配异常”;此处 where 的过滤语义会把异常计入“未分配”,以避免把过滤语义与展示值混淆。\n- source(可选,number)来源过滤:0=普通波次(正常后台操作),1=管理后台策略任务,2=PDA策略任务;不传则不过滤。\n说明:express_assignment_status 与 print_assignment_status 要求使用英文枚举值;storage_assignment_status 仍向后兼容中文展示值。若传入的枚举值不在允许集合内,接口会返回 400(参数校验失败),并在 message 中说明错误字段与允许取值。"
|
||||
}
|
||||
],
|
||||
"response": [
|
||||
|
||||
128
printer_data_template/cainiao.json
Normal file
128
printer_data_template/cainiao.json
Normal file
@ -0,0 +1,128 @@
|
||||
{
|
||||
"cmd": "print",
|
||||
"requetID": "001778509572949",
|
||||
"version": "1.0",
|
||||
"task": {
|
||||
"taskID": "001778509572949",
|
||||
"preview": {},
|
||||
"printer": "打印机",
|
||||
"documents": [
|
||||
|
||||
|
||||
|
||||
{
|
||||
"documentID": "773420508667648",
|
||||
"contents": [{
|
||||
"templateURL": "http://cloudprint.cainiao.com/cloudprint/template/getStandardTemplate.json?template_id=288948",
|
||||
|
||||
|
||||
"data": {
|
||||
"_dataFrom": "waybill",
|
||||
"_page_config": {
|
||||
"REQUEST_LAYERED_IMAGE": false
|
||||
},
|
||||
"adsInfo": {
|
||||
"adId": "5376",
|
||||
"advertisementType": "DEFAULT",
|
||||
"bannerUrl": "https://ad-cdn.cainiao.com/img/3093/1747622191034_250.png",
|
||||
"miniBannerUrl": "https://ad-cdn.cainiao.com/img/3093/1747622218523_927.png",
|
||||
"useCustomArea": false
|
||||
},
|
||||
"cpCode": "STO",
|
||||
"extraInfo": {
|
||||
"appKey": "23535631",
|
||||
"displayPrivacyBackup": false,
|
||||
"templateAdDisplayUp": true,
|
||||
"encryptWaybillCode": "uOg1jZ401LHupUYC4i7OXw%3D%3D"
|
||||
},
|
||||
"needEncrypt": false,
|
||||
"needReplaceRecipientInfoToTemplate": false,
|
||||
"orderChannelLogo": "https://cdn-cloudprint.cainiao.com/waybill-print/templateImages/tao.png",
|
||||
"orderChannelsType": "TB",
|
||||
"packageInfo": {
|
||||
"goodsDescription": "商品",
|
||||
"height": 1,
|
||||
"id": "1",
|
||||
"items": [{
|
||||
"count": 1,
|
||||
"name": "商品名称"
|
||||
}],
|
||||
"length": 1,
|
||||
"volume": 0,
|
||||
"weight": 0,
|
||||
"width": 1
|
||||
},
|
||||
"parent": false,
|
||||
"realCpCode": "STO",
|
||||
"recipient": {
|
||||
"address": {
|
||||
"city": "广州市",
|
||||
"detail": "AES:fh/VUbbPVBtXXRLMkz/aRhq7lK7IeXsLFk4yA/E5VYjD3QjzPoO/yVzEEsyBi62kmoRUz3Z0IVirOeWr0bnKYg==",
|
||||
"district": "番禺区",
|
||||
"province": "广东省"
|
||||
},
|
||||
"mobile": "AES:Y1keIwFeVCi7cxaZMN2kpA==",
|
||||
"name": "AES:g3tXHYOSthtqY6oZ4oOqHQ==",
|
||||
"secretConsigneeMobile": "18466138293-4726",
|
||||
"tid": "3301304088914008581"
|
||||
},
|
||||
"routingExtraInfo": {},
|
||||
"routingInfo": {
|
||||
"consolidation": {
|
||||
"name": "广州中转包"
|
||||
},
|
||||
"origin": {
|
||||
"code": "510902",
|
||||
"name": "广东广州白云区太和公司"
|
||||
},
|
||||
"receiveBranch": {
|
||||
"code": "510075",
|
||||
"name": "广东广州番禺区南村公司"
|
||||
},
|
||||
"routeCode": "XX9 013",
|
||||
"sortation": {
|
||||
"name": "600"
|
||||
},
|
||||
"startCenter": {},
|
||||
"terminalCenter": {}
|
||||
},
|
||||
"secretWaybillChannel": "14",
|
||||
"secretWaybillType": "recipientSecret",
|
||||
"sender": {
|
||||
"address": {
|
||||
"city": "",
|
||||
"detail": "广东省广州市白云区钟落潭良沙*****",
|
||||
"district": "",
|
||||
"province": ""
|
||||
},
|
||||
"mobile": "13800000000",
|
||||
"name": "吴**"
|
||||
},
|
||||
"shippingOption": {
|
||||
"code": "STANDARD_EXPRESS",
|
||||
"title": "标准快递"
|
||||
},
|
||||
"waybillCode": "773420508667648"
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
},
|
||||
{
|
||||
|
||||
"templateURL": "http://cloudprint.cainiao.com/cloudprint/customArea/queryCustomAreaList4Top.json?custom_area_id=6474956",
|
||||
"data": {
|
||||
"CustomControl": "#0 D1341089-1-1 商品总数 【1】\rE1区01-19-01 988948487 【1】\r\r验视员:太和"
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
|
||||
]
|
||||
}
|
||||
}
|
||||
61
printer_data_template/douyin.json
Normal file
61
printer_data_template/douyin.json
Normal file
File diff suppressed because one or more lines are too long
48
printer_data_template/jd.json
Normal file
48
printer_data_template/jd.json
Normal file
@ -0,0 +1,48 @@
|
||||
{
|
||||
|
||||
"orderType": "PRINT",
|
||||
"version": "2",
|
||||
|
||||
"key": "001778509941716",
|
||||
"parameters": {
|
||||
|
||||
"printName": "打印机",
|
||||
|
||||
|
||||
"contents": [
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
{
|
||||
"tempUrl": "https://template-content.jd.com/template-oss?tempCode=jdky76x130",
|
||||
|
||||
"printData": "qfJVGzg6XlGK1E/wOVvkE9YuUGEtuO+WNmfEdPZsvBdOW/4HOHSYwmwD7JSTsMvMZkYANPvI6J9UA1kq8lbMoCCeFQBKfiA4ZQ8FwSZet0Qx9FsccAhkM9O2zSd27jl/pmVaZkLDgxMOF/riW0DAhEz9i201C4ukq7Wy7EKjwu3AN7IK/iz/6R4VK2YZKCPeaSRpr7WjbtwTAPEvw+X8iyVeIqzK/NiscmwP8tCRKNLO91IhYMUwXYv7maNX0KHJqsdfyufIPb2vx2A6fRwHm/35i1wWCDqjMw9RVFarLQ6GdL3sA1jo3KPuP0EwEaZbQskBpDimDr4FqZfoYc1T3MR7r5HL65rX9lWOlm04U4JoR6DrYpBHX5lW0ncECMD8E/Q2J+Vdy9swfYh6lSx3maTUgUWOLYvKQY5iVPW3+FdMLSMSuhKooI3yJHzPiFDj/s2qFRKbAA5U46A1Rjne83cPgnn6KE2YHabzbKMoBf/dO+iv6jFB5AclWC5jU043oA1JkpxeYGRpp/waVR/PO0izjGSrldHMPTC7WqZUh9ijcYQRJjABwgp7TdXQcWTu2xVel8ht89QMF6ztHXio6LhTlmxOeJZD7dl0MPJTho1zXqHm+qVRc4N20uGBKZlFF6yhDMcFyYF7I3q01YedofetLCW2HLBe7lfFd7xRuOUT8b1BrRdx4tPKzBjlxnUggU8hzVriC0vcYP0eS7sArvy6xS0yIlD2Lszzos8TdhWi3PJkfrhzE+I5R3TQIrjh3IY7Z1ThIDmPcEoM6uGm1As/D1KjmU1bGEBsrFIh/W9CNP2LBOgYehViazxS8JoCqWFPlNYT+5dBzv4vTdbyyp9mbHuOl5A/Ob9HEifeU/L4m/Ohw0Hhqb0FzhbOwjCF8x3JqKqBLhjqEwKX2Rijin7u+orzUad9WHA6cG0kiV/rykvNeELZHLJcysIEK1+fdFmAW1spEwGf5wW06aOk9Ya3OIHYnMO5nsqa0h/b/szrIZLi2Du72qr9WjP1BIj9ex5EGOgZRdxL/VkOmx9W9lIGTaxqgI7k2ga/Z7wXoe8zztq2A6gpqtyHFkpvsZHYl/0sZNgb0zEGMgfvB7Mqb0Y2EJ8jV4LLcfaGOF/1w5T0XpA7SiTEI+Pw9OtKDH7J9F6QO0okxCPj8PTrSgx+yQ5pS1Fbk3FeR0vMZ0jEjNcOaUtRW5NxXkdLzGdIxIzXDmlLUVuTcV5HS8xnSMSM1w5pS1Fbk3FeR0vMZ0jEjNcOaUtRW5NxXkdLzGdIxIzX+uVqSOXVfVJNP02qnFkkXFkxWy6ko7XYxXiz+ckmdC6F5WqGihfMWbYHQEq8HVxb40fsxsKXiI4ykH01NVIsdOGxmwoM6QwCm+LoZLyGYCMoYwbfL5UUOHWOz31uDpbkwTjYYlSIkKNEQqTfADO1uAIB3geh9xnppA8GzqvViKmL5okxw+O0bM/H428bIFy7rphcgufmq/MutTtbUMd8EUMfu0kqhaEraIqc777v2+HM3FgJ4SNj5rr0mTYBdfkD1H+bJPKzs2rlzqzEBbb7Vqq7hVJh4emW5Cab34bbuSso+cI+5uaSte2SYlvJpnWv2RuFmGNeojzfRrJPeQFWoZ62O51AWpmt66oe8kxPVoXDP5erX1G+tmluno2FRcB/EMenRYAI97sRC2NAMvRNmN+BWSOPwNJjyMu70IJFuN3K1zebUu0DHmSHc3nb5PVoIoIyurFnU1e2AN7J4lBuhWss6HJj8Q2p2DD6TH6vkLHNGvZMCvedJIX+oaRXj3Luy8l96hMQ84zKVPiBsDD82b5NHOPw72eyjwuVqBO55mJsTVIhMWBHChWJZT+qkUs2N74wYxT2BPa7fXLoohWpmPcH3JIi98lhMwhY/RW1hhUJBHf/mlGdAs9Ed8yaMZe7LjWyNzjoCS5/UYT9/FFPceSgHj0wzpR0i0Q3xr5hZj+ZpP9nyhxLQyC0/2w88nLUKWu5zubIshdk50zrrRuaEfi8EyIJ3dS4fzzXoamd6Cl1MpmV6S79SeK8P1ZPiRtIAYMrtSBDBD7J2ONlHSfIbpHkcaT7GQqYYvkOBeHDJbCRaWVARnBEOr/feXR600T29U8XC7O3/9DrZjR6x+2BJHOMYbPNmQ92sGZR7PDc11JjjI7AkvvbnENvauuI8gtJd2p1bF4jwnrBXBvuOdL6pVeQAIbNzuygO5EagPmE4BKlwUwTODhmvNKy/6oSH/2j6re7nfrelcxnvjMbYtdOslgWZcyfSDbpQI09US03aYMgl0lJDonUkBok4PWFPwCcDpwH0tIbyhLBBKvWwh2x8HL8/VaahzOTiFf6rCdpA5etkjChgakqMK5dDyW9+FoOTQJWIITU4CvyaP69U2MSU/UM1MCVs5c4KRmZEIhrCFVOHyOuJIG9MXxfdyj3rPbXH3/vhhYuf+DneGvh1zYqVCCgOQtSL7smE5TL1UP5KCAiUU/IKG1i1p/tMFP9AJoIWVwS5fwErtGaQdTJIx5EXeR6cDQsP1RN26on/zOoECgJIKtQO4fxboFayaouAlyVoGTE32EpJF9d79D2P+rWbSCScjKWs8htlZxz47FcBC9kj0X16/56Uw71lfBZmCnvpLmJUYqG2ftW/8sf6ui2TWydi5N5UXyDHN40U5CDUWA9eUjuHcIIgkKw8cf1zGrqCQHqw1V2n3vrRO8TvpHmDgcg/UJH+7ZKDROhFqLU1X3WU4maCxAshFpaAME2h39au3ZOACnJLCNQ63zQzgMErcL8XxOEmfY8xCJxAdOxmqG1/6CEavGUfrBUvhj9xXCFXMwG5Kxm7yphOLGBrf6lfnqpgyV4x/SL/9k01U4Ww55JrX5MyBcUhAoPCBVGUvEUI2xcNFtWB/u9JuvUjspJOIzStD0ZrgUj8fY17OH4oy5WUzjlDJImY/YQRHZbr/RbJWLhqxDiUgkGzoI+VCX6i7m6rHVdzJ5mVPAHaui6mfplSn1QRTjnTC0t+yYF9pzXutDTQ+ftlWGwPvXVSP1+OfxQXQ8jVoj5QAEFYZ3XFdeBJL0EVxHwCWZ6BqwVx6DhK7llFsqait9KQjLkFZMrnO8Qx2YZfT6RC/DxIrkArePz5d1j7vMeprnp/w4l7g9Tl5cZPlZN4iyLGEq1tmBXPYcvz11QYW5raOofs5PB9wggi+nbK9jD/0g9vLGAlAvQrCQmgEmgkwg9Qsma3KP/L6Hfn8SJ4nFRfEpxkbBj6f7Gbi7jF0QH6POGehIOm5u2fYNAdMy/uKpb4SUg8rMlH8qrnWKCTfq0cluc5VOLlwafIcSSnGt7fzY/8HBfFo3mhCg60tffYIoeeUxzVbxHI+LJZbq0NFCoBsqYO5HxpUdZiW4lDkg24epJKcFcsoQYfMGeOSPY68fK6ZDuQ9Ia0Y0wR8lpueI9ToJuq5vP732OVSS8+PAAg3/zFfPGsM+bdnS3CvO9KG1ym6YLpIIMdRjTGflNFPmC/HSLW2/fYQJ6Qel8lYMg1WyjCVJyGLZzzTdKmANIgrG4R87XWVvCS1SHPxBpx97OqnIthuupcguBuOzpmv7Aryqa6Mi63hbYlUa9ui0mck1r2uEPXasj4M3Cnufz2Ni2ZIYveq8DLOC5RNo55L1EpTTRQ6FDOj96QzpbRsOh550YlfXRCI4iYU5d2kTHRZo9Wbx3DtAW43I+wjruiS5tbCBD1vl6q8EHPnLNdHvgXdJS0CBgNNripdt78zlYh2jNC2Yq280jDIHdrJjZVBPl8kscLuWDo6TweFYad+MuUlHBi78V84WiK79/O71svuWZpCP3mpvT71d0Y+q4twFbRwTcf9Flkar/R/L7FmjHWw8hiKGVKctrB/bBWMM2fhbcVd/6jJbSiNkxdA2LGJdnvyR43ZdAou2KKYVy2r7/78askSuBg6605Xo/2ci/wwps9n1EcNb3cVHekujmdQ5hAIYAVY85/GAh64UpUO2IiIpZkhQ2PIL/R5JntqABfX9t8oYQHuoUwMvHQcKGz/VRqywWRLIWEZqLhuTH4gimGLk8u/LL0gCKVKF1EejUyUPtCBYSsaAFWrM/r5+UmhjWJJUY0dOFr0GKx/+XeDLjT1FlVEKAgKutWTQbe4P8iFJAVG8bHA88tt7B18u9E29kYJmbygXizgXoUiBJ3uUlInxpayCU8siBBciU/KuypoPcGSDAmIo+JM47wETCWAS6f58U+M/tHgdWEVVPmSZ5GlS8pggFN1b9rgKg+Pkxh+WqPxutkDIjR0sY6I2K655M9jaWQmMaFVPH5P63V63ItB4oWoNN609Tqi/eklgEQigpc5e5Kc5ehCsa6JUe0C9Yp11nfto3wC8M",
|
||||
"customTempUrl": "https://storage.360buyimg.com/jdl-template/customs-1de75d30-f0ba-4260-9236-fa12fd4c2fa1.1631601180779.txt",
|
||||
"customData":
|
||||
|
||||
{
|
||||
"GoodsInfo": "#0 B1340984-1-1 商品总数 【1】\nE2区10-03-02 6971238692630 【1】 0\n"
|
||||
},
|
||||
|
||||
"addData": {
|
||||
"sender": {
|
||||
"name": "吴先生",
|
||||
"mobile": "180****7208",
|
||||
"address": "广东省广州市白云区钟落潭良沙二路32号天豹云仓供应链管理有限公司"
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
]
|
||||
|
||||
}
|
||||
}
|
||||
64
printer_data_template/kuaishou.json
Normal file
64
printer_data_template/kuaishou.json
Normal file
@ -0,0 +1,64 @@
|
||||
{
|
||||
|
||||
"cmd": "print",
|
||||
"requestID": "001778509772549",
|
||||
"version": "1.0",
|
||||
"task": {
|
||||
|
||||
"taskID": "001778509772549",
|
||||
"printer": "打印机",
|
||||
"preview": {},
|
||||
|
||||
"documents": [
|
||||
|
||||
|
||||
|
||||
{
|
||||
"documentID": "776442886175852",
|
||||
"waybillCode": "776442886175852",
|
||||
"ksOrderFlag": false,
|
||||
"contents": [{
|
||||
|
||||
|
||||
"addData": {
|
||||
"senderInfo": {
|
||||
"address": {
|
||||
"cityName": "",
|
||||
"countryCode": "CHN",
|
||||
"detailAddress": "良****路888号",
|
||||
"districtName": "",
|
||||
"provinceName": ""
|
||||
},
|
||||
|
||||
"contact": {
|
||||
"mobile": "151****7068",
|
||||
"name": "吴**"
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
"encryptedData": "7D5F32EE40A6C4732D5AD98E4DD20BC6BE6D369BE4180B00B9C987A0E936058B393353B5F8C0CC8CD43AFFA54A9C7A0E8A717A79DF9952A90F21DBA36BE7D548F67B2255C7CA8617C4BF7604547F77A1A6180B19958A9559536AD619E3CF1E19680B031CD7CD382DD9944951C21D42B2FF60D839E8EE95217DE1B71650176724207C890475F6F8638202D5EEABA72AC77385D1FE957D3A268B41D005A229CCD91FE9FD6885F78D7C674058DB59F391A8EB22713A8D3D2CFD2A8D33A0E6FAE679518EB3021C2B44090044A623D62184339C9DDCE62DD21EB4218369C225688C7002BD1B23FBF1918DF457652529868FB4A7980EDFE66E6E360A74F349BC1569E091138CCBE33B16B526A978E777A50CAB2550A6835D320A140B28376C9B58CB16C935656729D507F69019D65C7F58E13F0A2761CD8C07E1BA439B50136414F37981213F090FB5C6E43C6A417743E8ED0FF223FB83E1FBE7F14D504562C1B874B0C47806E818EC63D0C6A11B9777AF5B5D20E3752A9396E23B375D04B27271220BC573CB43D9EB94DA72AFCC1565D4C08389FE1D63FE9418D6554E05CBD1950FD1D0096B82079BBC4A96EE9B08950B8C4FB34C8E972CE0107A2A14F7B14F8553BE28CD10DD3C33FE16282995DF97D06E6C831051C917E87324F9C90496E5B17471D66665DFE237F0B82669C4B1C8B77C81279884575FCF8D3C94FF64189B0632C349BC59E17DC919FDE15A90A08703CAD4723403909735B97C1339BE611F09FDD496DC3E78FD07A35C1EB2E71366C0A35DB9026A42B3B509BE085A88610F87D24096BF88C50F7889DD27229F38FC59C13964AA1B28A7B1FE6E09A72FE51EE25ABCAE8ABE55AB4A453BB6DB4AB0B663F34D88D2BF6B836FF77A995690DC5BB1D74498EBB3CF245D7BD652BD3AFE8027959BF523B21CBE355F9268FB8FC226C1A08A609DC30DF5B81D2257423C918CD1F1081CA5C5FFB0E2A944D28E1E1134DB6E6F14728DF7A93421FC71C22C33EF8C8570561AE34B4E47FE45D885D90A7761F7EC994DD0C1FA23E0A9033F7F465DCC13184F46FABAA2570F760103FE795D3A2631FAFF9548657310173D17AA072B16AFD9E301B5C7374D2E1FBFC2CB724C45BA457D4FF54B6799EAFDEF5CD689C4F16F1C95C369D3C5491DFBD7CD022F0F1497AB5ED1CABF3EB0BEE75333AC5268BCFC7E7F3C4BC53B340C4E3810068088D1E193E31E4A9C06141FCB638D7E49D3E6600F2879DBAEF3BC61FDACAB821729DB91A7E584DC322297B0D3C7B1B0ACF91762087AA7A143065C58B736988F7F4BD89EC8DA576D28BD5205EE976EA08387852A2797240DEF31D6D0D17C124907DEECAD27EB19E03CEC5A489C853A99DC61C063DC386C4B24EF70CBE983CE555055BE5AB05D12E3B9262299144A1E1332EF33E83E51C2BFDADAE4EEB99DBB440E463EFD41AE5559B28A653595BAA6989F949D5A20B8330A971F235F7BCBC6E4E9141FBAF948D3EA8DB973CB67095820305A38B4A2722C67C03D54A98CCC7B87835AC2CB2BD0977C9D941BE05BF4401F6B4EFEA850776392AC3CA53F9F33AB79E9E495AA808EA28BCB2D5A9E03A6C6E8E3CF435D9D2DD5546A63592D91BEFB830873A5CE21218FA5298D36EC5F4655B54B1012AB36B298386BF24942757DCE625DFD482055745EA3044E981011860AED6E298D80F87958447E66D80FF9529B93E12A790668EFFD7CE0365C5320FD8B1D93764F1D21D4257F0CE58ABA326C9CEE591D5D11CE8FC829DF8FF8DB726D9C61DD0A8EF2A440107CBD469F320163E4515BCB8F8014AED3507A94C0CC77D41E40C04CD7303433D9E5164B68B4FD6AEF6466259B9C1E6DF49F1C364473628AD9AAC9D4D937F14FE76444919E0CF75FC2271782892C9F86D6EDB8D2977F56738724D639C3DA3A02E0637542EFDC9A3F4C676E832A025CF5619207BECD22EF3A5D76D19DAC6AC06C2004213FB743FEC5120C6BB43BB83D324D7C8C839E57D741D53B045C2E791919C182C1C907145C18CA4604AD3AEBF357FB2AF71081818182D8E4C46915B526CE75712B1EDC9D4F8B053B047762F2AC2F0882A8D96C1C5170E5A43D86054A71FF1B80D54218D19EECFB2B0205D28B433868BE6E95967DCB4547BA05FCEB2B7D04C4AC552589E91EECEAE565E9B32E985D02958CD1D3067A7923A3FA54CB5AA7DD702677C8450107A4332461F3B1A3F00C7997BBAB6E25C5F0A97E4546F457B169553B528BDA04CA8022B7E5B0FF2FD13ABE238D7532AF92EB9FA7B31A90ADD2C8600DED93A1840DF938D27C8E4DDD39D8A91C0BCA7367BD3006FAA5AE02B6132894CDBA83178322B35E5E2BA9144097D85E917ECE7FE0B9D281D5A644207C0529151E5920BBDBD0D06EBA3B46179635B017905AE51B465EDFA184E3140F11C890F70EBAC1F7645446B80DD2E399AE7F5F5E0E932AE04C682A891350307D84EFB4F9C23BF974948FBE96CFB0F8F5E638B6515E96CBDFE872A5CE4BA782CDFD4F",
|
||||
"signature": "d90bbd05e0d91fdc85d1ef7cdaf53400",
|
||||
"key": "M2Dw9oS9oNYaoF+xTZG+ZGaDigS90LrNvF9TteDqWgx93NdBboa1VyIY6tuCoUFyYIAbInDNgQOwryWJKm/L/1gB6TGq617hxZeed2/BVVQI9RMwHMdpJ0YjWCy+71OmRXStGiFAK7VOtHNzU9lFQhYh5osrzxQQLlrN8ZOzfxM=",
|
||||
"templateURL": "https://s1-11586.kwimgs.com/kos/nlav11586/EBST-EBSTO11.xml",
|
||||
"ver": "waybill_print_secret_version_1"
|
||||
|
||||
},
|
||||
{
|
||||
"customData": {
|
||||
"productInfo": "#0 B1340814-1-1 化妆品 商品总数 【2】\nE2区02-04-02 6973348850399;6974864094892 【2】 0\n\n验视员:"
|
||||
},
|
||||
"templateURL": "http://www.ye4s.com/mb/kuaishou.xml"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
|
||||
]
|
||||
|
||||
}
|
||||
}
|
||||
64
printer_data_template/pdd.json
Normal file
64
printer_data_template/pdd.json
Normal file
@ -0,0 +1,64 @@
|
||||
{
|
||||
|
||||
"ERPId": "001778509366293",
|
||||
"cmd": "print",
|
||||
"requestID": "001778509366293",
|
||||
"task": {
|
||||
"documents": [
|
||||
|
||||
|
||||
|
||||
{
|
||||
"contents": [{
|
||||
"addData": {
|
||||
"sender": {
|
||||
"address": {
|
||||
"city": "",
|
||||
"detail": "广东省广州市白云区钟落潭良沙二路32号天豹云仓供应链管理有限公司",
|
||||
"district": "",
|
||||
"province": ""
|
||||
},
|
||||
"mobile": "151****7068",
|
||||
"name": "吴**"
|
||||
}
|
||||
},
|
||||
"encryptedData": "nCGXTLX57Gy747SrsozPkx1eh8H2E5WU7MGcj3KxacD3TzcoaNPPiAFxtUZBU+YZrVW69kK/T6rXC2lzapP6qnT3vTYQJ8p4OBiUIKkzktG0HAnglg2im8lxFex1sYacjUrMJej4k9BCPgHkgcwmMna+LQ6jBL5Q4Fyr8v/37jSUOeDWKSwQC9vF0t1YKDqRakOT3PFuLsY/XOqeVdEJTFKcloISdvN+XIp3Sj1imV3fXK85In9lIGSndtpQzxWUQEoc8+NDiHxD41xmp1vCUKnRnXwaf6LJP3X+r9QAJ00v/CX+r7WTmZgbjV02UNzxov+xbIcBisI+9AdQhbaPSft9SxyUFzJDAYwh22iQUAB0d9HPmKs+KAMCA7A/Ot0btFzvIVLFp3l2U32aEfCpsaSL9MSPeYmMJp0tS5l0y36MhV8i2P09HnqwLGwd1X9tDmMkzUuOE0/BmigmCKDb2vt3JDsfqC7XEwSDjjuT22mbaf7uJ34hoDGOSdcUJtW16Tr44dblvRdReA8FF8fL0uveNiYsa8eWqFIQMkHa+gDyVGEafqSED/ojUt83ex+iOess9UaA3wSfqU3l/c2kcFduCPjLd5upPY+Q40ac4MTITuaID2ZJ6GY4IBMIRVQ2s4OGG3Wd9ZJWCsYEUnaZN8RIUjwCnIyqsOPcKlD6jsxe6dHYNdiP11TxSkjp0pj6i7qtvSFoQpKQBCmK+GtTR62ipecViZeiBqFEbuDxstnPqkj8bcYibvKNOp+5iWHVXQv5vDSMQflhXP0z+qbcTKtDJtkIMjV1zY1Or5+By3kOQTEzE2x9km1GzGgp7QqWoztA8P8yCDj99RtzMDLccQDJoYaOgBzb47Z1262OiofNDO8LbPrIqdrji6VZBFUiwJE28nw7wlyib/bAFqM4+HgeNiL21yadIOSrXWW4YvK1AtpeOjDso9Nl4d06ncwC3P1ITSl8si9/k2kWuPW9goZvfFXLxmswLPyRSLD1PusgcI0pu4o4MVXjjYOro+Ax0MphhLCmoWuM0/C2tE2Pgcr/Ye3GZdWQS2pDGKszJhgSR/tP3lc0yvRbOeLWU+MEpF2h+nL+JHWT3VysohVaL+ZR71lufRj2OJJxwNv/FsUzmhzSlGZMagKvm0F4e6wj7cwixsGXJoeRJszP/DLqPbMViVpbLvBe6zqiAevr8zSHaH0+UARzQ+Jdp1Yj8fc2iXzwJQEpSJUqTlv4CXsuCFdfpX/5Lz5veeBFqTwfeimhbhwuqjgUY00DJrQb7uCFoWIapA1DQ3qqpbPoqInrD/StMvD0oR+/wP3E7pkyirA6T2Rm5gqZcDygmJyuaHPOrRecbfzYJp1M9GVm1co63R7sSahnX/PfJH7HKNf3vqajT0YJ7mOcJwzsqz9sbQUMWuk/2oS9hWC+NXaRrs20kLhnP+hKg+tnrFR40E4SydhtVHOT1IBuS2GNxP6NpKSXWutRLOHhSMTx6TSci+aWvV3W4Cr31pCxX1ZIr38AvV8RDJbTMDxCFSmfza4Qw8EnIn25Z90qM/knDuHju3ixtD5vz5RqbUmnNbsjGbt7/YVg5MSLPaeG1fHE6VgP0npQTduCvz/unN+bkhNkYUD8lhsg7/Kbv4FJByrftMJVVhZ6ZDc/3acZ2IHTEQfOY6PwYGNRl8q9rPPSnoG3iWrgS33Nh7Zp/0xk9brdbDDoAA2NoOxiQvak/OTT5/qGxHTIHxz5SiBmltlpA5Zw+bcEHB9OwItdA1rywZrVrCpRY0zK8iGw+qUFqTEUN5ybT7557NHdJueiq6Wxw4czjNj8V7lTscxknUlw8zdwXfQsMAqDs8ogT8IyqjkaoIpDatE4qGB1TYR7JEBfrEXcCdMqqqlqj4tDo7oiNBAUka5SNKJ9z8WRjBQpEZgnMzaXE8aZmLCn6tbdo7XmHWGX+VkJCTZJvBDVi7ubM8+tdkynMLRPK6+uoMlPDGYDeKYfA9hGduFG/P6TiY+dpIrrKB2/HwQZCD0XwZv8D7bA0xnQSBlXcJDBVOshJA1gHppdqt0jdEOjMXyp9RwfP49lU90O6AuDI+imkYhGLh5WJXnsaQrw+cqvOb7dcpDS6sPQbzxaPp/9brK85x4z/yWw1UJbfjRybEoyTE2KXXKHqqN/MLJDlhSH1EI6uf+Jnq40Qh9+Zp72bLV+gNbovmFgNtJAlnDFji8wyW0H9iGWuKmlU7CNgxRozMZ7J+y+NbTDx5AjX4a0EiATpZsw8OKNtEN2K7RmVf5AusTcgN4uwgs95yDENyMomxU4hFB9f0AuvHla6XCBiMcsLMUGZiiBbeqASLtGH2/Oq7MxptOtDE3Mdy2MelmQdMwKaDUZ8+PF2WjqKcy5yw56jOlHlbCru4aomuf//Ck3LOXugvCzHscdVePxvTFeSFJsIYr4idUUuseOVGwaG3ftLW0YqLvh300rwEkQf5Wtj9EMXzGhD0FPLk+q5nD3vzi/puxuNILN1S/36krYjJBLfRfh2eaRY2st9Q==?v=11&pv=1",
|
||||
"signature": "MQktCwU3fF9H2C3PkcGm+eAtTIO/qOHVCUTfvbkxSVrM8VuyvYbq/Xkun4qItxUJuDsbl0oa1l8p1Wb2ZtMpQHgsOCMEQfeQrFZtzubYU1xayPv8+o4GYQ+GdPXueOJQ4hCyyrnGVjJSf/qV/LKWoUGsFrXN8jC1PapMdI93XEI=",
|
||||
"templateUrl": "https://file-link.pinduoduo.com/sto_one",
|
||||
|
||||
"userid": "",
|
||||
"ver": "11"
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"height": 240,
|
||||
"list": [{
|
||||
"fontSize": 28,
|
||||
"left": 2.08,
|
||||
"text": "#0 B1341067-1-1 良田 商品总数 【2】\rE2区08-05-02 皮带黑色;665835404213 【1】 0\rE2区08-04-02 皮带金色;600507 【1】 0\r",
|
||||
"top": 2.08,
|
||||
"width": 550
|
||||
}],
|
||||
"waterdata": {
|
||||
"text": ""
|
||||
},
|
||||
"width": 560
|
||||
},
|
||||
"templateURL": "http://www.ye4s.com/mb/pdd.xml"
|
||||
}
|
||||
],
|
||||
"documentID": "777408273892067"
|
||||
}
|
||||
|
||||
|
||||
|
||||
],
|
||||
"notifyType": [
|
||||
"print"
|
||||
],
|
||||
"preview": null,
|
||||
"previewType": "image",
|
||||
"printer": "打印机名称",
|
||||
"taskID": "001778509366293"
|
||||
}
|
||||
}
|
||||
41
printer_data_template/sph.json
Normal file
41
printer_data_template/sph.json
Normal file
@ -0,0 +1,41 @@
|
||||
{
|
||||
"command": "print",
|
||||
"version": "2.0",
|
||||
"requestID": "001778510051691",
|
||||
"taskList": [
|
||||
{
|
||||
"taskID": "772062370363221",
|
||||
"printInfo": "JTdCJTIycHJpbnREYXRhJTIyJTNBJTdCJTIyd2F5YmlsbElkJTIyJTNBJTIyNzcyMDYyMzcwMzYzMjIxJTIyJTJDJTIycHJpbnRUaW1lJTIyJTNBJTIyMjAyNiUyRjA1JTJGMTElMjAxOCUzQTEzJTIyJTJDJTIyc2VydmljZXMlMjIlM0ElNUIlNUQlMkMlMjJyZWNlaXZlck5hbWUlMjIlM0ElMjIlRTklOTklODgqKiUyMiUyQyUyMnJlY2VpdmVyUGhvbmUlMjIlM0ElMjIqKioqKioqNDE3OCUyMiUyQyUyMnJlY2VpdmVyQWRkcmVzcyUyMiUzQSUyMiVFOCVCRSVCRCVFNSVBRSU4MSVFNyU5QyU4MSVFNiVCMiU4OCVFOSU5OCVCMyVFNSVCOCU4MiVFNiU5NiVCMCVFNiVCMCU5MSVFNSVCOCU4MiVFNSVBNCVBNyVFNiVCMCU5MSVFNSVCMSVBRiVFOSU5NSU4NyVFNCVCQSVCRiVFOCVCRiU4OCVFNSU5MCU4OCVFNSVBRSVCNiVFNSU5QiVBRCVFNCVCOCU5QyVFNSU4QyVCQShHMjMwJUU1JThDJTk3KSUyMiUyQyUyMnNlbmRlck5hbWUlMjIlM0ElMjIlRTUlOTAlQjQqJUU3JTk0JTlGJTIyJTJDJTIyc2VuZGVyUGhvbmUlMjIlM0ElMjIxNSoqKioqKjA2OCUyMiUyQyUyMnNlbmRlckFkZHJlc3MlMjIlM0ElMjIlRTUlQjklQkYlRTQlQjglOUMlRTclOUMlODElRTUlQjklQkYlRTUlQjclOUUlRTUlQjglODIlRTclOTklQkQlRTQlQkElOTElRTUlOEMlQkElRTklOTIlOUYlRTglOTAlQkQlRTYlQkQlQUQlRTklOTUlODclRTQlQjglOUMlRTUlODclQTQlRTUlOEMlOTclRTglQjclQUYxNSVFNSU4RiVCNzAwMSUyMiUyQyUyMnNpdGVDb2RlJTIyJTNBJTIyNTI2MTI2JTIyJTJDJTIyZXdheWJpbGxPcmRlcklkJTIyJTNBJTIyMzczNjMwNTA0NTM1MzQwNjcxMiUyMiUyQyUyMnByb2R1Y3RUeXBlTmFtZSUyMiUzQSUyMiUyMiUyQyUyMnNob3J0QWRkcmVzcyUyMiUzQSUyMjIwMC1TMDQlMjAzMzMlMjIlMkMlMjJiYWdBZGRyJTIyJTNBJTIyJUU2JUIyJTg4JUU5JTk4JUIzJUU0JUI4JUFEJUU4JUJEJUFDJUU1JThDJTg1JTIyJTJDJTIybWFyayUyMiUzQSUyMjIwMC1TMDQlMjAzMzMlMjIlMkMlMjJ5dW5kYVl6bSUyMiUzQSUyMiUyMiUyQyUyMnl1bmRhSW5uZXJwcm92aW5jZSUyMiUzQSUyMiUyMiUyQyUyMnl1bmRhTWR0eXBlJTIyJTNBJTIyJTIyJTJDJTIyeXVuZGFNZGpjJTIyJTNBJTIyJTIyJTJDJTIyeXptJTIyJTNBJTIyJTIyJTJDJTIyZmluYWxBZGRyZXNzJTIyJTNBJTIyJTIyJTJDJTIycHJpbnRJbmZvJTIyJTNBJTIyJTIyJTJDJTIycHJlVHdvQ29kZSUyMiUzQSUyMiUyMiUyQyUyMnByb2R1Y3RDbnQlMjIlM0EwJTJDJTIyc3RvcmVOYW1lJTIyJTNBJTIyS0lOR0pPWSUyRiVFNSU4QSVCMiVFNiU4RCVCNyVFNiU5OSVCQSVFOCU4MyVCRCVFNiU5NSVCMCVFNyVBMCU4MSVFNSVCQSU5NyUyMiUyQyUyMmN1c3RvbWVyTm90ZXMlMjIlM0ElMjIlMjIlMkMlMjJtZXJjaGFudE5vdGVzJTIyJTNBJTIyJTIyJTJDJTIyb3JkZXJJZCUyMiUzQSUyMjM3MzYzMDUwNDUzNTM0MDY3MjAlMjIlMkMlMjJwcm9kdWN0SW5mb3NXaXRoUGFyYW1BbmRTa3UlMjIlM0ElNUIlMjJzcCUyMCUyMDAlMjAwJUU0JUJCJUI2JTIyJTVEJTJDJTIycHJvZHVjdEluZm9zV2l0aFBhcmFtJTIyJTNBJTVCJTIyc3AlMjAlMjAwJUU0JUJCJUI2JTIyJTVEJTJDJTIycHJvZHVjdEluZm9zT25seSUyMiUzQSU1QiUyMnNwJTIwMCVFNCVCQiVCNiUyMiU1RCUyQyUyMnN1bVByb2R1Y3RDbnQlMjIlM0EwJTJDJTIyaXNXeFNob3AlMjIlM0F0cnVlJTJDJTIyc2hvd0dpZnRMb2dvJTIyJTNBZmFsc2UlMkMlMjJpc09yZGVyVHlwZTElMjIlM0F0cnVlJTJDJTIydmlydHVhbFRlbE51bWJlciUyMiUzQSUyMjE4NCoqKio3Mjk3JUU4JUJEJUFDNDE3OCUyMiUyQyUyMnNpdGVOYW1lJTIyJTNBJTIyJTIyJTdEJTJDJTIydGVtcGxhdGUlMjIlM0ElN0IlMjJ0ZW1wbGF0ZUlkJTIyJTNBJTIyNjYzNDE4NzUwOCUyMiUyQyUyMnRlbXBsYXRlTmFtZSUyMiUzQSUyMiVFNyU5NCVCMyVFOSU4MCU5QSUyMiUyQyUyMnRlbXBsYXRlRGVzYyUyMiUzQSUyMiVFNCVCOCU4MCVFOCU4MSU5NCVFNSU4RCU5NSVFNiVBMCU4NyVFNSU4NyU4NiVFNiVBOCVBMSVFNiU5RCVCRiUyMiUyQyUyMnRlbXBsYXRlVHlwZSUyMiUzQSUyMnNpbmdsZSUyMiUyQyUyMm9wdGlvbkxpc3QlMjIlM0ElN0IlN0QlMkMlMjJvcHRpb25zJTIyJTNBJTVCJTdCJTIyb3B0aW9uSWQlMjIlM0EwJTJDJTIyZm9udFNpemUlMjIlM0EwJTJDJTIyaXNCb2xkJTIyJTNBZmFsc2UlMkMlMjJpc09wZW4lMjIlM0F0cnVlJTdEJTJDJTdCJTIyb3B0aW9uSWQlMjIlM0ExJTJDJTIyZm9udFNpemUlMjIlM0EwJTJDJTIyaXNCb2xkJTIyJTNBZmFsc2UlMkMlMjJpc09wZW4lMjIlM0F0cnVlJTdEJTJDJTdCJTIyb3B0aW9uSWQlMjIlM0EyJTJDJTIyZm9udFNpemUlMjIlM0EwJTJDJTIyaXNCb2xkJTIyJTNBZmFsc2UlMkMlMjJpc09wZW4lMjIlM0FmYWxzZSU3RCUyQyU3QiUyMm9wdGlvbklkJTIyJTNBMyUyQyUyMmZvbnRTaXplJTIyJTNBMCUyQyUyMmlzQm9sZCUyMiUzQWZhbHNlJTJDJTIyaXNPcGVuJTIyJTNBZmFsc2UlN0QlMkMlN0IlMjJvcHRpb25JZCUyMiUzQTQlMkMlMjJmb250U2l6ZSUyMiUzQTAlMkMlMjJpc0JvbGQlMjIlM0FmYWxzZSUyQyUyMmlzT3BlbiUyMiUzQWZhbHNlJTdEJTJDJTdCJTIyb3B0aW9uSWQlMjIlM0E1JTJDJTIyZm9udFNpemUlMjIlM0EwJTJDJTIyaXNCb2xkJTIyJTNBZmFsc2UlMkMlMjJpc09wZW4lMjIlM0FmYWxzZSU3RCUyQyU3QiUyMm9wdGlvbklkJTIyJTNBNiUyQyUyMmZvbnRTaXplJTIyJTNBMCUyQyUyMmlzQm9sZCUyMiUzQWZhbHNlJTJDJTIyaXNPcGVuJTIyJTNBZmFsc2UlN0QlMkMlN0IlMjJvcHRpb25JZCUyMiUzQTclMkMlMjJmb250U2l6ZSUyMiUzQTAlMkMlMjJpc0JvbGQlMjIlM0FmYWxzZSUyQyUyMmlzT3BlbiUyMiUzQWZhbHNlJTdEJTVEJTJDJTIyY29kZSUyMiUzQTAlMkMlMjJjcmVhdGVUaW1lJTIyJTNBJTIyMTcyOTM4NjM1NSUyMiUyQyUyMnVwZGF0ZVRpbWUlMjIlM0ElMjIxNzI5Mzg2MzU1JTIyJTJDJTIyaXNEZWZhdWx0JTIyJTNBdHJ1ZSUyQyUyMmRlbGl2ZXJ5SWQlMjIlM0ElMjJTVE8lMjIlMkMlMjJ0ZW1wbGF0ZVVybCUyMiUzQSUyMmh0dHBzJTNBJTJGJTJGbW1lYy1zaG9wLTEyNTgzNDQ3MDcuY29zLmFwLXNoYW5naGFpLm15cWNsb3VkLmNvbSUyRnNob3AlMkZwdWJsaWMlMkYyMDI2LTAzLTExJTJGNjRiZTg2ZmUtMmYyMi00ZjEyLWE2YzctMGYzMmVmMmFmZGJjLmh0bWwlMjIlMkMlMjJjdXN0b21Db25maWclMjIlM0ElN0IlMjJ0b3AlMjIlM0E3NTQlMkMlMjJsZWZ0JTIyJTNBMjQlMkMlMjJ3aWR0aCUyMiUzQTcxMiUyQyUyMmhlaWdodCUyMiUzQTMwMCU3RCUyQyUyMndpZHRoJTIyJTNBNzYlMkMlMjJoZWlnaHQlMjIlM0ExMzAlN0QlN0Q=",
|
||||
"printNum": {
|
||||
"curNum": 1,
|
||||
"sumNum": 20
|
||||
},
|
||||
"splitControl": 1,
|
||||
"showDeliveryLogo": 0,
|
||||
"customInfo": {
|
||||
"templateUrl": "https://ye4s.wms.gztbyc.com/spa.html",
|
||||
"data": {
|
||||
"description": "#0 B1340938-1-1 良田-轻货 商品总数 【4】<br>Y区04-02-02 6957815275250 【2】 0<br>临时库位 清洁剂纸箱2瓶装 【1】 0<br>临时库位 评价有礼 【1】 0<br> "
|
||||
}
|
||||
},
|
||||
"extendData": {
|
||||
"sender": {
|
||||
"address": {
|
||||
"provinceName": "",
|
||||
"cityName": "",
|
||||
"countyName": "",
|
||||
"detailInfo": "广东省广州市白云区钟落潭良沙二路32号天豹云仓供应链管理有限公司"
|
||||
},
|
||||
"userName": "劲捷",
|
||||
"telNumber": "18025435602"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"printType": 1,
|
||||
" size": {
|
||||
"width": 76,
|
||||
"height": 130
|
||||
},
|
||||
"printer": "打印机"
|
||||
}
|
||||
37
printer_data_template/xhs.json
Normal file
37
printer_data_template/xhs.json
Normal file
@ -0,0 +1,37 @@
|
||||
{
|
||||
"cmd": "print",
|
||||
"requetID": "001778510207128",
|
||||
"version": "1.0",
|
||||
"task": {
|
||||
"taskID": "001778510207128",
|
||||
"preview": false,
|
||||
"printer": "打印机",
|
||||
"documents": [
|
||||
{
|
||||
"documentID": "73707922786906",
|
||||
"contents": [
|
||||
{
|
||||
"encryptedData": "AES:I+wXXcF3iJT+MtdqV2DAWlRLVNAWfpwNPSNezEjTLcT6/JTCQwtPEKKDz8WLiEzn/swcaoZSyytVEWFuI5T80CflTpeigjCdXlqB48v6hrdT3Et0y/N2VpbqqhrpjlRtgqbtSZU3cTCU8BcdRorHUuNG9CJ2G+bszHBxAUQGHDHDeh92kZDGEIU0DxUJq0N7NJXhMFqSl3InYr8hfIBkUdbd/A/XxKZ6nyfx0chBcZ1bWDLGqCuuNutl8uCJbzEwsq0YIZkHRn1rYZJJNkW/U9rhlG4D6v5bMHkMBeFjqEOXBFfSmKdMrsQZle/kGCh8aRmn7yrLd+XiBw0L8wamfemhGZyfS+yVndfONd5w14EYvLVwnmjmadVCuKUukm9BhdTk86j1heP0+xAEbYMPoBE0nFhi36ZTMXYo+I3MLhydEe8X8OEslt9Voy5F/zduYWsUo2kQ/y1lXQam+M4dmTKJv2SiXpdok81nfN76o57Q2v+Kxl5Zk6ES+ZsKlKNsHkEJrD7bGPPU/dHqS42rw3TZmWrniIs4A/qso79uxbi4s/gYHwLRMTphL+g52e1NydecRZ0YkhgHXlHnzFJJW9GEMq5NpYyQ5J4VDtOWj44pU38h9vA1mA/t+OfYEw+P9rrYuD0K/crmg7H1nt1g9wPnQ7myfZrbTnqVz/tCTPNGAUqTRC4zJjo72HvBwj9tIfCBtwhoiFIXVkmWVD0+l89GEox2U6D7zk/sCuvJ0gnV+NPC9jQdDlZUTPWY/MuwaA7g2T/jlC9neGiqRywhMVH5B8SKM4hZYsxHYOp8eO9IQWv0WU96CLEQyuK+dy6ZxIzbjK1DW7wSppqZLM9fvoNUF6lWZOiVfASAqqd7diLiGOMxDyppQBCkcmvuIrkoosW8Iwpju47NgDkd747RbUjEB8/Ezpln2e5x8UiLr0J2bKj0Ra5OJFhgUF8a1KLUzQ1IN9358GpWZ0AUYAa87GN7/RJTxmwI5r8d3OAb/ekxqherTP+eTMnrbHOhzm80Az/Jrb9BdZ0bdCnsuwqgvGWEknYcApZBiqwuZKk/JOOQrD3tbMJU6NOzMJvd7bvNlqZKBcCKh4fjLPuNtKb56g==",
|
||||
"templateURL": "https://cloudprint.xiaohongshu.com/template/standard/15/1",
|
||||
"ver": "waybill_print_xiaohongshu_secret"
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"item": [],
|
||||
"order": [
|
||||
"#0 E1341360-1-1 箱包 商品总数 【2】\nE2区23-08-02 6938215881227 【1】\nE2区22-06-01 6938215884631 【1】\n "
|
||||
],
|
||||
"buyerMemo": [
|
||||
""
|
||||
],
|
||||
"sellerMemo": [
|
||||
""
|
||||
]
|
||||
},
|
||||
"templateURL": "https://cloudprint.xiaohongshu.com/template/standard/7/2"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
97
test/app/controller/system.order.print.platformData.test.js
Normal file
97
test/app/controller/system.order.print.platformData.test.js
Normal file
@ -0,0 +1,97 @@
|
||||
'use strict';
|
||||
|
||||
const assert = require('node:assert/strict');
|
||||
const OrderPrintService = require('../../../app/service/systemMethods/order/print');
|
||||
const { createServiceContext } = require('../../support/order_service_test_helper');
|
||||
|
||||
describe('test/app/controller/system.order.print.platformData.test.js', () => {
|
||||
it('should delegate getWavePlatformPrintData to systems.orderPrint with destructured params', async () => {
|
||||
const ctx = createServiceContext(100000);
|
||||
let capturedPayload = null;
|
||||
const expectedData = {
|
||||
summary: {
|
||||
total_waves: 1,
|
||||
total_orders: 1,
|
||||
total_platforms: 1,
|
||||
},
|
||||
waveGroups: [
|
||||
{
|
||||
wave_id: 9001,
|
||||
wave_no: 'W9001',
|
||||
order_count: 1,
|
||||
platforms: [
|
||||
{
|
||||
platform: 'jd',
|
||||
platform_name: '京东',
|
||||
order_count: 1,
|
||||
orders: [
|
||||
{
|
||||
order_id: 123,
|
||||
print_data: {
|
||||
platform: 'jd',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
wave_ids: [ 9001 ],
|
||||
platform_groups: [],
|
||||
order_list: [],
|
||||
ext: {
|
||||
missing_wave_ids: [],
|
||||
filtered_wave_ids: [],
|
||||
},
|
||||
};
|
||||
|
||||
ctx.service = {
|
||||
systems: {
|
||||
orderPrint: {
|
||||
async getWavePlatformPrintData(payload) {
|
||||
capturedPayload = payload;
|
||||
return expectedData;
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const service = new OrderPrintService(ctx);
|
||||
const result = await service.getWavePlatformPrintData({
|
||||
wave_ids: [ 9001, '9002' ],
|
||||
warehouse_id: 100000,
|
||||
ignored_field: 'ignored',
|
||||
});
|
||||
|
||||
assert.deepEqual(capturedPayload, {
|
||||
waveIds: [ 9001, '9002' ],
|
||||
warehouseId: 100000,
|
||||
});
|
||||
assert.equal(result.flag, 'success');
|
||||
assert.equal(result.code, 200);
|
||||
assert.equal(result.message, 'ok');
|
||||
assert.deepEqual(result.data, expectedData);
|
||||
});
|
||||
|
||||
it('should reject when wave_ids is empty', async () => {
|
||||
const ctx = createServiceContext(100000);
|
||||
ctx.service = {
|
||||
systems: {
|
||||
orderPrint: {
|
||||
async getWavePlatformPrintData() {
|
||||
return {};
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const service = new OrderPrintService(ctx);
|
||||
|
||||
await assert.rejects(async () => {
|
||||
await service.getWavePlatformPrintData({
|
||||
wave_ids: [],
|
||||
warehouse_id: 100000,
|
||||
});
|
||||
}, /wave_ids 必填,且必须为非空数组/);
|
||||
});
|
||||
});
|
||||
91
test/app/lib/printer_data_builder.test.js
Normal file
91
test/app/lib/printer_data_builder.test.js
Normal file
@ -0,0 +1,91 @@
|
||||
'use strict';
|
||||
|
||||
const assert = require('node:assert/strict');
|
||||
const PrinterDataBuilder = require('../../../app/lib/printer_data_builder');
|
||||
|
||||
describe('test/app/lib/printer_data_builder.test.js', () => {
|
||||
it('should keep documents, taskList and contents as arrays in the skeleton', () => {
|
||||
const result = PrinterDataBuilder.buildPlatformRequestSkeleton({
|
||||
platform: 'sph',
|
||||
order_express: {
|
||||
waybill_code: 'WB-001',
|
||||
},
|
||||
order_delivery: {
|
||||
name: '收件人',
|
||||
mobile: '13800000000',
|
||||
detail_address: '测试地址',
|
||||
},
|
||||
policy_config: {
|
||||
sender_name: '发件人',
|
||||
sender_tel: '13900000000',
|
||||
province_name: '广东省',
|
||||
city_name: '深圳市',
|
||||
district_name: '南山区',
|
||||
address: '发件地址',
|
||||
},
|
||||
template_sample: {
|
||||
cmd: 'print',
|
||||
requestID: 'REQ-001',
|
||||
version: '1.0',
|
||||
documents: [
|
||||
{
|
||||
documentID: 'root-doc-001',
|
||||
contents: [
|
||||
{
|
||||
text: 'root contents',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
taskList: [
|
||||
{
|
||||
taskID: 'root-task-001',
|
||||
documents: [
|
||||
{
|
||||
documentID: 'task-list-doc-001',
|
||||
contents: [
|
||||
{
|
||||
text: 'task list contents',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
task: {
|
||||
taskID: 'task-001',
|
||||
documents: [
|
||||
{
|
||||
documentID: 'task-doc-001',
|
||||
contents: [
|
||||
{
|
||||
text: 'task contents',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
assert.equal(result.request_skeleton.cmd, 'print');
|
||||
assert.ok(Array.isArray(result.request_skeleton.documents));
|
||||
assert.ok(Array.isArray(result.request_skeleton.taskList));
|
||||
assert.ok(Array.isArray(result.request_skeleton.task.documents));
|
||||
assert.ok(Array.isArray(result.request_skeleton.documents[0].contents));
|
||||
assert.ok(Array.isArray(result.request_skeleton.taskList[0].documents));
|
||||
assert.ok(Array.isArray(result.request_skeleton.taskList[0].documents[0].contents));
|
||||
assert.ok(Array.isArray(result.request_skeleton.task.documents[0].contents));
|
||||
assert.equal(result.request_skeleton.documents[0].documentID, 'root-doc-001');
|
||||
assert.equal(result.request_skeleton.taskList[0].taskID, 'root-task-001');
|
||||
assert.equal(result.request_skeleton.task.documents[0].documentID, 'task-doc-001');
|
||||
});
|
||||
|
||||
it('should expose the line break map for platform-specific reuse', () => {
|
||||
assert.deepEqual(PrinterDataBuilder.getLineBreakMap(), {
|
||||
LF: '\n',
|
||||
CR: '\r',
|
||||
CRLF: '\r\n',
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,133 @@
|
||||
'use strict';
|
||||
|
||||
const assert = require('node:assert/strict');
|
||||
const DeliveryOrderService = require('../../../../../app/service/systemMethods/order/deliveryOrder');
|
||||
const DeliveryExpectionOrderService = require('../../../../../app/service/systemMethods/order/deliveryExpectionOrder');
|
||||
|
||||
/**
|
||||
* 创建详情查询测试桩。
|
||||
* @param {Function} ServiceClass 目标 service 类。
|
||||
* @param {number} storeId 仓库ID。
|
||||
* @return {{ service: Object, calls: Object }} service 实例与调用记录。
|
||||
*/
|
||||
function createHarness(ServiceClass, storeId = 100321) {
|
||||
const calls = {};
|
||||
|
||||
const ctx = {
|
||||
app: {
|
||||
config: {},
|
||||
Sequelize: {
|
||||
Op: {
|
||||
in: Symbol.for('op.in'),
|
||||
},
|
||||
},
|
||||
},
|
||||
logger: {
|
||||
warn() {},
|
||||
},
|
||||
user: {
|
||||
store_id: storeId,
|
||||
},
|
||||
service: {
|
||||
systems: {
|
||||
operationLog: {
|
||||
async queryOrderLogs(query) {
|
||||
calls.queryOrderLogs = query;
|
||||
return {
|
||||
list: [{ id: 9001, operation_code: 'ORDER_CREATE' }],
|
||||
pagination: {
|
||||
page: 1,
|
||||
pageSize: 200,
|
||||
total: 1,
|
||||
totalPages: 1,
|
||||
},
|
||||
};
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const service = new ServiceClass(ctx);
|
||||
|
||||
service.getOrderModelByTableType = async (tableType, warehouseId) => {
|
||||
calls.orderModelTableType = tableType;
|
||||
calls.orderModelWarehouseId = warehouseId;
|
||||
return {
|
||||
async findOne(args) {
|
||||
calls.findOrderArgs = args;
|
||||
return {
|
||||
id: 99,
|
||||
warehouse_id: storeId,
|
||||
};
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
service.getOrderItemsModelByTableType = async (tableType, warehouseId) => {
|
||||
calls.orderItemsModelTableType = tableType;
|
||||
calls.orderItemsModelWarehouseId = warehouseId;
|
||||
return {
|
||||
async findAll(args) {
|
||||
calls.findOrderItemsArgs = args;
|
||||
return [{ id: 1, order_id: 99 }];
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
service.getOrderExpressesByOrderId = async orderId => {
|
||||
calls.expressOrderId = orderId;
|
||||
return [{ id: 11, order_id: 99, waybill_code: 'WB-001' }];
|
||||
};
|
||||
|
||||
return {
|
||||
service,
|
||||
calls,
|
||||
};
|
||||
}
|
||||
|
||||
describe('test/app/service/systemMethods/order/deliveryOrder.detail.defaultDispatch.test.js', () => {
|
||||
it('deliveryOrder.detail should use dispatch table by default and keep detail/items/expresses/logs shape', async () => {
|
||||
const { service, calls } = createHarness(DeliveryOrderService, 100321);
|
||||
|
||||
const result = await service.detail({
|
||||
id: 99,
|
||||
});
|
||||
|
||||
assert.equal(calls.orderModelTableType, 'dispatch');
|
||||
assert.equal(calls.orderItemsModelTableType, 'dispatch');
|
||||
assert.notEqual(calls.orderModelTableType, 'current');
|
||||
assert.notEqual(calls.orderItemsModelTableType, 'current');
|
||||
|
||||
assert.equal(calls.orderModelWarehouseId, 100321);
|
||||
assert.equal(calls.orderItemsModelWarehouseId, 100321);
|
||||
assert.equal(calls.findOrderArgs.where.id, 99);
|
||||
assert.equal(calls.findOrderItemsArgs.where.order_id, 99);
|
||||
assert.equal(calls.expressOrderId, 99);
|
||||
|
||||
assert.ok(result && typeof result === 'object');
|
||||
assert.ok(result.detail && typeof result.detail === 'object');
|
||||
assert.ok(Array.isArray(result.items));
|
||||
assert.ok(Array.isArray(result.expresses));
|
||||
assert.ok(Array.isArray(result.logs));
|
||||
});
|
||||
|
||||
it('deliveryExpectionOrder.detail should also use dispatch table by default', async () => {
|
||||
const { service, calls } = createHarness(DeliveryExpectionOrderService, 100321);
|
||||
|
||||
const result = await service.detail({
|
||||
id: 99,
|
||||
});
|
||||
|
||||
assert.equal(calls.orderModelTableType, 'dispatch');
|
||||
assert.equal(calls.orderItemsModelTableType, 'dispatch');
|
||||
assert.notEqual(calls.orderModelTableType, 'current');
|
||||
assert.notEqual(calls.orderItemsModelTableType, 'current');
|
||||
|
||||
assert.ok(result && typeof result === 'object');
|
||||
assert.ok(result.detail && typeof result.detail === 'object');
|
||||
assert.ok(Array.isArray(result.items));
|
||||
assert.ok(Array.isArray(result.expresses));
|
||||
assert.ok(Array.isArray(result.logs));
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,163 @@
|
||||
'use strict';
|
||||
|
||||
const assert = require('node:assert/strict');
|
||||
const EntrustOrderService = require('../../../../../app/service/systemMethods/order/entrustOrder');
|
||||
const ArchiveOrderService = require('../../../../../app/service/systemMethods/order/archiveOrder');
|
||||
|
||||
/**
|
||||
* 创建订单详情查询测试桩。
|
||||
* @param {Function} ServiceClass 目标 service 类。
|
||||
* @param {number} storeId 仓库ID。
|
||||
* @return {{ service: Object, calls: Object }} service 实例与调用记录。
|
||||
*/
|
||||
function createHarness(ServiceClass, storeId = 100321) {
|
||||
const calls = {};
|
||||
|
||||
const ctx = {
|
||||
app: {
|
||||
config: {},
|
||||
Sequelize: {
|
||||
Op: {
|
||||
in: Symbol.for('op.in'),
|
||||
},
|
||||
},
|
||||
},
|
||||
logger: {
|
||||
warn() {},
|
||||
},
|
||||
user: {
|
||||
store_id: storeId,
|
||||
},
|
||||
service: {
|
||||
systems: {
|
||||
operationLog: {
|
||||
async queryOrderLogs(query) {
|
||||
calls.queryOrderLogs = query;
|
||||
return {
|
||||
list: [{ id: 9001, operation_code: 'ORDER_CREATE' }],
|
||||
pagination: {
|
||||
page: 1,
|
||||
pageSize: 200,
|
||||
total: 1,
|
||||
totalPages: 1,
|
||||
},
|
||||
};
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const service = new ServiceClass(ctx);
|
||||
|
||||
service.getOrderModelByTableType = async (tableType, warehouseId) => {
|
||||
calls.orderModelTableType = tableType;
|
||||
calls.orderModelWarehouseId = warehouseId;
|
||||
return {
|
||||
async findOne(args) {
|
||||
calls.findOrderArgs = args;
|
||||
return {
|
||||
id: 99,
|
||||
warehouse_id: storeId,
|
||||
};
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
service.getOrderItemsModelByTableType = async (tableType, warehouseId) => {
|
||||
calls.orderItemsModelTableType = tableType;
|
||||
calls.orderItemsModelWarehouseId = warehouseId;
|
||||
return {
|
||||
async findAll(args) {
|
||||
calls.findOrderItemsArgs = args;
|
||||
return [{ id: 1, order_id: 99 }];
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
service.getOrderExpressesByOrderId = async orderId => {
|
||||
calls.expressOrderId = orderId;
|
||||
return [{ id: 11, order_id: 99, waybill_code: 'WB-001' }];
|
||||
};
|
||||
|
||||
return {
|
||||
service,
|
||||
calls,
|
||||
};
|
||||
}
|
||||
|
||||
describe('test/app/service/systemMethods/order/entrustArchiveOrder.detail.defaultTableType.test.js', () => {
|
||||
it('entrustOrder.detail 未传表位参数时应默认走 outsourced,且返回结构正确', async () => {
|
||||
const { service, calls } = createHarness(EntrustOrderService, 100321);
|
||||
|
||||
const result = await service.detail({
|
||||
id: 99,
|
||||
});
|
||||
|
||||
assert.equal(calls.orderModelTableType, 'outsourced');
|
||||
assert.equal(calls.orderItemsModelTableType, 'outsourced');
|
||||
assert.notEqual(calls.orderModelTableType, 'current');
|
||||
assert.notEqual(calls.orderItemsModelTableType, 'current');
|
||||
|
||||
assert.equal(calls.orderModelWarehouseId, 100321);
|
||||
assert.equal(calls.orderItemsModelWarehouseId, 100321);
|
||||
assert.equal(calls.findOrderArgs.where.id, 99);
|
||||
assert.equal(calls.findOrderItemsArgs.where.order_id, 99);
|
||||
assert.equal(calls.expressOrderId, 99);
|
||||
|
||||
assert.ok(result && typeof result === 'object');
|
||||
assert.ok(result.detail && typeof result.detail === 'object');
|
||||
assert.ok(Array.isArray(result.items));
|
||||
assert.ok(Array.isArray(result.expresses));
|
||||
assert.ok(Array.isArray(result.logs));
|
||||
});
|
||||
|
||||
it('archiveOrder.detail 未传表位参数时应默认走 history,且返回结构正确', async () => {
|
||||
const { service, calls } = createHarness(ArchiveOrderService, 100321);
|
||||
|
||||
const result = await service.detail({
|
||||
id: 99,
|
||||
});
|
||||
|
||||
assert.equal(calls.orderModelTableType, 'history');
|
||||
assert.equal(calls.orderItemsModelTableType, 'history');
|
||||
assert.notEqual(calls.orderModelTableType, 'current');
|
||||
assert.notEqual(calls.orderItemsModelTableType, 'current');
|
||||
|
||||
assert.equal(calls.orderModelWarehouseId, 100321);
|
||||
assert.equal(calls.orderItemsModelWarehouseId, 100321);
|
||||
assert.equal(calls.findOrderArgs.where.id, 99);
|
||||
assert.equal(calls.findOrderItemsArgs.where.order_id, 99);
|
||||
assert.equal(calls.expressOrderId, 99);
|
||||
|
||||
assert.ok(result && typeof result === 'object');
|
||||
assert.ok(result.detail && typeof result.detail === 'object');
|
||||
assert.ok(Array.isArray(result.items));
|
||||
assert.ok(Array.isArray(result.expresses));
|
||||
assert.ok(Array.isArray(result.logs));
|
||||
});
|
||||
|
||||
it('entrustOrder.detail 显式传入 tableType 时应尊重调用方参数', async () => {
|
||||
const { service, calls } = createHarness(EntrustOrderService, 100321);
|
||||
|
||||
await service.detail({
|
||||
id: 99,
|
||||
tableType: 'current',
|
||||
});
|
||||
|
||||
assert.equal(calls.orderModelTableType, 'current');
|
||||
assert.equal(calls.orderItemsModelTableType, 'current');
|
||||
});
|
||||
|
||||
it('archiveOrder.detail 显式传入 moduleName 时应尊重调用方参数', async () => {
|
||||
const { service, calls } = createHarness(ArchiveOrderService, 100321);
|
||||
|
||||
await service.detail({
|
||||
id: 99,
|
||||
moduleName: 'outsourced',
|
||||
});
|
||||
|
||||
assert.equal(calls.orderModelTableType, 'outsourced');
|
||||
assert.equal(calls.orderItemsModelTableType, 'outsourced');
|
||||
});
|
||||
});
|
||||
@ -14,42 +14,113 @@ function createHarness(orderRows = []) {
|
||||
const capturedSqls = [];
|
||||
|
||||
/**
|
||||
* 根据 SQL 中的聚合条件模拟库位分配状态过滤。
|
||||
* 统计单个波次下订单分配状态计数。
|
||||
*
|
||||
* @param {Array<Object>} rows 订单行。
|
||||
* @return {{ total: number, storage: { none: number, fin: number, error: number }, express: { none: number, fin: number, error: number }, print: { none: number, fin: number, error: number } }} 统计结果。
|
||||
*/
|
||||
function buildWaveOrderStats(rows) {
|
||||
const normalizedRows = Array.isArray(rows) ? rows : [];
|
||||
const stats = {
|
||||
total: normalizedRows.length,
|
||||
storage: { none: 0, fin: 0, error: 0 },
|
||||
express: { none: 0, fin: 0, error: 0 },
|
||||
print: { none: 0, fin: 0, error: 0 },
|
||||
};
|
||||
|
||||
for (const row of normalizedRows) {
|
||||
const storageStatus = String(row && row.storage_status || '').trim();
|
||||
const expressStatus = String(row && row.post_status || '').trim();
|
||||
const printStatus = String(row && row.print_status || '').trim();
|
||||
|
||||
if (storageStatus === 'none') {
|
||||
stats.storage.none += 1;
|
||||
} else if (storageStatus === 'fin') {
|
||||
stats.storage.fin += 1;
|
||||
} else if (storageStatus === 'error') {
|
||||
stats.storage.error += 1;
|
||||
}
|
||||
|
||||
if (expressStatus === 'none') {
|
||||
stats.express.none += 1;
|
||||
} else if (expressStatus === 'fin') {
|
||||
stats.express.fin += 1;
|
||||
} else if (expressStatus === 'error') {
|
||||
stats.express.error += 1;
|
||||
}
|
||||
|
||||
if (printStatus === 'none') {
|
||||
stats.print.none += 1;
|
||||
} else if (printStatus === 'fin') {
|
||||
stats.print.fin += 1;
|
||||
} else if (printStatus === 'error') {
|
||||
stats.print.error += 1;
|
||||
}
|
||||
}
|
||||
|
||||
return stats;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据 SQL 中的聚合条件模拟分配状态过滤。
|
||||
*
|
||||
* @param {string} sql 原始 SQL。
|
||||
* @param {Array<Object>} rows 订单行。
|
||||
* @param {{ total: number, storage: { none: number, fin: number, error: number }, express: { none: number, fin: number, error: number }, print: { none: number, fin: number, error: number } }} stats 统计结果。
|
||||
* @param {'storage'|'express'|'print'} type 分配类型。
|
||||
* @return {boolean} 是否命中过滤条件。
|
||||
*/
|
||||
function matchStorageAssignmentFilter(sql, rows) {
|
||||
const normalizedRows = Array.isArray(rows) ? rows : [];
|
||||
const total = normalizedRows.length;
|
||||
const noneCount = normalizedRows.filter(row => String(row && row.storage_status || '').trim() === 'none').length;
|
||||
const finCount = normalizedRows.filter(row => String(row && row.storage_status || '').trim() === 'fin').length;
|
||||
const errorCount = normalizedRows.filter(row => String(row && row.storage_status || '').trim() === 'error').length;
|
||||
function matchAssignmentFilter(sql, stats, type) {
|
||||
const normalizedType = String(type || '').trim();
|
||||
const total = Number(stats && stats.total || 0);
|
||||
const typeStats = stats && stats[normalizedType] ? stats[normalizedType] : { none: 0, fin: 0, error: 0 };
|
||||
const noneCount = Number(typeStats.none || 0);
|
||||
const finCount = Number(typeStats.fin || 0);
|
||||
const errorCount = Number(typeStats.error || 0);
|
||||
|
||||
const totalExpr = 'COALESCE(wave_order_stats.order_total, 0)';
|
||||
const noneExpr = 'COALESCE(wave_order_stats.storage_none_count, 0)';
|
||||
const finExpr = 'COALESCE(wave_order_stats.storage_fin_count, 0)';
|
||||
const errorExpr = 'COALESCE(wave_order_stats.storage_error_count, 0)';
|
||||
const fieldMap = {
|
||||
storage: {
|
||||
noneExpr: 'COALESCE(wave_order_stats.storage_none_count, 0)',
|
||||
finExpr: 'COALESCE(wave_order_stats.storage_fin_count, 0)',
|
||||
errorExpr: 'COALESCE(wave_order_stats.storage_error_count, 0)',
|
||||
withError: true,
|
||||
},
|
||||
express: {
|
||||
noneExpr: 'COALESCE(wave_order_stats.post_none_count, 0)',
|
||||
finExpr: 'COALESCE(wave_order_stats.post_fin_count, 0)',
|
||||
errorExpr: 'COALESCE(wave_order_stats.post_error_count, 0)',
|
||||
withError: true,
|
||||
},
|
||||
print: {
|
||||
noneExpr: 'COALESCE(wave_order_stats.print_none_count, 0)',
|
||||
finExpr: 'COALESCE(wave_order_stats.print_fin_count, 0)',
|
||||
errorExpr: '',
|
||||
withError: false,
|
||||
},
|
||||
};
|
||||
const config = fieldMap[normalizedType];
|
||||
if (!config) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const { noneExpr, finExpr, errorExpr, withError } = config;
|
||||
|
||||
if (sql.includes(`${finExpr} = ${totalExpr}`) && sql.includes(`${totalExpr} > 0`)) {
|
||||
return total > 0 && finCount === total;
|
||||
}
|
||||
|
||||
if (
|
||||
sql.includes(`${errorExpr} = 0`)
|
||||
&& sql.includes(`${noneExpr} <> ${totalExpr}`)
|
||||
sql.includes(`${noneExpr} <> ${totalExpr}`)
|
||||
&& sql.includes(`${finExpr} <> ${totalExpr}`)
|
||||
) {
|
||||
return errorCount === 0 && noneCount !== total && finCount !== total;
|
||||
if (withError && !sql.includes(`${errorExpr} = 0`)) {
|
||||
return true;
|
||||
}
|
||||
return (!withError || errorCount === 0) && noneCount !== total && finCount !== total;
|
||||
}
|
||||
|
||||
if (
|
||||
sql.includes(`${totalExpr} = 0`)
|
||||
&& sql.includes(`${errorExpr} > 0`)
|
||||
&& sql.includes(`${noneExpr} = ${totalExpr}`)
|
||||
) {
|
||||
return total === 0 || errorCount > 0 || noneCount === total;
|
||||
if (sql.includes(`${totalExpr} = 0`) && sql.includes(`${noneExpr} = ${totalExpr}`)) {
|
||||
return total === 0 || (withError && errorCount > 0) || noneCount === total;
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -65,7 +136,10 @@ function createHarness(orderRows = []) {
|
||||
model: {
|
||||
async query(sql) {
|
||||
capturedSqls.push(String(sql));
|
||||
const matched = matchStorageAssignmentFilter(sql, orderRows);
|
||||
const stats = buildWaveOrderStats(orderRows);
|
||||
const matched = matchAssignmentFilter(sql, stats, 'storage')
|
||||
&& matchAssignmentFilter(sql, stats, 'express')
|
||||
&& matchAssignmentFilter(sql, stats, 'print');
|
||||
if (sql.includes('COUNT(1) AS total')) {
|
||||
return [[{ total: matched ? 1 : 0 }]];
|
||||
}
|
||||
@ -81,6 +155,15 @@ function createHarness(orderRows = []) {
|
||||
wave_status: 0,
|
||||
total_orders: orderRows.length,
|
||||
processed_orders: 0,
|
||||
order_total: stats.total,
|
||||
storage_none_count: stats.storage.none,
|
||||
storage_fin_count: stats.storage.fin,
|
||||
storage_error_count: stats.storage.error,
|
||||
post_none_count: stats.express.none,
|
||||
post_fin_count: stats.express.fin,
|
||||
post_error_count: stats.express.error,
|
||||
print_none_count: stats.print.none,
|
||||
print_fin_count: stats.print.fin,
|
||||
item_detail_machine: '',
|
||||
item_part_type: 'items_hash',
|
||||
item_part: 'hash-x',
|
||||
@ -218,6 +301,69 @@ describe('test/app/service/systemMethods/order/wave.batchList.assignmentStatus.t
|
||||
);
|
||||
});
|
||||
|
||||
it('should support where.express_assignment_status with english enums', async () => {
|
||||
const { result } = await getBatchListResult([
|
||||
{ wave_id: 1, storage_status: 'none', post_status: 'fin', print_status: 'none' },
|
||||
{ wave_id: 1, storage_status: 'none', post_status: 'fin', print_status: 'none' },
|
||||
], {
|
||||
express_assignment_status: 'assigned',
|
||||
});
|
||||
|
||||
assert.equal(result.flag, 'success');
|
||||
assert.equal(result.list.length, 1);
|
||||
assert.equal(result.list[0].express_assignment_status, '已分配');
|
||||
});
|
||||
|
||||
it('should filter print assignment status by unprinted', async () => {
|
||||
const { result } = await getBatchListResult([
|
||||
{ wave_id: 1, storage_status: 'none', post_status: 'none', print_status: 'none' },
|
||||
{ wave_id: 1, storage_status: 'none', post_status: 'none', print_status: 'none' },
|
||||
], {
|
||||
print_assignment_status: 'unprinted',
|
||||
});
|
||||
|
||||
assert.equal(result.flag, 'success');
|
||||
assert.equal(result.list.length, 1);
|
||||
assert.equal(result.list[0].print_assignment_status, '未打印');
|
||||
});
|
||||
|
||||
it('should filter print assignment status by partially_printed', async () => {
|
||||
const { result } = await getBatchListResult([
|
||||
{ wave_id: 1, storage_status: 'none', post_status: 'none', print_status: 'none' },
|
||||
{ wave_id: 1, storage_status: 'none', post_status: 'none', print_status: 'fin' },
|
||||
], {
|
||||
print_assignment_status: 'partially_printed',
|
||||
});
|
||||
|
||||
assert.equal(result.flag, 'success');
|
||||
assert.equal(result.list.length, 1);
|
||||
assert.equal(result.list[0].print_assignment_status, '部分打印');
|
||||
});
|
||||
|
||||
it('should filter print assignment status by printed', async () => {
|
||||
const { result } = await getBatchListResult([
|
||||
{ wave_id: 1, storage_status: 'none', post_status: 'none', print_status: 'fin' },
|
||||
{ wave_id: 1, storage_status: 'none', post_status: 'none', print_status: 'fin' },
|
||||
], {
|
||||
print_assignment_status: 'printed',
|
||||
});
|
||||
|
||||
assert.equal(result.flag, 'success');
|
||||
assert.equal(result.list.length, 1);
|
||||
assert.equal(result.list[0].print_assignment_status, '已打印');
|
||||
});
|
||||
|
||||
it('should throw readable error when where.print_assignment_status is invalid', async () => {
|
||||
await assert.rejects(
|
||||
async () => {
|
||||
await getBatchListResult([], {
|
||||
print_assignment_status: 'invalid_enum',
|
||||
});
|
||||
},
|
||||
/print_assignment_status 参数不合法,仅支持: unprinted、partially_printed、printed/
|
||||
);
|
||||
});
|
||||
|
||||
it('should use aggregate join SQL and avoid correlated subquery when filtering 未分配 with wave_type', async () => {
|
||||
const { capturedSqls } = await getBatchListResult([
|
||||
{ wave_id: 1, storage_status: 'error', post_status: 'none', print_status: 'none' },
|
||||
|
||||
@ -0,0 +1,451 @@
|
||||
'use strict';
|
||||
|
||||
const assert = require('node:assert/strict');
|
||||
const OrderPrintSystemService = require('../../../../app/service/systems/order_print');
|
||||
|
||||
function createOrderPrintServiceHarness() {
|
||||
const ctx = {
|
||||
app: {
|
||||
baseDir: 'd:/wms',
|
||||
},
|
||||
user: {
|
||||
store_id: 100000,
|
||||
},
|
||||
logger: {
|
||||
info() {},
|
||||
warn() {},
|
||||
error() {},
|
||||
},
|
||||
model: {
|
||||
QueryTypes: {
|
||||
SELECT: 'SELECT',
|
||||
},
|
||||
},
|
||||
service: {
|
||||
systems: {
|
||||
storeWarehouse: {
|
||||
async getContractConfig() {
|
||||
return {
|
||||
policy_config: {},
|
||||
};
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
return new OrderPrintSystemService(ctx);
|
||||
}
|
||||
|
||||
describe('test/app/service/systems/order_print.getWavePlatformPrintData.test.js', () => {
|
||||
it('should map kuaishou encryptedData/signature/key from order_express fields', () => {
|
||||
const service = createOrderPrintServiceHarness();
|
||||
|
||||
const result = service.buildOrderPlatformPrintItem({
|
||||
orderRow: {
|
||||
id: 101,
|
||||
wave_id: 10,
|
||||
wave_no: 'W010',
|
||||
delivery_order_code: 'DO101',
|
||||
store_id: 1,
|
||||
warehouse_id: 100000,
|
||||
items: JSON.stringify([
|
||||
{
|
||||
item_name: '化妆品',
|
||||
pick_location: 'E2区02-04-02',
|
||||
barcode: '6973348850399',
|
||||
quantity: 2,
|
||||
},
|
||||
]),
|
||||
},
|
||||
orderExpress: {
|
||||
waybill_code: 'WB101',
|
||||
printinfo: 'ENC_FROM_DB',
|
||||
signature: 'SIG_FROM_DB',
|
||||
encryptprintinfo: 'KEY_FROM_DB',
|
||||
},
|
||||
policyConfig: {
|
||||
province_name: '浙江省',
|
||||
city_name: '杭州市',
|
||||
district_name: '滨江区',
|
||||
address: '网商路 699 号',
|
||||
sender_name: '张三',
|
||||
sender_tel: '13800000000',
|
||||
waybill_custom_display_type: '5',
|
||||
},
|
||||
platformCode: 'kuaishou',
|
||||
templateSample: {
|
||||
cmd: 'print',
|
||||
requestID: 'sample-request',
|
||||
version: '1.0',
|
||||
taskID: 'sample-task',
|
||||
task: {
|
||||
documents: [
|
||||
{
|
||||
documentID: 'sample-doc',
|
||||
contents: [
|
||||
{
|
||||
encryptedData: 'SAMPLE_ENCRYPTED_DATA',
|
||||
signature: 'SAMPLE_SIGNATURE',
|
||||
key: 'SAMPLE_KEY',
|
||||
templateURL: 'https://example.com/kuaishou.xml',
|
||||
data: {
|
||||
productInfo: '#0 sample product info',
|
||||
},
|
||||
},
|
||||
{
|
||||
templateURL: 'http://www.ye4s.com/mb/kuaishou.xml',
|
||||
customData: {
|
||||
productInfo: '#1 sample custom product info',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
assert.equal(result.print_data.documentID, 'WB101');
|
||||
assert.equal(result.print_data.waybillCode, 'WB101');
|
||||
assert.ok(Array.isArray(result.print_data.contents));
|
||||
|
||||
const mappedContent = result.print_data.contents[0];
|
||||
assert.equal(mappedContent.encryptedData, 'ENC_FROM_DB');
|
||||
assert.equal(mappedContent.signature, 'SIG_FROM_DB');
|
||||
assert.equal(mappedContent.key, 'KEY_FROM_DB');
|
||||
assert.equal(mappedContent.templateURL, 'https://example.com/kuaishou.xml');
|
||||
assert.equal(mappedContent.data.productInfo, '__SAMPLE__');
|
||||
assert.equal(mappedContent.addData.senderInfo.address.countryCode, 'CHN');
|
||||
assert.equal(mappedContent.addData.senderInfo.address.detailAddress, '网商路 699 号');
|
||||
assert.equal(mappedContent.addData.senderInfo.contact.name, '张三');
|
||||
assert.equal(mappedContent.addData.senderInfo.contact.mobile, '13800000000');
|
||||
|
||||
const customDataContent = result.print_data.contents.find(content => content && content.customData);
|
||||
assert.ok(customDataContent);
|
||||
assert.equal(customDataContent.templateURL, 'http://www.ye4s.com/mb/kuaishou.xml');
|
||||
assert.ok(customDataContent.customData.productInfo.includes('商品总数 【2】'));
|
||||
assert.ok(customDataContent.customData.productInfo.includes('E2区02-04-02 化妆品 6973348850399 【2】'));
|
||||
});
|
||||
|
||||
it('should map pdd encryptedData/signature and sender fields from order_express and policy_config', () => {
|
||||
const service = createOrderPrintServiceHarness();
|
||||
|
||||
const result = service.buildOrderPlatformPrintItem({
|
||||
orderRow: {
|
||||
id: 201,
|
||||
wave_id: 20,
|
||||
wave_no: 'W020',
|
||||
delivery_order_code: 'DO201',
|
||||
store_id: 1,
|
||||
warehouse_id: 100000,
|
||||
items: JSON.stringify([
|
||||
{
|
||||
pick_location: 'A1-01-01',
|
||||
barcode: '1234567890123',
|
||||
quantity: 1,
|
||||
},
|
||||
]),
|
||||
},
|
||||
orderExpress: {
|
||||
waybill_code: ' WB201 ',
|
||||
printinfo: ' ENC_FROM_DB_PDD ',
|
||||
signature: ' SIG_FROM_DB_PDD ',
|
||||
},
|
||||
policyConfig: {
|
||||
province_name: '广东省',
|
||||
city_name: '深圳市',
|
||||
district_name: '南山区',
|
||||
address: '科技园南区 1 号',
|
||||
sender_name: '李四',
|
||||
sender_tel: '13900000000',
|
||||
waybill_custom_display_type: '4',
|
||||
},
|
||||
platformCode: 'pdd',
|
||||
templateSample: {
|
||||
cmd: 'print',
|
||||
requestID: 'sample-request',
|
||||
version: '1.0',
|
||||
taskID: 'sample-task',
|
||||
task: {
|
||||
documents: [
|
||||
{
|
||||
documentID: 'sample-doc',
|
||||
contents: [
|
||||
{
|
||||
addData: {
|
||||
sender: {
|
||||
address: {
|
||||
province: '',
|
||||
city: '',
|
||||
district: '',
|
||||
detail: '',
|
||||
},
|
||||
mobile: '',
|
||||
name: '',
|
||||
},
|
||||
},
|
||||
encryptedData: 'SAMPLE_ENCRYPTED_DATA',
|
||||
signature: 'SAMPLE_SIGNATURE',
|
||||
templateURL: 'https://example.com/pdd.xml',
|
||||
data: {
|
||||
productInfo: '#0 sample product info',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
assert.equal(result.print_data.documentID, 'WB201');
|
||||
assert.equal(result.print_data.contents[0].encryptedData, 'ENC_FROM_DB_PDD');
|
||||
assert.equal(result.print_data.contents[0].signature, 'SIG_FROM_DB_PDD');
|
||||
assert.equal(result.print_data.contents[0].addData.sender.address.province, '广东省');
|
||||
assert.equal(result.print_data.contents[0].addData.sender.address.city, '深圳市');
|
||||
assert.equal(result.print_data.contents[0].addData.sender.address.district, '南山区');
|
||||
assert.equal(result.print_data.contents[0].addData.sender.address.detail, '科技园南区 1 号');
|
||||
assert.equal(result.print_data.contents[0].addData.sender.mobile, '13900000000');
|
||||
assert.equal(result.print_data.contents[0].addData.sender.name, '李四');
|
||||
|
||||
const customContent = result.print_data.contents.find(content => {
|
||||
return content && content.data && Array.isArray(content.data.list);
|
||||
});
|
||||
assert.ok(customContent);
|
||||
assert.equal(customContent.templateURL, 'http://www.ye4s.com/mb/pdd.xml');
|
||||
assert.ok(customContent.data.list[0].text.includes('\r'));
|
||||
assert.ok(customContent.data.list[0].text.includes('商品总数 【1】'));
|
||||
assert.ok(customContent.data.list[0].text.includes('A1-01-01 90123 【1】'));
|
||||
});
|
||||
|
||||
it('should query order_express with kuaishou encrypted payload columns', async () => {
|
||||
const service = createOrderPrintServiceHarness();
|
||||
let capturedAttributes = [];
|
||||
let capturedWhere = {};
|
||||
service.ctx.model.OrderExpress = {
|
||||
async findAll(options) {
|
||||
capturedAttributes = Array.isArray(options && options.attributes) ? options.attributes : [];
|
||||
capturedWhere = options && options.where || {};
|
||||
return [];
|
||||
},
|
||||
};
|
||||
|
||||
await service.queryOrderExpressByOrderIds([ 101 ]);
|
||||
|
||||
assert.ok(capturedAttributes.includes('printinfo'));
|
||||
assert.ok(capturedAttributes.includes('signature'));
|
||||
assert.ok(capturedAttributes.includes('encryptprintinfo'));
|
||||
assert.equal(capturedWhere.business_key, 1);
|
||||
});
|
||||
|
||||
it('should throw when business_key=1 waybill data is missing', async () => {
|
||||
const service = createOrderPrintServiceHarness();
|
||||
|
||||
service.queryWavesByIds = async () => ([
|
||||
{ wave_id: 1, wave_no: 'W001' },
|
||||
]);
|
||||
service.queryOrdersByWaveIds = async () => ([
|
||||
{
|
||||
id: 101,
|
||||
wave_id: 1,
|
||||
wave_no: 'W001',
|
||||
warehouse_id: 100000,
|
||||
store_id: 1,
|
||||
delivery_order_code: 'O101',
|
||||
post_status: 'fin',
|
||||
sys_platform_code: 'kuaishou',
|
||||
},
|
||||
{
|
||||
id: 102,
|
||||
wave_id: 1,
|
||||
wave_no: 'W001',
|
||||
warehouse_id: 100000,
|
||||
store_id: 1,
|
||||
delivery_order_code: 'O102',
|
||||
post_status: 'fin',
|
||||
sys_platform_code: 'kuaishou',
|
||||
},
|
||||
]);
|
||||
service.filterFullyAssignedExpressWaves = () => ({
|
||||
validWaveIds: [ 1 ],
|
||||
filteredWaveIds: [],
|
||||
});
|
||||
service.queryOrderExpressByOrderIds = async () => ([
|
||||
{
|
||||
order_id: 101,
|
||||
business_key: 1,
|
||||
waybill_code: 'WB101',
|
||||
},
|
||||
{
|
||||
order_id: 102,
|
||||
business_key: 1,
|
||||
waybill_code: '',
|
||||
},
|
||||
]);
|
||||
|
||||
await assert.rejects(
|
||||
async () => service.getWavePlatformPrintData({
|
||||
waveIds: [ 1 ],
|
||||
warehouseId: 100000,
|
||||
}),
|
||||
error => {
|
||||
assert.ok(error instanceof Error);
|
||||
assert.ok(error.message.includes('业务id为1的运单号数据缺失'));
|
||||
return true;
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('should return waveGroups grouped by wave then platform and keep summary counters correct', async () => {
|
||||
const service = createOrderPrintServiceHarness();
|
||||
|
||||
service.queryWavesByIds = async () => ([
|
||||
{ wave_id: 2, wave_no: 'W002' },
|
||||
{ wave_id: 1, wave_no: 'W001' },
|
||||
]);
|
||||
|
||||
service.queryOrdersByWaveIds = async () => ([
|
||||
{
|
||||
id: 11,
|
||||
wave_id: 1,
|
||||
wave_no: 'W001',
|
||||
warehouse_id: 100000,
|
||||
store_id: 1,
|
||||
delivery_order_code: 'O11',
|
||||
post_status: 'fin',
|
||||
sys_platform_code: 'jd',
|
||||
},
|
||||
{
|
||||
id: 12,
|
||||
wave_id: 1,
|
||||
wave_no: 'W001',
|
||||
warehouse_id: 100000,
|
||||
store_id: 1,
|
||||
delivery_order_code: 'O12',
|
||||
post_status: 'fin',
|
||||
sys_platform_code: 'cainiao',
|
||||
},
|
||||
{
|
||||
id: 21,
|
||||
wave_id: 2,
|
||||
wave_no: 'W002',
|
||||
warehouse_id: 100000,
|
||||
store_id: 2,
|
||||
delivery_order_code: 'O21',
|
||||
post_status: 'fin',
|
||||
sys_platform_code: 'jd',
|
||||
},
|
||||
]);
|
||||
|
||||
service.filterFullyAssignedExpressWaves = () => ({
|
||||
validWaveIds: [ 2, 1 ],
|
||||
filteredWaveIds: [],
|
||||
});
|
||||
|
||||
service.queryOrderExpressByOrderIds = async () => ([
|
||||
{
|
||||
order_id: 11,
|
||||
business_key: 1,
|
||||
waybill_code: 'WB11',
|
||||
},
|
||||
{
|
||||
order_id: 12,
|
||||
business_key: 1,
|
||||
waybill_code: 'WB12',
|
||||
},
|
||||
{
|
||||
order_id: 21,
|
||||
business_key: 1,
|
||||
waybill_code: 'WB21',
|
||||
},
|
||||
]);
|
||||
service.buildOrderExpressMap = () => new Map();
|
||||
service.getPolicyConfigMapByStore = async () => new Map([
|
||||
[ 1, {}],
|
||||
[ 2, {}],
|
||||
]);
|
||||
service.resolvePrintPlatformCode = orderRow => String(orderRow && orderRow.sys_platform_code || '').trim();
|
||||
service.loadTemplateSampleByPlatform = () => ({});
|
||||
service.buildOrderPlatformPrintItem = ({ orderRow, platformCode }) => ({
|
||||
wave_id: Number(orderRow.wave_id),
|
||||
wave_no: String(orderRow.wave_no),
|
||||
order_id: Number(orderRow.id),
|
||||
order_no: String(orderRow.delivery_order_code),
|
||||
platform: String(platformCode),
|
||||
platform_name: platformCode === 'jd' ? '京东' : '菜鸟',
|
||||
print_data: {
|
||||
platform: String(platformCode),
|
||||
order_id: Number(orderRow.id),
|
||||
},
|
||||
});
|
||||
|
||||
const result = await service.getWavePlatformPrintData({
|
||||
waveIds: [ 2, 1 ],
|
||||
warehouseId: 100000,
|
||||
});
|
||||
|
||||
assert.deepEqual(result.summary, {
|
||||
total_waves: 2,
|
||||
total_orders: 3,
|
||||
total_platforms: 3,
|
||||
});
|
||||
|
||||
assert.equal(result.waveGroups.length, 2);
|
||||
assert.deepEqual(result.waveGroups.map(item => item.wave_no), [ 'W001', 'W002' ]);
|
||||
|
||||
assert.deepEqual(result.waveGroups[0], {
|
||||
wave_id: 1,
|
||||
wave_no: 'W001',
|
||||
order_count: 2,
|
||||
platforms: [
|
||||
{
|
||||
platform: 'cainiao',
|
||||
platform_name: '菜鸟',
|
||||
order_count: 1,
|
||||
orders: [
|
||||
{
|
||||
platform: 'cainiao',
|
||||
order_id: 12,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
platform: 'jd',
|
||||
platform_name: '京东',
|
||||
order_count: 1,
|
||||
orders: [
|
||||
{
|
||||
platform: 'jd',
|
||||
order_id: 11,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
assert.deepEqual(result.waveGroups[1], {
|
||||
wave_id: 2,
|
||||
wave_no: 'W002',
|
||||
order_count: 1,
|
||||
platforms: [
|
||||
{
|
||||
platform: 'jd',
|
||||
platform_name: '京东',
|
||||
order_count: 1,
|
||||
orders: [
|
||||
{
|
||||
platform: 'jd',
|
||||
order_id: 21,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
assert.deepEqual(result.ext, {
|
||||
missing_wave_ids: [],
|
||||
filtered_wave_ids: [],
|
||||
});
|
||||
});
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user