Compare commits
No commits in common. "145fc04022e83c009cfd845be321c197a6b0d878" and "932761155227d5966184c3951911ca9e603c993e" have entirely different histories.
145fc04022
...
9327611552
@ -153,8 +153,8 @@ rg "class .*Service|module.exports" app/service/qimenMethods
|
|||||||
- list
|
- list
|
||||||
- app/service/systemMethods/dashboard.js (6)
|
- app/service/systemMethods/dashboard.js (6)
|
||||||
- storeStats, warehouseStats, hot_order_rank, express_ratio, platform_distribution, order_trend
|
- storeStats, warehouseStats, hot_order_rank, express_ratio, platform_distribution, order_trend
|
||||||
- app/service/systemMethods/index.js (14)
|
- app/service/systemMethods/index.js (13)
|
||||||
- fastWhereTree, loadStores, getCOSUploadConfig, getImages, uploadSuccessNotify, ReferenceFile, getMessageDetail, getI18nMessage, putI18nCollect, extractModule, tryAutoTranslateNewKeys, searchSpace, searchSpaces, getExpressList
|
- fastWhereTree, loadStores, getCOSUploadConfig, getImages, uploadSuccessNotify, ReferenceFile, getMessageDetail, getI18nMessage, putI18nCollect, extractModule, tryAutoTranslateNewKeys, searchSpace, getExpressList
|
||||||
- app/service/systemMethods/order.js (11)
|
- app/service/systemMethods/order.js (11)
|
||||||
- getWarehouseId, getOrderModels, applyDateRange, buildWhere, parseDateTime, list, detail, listItems, stats, updateStatus, updateDeliveryTime
|
- getWarehouseId, getOrderModels, applyDateRange, buildWhere, parseDateTime, list, detail, listItems, stats, updateStatus, updateDeliveryTime
|
||||||
- app/service/systemMethods/print.js (3)
|
- app/service/systemMethods/print.js (3)
|
||||||
@ -215,8 +215,8 @@ rg "class .*Service|module.exports" app/service/qimenMethods
|
|||||||
- listTemplatesByType, getTree, getTemplatesByType, save, getBusinessTypesAndItem, getGroupedPrintItems, getTableConfigs, clearBusinessTypesCache, getXmlByTemplate, buildXmlFromElements, renderElement, computeItemStyle, computeTableItemStyle, renderTable
|
- listTemplatesByType, getTree, getTemplatesByType, save, getBusinessTypesAndItem, getGroupedPrintItems, getTableConfigs, clearBusinessTypesCache, getXmlByTemplate, buildXmlFromElements, renderElement, computeItemStyle, computeTableItemStyle, renderTable
|
||||||
- app/service/systems/sign.js (10)
|
- app/service/systems/sign.js (10)
|
||||||
- Constants, toXml, signTopRequest, verifyTopRequest, verifyAndExtractParams, generateSignedParams, encryptHMAC, encryptHMACSHA256, encryptMD5, byte2hex
|
- Constants, toXml, signTopRequest, verifyTopRequest, verifyAndExtractParams, generateSignedParams, encryptHMAC, encryptHMACSHA256, encryptMD5, byte2hex
|
||||||
- app/service/systems/space.js (2)
|
- app/service/systems/space.js (1)
|
||||||
- searchSpace, searchSpaces
|
- searchSpace
|
||||||
- app/service/systems/stock_store.js (34)
|
- app/service/systems/stock_store.js (34)
|
||||||
- create, initQimenStockData, convertToQimenFormat, getItemInfoWithCache, getItemStorages, _calculateCacheTTL, clearItemStorageCache, lockItemStorages, ID, inbound, outbound, checkAndCreateWarehouseStock, getWarehouseStock, buildSequelizeCondition, processConditionValue, formatDate, isEmptyValue, getProhibitedType, getBarcodes, handleBatchChange, saveWarehouseStockBarcode, getStoreStocks, bindItem, unbindItem, getInfo, saveWarehouseStock, createWarehouseStock, validateSaveParams, stockLog, checkItemCodeUnique, handleBatchDelete, deleteUnit, deleteProhibited, search
|
- create, initQimenStockData, convertToQimenFormat, getItemInfoWithCache, getItemStorages, _calculateCacheTTL, clearItemStorageCache, lockItemStorages, ID, inbound, outbound, checkAndCreateWarehouseStock, getWarehouseStock, buildSequelizeCondition, processConditionValue, formatDate, isEmptyValue, getProhibitedType, getBarcodes, handleBatchChange, saveWarehouseStockBarcode, getStoreStocks, bindItem, unbindItem, getInfo, saveWarehouseStock, createWarehouseStock, validateSaveParams, stockLog, checkItemCodeUnique, handleBatchDelete, deleteUnit, deleteProhibited, search
|
||||||
- app/service/systems/storage/index.js (1)
|
- app/service/systems/storage/index.js (1)
|
||||||
|
|||||||
@ -76,7 +76,6 @@ module.exports = {
|
|||||||
ORDER_WAVE_GRAB: '抓取波次',
|
ORDER_WAVE_GRAB: '抓取波次',
|
||||||
ORDER_WAVE_AUTO_GROUP: '自动加团',
|
ORDER_WAVE_AUTO_GROUP: '自动加团',
|
||||||
ORDER_WAVE_STRATEGY_FETCH: '策略抓取波次',
|
ORDER_WAVE_STRATEGY_FETCH: '策略抓取波次',
|
||||||
ORDER_WAVE_CLAIM: '领取波次',
|
|
||||||
ORDER_PICK_COMPLETE: '拣货完成',
|
ORDER_PICK_COMPLETE: '拣货完成',
|
||||||
ORDER_RECHECK: '订单复核',
|
ORDER_RECHECK: '订单复核',
|
||||||
ORDER_RECHECK_BATCH: '批量复核',
|
ORDER_RECHECK_BATCH: '批量复核',
|
||||||
|
|||||||
@ -1,63 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 订单波次顺序定位副表模型。
|
|
||||||
* 表结构:database/migrations/20260513113000-create-wms_order_wave_index.js
|
|
||||||
* @param {import('egg').Application} app Egg 应用实例。
|
|
||||||
* @return {import('sequelize').ModelCtor<import('sequelize').Model>} Sequelize 模型。
|
|
||||||
*/
|
|
||||||
module.exports = app => {
|
|
||||||
const { BIGINT, INTEGER, DATE } = app.Sequelize;
|
|
||||||
|
|
||||||
const OrderWaveIndex = app.model.define('wms_order_wave_index', {
|
|
||||||
id: {
|
|
||||||
type: BIGINT(20).UNSIGNED,
|
|
||||||
primaryKey: true,
|
|
||||||
autoIncrement: true,
|
|
||||||
allowNull: false,
|
|
||||||
comment: '主键ID',
|
|
||||||
},
|
|
||||||
warehouse_id: {
|
|
||||||
type: BIGINT(20).UNSIGNED,
|
|
||||||
allowNull: false,
|
|
||||||
defaultValue: 0,
|
|
||||||
comment: '仓库ID',
|
|
||||||
},
|
|
||||||
order_id: {
|
|
||||||
type: BIGINT(20).UNSIGNED,
|
|
||||||
allowNull: false,
|
|
||||||
defaultValue: 0,
|
|
||||||
comment: '订单ID',
|
|
||||||
},
|
|
||||||
wave_id: {
|
|
||||||
type: BIGINT(20).UNSIGNED,
|
|
||||||
allowNull: false,
|
|
||||||
defaultValue: 0,
|
|
||||||
comment: '波次ID',
|
|
||||||
},
|
|
||||||
wave_index: {
|
|
||||||
type: INTEGER(10).UNSIGNED,
|
|
||||||
allowNull: false,
|
|
||||||
defaultValue: 0,
|
|
||||||
comment: '订单在波次中的全局顺序',
|
|
||||||
},
|
|
||||||
platforms_index: {
|
|
||||||
type: INTEGER(10).UNSIGNED,
|
|
||||||
allowNull: false,
|
|
||||||
defaultValue: 0,
|
|
||||||
comment: '订单在平台分组内顺序',
|
|
||||||
},
|
|
||||||
create_at: {
|
|
||||||
type: DATE,
|
|
||||||
allowNull: false,
|
|
||||||
comment: '创建时间',
|
|
||||||
},
|
|
||||||
}, {
|
|
||||||
tableName: 'wms_order_wave_index',
|
|
||||||
timestamps: false,
|
|
||||||
underscored: true,
|
|
||||||
comment: '订单波次顺序定位副表',
|
|
||||||
});
|
|
||||||
|
|
||||||
return OrderWaveIndex;
|
|
||||||
};
|
|
||||||
@ -326,6 +326,18 @@ module.exports = app => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Object.prototype.hasOwnProperty.call(parsed, 'webhook_enabled')) {
|
||||||
|
normalized.webhook_enabled = normalizeBooleanFlag(parsed.webhook_enabled, 'subject_config.webhook_enabled');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Object.prototype.hasOwnProperty.call(parsed, 'callback_strategy')) {
|
||||||
|
const strategy = String(parsed.callback_strategy || '').trim().toLowerCase();
|
||||||
|
if (strategy && ![ 'sync', 'async' ].includes(strategy)) {
|
||||||
|
throw new Error('subject_config.callback_strategy 仅支持 sync 或 async');
|
||||||
|
}
|
||||||
|
normalized.callback_strategy = strategy || 'async';
|
||||||
|
}
|
||||||
|
|
||||||
normalized.inventory_warning_rules = normalizeInventoryWarningRules(parsed.inventory_warning_rules);
|
normalized.inventory_warning_rules = normalizeInventoryWarningRules(parsed.inventory_warning_rules);
|
||||||
normalized.auto_outbound_rules = normalizeAutoOutboundRules(parsed.auto_outbound_rules);
|
normalized.auto_outbound_rules = normalizeAutoOutboundRules(parsed.auto_outbound_rules);
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
module.exports = app => {
|
module.exports = app => {
|
||||||
const { BIGINT, INTEGER, STRING, TEXT, DATE, TINYINT, BOOLEAN } = app.Sequelize;
|
const { BIGINT, INTEGER, STRING, DATE, TINYINT, BOOLEAN } = app.Sequelize;
|
||||||
|
|
||||||
const WaveBatch = app.model.define('wms_wave_batch', {
|
const WaveBatch = app.model.define('wms_wave_batch', {
|
||||||
wave_id: {
|
wave_id: {
|
||||||
@ -115,9 +115,9 @@ module.exports = app => {
|
|||||||
comment: '更新时间',
|
comment: '更新时间',
|
||||||
},
|
},
|
||||||
item_detail_machine: {
|
item_detail_machine: {
|
||||||
type: TEXT,
|
type: STRING(1024),
|
||||||
allowNull: true,
|
allowNull: true,
|
||||||
comment: '抓取结构token:v1|item_part_type|item_part|distinguish_express|logistics_name|item_snapshot_key(TEXT 以容纳多商品订单的长结构标识)',
|
comment: '抓取结构token:v1|item_part_type|item_part|distinguish_express|logistics_name|item_snapshot_key',
|
||||||
},
|
},
|
||||||
item_part_type: {
|
item_part_type: {
|
||||||
type: STRING(32),
|
type: STRING(32),
|
||||||
@ -143,7 +143,7 @@ module.exports = app => {
|
|||||||
item_snapshot_key: {
|
item_snapshot_key: {
|
||||||
type: STRING(1024),
|
type: STRING(1024),
|
||||||
allowNull: true,
|
allowNull: true,
|
||||||
comment: '结构快照键(多商品订单的快照键,最长 1024)',
|
comment: '结构快照键(与 item_detail_machine 一致,1024 长度以容纳多商品订单的快照)',
|
||||||
},
|
},
|
||||||
}, {
|
}, {
|
||||||
tableName: 'wms_wave_batch',
|
tableName: 'wms_wave_batch',
|
||||||
|
|||||||
@ -1,118 +0,0 @@
|
|||||||
// app/schedule/sync_finished_wave_batch.js
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
const EXECUTION_LOG_CACHE_KEY = 'schedule:sync_finished_wave_batch:last_execution';
|
|
||||||
const EXECUTION_LOG_CACHE_TTL = 300; // 5 分钟
|
|
||||||
const EXECUTION_LOG_HISTORY_CACHE_KEY = 'schedule:sync_finished_wave_batch:history';
|
|
||||||
const EXECUTION_LOG_HISTORY_MAX = 20; // 保留最近 20 次执行记录
|
|
||||||
const EXECUTION_LOG_HISTORY_TTL = 86400; // 1 天
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 将本次执行日志写入缓存。
|
|
||||||
*
|
|
||||||
* @param {Object} ctx Egg 上下文。
|
|
||||||
* @param {Object} logEntry 日志条目。
|
|
||||||
* @return {Promise<void>}
|
|
||||||
*/
|
|
||||||
async function writeExecutionLogToCache(ctx, logEntry) {
|
|
||||||
try {
|
|
||||||
if (ctx.app && typeof ctx.app.setCacheAsync === 'function') {
|
|
||||||
await ctx.app.setCacheAsync(EXECUTION_LOG_CACHE_KEY, logEntry, EXECUTION_LOG_CACHE_TTL);
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
ctx.logger.warn(`[sync-finished-wave-batch] 写入执行日志缓存失败: ${err.message}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 将本次执行日志追加到历史记录缓存(保留最近 N 次)。
|
|
||||||
*
|
|
||||||
* @param {Object} ctx Egg 上下文。
|
|
||||||
* @param {Object} logEntry 日志条目。
|
|
||||||
* @return {Promise<void>}
|
|
||||||
*/
|
|
||||||
async function appendExecutionHistory(ctx, logEntry) {
|
|
||||||
try {
|
|
||||||
if (typeof ctx.app.getCacheAsync !== 'function' || typeof ctx.app.setCacheAsync !== 'function') {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const rawHistory = await ctx.app.getCacheAsync(EXECUTION_LOG_HISTORY_CACHE_KEY);
|
|
||||||
const history = Array.isArray(rawHistory) ? rawHistory : [];
|
|
||||||
history.unshift(logEntry);
|
|
||||||
await ctx.app.setCacheAsync(
|
|
||||||
EXECUTION_LOG_HISTORY_CACHE_KEY,
|
|
||||||
history.slice(0, EXECUTION_LOG_HISTORY_MAX),
|
|
||||||
EXECUTION_LOG_HISTORY_TTL
|
|
||||||
);
|
|
||||||
} catch (err) {
|
|
||||||
ctx.logger.warn(`[sync-finished-wave-batch] 写入执行历史缓存失败: ${err.message}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 每 1 分钟在单 worker 中执行一次波次自动终结。
|
|
||||||
*
|
|
||||||
* 将"订单已全部离开待处理表"的活动波次(wave_status IN (0,1))收敛为
|
|
||||||
* wave_status=5(复核完成),修复遗留 0 单波次在 batchList 中展示的问题。
|
|
||||||
*/
|
|
||||||
module.exports = {
|
|
||||||
schedule: {
|
|
||||||
interval: '1m',
|
|
||||||
type: 'worker',
|
|
||||||
immediate: false,
|
|
||||||
disable: false,
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 执行波次自动终结任务。
|
|
||||||
*
|
|
||||||
* @param {Object} ctx Egg 上下文。
|
|
||||||
* @return {Promise<void>} 无返回值。
|
|
||||||
*/
|
|
||||||
async task(ctx) {
|
|
||||||
if (ctx.app._syncFinishedWaveBatchRunning) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx.app._syncFinishedWaveBatchRunning = true;
|
|
||||||
|
|
||||||
const startedAt = Date.now();
|
|
||||||
let status = 'success';
|
|
||||||
let errorMessage = '';
|
|
||||||
let result = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
result = await ctx.service.systems.waveBatchClosure.closeFinishedWaves();
|
|
||||||
|
|
||||||
if (result && result.closed_count > 0) {
|
|
||||||
ctx.logger.info(
|
|
||||||
`[sync-finished-wave-batch] 自动终结 ${result.closed_count} 个波次: ${JSON.stringify(result.closed_waves)}`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
status = 'error';
|
|
||||||
errorMessage = error.message;
|
|
||||||
ctx.logger.error(`[sync-finished-wave-batch] 执行失败: ${error.message}`);
|
|
||||||
} finally {
|
|
||||||
ctx.app._syncFinishedWaveBatchRunning = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const logEntry = {
|
|
||||||
executed_at: new Date().toISOString(),
|
|
||||||
duration_ms: Date.now() - startedAt,
|
|
||||||
status,
|
|
||||||
error_message: errorMessage,
|
|
||||||
candidate_count: result ? result.candidate_count : 0,
|
|
||||||
closed_count: result ? result.closed_count : 0,
|
|
||||||
warehouse_ids: result ? result.warehouse_ids : [],
|
|
||||||
closed_waves: result ? result.closed_waves : [],
|
|
||||||
};
|
|
||||||
await writeExecutionLogToCache(ctx, logEntry);
|
|
||||||
await appendExecutionHistory(ctx, logEntry);
|
|
||||||
|
|
||||||
ctx.logger.info(
|
|
||||||
`[sync-finished-wave-batch] 本轮完成 closed=${result ? result.closed_count : 0} candidate=${result ? result.candidate_count : 0} warehouses=${result ? result.warehouse_ids.length : 0}`
|
|
||||||
);
|
|
||||||
},
|
|
||||||
};
|
|
||||||
@ -1053,9 +1053,9 @@ class indexService extends MainService {
|
|||||||
constructor(ctx) {
|
constructor(ctx) {
|
||||||
super(ctx);
|
super(ctx);
|
||||||
const _noNeedLogin = 'getI18nMessage,putI18nCollect,test,getCainiaoStfTemplates,polyapiAuthorizeUrl';
|
const _noNeedLogin = 'getI18nMessage,putI18nCollect,test,getCainiaoStfTemplates,polyapiAuthorizeUrl';
|
||||||
const _noNeedRight = 'loginToIm,getI18nMessage,putI18nCollect,fastWhereTree,loadStores,loadWarehouses,loadExpressInterfaces,getImages,getCOSUploadConfig,uploadSuccessNotify,getMessageDetail,searchSpace,searchSpaces,listInterfaceTypes,getLocationTypeList,getQimenAppList,getExpressList,getExpressProductTypeList,getPlatformList,getPrintPlatformList,getPlatformOauthLink,listenPlatformOauthBind,recognizeLicensePlate,getCainiaoStfTemplates,getPrintPlatformTemplateList,polyapiAuthorizeUrl,toOrder';
|
const _noNeedRight = 'loginToIm,getI18nMessage,putI18nCollect,fastWhereTree,loadStores,loadWarehouses,loadExpressInterfaces,getImages,getCOSUploadConfig,uploadSuccessNotify,getMessageDetail,searchSpace,listInterfaceTypes,getLocationTypeList,getQimenAppList,getExpressList,getExpressProductTypeList,getPlatformList,getPrintPlatformList,getPlatformOauthLink,listenPlatformOauthBind,recognizeLicensePlate,getCainiaoStfTemplates,getPrintPlatformTemplateList,polyapiAuthorizeUrl,toOrder';
|
||||||
const _noNeedLog = '*';
|
const _noNeedLog = '*';
|
||||||
const _noNeedAuth = 'loginToIm,getI18nMessage,putI18nCollect,fastWhereTree,loadStores,loadWarehouses,loadExpressInterfaces,getImages,getMessageDetail,searchSpace,searchSpaces,listInterfaceTypes,getLocationTypeList,getQimenAppList,getExpressList,getExpressProductTypeList,getPlatformList,getPrintPlatformList,getPlatformOauthLink,listenPlatformOauthBind,recognizeLicensePlate,test,getCainiaoStfTemplates,getPrintPlatformTemplateList,polyapiAuthorizeUrl,toOrder';
|
const _noNeedAuth = 'loginToIm,getI18nMessage,putI18nCollect,fastWhereTree,loadStores,loadWarehouses,loadExpressInterfaces,getImages,getMessageDetail,searchSpace,listInterfaceTypes,getLocationTypeList,getQimenAppList,getExpressList,getExpressProductTypeList,getPlatformList,getPrintPlatformList,getPlatformOauthLink,listenPlatformOauthBind,recognizeLicensePlate,test,getCainiaoStfTemplates,getPrintPlatformTemplateList,polyapiAuthorizeUrl,toOrder';
|
||||||
this.systemInit(_noNeedLogin, _noNeedRight, _noNeedLog, _noNeedAuth);
|
this.systemInit(_noNeedLogin, _noNeedRight, _noNeedLog, _noNeedAuth);
|
||||||
}
|
}
|
||||||
async fastWhereTree(data) {
|
async fastWhereTree(data) {
|
||||||
@ -1578,11 +1578,6 @@ class indexService extends MainService {
|
|||||||
const result = await service.systems.space.searchSpace(data);
|
const result = await service.systems.space.searchSpace(data);
|
||||||
return this.success('ok', result);
|
return this.success('ok', result);
|
||||||
}
|
}
|
||||||
async searchSpaces(data) {
|
|
||||||
const { service } = this;
|
|
||||||
const result = await service.systems.space.searchSpaces(data);
|
|
||||||
return this.success('ok', result);
|
|
||||||
}
|
|
||||||
async listInterfaceTypes() {
|
async listInterfaceTypes() {
|
||||||
const { ctx } = this;
|
const { ctx } = this;
|
||||||
const rows = await ctx.model.InterfaceType.findAll({
|
const rows = await ctx.model.InterfaceType.findAll({
|
||||||
|
|||||||
@ -938,70 +938,6 @@ class OrderBaseService extends MainService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 批量补齐订单列表的波次内序号(wms_order_wave_index.wave_index)。
|
|
||||||
* 表无记录或查询异常时降级为 0,不影响列表主流程。
|
|
||||||
* @param {Object[]} list 订单列表,每项需含 id(订单ID)。
|
|
||||||
* @return {Promise<Object[]>} 补齐 wave_index 后的列表。
|
|
||||||
*/
|
|
||||||
async attachOrderWaveIndex(list = []) {
|
|
||||||
if (!Array.isArray(list) || list.length === 0) {
|
|
||||||
return Array.isArray(list) ? list : [];
|
|
||||||
}
|
|
||||||
|
|
||||||
const orderIds = Array.from(new Set(
|
|
||||||
list
|
|
||||||
.map(item => Number(item && item.id))
|
|
||||||
.filter(value => Number.isFinite(value) && value > 0)
|
|
||||||
));
|
|
||||||
|
|
||||||
if (orderIds.length === 0) {
|
|
||||||
return list.map(item => ({ ...item, wave_index: 0 }));
|
|
||||||
}
|
|
||||||
|
|
||||||
const warehouseId = this.getWarehouseId();
|
|
||||||
const { ctx } = this;
|
|
||||||
const waveIndexMap = new Map();
|
|
||||||
|
|
||||||
if (warehouseId !== null && warehouseId !== undefined && warehouseId !== ''
|
|
||||||
&& ctx.model && typeof ctx.model.query === 'function') {
|
|
||||||
try {
|
|
||||||
const rows = await ctx.model.query(`
|
|
||||||
SELECT order_id, wave_index
|
|
||||||
FROM wms_order_wave_index
|
|
||||||
WHERE warehouse_id = :warehouseId
|
|
||||||
AND order_id IN (:orderIds)
|
|
||||||
`, {
|
|
||||||
replacements: { warehouseId, orderIds },
|
|
||||||
type: ctx.model.QueryTypes && ctx.model.QueryTypes.SELECT,
|
|
||||||
});
|
|
||||||
|
|
||||||
for (const row of (Array.isArray(rows) ? rows : [])) {
|
|
||||||
const orderId = Number(row && row.order_id || 0);
|
|
||||||
if (orderId > 0) {
|
|
||||||
waveIndexMap.set(orderId, Number(row && row.wave_index || 0));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
ctx.logger && ctx.logger.warn && ctx.logger.warn('[order.base.attachOrderWaveIndex] 查询波次序号失败,已降级为 0', {
|
|
||||||
warehouseId,
|
|
||||||
orderCount: orderIds.length,
|
|
||||||
error: error && error.message ? error.message : `${error}`,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return list.map(item => {
|
|
||||||
const orderId = Number(item && item.id);
|
|
||||||
return {
|
|
||||||
...item,
|
|
||||||
wave_index: Number.isFinite(orderId) && orderId > 0 && waveIndexMap.has(orderId)
|
|
||||||
? waveIndexMap.get(orderId)
|
|
||||||
: 0,
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 提取订单列表中的运单号虚拟筛选条件。
|
* 提取订单列表中的运单号虚拟筛选条件。
|
||||||
* @param {Object} whereInput 标准化后的 where 条件。
|
* @param {Object} whereInput 标准化后的 where 条件。
|
||||||
@ -1092,230 +1028,6 @@ class OrderBaseService extends MainService {
|
|||||||
return { where: normalizedWhere, stockQuery };
|
return { where: normalizedWhere, stockQuery };
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 提取 wave_index(波次内序号)虚拟筛选条件。
|
|
||||||
* 序号存储在 wms_order_wave_index 副表,需先查副表得到订单 ID 集合再注入主查询。
|
|
||||||
* 支持 eq / in / gt / lt / ge / le / between / notbetween 等操作符,
|
|
||||||
* 其中 between 要求 value 为长度为 2 的数组(如 [1, 50])。
|
|
||||||
* @param {Object} whereInput 标准化后的 where 条件。
|
|
||||||
* @return {{ where: Object, waveIndexCondition: Object|null }} 清洗后的 where 与序号筛选条件。
|
|
||||||
*/
|
|
||||||
extractWaveIndexVirtualFilter(whereInput = {}) {
|
|
||||||
const normalizedWhere = this.isPlainObject(whereInput)
|
|
||||||
? { ...whereInput }
|
|
||||||
: {};
|
|
||||||
const waveIndexCondition = normalizedWhere.wave_index ?? normalizedWhere.waveIndex;
|
|
||||||
|
|
||||||
delete normalizedWhere.wave_index;
|
|
||||||
delete normalizedWhere.waveIndex;
|
|
||||||
|
|
||||||
// 条件为空时忽略
|
|
||||||
if (waveIndexCondition === undefined || waveIndexCondition === null || waveIndexCondition === '') {
|
|
||||||
return { where: normalizedWhere, waveIndexCondition: null };
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.isPlainObject(waveIndexCondition)
|
|
||||||
&& (waveIndexCondition.value === undefined || waveIndexCondition.value === null || waveIndexCondition.value === '')) {
|
|
||||||
return { where: normalizedWhere, waveIndexCondition: null };
|
|
||||||
}
|
|
||||||
|
|
||||||
// 兼容简写:wave_index 直接传数值时按 eq 处理
|
|
||||||
const normalizedCondition = this.isPlainObject(waveIndexCondition)
|
|
||||||
? { ...waveIndexCondition }
|
|
||||||
: { operator: 'eq', value: waveIndexCondition };
|
|
||||||
|
|
||||||
return { where: normalizedWhere, waveIndexCondition: normalizedCondition };
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 提取 wave_scope(波次范围)虚拟筛选条件。
|
|
||||||
* 将其从 where 中移除并解析为波次范围值集合,后续通过 wms_wave_batch 反查波次ID注入条件。
|
|
||||||
* 取值约定:0=未分配波次,1=团购,2=散单;value 支持单个值或数组(多选)。
|
|
||||||
* @param {Object} whereInput 标准化后的 where 条件。
|
|
||||||
* @return {{ where: Object, waveScope: number[]|null }} 清洗后的 where 与波次范围值集合。
|
|
||||||
*/
|
|
||||||
extractWaveScopeVirtualFilter(whereInput = {}) {
|
|
||||||
const normalizedWhere = this.isPlainObject(whereInput)
|
|
||||||
? { ...whereInput }
|
|
||||||
: {};
|
|
||||||
const waveScopeCondition = normalizedWhere.wave_scope ?? normalizedWhere.waveScope;
|
|
||||||
|
|
||||||
delete normalizedWhere.wave_scope;
|
|
||||||
delete normalizedWhere.waveScope;
|
|
||||||
|
|
||||||
// 条件为空时忽略
|
|
||||||
if (waveScopeCondition === undefined || waveScopeCondition === null || waveScopeCondition === '') {
|
|
||||||
return { where: normalizedWhere, waveScope: null };
|
|
||||||
}
|
|
||||||
|
|
||||||
const sourceValue = this.isPlainObject(waveScopeCondition)
|
|
||||||
&& Object.prototype.hasOwnProperty.call(waveScopeCondition, 'value')
|
|
||||||
? waveScopeCondition.value
|
|
||||||
: waveScopeCondition;
|
|
||||||
|
|
||||||
// 兼容简写:wave_scope 直接传数值或数组时按 eq/in 处理
|
|
||||||
const sourceItems = Array.isArray(sourceValue) ? sourceValue : [ sourceValue ];
|
|
||||||
const normalizedScopes = Array.from(new Set(
|
|
||||||
sourceItems
|
|
||||||
.filter(item => item !== undefined && item !== null && item !== '')
|
|
||||||
.map(item => Number(item))
|
|
||||||
));
|
|
||||||
|
|
||||||
for (const scope of normalizedScopes) {
|
|
||||||
if (!Number.isInteger(scope) || scope < 0 || scope > 2) {
|
|
||||||
throw new Error('wave_scope 参数不合法,仅支持 0(未分配波次)/1(团购)/2(散单)');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
where: normalizedWhere,
|
|
||||||
waveScope: normalizedScopes.length > 0 ? normalizedScopes : null,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据 wave_index 筛选条件查询 wms_order_wave_index 命中的订单ID。
|
|
||||||
* @param {Object} waveIndexCondition 序号筛选条件(含 operator/value)。
|
|
||||||
* @param {number|string} warehouseId 仓库ID。
|
|
||||||
* @return {Promise<number[]>} 命中的订单ID列表。
|
|
||||||
*/
|
|
||||||
async findOrderIdsByWaveIndexCondition(waveIndexCondition = null, warehouseId = this.getWarehouseId()) {
|
|
||||||
const contextWarehouseId = this.getWarehouseId();
|
|
||||||
|
|
||||||
if (contextWarehouseId === null || contextWarehouseId === undefined || contextWarehouseId === '') {
|
|
||||||
throw new Error('缺少当前用户仓库上下文 store_id');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (warehouseId !== null && warehouseId !== undefined && warehouseId !== ''
|
|
||||||
&& String(warehouseId) !== String(contextWarehouseId)) {
|
|
||||||
throw new Error('订单工作台仓库ID必须来自当前用户上下文 store_id,禁止传入外部仓库ID。');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!waveIndexCondition || !this.isPlainObject(waveIndexCondition)) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
const orderWaveIndexModel = this.ctx.model && this.ctx.model.OrderWaveIndex;
|
|
||||||
if (!orderWaveIndexModel || typeof orderWaveIndexModel.findAll !== 'function') {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
const parsed = parseWhereConditions({
|
|
||||||
where: { wave_index: waveIndexCondition },
|
|
||||||
app: this.app,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!parsed.ok) {
|
|
||||||
throw new Error(`wave_index 参数解析失败: ${parsed.reason}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
const { Sequelize } = this.app;
|
|
||||||
const conditions = Array.isArray(parsed.result.dynamicConditions)
|
|
||||||
? parsed.result.dynamicConditions
|
|
||||||
: [];
|
|
||||||
|
|
||||||
if (conditions.length === 0) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
const waveIndexWhere = conditions.length > 1
|
|
||||||
? { [Sequelize.Op.and]: conditions }
|
|
||||||
: conditions[0];
|
|
||||||
|
|
||||||
const rows = await orderWaveIndexModel.findAll({
|
|
||||||
where: {
|
|
||||||
[Sequelize.Op.and]: [
|
|
||||||
waveIndexWhere,
|
|
||||||
{ warehouse_id: contextWarehouseId },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
attributes: [ 'order_id' ],
|
|
||||||
raw: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
return Array.from(new Set((Array.isArray(rows) ? rows : [])
|
|
||||||
.map(row => Number(row && row.order_id))
|
|
||||||
.filter(orderId => Number.isFinite(orderId) && orderId > 0)));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据波次范围(wave_scope)构建订单表 wave_id 过滤条件。
|
|
||||||
* 0(未分配波次)直接生成 wave_id = 0;1(团购)/2(散单)先查 wms_wave_batch
|
|
||||||
* 得到对应 wave_type 的波次ID集合,再生成 wave_id in (...)。
|
|
||||||
* @param {Array<number>} waveScopes 波次范围值集合(0/1/2)。
|
|
||||||
* @param {number|string} [warehouseId] 仓库ID。
|
|
||||||
* @return {Promise<Object|null>} Sequelize 条件,无有效范围时返回 null。
|
|
||||||
*/
|
|
||||||
async buildWaveScopeWhereCondition(waveScopes = [], warehouseId = this.getWarehouseId()) {
|
|
||||||
const contextWarehouseId = this.getWarehouseId();
|
|
||||||
|
|
||||||
if (contextWarehouseId === null || contextWarehouseId === undefined || contextWarehouseId === '') {
|
|
||||||
throw new Error('缺少当前用户仓库上下文 store_id');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (warehouseId !== null && warehouseId !== undefined && warehouseId !== ''
|
|
||||||
&& String(warehouseId) !== String(contextWarehouseId)) {
|
|
||||||
throw new Error('订单工作台仓库ID必须来自当前用户上下文 store_id,禁止传入外部仓库ID。');
|
|
||||||
}
|
|
||||||
|
|
||||||
const normalizedScopes = Array.from(new Set(
|
|
||||||
(Array.isArray(waveScopes) ? waveScopes : [ waveScopes ])
|
|
||||||
.filter(scope => scope !== undefined && scope !== null && scope !== '')
|
|
||||||
.map(scope => Number(scope))
|
|
||||||
)).filter(scope => Number.isInteger(scope) && scope >= 0 && scope <= 2);
|
|
||||||
|
|
||||||
if (normalizedScopes.length === 0) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const { Op } = this.app.Sequelize;
|
|
||||||
const waveTypeScopes = normalizedScopes.filter(scope => scope === 1 || scope === 2);
|
|
||||||
const conditions = [];
|
|
||||||
|
|
||||||
if (normalizedScopes.includes(0)) {
|
|
||||||
conditions.push({ wave_id: 0 });
|
|
||||||
}
|
|
||||||
|
|
||||||
if (waveTypeScopes.length > 0) {
|
|
||||||
const waveBatchModel = this.ctx.model && this.ctx.model.WaveBatch;
|
|
||||||
const waveIds = [];
|
|
||||||
if (waveBatchModel && typeof waveBatchModel.findAll === 'function') {
|
|
||||||
const waveRows = await waveBatchModel.findAll({
|
|
||||||
attributes: [ 'wave_id' ],
|
|
||||||
where: {
|
|
||||||
warehouse_id: contextWarehouseId,
|
|
||||||
wave_type: {
|
|
||||||
[Op.in]: waveTypeScopes,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
raw: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
for (const row of Array.isArray(waveRows) ? waveRows : []) {
|
|
||||||
const waveId = Number(row && row.wave_id || 0);
|
|
||||||
if (waveId > 0) {
|
|
||||||
waveIds.push(waveId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 空集合时 Op.in: [] 生成恒假条件,保证团购/散单无波次时结果为空
|
|
||||||
conditions.push({
|
|
||||||
wave_id: {
|
|
||||||
[Op.in]: Array.from(new Set(waveIds)),
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (conditions.length === 1) {
|
|
||||||
return conditions[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
[Op.or]: conditions,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构建 buyer_message_has 虚拟字段的 Sequelize where 条件。
|
* 构建 buyer_message_has 虚拟字段的 Sequelize where 条件。
|
||||||
* 覆盖三个留言/备注字段:buyer_message、seller_message、remark。
|
* 覆盖三个留言/备注字段:buyer_message、seller_message、remark。
|
||||||
@ -1717,9 +1429,7 @@ class OrderBaseService extends MainService {
|
|||||||
const { where: sanitizedWhere, expressNumbers } = this.extractOrderListExpressVirtualFilter(where);
|
const { where: sanitizedWhere, expressNumbers } = this.extractOrderListExpressVirtualFilter(where);
|
||||||
const { where: whereAfterBuyerMessage, buyerMessageHas } = this.extractBuyerMessageHasVirtualFilter(sanitizedWhere);
|
const { where: whereAfterBuyerMessage, buyerMessageHas } = this.extractBuyerMessageHasVirtualFilter(sanitizedWhere);
|
||||||
const { where: whereAfterStockQuery, stockQuery } = this.extractStockQueryVirtualFilter(whereAfterBuyerMessage);
|
const { where: whereAfterStockQuery, stockQuery } = this.extractStockQueryVirtualFilter(whereAfterBuyerMessage);
|
||||||
const { where: whereAfterWaveIndex, waveIndexCondition } = this.extractWaveIndexVirtualFilter(whereAfterStockQuery);
|
const mergedWhere = this.mergeWhereObjects(this.getDefaultWhere(moduleName), whereAfterStockQuery);
|
||||||
const { where: whereAfterWaveScope, waveScope } = this.extractWaveScopeVirtualFilter(whereAfterWaveIndex);
|
|
||||||
const mergedWhere = this.mergeWhereObjects(this.getDefaultWhere(moduleName), whereAfterWaveScope);
|
|
||||||
let queryWhere = this.buildWhere(mergedWhere, contextWarehouseId, {
|
let queryWhere = this.buildWhere(mergedWhere, contextWarehouseId, {
|
||||||
specialFieldMap: {
|
specialFieldMap: {
|
||||||
quickWhere: {
|
quickWhere: {
|
||||||
@ -1743,16 +1453,6 @@ class OrderBaseService extends MainService {
|
|||||||
queryWhere = this.appendOrderIdsFilterToWhere(queryWhere, stockOrderIds);
|
queryWhere = this.appendOrderIdsFilterToWhere(queryWhere, stockOrderIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (waveIndexCondition) {
|
|
||||||
const waveIndexOrderIds = await this.findOrderIdsByWaveIndexCondition(waveIndexCondition, contextWarehouseId);
|
|
||||||
queryWhere = this.appendOrderIdsFilterToWhere(queryWhere, waveIndexOrderIds);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (waveScope) {
|
|
||||||
const waveScopeCondition = await this.buildWaveScopeWhereCondition(waveScope, contextWarehouseId);
|
|
||||||
queryWhere = this.appendConditionToWhere(queryWhere, waveScopeCondition);
|
|
||||||
}
|
|
||||||
|
|
||||||
const model = await this.getOrderModel(moduleName, contextWarehouseId);
|
const model = await this.getOrderModel(moduleName, contextWarehouseId);
|
||||||
const order = this.buildListOrder(requestData.sort, moduleName);
|
const order = this.buildListOrder(requestData.sort, moduleName);
|
||||||
const offset = (page - 1) * pageSize;
|
const offset = (page - 1) * pageSize;
|
||||||
@ -1811,12 +1511,11 @@ class OrderBaseService extends MainService {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
const normalizedList = await this.attachOrderExpressNumbers(listWithRemark);
|
const normalizedList = await this.attachOrderExpressNumbers(listWithRemark);
|
||||||
const listWithWaveIndex = await this.attachOrderWaveIndex(normalizedList);
|
|
||||||
|
|
||||||
const totalPages = pageSize > 0 ? Math.ceil(total / pageSize) : 0;
|
const totalPages = pageSize > 0 ? Math.ceil(total / pageSize) : 0;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
list: listWithWaveIndex,
|
list: normalizedList,
|
||||||
pagination: {
|
pagination: {
|
||||||
page,
|
page,
|
||||||
pageSize,
|
pageSize,
|
||||||
|
|||||||
@ -2,14 +2,6 @@
|
|||||||
|
|
||||||
const OrderBaseService = require('./base');
|
const OrderBaseService = require('./base');
|
||||||
|
|
||||||
/**
|
|
||||||
* 允许确认拦截(更新为 intercepted_at_warehouse)的前置拦截状态:
|
|
||||||
* 拦截发起中(requested/requesting/intercepting)与历史遗留值 intercepted。
|
|
||||||
* 其余状态(none/空、intercepted_at_warehouse、intercepted_in_transit、returning、returned、
|
|
||||||
* delivered_by_mistake、timeout、cancelled、failed、exception)一律不允许确认拦截。
|
|
||||||
*/
|
|
||||||
const CONFIRMABLE_INTERCEPT_STATUSES = [ 'requested', 'requesting', 'intercepting', 'intercepted' ];
|
|
||||||
|
|
||||||
class RecheckOrderService extends OrderBaseService {
|
class RecheckOrderService extends OrderBaseService {
|
||||||
/**
|
/**
|
||||||
* 初始化复核订单系统方法免登录、免权限、免日志与免鉴权配置。
|
* 初始化复核订单系统方法免登录、免权限、免日志与免鉴权配置。
|
||||||
@ -3323,65 +3315,6 @@ class RecheckOrderService extends OrderBaseService {
|
|||||||
replacements.pickStatus = pickStatus;
|
replacements.pickStatus = pickStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 波次内序号筛选(wms_order_wave_index.wave_index)
|
|
||||||
// 支持 wave_index: { operator: 'between', value: [起, 止] },以及 wave_index_min / wave_index_max
|
|
||||||
const rawWaveIndexCondition = this.isPlainObject(where.wave_index) ? where.wave_index : null;
|
|
||||||
if (rawWaveIndexCondition) {
|
|
||||||
const waveIndexOperator = String(rawWaveIndexCondition.operator || 'eq').toLowerCase();
|
|
||||||
const rawWaveIndexValue = rawWaveIndexCondition.value;
|
|
||||||
if (waveIndexOperator === 'between' && Array.isArray(rawWaveIndexValue) && rawWaveIndexValue.length === 2) {
|
|
||||||
const betweenStart = Number(rawWaveIndexValue[0]);
|
|
||||||
const betweenEnd = Number(rawWaveIndexValue[1]);
|
|
||||||
if (Number.isFinite(betweenStart) && Number.isFinite(betweenEnd)) {
|
|
||||||
conditions.push('wi.wave_index BETWEEN :waveIndexBetweenStart AND :waveIndexBetweenEnd');
|
|
||||||
replacements.waveIndexBetweenStart = betweenStart;
|
|
||||||
replacements.waveIndexBetweenEnd = betweenEnd;
|
|
||||||
}
|
|
||||||
} else if ((waveIndexOperator === 'gte' || waveIndexOperator === 'ge')
|
|
||||||
&& rawWaveIndexValue !== undefined && rawWaveIndexValue !== null && rawWaveIndexValue !== '') {
|
|
||||||
const gteValue = Number(rawWaveIndexValue);
|
|
||||||
if (Number.isFinite(gteValue)) {
|
|
||||||
conditions.push('wi.wave_index >= :waveIndexGte');
|
|
||||||
replacements.waveIndexGte = gteValue;
|
|
||||||
}
|
|
||||||
} else if ((waveIndexOperator === 'lte' || waveIndexOperator === 'le')
|
|
||||||
&& rawWaveIndexValue !== undefined && rawWaveIndexValue !== null && rawWaveIndexValue !== '') {
|
|
||||||
const lteValue = Number(rawWaveIndexValue);
|
|
||||||
if (Number.isFinite(lteValue)) {
|
|
||||||
conditions.push('wi.wave_index <= :waveIndexLte');
|
|
||||||
replacements.waveIndexLte = lteValue;
|
|
||||||
}
|
|
||||||
} else if (waveIndexOperator === 'eq'
|
|
||||||
&& rawWaveIndexValue !== undefined && rawWaveIndexValue !== null && rawWaveIndexValue !== '') {
|
|
||||||
const eqValue = Number(rawWaveIndexValue);
|
|
||||||
if (Number.isFinite(eqValue)) {
|
|
||||||
conditions.push('wi.wave_index = :waveIndexEq');
|
|
||||||
replacements.waveIndexEq = eqValue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
const rawWaveIndexMin = this.isPlainObject(where.wave_index_min)
|
|
||||||
? where.wave_index_min.value
|
|
||||||
: where.wave_index_min;
|
|
||||||
if (rawWaveIndexMin !== undefined && rawWaveIndexMin !== null && rawWaveIndexMin !== '') {
|
|
||||||
const waveIndexMin = Number(rawWaveIndexMin);
|
|
||||||
if (Number.isFinite(waveIndexMin)) {
|
|
||||||
conditions.push('wi.wave_index >= :waveIndexMin');
|
|
||||||
replacements.waveIndexMin = waveIndexMin;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const rawWaveIndexMax = this.isPlainObject(where.wave_index_max)
|
|
||||||
? where.wave_index_max.value
|
|
||||||
: where.wave_index_max;
|
|
||||||
if (rawWaveIndexMax !== undefined && rawWaveIndexMax !== null && rawWaveIndexMax !== '') {
|
|
||||||
const waveIndexMax = Number(rawWaveIndexMax);
|
|
||||||
if (Number.isFinite(waveIndexMax)) {
|
|
||||||
conditions.push('wi.wave_index <= :waveIndexMax');
|
|
||||||
replacements.waveIndexMax = waveIndexMax;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// stock_query 商品模糊筛选:通过 stock_warehouse / stock_barcodes → order_items → order_id
|
// stock_query 商品模糊筛选:通过 stock_warehouse / stock_barcodes → order_items → order_id
|
||||||
const stockQuery = String(where.stock_query || '').trim();
|
const stockQuery = String(where.stock_query || '').trim();
|
||||||
if (stockQuery) {
|
if (stockQuery) {
|
||||||
@ -3409,11 +3342,6 @@ class RecheckOrderService extends OrderBaseService {
|
|||||||
? `WHERE ${conditions.join('\n AND ')}`
|
? `WHERE ${conditions.join('\n AND ')}`
|
||||||
: '';
|
: '';
|
||||||
|
|
||||||
const waveIndexJoin = `
|
|
||||||
LEFT JOIN wms_order_wave_index wi
|
|
||||||
ON wi.warehouse_id = o.warehouse_id
|
|
||||||
AND wi.order_id = o.id`;
|
|
||||||
|
|
||||||
const listSql = `
|
const listSql = `
|
||||||
SELECT
|
SELECT
|
||||||
o.id AS order_id,
|
o.id AS order_id,
|
||||||
@ -3433,9 +3361,8 @@ class RecheckOrderService extends OrderBaseService {
|
|||||||
o.status,
|
o.status,
|
||||||
o.create_at,
|
o.create_at,
|
||||||
o.recheck_time,
|
o.recheck_time,
|
||||||
wi.wave_index,
|
|
||||||
(SELECT oe.waybill_code FROM order_express oe WHERE oe.order_id = o.id AND oe.delete_at IS NULL LIMIT 1) AS waybill_code
|
(SELECT oe.waybill_code FROM order_express oe WHERE oe.order_id = o.id AND oe.delete_at IS NULL LIMIT 1) AS waybill_code
|
||||||
FROM ${orderTableName} o${waveIndexJoin}
|
FROM ${orderTableName} o
|
||||||
${whereClause}
|
${whereClause}
|
||||||
ORDER BY o.id ASC
|
ORDER BY o.id ASC
|
||||||
LIMIT :limit OFFSET :offset
|
LIMIT :limit OFFSET :offset
|
||||||
@ -3443,7 +3370,7 @@ class RecheckOrderService extends OrderBaseService {
|
|||||||
|
|
||||||
const countSql = `
|
const countSql = `
|
||||||
SELECT COUNT(1) AS total
|
SELECT COUNT(1) AS total
|
||||||
FROM ${orderTableName} o${waveIndexJoin}
|
FROM ${orderTableName} o
|
||||||
${whereClause}
|
${whereClause}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
@ -3478,7 +3405,6 @@ class RecheckOrderService extends OrderBaseService {
|
|||||||
items_weight: row?.items_weight != null ? Number(row.items_weight) : null,
|
items_weight: row?.items_weight != null ? Number(row.items_weight) : null,
|
||||||
weight_type: this.formatWeightTypeLabel(row?.weight_type),
|
weight_type: this.formatWeightTypeLabel(row?.weight_type),
|
||||||
waybill_code: String(row?.waybill_code || '').trim(),
|
waybill_code: String(row?.waybill_code || '').trim(),
|
||||||
wave_index: Number(row?.wave_index || 0),
|
|
||||||
status: Number(row?.status || 0),
|
status: Number(row?.status || 0),
|
||||||
create_at: row?.create_at || null,
|
create_at: row?.create_at || null,
|
||||||
recheck_time: row?.recheck_time || null,
|
recheck_time: row?.recheck_time || null,
|
||||||
@ -3691,93 +3617,34 @@ class RecheckOrderService extends OrderBaseService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 确认仓库拦截:通过订单 ID 列表直接匹配订单,批量将其拦截状态更新为"仓库拦截成功"。
|
* 确认仓库拦截:通过订单ID直接匹配订单,将其拦截状态更新为"仓库拦截成功"。
|
||||||
* 仅拦截当前指定订单(不波及波次内其他订单),支持部分失败:未找到的订单与处理失败的
|
* 仅拦截当前指定订单(不波及波次内其他订单)。
|
||||||
* 订单记录在 failed 列表并返回失败原因,其余订单继续处理。
|
|
||||||
*
|
|
||||||
* 前置条件:订单必须处于拦截发起中状态(requested/requesting/intercepting,历史值 intercepted 兼容)。
|
|
||||||
* 未发起拦截(none/空)的订单直接静默跳过不参与处理;已确认拦截(intercepted_at_warehouse)及其它
|
|
||||||
* 非可确认状态(intercepted_in_transit/returning/returned/delivered_by_mistake/timeout/cancelled/failed/
|
|
||||||
* exception)的订单一律跳过并记录失败原因;更新 SQL 的 where 同时限定拦截状态,防止并发修改导致误更新。
|
|
||||||
*
|
|
||||||
* 每个订单的拦截处理:
|
|
||||||
* 1. 更新 wms_order_delivery:intercept_status = intercepted_at_warehouse、step=4、outbound_status=fin
|
|
||||||
* 2. 同步更新运单表:is_intercept='Y'、is_back='Y'(库内拦截确认,货物在库内需退回)
|
|
||||||
* 3. 释放储位分配(cancelAllocateStorage,归还库存)
|
|
||||||
* 4. 释放订单锁(lock_status='none')
|
|
||||||
* 5. 写入操作日志(ORDER_INTERCEPT_CONFIRM)
|
|
||||||
* 全部订单处理完后,按成功订单 ID 汇总批量创建售后工单 + 通知快递群。
|
|
||||||
* 运单标记、储位释放、锁释放、工单创建、日志写入失败均不影响主流程。
|
|
||||||
*
|
|
||||||
* @param {Object} data 请求体。
|
* @param {Object} data 请求体。
|
||||||
* @param {number[]|string} data.ids 订单 ID 列表,支持数组或以逗号分隔的字符串(兼容 id/order_id/orderId 单值写法)。
|
* @param {number} data.order_id 订单ID。
|
||||||
* @return {Promise<Object>} 批量拦截结果,包含 success/failed 列表与 success_count/failed_count 计数。
|
* @return {Promise<Object>} 拦截确认结果,包含 order_id、intercept_status 与更新时间。
|
||||||
*/
|
*/
|
||||||
async confirmIntercept(data = {}) {
|
async confirmIntercept(data = {}) {
|
||||||
const { ctx } = this;
|
const { ctx } = this;
|
||||||
|
const { order_id } = data;
|
||||||
const warehouseId = this.getWarehouseId();
|
const warehouseId = this.getWarehouseId();
|
||||||
const orderIds = this.normalizeOrderIds(data);
|
const orderId = Number(order_id);
|
||||||
|
|
||||||
if (orderIds.length === 0) {
|
if (!orderId || !Number.isFinite(orderId) || orderId <= 0) {
|
||||||
this.ctx.throw(400, '订单ID列表不能为空');
|
throw new Error('order_id 无效');
|
||||||
}
|
}
|
||||||
|
|
||||||
const orderModel = await this.getOrderModelByTableType('current', warehouseId);
|
const orderModel = await this.getOrderModelByTableType('current', warehouseId);
|
||||||
const orderRows = await orderModel.findAll({
|
const orderWhere = this.buildOrderWhere([ orderId ], warehouseId);
|
||||||
where: this.buildOrderWhere(orderIds, warehouseId),
|
const order = await orderModel.findOne({
|
||||||
|
where: orderWhere,
|
||||||
attributes: [ 'id', 'delivery_order_code', 'pre_delivery_order_code', 'intercept_status', 'wave_no' ],
|
attributes: [ 'id', 'delivery_order_code', 'pre_delivery_order_code', 'intercept_status', 'wave_no' ],
|
||||||
raw: true,
|
raw: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
const orderMap = new Map();
|
|
||||||
for (const row of orderRows) {
|
|
||||||
orderMap.set(Number(row.id), row);
|
|
||||||
}
|
|
||||||
|
|
||||||
const successOrders = [];
|
|
||||||
const failedOrders = [];
|
|
||||||
const successOrderIds = [];
|
|
||||||
|
|
||||||
for (const orderId of orderIds) {
|
|
||||||
const order = orderMap.get(orderId);
|
|
||||||
|
|
||||||
if (!order) {
|
if (!order) {
|
||||||
failedOrders.push({ order_id: orderId, reason: '未找到对应订单' });
|
throw new Error('未找到对应订单');
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const orderWhere = this.buildOrderWhere([ orderId ], warehouseId);
|
|
||||||
const orderNo = String(order.delivery_order_code || order.pre_delivery_order_code || '').trim();
|
|
||||||
const interceptStatus = String(order.intercept_status || '').trim();
|
|
||||||
|
|
||||||
// 未发起拦截(none/空)的订单直接跳过,不参与确认拦截处理
|
|
||||||
if (interceptStatus === '' || interceptStatus === 'none') {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 已确认拦截的订单跳过,避免重复执行副作用(释放储位/工单/日志等)
|
|
||||||
if (interceptStatus === 'intercepted_at_warehouse') {
|
|
||||||
failedOrders.push({
|
|
||||||
order_id: orderId,
|
|
||||||
delivery_order_code: orderNo,
|
|
||||||
reason: '订单已确认拦截',
|
|
||||||
});
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 仅拦截发起中(requested/requesting/intercepting)与历史值 intercepted 允许确认,
|
|
||||||
// 其余状态(intercepted_in_transit/returning/returned/delivered_by_mistake/timeout/
|
|
||||||
// cancelled/failed/exception)不允许确认拦截
|
|
||||||
if (!CONFIRMABLE_INTERCEPT_STATUSES.includes(interceptStatus)) {
|
|
||||||
failedOrders.push({
|
|
||||||
order_id: orderId,
|
|
||||||
delivery_order_code: orderNo,
|
|
||||||
reason: `订单拦截状态不允许确认拦截: ${interceptStatus}`,
|
|
||||||
});
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const updateValues = {
|
const updateValues = {
|
||||||
intercept_status: 'intercepted_at_warehouse',
|
intercept_status: 'intercepted_at_warehouse',
|
||||||
@ -3786,11 +3653,7 @@ class RecheckOrderService extends OrderBaseService {
|
|||||||
updated_at: now,
|
updated_at: now,
|
||||||
};
|
};
|
||||||
const updateResult = await orderModel.update(updateValues, {
|
const updateResult = await orderModel.update(updateValues, {
|
||||||
where: {
|
where: orderWhere,
|
||||||
...orderWhere,
|
|
||||||
// 数据库层再次限定拦截状态,防止查询后状态被并发修改导致误更新
|
|
||||||
intercept_status: { [ctx.app.Sequelize.Op.in]: CONFIRMABLE_INTERCEPT_STATUSES },
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
const affectedRows = Array.isArray(updateResult) ? Number(updateResult[0] || 0) : Number(updateResult || 0);
|
const affectedRows = Array.isArray(updateResult) ? Number(updateResult[0] || 0) : Number(updateResult || 0);
|
||||||
|
|
||||||
@ -3833,6 +3696,22 @@ class RecheckOrderService extends OrderBaseService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 创建售后工单 + 通知快递群(失败不影响主流程)
|
||||||
|
try {
|
||||||
|
const operator = this.getOrderLogOperator();
|
||||||
|
await this.service.systems.afterSale.createInterceptWorkOrdersAndNotify({
|
||||||
|
orderIds: [ orderId ],
|
||||||
|
warehouseId,
|
||||||
|
creatorLabel: operator.name || '系统',
|
||||||
|
});
|
||||||
|
} catch (workOrderErr) {
|
||||||
|
ctx.logger.warn(
|
||||||
|
`[recheckOrder.confirmIntercept] 创建工单/通知失败, orderId=${orderId}, error=${workOrderErr.message}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const orderNo = String(order.delivery_order_code || order.pre_delivery_order_code || '').trim();
|
||||||
|
|
||||||
// 写入操作日志(失败不影响主流程)
|
// 写入操作日志(失败不影响主流程)
|
||||||
try {
|
try {
|
||||||
const operator = this.getOrderLogOperator();
|
const operator = this.getOrderLogOperator();
|
||||||
@ -3857,46 +3736,11 @@ class RecheckOrderService extends OrderBaseService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
successOrders.push({
|
return {
|
||||||
order_id: orderId,
|
order_id: orderId,
|
||||||
order_no: orderNo,
|
order_no: orderNo,
|
||||||
intercept_status: 'intercepted_at_warehouse',
|
intercept_status: 'intercepted_at_warehouse',
|
||||||
updated_at: now,
|
updated_at: now,
|
||||||
});
|
|
||||||
successOrderIds.push(orderId);
|
|
||||||
} catch (error) {
|
|
||||||
ctx.logger.warn(
|
|
||||||
`[recheckOrder.confirmIntercept] 确认拦截失败, orderId=${orderId}, error=${error.message}`
|
|
||||||
);
|
|
||||||
failedOrders.push({
|
|
||||||
order_id: orderId,
|
|
||||||
delivery_order_code: orderNo,
|
|
||||||
reason: `确认拦截失败: ${error.message}`,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 创建售后工单 + 通知快递群(成功订单 ID 汇总统一调用,失败不影响主流程)
|
|
||||||
if (successOrderIds.length > 0) {
|
|
||||||
try {
|
|
||||||
const operator = this.getOrderLogOperator();
|
|
||||||
await this.service.systems.afterSale.createInterceptWorkOrdersAndNotify({
|
|
||||||
orderIds: successOrderIds,
|
|
||||||
warehouseId,
|
|
||||||
creatorLabel: operator.name || '系统',
|
|
||||||
});
|
|
||||||
} catch (workOrderErr) {
|
|
||||||
ctx.logger.warn(
|
|
||||||
`[recheckOrder.confirmIntercept] 创建工单/通知失败, orderIds=${successOrderIds.join(',')}, error=${workOrderErr.message}`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
success: successOrders,
|
|
||||||
failed: failedOrders,
|
|
||||||
success_count: successOrders.length,
|
|
||||||
failed_count: failedOrders.length,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -47,12 +47,6 @@ const WAVE_STRATEGY_FALLBACK_WHERE_FIELD_MAP = Object.freeze({
|
|||||||
province: 'province',
|
province: 'province',
|
||||||
sys_platform_name: 'sys_platform_name',
|
sys_platform_name: 'sys_platform_name',
|
||||||
});
|
});
|
||||||
const WAVE_STRATEGY_FALLBACK_EXCLUDED_REASON_LABELS = Object.freeze({
|
|
||||||
locked: '已锁定',
|
|
||||||
intercepted: '已拦截',
|
|
||||||
printed: '已打印',
|
|
||||||
no_match: '未匹配策略',
|
|
||||||
});
|
|
||||||
const BATCH_LIST_ASSIGNMENT_FILTER_SCHEMAS = Object.freeze({
|
const BATCH_LIST_ASSIGNMENT_FILTER_SCHEMAS = Object.freeze({
|
||||||
storage: Object.freeze({
|
storage: Object.freeze({
|
||||||
fieldName: 'storage_assignment_status',
|
fieldName: 'storage_assignment_status',
|
||||||
@ -110,7 +104,7 @@ class WaveService extends OrderBaseService {
|
|||||||
super(ctx);
|
super(ctx);
|
||||||
const _noNeedLogin = '';
|
const _noNeedLogin = '';
|
||||||
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 _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,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';
|
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);
|
this.systemInit(_noNeedLogin, _noNeedRight, _noNeedLog, _noNeedAuth);
|
||||||
}
|
}
|
||||||
@ -2681,9 +2675,12 @@ class WaveService extends OrderBaseService {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const list = Array.isArray(queryResult && queryResult.rows) ? queryResult.rows : [];
|
const list = Array.isArray(queryResult && queryResult.rows) ? queryResult.rows : [];
|
||||||
|
const strategyIds = [ ...new Set(list
|
||||||
|
.map(item => Number(item && item.id || 0))
|
||||||
|
.filter(item => Number.isInteger(item) && item > 0)) ];
|
||||||
const matchedOrderCountMap = await this.getWaveStrategyMatchedOrderCountFilteredMap(
|
const matchedOrderCountMap = await this.getWaveStrategyMatchedOrderCountFilteredMap(
|
||||||
contextWarehouseId,
|
contextWarehouseId,
|
||||||
list
|
strategyIds
|
||||||
);
|
);
|
||||||
const nextFetchOrderCountMap = calculateNextFetchOrderCount
|
const nextFetchOrderCountMap = calculateNextFetchOrderCount
|
||||||
? await this.getWaveStrategyNextFetchOrderCountMap(contextWarehouseId, list)
|
? await this.getWaveStrategyNextFetchOrderCountMap(contextWarehouseId, list)
|
||||||
@ -2999,54 +2996,33 @@ class WaveService extends OrderBaseService {
|
|||||||
/**
|
/**
|
||||||
* 按策略统计过滤后命中订单数。
|
* 按策略统计过滤后命中订单数。
|
||||||
*
|
*
|
||||||
* 过滤口径与抓取候选 SQL(getWaveStrategyFetchCandidateOrders)保持一致:
|
* 过滤口径:
|
||||||
* 1) 仅统计未在波次订单(wave_id = 0);
|
* 1) 仅统计未在波次订单(wave_id = 0);
|
||||||
* 2) 仅统计 step != 0 的订单;
|
* 2) 仅统计 step != 0 的订单;
|
||||||
* 3) 仅统计状态有效订单(status != cancel 且 outbound_status != padding);
|
* 3) 仅统计状态有效订单(status != cancel 且 outbound_status != padding);
|
||||||
* 4) 同结构数量需落在策略 min_same_structure/max_same_structure 区间内;
|
* 4) 同结构数量需落在策略 min_same_structure/max_same_structure 区间内。
|
||||||
* 当 require_same_express = 1 时按「结构(items_hash) + 快递」分组计数,
|
*
|
||||||
* 否则仅按结构(items_hash)分组计数。
|
* 同结构定义沿用快速扫描口径:优先 items_hash,空时回退 items。
|
||||||
*
|
*
|
||||||
* @param {number|string} warehouseId 仓库ID。
|
* @param {number|string} warehouseId 仓库ID。
|
||||||
* @param {Array<Object|number|string>} strategyRows 当前页策略行数组(含 require_same_express)。
|
* @param {Array<number|string>} strategyIds 当前页策略ID列表。
|
||||||
* @return {Promise<Map<number, number>>} strategy_id 到过滤后命中订单数的映射。
|
* @return {Promise<Map<number, number>>} strategy_id 到过滤后命中订单数的映射。
|
||||||
*/
|
*/
|
||||||
async getWaveStrategyMatchedOrderCountFilteredMap(warehouseId, strategyRows = []) {
|
async getWaveStrategyMatchedOrderCountFilteredMap(warehouseId, strategyIds = []) {
|
||||||
const normalizedWarehouseId = Number(warehouseId || 0);
|
const normalizedWarehouseId = Number(warehouseId || 0);
|
||||||
if (!Number.isInteger(normalizedWarehouseId) || normalizedWarehouseId <= 0) {
|
if (!Number.isInteger(normalizedWarehouseId) || normalizedWarehouseId <= 0) {
|
||||||
throw new Error('未识别到当前仓库上下文');
|
throw new Error('未识别到当前仓库上下文');
|
||||||
}
|
}
|
||||||
|
|
||||||
const normalizedStrategies = [ ...new Map((Array.isArray(strategyRows) ? strategyRows : [])
|
const normalizedStrategyIds = [ ...new Set((Array.isArray(strategyIds) ? strategyIds : [])
|
||||||
.map(item => {
|
.map(item => Number(item))
|
||||||
const strategyId = Number(item && (item.id ?? item.strategy_id) || 0);
|
.filter(item => Number.isInteger(item) && item > 0)) ];
|
||||||
if (!Number.isInteger(strategyId) || strategyId <= 0) {
|
if (normalizedStrategyIds.length === 0) {
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return [ strategyId, {
|
|
||||||
id: strategyId,
|
|
||||||
requireSameExpress: Number(item && item.require_same_express || 0) === 1,
|
|
||||||
}];
|
|
||||||
})
|
|
||||||
.filter(Boolean)).values() ];
|
|
||||||
if (normalizedStrategies.length === 0) {
|
|
||||||
return new Map();
|
return new Map();
|
||||||
}
|
}
|
||||||
|
|
||||||
const orderModel = await this.getOrderModel('pendingOrder', normalizedWarehouseId);
|
const orderModel = await this.getOrderModel('pendingOrder', normalizedWarehouseId);
|
||||||
const orderTableName = this.getModelTableSqlName(orderModel);
|
const orderTableName = this.getModelTableSqlName(orderModel);
|
||||||
const expressExpr = alias => `COALESCE(NULLIF(TRIM(COALESCE(${alias}.sys_logistics_code, '')), ''), NULLIF(TRIM(COALESCE(${alias}.logistics_code, '')), ''), TRIM(COALESCE(${alias}.logistics_name, '')))`;
|
|
||||||
|
|
||||||
const matchedMap = new Map();
|
|
||||||
const runCountQuery = async (strategyGroup, requireSameExpress) => {
|
|
||||||
const strategyIds = strategyGroup.map(item => item.id);
|
|
||||||
if (strategyIds.length === 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const groupKeyExtra = requireSameExpress ? `, ${expressExpr('src')} AS express_key` : '';
|
|
||||||
const joinKeyExtra = requireSameExpress ? ` AND same_structure.express_key = ${expressExpr('o')}` : '';
|
|
||||||
const querySql = `
|
const querySql = `
|
||||||
SELECT
|
SELECT
|
||||||
m.strategy_id,
|
m.strategy_id,
|
||||||
@ -3066,7 +3042,7 @@ class WaveService extends OrderBaseService {
|
|||||||
AND o.lock_status = 'none'
|
AND o.lock_status = 'none'
|
||||||
INNER JOIN (
|
INNER JOIN (
|
||||||
SELECT
|
SELECT
|
||||||
src.items_hash AS structure_key${groupKeyExtra},
|
src.items_hash AS structure_key,
|
||||||
COUNT(1) AS same_structure_count
|
COUNT(1) AS same_structure_count
|
||||||
FROM ${orderTableName} src
|
FROM ${orderTableName} src
|
||||||
WHERE src.warehouse_id = :warehouseId
|
WHERE src.warehouse_id = :warehouseId
|
||||||
@ -3079,27 +3055,28 @@ class WaveService extends OrderBaseService {
|
|||||||
AND src.outbound_status != 'padding'
|
AND src.outbound_status != 'padding'
|
||||||
AND src.intercept_status = 'none'
|
AND src.intercept_status = 'none'
|
||||||
AND src.lock_status = 'none'
|
AND src.lock_status = 'none'
|
||||||
GROUP BY src.items_hash${requireSameExpress ? `, ${expressExpr('src')}` : ''}
|
GROUP BY src.items_hash
|
||||||
) same_structure
|
) same_structure
|
||||||
ON same_structure.structure_key = o.items_hash${joinKeyExtra}
|
ON same_structure.structure_key = o.items_hash
|
||||||
INNER JOIN wms_wave_strategy s
|
INNER JOIN wms_wave_strategy s
|
||||||
ON s.id = m.strategy_id
|
ON s.id = m.strategy_id
|
||||||
AND s.warehouse_id = :warehouseId
|
AND s.warehouse_id = :warehouseId
|
||||||
WHERE m.warehouse_id = :warehouseId
|
WHERE m.warehouse_id = :warehouseId
|
||||||
AND m.strategy_id IN (:strategyIds)
|
AND m.strategy_id IN (:strategyIds)
|
||||||
AND same_structure.same_structure_count >= COALESCE(NULLIF(s.min_same_structure, 0), 0)
|
AND same_structure.same_structure_count >= COALESCE(s.min_same_structure, 0)
|
||||||
AND (s.max_same_structure IS NULL OR s.max_same_structure <= 0 OR same_structure.same_structure_count <= s.max_same_structure)
|
AND (s.max_same_structure IS NULL OR same_structure.same_structure_count <= s.max_same_structure)
|
||||||
GROUP BY m.strategy_id
|
GROUP BY m.strategy_id
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const queryRows = await this.ctx.model.query(querySql, {
|
const queryRows = await this.ctx.model.query(querySql, {
|
||||||
replacements: {
|
replacements: {
|
||||||
warehouseId: normalizedWarehouseId,
|
warehouseId: normalizedWarehouseId,
|
||||||
strategyIds,
|
strategyIds: normalizedStrategyIds,
|
||||||
},
|
},
|
||||||
type: this.ctx.model.QueryTypes.SELECT,
|
type: this.ctx.model.QueryTypes.SELECT,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const matchedMap = new Map();
|
||||||
(Array.isArray(queryRows) ? queryRows : []).forEach(row => {
|
(Array.isArray(queryRows) ? queryRows : []).forEach(row => {
|
||||||
const strategyId = Number(row && row.strategy_id || 0);
|
const strategyId = Number(row && row.strategy_id || 0);
|
||||||
const matchedCount = Number(row && row.matched_order_count_filtered || 0);
|
const matchedCount = Number(row && row.matched_order_count_filtered || 0);
|
||||||
@ -3109,12 +3086,6 @@ class WaveService extends OrderBaseService {
|
|||||||
|
|
||||||
matchedMap.set(strategyId, matchedCount);
|
matchedMap.set(strategyId, matchedCount);
|
||||||
});
|
});
|
||||||
};
|
|
||||||
|
|
||||||
await Promise.all([
|
|
||||||
runCountQuery(normalizedStrategies.filter(item => item.requireSameExpress), true),
|
|
||||||
runCountQuery(normalizedStrategies.filter(item => !item.requireSameExpress), false),
|
|
||||||
]);
|
|
||||||
|
|
||||||
return matchedMap;
|
return matchedMap;
|
||||||
}
|
}
|
||||||
@ -4007,12 +3978,6 @@ class WaveService extends OrderBaseService {
|
|||||||
buildWaveStrategyFallbackOrderListItem(orderRow = {}, itemSnapshot = '') {
|
buildWaveStrategyFallbackOrderListItem(orderRow = {}, itemSnapshot = '') {
|
||||||
const normalizedOrderRow = this.isPlainObject(orderRow) ? orderRow : {};
|
const normalizedOrderRow = this.isPlainObject(orderRow) ? orderRow : {};
|
||||||
|
|
||||||
// normalizeOrderListItem 已将 lock_status 归一化为 Y/N(none→N,其余→Y),
|
|
||||||
// 这里兼容归一化值(Y/N)与原始值(none/warehouse/store),避免把 N 误判为已锁定。
|
|
||||||
const lockStatus = String(normalizedOrderRow.lock_status || '').trim();
|
|
||||||
const isLocked = lockStatus === 'Y'
|
|
||||||
|| (lockStatus !== '' && lockStatus !== 'N' && lockStatus !== 'none');
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: normalizedOrderRow.id ?? null,
|
id: normalizedOrderRow.id ?? null,
|
||||||
delivery_no: normalizedOrderRow.delivery_no ?? normalizedOrderRow.delivery_order_code ?? null,
|
delivery_no: normalizedOrderRow.delivery_no ?? normalizedOrderRow.delivery_order_code ?? null,
|
||||||
@ -4026,14 +3991,13 @@ class WaveService extends OrderBaseService {
|
|||||||
province: normalizedOrderRow.province ?? null,
|
province: normalizedOrderRow.province ?? null,
|
||||||
sys_platform_name: normalizedOrderRow.sys_platform_name ?? null,
|
sys_platform_name: normalizedOrderRow.sys_platform_name ?? null,
|
||||||
item_snapshot: String(itemSnapshot || ''),
|
item_snapshot: String(itemSnapshot || ''),
|
||||||
wave_index: Number(normalizedOrderRow.wave_index || 0),
|
excluded_reason: normalizedOrderRow.lock_status !== 'none'
|
||||||
excluded_reason: isLocked
|
? 'locked'
|
||||||
? WAVE_STRATEGY_FALLBACK_EXCLUDED_REASON_LABELS.locked
|
|
||||||
: normalizedOrderRow.intercept_status !== 'none'
|
: normalizedOrderRow.intercept_status !== 'none'
|
||||||
? WAVE_STRATEGY_FALLBACK_EXCLUDED_REASON_LABELS.intercepted
|
? 'intercepted'
|
||||||
: normalizedOrderRow.print_status === 'fin'
|
: normalizedOrderRow.print_status === 'fin'
|
||||||
? WAVE_STRATEGY_FALLBACK_EXCLUDED_REASON_LABELS.printed
|
? 'printed'
|
||||||
: WAVE_STRATEGY_FALLBACK_EXCLUDED_REASON_LABELS.no_match,
|
: 'no_match',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4122,10 +4086,8 @@ class WaveService extends OrderBaseService {
|
|||||||
}),
|
}),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const normalizedList = await this.attachOrderWaveIndex(
|
const normalizedList = await this.attachOrderExpressNumbers(
|
||||||
await this.attachOrderExpressNumbers(
|
|
||||||
sourceList.map(item => this.normalizeOrderListItem(item))
|
sourceList.map(item => this.normalizeOrderListItem(item))
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// 回填 item_snapshot
|
// 回填 item_snapshot
|
||||||
@ -6583,6 +6545,9 @@ class WaveService extends OrderBaseService {
|
|||||||
const normalizedOrder = this.isPlainObject(order) ? order : {};
|
const normalizedOrder = this.isPlainObject(order) ? order : {};
|
||||||
const normalizedStrategy = this.isPlainObject(strategy) ? strategy : {};
|
const normalizedStrategy = this.isPlainObject(strategy) ? strategy : {};
|
||||||
const structureStoreSetMap = context && context.structureStoreSetMap instanceof Map ? context.structureStoreSetMap : new Map();
|
const structureStoreSetMap = context && context.structureStoreSetMap instanceof Map ? context.structureStoreSetMap : new Map();
|
||||||
|
const structurePrimaryExpressMap = context && context.structurePrimaryExpressMap instanceof Map
|
||||||
|
? context.structurePrimaryExpressMap
|
||||||
|
: null;
|
||||||
const structurePrimaryOwnerMap = context && context.structurePrimaryOwnerMap instanceof Map
|
const structurePrimaryOwnerMap = context && context.structurePrimaryOwnerMap instanceof Map
|
||||||
? context.structurePrimaryOwnerMap
|
? context.structurePrimaryOwnerMap
|
||||||
: null;
|
: null;
|
||||||
@ -6608,6 +6573,18 @@ class WaveService extends OrderBaseService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (normalizedStrategy.require_same_express === true && structurePrimaryExpressMap instanceof Map) {
|
||||||
|
const primaryExpressKey = String(structurePrimaryExpressMap.get(structureKey) || '').trim().toLowerCase();
|
||||||
|
if (!primaryExpressKey) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const currentExpressKey = String(this.getWaveStrategyQuickScanExpressKey(normalizedOrder) || '').trim().toLowerCase();
|
||||||
|
if (currentExpressKey !== primaryExpressKey) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const itemsCount = Number(normalizedOrder.items_count || 0);
|
const itemsCount = Number(normalizedOrder.items_count || 0);
|
||||||
const itemsTotal = Number(normalizedOrder.items_total || 0);
|
const itemsTotal = Number(normalizedOrder.items_total || 0);
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const { Op } = require('sequelize');
|
|
||||||
const MainService = require('../main');
|
const MainService = require('../main');
|
||||||
const { isInterceptedOrderStatus } = require('../../lib/intercept_guard');
|
const { isInterceptedOrderStatus } = require('../../lib/intercept_guard');
|
||||||
|
|
||||||
@ -13,9 +12,9 @@ class PickService extends MainService {
|
|||||||
constructor(ctx) {
|
constructor(ctx) {
|
||||||
super(ctx);
|
super(ctx);
|
||||||
const _noNeedLogin = '';
|
const _noNeedLogin = '';
|
||||||
const _noNeedRight = 'query,wavePickComplete,wavePickTaskDetail,wavePickTaskCurrent,wavePickTaskSubmit,wavePickTaskComplete,waveClaimScan';
|
const _noNeedRight = 'query,wavePickComplete,wavePickTaskDetail,wavePickTaskCurrent,wavePickTaskSubmit,wavePickTaskComplete';
|
||||||
const _noNeedLog = 'query';
|
const _noNeedLog = 'query';
|
||||||
const _noNeedAuth = 'query,wavePickComplete,wavePickTaskDetail,wavePickTaskCurrent,wavePickTaskSubmit,wavePickTaskComplete,waveClaimScan';
|
const _noNeedAuth = 'query,wavePickComplete,wavePickTaskDetail,wavePickTaskCurrent,wavePickTaskSubmit,wavePickTaskComplete';
|
||||||
this.systemInit(_noNeedLogin, _noNeedRight, _noNeedLog, _noNeedAuth);
|
this.systemInit(_noNeedLogin, _noNeedRight, _noNeedLog, _noNeedAuth);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1489,352 +1488,6 @@ class PickService extends MainService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询波次关联的拣货模式。
|
|
||||||
*
|
|
||||||
* 优先按拣货任务主表(wms_wave_pick_task.wave_id)直接关联查询,
|
|
||||||
* 未命中时回退到任务与波次关联表(wms_wave_pick_task_wave)查询。
|
|
||||||
*
|
|
||||||
* @param {number|string} waveId 波次ID。
|
|
||||||
* @return {Promise<number>} 拣货模式:1-团购小波次 2-散单单品单件 3-先拣后分 4-边拣边分 5-团购大波次(0 表示无关联拣货任务)。
|
|
||||||
*/
|
|
||||||
async getWavePickModeByWaveId(waveId) {
|
|
||||||
const { ctx } = this;
|
|
||||||
const normalizedWaveId = Number(waveId || 0);
|
|
||||||
if (!Number.isInteger(normalizedWaveId) || normalizedWaveId <= 0) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
const directRows = await ctx.model.query(
|
|
||||||
`SELECT pick_mode
|
|
||||||
FROM wms_wave_pick_task
|
|
||||||
WHERE wave_id = :waveId
|
|
||||||
ORDER BY id DESC
|
|
||||||
LIMIT 1`,
|
|
||||||
{
|
|
||||||
replacements: { waveId: normalizedWaveId },
|
|
||||||
type: ctx.model.QueryTypes.SELECT,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
const directRow = Array.isArray(directRows) && directRows.length > 0 ? directRows[0] : null;
|
|
||||||
if (directRow) {
|
|
||||||
return Number(directRow.pick_mode || 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
const linkRows = await ctx.model.query(
|
|
||||||
`SELECT t.pick_mode
|
|
||||||
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
|
|
||||||
ORDER BY t.id DESC
|
|
||||||
LIMIT 1`,
|
|
||||||
{
|
|
||||||
replacements: { waveId: normalizedWaveId },
|
|
||||||
type: ctx.model.QueryTypes.SELECT,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
const linkRow = Array.isArray(linkRows) && linkRows.length > 0 ? linkRows[0] : null;
|
|
||||||
return linkRow ? Number(linkRow.pick_mode || 0) : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 扫描面单号领取整波(领料)。
|
|
||||||
*
|
|
||||||
* 按面单号(运单号,wms_order_express.waybill_code)定位待处理订单表中的订单后反查订单所在波次,
|
|
||||||
* 仅对普通波次(wms_wave_batch.source=0,含团购/散单)支持整波领料:
|
|
||||||
* 命中后将该波次下全部未领单订单 claim_status 置为 fin(领单完成),
|
|
||||||
* 并写入 ORDER_WAVE_CLAIM 订单操作日志,返回波次ID(wave_id)与波次编码(wave_no);
|
|
||||||
* 策略抓取波次(source=1/2)无需领料,返回 400 并提示「该波次为抓取波次,无需领料」
|
|
||||||
* (失败 data 含 no_claim_needed=true、wave_id、wave_no);
|
|
||||||
* 波次下存在未打印订单(print_status != fin)时禁止领料,
|
|
||||||
* 返回 400 并提示「波次未打印,禁止领料」(失败 data 含 wave_id、wave_no、unprinted_order_count);
|
|
||||||
* 其余未知类型返回通用不支持提示。
|
|
||||||
* 波次内订单已全部领单时返回 already_claimed 幂等结果并提示已领料。
|
|
||||||
*
|
|
||||||
* @param {Object} data 请求参数。
|
|
||||||
* @param {string} data.waybill_no 面单号(运单号,wms_order_express.waybill_code)。
|
|
||||||
* @return {Promise<Object>} 统一 success/fail 包装结果。
|
|
||||||
*/
|
|
||||||
async waveClaimScan(data = {}) {
|
|
||||||
const { ctx } = this;
|
|
||||||
const requestData = this.isPlainObject(data) ? data : {};
|
|
||||||
const waybillNo = String(requestData.waybill_no || requestData.waybillNo || '').trim();
|
|
||||||
if (!waybillNo) {
|
|
||||||
return this.fail('waybill_no 必填(面单号/运单号)', {}, 400);
|
|
||||||
}
|
|
||||||
|
|
||||||
// --- 仓库上下文与操作人 ---
|
|
||||||
const userWarehouseId = ctx && ctx.user ? ctx.user.store_id : undefined;
|
|
||||||
const stateWarehouseId = ctx && ctx.state && ctx.state.user ? ctx.state.user.store_id : undefined;
|
|
||||||
const normalizedWarehouseId = Number(userWarehouseId || stateWarehouseId || 0);
|
|
||||||
if (!Number.isFinite(normalizedWarehouseId) || normalizedWarehouseId <= 0) {
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
// --- 1. 面单号定位订单 ---
|
|
||||||
const orderExpress = await ctx.model.OrderExpress.findOne({
|
|
||||||
where: {
|
|
||||||
warehouse_id: normalizedWarehouseId,
|
|
||||||
waybill_code: waybillNo,
|
|
||||||
},
|
|
||||||
attributes: [ 'order_id' ],
|
|
||||||
raw: true,
|
|
||||||
});
|
|
||||||
const matchedOrderId = Number(orderExpress && orderExpress.order_id || 0);
|
|
||||||
if (!(matchedOrderId > 0)) {
|
|
||||||
return this.fail('未查询到该面单号对应的订单,无记录', {}, 404);
|
|
||||||
}
|
|
||||||
|
|
||||||
// --- 2. 待处理订单表定位订单 ---
|
|
||||||
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: matchedOrderId,
|
|
||||||
warehouse_id: normalizedWarehouseId,
|
|
||||||
},
|
|
||||||
attributes: [ 'id', 'wave_id', 'wave_no' ],
|
|
||||||
raw: true,
|
|
||||||
});
|
|
||||||
if (!order) {
|
|
||||||
return this.fail('订单不在待处理订单表,无记录', {}, 404);
|
|
||||||
}
|
|
||||||
|
|
||||||
// --- 3. 订单定位波次 ---
|
|
||||||
const orderWaveId = Number(order.wave_id || 0);
|
|
||||||
const orderWaveNo = String(order.wave_no || '').trim();
|
|
||||||
if (!(orderWaveId > 0 || orderWaveNo)) {
|
|
||||||
return this.fail('运单对应订单未分配波次', {}, 400);
|
|
||||||
}
|
|
||||||
|
|
||||||
let waveRows = [];
|
|
||||||
if (orderWaveId > 0) {
|
|
||||||
waveRows = await ctx.model.query(
|
|
||||||
`SELECT wave_id, wave_no, wave_type, source
|
|
||||||
FROM wms_wave_batch
|
|
||||||
WHERE warehouse_id = :warehouseId
|
|
||||||
AND wave_id = :waveId
|
|
||||||
LIMIT 1`,
|
|
||||||
{
|
|
||||||
replacements: {
|
|
||||||
warehouseId: normalizedWarehouseId,
|
|
||||||
waveId: orderWaveId,
|
|
||||||
},
|
|
||||||
type: ctx.model.QueryTypes.SELECT,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
waveRows = await ctx.model.query(
|
|
||||||
`SELECT wave_id, wave_no, wave_type, source
|
|
||||||
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(waveRows) && waveRows.length > 0 ? waveRows[0] : null;
|
|
||||||
if (!waveRow) {
|
|
||||||
return this.fail('运单对应波次不存在或不属于当前仓库', {}, 404);
|
|
||||||
}
|
|
||||||
|
|
||||||
const targetWaveId = Number(waveRow.wave_id || 0);
|
|
||||||
const targetWaveNo = String(waveRow.wave_no || '').trim();
|
|
||||||
const targetWaveType = Number(waveRow.wave_type || 0);
|
|
||||||
const targetWaveSource = Number(waveRow.source || 0);
|
|
||||||
if (!(targetWaveId > 0) || !targetWaveNo) {
|
|
||||||
return this.fail('目标波次信息不完整', {}, 400);
|
|
||||||
}
|
|
||||||
|
|
||||||
// --- 4. 波次关联拣货模式与领料资格判定(仅普通波次 source=0 支持整波领料)---
|
|
||||||
const pickMode = await this.getWavePickModeByWaveId(targetWaveId);
|
|
||||||
|
|
||||||
const isFetchedWave = targetWaveSource === 1 || targetWaveSource === 2;
|
|
||||||
if (isFetchedWave) {
|
|
||||||
return this.fail('该波次为抓取波次,无需领料', {
|
|
||||||
no_claim_needed: true,
|
|
||||||
wave_id: targetWaveId,
|
|
||||||
wave_no: targetWaveNo,
|
|
||||||
wave_type: targetWaveType,
|
|
||||||
wave_source: targetWaveSource,
|
|
||||||
pick_mode: pickMode,
|
|
||||||
matched_order_id: matchedOrderId,
|
|
||||||
waybill_no: waybillNo,
|
|
||||||
}, 400);
|
|
||||||
}
|
|
||||||
if (targetWaveSource !== 0) {
|
|
||||||
return this.fail('当前波次类型不支持整波领单', {
|
|
||||||
wave_id: targetWaveId,
|
|
||||||
wave_no: targetWaveNo,
|
|
||||||
wave_type: targetWaveType,
|
|
||||||
wave_source: targetWaveSource,
|
|
||||||
}, 400);
|
|
||||||
}
|
|
||||||
|
|
||||||
// --- 5. 查询波次下全部订单 ---
|
|
||||||
const waveOrderRows = await orderModel.findAll({
|
|
||||||
where: {
|
|
||||||
warehouse_id: normalizedWarehouseId,
|
|
||||||
wave_id: targetWaveId,
|
|
||||||
},
|
|
||||||
attributes: [ 'id', 'claim_status', 'print_status' ],
|
|
||||||
raw: true,
|
|
||||||
});
|
|
||||||
let waveOrders = Array.isArray(waveOrderRows) ? waveOrderRows : [];
|
|
||||||
if (waveOrders.length === 0) {
|
|
||||||
const fallbackRows = await orderModel.findAll({
|
|
||||||
where: {
|
|
||||||
warehouse_id: normalizedWarehouseId,
|
|
||||||
wave_no: targetWaveNo,
|
|
||||||
},
|
|
||||||
attributes: [ 'id', 'claim_status', 'print_status' ],
|
|
||||||
raw: true,
|
|
||||||
});
|
|
||||||
waveOrders = Array.isArray(fallbackRows) ? fallbackRows : [];
|
|
||||||
}
|
|
||||||
const waveOrderIds = [ ...new Set(waveOrders
|
|
||||||
.map(item => Number(item && item.id || 0))
|
|
||||||
.filter(id => Number.isInteger(id) && id > 0)) ];
|
|
||||||
if (waveOrderIds.length === 0) {
|
|
||||||
return this.fail('波次下无可用订单', {}, 400);
|
|
||||||
}
|
|
||||||
|
|
||||||
const totalOrderCount = waveOrderIds.length;
|
|
||||||
const unclaimedOrderIds = [ ...new Set(waveOrders
|
|
||||||
.filter(item => String(item && item.claim_status || '') !== 'fin')
|
|
||||||
.map(item => Number(item && item.id || 0))
|
|
||||||
.filter(id => Number.isInteger(id) && id > 0)) ];
|
|
||||||
|
|
||||||
const baseResponse = {
|
|
||||||
wave_id: targetWaveId,
|
|
||||||
wave_no: targetWaveNo,
|
|
||||||
wave_type: targetWaveType,
|
|
||||||
wave_source: targetWaveSource,
|
|
||||||
pick_mode: pickMode,
|
|
||||||
matched_order_id: matchedOrderId,
|
|
||||||
waybill_no: waybillNo,
|
|
||||||
total_order_count: totalOrderCount,
|
|
||||||
};
|
|
||||||
|
|
||||||
if (unclaimedOrderIds.length === 0) {
|
|
||||||
return this.success('ok', {
|
|
||||||
data: {
|
|
||||||
...baseResponse,
|
|
||||||
claimed_order_count: 0,
|
|
||||||
status: 'already_claimed',
|
|
||||||
tip: '该波次已领料,无需重复领取',
|
|
||||||
},
|
|
||||||
code: 200,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// 波次打印校验:存在未打印订单(print_status != fin)时禁止整波领料
|
|
||||||
const unprintedOrderIds = [ ...new Set(waveOrders
|
|
||||||
.filter(item => String(item && item.print_status || '') !== 'fin')
|
|
||||||
.map(item => Number(item && item.id || 0))
|
|
||||||
.filter(id => Number.isInteger(id) && id > 0)) ];
|
|
||||||
if (unprintedOrderIds.length > 0) {
|
|
||||||
return this.fail('波次未打印,禁止领料', {
|
|
||||||
...baseResponse,
|
|
||||||
unprinted_order_count: unprintedOrderIds.length,
|
|
||||||
}, 400);
|
|
||||||
}
|
|
||||||
|
|
||||||
// --- 6. 事务更新领单状态并写订单日志 ---
|
|
||||||
const operationLogService = ctx.service
|
|
||||||
&& ctx.service.systems
|
|
||||||
&& ctx.service.systems.operationLog;
|
|
||||||
const transaction = await ctx.model.transaction();
|
|
||||||
try {
|
|
||||||
await orderModel.update(
|
|
||||||
{ claim_status: 'fin' },
|
|
||||||
{
|
|
||||||
where: {
|
|
||||||
id: { [Op.in]: unclaimedOrderIds },
|
|
||||||
warehouse_id: normalizedWarehouseId,
|
|
||||||
claim_status: { [Op.ne]: 'fin' },
|
|
||||||
},
|
|
||||||
transaction,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
const claimedRows = await orderModel.findAll({
|
|
||||||
where: {
|
|
||||||
id: { [Op.in]: unclaimedOrderIds },
|
|
||||||
warehouse_id: normalizedWarehouseId,
|
|
||||||
claim_status: 'fin',
|
|
||||||
},
|
|
||||||
attributes: [ 'id' ],
|
|
||||||
raw: true,
|
|
||||||
transaction,
|
|
||||||
});
|
|
||||||
const claimedOrderIds = [ ...new Set((Array.isArray(claimedRows) ? claimedRows : [])
|
|
||||||
.map(item => Number(item && item.id || 0))
|
|
||||||
.filter(id => Number.isInteger(id) && id > 0)) ];
|
|
||||||
|
|
||||||
if (claimedOrderIds.length > 0
|
|
||||||
&& operationLogService
|
|
||||||
&& typeof operationLogService.createOperationLogs === 'function') {
|
|
||||||
await operationLogService.createOperationLogs(claimedOrderIds.map(orderId => ({
|
|
||||||
businessType: 'order',
|
|
||||||
businessId: `${orderId}`,
|
|
||||||
operationCode: 'ORDER_WAVE_CLAIM',
|
|
||||||
operator: {
|
|
||||||
id: operatorId ? String(operatorId) : null,
|
|
||||||
name: operatorName || 'system',
|
|
||||||
},
|
|
||||||
operationAction: 'UPDATE',
|
|
||||||
extras: {
|
|
||||||
message: `整波领单完成(波次 ${targetWaveNo})`,
|
|
||||||
warehouseId: normalizedWarehouseId,
|
|
||||||
externalLogType: 'API',
|
|
||||||
},
|
|
||||||
})), { transaction });
|
|
||||||
}
|
|
||||||
|
|
||||||
await transaction.commit();
|
|
||||||
|
|
||||||
return this.success('ok', {
|
|
||||||
data: {
|
|
||||||
...baseResponse,
|
|
||||||
claimed_order_count: claimedOrderIds.length,
|
|
||||||
status: 'claimed',
|
|
||||||
tip: `整波领单完成,本次领取 ${claimedOrderIds.length} 个订单`,
|
|
||||||
},
|
|
||||||
code: 200,
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
await transaction.rollback();
|
|
||||||
ctx.logger.error('[PickService.waveClaimScan] 整波领单失败: %s', error && error.message ? error.message : error);
|
|
||||||
return this.fail('领单失败', {}, 500);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = PickService;
|
module.exports = PickService;
|
||||||
|
|||||||
@ -533,24 +533,7 @@ class DeliveryOrderService extends Service {
|
|||||||
explicitEnableExternalExpressCode
|
explicitEnableExternalExpressCode
|
||||||
);
|
);
|
||||||
|
|
||||||
this.ctx.logger.info('[DeliveryOrderService.resolveExpressSnapshot] 快递解析开始', {
|
|
||||||
deliveryOrderCode: info.deliveryOrderCode,
|
|
||||||
warehouseId: info.warehouseId,
|
|
||||||
storeId: info.storeId,
|
|
||||||
logisticsCode: externalCode,
|
|
||||||
enableExternalExpressCode: isEnableExternalExpressCode,
|
|
||||||
defaultExpressCode: defaultCode,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!isEnableExternalExpressCode) {
|
if (!isEnableExternalExpressCode) {
|
||||||
this.ctx.logger.info('[DeliveryOrderService.resolveExpressSnapshot] 未启用外部快递编码,直接使用默认快递', {
|
|
||||||
deliveryOrderCode: info.deliveryOrderCode,
|
|
||||||
logisticsCode: externalCode,
|
|
||||||
matched: false,
|
|
||||||
fallbackLogisticsCode,
|
|
||||||
fallbackLogisticsName,
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
logisticsCode: fallbackLogisticsCode,
|
logisticsCode: fallbackLogisticsCode,
|
||||||
logisticsName: fallbackLogisticsName,
|
logisticsName: fallbackLogisticsName,
|
||||||
@ -570,17 +553,6 @@ class DeliveryOrderService extends Service {
|
|||||||
).trim();
|
).trim();
|
||||||
const matchedSysLogisticsName = this.getOptionName(matchedSysExpress);
|
const matchedSysLogisticsName = this.getOptionName(matchedSysExpress);
|
||||||
|
|
||||||
this.ctx.logger.info('[DeliveryOrderService.resolveExpressSnapshot] 外部快递编码命中 wms_express_setting 映射', {
|
|
||||||
deliveryOrderCode: info.deliveryOrderCode,
|
|
||||||
logisticsCode: externalCode,
|
|
||||||
matched: true,
|
|
||||||
source: 'wms_express_setting',
|
|
||||||
mappedLogisticsCode: String(expressSetting.code || externalCode).trim(),
|
|
||||||
mappedLogisticsName: String(expressSetting.name || '').trim(),
|
|
||||||
sysLogisticsCode: matchedSysLogisticsCode,
|
|
||||||
sysLogisticsName: matchedSysLogisticsName,
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
logisticsCode: String(expressSetting.code || externalCode).trim(),
|
logisticsCode: String(expressSetting.code || externalCode).trim(),
|
||||||
logisticsName: String(expressSetting.name || '').trim(),
|
logisticsName: String(expressSetting.name || '').trim(),
|
||||||
@ -598,15 +570,6 @@ class DeliveryOrderService extends Service {
|
|||||||
).trim();
|
).trim();
|
||||||
const matchedLogisticsName = this.getOptionName(matchedExpress);
|
const matchedLogisticsName = this.getOptionName(matchedExpress);
|
||||||
|
|
||||||
this.ctx.logger.info('[DeliveryOrderService.resolveExpressSnapshot] 外部快递编码命中系统快递列表', {
|
|
||||||
deliveryOrderCode: info.deliveryOrderCode,
|
|
||||||
logisticsCode: externalCode,
|
|
||||||
matched: true,
|
|
||||||
source: 'wms_express',
|
|
||||||
matchedLogisticsCode,
|
|
||||||
matchedLogisticsName,
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
logisticsCode: matchedLogisticsCode,
|
logisticsCode: matchedLogisticsCode,
|
||||||
logisticsName: matchedLogisticsName,
|
logisticsName: matchedLogisticsName,
|
||||||
@ -616,21 +579,18 @@ class DeliveryOrderService extends Service {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (fallbackExpress) {
|
if (fallbackExpress) {
|
||||||
this.ctx.logger.warn('[DeliveryOrderService.resolveExpressSnapshot] 快递编码未匹配到任何快递,兜底为默认快递', {
|
this.ctx.logger.warn('[DeliveryOrderService.prepareOrderData] invalid logistics code fallback to store default', {
|
||||||
deliveryOrderCode: info.deliveryOrderCode,
|
deliveryOrderCode: info.deliveryOrderCode,
|
||||||
warehouseId: info.warehouseId,
|
warehouseId: info.warehouseId,
|
||||||
storeId: info.storeId,
|
storeId: info.storeId,
|
||||||
logisticsCode: externalCode,
|
logisticsCode: externalCode,
|
||||||
matched: false,
|
|
||||||
fallbackLogisticsCode,
|
|
||||||
fallbackLogisticsName,
|
|
||||||
defaultExpressCode: defaultCode,
|
defaultExpressCode: defaultCode,
|
||||||
});
|
});
|
||||||
|
|
||||||
this.appendOrderOperationLog(
|
this.appendOrderOperationLog(
|
||||||
operationLogs,
|
operationLogs,
|
||||||
ORDER_OPERATION_CODES.EXPRESS_FALLBACK,
|
ORDER_OPERATION_CODES.EXPRESS_FALLBACK,
|
||||||
`快递编码${externalCode}匹配不到快递,已转为默认快递:${fallbackLogisticsName || fallbackLogisticsCode}`
|
`快递编码${externalCode}匹配不到快递,已转为默认快递:${this.getOptionName(fallbackExpress) || defaultCode}`
|
||||||
);
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -642,23 +602,14 @@ class DeliveryOrderService extends Service {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
this.ctx.logger.warn('[DeliveryOrderService.resolveExpressSnapshot] 默认快递不在快递列表中,使用全局兜底快递', {
|
this.ctx.logger.warn('[DeliveryOrderService.prepareOrderData] express default not found in express service list', {
|
||||||
deliveryOrderCode: info.deliveryOrderCode,
|
deliveryOrderCode: info.deliveryOrderCode,
|
||||||
warehouseId: info.warehouseId,
|
warehouseId: info.warehouseId,
|
||||||
storeId: info.storeId,
|
storeId: info.storeId,
|
||||||
logisticsCode: externalCode,
|
logisticsCode: externalCode,
|
||||||
matched: false,
|
|
||||||
fallbackLogisticsCode,
|
|
||||||
fallbackLogisticsName,
|
|
||||||
defaultExpressCode: defaultCode,
|
defaultExpressCode: defaultCode,
|
||||||
});
|
});
|
||||||
|
|
||||||
this.appendOrderOperationLog(
|
|
||||||
operationLogs,
|
|
||||||
ORDER_OPERATION_CODES.EXPRESS_FALLBACK,
|
|
||||||
`快递编码${externalCode}匹配不到快递,兜底快递:${fallbackLogisticsName || fallbackLogisticsCode}`
|
|
||||||
);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
logisticsCode: fallbackLogisticsCode,
|
logisticsCode: fallbackLogisticsCode,
|
||||||
logisticsName: fallbackLogisticsName,
|
logisticsName: fallbackLogisticsName,
|
||||||
@ -797,22 +748,10 @@ class DeliveryOrderService extends Service {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// ===== 快递绑定策略漏斗匹配(items 处理后 weight 可用) =====
|
// ===== 快递绑定策略漏斗匹配(items 处理后 weight 可用) =====
|
||||||
// enable_external_express_code 开启时以外部快递匹配结果为准(匹配不到已在 resolveExpressSnapshot 兜底默认快递),跳过策略漏斗覆盖
|
|
||||||
try {
|
try {
|
||||||
const funnelPolicyConfig = await this.getStoreWarehousePolicyConfig(info.storeId, info.warehouseId);
|
|
||||||
const enableExternalExpressCode = this.resolveEnableExternalExpressCode(funnelPolicyConfig, funnelPolicyConfig);
|
|
||||||
if (enableExternalExpressCode) {
|
|
||||||
ctx.logger.info('[ExpressPolicyMatch] enable_external_express_code 开启,跳过快递策略漏斗,保留外部快递匹配或兜底结果', {
|
|
||||||
orderId,
|
|
||||||
orderCode: deliveryOrder.deliveryOrderCode,
|
|
||||||
logisticsCode: orderData.logistics_code,
|
|
||||||
sysLogisticsCode: orderData.sys_logistics_code,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
const receiverInfo = deliveryOrder.receiverInfo;
|
const receiverInfo = deliveryOrder.receiverInfo;
|
||||||
const shopNick = deliveryOrder.shopNick;
|
const shopNick = deliveryOrder.shopNick;
|
||||||
const hasEnoughData = !enableExternalExpressCode
|
const hasEnoughData = shopNick || (receiverInfo && (receiverInfo.province || receiverInfo.city));
|
||||||
&& (shopNick || (receiverInfo && (receiverInfo.province || receiverInfo.city)));
|
|
||||||
|
|
||||||
if (hasEnoughData) {
|
if (hasEnoughData) {
|
||||||
const address = [
|
const address = [
|
||||||
@ -1483,17 +1422,6 @@ class DeliveryOrderService extends Service {
|
|||||||
gross_weight: 0,
|
gross_weight: 0,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// 手工单直接传仓库 stock_id:校验库存记录归属当前货主,禁止跨货主下单
|
|
||||||
const stockWarehouseRecord = await app.model.StockWarehouse.findByPk(line.stockId, {
|
|
||||||
attributes: [ 'id', 'store_id' ],
|
|
||||||
transaction,
|
|
||||||
raw: true,
|
|
||||||
});
|
|
||||||
if (stockWarehouseRecord && Number(stockWarehouseRecord.store_id) !== Number(storeId)) {
|
|
||||||
errors.push(`商品《${line.itemName}》编码《${line.itemCode}》\n库存归属货主(store_id=${stockWarehouseRecord.store_id})与当前货主(store_id=${storeId})不一致,无法创建订单`);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
} else if (!line.itemId) {
|
} else if (!line.itemId) {
|
||||||
// 查找唯一键(appKey 为空时不作为条件,兼容内部手动建单场景)
|
// 查找唯一键(appKey 为空时不作为条件,兼容内部手动建单场景)
|
||||||
const stockWhere = {
|
const stockWhere = {
|
||||||
|
|||||||
@ -708,8 +708,8 @@ class ExpressPlatformService extends MainService {
|
|||||||
orderno: `${order.warehouse_id.toString(16)}_${order.id}_${order_tmp.business_key}`, // 菠萝派平台要求订单号必须为字符串
|
orderno: `${order.warehouse_id.toString(16)}_${order.id}_${order_tmp.business_key}`, // 菠萝派平台要求订单号必须为字符串
|
||||||
plattradeno: listByWarehousePlatformCode.platform_code === 'DY' && order.from_key === 23060081 && !!order.pay_no ? order.pay_no : order.source_order_codes || order.delivery_order_code || '',
|
plattradeno: listByWarehousePlatformCode.platform_code === 'DY' && order.from_key === 23060081 && !!order.pay_no ? order.pay_no : order.source_order_codes || order.delivery_order_code || '',
|
||||||
tid:listByWarehousePlatformCode.platform_code === 'DY' && order.from_key === 23060081 && !!order.pay_no ? order.pay_no : order.source_order_codes || order.delivery_order_code || '',
|
tid:listByWarehousePlatformCode.platform_code === 'DY' && order.from_key === 23060081 && !!order.pay_no ? order.pay_no : order.source_order_codes || order.delivery_order_code || '',
|
||||||
ismultiplepieces: order.package_count > 1 ? 1 : 0,
|
//ismultiplepieces: order.package_count > 1 ? 1 : 0,
|
||||||
logisticno: allocatedWaybillMap.get(`${Number(order.id) || 0}:${Number(order_tmp.business_key) || 0}`) || '',
|
//logisticno: allocatedWaybillMap.get(`${Number(order.id) || 0}:${Number(order_tmp.business_key) || 0}`) || '',
|
||||||
logistictype: expressListItem[listByWarehousePlatformCode.platform_code] || '',
|
logistictype: expressListItem[listByWarehousePlatformCode.platform_code] || '',
|
||||||
providercode: expressListItem[listByWarehousePlatformCode.platform_code] || order.logistics_code || '',
|
providercode: expressListItem[listByWarehousePlatformCode.platform_code] || order.logistics_code || '',
|
||||||
numpackage: order.package_count || '1',
|
numpackage: order.package_count || '1',
|
||||||
@ -718,31 +718,26 @@ class ExpressPlatformService extends MainService {
|
|||||||
transtypecode:'1',
|
transtypecode:'1',
|
||||||
mainsubpaymode:'1',
|
mainsubpaymode:'1',
|
||||||
businessplat: order.sys_platform_code === 'KS' ? order.sys_platform_code : 'OTHERS',
|
businessplat: order.sys_platform_code === 'KS' ? order.sys_platform_code : 'OTHERS',
|
||||||
paymode: '1',
|
paymode: listByWarehousePlatformCode.paymode.toString() ?? '1',
|
||||||
ordertype: listByWarehousePlatformCode.ordertype ?? 'JH_Normal',
|
ordertype: listByWarehousePlatformCode.ordertype ?? 'JH_Normal',
|
||||||
ProviderID:'',
|
ProviderID:'',
|
||||||
procode: order.procode || '普通商品',
|
//procode: order.procode || '普通商品',
|
||||||
codpaymoney: order.ar_amount ?? null,
|
//codpaymoney: order.ar_amount ?? null,
|
||||||
packagemoney: order.item_amount ?? null,
|
//packagemoney: order.item_amount ?? null,
|
||||||
weight: Number(order.items_weight) || 0, // 单位 g,需确认 PolyAPI 期望单位
|
//weight: Number(order.items_weight) || 0, // 单位 g,需确认 PolyAPI 期望单位
|
||||||
supporpaymoney: order.total_amount ?? null,
|
//supporpaymoney: order.total_amount ?? null,
|
||||||
length: Number(order.length) || 0,
|
//ispickup: listByWarehousePlatformCode.ispickup ?? 0,
|
||||||
width: Number(order.width) || 0,
|
//ProductType: listByWarehousePlatformCode.product_type || '',
|
||||||
height: Number(order.height) || 0,
|
//Sipshopid: listByWarehousePlatformCode.platform_shop_id || '',
|
||||||
volume: Number(order.volume) || 0,
|
|
||||||
ispickup: listByWarehousePlatformCode.ispickup ?? 0,
|
|
||||||
ProductType: listByWarehousePlatformCode.product_type || '',
|
|
||||||
Sipshopid: listByWarehousePlatformCode.platform_shop_id || '',
|
|
||||||
oaid: order.oaid || '',
|
oaid: order.oaid || '',
|
||||||
cpcode: expressListItem[listByWarehousePlatformCode.platform_code] || '',
|
cpcode: expressListItem[listByWarehousePlatformCode.platform_code] || '',
|
||||||
logisticsproductname: 'JH_02',
|
logisticsproductname: 'JH_02',
|
||||||
dmssorting: 0,
|
//dmssorting: 0,
|
||||||
brandno: listByWarehousePlatformCode.brandno || null,
|
//brandno: listByWarehousePlatformCode.brandno || null,
|
||||||
needencrypt: 1,
|
needencrypt: 1,
|
||||||
ordertime: order.place_order_time || '',
|
|
||||||
customername:"测试",
|
customername:"测试",
|
||||||
ordersource: matchedPlatform.ordersource || '',
|
ordersource: matchedPlatform.ordersource || '',
|
||||||
inputsite: order.sys_platform_code === 'XHS' ? '' :listByWarehousePlatformCode.site_code || '',
|
//inputsite: order.sys_platform_code === 'XHS' ? '' :listByWarehousePlatformCode.site_code || '',
|
||||||
sitecode: listByWarehousePlatformCode.site_code || '',
|
sitecode: listByWarehousePlatformCode.site_code || '',
|
||||||
shipperno: order.sys_platform_code === 'XHS' ? '' :listByWarehousePlatformCode.shipperno || '',
|
shipperno: order.sys_platform_code === 'XHS' ? '' :listByWarehousePlatformCode.shipperno || '',
|
||||||
customercode: order.sys_platform_code === 'XHS' ? '' :listByWarehousePlatformCode.shipperno || listByWarehousePlatformCode.client_id || '',
|
customercode: order.sys_platform_code === 'XHS' ? '' :listByWarehousePlatformCode.shipperno || listByWarehousePlatformCode.client_id || '',
|
||||||
@ -781,8 +776,8 @@ class ExpressPlatformService extends MainService {
|
|||||||
//Mallmaskid: '',
|
//Mallmaskid: '',
|
||||||
|
|
||||||
template_url: listByWarehousePlatformCode.template_id || '',
|
template_url: listByWarehousePlatformCode.template_id || '',
|
||||||
labelformat: listByWarehousePlatformCode.labelformat || '',
|
//labelformat: listByWarehousePlatformCode.labelformat || '',
|
||||||
extraInfo: ExpressList.find(item => item.code === listByWarehousePlatformCode.sys_express_code)?.polyapi_extra_info || '',
|
//extraInfo: ExpressList.find(item => item.code === listByWarehousePlatformCode.sys_express_code)?.polyapi_extra_info || '',
|
||||||
};
|
};
|
||||||
console.log('matchedPlatform.platid', matchedPlatform.platid);
|
console.log('matchedPlatform.platid', matchedPlatform.platid);
|
||||||
console.log('startPlayload', playload);
|
console.log('startPlayload', playload);
|
||||||
@ -841,13 +836,11 @@ class ExpressPlatformService extends MainService {
|
|||||||
orderno,
|
orderno,
|
||||||
plattradeno,
|
plattradeno,
|
||||||
ProductType,
|
ProductType,
|
||||||
businesstype:ProductType,
|
|
||||||
expresstype: ProductType,
|
expresstype: ProductType,
|
||||||
logistictype,
|
logistictype,
|
||||||
providercode: providercode || cpcode || logistictype || '',
|
providercode: providercode || cpcode || logistictype || '',
|
||||||
numpackage,
|
numpackage,
|
||||||
businessplat,
|
businessplat,
|
||||||
platcode:plattradeno,
|
|
||||||
mainsubpaymode: '1',
|
mainsubpaymode: '1',
|
||||||
ordertype,
|
ordertype,
|
||||||
businessType: businessType || ordertype || 'JH_Normal',
|
businessType: businessType || ordertype || 'JH_Normal',
|
||||||
@ -862,7 +855,7 @@ class ExpressPlatformService extends MainService {
|
|||||||
customername,
|
customername,
|
||||||
goods,
|
goods,
|
||||||
oaid,
|
oaid,
|
||||||
customercode: logistictype==="SF" ? undefined: customercode || shipperno || listByWarehousePlatformCode.shipperno || listByWarehousePlatformCode.client_id || '',
|
customercode: customercode || shipperno || listByWarehousePlatformCode.shipperno || listByWarehousePlatformCode.client_id || '',
|
||||||
sender: {
|
sender: {
|
||||||
name: senderName,
|
name: senderName,
|
||||||
phone: senderPhoneRaw,
|
phone: senderPhoneRaw,
|
||||||
@ -1309,8 +1302,7 @@ class ExpressPlatformService extends MainService {
|
|||||||
}
|
}
|
||||||
case 'PDD':
|
case 'PDD':
|
||||||
successUpdates = (result.results || []).map(item => {
|
successUpdates = (result.results || []).map(item => {
|
||||||
const [ warehouse_id_hex, order_id, business_key ] = String(item.orderno || '').split('_');
|
const [ warehouse_id, order_id, business_key ] = String(item.orderno || '').split('_');
|
||||||
const warehouse_id = parseInt(warehouse_id_hex, 16);
|
|
||||||
const waybillCode = resolveWaybillCode(item);
|
const waybillCode = resolveWaybillCode(item);
|
||||||
return {
|
return {
|
||||||
warehouse_id,
|
warehouse_id,
|
||||||
@ -1345,8 +1337,7 @@ class ExpressPlatformService extends MainService {
|
|||||||
case 'QT':
|
case 'QT':
|
||||||
case 'OTHER':
|
case 'OTHER':
|
||||||
successUpdates = (result.results || []).map(item => {
|
successUpdates = (result.results || []).map(item => {
|
||||||
const [ warehouse_id_hex, order_id, business_key ] = String(item.orderno || '').split('_');
|
const [ warehouse_id, order_id, business_key ] = String(item.orderno || '').split('_');
|
||||||
const warehouse_id = parseInt(warehouse_id_hex, 16);
|
|
||||||
const waybillCode = String(item.logisticno || item.waybill_code || '').trim();
|
const waybillCode = String(item.logisticno || item.waybill_code || '').trim();
|
||||||
return {
|
return {
|
||||||
warehouse_id,
|
warehouse_id,
|
||||||
@ -1770,7 +1761,7 @@ class ExpressPlatformService extends MainService {
|
|||||||
: [];
|
: [];
|
||||||
const recipientMobile = orderDelivery && (orderDelivery.mobile || orderDelivery.tel) || '';
|
const recipientMobile = orderDelivery && (orderDelivery.mobile || orderDelivery.tel) || '';
|
||||||
const orderDeliveryOaid = orderDelivery && orderDelivery.oaid ? String(orderDelivery.oaid).trim() : '';
|
const orderDeliveryOaid = orderDelivery && orderDelivery.oaid ? String(orderDelivery.oaid).trim() : '';
|
||||||
const oaidTooLong = orderDeliveryOaid.indexOf("-") !== -1 || orderDeliveryOaid.length > 128;
|
const oaidTooLong = orderDeliveryOaid.length > 128;
|
||||||
|
|
||||||
const tradeOrderInfo = {
|
const tradeOrderInfo = {
|
||||||
logistics_services: normalizedExtData,
|
logistics_services: normalizedExtData,
|
||||||
@ -1794,10 +1785,6 @@ class ExpressPlatformService extends MainService {
|
|||||||
})) || [],
|
})) || [],
|
||||||
goods_description: '物品',
|
goods_description: '物品',
|
||||||
id: `${orderDelivery.warehouse_id}_${orderDelivery.id}_${order_tmp.business_key}`,
|
id: `${orderDelivery.warehouse_id}_${orderDelivery.id}_${order_tmp.business_key}`,
|
||||||
length:Number(orderDelivery.length || 1),
|
|
||||||
width:Number(orderDelivery.width || 1),
|
|
||||||
height:Number(orderDelivery.height || 1),
|
|
||||||
weight:Number(orderDelivery.items_weight || 1),
|
|
||||||
},
|
},
|
||||||
recipient: {
|
recipient: {
|
||||||
address: {
|
address: {
|
||||||
@ -1813,7 +1800,7 @@ class ExpressPlatformService extends MainService {
|
|||||||
phone: recipientMobile,
|
phone: recipientMobile,
|
||||||
oaid: oaidTooLong ? '' : orderDeliveryOaid,
|
oaid: oaidTooLong ? '' : orderDeliveryOaid,
|
||||||
caid: oaidTooLong ? orderDeliveryOaid : '',
|
caid: oaidTooLong ? orderDeliveryOaid : '',
|
||||||
tid: orderDelivery.source_order_codes,
|
tid: orderDelivery.pay_no || '',
|
||||||
},
|
},
|
||||||
user_id: listByWarehousePlatformCode.shop && listByWarehousePlatformCode.shop.owner_id || 0,
|
user_id: listByWarehousePlatformCode.shop && listByWarehousePlatformCode.shop.owner_id || 0,
|
||||||
notify_extend_info: normalizedExtData,
|
notify_extend_info: normalizedExtData,
|
||||||
|
|||||||
@ -28,7 +28,6 @@ const ORDER_EXPORT_COLUMNS = Object.freeze([
|
|||||||
{ header: '平台单号', key: 'external_order_code', width: 24 },
|
{ header: '平台单号', key: 'external_order_code', width: 24 },
|
||||||
{ header: '订单状态', key: 'status', width: 16 },
|
{ header: '订单状态', key: 'status', width: 16 },
|
||||||
{ header: '抓取波次号', key: 'wave_no', width: 18 },
|
{ header: '抓取波次号', key: 'wave_no', width: 18 },
|
||||||
{ header: '波次序号', key: 'wave_index', width: 12 },
|
|
||||||
{ header: '货主', key: 'store_id', width: 20 },
|
{ header: '货主', key: 'store_id', width: 20 },
|
||||||
{ header: '平台', key: 'sys_platform_name', width: 16 },
|
{ header: '平台', key: 'sys_platform_name', width: 16 },
|
||||||
{ header: '店铺昵称', key: 'shop_nick', width: 20 },
|
{ header: '店铺昵称', key: 'shop_nick', width: 20 },
|
||||||
@ -75,7 +74,6 @@ const ORDER_EXPORT_ITEM_COLUMNS = Object.freeze([
|
|||||||
{ header: '外部单号', key: 'external_order_code', width: 24 },
|
{ header: '外部单号', key: 'external_order_code', width: 24 },
|
||||||
{ header: '订单状态', key: 'status', width: 16 },
|
{ header: '订单状态', key: 'status', width: 16 },
|
||||||
{ header: '波次号', key: 'wave_no', width: 18 },
|
{ header: '波次号', key: 'wave_no', width: 18 },
|
||||||
{ header: '波次序号', key: 'wave_index', width: 12 },
|
|
||||||
{ header: '货主', key: 'store_id', width: 20 },
|
{ header: '货主', key: 'store_id', width: 20 },
|
||||||
{ header: '平台', key: 'sys_platform_name', width: 16 },
|
{ header: '平台', key: 'sys_platform_name', width: 16 },
|
||||||
{ header: '店铺昵称', key: 'shop_nick', width: 20 },
|
{ header: '店铺昵称', key: 'shop_nick', width: 20 },
|
||||||
@ -404,7 +402,6 @@ class OrderExportService extends OrderBaseService {
|
|||||||
external_order_code: this.normalizeExportCellValue(externalOrderCode),
|
external_order_code: this.normalizeExportCellValue(externalOrderCode),
|
||||||
status: translateStatus('status', safeOrderRow.status),
|
status: translateStatus('status', safeOrderRow.status),
|
||||||
wave_no: this.normalizeExportCellValue(safeOrderRow.wave_no),
|
wave_no: this.normalizeExportCellValue(safeOrderRow.wave_no),
|
||||||
wave_index: this.normalizeExportCellValue(safeOrderRow.wave_index ?? 0),
|
|
||||||
store_id: this.normalizeExportCellValue(storeRemark || safeOrderRow.store_name || safeOrderRow.store_id),
|
store_id: this.normalizeExportCellValue(storeRemark || safeOrderRow.store_name || safeOrderRow.store_id),
|
||||||
sys_platform_name: this.normalizeExportCellValue(safeOrderRow.sys_platform_name),
|
sys_platform_name: this.normalizeExportCellValue(safeOrderRow.sys_platform_name),
|
||||||
shop_nick: this.normalizeExportCellValue(safeOrderRow.shop_nick),
|
shop_nick: this.normalizeExportCellValue(safeOrderRow.shop_nick),
|
||||||
@ -619,11 +616,9 @@ class OrderExportService extends OrderBaseService {
|
|||||||
});
|
});
|
||||||
const { where: sanitizedWhere, expressNumbers } = this.extractOrderListExpressVirtualFilter(where);
|
const { where: sanitizedWhere, expressNumbers } = this.extractOrderListExpressVirtualFilter(where);
|
||||||
const { where: whereAfterBuyerMessage, buyerMessageHas } = this.extractBuyerMessageHasVirtualFilter(sanitizedWhere);
|
const { where: whereAfterBuyerMessage, buyerMessageHas } = this.extractBuyerMessageHasVirtualFilter(sanitizedWhere);
|
||||||
const { where: whereAfterWaveIndex, waveIndexCondition } = this.extractWaveIndexVirtualFilter(whereAfterBuyerMessage);
|
|
||||||
const { where: whereAfterWaveScope, waveScope } = this.extractWaveScopeVirtualFilter(whereAfterWaveIndex);
|
|
||||||
const mergedWhere = this.mergeWhereObjects(
|
const mergedWhere = this.mergeWhereObjects(
|
||||||
target.defaultWhereModuleName ? this.getDefaultWhere(target.defaultWhereModuleName) : {},
|
target.defaultWhereModuleName ? this.getDefaultWhere(target.defaultWhereModuleName) : {},
|
||||||
whereAfterWaveScope
|
whereAfterBuyerMessage
|
||||||
);
|
);
|
||||||
let queryWhere = this.buildWhere(mergedWhere, warehouseId, {
|
let queryWhere = this.buildWhere(mergedWhere, warehouseId, {
|
||||||
specialFieldMap: {
|
specialFieldMap: {
|
||||||
@ -643,16 +638,6 @@ class OrderExportService extends OrderBaseService {
|
|||||||
queryWhere = this.appendConditionToWhere(queryWhere, buyerMessageCondition);
|
queryWhere = this.appendConditionToWhere(queryWhere, buyerMessageCondition);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (waveIndexCondition) {
|
|
||||||
const waveIndexOrderIds = await this.findOrderIdsByWaveIndexCondition(waveIndexCondition, warehouseId);
|
|
||||||
queryWhere = this.appendOrderIdsFilterToWhere(queryWhere, waveIndexOrderIds);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (waveScope) {
|
|
||||||
const waveScopeCondition = await this.buildWaveScopeWhereCondition(waveScope, warehouseId);
|
|
||||||
queryWhere = this.appendConditionToWhere(queryWhere, waveScopeCondition);
|
|
||||||
}
|
|
||||||
|
|
||||||
const orderModel = await this.getOrderModelByTableType(target.tableType, warehouseId);
|
const orderModel = await this.getOrderModelByTableType(target.tableType, warehouseId);
|
||||||
const pageSize = this.getExportPageSize();
|
const pageSize = this.getExportPageSize();
|
||||||
const order = this.buildListOrder(requestData.sort, target.sortModuleName);
|
const order = this.buildListOrder(requestData.sort, target.sortModuleName);
|
||||||
@ -698,9 +683,8 @@ class OrderExportService extends OrderBaseService {
|
|||||||
const normalizedRows = rows.map(row =>
|
const normalizedRows = rows.map(row =>
|
||||||
this.normalizeOrderListItem(this.toPlainRow(row))
|
this.normalizeOrderListItem(this.toPlainRow(row))
|
||||||
);
|
);
|
||||||
const rowsWithWaveIndex = await this.attachOrderWaveIndex(normalizedRows);
|
|
||||||
|
|
||||||
const orderIds = rowsWithWaveIndex.map(r => Number(r.id || 0)).filter(id => id > 0);
|
const orderIds = normalizedRows.map(r => Number(r.id || 0)).filter(id => id > 0);
|
||||||
|
|
||||||
// 批量查询商品明细(wms_order_items)
|
// 批量查询商品明细(wms_order_items)
|
||||||
const itemsMap = new Map();
|
const itemsMap = new Map();
|
||||||
@ -775,7 +759,7 @@ class OrderExportService extends OrderBaseService {
|
|||||||
try {
|
try {
|
||||||
const storeIds = [
|
const storeIds = [
|
||||||
...new Set(
|
...new Set(
|
||||||
rowsWithWaveIndex
|
normalizedRows
|
||||||
.map(r => Number(r.store_id || 0))
|
.map(r => Number(r.store_id || 0))
|
||||||
.filter(id => id > 0)
|
.filter(id => id > 0)
|
||||||
),
|
),
|
||||||
@ -860,14 +844,14 @@ class OrderExportService extends OrderBaseService {
|
|||||||
|
|
||||||
const exportContext = { itemsMap, storeRemarkMap, stockNameMap, barcodeMap, imageUrlMap, expressMap, packageMaterialMap };
|
const exportContext = { itemsMap, storeRemarkMap, stockNameMap, barcodeMap, imageUrlMap, expressMap, packageMaterialMap };
|
||||||
|
|
||||||
for (const row of rowsWithWaveIndex) {
|
for (const row of normalizedRows) {
|
||||||
const exportRows = this.mapOrderExportRow(row, exportContext, mode);
|
const exportRows = this.mapOrderExportRow(row, exportContext, mode);
|
||||||
for (const exportRow of exportRows) {
|
for (const exportRow of exportRows) {
|
||||||
worksheet.addRow(exportRow).commit();
|
worksheet.addRow(exportRow).commit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
currentCount += rowsWithWaveIndex.length;
|
currentCount += normalizedRows.length;
|
||||||
|
|
||||||
await progressHandler({
|
await progressHandler({
|
||||||
status: 'running',
|
status: 'running',
|
||||||
|
|||||||
@ -172,40 +172,6 @@ class OrderPrintSystemService extends OrderBaseService {
|
|||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 构建打印项聚合键。
|
|
||||||
*
|
|
||||||
* 同一库位下的拣货行只有商品身份一致时才允许合并:
|
|
||||||
* - 优先 stock_id(>0):同一库位同一商品合并数量;
|
|
||||||
* - stock_id 缺失时回退 order_item_id(同一订单商品行);
|
|
||||||
* - 再缺失时回退 商品名称+条码 兜底;
|
|
||||||
* - 均无法识别时不做跨行合并(每行独立)。
|
|
||||||
*
|
|
||||||
* @param {Object} item 打印项。
|
|
||||||
* @return {string} 聚合键。
|
|
||||||
*/
|
|
||||||
buildPrintItemAggregationKey(item = {}) {
|
|
||||||
const source = this.isPlainObject(item) ? item : {};
|
|
||||||
const location = String(source.pick_location || '').trim();
|
|
||||||
const stockId = Number(source.stock_id || 0);
|
|
||||||
if (stockId > 0) {
|
|
||||||
return `${location}::stock:${stockId}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
const orderItemId = Number(source.order_item_id || 0);
|
|
||||||
if (orderItemId > 0) {
|
|
||||||
return `${location}::order_item:${orderItemId}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
const name = String(source.item_name || '').trim();
|
|
||||||
const barcode = String(source.barcode || '').trim();
|
|
||||||
if (name || barcode) {
|
|
||||||
return `${location}::name:${name}|${barcode}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
return `${location}::id:${Math.random()}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 批量补查打印所需的拣货明细,并注入商品多条码。
|
* 批量补查打印所需的拣货明细,并注入商品多条码。
|
||||||
*
|
*
|
||||||
@ -411,19 +377,20 @@ class OrderPrintSystemService extends OrderBaseService {
|
|||||||
|
|
||||||
// 为每条打印项注入 barcodes 数组,供 resolveItemBarcodeText 优先读取
|
// 为每条打印项注入 barcodes 数组,供 resolveItemBarcodeText 优先读取
|
||||||
for (const item of printItems) {
|
for (const item of printItems) {
|
||||||
const stockId = Number(item.stock_id || 0);
|
const stockId = item.stock_id;
|
||||||
item.stock_id = stockId > 0 ? stockId : 0;
|
|
||||||
|
|
||||||
if (stockId > 0 && barcodeMap.has(stockId)) {
|
if (stockId && barcodeMap.has(stockId)) {
|
||||||
item.barcodes = barcodeMap.get(stockId);
|
item.barcodes = barcodeMap.get(stockId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 清理内部字段,避免污染 JSON 输出
|
||||||
|
delete item.stock_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 按「库位 + 商品(stock_id)」聚合:同一库位的同一商品合并为一行,
|
// 按库位(pick_location)聚合,同一库位的商品合并为一行
|
||||||
// 同一库位的不同商品保持独立行,避免数量、条码被错误合并。
|
|
||||||
const aggregatedMap = new Map();
|
const aggregatedMap = new Map();
|
||||||
for (const item of printItems) {
|
for (const item of printItems) {
|
||||||
const key = this.buildPrintItemAggregationKey(item);
|
const key = item.pick_location || '';
|
||||||
const existing = aggregatedMap.get(key);
|
const existing = aggregatedMap.get(key);
|
||||||
if (existing) {
|
if (existing) {
|
||||||
// 累加数量
|
// 累加数量
|
||||||
@ -447,11 +414,6 @@ class OrderPrintSystemService extends OrderBaseService {
|
|||||||
}
|
}
|
||||||
const mergedPrintItems = Array.from(aggregatedMap.values());
|
const mergedPrintItems = Array.from(aggregatedMap.values());
|
||||||
|
|
||||||
// 聚合完成后清理内部字段,避免污染 JSON 输出
|
|
||||||
for (const item of mergedPrintItems) {
|
|
||||||
delete item.stock_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 为聚合后的商品行添加序号(从 1 开始)
|
// 为聚合后的商品行添加序号(从 1 开始)
|
||||||
for (let i = 0; i < mergedPrintItems.length; i++) {
|
for (let i = 0; i < mergedPrintItems.length; i++) {
|
||||||
mergedPrintItems[i].seq_no = i + 1;
|
mergedPrintItems[i].seq_no = i + 1;
|
||||||
|
|||||||
@ -2228,7 +2228,6 @@ class OrderStorageAllocationService extends MainService {
|
|||||||
orders: skippedOrders,
|
orders: skippedOrders,
|
||||||
picking_count: 0,
|
picking_count: 0,
|
||||||
storage_unlock_summary: [],
|
storage_unlock_summary: [],
|
||||||
storage_return_summary: [],
|
|
||||||
stock_unlock_summary: [],
|
stock_unlock_summary: [],
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@ -2250,8 +2249,7 @@ class OrderStorageAllocationService extends MainService {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const pickingRowsByOrderId = new Map();
|
const pickingRowsByOrderId = new Map();
|
||||||
const pendingStorageQuantityMap = new Map();
|
const storageQuantityMap = new Map();
|
||||||
const finStorageQuantityMap = new Map();
|
|
||||||
const storageIdSet = new Set();
|
const storageIdSet = new Set();
|
||||||
|
|
||||||
for (const pickingRow of Array.isArray(pickingRows) ? pickingRows : []) {
|
for (const pickingRow of Array.isArray(pickingRows) ? pickingRows : []) {
|
||||||
@ -2269,14 +2267,7 @@ class OrderStorageAllocationService extends MainService {
|
|||||||
pickingRowsByOrderId.set(orderId, orderPickingRows);
|
pickingRowsByOrderId.set(orderId, orderPickingRows);
|
||||||
|
|
||||||
storageIdSet.add(storageId);
|
storageIdSet.add(storageId);
|
||||||
// 按状态分流:pending 记录解除锁定(实物不动);
|
storageQuantityMap.set(storageId, (storageQuantityMap.get(storageId) || 0) + quantity);
|
||||||
// fin 记录(已拣货)返还实物数量,锁定已在拣货完成时扣减,不再重复扣除
|
|
||||||
const pickingStatus = String(plainPicking?.status || '').trim();
|
|
||||||
if (pickingStatus === 'fin') {
|
|
||||||
finStorageQuantityMap.set(storageId, (finStorageQuantityMap.get(storageId) || 0) + quantity);
|
|
||||||
} else {
|
|
||||||
pendingStorageQuantityMap.set(storageId, (pendingStorageQuantityMap.get(storageId) || 0) + quantity);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const cancellableOrderIds = [];
|
const cancellableOrderIds = [];
|
||||||
@ -2307,7 +2298,6 @@ class OrderStorageAllocationService extends MainService {
|
|||||||
orders: skippedOrders,
|
orders: skippedOrders,
|
||||||
picking_count: 0,
|
picking_count: 0,
|
||||||
storage_unlock_summary: [],
|
storage_unlock_summary: [],
|
||||||
storage_return_summary: [],
|
|
||||||
stock_unlock_summary: [],
|
stock_unlock_summary: [],
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@ -2336,10 +2326,8 @@ class OrderStorageAllocationService extends MainService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const storageUnlockSummary = [];
|
const storageUnlockSummary = [];
|
||||||
const storageReturnSummary = [];
|
|
||||||
|
|
||||||
// pending 记录:解除锁定,实物库存不动
|
for (const [ storageId, quantity ] of storageQuantityMap.entries()) {
|
||||||
for (const [ storageId, quantity ] of pendingStorageQuantityMap.entries()) {
|
|
||||||
if (quantity <= 0) {
|
if (quantity <= 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -2384,53 +2372,6 @@ class OrderStorageAllocationService extends MainService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// fin 记录(已拣货):返还实物数量,锁定已在拣货完成时扣减,不再重复扣除
|
|
||||||
for (const [ storageId, returnQuantity ] of finStorageQuantityMap.entries()) {
|
|
||||||
if (returnQuantity <= 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const storageRow = storageMap.get(storageId);
|
|
||||||
if (!storageRow) {
|
|
||||||
throw new Error(`库存记录不存在: ${storageId}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
const beforeQuantity = toNumber(storageRow.quantity, 0);
|
|
||||||
const beforeLockedQuantity = toNumber(storageRow.locked_quantity, 0);
|
|
||||||
|
|
||||||
await ctx.service.systems.storage.index.updateQuantity(storageId, returnQuantity, 0, {
|
|
||||||
transaction,
|
|
||||||
});
|
|
||||||
|
|
||||||
// 写入库存返还流水(实物数量增加,锁定不变)
|
|
||||||
await ctx.model.StorageTransaction.create({
|
|
||||||
transaction_type: 'INBOUND',
|
|
||||||
warehouse_id: warehouseId,
|
|
||||||
store_id: storageRow.store_id,
|
|
||||||
stock_id: storageRow.stock_id,
|
|
||||||
storage_id: storageId,
|
|
||||||
space_id: storageRow.space_id,
|
|
||||||
quantity: returnQuantity,
|
|
||||||
before_quantity: beforeQuantity,
|
|
||||||
after_quantity: beforeQuantity + returnQuantity,
|
|
||||||
before_locked_quantity: beforeLockedQuantity,
|
|
||||||
after_locked_quantity: beforeLockedQuantity,
|
|
||||||
batch_no: storageRow.batch_no,
|
|
||||||
inventory_type: storageRow.inventory_type,
|
|
||||||
order_type: 'PICK_RETURN',
|
|
||||||
order_no: 'CANCEL_BATCH',
|
|
||||||
order_id: 0,
|
|
||||||
operator_id: String(ctx.user?.employees_id ?? ctx.user?.id ?? ''),
|
|
||||||
operator_name: ctx.user?.employees_name ?? ctx.user?.real_name ?? ctx.user?.name ?? '',
|
|
||||||
remark: '取消分配储位(已拣货返还库存)',
|
|
||||||
}, { transaction });
|
|
||||||
|
|
||||||
storageReturnSummary.push({
|
|
||||||
storage_id: storageId,
|
|
||||||
returned_quantity: returnQuantity,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const cancelPickingIds = [];
|
const cancelPickingIds = [];
|
||||||
for (const orderId of cancellableOrderIds) {
|
for (const orderId of cancellableOrderIds) {
|
||||||
const orderPickingRows = pickingRowsByOrderId.get(orderId) || [];
|
const orderPickingRows = pickingRowsByOrderId.get(orderId) || [];
|
||||||
@ -2498,7 +2439,6 @@ class OrderStorageAllocationService extends MainService {
|
|||||||
orders: [ ...skippedOrders, ...orderResults ],
|
orders: [ ...skippedOrders, ...orderResults ],
|
||||||
picking_count: cancelPickingIds.length,
|
picking_count: cancelPickingIds.length,
|
||||||
storage_unlock_summary: storageUnlockSummary,
|
storage_unlock_summary: storageUnlockSummary,
|
||||||
storage_return_summary: storageReturnSummary,
|
|
||||||
stock_unlock_summary: [],
|
stock_unlock_summary: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -1947,9 +1947,7 @@ class PickSystemService extends Service {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查目标订单是否进入拦截流程,拦截订单直接跳过:
|
// 检查目标订单是否进入拦截流程,拦截订单不允许完成拣货
|
||||||
// 不完成拣货、不扣减库存(不取出)、不报错,其余订单照常完成
|
|
||||||
const skippedInterceptedOrders = [];
|
|
||||||
if (targetOrderIds.length > 0) {
|
if (targetOrderIds.length > 0) {
|
||||||
const interceptCheckModel = await this.getOrderModel(warehouseId);
|
const interceptCheckModel = await this.getOrderModel(warehouseId);
|
||||||
const interceptedOrderRows = await interceptCheckModel.findAll({
|
const interceptedOrderRows = await interceptCheckModel.findAll({
|
||||||
@ -1968,288 +1966,14 @@ class PickSystemService extends Service {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (interceptedOrderRows && interceptedOrderRows.length > 0) {
|
if (interceptedOrderRows && interceptedOrderRows.length > 0) {
|
||||||
const interceptedOrderIdSet = new Set(
|
const detailList = interceptedOrderRows.map(
|
||||||
interceptedOrderRows.map(orderRow => Number(orderRow && orderRow.id || 0))
|
orderRow => `订单${orderRow.id}(intercept_status=${orderRow.intercept_status})`
|
||||||
|
).join(';');
|
||||||
|
throw this.createBusinessError(
|
||||||
|
`以下订单已被拦截,无法完成拣货:${detailList}`,
|
||||||
|
400
|
||||||
);
|
);
|
||||||
for (const orderRow of interceptedOrderRows) {
|
|
||||||
skippedInterceptedOrders.push({
|
|
||||||
order_id: Number(orderRow && orderRow.id || 0),
|
|
||||||
intercept_status: String(orderRow && orderRow.intercept_status || '').trim() || 'none',
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
targetOrderIds = targetOrderIds.filter(orderId => !interceptedOrderIdSet.has(orderId));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// source !== 0(PDA/后台抓取创建的任务)时,被跳过的拦截订单直接从波次中移除:
|
|
||||||
// 订单 wave_id 清零、重建波次索引、回写波次统计,并移除任务订单关联
|
|
||||||
const removedFromWaveOrderLogItems = [];
|
|
||||||
const removedFromWaveOrderIds = [];
|
|
||||||
if (skippedInterceptedOrders.length > 0 && taskSource !== 0) {
|
|
||||||
const skippedOrderIds = skippedInterceptedOrders.map(item => item.order_id);
|
|
||||||
const interceptOrderModel = await this.getOrderModel(warehouseId);
|
|
||||||
const removableRows = await interceptOrderModel.findAll({
|
|
||||||
attributes: [ 'id', 'wave_id', 'wave_no' ],
|
|
||||||
where: {
|
|
||||||
warehouse_id: warehouseId,
|
|
||||||
id: {
|
|
||||||
[this.app.Sequelize.Op.in]: skippedOrderIds,
|
|
||||||
},
|
|
||||||
wave_id: {
|
|
||||||
[this.app.Sequelize.Op.gt]: 0,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
raw: true,
|
|
||||||
transaction,
|
|
||||||
});
|
|
||||||
|
|
||||||
const normalizedRemovableRows = Array.isArray(removableRows) ? removableRows : [];
|
|
||||||
const affectedWaveIds = [ ...new Set(normalizedRemovableRows
|
|
||||||
.map(row => Number(row && row.wave_id || 0))
|
|
||||||
.filter(waveId => Number.isInteger(waveId) && waveId > 0)) ];
|
|
||||||
|
|
||||||
if (normalizedRemovableRows.length > 0) {
|
|
||||||
await interceptOrderModel.update({
|
|
||||||
wave_id: 0,
|
|
||||||
wave_no: '',
|
|
||||||
wave_strategy_version: 0,
|
|
||||||
wave_scan_result: 0,
|
|
||||||
}, {
|
|
||||||
where: {
|
|
||||||
warehouse_id: warehouseId,
|
|
||||||
id: {
|
|
||||||
[this.app.Sequelize.Op.in]: normalizedRemovableRows.map(row => Number(row.id)),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
transaction,
|
|
||||||
});
|
|
||||||
|
|
||||||
for (const row of normalizedRemovableRows) {
|
|
||||||
removedFromWaveOrderIds.push(Number(row && row.id || 0));
|
|
||||||
removedFromWaveOrderLogItems.push({
|
|
||||||
orderId: Number(row && row.id || 0),
|
|
||||||
operationCode: 'ORDER_WAVE_REMOVE',
|
|
||||||
message: `订单从波次 ${String(row && row.wave_no || '').trim() || '未知波次'} 中移除`,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (affectedWaveIds.length > 0) {
|
|
||||||
const waveService = this.ctx.service
|
|
||||||
&& this.ctx.service.systemMethods
|
|
||||||
&& this.ctx.service.systemMethods.order
|
|
||||||
&& this.ctx.service.systemMethods.order.wave;
|
|
||||||
|
|
||||||
// 仅删除拦截单自身的索引行,不重建整波索引:
|
|
||||||
// 其余订单 wave_index 保持不变(仅跳号),避免与已放货的篮子编号
|
|
||||||
// (task_order.box_no / task_box.box_no 为创建时 wave_index 快照)错位,
|
|
||||||
// 保证复核/打印等按 wave_index 排序的环节仍与实物位置一致。
|
|
||||||
if (waveService && typeof waveService.deleteOrderWaveIndexByOrderIds === 'function') {
|
|
||||||
await waveService.deleteOrderWaveIndexByOrderIds({
|
|
||||||
warehouseId,
|
|
||||||
orderIds: normalizedRemovableRows.map(row => Number(row.id)),
|
|
||||||
transaction,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// 按剩余索引行数回写波次统计(删除后未重建,剩余订单序号保持不变)
|
|
||||||
const remainingIndexRows = await this.ctx.model.query(`
|
|
||||||
SELECT wave_id, COUNT(*) AS remaining_count
|
|
||||||
FROM wms_order_wave_index
|
|
||||||
WHERE warehouse_id = :warehouseId
|
|
||||||
AND wave_id IN (:waveIds)
|
|
||||||
GROUP BY wave_id
|
|
||||||
`, {
|
|
||||||
replacements: {
|
|
||||||
warehouseId,
|
|
||||||
waveIds: affectedWaveIds,
|
|
||||||
},
|
|
||||||
type: this.ctx.model.QueryTypes.SELECT,
|
|
||||||
transaction,
|
|
||||||
});
|
|
||||||
|
|
||||||
const remainingCountMap = new Map();
|
|
||||||
for (const row of Array.isArray(remainingIndexRows) ? remainingIndexRows : []) {
|
|
||||||
const waveId = Number(row && row.wave_id || 0);
|
|
||||||
const remainingCount = Number(row && row.remaining_count || 0);
|
|
||||||
if (Number.isInteger(waveId) && waveId > 0) {
|
|
||||||
remainingCountMap.set(waveId, remainingCount);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const updatedWaveIds = [];
|
|
||||||
const emptiedWaveIds = [];
|
|
||||||
for (const waveId of affectedWaveIds) {
|
|
||||||
const remainingCount = Number(remainingCountMap.get(waveId) || 0);
|
|
||||||
if (remainingCount > 0) {
|
|
||||||
updatedWaveIds.push(waveId);
|
|
||||||
} else {
|
|
||||||
emptiedWaveIds.push(waveId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const waveId of updatedWaveIds) {
|
|
||||||
const remainingCount = Number(remainingCountMap.get(waveId) || 0);
|
|
||||||
await this.ctx.model.query(`
|
|
||||||
UPDATE wms_wave_batch
|
|
||||||
SET total_orders = :remainingCount,
|
|
||||||
processed_orders = LEAST(processed_orders, :remainingCount),
|
|
||||||
update_time = NOW()
|
|
||||||
WHERE warehouse_id = :warehouseId
|
|
||||||
AND wave_id = :waveId
|
|
||||||
`, {
|
|
||||||
replacements: {
|
|
||||||
warehouseId,
|
|
||||||
waveId,
|
|
||||||
remainingCount,
|
|
||||||
},
|
|
||||||
transaction,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (emptiedWaveIds.length > 0) {
|
|
||||||
await this.ctx.model.query(`
|
|
||||||
UPDATE wms_wave_batch
|
|
||||||
SET total_orders = 0,
|
|
||||||
processed_orders = 0,
|
|
||||||
wave_status = -1,
|
|
||||||
update_time = NOW()
|
|
||||||
WHERE warehouse_id = :warehouseId
|
|
||||||
AND wave_id IN (:waveIds)
|
|
||||||
`, {
|
|
||||||
replacements: {
|
|
||||||
warehouseId,
|
|
||||||
waveIds: emptiedWaveIds,
|
|
||||||
},
|
|
||||||
transaction,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 移除任务订单关联记录,任务进度不再包含被移出波次的拦截单
|
|
||||||
await this.ctx.model.query(`
|
|
||||||
DELETE FROM wms_wave_pick_task_order
|
|
||||||
WHERE task_id = :taskId
|
|
||||||
AND warehouse_id = :warehouseId
|
|
||||||
AND order_id IN (:orderIds)
|
|
||||||
`, {
|
|
||||||
replacements: {
|
|
||||||
taskId,
|
|
||||||
warehouseId,
|
|
||||||
orderIds: normalizedRemovableRows.map(row => Number(row.id)),
|
|
||||||
},
|
|
||||||
transaction,
|
|
||||||
});
|
|
||||||
|
|
||||||
// 同步移除拦截单对应的篮子明细(散单模式 box_type=2 绑定订单),避免遗留空盒
|
|
||||||
const taskBoxColumnSet = await this.getTableColumnSet('wms_wave_pick_task_box');
|
|
||||||
const taskBoxWarehouseFilterSql = taskBoxColumnSet.has('warehouse_id') ? ' AND warehouse_id = :warehouseId' : '';
|
|
||||||
await this.ctx.model.query(`
|
|
||||||
DELETE FROM wms_wave_pick_task_box
|
|
||||||
WHERE task_id = :taskId
|
|
||||||
AND order_id IN (:orderIds)
|
|
||||||
${taskBoxWarehouseFilterSql}
|
|
||||||
`, {
|
|
||||||
replacements: {
|
|
||||||
taskId,
|
|
||||||
warehouseId,
|
|
||||||
orderIds: normalizedRemovableRows.map(row => Number(row.id)),
|
|
||||||
},
|
|
||||||
transaction,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 目标订单全部被拦截跳过:不做任何拣货/库存变更,直接成功返回
|
|
||||||
if (targetOrderIds.length <= 0) {
|
|
||||||
// mode=1(全部确认)时任务标记完成;mode=2 依据任务进度判断
|
|
||||||
const skipProgressBeforeComplete = await this.getTaskPickProgress(taskId, warehouseId, transaction);
|
|
||||||
const skipTaskCompleted = mode === 1 || skipProgressBeforeComplete.isCompleted;
|
|
||||||
if (skipTaskCompleted) {
|
|
||||||
await this.ctx.model.query(`
|
|
||||||
UPDATE wms_wave_pick_task
|
|
||||||
SET status = 2,
|
|
||||||
finish_time = NOW(),
|
|
||||||
start_time = CASE WHEN start_time IS NULL THEN NOW() ELSE start_time END,
|
|
||||||
update_time = NOW()
|
|
||||||
WHERE id = :taskId
|
|
||||||
AND warehouse_id = :warehouseId
|
|
||||||
`, {
|
|
||||||
replacements: {
|
|
||||||
taskId,
|
|
||||||
warehouseId,
|
|
||||||
},
|
|
||||||
transaction,
|
|
||||||
});
|
|
||||||
|
|
||||||
// 同步更新波次关联状态为已拣
|
|
||||||
const taskWaveColumnSet = await this.getTableColumnSet('wms_wave_pick_task_wave');
|
|
||||||
const taskWaveWarehouseFilterSql = taskWaveColumnSet.has('warehouse_id') ? ' AND warehouse_id = :warehouseId' : '';
|
|
||||||
await this.ctx.model.query(`
|
|
||||||
UPDATE wms_wave_pick_task_wave
|
|
||||||
SET status = 1,
|
|
||||||
pick_time = NOW(),
|
|
||||||
update_time = NOW()
|
|
||||||
WHERE task_id = :taskId
|
|
||||||
${taskWaveWarehouseFilterSql}
|
|
||||||
`, {
|
|
||||||
replacements: {
|
|
||||||
taskId,
|
|
||||||
warehouseId,
|
|
||||||
},
|
|
||||||
transaction,
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
await this.ctx.model.query(`
|
|
||||||
UPDATE wms_wave_pick_task
|
|
||||||
SET status = CASE WHEN status = 0 THEN 1 ELSE status END,
|
|
||||||
start_time = CASE WHEN start_time IS NULL THEN NOW() ELSE start_time END,
|
|
||||||
update_time = NOW()
|
|
||||||
WHERE id = :taskId
|
|
||||||
AND warehouse_id = :warehouseId
|
|
||||||
`, {
|
|
||||||
replacements: {
|
|
||||||
taskId,
|
|
||||||
warehouseId,
|
|
||||||
},
|
|
||||||
transaction,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
await transaction.commit();
|
|
||||||
const skipProgress = await this.getTaskPickProgress(taskId, warehouseId);
|
|
||||||
await this._writePickCompleteActionLog({
|
|
||||||
taskId,
|
|
||||||
warehouseId,
|
|
||||||
operatorId,
|
|
||||||
operatorName,
|
|
||||||
targetOrderIds: [],
|
|
||||||
mode,
|
|
||||||
isCompleted: skipProgress.isCompleted,
|
|
||||||
progress: skipProgress,
|
|
||||||
skippedInterceptedOrders,
|
|
||||||
});
|
|
||||||
await this._afterSkipInterceptedPostActions({
|
|
||||||
warehouseId,
|
|
||||||
operatorId,
|
|
||||||
operatorName,
|
|
||||||
removedFromWaveOrderLogItems,
|
|
||||||
removedFromWaveOrderIds,
|
|
||||||
});
|
|
||||||
return {
|
|
||||||
task_id: taskId,
|
|
||||||
mode,
|
|
||||||
confirmed_order_ids: [],
|
|
||||||
skipped_intercepted_order_ids: skippedInterceptedOrders.map(item => item.order_id),
|
|
||||||
skipped_intercepted_orders: skippedInterceptedOrders,
|
|
||||||
removed_from_wave_order_ids: removedFromWaveOrderIds,
|
|
||||||
is_completed: skipProgress.isCompleted,
|
|
||||||
task_completed: skipTaskCompleted,
|
|
||||||
progress: {
|
|
||||||
total_orders: skipProgress.totalOrders,
|
|
||||||
picked_orders: skipProgress.pickedOrders,
|
|
||||||
pending_orders: skipProgress.pendingOrders,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查目标订单是否已分配储位(storage_status='fin'),防止订单在波次中被取消储位分配后仍然完成拣货
|
// 检查目标订单是否已分配储位(storage_status='fin'),防止订单在波次中被取消储位分配后仍然完成拣货
|
||||||
@ -2444,9 +2168,7 @@ class PickSystemService extends Service {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const progress = await this.getTaskPickProgress(taskId, warehouseId, transaction);
|
const progress = await this.getTaskPickProgress(taskId, warehouseId, transaction);
|
||||||
// mode=1(全部确认)时任务直接标记完成;mode=2 依据任务进度判断
|
if (mode === 1 || progress.isCompleted) {
|
||||||
const taskCompleted = mode === 1 || progress.isCompleted;
|
|
||||||
if (taskCompleted) {
|
|
||||||
await ctx.model.query(`
|
await ctx.model.query(`
|
||||||
UPDATE wms_wave_pick_task
|
UPDATE wms_wave_pick_task
|
||||||
SET status = 2,
|
SET status = 2,
|
||||||
@ -2509,16 +2231,6 @@ class PickSystemService extends Service {
|
|||||||
mode,
|
mode,
|
||||||
isCompleted: progress.isCompleted,
|
isCompleted: progress.isCompleted,
|
||||||
progress,
|
progress,
|
||||||
skippedInterceptedOrders,
|
|
||||||
});
|
|
||||||
|
|
||||||
// 被移出波次的拦截订单:写订单操作日志 + 触发策略快扫(不影响主流程)
|
|
||||||
await this._afterSkipInterceptedPostActions({
|
|
||||||
warehouseId,
|
|
||||||
operatorId,
|
|
||||||
operatorName,
|
|
||||||
removedFromWaveOrderLogItems,
|
|
||||||
removedFromWaveOrderIds,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// 写入 order_operation_log 拣货完成日志
|
// 写入 order_operation_log 拣货完成日志
|
||||||
@ -2555,11 +2267,7 @@ class PickSystemService extends Service {
|
|||||||
task_id: taskId,
|
task_id: taskId,
|
||||||
mode,
|
mode,
|
||||||
confirmed_order_ids: targetOrderIds,
|
confirmed_order_ids: targetOrderIds,
|
||||||
skipped_intercepted_order_ids: skippedInterceptedOrders.map(item => item.order_id),
|
|
||||||
skipped_intercepted_orders: skippedInterceptedOrders,
|
|
||||||
removed_from_wave_order_ids: removedFromWaveOrderIds,
|
|
||||||
is_completed: progress.isCompleted,
|
is_completed: progress.isCompleted,
|
||||||
task_completed: taskCompleted,
|
|
||||||
progress: {
|
progress: {
|
||||||
total_orders: progress.totalOrders,
|
total_orders: progress.totalOrders,
|
||||||
picked_orders: progress.pickedOrders,
|
picked_orders: progress.pickedOrders,
|
||||||
@ -2572,81 +2280,6 @@ class PickSystemService extends Service {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 拦截单跳过后的收尾动作(均不影响主流程):
|
|
||||||
* 1. 写入被移出波次拦截订单的 ORDER_WAVE_REMOVE 操作日志;
|
|
||||||
* 2. 触发波次策略快速扫描,让移出波次的订单重新进入可抓取池。
|
|
||||||
*
|
|
||||||
* @param {Object} params 参数。
|
|
||||||
* @param {number} params.warehouseId 仓库ID。
|
|
||||||
* @param {number} params.operatorId 操作人ID。
|
|
||||||
* @param {string} params.operatorName 操作人名称。
|
|
||||||
* @param {Array<Object>} params.removedFromWaveOrderLogItems 波次移除日志项。
|
|
||||||
* @param {Array<number>} params.removedFromWaveOrderIds 被移出波次的订单ID。
|
|
||||||
* @return {Promise<void>} 无返回值。
|
|
||||||
*/
|
|
||||||
async _afterSkipInterceptedPostActions(params = {}) {
|
|
||||||
const warehouseId = Number(params && params.warehouseId || 0);
|
|
||||||
const operatorId = Number(params && params.operatorId || 0);
|
|
||||||
const operatorName = String(params && params.operatorName || '').trim() || 'system';
|
|
||||||
const removedFromWaveOrderLogItems = Array.isArray(params && params.removedFromWaveOrderLogItems)
|
|
||||||
? params.removedFromWaveOrderLogItems
|
|
||||||
: [];
|
|
||||||
const removedFromWaveOrderIds = Array.isArray(params && params.removedFromWaveOrderIds)
|
|
||||||
? params.removedFromWaveOrderIds
|
|
||||||
: [];
|
|
||||||
|
|
||||||
if (removedFromWaveOrderLogItems.length > 0) {
|
|
||||||
try {
|
|
||||||
const operationLogService = this.ctx
|
|
||||||
&& this.ctx.service
|
|
||||||
&& this.ctx.service.systems
|
|
||||||
&& this.ctx.service.systems.operationLog;
|
|
||||||
if (operationLogService && typeof operationLogService.createOperationLogs === 'function') {
|
|
||||||
const logPayloads = removedFromWaveOrderLogItems.map(item => ({
|
|
||||||
businessType: 'order',
|
|
||||||
businessId: `${item.orderId}`,
|
|
||||||
operationCode: item.operationCode,
|
|
||||||
operator: {
|
|
||||||
id: operatorId ? String(operatorId) : null,
|
|
||||||
name: operatorName,
|
|
||||||
},
|
|
||||||
extras: {
|
|
||||||
message: item.message,
|
|
||||||
warehouseId,
|
|
||||||
externalLogType: 'API',
|
|
||||||
},
|
|
||||||
}));
|
|
||||||
await operationLogService.createOperationLogs(logPayloads);
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
this.ctx.logger.warn('[pick.wavePickTaskComplete] 写入波次移除操作日志失败,不影响主流程', {
|
|
||||||
error: e && e.message,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (removedFromWaveOrderIds.length > 0) {
|
|
||||||
try {
|
|
||||||
const waveService = this.ctx.service
|
|
||||||
&& this.ctx.service.systemMethods
|
|
||||||
&& this.ctx.service.systemMethods.order
|
|
||||||
&& this.ctx.service.systemMethods.order.wave;
|
|
||||||
if (waveService && typeof waveService.enqueueWaveStrategyQuickScanPostOrderChange === 'function') {
|
|
||||||
waveService.enqueueWaveStrategyQuickScanPostOrderChange(
|
|
||||||
warehouseId,
|
|
||||||
removedFromWaveOrderIds,
|
|
||||||
{ triggerScan: true, source: 'pickSkipInterceptedRemoveWave' }
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
this.ctx.logger.warn('[pick.wavePickTaskComplete] 触发波次策略快扫失败,不影响主流程', {
|
|
||||||
error: e && e.message,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 写入拣货完成操作日志到 wms_wave_pick_action_log(内部方法)。
|
* 写入拣货完成操作日志到 wms_wave_pick_action_log(内部方法)。
|
||||||
*
|
*
|
||||||
@ -2659,7 +2292,6 @@ class PickSystemService extends Service {
|
|||||||
* @param {number} params.mode 提交模式(1全部确认 2部分确认)。
|
* @param {number} params.mode 提交模式(1全部确认 2部分确认)。
|
||||||
* @param {boolean} params.isCompleted 任务是否全部完成。
|
* @param {boolean} params.isCompleted 任务是否全部完成。
|
||||||
* @param {Object} params.progress 任务进度信息。
|
* @param {Object} params.progress 任务进度信息。
|
||||||
* @param {Array<Object>} params.skippedInterceptedOrders 被跳过的拦截订单(order_id + intercept_status)。
|
|
||||||
* @return {Promise<void>} 无返回值。
|
* @return {Promise<void>} 无返回值。
|
||||||
*/
|
*/
|
||||||
async _writePickCompleteActionLog(params = {}) {
|
async _writePickCompleteActionLog(params = {}) {
|
||||||
@ -2672,7 +2304,6 @@ class PickSystemService extends Service {
|
|||||||
mode,
|
mode,
|
||||||
isCompleted,
|
isCompleted,
|
||||||
progress,
|
progress,
|
||||||
skippedInterceptedOrders,
|
|
||||||
} = params;
|
} = params;
|
||||||
|
|
||||||
const requestId = `pick_complete_${warehouseId}_${taskId}_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`;
|
const requestId = `pick_complete_${warehouseId}_${taskId}_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`;
|
||||||
@ -2732,7 +2363,6 @@ class PickSystemService extends Service {
|
|||||||
mode,
|
mode,
|
||||||
confirmed_order_ids: targetOrderIds,
|
confirmed_order_ids: targetOrderIds,
|
||||||
confirmed_order_count: Array.isArray(targetOrderIds) ? targetOrderIds.length : 0,
|
confirmed_order_count: Array.isArray(targetOrderIds) ? targetOrderIds.length : 0,
|
||||||
skipped_intercepted_orders: Array.isArray(skippedInterceptedOrders) ? skippedInterceptedOrders : [],
|
|
||||||
is_completed: isCompleted,
|
is_completed: isCompleted,
|
||||||
progress: {
|
progress: {
|
||||||
total_orders: progress && progress.totalOrders,
|
total_orders: progress && progress.totalOrders,
|
||||||
|
|||||||
@ -189,6 +189,26 @@ const WAREHOUSE_SETTING_FIELDS = Object.freeze([
|
|||||||
required: false,
|
required: false,
|
||||||
description: '可配置多个库存预警项,每项包含 name、key、expire_days、tip_text',
|
description: '可配置多个库存预警项,每项包含 name、key、expire_days、tip_text',
|
||||||
}),
|
}),
|
||||||
|
Object.freeze({
|
||||||
|
key: 'webhook_enabled',
|
||||||
|
name: '是否启用 Webhook',
|
||||||
|
type: 'flag',
|
||||||
|
default: false,
|
||||||
|
required: false,
|
||||||
|
description: '控制仓库是否启用 Webhook 事件推送',
|
||||||
|
}),
|
||||||
|
Object.freeze({
|
||||||
|
key: 'callback_strategy',
|
||||||
|
name: '回调策略',
|
||||||
|
type: 'enum',
|
||||||
|
default: 'async',
|
||||||
|
required: false,
|
||||||
|
description: '仓库 Webhook 事件的回调执行策略',
|
||||||
|
options: [
|
||||||
|
Object.freeze({ value: 'sync', label: '同步回调' }),
|
||||||
|
Object.freeze({ value: 'async', label: '异步回调' }),
|
||||||
|
],
|
||||||
|
}),
|
||||||
Object.freeze({
|
Object.freeze({
|
||||||
key: 'auto_outbound_rules',
|
key: 'auto_outbound_rules',
|
||||||
name: '自动出库规则',
|
name: '自动出库规则',
|
||||||
|
|||||||
@ -2,14 +2,9 @@
|
|||||||
const Service = require('egg').Service;
|
const Service = require('egg').Service;
|
||||||
|
|
||||||
class spaceService extends Service {
|
class spaceService extends Service {
|
||||||
/**
|
async searchSpace(data) {
|
||||||
* 按关键字查询库位(单个关键字)。
|
|
||||||
*
|
|
||||||
* @param {string} [keyword] 搜索关键字,为空时返回当前仓库下前 50 条。
|
|
||||||
* @return {Promise<Array>} 库位列表(最多 50 条)。
|
|
||||||
*/
|
|
||||||
async _searchByKeyword(keyword) {
|
|
||||||
const { ctx, app } = this;
|
const { ctx, app } = this;
|
||||||
|
const { keyword } = data;
|
||||||
const warehouseId = ctx.user.store_id;
|
const warehouseId = ctx.user.store_id;
|
||||||
|
|
||||||
// 构建基础查询条件:warehouse_id 为当前仓库或 null
|
// 构建基础查询条件:warehouse_id 为当前仓库或 null
|
||||||
@ -51,7 +46,7 @@ class spaceService extends Service {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return app.model.LocationSpace.findAll({
|
const results = await app.model.LocationSpace.findAll({
|
||||||
where: whereCondition,
|
where: whereCondition,
|
||||||
attributes: [
|
attributes: [
|
||||||
'id', 'space_code', 'custom_barcode', 'custom_name',
|
'id', 'space_code', 'custom_barcode', 'custom_name',
|
||||||
@ -60,31 +55,8 @@ class spaceService extends Service {
|
|||||||
limit: 50,
|
limit: 50,
|
||||||
subQuery: false,
|
subQuery: false,
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
async searchSpace(data) {
|
|
||||||
const { keyword } = data;
|
|
||||||
const results = await this._searchByKeyword(keyword);
|
|
||||||
|
|
||||||
return { code: 200, data: results, total: results.length };
|
return { code: 200, data: results, total: results.length };
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 批量按关键字查询库位。
|
|
||||||
*
|
|
||||||
* @param {Object} data 请求数据。
|
|
||||||
* @param {Array<string>} data.keywords 搜索关键字数组。
|
|
||||||
* @return {Promise<Object>} data 为与 keywords 一一对应的库位列表数组,
|
|
||||||
* 无记录时对应项为空数组 []。
|
|
||||||
*/
|
|
||||||
async searchSpaces(data) {
|
|
||||||
const { keywords } = data;
|
|
||||||
const keywordList = Array.isArray(keywords) ? keywords : [];
|
|
||||||
const resultList = await Promise.all(
|
|
||||||
keywordList.map(keyword => this._searchByKeyword(keyword))
|
|
||||||
);
|
|
||||||
|
|
||||||
return { code: 200, data: resultList, total: resultList.length };
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
module.exports = spaceService;
|
module.exports = spaceService;
|
||||||
|
|||||||
@ -1,173 +0,0 @@
|
|||||||
// app/service/systems/wave_batch_closure.js
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
const MainService = require('../main');
|
|
||||||
|
|
||||||
// 活动中的波次状态(batchList 可见口径)
|
|
||||||
const ACTIVE_WAVE_STATUSES = [ 0, 1 ];
|
|
||||||
// 终结态:复核完成(与 recheckOrder 复核完成路径一致,使波次从 batchList 中自然消失)
|
|
||||||
const CLOSED_WAVE_STATUS = 5;
|
|
||||||
// 创建不足该分钟数的波次不参与自动终结,避免与创建事务并发误判
|
|
||||||
const WAVE_MIN_AGE_MINUTES = 5;
|
|
||||||
// 单次 SQL IN 列表的波次数量上限
|
|
||||||
const WAVE_ID_BATCH_SIZE = 500;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 波次批次自动终结服务。
|
|
||||||
*
|
|
||||||
* 背景:波次内订单全部离开待处理表后(发货迁移配送表、库内拦截确认、取消等),
|
|
||||||
* 若相关路径未回写 wms_wave_batch,波次会停留在 wave_status IN (0,1),
|
|
||||||
* 导致 order.wave.batchList 展示 0 单波次。
|
|
||||||
*
|
|
||||||
* 本服务按仓库扫描活动波次,对"待处理表中已无任何订单"的波次,
|
|
||||||
* 将 wave_status 收敛为 5(复核完成),使其从批次列表中消失。
|
|
||||||
*/
|
|
||||||
class WaveBatchClosureService extends MainService {
|
|
||||||
/**
|
|
||||||
* 扫描并关闭"订单已全部离表"的活动波次。
|
|
||||||
*
|
|
||||||
* @param {Object} [options={}] 执行选项。
|
|
||||||
* @param {boolean} [options.dryRun=false] 仅盘点不更新(用于验证命中范围)。
|
|
||||||
* @return {Promise<Object>} 执行结果汇总。
|
|
||||||
*/
|
|
||||||
async closeFinishedWaves(options = {}) {
|
|
||||||
const { ctx } = this;
|
|
||||||
const startedAt = Date.now();
|
|
||||||
const dryRun = Boolean(options && options.dryRun);
|
|
||||||
|
|
||||||
const candidateRows = await ctx.model.query(
|
|
||||||
`SELECT wave_id, wave_no, warehouse_id, wave_status, total_orders
|
|
||||||
FROM wms_wave_batch
|
|
||||||
WHERE wave_status IN (:waveStatuses)
|
|
||||||
AND total_orders > 0
|
|
||||||
AND create_time < (NOW() - INTERVAL ${WAVE_MIN_AGE_MINUTES} MINUTE)`,
|
|
||||||
{
|
|
||||||
replacements: { waveStatuses: ACTIVE_WAVE_STATUSES },
|
|
||||||
type: ctx.model.QueryTypes.SELECT,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
// 按仓库分组,过滤非法数据
|
|
||||||
const warehouseWaveMap = new Map();
|
|
||||||
for (const row of (Array.isArray(candidateRows) ? candidateRows : [])) {
|
|
||||||
const warehouseId = Number(row && row.warehouse_id || 0);
|
|
||||||
const waveId = Number(row && row.wave_id || 0);
|
|
||||||
if (!Number.isInteger(warehouseId) || warehouseId <= 0
|
|
||||||
|| !Number.isInteger(waveId) || waveId <= 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!warehouseWaveMap.has(warehouseId)) {
|
|
||||||
warehouseWaveMap.set(warehouseId, []);
|
|
||||||
}
|
|
||||||
warehouseWaveMap.get(warehouseId).push({
|
|
||||||
waveId,
|
|
||||||
waveNo: String(row && row.wave_no || '').trim(),
|
|
||||||
warehouseId,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const warehouseIds = Array.from(warehouseWaveMap.keys());
|
|
||||||
const closedWaves = [];
|
|
||||||
|
|
||||||
for (const warehouseId of warehouseIds) {
|
|
||||||
const waves = warehouseWaveMap.get(warehouseId);
|
|
||||||
let currentTableName = '';
|
|
||||||
try {
|
|
||||||
const factory = ctx.model && ctx.model.OrderDeliveryFactory;
|
|
||||||
if (!factory || typeof factory.generateTableName !== 'function') {
|
|
||||||
throw new Error('订单工厂不可用');
|
|
||||||
}
|
|
||||||
currentTableName = factory.generateTableName(warehouseId, 'current');
|
|
||||||
} catch (error) {
|
|
||||||
ctx.logger.warn(`[wave-batch-closure] 生成仓库 ${warehouseId} 订单表名失败,跳过: ${error.message}`);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 分批查询待处理表中仍存在订单的波次
|
|
||||||
const existingWaveIds = new Set();
|
|
||||||
let warehouseQueryFailed = false;
|
|
||||||
for (let offset = 0; offset < waves.length; offset += WAVE_ID_BATCH_SIZE) {
|
|
||||||
const batchWaves = waves.slice(offset, offset + WAVE_ID_BATCH_SIZE);
|
|
||||||
const batchWaveIds = batchWaves.map(item => item.waveId);
|
|
||||||
try {
|
|
||||||
const existingRows = await ctx.model.query(
|
|
||||||
`SELECT DISTINCT wave_id
|
|
||||||
FROM ${currentTableName}
|
|
||||||
WHERE wave_id IN (:waveIds)`,
|
|
||||||
{
|
|
||||||
replacements: { waveIds: batchWaveIds },
|
|
||||||
type: ctx.model.QueryTypes.SELECT,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
for (const row of (Array.isArray(existingRows) ? existingRows : [])) {
|
|
||||||
const waveId = Number(row && row.wave_id || 0);
|
|
||||||
if (Number.isInteger(waveId) && waveId > 0) {
|
|
||||||
existingWaveIds.add(waveId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
warehouseQueryFailed = true;
|
|
||||||
ctx.logger.warn(`[wave-batch-closure] 查询仓库 ${warehouseId} 待处理表失败,跳过该仓库: ${error.message}`);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (warehouseQueryFailed) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const finishedWaves = waves.filter(item => !existingWaveIds.has(item.waveId));
|
|
||||||
if (finishedWaves.length > 0) {
|
|
||||||
closedWaves.push(...finishedWaves);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const closedWaveIds = closedWaves.map(item => item.waveId);
|
|
||||||
const candidateCount = Array.from(warehouseWaveMap.values()).reduce((sum, waves) => sum + waves.length, 0);
|
|
||||||
|
|
||||||
if (!dryRun && closedWaveIds.length > 0) {
|
|
||||||
for (let offset = 0; offset < closedWaveIds.length; offset += WAVE_ID_BATCH_SIZE) {
|
|
||||||
const batchWaveIds = closedWaveIds.slice(offset, offset + WAVE_ID_BATCH_SIZE);
|
|
||||||
await ctx.model.query(
|
|
||||||
`UPDATE wms_wave_batch
|
|
||||||
SET wave_status = :closedStatus,
|
|
||||||
processed_orders = total_orders,
|
|
||||||
check_time = NOW(),
|
|
||||||
update_time = NOW()
|
|
||||||
WHERE wave_id IN (:waveIds)
|
|
||||||
AND wave_status IN (:waveStatuses)
|
|
||||||
AND total_orders > 0`,
|
|
||||||
{
|
|
||||||
replacements: {
|
|
||||||
closedStatus: CLOSED_WAVE_STATUS,
|
|
||||||
waveIds: batchWaveIds,
|
|
||||||
waveStatuses: ACTIVE_WAVE_STATUSES,
|
|
||||||
},
|
|
||||||
type: ctx.model.QueryTypes.UPDATE,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = {
|
|
||||||
dryRun,
|
|
||||||
candidate_count: candidateCount,
|
|
||||||
closed_count: closedWaves.length,
|
|
||||||
warehouse_ids: warehouseIds,
|
|
||||||
closed_waves: closedWaves,
|
|
||||||
duration_ms: Date.now() - startedAt,
|
|
||||||
};
|
|
||||||
|
|
||||||
if (closedWaves.length > 0) {
|
|
||||||
ctx.logger.info(
|
|
||||||
`[wave-batch-closure] 波次终结结果 dryRun=${dryRun} closed=${closedWaves.length}/${candidateCount} waves=${closedWaveIds.join(',')}`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = WaveBatchClosureService;
|
|
||||||
@ -1,120 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 将 wms_wave_batch.item_detail_machine 列从 VARCHAR(1024) 改为 TEXT。
|
|
||||||
*
|
|
||||||
* 背景:
|
|
||||||
* buildMachineStructureToken 生成的结构标识为
|
|
||||||
* `v1|item_part_type|item_part|distinguish_express|logistics_name|item_snapshot_key`,
|
|
||||||
* 其中 item_part 与 item_snapshot_key 均经 encodeURIComponent 编码,
|
|
||||||
* 多商品订单下编码后的长度可能远超 1024,抓取分组 INSERT 时报
|
|
||||||
* "Data too long for column 'item_detail_machine' at row 1"。
|
|
||||||
*
|
|
||||||
* 变更:
|
|
||||||
* 1. wms_wave_batch.item_detail_machine: VARCHAR(1024) → TEXT
|
|
||||||
* 2. 索引 idx_wave_item_machine_prefix 维持前缀索引
|
|
||||||
* (item_detail_machine(191)),TEXT 列前缀索引仍合法;
|
|
||||||
* 若存量环境存在全列索引则先删除。
|
|
||||||
* 3. 模型定义同步改为 TEXT(app/model/wave_batch.js)。
|
|
||||||
*/
|
|
||||||
|
|
||||||
const TABLE_NAME = 'wms_wave_batch';
|
|
||||||
const COLUMN_NAME = 'item_detail_machine';
|
|
||||||
const INDEX_NAME = 'idx_wave_item_machine_prefix';
|
|
||||||
|
|
||||||
async function hasColumn(queryInterface, tableName, columnName) {
|
|
||||||
const [ columns ] = await queryInterface.sequelize.query(
|
|
||||||
`
|
|
||||||
SELECT COLUMN_NAME
|
|
||||||
FROM INFORMATION_SCHEMA.COLUMNS
|
|
||||||
WHERE TABLE_SCHEMA = DATABASE()
|
|
||||||
AND TABLE_NAME = :tableName
|
|
||||||
AND COLUMN_NAME = :columnName
|
|
||||||
`,
|
|
||||||
{ replacements: { tableName, columnName } }
|
|
||||||
);
|
|
||||||
|
|
||||||
return (Array.isArray(columns) ? columns : []).length > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function listColumnIndexes(queryInterface, tableName, columnName) {
|
|
||||||
const [ rows ] = await queryInterface.sequelize.query(
|
|
||||||
`
|
|
||||||
SELECT DISTINCT INDEX_NAME, SUB_PART
|
|
||||||
FROM INFORMATION_SCHEMA.STATISTICS
|
|
||||||
WHERE TABLE_SCHEMA = DATABASE()
|
|
||||||
AND TABLE_NAME = :tableName
|
|
||||||
AND COLUMN_NAME = :columnName
|
|
||||||
`,
|
|
||||||
{ replacements: { tableName, columnName } }
|
|
||||||
);
|
|
||||||
|
|
||||||
return Array.isArray(rows) ? rows : [];
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
up: async queryInterface => {
|
|
||||||
if (!(await hasColumn(queryInterface, TABLE_NAME, COLUMN_NAME))) {
|
|
||||||
console.log(`[migrate] ${TABLE_NAME}.${COLUMN_NAME} 列不存在,跳过`);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── 1. 全列索引对 TEXT 无效(无前缀),先删除存量全列索引 ──
|
|
||||||
const existingIndexes = await listColumnIndexes(queryInterface, TABLE_NAME, COLUMN_NAME);
|
|
||||||
for (const idx of existingIndexes) {
|
|
||||||
const indexName = String(idx.INDEX_NAME || '').trim();
|
|
||||||
const subPart = idx.SUB_PART === null || idx.SUB_PART === undefined
|
|
||||||
? null
|
|
||||||
: Number(idx.SUB_PART);
|
|
||||||
if (!indexName || subPart) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
await queryInterface.removeIndex(TABLE_NAME, indexName);
|
|
||||||
console.log(`[migrate] 已移除全列索引 ${indexName}(TEXT 列要求前缀索引)`);
|
|
||||||
} catch (e) {
|
|
||||||
const msg = String(e && e.message || '');
|
|
||||||
if (!msg.includes('check that it exists') && !msg.includes('exist')) {
|
|
||||||
console.warn(`[migrate] 移除全列索引 ${indexName} 时出现非预期错误: ${msg}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── 2. 修改列类型为 TEXT ──
|
|
||||||
await queryInterface.sequelize.query(
|
|
||||||
`ALTER TABLE \`${TABLE_NAME}\` MODIFY \`${COLUMN_NAME}\` TEXT NULL COMMENT '抓取结构token:v1|item_part_type|item_part|distinguish_express|logistics_name|item_snapshot_key'`
|
|
||||||
);
|
|
||||||
console.log(`[migrate] ${TABLE_NAME}.${COLUMN_NAME} VARCHAR(1024) → TEXT`);
|
|
||||||
|
|
||||||
// ── 3. 确保前缀索引存在 ──
|
|
||||||
const remainingIndexes = await listColumnIndexes(queryInterface, TABLE_NAME, COLUMN_NAME);
|
|
||||||
if (remainingIndexes.length === 0) {
|
|
||||||
try {
|
|
||||||
await queryInterface.sequelize.query(
|
|
||||||
`ALTER TABLE \`${TABLE_NAME}\` ADD INDEX \`${INDEX_NAME}\` (\`${COLUMN_NAME}\`(191))`
|
|
||||||
);
|
|
||||||
console.log(`[migrate] 已创建前缀索引 ${INDEX_NAME}(${COLUMN_NAME}(191))`);
|
|
||||||
} catch (e) {
|
|
||||||
const msg = String(e && e.message || '');
|
|
||||||
if (!msg.includes('Duplicate')) {
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
console.log(`[migrate] 前缀索引 ${INDEX_NAME} 已存在,跳过`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
down: async queryInterface => {
|
|
||||||
if (!(await hasColumn(queryInterface, TABLE_NAME, COLUMN_NAME))) {
|
|
||||||
console.log(`[migrate:down] ${TABLE_NAME}.${COLUMN_NAME} 列不存在,跳过`);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 注意:若已有数据超过 1024 字符,回滚会失败,需先人工截断数据
|
|
||||||
await queryInterface.sequelize.query(
|
|
||||||
`ALTER TABLE \`${TABLE_NAME}\` MODIFY \`${COLUMN_NAME}\` VARCHAR(1024) NULL COMMENT '抓取结构token:v1|item_part_type|item_part|distinguish_express|logistics_name|item_snapshot_key'`
|
|
||||||
);
|
|
||||||
console.log(`[migrate:down] ${TABLE_NAME}.${COLUMN_NAME} TEXT → VARCHAR(1024)`);
|
|
||||||
},
|
|
||||||
};
|
|
||||||
@ -1,236 +1,4 @@
|
|||||||
[
|
[
|
||||||
{
|
|
||||||
"version": "2026.08.21-index.searchSpaces-batch-search",
|
|
||||||
"date": "2026-08-21",
|
|
||||||
"type": "added",
|
|
||||||
"summary": "新增 index.searchSpaces 批量库位查询接口:keywords 传入字符串数组,逐项按当前仓库上下文模糊查询(space_code/custom_barcode/custom_name,每项最多 50 条),结果按传入顺序以二维数组返回,无记录对应项返回空数组。",
|
|
||||||
"methods": [
|
|
||||||
"index.searchSpaces"
|
|
||||||
],
|
|
||||||
"notes": [
|
|
||||||
"app/service/systems/space.js 抽取 _searchByKeyword 私有查询方法(searchSpace 与 searchSpaces 共用同一查询口径),新增 searchSpaces 并行查询每个关键字并保持传入顺序输出,无记录项返回 []",
|
|
||||||
"app/service/systemMethods/index.js 新增 searchSpaces 出口方法,并加入 _noNeedRight/_noNeedAuth 白名单(与 searchSpace 一致,免鉴权免权限、需登录)",
|
|
||||||
"同步更新 methods/system.json 与 AI_METHOD_ROUTING.md"
|
|
||||||
],
|
|
||||||
"module": "index"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"version": "2026.08.20-order.wave.matched-count-same-express-split",
|
|
||||||
"date": "2026-08-20",
|
|
||||||
"type": "fixed",
|
|
||||||
"summary": "order.wave.waveStrategyList 的 matched_order_count_filtered 计数口径与按策略抓取保持一致:require_same_express=1 的策略按「结构(items_hash)+快递」分组计数并应用 min/max_same_structure,不再仅按结构分组统计,避免列表显示有命中订单但 waveStrategyFetchAdmin 实际抓取为 0 的口径不一致。",
|
|
||||||
"methods": [
|
|
||||||
"order.wave.waveStrategyList"
|
|
||||||
],
|
|
||||||
"notes": [
|
|
||||||
"app/service/systemMethods/order/wave.js getWaveStrategyMatchedOrderCountFilteredMap 改为接收策略行数组并按 require_same_express 拆分两类计数查询:同快递策略按 items_hash+快递(sys_logistics_code>logistics_code>logistics_name COALESCE 口径)分组,其余仅按 items_hash 分组;max_same_structure<=0 视为不设上限,与抓取候选 SQL 归一化一致;调用方 waveStrategyList 改传当前页策略行 list",
|
|
||||||
"同步更新 methods/system.json 中 matched_order_count_filtered 字段描述"
|
|
||||||
],
|
|
||||||
"module": "order"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"version": "2026.08.20-pick.waveClaimScan-print-gate",
|
|
||||||
"date": "2026-08-20",
|
|
||||||
"type": "enhanced",
|
|
||||||
"summary": "pick.waveClaimScan 新增波次打印校验:整波领料前检查波次下全部订单 print_status,存在未打印订单(print_status != fin)时返回 400「波次未打印,禁止领料」(data 含 wave_id、wave_no、unprinted_order_count、total_order_count),波次全部打印后才允许将订单 claim_status 置为 fin;已全部领料幂等结果优先返回,不受打印校验拦截。",
|
|
||||||
"methods": [
|
|
||||||
"pick.waveClaimScan"
|
|
||||||
],
|
|
||||||
"notes": [
|
|
||||||
"app/service/systemMethods/pick.js waveClaimScan 波次订单查询 attributes 增加 print_status,already_claimed 幂等判断之后插入打印校验:unprinted_order_count > 0 时 fail 400「波次未打印,禁止领料」",
|
|
||||||
"同步更新 methods/system.json 中 pick.waveClaimScan 的 description 与 400 错误说明"
|
|
||||||
],
|
|
||||||
"module": "pick"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"version": "2026.08.20-pick.waveClaimScan-source-gate",
|
|
||||||
"date": "2026-08-20",
|
|
||||||
"type": "enhanced",
|
|
||||||
"summary": "pick.waveClaimScan 整波领料资格判定收敛为仅普通波次(wms_wave_batch.source=0)生效:符合时将该波次下全部未领单订单 claim_status 置为 fin 并返回 wave_id/wave_no 与领单说明;策略抓取波次(source=1/2)返回「该波次为抓取波次,无需领料」(data 含 no_claim_needed=true、wave_id、wave_no);波次已全部领料返回 already_claimed 并提示「该波次已领料,无需重复领取」;面单号无记录/订单不在待处理订单表返回 404 无记录提示。",
|
|
||||||
"methods": [
|
|
||||||
"pick.waveClaimScan"
|
|
||||||
],
|
|
||||||
"notes": [
|
|
||||||
"app/service/systemMethods/pick.js waveClaimScan 资格判定由(大团购 wave_type=1 且 pick_mode=5 / 非抓取散单 wave_type=2 且 source=0)改为仅按 source 判定:source=0 全部支持整波领料,source∈{1,2} 返回抓取波次无需领料并携带 no_claim_needed=true、wave_id、wave_no,其余返回不支持提示;already_claimed tip 改为「该波次已领料,无需重复领取」",
|
|
||||||
"app/dict/businessDict.js OPERATION_CODE 补记 ORDER_WAVE_CLAIM:'领取波次'",
|
|
||||||
"同步更新 methods/system.json 中 pick.waveClaimScan 的 description/400/404 错误说明"
|
|
||||||
],
|
|
||||||
"module": "pick"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"version": "2026.08.19-print-custom-area-stock-merge",
|
|
||||||
"date": "2026-08-19",
|
|
||||||
"type": "fixed",
|
|
||||||
"summary": "修复打印自定义区同库位不同商品被合并为一行的问题:拣货明细聚合键由「库位」改为「库位+stock_id」复合键,仅同一库位同一商品才合并数量;stock_id 缺失时依次回退 order_item_id、商品名称+条码,无法识别商品身份时不再跨行合并。",
|
|
||||||
"methods": [
|
|
||||||
"order.print.getOrderPrintData",
|
|
||||||
"order.print.getWavePlatformPrintData",
|
|
||||||
"order.print.getPrintDataByWaybillCodes"
|
|
||||||
],
|
|
||||||
"notes": [
|
|
||||||
"app/service/systems/order_print.js buildPrintOrderRowMapWithPicking 阶段五聚合改为 buildPrintItemAggregationKey 复合键(pick_location::stock:stock_id),同库位不同商品保持独立行,数量/条码不再串;stock_id 字段延迟到聚合完成后才删除,避免污染 items JSON"
|
|
||||||
],
|
|
||||||
"module": "order"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"version": "2026.08.19-pick.claim-prompt-refine",
|
|
||||||
"date": "2026-08-19",
|
|
||||||
"type": "enhanced",
|
|
||||||
"summary": "领料提示文案细化:pick.query 领单前置校验拦截时直接提示「订单未领料,请先领料后再拣货」;pick.waveClaimScan 对抓取的波次(团购小波次 pick_mode=1、策略抓取散单波次 source=1/2)返回「该波次为抓取波次,无需领料」提示(失败 data 新增 no_claim_needed=true),其余未知类型保留通用不支持提示。",
|
|
||||||
"methods": [
|
|
||||||
"pick.query",
|
|
||||||
"pick.waveClaimScan"
|
|
||||||
],
|
|
||||||
"notes": [
|
|
||||||
"app/service/systemMethods/pick.js query 领单前置校验拦截文案由「该波次尚未领单,请先整波领单后再拣货」改为「订单未领料,请先领料后再拣货」,action=wave_claim 等失败 data 字段不变",
|
|
||||||
"app/service/systemMethods/pick.js waveClaimScan 资格判定失败时细分提示:抓取波次(wave_type=2 且 source∈{1,2},或 wave_type=1 且 pick_mode=1)返回「该波次为抓取波次,无需领料」并携带 no_claim_needed=true;其他未知类型保留「当前波次类型不支持整波领单」",
|
|
||||||
"同步更新 methods/system.json 中 pick.query 与 pick.waveClaimScan 的 description/400 错误说明"
|
|
||||||
],
|
|
||||||
"module": "pick"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"version": "2026.08.19-pick.query-wave-claim-gate",
|
|
||||||
"date": "2026-08-19",
|
|
||||||
"type": "enhanced",
|
|
||||||
"summary": "pick.query 新增领单前置校验:扫描命中的波次属于大团购(pick_mode=5)或非抓取散单(wms_wave_batch.source=0 普通波次)时,若波次内存在未领单订单(claim_status != fin)则返回 400 并携带 action=wave_claim 提示先整波领单(pick.waveClaimScan),中止拣货任务创建;已全部领单则继续原流程。",
|
|
||||||
"methods": [
|
|
||||||
"pick.query"
|
|
||||||
],
|
|
||||||
"notes": [
|
|
||||||
"app/service/systemMethods/pick.js query 在解析目标波次后、活动任务去重前插入领单校验:复用 getWavePickModeByWaveId 与 wms_wave_batch.source 判定波次类型(大团购=wave_type 1 且 pick_mode 5;非抓取散单=wave_type 2 且 source 0),查询波次订单 claim_status,存在未领单订单时 fail 400(data 含 action=wave_claim、wave_id、wave_no、wave_type、wave_source、pick_mode、unclaimed_order_count、total_order_count)",
|
|
||||||
"同步更新 methods/system.json 中 pick.query 的 description 与 400 错误说明"
|
|
||||||
],
|
|
||||||
"module": "pick"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"version": "2026.08.19-pick.waveClaimScan",
|
|
||||||
"date": "2026-08-19",
|
|
||||||
"type": "enhanced",
|
|
||||||
"summary": "新增 pick.waveClaimScan 整波领单接口:PDA 扫描波次内一个面单号后,针对大团购(pick_mode=5 团购大波次)与非抓取的散单(wms_wave_batch.source=0 普通波次)将该波次下全部订单 claim_status 置为 fin(领单完成),并写入 ORDER_WAVE_CLAIM 订单操作日志;团购小波次与策略抓取散单波次不支持整波领单,返回 400;波次已全部领单时返回 already_claimed 幂等结果。",
|
|
||||||
"methods": [
|
|
||||||
"pick.waveClaimScan"
|
|
||||||
],
|
|
||||||
"notes": [
|
|
||||||
"app/service/systemMethods/pick.js 新增 waveClaimScan:面单号定位订单(wms_order_express.waybill_code)→ 订单定位波次 → 读取 wms_wave_batch(wave_type/source)与拣货任务 pick_mode 判定资格(大团购=wave_type 1 且 pick_mode 5;非抓取散单=wave_type 2 且 source 0)→ 整波订单 claim_status='fin',并新增 getWavePickModeByWaveId 查询关联拣货模式",
|
|
||||||
"app/service/systemMethods/pick.js 鉴权配置:waveClaimScan 加入 _noNeedRight/_noNeedAuth(免权限、免仓库有效期校验),保留登录校验与请求日志",
|
|
||||||
"app/dict/businessDict.js OPERATION_CODE 新增 ORDER_WAVE_CLAIM:'领取波次'",
|
|
||||||
"同步更新 methods/system.json 中 pick.waveClaimScan 接口文档"
|
|
||||||
],
|
|
||||||
"module": "pick"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"version": "2026.08.19-manual-order-stock-store-guard",
|
|
||||||
"date": "2026-08-19",
|
|
||||||
"type": "fixed",
|
|
||||||
"summary": "手工单(order.pendingOrder.createOrder)新增库存归属货主校验:item_id 直接传仓库 stock_id 时,校验 wms_stock_warehouse.store_id 与订单货主 store_id 一致,跨货主传库存将被拒绝,杜绝把其他货主库存挂在当前货主订单下。",
|
|
||||||
"methods": [
|
|
||||||
"order.pendingOrder.createOrder"
|
|
||||||
],
|
|
||||||
"notes": [
|
|
||||||
"app/service/systems/delivery_order.js addOrderLines 手工单分支(line.stockId)新增 StockWarehouse 归属校验,不一致时计入 errors 并跳过该行,错误文案:商品《xxx》编码《xxx》库存归属货主(store_id=…)与当前货主(store_id=…)不一致,无法创建订单",
|
|
||||||
"同步更新 methods/system.json 中 order.pendingOrder.createOrder 的 notes 说明"
|
|
||||||
],
|
|
||||||
"module": "order"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"version": "2026.08.19-wave-fallback-excluded-reason-cn-label",
|
|
||||||
"date": "2026-08-19",
|
|
||||||
"type": "enhanced",
|
|
||||||
"summary": "order.wave.waveStrategyFallbackOrderList 响应 excluded_reason 由英文枚举值改为中文标签:locked→已锁定、intercepted→已拦截、printed→已打印、no_match→未匹配策略。",
|
|
||||||
"methods": [
|
|
||||||
"order.wave.waveStrategyFallbackOrderList"
|
|
||||||
],
|
|
||||||
"notes": [
|
|
||||||
"app/service/systemMethods/order/wave.js 新增 WAVE_STRATEGY_FALLBACK_EXCLUDED_REASON_LABELS 常量并用于 buildWaveStrategyFallbackOrderListItem,判定优先级不变",
|
|
||||||
"同步更新 methods/system.json 中该接口 excluded_reason 字段与 list 说明"
|
|
||||||
],
|
|
||||||
"module": "order"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"version": "2026.08.19-wave-fallback-excluded-reason-lock-fix",
|
|
||||||
"date": "2026-08-19",
|
|
||||||
"type": "fixed",
|
|
||||||
"summary": "修复 order.wave.waveStrategyFallbackOrderList 所有行 excluded_reason 恒为 locked 的问题:列表行经 normalizeOrderListItem 后 lock_status 已归一化为 Y/N,原判断 lock_status !== 'none' 恒成立导致全部误标 locked;改为兼容归一化值(Y=锁定,N/none/空=未锁定)与原始值(warehouse/store 等),恢复 locked/intercepted/printed/no_match 的正确判定。",
|
|
||||||
"methods": [
|
|
||||||
"order.wave.waveStrategyFallbackOrderList"
|
|
||||||
],
|
|
||||||
"notes": [
|
|
||||||
"app/service/systemMethods/order/wave.js buildWaveStrategyFallbackOrderListItem 新增 lockStatus 归一化与 isLocked 判定(Y 或非 none/非 N 的原始值视为锁定),excluded_reason 优先级不变:locked > intercepted > printed > no_match"
|
|
||||||
],
|
|
||||||
"module": "order"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"version": "2026.08.19-order-list-wave-index-range-filter",
|
|
||||||
"date": "2026-08-19",
|
|
||||||
"type": "enhanced",
|
|
||||||
"summary": "订单列表 where 新增 wave_index 波次内序号范围查询入参:工作台订单列表(经 listByModule 的 9 个列表)与订单导出支持 wave_index 虚拟筛选(eq/in/gt/lt/ge/le/between/notbetween,between 要求 value 为长度 2 的数组);复核散单列表支持 wave_index between 与 wave_index_min/wave_index_max。",
|
|
||||||
"methods": [
|
|
||||||
"order.list",
|
|
||||||
"order.reviewOrder.list",
|
|
||||||
"order.pendingOrder.list",
|
|
||||||
"order.outboundOrder.list",
|
|
||||||
"order.expectionOrder.list",
|
|
||||||
"order.entrustOrder.list",
|
|
||||||
"order.deliveryOrder.list",
|
|
||||||
"order.deliveryExpectionOrder.list",
|
|
||||||
"order.archiveOrder.list",
|
|
||||||
"order.recheckOrder.recheckOrderList",
|
|
||||||
"order.recheckOrder.queryRecheckOrderSingleList"
|
|
||||||
],
|
|
||||||
"notes": [
|
|
||||||
"新增 app/model/order_wave_index.js 模型(wms_order_wave_index,timestamps=false),供副表条件查询",
|
|
||||||
"app/service/systemMethods/order/base.js 新增 extractWaveIndexVirtualFilter(从 where 提取 wave_index/waveIndex,兼容数值简写按 eq 处理)与 findOrderIdsByWaveIndexCondition(用 parseWhereConditions 解析条件后查副表得 order_id 集合);listByModule 在 stock_query 之后接入,命中为空时主查询结果为空",
|
|
||||||
"app/service/systems/order_export.js exportOrders 同样接入 wave_index 虚拟筛选,与列表 where 语义一致",
|
|
||||||
"app/service/systemMethods/order/recheckOrder.js queryRecheckOrderSingleList 新增 wave_index 筛选(between/gte/lte/eq 或 wave_index_min/wave_index_max),countSql 同步 LEFT JOIN wms_order_wave_index 保持总数一致",
|
|
||||||
"同步更新 methods/system.json 中 order.list 与复核列表 where 参数说明"
|
|
||||||
],
|
|
||||||
"module": "order"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"version": "2026.08.19-order-list-wave-index-join",
|
|
||||||
"date": "2026-08-19",
|
|
||||||
"type": "enhanced",
|
|
||||||
"summary": "所有订单列表统一联查 wms_order_wave_index 并输出 wave_index(波次内序号,无记录时降级为 0):覆盖 9 个工作台订单列表(order.list / reviewOrder.list / pendingOrder.list / outboundOrder.list / expectionOrder.list / entrustOrder.list / deliveryOrder.list / deliveryExpectionOrder.list / archiveOrder.list)、复核散单列表与波次策略兜底列表;订单导出(waybill/item 两种模式)新增「波次序号」列。",
|
|
||||||
"methods": [
|
|
||||||
"order.list",
|
|
||||||
"order.reviewOrder.list",
|
|
||||||
"order.pendingOrder.list",
|
|
||||||
"order.outboundOrder.list",
|
|
||||||
"order.expectionOrder.list",
|
|
||||||
"order.entrustOrder.list",
|
|
||||||
"order.deliveryOrder.list",
|
|
||||||
"order.deliveryExpectionOrder.list",
|
|
||||||
"order.archiveOrder.list",
|
|
||||||
"order.recheckOrder.recheckOrderList",
|
|
||||||
"order.recheckOrder.queryRecheckOrderSingleList",
|
|
||||||
"order.wave.waveStrategyFallbackOrderList"
|
|
||||||
],
|
|
||||||
"notes": [
|
|
||||||
"app/service/systemMethods/order/base.js 新增 attachOrderWaveIndex:按列表行 id 批量查询 wms_order_wave_index(warehouse_id + order_id,命中唯一索引),无记录或查询异常时降级为 0 并告警;listByModule 在 attachOrderExpressNumbers 之后接入,统一覆盖全部工作台订单列表",
|
|
||||||
"app/service/systemMethods/order/wave.js waveStrategyFallbackOrderList 接入 attachOrderWaveIndex,buildWaveStrategyFallbackOrderListItem 输出 wave_index(默认 0)",
|
|
||||||
"app/service/systemMethods/order/recheckOrder.js queryRecheckOrderSingleList 列表 SQL 增加 LEFT JOIN wms_order_wave_index(warehouse_id + order_id),响应行新增 wave_index;recheckOrderList 散单分支同源生效",
|
|
||||||
"app/service/systems/order_export.js exportOrders 接入 attachOrderWaveIndex,ORDER_EXPORT_COLUMNS / ORDER_EXPORT_ITEM_COLUMNS 在波次号后新增「波次序号」列,mapOrderExportRow commonFields 新增 wave_index",
|
|
||||||
"同步更新 methods/system.json 中上述接口的 response 字段说明"
|
|
||||||
],
|
|
||||||
"module": "order"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"version": "2026.08.19-recheckOrder.confirmIntercept-ids",
|
|
||||||
"date": "2026-08-19",
|
|
||||||
"type": "enhanced",
|
|
||||||
"summary": "order.recheckOrder.confirmIntercept 入参由单值 order_id 改为批量 ids:支持数组或以逗号分隔的字符串(兼容 id/order_id/orderId 单值写法),批量确认拦截,返回 success/failed 列表与 success_count/failed_count 计数;单个订单失败不再阻断整体,未找到订单与更新失败订单记录在 failed 列表",
|
|
||||||
"methods": [
|
|
||||||
"order.recheckOrder.confirmIntercept"
|
|
||||||
],
|
|
||||||
"notes": [
|
|
||||||
"app/service/systemMethods/order/recheckOrder.js confirmIntercept:用 base.normalizeOrderIds 解析 ids(兼容 ids/id/order_id/orderId),findAll 批量查询后逐订单执行拦截主流程(intercept_status=intercepted_at_warehouse、step=4、outbound_status=fin,运单标记 is_back/is_intercept='Y',释放储位分配与订单锁,写入 ORDER_INTERCEPT_CONFIRM 操作日志),未找到订单与处理异常订单记录 failed 不抛错,仅 ids 全部无效时 400「订单ID列表不能为空」",
|
|
||||||
"确认拦截前置校验:仅拦截发起中状态(requested/requesting/intercepting,历史值 intercepted 兼容)允许确认;未发起拦截(none/空)的订单直接静默跳过不参与处理,已确认拦截(intercepted_at_warehouse)订单跳过避免重复副作用并记录 failed「订单已确认拦截」,其余非可确认状态(intercepted_in_transit/returning/returned/delivered_by_mistake/timeout/cancelled/failed/exception)记录 failed「订单拦截状态不允许确认拦截: {状态}」;更新 SQL where 同时限定 intercept_status 白名单(CONFIRMABLE_INTERCEPT_STATUSES),防止查询后状态被并发修改导致误更新",
|
|
||||||
"售后工单+快递群通知由原每订单调用改为按成功订单 ID 汇总后统一调用一次 afterSale.createInterceptWorkOrdersAndNotify,失败仅告警",
|
|
||||||
"返回结构由单对象改为 { success, failed, success_count, failed_count },success 每项保持 order_id/order_no/intercept_status/updated_at,failed 每项含 order_id/delivery_order_code/reason",
|
|
||||||
"同步更新 methods/system.json 中该接口 params(ids)、response 与 errors 文档"
|
|
||||||
],
|
|
||||||
"module": "order.recheckOrder"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"version": "2026.08.18-order-list-lock-status-filter-doc",
|
"version": "2026.08.18-order-list-lock-status-filter-doc",
|
||||||
"date": "2026-08-18",
|
"date": "2026-08-18",
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
{
|
{
|
||||||
"module": "system",
|
"module": "system",
|
||||||
"description": "系统接口标准入口,method 对应系统内置方法,全部使用 POST 请求,参数统一放在 body 内",
|
"description": "系统接口标准入口,method 对应系统内置方法,全部使用 POST 请求,参数统一放在 body 内",
|
||||||
"version": "0.3.32",
|
"version": "0.3.29",
|
||||||
"updatedAt": "2026-08-19",
|
"updatedAt": "2026-08-18",
|
||||||
"headers": [
|
"headers": [
|
||||||
{
|
{
|
||||||
"name": "platform",
|
"name": "platform",
|
||||||
@ -949,79 +949,6 @@
|
|||||||
],
|
],
|
||||||
"errors": []
|
"errors": []
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"method": "index.searchSpaces",
|
|
||||||
"description": "按当前仓库上下文批量搜索库位(使用 ctx.user.store_id;对每个关键字在 location_space 表中按 space_code/custom_barcode/custom_name 做模糊匹配,结果按传入顺序返回)",
|
|
||||||
"isNeedAuth": false,
|
|
||||||
"isNeedLogin": true,
|
|
||||||
"headers": [
|
|
||||||
{
|
|
||||||
"name": "Authorization",
|
|
||||||
"type": "string",
|
|
||||||
"required": true,
|
|
||||||
"description": "Bearer token"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"params": [
|
|
||||||
{
|
|
||||||
"name": "keywords",
|
|
||||||
"type": "array",
|
|
||||||
"required": true,
|
|
||||||
"source": "body",
|
|
||||||
"description": "搜索关键字数组,每项对 space_code、custom_barcode、custom_name 做模糊匹配(%keyword%);非数组视为空数组"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"response": [
|
|
||||||
{
|
|
||||||
"name": "flag",
|
|
||||||
"type": "string",
|
|
||||||
"description": "全局调用结果标识,成功时为 success"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "code",
|
|
||||||
"type": "number",
|
|
||||||
"description": "业务状态码,200 表示成功"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "message",
|
|
||||||
"type": "string",
|
|
||||||
"description": "返回信息"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "data",
|
|
||||||
"type": "array",
|
|
||||||
"description": "库位列表的数组,与 keywords 一一对应;每项为库位数组(最多 50 条),无记录时对应项为空数组 []",
|
|
||||||
"children": [
|
|
||||||
{
|
|
||||||
"name": "id",
|
|
||||||
"type": "number",
|
|
||||||
"description": "库位 ID"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "space_code",
|
|
||||||
"type": "string",
|
|
||||||
"description": "库位编码"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "custom_barcode",
|
|
||||||
"type": "string",
|
|
||||||
"description": "库位自定义条码"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "custom_name",
|
|
||||||
"type": "string",
|
|
||||||
"description": "库位自定义名称"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "total",
|
|
||||||
"type": "number",
|
|
||||||
"description": "返回的分组数量(等于 keywords.length)"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"errors": []
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"method": "index.listInterfaceTypes",
|
"method": "index.listInterfaceTypes",
|
||||||
"description": "查询可用的接口类型列表(如奇门仓储、开放接口等)",
|
"description": "查询可用的接口类型列表(如奇门仓储、开放接口等)",
|
||||||
@ -1841,7 +1768,7 @@
|
|||||||
"type": "object",
|
"type": "object",
|
||||||
"required": false,
|
"required": false,
|
||||||
"source": "body",
|
"source": "body",
|
||||||
"description": "统一 where 条件对象;推荐使用 { operator, value, type } 标准结构,历史简写会自动标准化;禁止传入 warehouse_id / warehouseId。支持虚拟字段:buyer_message_has(覆盖 buyer_message/seller_message/remark 三个字段,任一有值即为有留言,value=true/false),express_numbers / waybill_codes(运单号筛选),wave_index(波次内序号筛选,联查 wms_order_wave_index,支持 eq/in/gt/lt/ge/le/between/notbetween,between 要求 value 为长度 2 的数组,如 {\"wave_index\":{\"operator\":\"between\",\"value\":[1,50]}})。"
|
"description": "统一 where 条件对象;推荐使用 { operator, value, type } 标准结构,历史简写会自动标准化;禁止传入 warehouse_id / warehouseId。支持虚拟字段:buyer_message_has(覆盖 buyer_message/seller_message/remark 三个字段,任一有值即为有留言,value=true/false),express_numbers / waybill_codes(运单号筛选)。"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "sort",
|
"name": "sort",
|
||||||
@ -1856,7 +1783,7 @@
|
|||||||
"name": "list",
|
"name": "list",
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"required": true,
|
"required": true,
|
||||||
"description": "订单列表(raw 行数据,字段字典见 <window>docs/order-workbench-list-api.md</window> 中的“订单列表 raw 字段字典”章节),本次新增 store_remark(货主备注)字段;wave_index(波次内序号,联查 wms_order_wave_index,无记录时为 0)。"
|
"description": "订单列表(raw 行数据,字段字典见 <window>docs/order-workbench-list-api.md</window> 中的“订单列表 raw 字段字典”章节),本次新增 store_remark(货主备注)字段。"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "pagination",
|
"name": "pagination",
|
||||||
@ -2742,7 +2669,7 @@
|
|||||||
"name": "list",
|
"name": "list",
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"required": true,
|
"required": true,
|
||||||
"description": "订单列表(raw 行数据,字段字典见 <window>docs/order-workbench-list-api.md</window> 中的“订单列表 raw 字段字典”章节),本次新增 store_remark(货主备注)字段;wave_index(波次内序号,联查 wms_order_wave_index,无记录时为 0)。"
|
"description": "订单列表(raw 行数据,字段字典见 <window>docs/order-workbench-list-api.md</window> 中的“订单列表 raw 字段字典”章节),本次新增 store_remark(货主备注)字段。"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "pagination",
|
"name": "pagination",
|
||||||
@ -3033,7 +2960,7 @@
|
|||||||
"name": "list",
|
"name": "list",
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"required": true,
|
"required": true,
|
||||||
"description": "订单列表(raw 行数据,字段字典见 <window>docs/order-workbench-list-api.md</window> 中的“订单列表 raw 字段字典”章节),本次新增 store_remark(货主备注)字段;wave_index(波次内序号,联查 wms_order_wave_index,无记录时为 0)。lock_status 字段统一输出为 Y/N:none(含空值)→ 'N',其余值(如 warehouse/store)→ 'Y'。"
|
"description": "订单列表(raw 行数据,字段字典见 <window>docs/order-workbench-list-api.md</window> 中的“订单列表 raw 字段字典”章节),本次新增 store_remark(货主备注)字段。lock_status 字段统一输出为 Y/N:none(含空值)→ 'N',其余值(如 warehouse/store)→ 'Y'。"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "pagination",
|
"name": "pagination",
|
||||||
@ -4247,7 +4174,6 @@
|
|||||||
],
|
],
|
||||||
"notes": [
|
"notes": [
|
||||||
"使用 item_id 直接匹配商品主键,不依赖外部系统商品同步;item_id 可通过 singleitem.synchronize 返回的 itemId 获取",
|
"使用 item_id 直接匹配商品主键,不依赖外部系统商品同步;item_id 可通过 singleitem.synchronize 返回的 itemId 获取",
|
||||||
"手工单 item_id 即仓库 stock_id(wms_stock_warehouse.id),系统会校验该库存记录归属货主与 store_id 一致,跨货主传库存将被拒绝(商品《xxx》库存归属货主与当前货主不一致)",
|
|
||||||
"province/city/area 为必填项,空值返回 400"
|
"province/city/area 为必填项,空值返回 400"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -6113,7 +6039,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"method": "order.recheckOrder.confirmIntercept",
|
"method": "order.recheckOrder.confirmIntercept",
|
||||||
"description": "确认拦截:通过订单 ID 列表批量匹配订单,将拦截状态更新为 intercepted_at_warehouse(仓库已拦截,step=4、outbound_status=fin),同步标记运单退回与拦截(is_back='Y', is_intercept='Y'),并释放储位分配(cancelAllocateStorage)与订单锁(lock_status=none)。仅拦截当前指定订单,不波及波次内其他订单。前置条件:订单必须处于拦截发起中状态(requested/requesting/intercepting,历史值 intercepted 兼容),未发起拦截(none/空)的订单直接静默跳过不参与处理,已确认拦截(intercepted_at_warehouse)及其它非可确认状态(intercepted_in_transit/returning/returned/delivered_by_mistake/timeout/cancelled/failed/exception)一律跳过并记录失败原因;更新 SQL 的 where 同时限定拦截状态白名单,防止并发修改导致误更新。支持部分失败:未找到的订单与处理失败的订单记录在 failed 列表并返回失败原因,其余订单继续处理。全部订单处理完后按成功订单 ID 汇总批量创建售后工单 + 通知快递群。每个订单操作成功后写入操作日志(ORDER_INTERCEPT_CONFIRM)。运单标记、储位释放、锁释放、工单创建、日志写入失败均不影响主流程。",
|
"description": "确认拦截:通过订单ID直接匹配订单,将其拦截状态更新为 intercepted_at_warehouse(仓库已拦截),同时释放储位分配(cancelAllocateStorage)与订单锁(lock_status=none)。仅拦截当前指定订单,不波及波次内其他订单。操作成功后写入操作日志(ORDER_INTERCEPT_CONFIRM)。储位释放、锁释放、日志写入失败均不影响主流程。",
|
||||||
"isNeedAuth": false,
|
"isNeedAuth": false,
|
||||||
"isNeedLogin": true,
|
"isNeedLogin": true,
|
||||||
"headers": [
|
"headers": [
|
||||||
@ -6126,83 +6052,53 @@
|
|||||||
],
|
],
|
||||||
"params": [
|
"params": [
|
||||||
{
|
{
|
||||||
"name": "ids",
|
"name": "order_id",
|
||||||
"type": "array<number>|string",
|
"type": "number",
|
||||||
"required": true,
|
"required": true,
|
||||||
"source": "body",
|
"source": "body",
|
||||||
"description": "订单 ID 列表,支持数组或以逗号分隔的字符串。兼容 id / order_id / orderId 单值写法"
|
"description": "订单 ID"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"response": [
|
"response": [
|
||||||
{
|
|
||||||
"name": "success",
|
|
||||||
"type": "array",
|
|
||||||
"required": true,
|
|
||||||
"description": "拦截成功的订单列表",
|
|
||||||
"children": [
|
|
||||||
{
|
{
|
||||||
"name": "order_id",
|
"name": "order_id",
|
||||||
"type": "number",
|
"type": "number",
|
||||||
|
"required": true,
|
||||||
"description": "订单 ID"
|
"description": "订单 ID"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "order_no",
|
"name": "order_no",
|
||||||
"type": "string",
|
"type": "string",
|
||||||
|
"required": true,
|
||||||
"description": "订单号(优先 delivery_order_code,其次 pre_delivery_order_code)"
|
"description": "订单号(优先 delivery_order_code,其次 pre_delivery_order_code)"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "intercept_status",
|
"name": "intercept_status",
|
||||||
"type": "string",
|
"type": "string",
|
||||||
|
"required": true,
|
||||||
"description": "拦截状态(固定为 'intercepted_at_warehouse')"
|
"description": "拦截状态(固定为 'intercepted_at_warehouse')"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "updated_at",
|
"name": "updated_at",
|
||||||
"type": "string",
|
"type": "string",
|
||||||
|
"required": true,
|
||||||
"description": "更新时间(ISO 字符串)"
|
"description": "更新时间(ISO 字符串)"
|
||||||
}
|
}
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "failed",
|
|
||||||
"type": "array",
|
|
||||||
"required": true,
|
|
||||||
"description": "拦截失败的订单列表",
|
|
||||||
"children": [
|
|
||||||
{
|
|
||||||
"name": "order_id",
|
|
||||||
"type": "number",
|
|
||||||
"description": "订单 ID"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "delivery_order_code",
|
|
||||||
"type": "string",
|
|
||||||
"description": "发货单号(订单存在时返回)"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "reason",
|
|
||||||
"type": "string",
|
|
||||||
"description": "失败原因(未找到对应订单 / 订单已确认拦截 / 订单拦截状态不允许确认拦截: xxx / 确认拦截失败: xxx);拦截状态为 none 的订单静默跳过,不进入 failed"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "success_count",
|
|
||||||
"type": "number",
|
|
||||||
"required": true,
|
|
||||||
"description": "成功数量"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "failed_count",
|
|
||||||
"type": "number",
|
|
||||||
"required": true,
|
|
||||||
"description": "失败数量"
|
|
||||||
}
|
|
||||||
],
|
],
|
||||||
"errors": [
|
"errors": [
|
||||||
{
|
{
|
||||||
"code": 400,
|
"code": 400,
|
||||||
"message": "订单ID列表不能为空",
|
"message": "order_id 无效",
|
||||||
"description": "ids 为空或全部无效(非正整数)时返回"
|
"description": "order_id 无效(为空或非正整数)"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"code": 404,
|
||||||
|
"message": "未找到对应订单"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"code": 500,
|
||||||
|
"message": "拦截状态更新失败,请稍后重试",
|
||||||
|
"description": "数据库更新影响行数为 0 时返回"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -6297,7 +6193,7 @@
|
|||||||
"type": "object",
|
"type": "object",
|
||||||
"required": false,
|
"required": false,
|
||||||
"source": "body",
|
"source": "body",
|
||||||
"description": "筛选条件。散单模式支持 keyword(运单号/订单号模糊搜索)、wave_no(精确匹配)、recheck_status、pick_status、wave_index(波次内序号范围筛选,如 {\"operator\":\"between\",\"value\":[起,止]},或 wave_index_min / wave_index_max);团购模式支持 wave_no(模糊搜索)、wave_type、wave_status"
|
"description": "筛选条件。散单模式支持 keyword(运单号/订单号模糊搜索)、wave_no(精确匹配)、recheck_status、pick_status;团购模式支持 wave_no(模糊搜索)、wave_type、wave_status"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "pagination",
|
"name": "pagination",
|
||||||
@ -6312,7 +6208,7 @@
|
|||||||
"name": "list",
|
"name": "list",
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"required": true,
|
"required": true,
|
||||||
"description": "散单模式(list_type=single):订单数组,每项含 order_id、delivery_order_code、order_type、wave_id、wave_no、pick_status、recheck_status、shop_nick、logistics_name、items_count、items_total、wave_index、status、create_at、pick_time、recheck_time。团购模式(list_type=group):波次汇总数组,每项含 wave_id、wave_no、wave_type、wave_status、total_orders、processed_orders、creator、create_time、update_time、order_count、reviewed_count、unreviewed_count、review_assignment_status(unreviewed/partially_reviewed/reviewed)"
|
"description": "散单模式(list_type=single):订单数组,每项含 order_id、delivery_order_code、order_type、wave_id、wave_no、pick_status、recheck_status、shop_nick、logistics_name、items_count、items_total、status、create_at、pick_time、recheck_time。团购模式(list_type=group):波次汇总数组,每项含 wave_id、wave_no、wave_type、wave_status、total_orders、processed_orders、creator、create_time、update_time、order_count、reviewed_count、unreviewed_count、review_assignment_status(unreviewed/partially_reviewed/reviewed)"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "pagination",
|
"name": "pagination",
|
||||||
@ -6803,7 +6699,7 @@
|
|||||||
"type": "object",
|
"type": "object",
|
||||||
"required": false,
|
"required": false,
|
||||||
"source": "body",
|
"source": "body",
|
||||||
"description": "筛选条件。支持 keyword(运单号/订单号模糊搜索)、wave_no(精确匹配)、recheck_status、pick_status、wave_index(波次内序号范围筛选,如 {\"operator\":\"between\",\"value\":[起,止]},或 wave_index_min / wave_index_max)"
|
"description": "筛选条件。支持 keyword(运单号/订单号模糊搜索)、wave_no(精确匹配)、recheck_status、pick_status"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "pagination",
|
"name": "pagination",
|
||||||
@ -6818,7 +6714,7 @@
|
|||||||
"name": "list",
|
"name": "list",
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"required": true,
|
"required": true,
|
||||||
"description": "散单复核订单列表,每项含 order_id、delivery_order_code、order_type、wave_id、wave_no、pick_status、recheck_status、shop_nick、logistics_name、items_count、items_total、items_weight、weight_type、waybill_code、wave_index、status、create_at、recheck_time"
|
"description": "散单复核订单列表,每项含 order_id、delivery_order_code、order_type、wave_id、wave_no、pick_status、recheck_status、shop_nick、logistics_name、items_count、items_total、items_weight、weight_type、waybill_code、status、create_at、recheck_time"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "pagination",
|
"name": "pagination",
|
||||||
@ -7337,7 +7233,7 @@
|
|||||||
{
|
{
|
||||||
"name": "matched_order_count_filtered",
|
"name": "matched_order_count_filtered",
|
||||||
"type": "number",
|
"type": "number",
|
||||||
"description": "按当前仓库且仅统计未在波次(step!=0)并满足同结构区间后的命中订单数;口径与抓取候选一致:require_same_express=1 时按「结构+快递」分组计数,否则仅按结构分组计数"
|
"description": "按当前仓库且仅统计未在波次(step!=0)并满足同结构区间后的命中订单数"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "next_fetch_order_count",
|
"name": "next_fetch_order_count",
|
||||||
@ -8529,7 +8425,7 @@
|
|||||||
"name": "list",
|
"name": "list",
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"required": true,
|
"required": true,
|
||||||
"description": "回退候选订单简要列表。数组内对象字段说明见 children;每行含 excluded_reason 中文标记:已锁定(lock_status 非 none)、已拦截、已打印、未匹配策略。",
|
"description": "回退候选订单简要列表。数组内对象字段说明见 children;每行含 excluded_reason 标记:locked=订单已锁定(lock_status 非 none)、intercepted=订单已拦截、printed=已完全打印、no_match=未匹配任何波次策略。",
|
||||||
"children": [
|
"children": [
|
||||||
{
|
{
|
||||||
"name": "id",
|
"name": "id",
|
||||||
@ -8591,15 +8487,10 @@
|
|||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "商品快照,格式示例:苹果*2|香蕉*3"
|
"description": "商品快照,格式示例:苹果*2|香蕉*3"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"name": "wave_index",
|
|
||||||
"type": "number",
|
|
||||||
"description": "波次内序号(联查 wms_order_wave_index,无记录时为 0)"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"name": "excluded_reason",
|
"name": "excluded_reason",
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "订单进入回退列表的原因(中文标签):已锁定(lock_status 非 none)/ 已拦截 / 已打印 / 未匹配策略"
|
"description": "订单进入回退列表的原因枚举:locked(已锁定,lock_status 非 none)/ intercepted(已拦截)/ printed(已完全打印)/ no_match(未匹配任何波次策略)"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -10464,7 +10355,7 @@
|
|||||||
"name": "list",
|
"name": "list",
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"required": true,
|
"required": true,
|
||||||
"description": "订单列表(raw 行数据,字段字典见 <window>docs/order-workbench-list-api.md</window> 中的“订单列表 raw 字段字典”章节);本次新增 wave_index(波次内序号,联查 wms_order_wave_index,无记录时为 0)。"
|
"description": "订单列表(raw 行数据,字段字典见 <window>docs/order-workbench-list-api.md</window> 中的“订单列表 raw 字段字典”章节)"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "pagination",
|
"name": "pagination",
|
||||||
@ -10712,7 +10603,7 @@
|
|||||||
"name": "list",
|
"name": "list",
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"required": true,
|
"required": true,
|
||||||
"description": "订单列表(raw 行数据,字段字典见 <window>docs/order-workbench-list-api.md</window> 中的“订单列表 raw 字段字典”章节),本次新增 store_remark(货主备注)字段;wave_index(波次内序号,联查 wms_order_wave_index,无记录时为 0)。"
|
"description": "订单列表(raw 行数据,字段字典见 <window>docs/order-workbench-list-api.md</window> 中的“订单列表 raw 字段字典”章节),本次新增 store_remark(货主备注)字段。"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "pagination",
|
"name": "pagination",
|
||||||
@ -10897,7 +10788,7 @@
|
|||||||
"name": "list",
|
"name": "list",
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"required": true,
|
"required": true,
|
||||||
"description": "订单列表(raw 行数据,字段字典见 <window>docs/order-workbench-list-api.md</window> 中的“订单列表 raw 字段字典”章节),本次新增 store_remark(货主备注)字段;wave_index(波次内序号,联查 wms_order_wave_index,无记录时为 0)。"
|
"description": "订单列表(raw 行数据,字段字典见 <window>docs/order-workbench-list-api.md</window> 中的“订单列表 raw 字段字典”章节),本次新增 store_remark(货主备注)字段。"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "pagination",
|
"name": "pagination",
|
||||||
@ -11035,7 +10926,7 @@
|
|||||||
"name": "list",
|
"name": "list",
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"required": true,
|
"required": true,
|
||||||
"description": "订单列表(raw 行数据,字段字典见 <window>docs/order-workbench-list-api.md</window> 中的“订单列表 raw 字段字典”章节),本次新增 store_remark(货主备注)字段;wave_index(波次内序号,联查 wms_order_wave_index,无记录时为 0)。"
|
"description": "订单列表(raw 行数据,字段字典见 <window>docs/order-workbench-list-api.md</window> 中的“订单列表 raw 字段字典”章节),本次新增 store_remark(货主备注)字段。"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "pagination",
|
"name": "pagination",
|
||||||
@ -11429,7 +11320,7 @@
|
|||||||
"name": "list",
|
"name": "list",
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"required": true,
|
"required": true,
|
||||||
"description": "订单列表(raw 行数据,字段字典见 <window>docs/order-workbench-list-api.md</window> 中的“订单列表 raw 字段字典”章节),本次新增 store_remark(货主备注)字段;wave_index(波次内序号,联查 wms_order_wave_index,无记录时为 0)。"
|
"description": "订单列表(raw 行数据,字段字典见 <window>docs/order-workbench-list-api.md</window> 中的“订单列表 raw 字段字典”章节),本次新增 store_remark(货主备注)字段。"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "pagination",
|
"name": "pagination",
|
||||||
@ -11573,7 +11464,7 @@
|
|||||||
"name": "list",
|
"name": "list",
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"required": true,
|
"required": true,
|
||||||
"description": "订单列表(raw 行数据,字段字典见 <window>docs/order-workbench-list-api.md</window> 中的“订单列表 raw 字段字典”章节),本次新增 store_remark(货主备注)字段;wave_index(波次内序号,联查 wms_order_wave_index,无记录时为 0)。"
|
"description": "订单列表(raw 行数据,字段字典见 <window>docs/order-workbench-list-api.md</window> 中的“订单列表 raw 字段字典”章节),本次新增 store_remark(货主备注)字段。"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "pagination",
|
"name": "pagination",
|
||||||
@ -18688,7 +18579,7 @@
|
|||||||
"list": [
|
"list": [
|
||||||
{
|
{
|
||||||
"method": "pick.query",
|
"method": "pick.query",
|
||||||
"description": "按 keyword(运单号或波次号)获取或创建当前用户的拣货任务:命中同用户活动任务返回 existing;无活动任务则创建并返回 created;若活动任务归属他人则返回冲突提示。新增领单前置校验:扫描命中的波次属于大团购(pick_mode=5)或非抓取散单(wms_wave_batch.source=0 普通波次)时,若波次内存在未领料订单(claim_status != fin)则返回 400 并携带 action=wave_claim 提示「订单未领料,请先领料后再拣货」(pick.waveClaimScan),中止拣货任务创建。",
|
"description": "按 keyword(运单号或波次号)获取或创建当前用户的拣货任务:命中同用户活动任务返回 existing;无活动任务则创建并返回 created;若活动任务归属他人则返回冲突提示。",
|
||||||
"isNeedAuth": false,
|
"isNeedAuth": false,
|
||||||
"isNeedLogin": true,
|
"isNeedLogin": true,
|
||||||
"headers": [
|
"headers": [
|
||||||
@ -18731,7 +18622,7 @@
|
|||||||
"errors": [
|
"errors": [
|
||||||
{
|
{
|
||||||
"code": 400,
|
"code": 400,
|
||||||
"message": "参数错误或目标波次不满足建任务条件(如 keyword 为空、缺少仓库上下文、目标波次信息不完整、散单波次无可用订单);大团购/非抓取散单波次未领料时中止建任务并提示「订单未领料,请先领料后再拣货」(失败 data 含 action=wave_claim、wave_id、wave_no、wave_type、wave_source、pick_mode、unclaimed_order_count、total_order_count)。"
|
"message": "参数错误或目标波次不满足建任务条件(如 keyword 为空、缺少仓库上下文、目标波次信息不完整、散单波次无可用订单)。"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"code": 401,
|
"code": 401,
|
||||||
@ -19551,116 +19442,6 @@
|
|||||||
"message": "提交失败。"
|
"message": "提交失败。"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
|
||||||
{
|
|
||||||
"method": "pick.waveClaimScan",
|
|
||||||
"description": "扫描面单号领取整波(领料)。按面单号(运单号)定位待处理订单表中的订单后反查订单所在波次,仅对普通波次(wms_wave_batch.source=0,含团购/散单)支持整波领料:命中后将该波次下全部未领单订单 claim_status 置为 fin(领料完成)并写入 ORDER_WAVE_CLAIM 订单操作日志,返回波次ID与波次编码;波次下存在未打印订单(print_status != fin)时返回 400「波次未打印,禁止领料」(data 含 wave_id、wave_no、unprinted_order_count);策略抓取波次(source=1/2)无需领料,返回 400 并提示「该波次为抓取波次,无需领料」(失败 data 含 no_claim_needed=true、wave_id、wave_no);面单号查不到订单或订单不在待处理订单表返回 404 提示无记录;波次内订单已全部领料时返回 already_claimed 幂等结果并提示已领料。",
|
|
||||||
"isNeedAuth": false,
|
|
||||||
"isNeedLogin": true,
|
|
||||||
"isNeedRight": false,
|
|
||||||
"headers": [
|
|
||||||
{
|
|
||||||
"name": "Authorization",
|
|
||||||
"type": "string",
|
|
||||||
"required": true,
|
|
||||||
"description": "Bearer token"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"params": [
|
|
||||||
{
|
|
||||||
"name": "waybill_no",
|
|
||||||
"type": "string",
|
|
||||||
"required": true,
|
|
||||||
"source": "body",
|
|
||||||
"description": "面单号(运单号,wms_order_express.waybill_code)"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"response": [
|
|
||||||
{
|
|
||||||
"name": "wave_id",
|
|
||||||
"type": "number",
|
|
||||||
"required": true,
|
|
||||||
"description": "波次ID"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "wave_no",
|
|
||||||
"type": "string",
|
|
||||||
"required": true,
|
|
||||||
"description": "波次号"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "wave_type",
|
|
||||||
"type": "number",
|
|
||||||
"required": true,
|
|
||||||
"description": "波次类型:1-团购 2-散单"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "wave_source",
|
|
||||||
"type": "number",
|
|
||||||
"required": true,
|
|
||||||
"description": "波次来源:0-普通波次 1-管理后台策略任务 2-PDA策略任务"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "pick_mode",
|
|
||||||
"type": "number",
|
|
||||||
"required": true,
|
|
||||||
"description": "拣货模式:1-团购小波次 2-散单单品单件 3-散单先拣后分 4-边拣边分 5-团购大波次(0 表示无关联拣货任务)"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "matched_order_id",
|
|
||||||
"type": "number",
|
|
||||||
"required": true,
|
|
||||||
"description": "面单号命中的订单ID"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "waybill_no",
|
|
||||||
"type": "string",
|
|
||||||
"required": true,
|
|
||||||
"description": "扫描的面单号"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "total_order_count",
|
|
||||||
"type": "number",
|
|
||||||
"required": true,
|
|
||||||
"description": "波次下订单总数"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "claimed_order_count",
|
|
||||||
"type": "number",
|
|
||||||
"required": true,
|
|
||||||
"description": "本次置为 fin 的订单数(已全部领料时返回 0)"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "status",
|
|
||||||
"type": "string",
|
|
||||||
"required": true,
|
|
||||||
"description": "操作结果:claimed(整波领料完成)或 already_claimed(波次已领料)"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "tip",
|
|
||||||
"type": "string",
|
|
||||||
"required": true,
|
|
||||||
"description": "提示文案"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"errors": [
|
|
||||||
{
|
|
||||||
"code": 400,
|
|
||||||
"message": "参数错误(waybill_no 为空、缺少仓库上下文、订单未分配波次、波次下无可用订单);波次下存在未打印订单返回「波次未打印,禁止领料」(data 含 wave_id、wave_no、unprinted_order_count);策略抓取波次(source=1/2)返回「该波次为抓取波次,无需领料」(data 含 no_claim_needed=true、wave_id、wave_no);其余不支持类型返回通用提示。"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"code": 401,
|
|
||||||
"message": "未获取到操作人上下文。"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"code": 404,
|
|
||||||
"message": "未查询到该面单号对应的订单(无记录)、订单不在待处理订单表(无记录),或波次不存在/不属于当前仓库。"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"code": 500,
|
|
||||||
"message": "运单模型/订单模型不可用或内部错误。"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|||||||
4
package-lock.json
generated
4
package-lock.json
generated
@ -1,11 +1,11 @@
|
|||||||
{
|
{
|
||||||
"name": "wms",
|
"name": "oms",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "wms",
|
"name": "oms",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|||||||
@ -314,7 +314,7 @@ describe('test/app/service/systemMethods/order/wave.waveStrategyQuickScan.test.j
|
|||||||
assert.deepEqual(result.matchedOrderIds, [ 101, 102 ]);
|
assert.deepEqual(result.matchedOrderIds, [ 101, 102 ]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('require_same_express=true 时扫描阶段不再按主快递排除订单', async () => {
|
it('require_same_express=true 时应按同结构主快递优先命中', async () => {
|
||||||
const { service } = createHarness();
|
const { service } = createHarness();
|
||||||
|
|
||||||
const orders = [
|
const orders = [
|
||||||
@ -389,6 +389,6 @@ describe('test/app/service/systemMethods/order/wave.waveStrategyQuickScan.test.j
|
|||||||
),
|
),
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.deepEqual(result.matchedOrderIds, [ 201, 202, 203 ]);
|
assert.deepEqual(result.matchedOrderIds, [ 201, 202 ]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user