feat(wms): 拦截订单门禁豁免、波次号原子取号、打印自定义区数量、拆包视频与商品复核字段
- pick: waveClaimScan 拦截订单整体跳过领料(不置 claim_status=fin,未打印不阻隔领料);query 领料前置校验仅统计非拦截未领料订单(拦截未领料不阻隔拣货);createWavePickTask 新增 excludeUnclaimed,普通波次(source=0)计算拣货数量(order_count/任务订单/筐)时剔除未领料订单 - wave: 波次号改为 wms_number_sequence 原子取号(upsert + LAST_INSERT_ID,seed 对齐当日历史最大序),wave_no 唯一索引 uniq_wave_no,并发撞号自动重取(最多 3 次) - print: 面单自定义区首行「商品总数【n】」(items_total 优先),团购波次商品明细行尾「波次总单数×商品数量」 - returnUnpack: 列表新增 has_video/video_enable/videos 视频字段与筛选,补视频列表权限迁移 - stock: 商品新增 need_recheck(是否需要复核)字段,导入归一化与导出列支持,补迁移 - docs: 同步 methods/system.json 与 methods/changes/system.json 变更记录(恢复遗漏的已提交记录)
This commit is contained in:
parent
a499298670
commit
763573ee41
@ -464,9 +464,13 @@ function resolveItemQuantity(item) {
|
||||
* @param {number} [options.wave_index] 当前波次内序号。
|
||||
* @param {number} [options.platforms_index] 平台内序号。
|
||||
* @param {string} [options.expressInterfaceName] 快递渠道显示名。
|
||||
* @param {number} [options.fallbackTotalQty] 兜底商品总数。
|
||||
* @param {number} [options.fallbackTotalQty] 订单级商品总数(items_total),优先于商品明细数量累加。
|
||||
* @param {number} [options.fallbackItemsCount] 订单级商品种类数(items_count),仅当商品总数与明细累加均为 0 时兜底。
|
||||
* @param {number} [options.waveSource] 波次来源(wms_wave_batch.source),与 waveType 共同决定商品明细行尾是否追加「波次总单数×数量」。
|
||||
* @param {number} [options.waveType] 波次类型(wms_wave_batch.wave_type)。
|
||||
* @param {string} [options.packageMaterialName] 推荐包材名称,非空时追加到波次号前。
|
||||
* @return {Array<string>} 自定义区文本行数组。
|
||||
* @return {Array<string>} 自定义区文本行数组。首行头部分在快递渠道名后追加 商品总数【n】(优先取订单级商品总数 items_total,其次商品明细数量累加,最后 items_count 兜底);
|
||||
* 当 waveSource=0 且 waveType=1 时,商品明细行尾追加「波次总单数×该行商品数量」。
|
||||
*/
|
||||
function buildWaybillCustomProductInfoLines(items, policyConfig = {}, options = {}) {
|
||||
const safeItems = Array.isArray(items) ? items : [];
|
||||
@ -479,6 +483,13 @@ function buildWaybillCustomProductInfoLines(items, policyConfig = {}, options =
|
||||
|
||||
const isHideMode = displayType === WAYBILL_CUSTOM_DISPLAY_TYPES.HIDE;
|
||||
|
||||
// 波次总单数、来源与类型:wave.source=0(普通波次)且 wave_type=1 时,
|
||||
// 商品明细行尾追加「波次总单数 × 该行商品数量」(如 500 单 × 3 件 = 1500)
|
||||
const waveTotalOrders = toNumber(safeOptions.wave_total_orders, 0);
|
||||
const waveSource = toNumber(safeOptions.waveSource, 0);
|
||||
const waveType = toNumber(safeOptions.waveType, 0);
|
||||
const shouldAppendWaveMultiply = waveSource === 0 && waveType === 1 && waveTotalOrders > 0;
|
||||
|
||||
const detailLines = [];
|
||||
|
||||
// HIDE 模式下跳过商品明细行构建,但仍保留 headerLine(波次号、快递渠道等)的输出
|
||||
@ -498,7 +509,7 @@ function buildWaybillCustomProductInfoLines(items, policyConfig = {}, options =
|
||||
'storage_code',
|
||||
]);
|
||||
const barcode = resolveItemBarcodeText(item);
|
||||
const { qtyText } = resolveItemQuantity(item);
|
||||
const { qtyText, qtyNumber } = resolveItemQuantity(item);
|
||||
|
||||
let line = '';
|
||||
switch (displayType) {
|
||||
@ -526,13 +537,17 @@ function buildWaybillCustomProductInfoLines(items, policyConfig = {}, options =
|
||||
}
|
||||
|
||||
if (line) {
|
||||
detailLines.push(line.replace(/\s{2,}/g, ' '));
|
||||
line = line.replace(/\s{2,}/g, ' ');
|
||||
// wave.source=0 且 wave_type=1:行尾追加 波次总单数 × 该行商品数量(数量与乘数之间以两个空格分隔)
|
||||
if (shouldAppendWaveMultiply && qtyNumber > 0) {
|
||||
line += ` ${waveTotalOrders * qtyNumber}`;
|
||||
}
|
||||
detailLines.push(line);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const waveNo = String(safeOptions.waveNo || '').trim();
|
||||
const waveTotalOrders = toNumber(safeOptions.wave_total_orders, 0);
|
||||
const waveIndex = toNumber(safeOptions.wave_index, 0);
|
||||
const platformsIndex = toNumber(safeOptions.platforms_index, 0);
|
||||
const expressInterfaceName = String(safeOptions.expressInterfaceName || '').trim();
|
||||
@ -546,7 +561,25 @@ function buildWaybillCustomProductInfoLines(items, policyConfig = {}, options =
|
||||
? `${waveNo} [${waveTotalOrders}-${waveIndex}]`
|
||||
: waveNo;
|
||||
const waveHeaderText = packageMaterialLabel + waveBodyText;
|
||||
const headerParts = [ waveHeaderText, expressInterfaceName ].filter(Boolean);
|
||||
|
||||
// 商品总数:优先取订单级商品总数(items_total,权威字段),
|
||||
// 其次累加所有商品明细的数量,最后用商品种类数(items_count)兜底。
|
||||
// 订单 items 快照可能是宽松文本(stock_id+数量)甚至陈旧不完整,不能无条件信任明细累加结果
|
||||
const computedTotalQty = safeItems.reduce((total, item) => {
|
||||
if (!isPlainObject(item)) {
|
||||
return total;
|
||||
}
|
||||
const { qtyNumber } = resolveItemQuantity(item);
|
||||
return total + (Number.isFinite(qtyNumber) && qtyNumber > 0 ? qtyNumber : 0);
|
||||
}, 0);
|
||||
const fallbackTotalQty = toNumber(safeOptions.fallbackTotalQty, 0);
|
||||
const fallbackItemsCount = toNumber(safeOptions.fallbackItemsCount, 0);
|
||||
const totalQty = fallbackTotalQty > 0
|
||||
? fallbackTotalQty
|
||||
: (computedTotalQty > 0 ? computedTotalQty : fallbackItemsCount);
|
||||
const totalQtyLabel = totalQty > 0 ? `商品总数【${totalQty}】` : '';
|
||||
|
||||
const headerParts = [ waveHeaderText, expressInterfaceName, totalQtyLabel ].filter(Boolean);
|
||||
const headerLine = headerParts.join(' ');
|
||||
|
||||
if (detailLines.length === 0) {
|
||||
@ -1253,7 +1286,7 @@ function sanitizeTemplatePrivateFields(value, warnings, currentKey = '') {
|
||||
* @param {string[]} warnings 风险提示列表。
|
||||
* @param {Object} policyConfig 策略配置对象。
|
||||
* @param {string} customDataTemplateURL 自定义区模板地址默认值。
|
||||
* @param extraCustomLines
|
||||
* @param {string[]} extraCustomLines 追加到自定义区的额外文本行数组。
|
||||
*/
|
||||
function applyKuaishouExpressFieldMapping(platform, skeleton, orderExpress, orderDelivery, warnings, policyConfig, customDataTemplateURL, extraCustomLines = []) {
|
||||
if (platform !== 'kuaishou') {
|
||||
@ -1293,7 +1326,10 @@ function applyKuaishouExpressFieldMapping(platform, skeleton, orderExpress, orde
|
||||
|| safeOrderDelivery.logistics_interface_name
|
||||
|| safeOrderDelivery.logistics_name
|
||||
),
|
||||
fallbackTotalQty: Number(safeOrderDelivery.items_count || safeOrderDelivery.items_total || 0),
|
||||
fallbackTotalQty: Number(safeOrderDelivery.items_total || 0),
|
||||
fallbackItemsCount: Number(safeOrderDelivery.items_count || 0),
|
||||
waveSource: Number(safeOrderDelivery.wave_source || 0),
|
||||
waveType: Number(safeOrderDelivery.wave_type || 0),
|
||||
}
|
||||
);
|
||||
const customProductInfo = appendExtraCustomLines(
|
||||
@ -1403,7 +1439,7 @@ function applyKuaishouExpressFieldMapping(platform, skeleton, orderExpress, orde
|
||||
* @param {Object} orderExpress 快递单对象。
|
||||
* @param {Object} orderDelivery 订单对象。
|
||||
* @param {Object} policyConfig 策略配置对象。
|
||||
* @param extraCustomLines
|
||||
* @param {string[]} extraCustomLines 追加到自定义区的额外文本行数组。
|
||||
*/
|
||||
function applyPddExpressFieldMapping(platform, skeleton, orderExpress, orderDelivery, policyConfig, extraCustomLines = []) {
|
||||
if (platform !== 'pdd') {
|
||||
@ -1443,7 +1479,10 @@ function applyPddExpressFieldMapping(platform, skeleton, orderExpress, orderDeli
|
||||
|| safeOrderDelivery.logistics_interface_name
|
||||
|| safeOrderDelivery.logistics_name
|
||||
),
|
||||
fallbackTotalQty: Number(safeOrderDelivery.items_count || safeOrderDelivery.items_total || 0),
|
||||
fallbackTotalQty: Number(safeOrderDelivery.items_total || 0),
|
||||
fallbackItemsCount: Number(safeOrderDelivery.items_count || 0),
|
||||
waveSource: Number(safeOrderDelivery.wave_source || 0),
|
||||
waveType: Number(safeOrderDelivery.wave_type || 0),
|
||||
}
|
||||
);
|
||||
const customProductInfo = appendExtraCustomLines(
|
||||
@ -1636,7 +1675,10 @@ function applyDouyinExpressFieldMapping(platform, skeleton, orderExpress, orderD
|
||||
|| safeOrderDelivery.logistics_interface_name
|
||||
|| safeOrderDelivery.logistics_name
|
||||
),
|
||||
fallbackTotalQty: Number(safeOrderDelivery.items_count || safeOrderDelivery.items_total || 0),
|
||||
fallbackTotalQty: Number(safeOrderDelivery.items_total || 0),
|
||||
fallbackItemsCount: Number(safeOrderDelivery.items_count || 0),
|
||||
waveSource: Number(safeOrderDelivery.wave_source || 0),
|
||||
waveType: Number(safeOrderDelivery.wave_type || 0),
|
||||
}
|
||||
);
|
||||
const customProductInfo = appendExtraCustomLines(
|
||||
@ -1726,7 +1768,7 @@ function applyDouyinExpressFieldMapping(platform, skeleton, orderExpress, orderD
|
||||
* @param {Object} policyConfig 策略配置对象。
|
||||
* @param {string} customControlTemplateURL 菜鸟自定义区模板地址。
|
||||
* @param {string[]} warnings 风险提示列表。
|
||||
* @param extraCustomLines
|
||||
* @param {string[]} extraCustomLines 追加到自定义区的额外文本行数组。
|
||||
*/
|
||||
function applyCainiaoExpressFieldMapping(
|
||||
platform,
|
||||
@ -1776,7 +1818,10 @@ function applyCainiaoExpressFieldMapping(
|
||||
|| safeOrderDelivery.logistics_interface_name
|
||||
|| safeOrderDelivery.logistics_name
|
||||
),
|
||||
fallbackTotalQty: Number(safeOrderDelivery.items_count || safeOrderDelivery.items_total || 0),
|
||||
fallbackTotalQty: Number(safeOrderDelivery.items_total || 0),
|
||||
fallbackItemsCount: Number(safeOrderDelivery.items_count || 0),
|
||||
waveSource: Number(safeOrderDelivery.wave_source || 0),
|
||||
waveType: Number(safeOrderDelivery.wave_type || 0),
|
||||
}
|
||||
);
|
||||
const customControlText = appendExtraCustomLines(
|
||||
@ -1937,7 +1982,7 @@ function resolveXhsMainContentFromPrintinfo(printinfo, warnings = []) {
|
||||
* @param {Object} orderDelivery 订单对象。
|
||||
* @param {Object} policyConfig 策略配置对象。
|
||||
* @param {string[]} warnings 风险提示列表。
|
||||
* @param extraCustomLines
|
||||
* @param {string[]} extraCustomLines 追加到自定义区的额外文本行数组。
|
||||
*/
|
||||
function applyXhsExpressFieldMapping(
|
||||
platform,
|
||||
@ -1983,7 +2028,10 @@ function applyXhsExpressFieldMapping(
|
||||
|| safeOrderDelivery.logistics_interface_name
|
||||
|| safeOrderDelivery.logistics_name
|
||||
),
|
||||
fallbackTotalQty: Number(safeOrderDelivery.items_count || safeOrderDelivery.items_total || 0),
|
||||
fallbackTotalQty: Number(safeOrderDelivery.items_total || 0),
|
||||
fallbackItemsCount: Number(safeOrderDelivery.items_count || 0),
|
||||
waveSource: Number(safeOrderDelivery.wave_source || 0),
|
||||
waveType: Number(safeOrderDelivery.wave_type || 0),
|
||||
}
|
||||
);
|
||||
const customProductInfo = appendExtraCustomLines(
|
||||
@ -2040,7 +2088,7 @@ function applyXhsExpressFieldMapping(
|
||||
* @param {Object} orderExpress 快递单对象。
|
||||
* @param {Object} orderDelivery 订单对象。
|
||||
* @param {Object} policyConfig 策略配置对象。
|
||||
* @param extraCustomLines
|
||||
* @param {string[]} extraCustomLines 追加到自定义区的额外文本行数组。
|
||||
*/
|
||||
function applySphExpressFieldMapping(
|
||||
platform,
|
||||
@ -2099,7 +2147,10 @@ function applySphExpressFieldMapping(
|
||||
|| safeOrderDelivery.logistics_interface_name
|
||||
|| safeOrderDelivery.logistics_name
|
||||
),
|
||||
fallbackTotalQty: Number(safeOrderDelivery.items_count || safeOrderDelivery.items_total || 0),
|
||||
fallbackTotalQty: Number(safeOrderDelivery.items_total || 0),
|
||||
fallbackItemsCount: Number(safeOrderDelivery.items_count || 0),
|
||||
waveSource: Number(safeOrderDelivery.wave_source || 0),
|
||||
waveType: Number(safeOrderDelivery.wave_type || 0),
|
||||
}
|
||||
);
|
||||
const customProductInfo = appendExtraCustomLines(
|
||||
@ -2181,7 +2232,7 @@ function resolveJdTemplateUrlFromOrderExpress(orderExpress) {
|
||||
* @param {Object} policyConfig 策略配置对象。
|
||||
* @param {Object} templateSample 模板样例对象。
|
||||
* @param {string[]} warnings 风险提示列表。
|
||||
* @param extraCustomLines
|
||||
* @param {string[]} extraCustomLines 追加到自定义区的额外文本行数组。
|
||||
*/
|
||||
function applyJdExpressFieldMapping(
|
||||
platform,
|
||||
@ -2271,7 +2322,10 @@ function applyJdExpressFieldMapping(
|
||||
|| safeOrderDelivery.logistics_interface_name
|
||||
|| safeOrderDelivery.logistics_name
|
||||
),
|
||||
fallbackTotalQty: Number(safeOrderDelivery.items_count || safeOrderDelivery.items_total || 0),
|
||||
fallbackTotalQty: Number(safeOrderDelivery.items_total || 0),
|
||||
fallbackItemsCount: Number(safeOrderDelivery.items_count || 0),
|
||||
waveSource: Number(safeOrderDelivery.wave_source || 0),
|
||||
waveType: Number(safeOrderDelivery.wave_type || 0),
|
||||
}
|
||||
);
|
||||
const customProductInfo = appendExtraCustomLines(
|
||||
|
||||
@ -111,6 +111,12 @@ module.exports = app => {
|
||||
defaultValue: 'N',
|
||||
comment: '是否批次管理',
|
||||
},
|
||||
need_recheck: {
|
||||
type: CHAR(1),
|
||||
allowNull: false,
|
||||
defaultValue: 'Y',
|
||||
comment: '是否需要复核:Y=需要复核,N=不需要复核',
|
||||
},
|
||||
create_at: {
|
||||
type: DATE,
|
||||
allowNull: false,
|
||||
|
||||
@ -155,8 +155,9 @@ module.exports = app => {
|
||||
fields: [ 'wave_status', 'create_time' ],
|
||||
},
|
||||
{
|
||||
name: 'idx_wave_no',
|
||||
name: 'uniq_wave_no',
|
||||
fields: [ 'wave_no' ],
|
||||
unique: true,
|
||||
},
|
||||
{
|
||||
name: 'idx_warehouse',
|
||||
|
||||
@ -563,7 +563,13 @@ class WaveService extends OrderBaseService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询当天前缀下的下一个波次序号。
|
||||
* 获取当天前缀下的下一个波次序号(原子取号)。
|
||||
*
|
||||
* 基于序列表 wms_number_sequence 的单条 upsert 原子递增:
|
||||
* INSERT ... VALUES (LAST_INSERT_ID(:seed + 1)) ON DUPLICATE KEY UPDATE
|
||||
* current_seq = LAST_INSERT_ID(GREATEST(current_seq, :seed) + 1)
|
||||
* 其中 :seed 为当日该前缀主表已有最大序号,保证与历史编号对齐;
|
||||
* 同事务(同连接)内回读 LAST_INSERT_ID() 取回本次分配序号,并发下不再撞号。
|
||||
*
|
||||
* @param {string} prefix 波次编号前缀。
|
||||
* @param {string} datePart 日期片段(YYYYMMDD)。
|
||||
@ -574,32 +580,54 @@ class WaveService extends OrderBaseService {
|
||||
const normalizedPrefix = String(prefix || '').trim() || 'B';
|
||||
const normalizedDatePart = String(datePart || '').trim();
|
||||
const pattern = `${normalizedPrefix}${normalizedDatePart}%`;
|
||||
const sql = `
|
||||
SELECT wave_no
|
||||
FROM wms_wave_batch
|
||||
WHERE wave_no LIKE :pattern
|
||||
ORDER BY wave_no DESC
|
||||
LIMIT 1
|
||||
`;
|
||||
const prefixDatePartLength = normalizedPrefix.length + normalizedDatePart.length;
|
||||
const bizType = `wave_no_${normalizedPrefix.slice(0, 20)}`;
|
||||
|
||||
const rows = await this.ctx.model.query(sql, {
|
||||
replacements: { pattern },
|
||||
type: this.ctx.model.QueryTypes.SELECT,
|
||||
transaction,
|
||||
});
|
||||
// 历史对齐种子:当日该前缀主表已有最大序号(无则为 0)
|
||||
const seedRows = await this.ctx.model.query(
|
||||
`SELECT IFNULL(MAX(CAST(SUBSTRING(wave_no, :startPos) AS UNSIGNED)), 0) AS max_seq
|
||||
FROM wms_wave_batch
|
||||
WHERE wave_no LIKE :pattern`,
|
||||
{
|
||||
replacements: {
|
||||
pattern,
|
||||
startPos: prefixDatePartLength + 1,
|
||||
},
|
||||
type: this.ctx.model.QueryTypes.SELECT,
|
||||
transaction,
|
||||
}
|
||||
);
|
||||
const seed = Number(seedRows && seedRows[0] && seedRows[0].max_seq || 0);
|
||||
|
||||
const latestWaveNo = String(rows && rows[0] && rows[0].wave_no || '').trim();
|
||||
if (!latestWaveNo) {
|
||||
// 原子取号:全局维度(warehouse_id=0)按「前缀+日期」递增,唯一键串行化并发事务
|
||||
await this.ctx.model.query(
|
||||
`INSERT INTO wms_number_sequence (warehouse_id, biz_type, date_part, current_seq, created_at, updated_at)
|
||||
VALUES (:warehouseId, :bizType, :datePart, LAST_INSERT_ID(:seed + 1), NOW(), NOW())
|
||||
ON DUPLICATE KEY UPDATE current_seq = LAST_INSERT_ID(GREATEST(current_seq, :seed) + 1), updated_at = NOW()`,
|
||||
{
|
||||
replacements: {
|
||||
warehouseId: 0,
|
||||
bizType,
|
||||
datePart: normalizedDatePart,
|
||||
seed,
|
||||
},
|
||||
transaction,
|
||||
}
|
||||
);
|
||||
|
||||
const seqRows = await this.ctx.model.query(
|
||||
'SELECT LAST_INSERT_ID() AS seq',
|
||||
{
|
||||
type: this.ctx.model.QueryTypes.SELECT,
|
||||
transaction,
|
||||
}
|
||||
);
|
||||
const sequence = Number(seqRows && seqRows[0] && seqRows[0].seq || 0);
|
||||
if (!Number.isInteger(sequence) || sequence <= 0) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
const match = latestWaveNo.match(/(\d{5})$/);
|
||||
const lastSequence = match ? Number(match[1]) : 0;
|
||||
if (!Number.isInteger(lastSequence) || lastSequence <= 0) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return lastSequence + 1;
|
||||
return sequence;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -699,6 +727,22 @@ class WaveService extends OrderBaseService {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断数据库错误是否为唯一键冲突(重复键 ER_DUP_ENTRY)。
|
||||
*
|
||||
* @param {*} error 数据库异常对象。
|
||||
* @return {boolean} 是否唯一键冲突。
|
||||
*/
|
||||
isDuplicateEntryError(error) {
|
||||
const errno = Number(
|
||||
error && (error.original && error.original.errno || error.parent && error.parent.errno || error.errno) || 0
|
||||
);
|
||||
const code = String(
|
||||
error && (error.original && error.original.code || error.parent && error.parent.code || error.code) || ''
|
||||
);
|
||||
return errno === 1062 || code === 'ER_DUP_ENTRY';
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增一条“已就绪”波次批次记录,并返回自增 wave_id。
|
||||
*
|
||||
@ -746,12 +790,9 @@ class WaveService extends OrderBaseService {
|
||||
const normalizedWaveType = Number(waveType) === 2 ? 2 : 1;
|
||||
const normalizedSourceInput = Number(source);
|
||||
const normalizedSource = [ 0, 1, 2 ].includes(normalizedSourceInput) ? normalizedSourceInput : 0;
|
||||
const retryOnDuplicate = !normalizedWaveNoInput;
|
||||
const maxWaveNoAttempts = retryOnDuplicate ? 3 : 1;
|
||||
let normalizedWaveNo = normalizedWaveNoInput;
|
||||
if (!normalizedWaveNo) {
|
||||
const datePart = this.getCurrentDatePart();
|
||||
const sequence = await this.getNextWaveNoSequence(normalizedWavePrefix, datePart, transaction);
|
||||
normalizedWaveNo = this.buildWaveNo(normalizedWavePrefix, datePart, sequence);
|
||||
}
|
||||
const creator = this.getWaveCreator();
|
||||
|
||||
const sql = `
|
||||
@ -795,23 +836,49 @@ class WaveService extends OrderBaseService {
|
||||
)
|
||||
`;
|
||||
|
||||
const createResult = await this.ctx.model.query(sql, {
|
||||
replacements: {
|
||||
waveNo: normalizedWaveNo,
|
||||
waveType: normalizedWaveType,
|
||||
totalOrders: normalizedTotalOrders,
|
||||
itemDetailMachine: normalizedItemDetailMachine,
|
||||
itemPartType: normalizedItemPartType,
|
||||
itemPart: normalizedItemPart,
|
||||
distinguishExpress: normalizedDistinguishExpress,
|
||||
logisticsName: normalizedLogisticsName,
|
||||
itemSnapshotKey: normalizedItemSnapshotKey,
|
||||
warehouseId: Number.isInteger(normalizedWarehouseId) ? normalizedWarehouseId : 0,
|
||||
creator,
|
||||
source: normalizedSource,
|
||||
},
|
||||
transaction,
|
||||
});
|
||||
// 撞号重试:唯一索引兜底下,并发撞号时自动重新取号(最多 3 次)
|
||||
let createResult = null;
|
||||
for (let attempt = 1; attempt <= maxWaveNoAttempts; attempt += 1) {
|
||||
if (!normalizedWaveNo) {
|
||||
const datePart = this.getCurrentDatePart();
|
||||
const sequence = await this.getNextWaveNoSequence(normalizedWavePrefix, datePart, transaction);
|
||||
normalizedWaveNo = this.buildWaveNo(normalizedWavePrefix, datePart, sequence);
|
||||
}
|
||||
|
||||
try {
|
||||
createResult = await this.ctx.model.query(sql, {
|
||||
replacements: {
|
||||
waveNo: normalizedWaveNo,
|
||||
waveType: normalizedWaveType,
|
||||
totalOrders: normalizedTotalOrders,
|
||||
itemDetailMachine: normalizedItemDetailMachine,
|
||||
itemPartType: normalizedItemPartType,
|
||||
itemPart: normalizedItemPart,
|
||||
distinguishExpress: normalizedDistinguishExpress,
|
||||
logisticsName: normalizedLogisticsName,
|
||||
itemSnapshotKey: normalizedItemSnapshotKey,
|
||||
warehouseId: Number.isInteger(normalizedWarehouseId) ? normalizedWarehouseId : 0,
|
||||
creator,
|
||||
source: normalizedSource,
|
||||
},
|
||||
transaction,
|
||||
});
|
||||
break;
|
||||
} catch (error) {
|
||||
const isDuplicateWaveNo = this.isDuplicateEntryError(error);
|
||||
if (!retryOnDuplicate || !isDuplicateWaveNo || attempt >= maxWaveNoAttempts) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
this.ctx.logger.warn(
|
||||
'[wave.createWaveBatchReady] 波次编号 %s 已存在(撞号),自动重新取号重试 %d/%d',
|
||||
normalizedWaveNo,
|
||||
attempt,
|
||||
maxWaveNoAttempts
|
||||
);
|
||||
normalizedWaveNo = '';
|
||||
}
|
||||
}
|
||||
|
||||
let insertedWaveId = this.extractInsertId(createResult);
|
||||
if (!Number.isInteger(insertedWaveId) || insertedWaveId <= 0) {
|
||||
|
||||
@ -97,6 +97,8 @@ class PickService extends MainService {
|
||||
* @param {Array<number>} params.orderIds 波次订单ID集合。
|
||||
* @param {string} [params.remark=''] 备注。
|
||||
* @param {number} [params.source=2] 任务来源:1-PDA抓取创建,2-扫描进任务/后台抓取,默认为2。
|
||||
* @param {boolean} [params.excludeUnclaimed=false] 普通波次(source=0)计算拣货数量时是否剔除未领料
|
||||
* (claim_status != fin)订单:true 时未领料订单不写入任务订单/筐,也不计入 order_count。
|
||||
* @return {Promise<{task_id: number, task_no: string}>} 创建结果。
|
||||
*/
|
||||
async createWavePickTask(params = {}) {
|
||||
@ -109,6 +111,7 @@ class PickService extends MainService {
|
||||
const operatorName = String(params && params.operatorName || '').trim() || 'system';
|
||||
const source = Number(params && params.source !== undefined ? params.source : 2);
|
||||
const remark = String(params && params.remark || '').trim();
|
||||
const excludeUnclaimed = Boolean(params && params.excludeUnclaimed);
|
||||
const normalizedOrderIds = [ ...new Set((Array.isArray(params && params.orderIds) ? params.orderIds : [])
|
||||
.map(id => Number(id || 0))
|
||||
.filter(id => Number.isInteger(id) && id > 0)) ];
|
||||
@ -134,11 +137,13 @@ class PickService extends MainService {
|
||||
[this.app.Sequelize.Op.in]: normalizedOrderIds,
|
||||
},
|
||||
},
|
||||
attributes: [ 'id', 'intercept_status' ],
|
||||
attributes: [ 'id', 'intercept_status', 'claim_status' ],
|
||||
raw: true,
|
||||
});
|
||||
|
||||
// 拦截流程中的订单不允许抓取波次,直接剔除
|
||||
const orderRowMap = new Map((Array.isArray(orderRows) ? orderRows : [])
|
||||
.map(row => [ Number(row && row.id || 0), row ]));
|
||||
const interceptedOrderIds = new Set((Array.isArray(orderRows) ? orderRows : [])
|
||||
.filter(row => isInterceptedOrderStatus(row && row.intercept_status))
|
||||
.map(row => Number(row && row.id || 0))
|
||||
@ -149,9 +154,28 @@ class PickService extends MainService {
|
||||
ctx.logger.info('[pick.createWavePickTask] 剔除拦截订单: %s', excludedIds.join(','));
|
||||
}
|
||||
}
|
||||
const activeOrderIds = normalizedOrderIds.filter(id => !interceptedOrderIds.has(id));
|
||||
|
||||
// 领料语义(普通波次 source=0):未领料订单(claim_status != fin)不参与拣货数量计算,直接剔除
|
||||
const unclaimedOrderIds = excludeUnclaimed
|
||||
? new Set(normalizedOrderIds.filter(id => {
|
||||
const row = orderRowMap.get(id);
|
||||
return !row || String(row && row.claim_status || '') !== 'fin';
|
||||
}))
|
||||
: new Set();
|
||||
if (unclaimedOrderIds.size > 0) {
|
||||
const excludedIds = normalizedOrderIds.filter(id => unclaimedOrderIds.has(id));
|
||||
if (excludedIds.length > 0) {
|
||||
ctx.logger.info('[pick.createWavePickTask] 剔除未领料订单: %s', excludedIds.join(','));
|
||||
}
|
||||
}
|
||||
|
||||
const activeOrderIds = normalizedOrderIds
|
||||
.filter(id => !interceptedOrderIds.has(id) && !unclaimedOrderIds.has(id));
|
||||
if (activeOrderIds.length <= 0) {
|
||||
throw Object.assign(new Error('波次下订单均已被拦截,无法创建任务'), { code: 400 });
|
||||
const emptyReason = unclaimedOrderIds.size > 0
|
||||
? '波次下订单均未领料或均被拦截,无法创建任务'
|
||||
: '波次下订单均已被拦截,无法创建任务';
|
||||
throw Object.assign(new Error(emptyReason), { code: 400 });
|
||||
}
|
||||
|
||||
const orderNoMap = new Map((Array.isArray(orderRows) ? orderRows : [])
|
||||
@ -674,6 +698,7 @@ class PickService extends MainService {
|
||||
let targetWaveId = 0;
|
||||
let targetWaveNo = '';
|
||||
let targetWaveType = 2;
|
||||
let targetWaveSource = 0;
|
||||
let selectedOrderIds = [];
|
||||
|
||||
const orderId = Number(orderExpress && orderExpress.order_id || 0);
|
||||
@ -706,7 +731,7 @@ class PickService extends MainService {
|
||||
if (orderWaveId > 0) {
|
||||
const waveByIdRows = await ctx.model.query(
|
||||
`
|
||||
SELECT wave_id, wave_no, wave_type
|
||||
SELECT wave_id, wave_no, wave_type, source
|
||||
FROM wms_wave_batch
|
||||
WHERE warehouse_id = :warehouseId
|
||||
AND wave_id = :waveId
|
||||
@ -728,10 +753,11 @@ class PickService extends MainService {
|
||||
targetWaveId = Number(waveRow.wave_id || 0);
|
||||
targetWaveNo = String(waveRow.wave_no || '').trim();
|
||||
targetWaveType = Number(waveRow.wave_type || 2);
|
||||
targetWaveSource = Number(waveRow.source || 0);
|
||||
} else {
|
||||
const waveByNoRows = await ctx.model.query(
|
||||
`
|
||||
SELECT wave_id, wave_no, wave_type
|
||||
SELECT wave_id, wave_no, wave_type, source
|
||||
FROM wms_wave_batch
|
||||
WHERE warehouse_id = :warehouseId
|
||||
AND wave_no = :waveNo
|
||||
@ -753,11 +779,12 @@ class PickService extends MainService {
|
||||
targetWaveId = Number(waveRow.wave_id || 0);
|
||||
targetWaveNo = String(waveRow.wave_no || '').trim();
|
||||
targetWaveType = Number(waveRow.wave_type || 2);
|
||||
targetWaveSource = Number(waveRow.source || 0);
|
||||
}
|
||||
} else {
|
||||
const waveRows = await ctx.model.query(
|
||||
`
|
||||
SELECT wave_id, wave_no, wave_type
|
||||
SELECT wave_id, wave_no, wave_type, source
|
||||
FROM wms_wave_batch
|
||||
WHERE warehouse_id = :warehouseId
|
||||
AND wave_no = :waveNo
|
||||
@ -780,12 +807,45 @@ class PickService extends MainService {
|
||||
targetWaveId = Number(waveRow.wave_id || 0);
|
||||
targetWaveNo = String(waveRow.wave_no || '').trim();
|
||||
targetWaveType = Number(waveRow.wave_type || 2);
|
||||
targetWaveSource = Number(waveRow.source || 0);
|
||||
}
|
||||
|
||||
if (!Number.isInteger(targetWaveId) || targetWaveId <= 0 || !targetWaveNo) {
|
||||
return this.fail('目标波次信息不完整', {}, 400);
|
||||
}
|
||||
|
||||
// 领料前置校验:source=0 普通波次需整波领料,未领料阻隔创建拣货任务
|
||||
// (拦截订单未领料不阻隔拣货,拦截订单将在任务创建时被剔除)
|
||||
if (targetWaveSource === 0) {
|
||||
const claimGatePickMode = await this.getWavePickModeByWaveId(targetWaveId);
|
||||
let claimGateOrderModel = null;
|
||||
try {
|
||||
claimGateOrderModel = await this.getOrderModelByWarehouse(normalizedWarehouseId);
|
||||
} catch (error) {
|
||||
return this.fail(error && error.message ? error.message : '订单模型不可用', {}, 500);
|
||||
}
|
||||
|
||||
const claimGateStats = await this.getWaveClaimGateStats({
|
||||
orderModel: claimGateOrderModel,
|
||||
warehouseId: normalizedWarehouseId,
|
||||
waveId: targetWaveId,
|
||||
waveNo: targetWaveNo,
|
||||
});
|
||||
if (claimGateStats.total_order_count > 0 && claimGateStats.unclaimed_order_count > 0) {
|
||||
return this.fail('订单未领料,请先领料后再拣货', {
|
||||
action: 'wave_claim',
|
||||
wave_id: targetWaveId,
|
||||
wave_no: targetWaveNo,
|
||||
wave_type: targetWaveType,
|
||||
wave_source: targetWaveSource,
|
||||
pick_mode: claimGatePickMode,
|
||||
unclaimed_order_count: claimGateStats.unclaimed_order_count,
|
||||
intercepted_order_count: claimGateStats.intercepted_order_count,
|
||||
total_order_count: claimGateStats.total_order_count,
|
||||
}, 400);
|
||||
}
|
||||
}
|
||||
|
||||
const activeTaskRows = await ctx.model.query(
|
||||
`
|
||||
SELECT t.id AS task_id, t.pick_user_id, t.pick_user_name
|
||||
@ -1042,6 +1102,8 @@ class PickService extends MainService {
|
||||
orderIds: selectedOrderIds,
|
||||
remark: `pick.query keyword=${normalizedKeyword}`,
|
||||
source: 2,
|
||||
// 普通波次(source=0):计算拣货数量时剔除未领料(claim_status != fin)订单
|
||||
excludeUnclaimed: targetWaveSource === 0,
|
||||
});
|
||||
|
||||
return this.success('ok', {
|
||||
@ -1226,7 +1288,7 @@ class PickService extends MainService {
|
||||
|
||||
// --- 按 wave_id 直接查波次 ---
|
||||
const waveRows = await ctx.model.query(
|
||||
`SELECT wave_id, wave_no, wave_type
|
||||
`SELECT wave_id, wave_no, wave_type, source
|
||||
FROM wms_wave_batch
|
||||
WHERE warehouse_id = :warehouseId
|
||||
AND wave_id = :waveId
|
||||
@ -1244,6 +1306,7 @@ class PickService extends MainService {
|
||||
const targetWaveId = Number(waveRow.wave_id || 0);
|
||||
const targetWaveNo = String(waveRow.wave_no || '').trim();
|
||||
const targetWaveType = Number(waveRow.wave_type || 2);
|
||||
const targetWaveSource = Number(waveRow.source || 0);
|
||||
|
||||
if (!Number.isInteger(targetWaveId) || targetWaveId <= 0 || !targetWaveNo) {
|
||||
return this.fail('目标波次信息不完整', {}, 400);
|
||||
@ -1392,6 +1455,8 @@ class PickService extends MainService {
|
||||
orderIds: selectedOrderIds,
|
||||
remark: `pick.wavePickComplete wave_id=${waveId}`,
|
||||
source: 2,
|
||||
// 普通波次(source=0):计算拣货数量时剔除未领料(claim_status != fin)订单
|
||||
excludeUnclaimed: targetWaveSource === 0,
|
||||
});
|
||||
taskId = createdTask.task_id;
|
||||
} catch (error) {
|
||||
@ -1537,6 +1602,78 @@ class PickService extends MainService {
|
||||
return linkRow ? Number(linkRow.pick_mode || 0) : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 统计波次下领料门禁相关数量(普通波次 source=0 领料前置校验)。
|
||||
*
|
||||
* 统计口径:
|
||||
* - total_order_count:波次下全部订单数(含拦截订单);
|
||||
* - intercepted_order_count:拦截订单数(intercept_status != none);
|
||||
* - unclaimed_order_count:非拦截且未领料(claim_status != fin)订单数,
|
||||
* 拦截订单未领料不阻隔拣货,不计入该数量。
|
||||
*
|
||||
* @param {Object} params 统计参数。
|
||||
* @param {Object} params.orderModel 订单分表模型。
|
||||
* @param {number} params.warehouseId 仓库ID。
|
||||
* @param {number} params.waveId 波次ID。
|
||||
* @param {string} [params.waveNo=''] 波次编码(wave_id 未命中时回退按 wave_no 统计)。
|
||||
* @return {Promise<{total_order_count: number, intercepted_order_count: number, unclaimed_order_count: number}>}
|
||||
* 统计结果。
|
||||
*/
|
||||
async getWaveClaimGateStats(params = {}) {
|
||||
const { ctx } = this;
|
||||
const orderModel = params && params.orderModel;
|
||||
const warehouseId = Number(params && params.warehouseId || 0);
|
||||
const waveId = Number(params && params.waveId || 0);
|
||||
const waveNo = String(params && params.waveNo || '').trim();
|
||||
if (!orderModel || typeof orderModel.findAll !== 'function') {
|
||||
ctx.logger.warn('[pick.getWaveClaimGateStats] 订单模型不可用,返回空统计');
|
||||
return { total_order_count: 0, intercepted_order_count: 0, unclaimed_order_count: 0 };
|
||||
}
|
||||
|
||||
let rows = [];
|
||||
if (Number.isInteger(waveId) && waveId > 0) {
|
||||
rows = await orderModel.findAll({
|
||||
where: {
|
||||
warehouse_id: warehouseId,
|
||||
wave_id: waveId,
|
||||
},
|
||||
attributes: [ 'id', 'claim_status', 'intercept_status' ],
|
||||
raw: true,
|
||||
});
|
||||
rows = Array.isArray(rows) ? rows : [];
|
||||
}
|
||||
if (rows.length === 0 && waveNo) {
|
||||
const fallbackRows = await orderModel.findAll({
|
||||
where: {
|
||||
warehouse_id: warehouseId,
|
||||
wave_no: waveNo,
|
||||
},
|
||||
attributes: [ 'id', 'claim_status', 'intercept_status' ],
|
||||
raw: true,
|
||||
});
|
||||
rows = Array.isArray(fallbackRows) ? fallbackRows : [];
|
||||
}
|
||||
|
||||
const orderIds = [ ...new Set(rows
|
||||
.map(item => Number(item && item.id || 0))
|
||||
.filter(id => Number.isInteger(id) && id > 0)) ];
|
||||
const interceptedOrderIds = new Set(rows
|
||||
.filter(item => isInterceptedOrderStatus(item && item.intercept_status))
|
||||
.map(item => Number(item && item.id || 0))
|
||||
.filter(id => Number.isInteger(id) && id > 0));
|
||||
const unclaimedOrderCount = rows
|
||||
.filter(item => String(item && item.claim_status || '') !== 'fin'
|
||||
&& orderIds.includes(Number(item && item.id || 0))
|
||||
&& !interceptedOrderIds.has(Number(item && item.id || 0)))
|
||||
.length;
|
||||
|
||||
return {
|
||||
total_order_count: orderIds.length,
|
||||
intercepted_order_count: interceptedOrderIds.size,
|
||||
unclaimed_order_count: unclaimedOrderCount,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 扫描面单号领取整波(领料)。
|
||||
*
|
||||
@ -1546,8 +1683,10 @@ class PickService extends MainService {
|
||||
* 并写入 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);
|
||||
* 波次下存在未打印订单(print_status != fin,拦截订单除外)时禁止领料,
|
||||
* 返回 400 并提示「波次未打印,禁止领料」(失败 data 含 wave_id、wave_no、unprinted_order_count、
|
||||
* intercepted_order_count,拦截订单未打印不阻隔领料);
|
||||
* 拦截订单整体跳过领料:既不置为领料完成,其未打印状态也不阻隔整波领料。
|
||||
* 其余未知类型返回通用不支持提示。
|
||||
* 波次内订单已全部领单时返回 already_claimed 幂等结果并提示已领料。
|
||||
*
|
||||
@ -1702,7 +1841,7 @@ class PickService extends MainService {
|
||||
warehouse_id: normalizedWarehouseId,
|
||||
wave_id: targetWaveId,
|
||||
},
|
||||
attributes: [ 'id', 'claim_status', 'print_status' ],
|
||||
attributes: [ 'id', 'claim_status', 'print_status', 'intercept_status' ],
|
||||
raw: true,
|
||||
});
|
||||
let waveOrders = Array.isArray(waveOrderRows) ? waveOrderRows : [];
|
||||
@ -1712,7 +1851,7 @@ class PickService extends MainService {
|
||||
warehouse_id: normalizedWarehouseId,
|
||||
wave_no: targetWaveNo,
|
||||
},
|
||||
attributes: [ 'id', 'claim_status', 'print_status' ],
|
||||
attributes: [ 'id', 'claim_status', 'print_status', 'intercept_status' ],
|
||||
raw: true,
|
||||
});
|
||||
waveOrders = Array.isArray(fallbackRows) ? fallbackRows : [];
|
||||
@ -1725,8 +1864,15 @@ class PickService extends MainService {
|
||||
}
|
||||
|
||||
const totalOrderCount = waveOrderIds.length;
|
||||
// 拦截订单整体跳过领料:不参与领取(保持未领料),其未打印/未领料状态也不阻隔领料与拣货
|
||||
const interceptedWaveOrderIds = new Set(waveOrders
|
||||
.filter(item => isInterceptedOrderStatus(item && item.intercept_status))
|
||||
.map(item => Number(item && item.id || 0))
|
||||
.filter(id => Number.isInteger(id) && id > 0));
|
||||
|
||||
const unclaimedOrderIds = [ ...new Set(waveOrders
|
||||
.filter(item => String(item && item.claim_status || '') !== 'fin')
|
||||
.filter(item => String(item && item.claim_status || '') !== 'fin'
|
||||
&& !interceptedWaveOrderIds.has(Number(item && item.id || 0)))
|
||||
.map(item => Number(item && item.id || 0))
|
||||
.filter(id => Number.isInteger(id) && id > 0)) ];
|
||||
|
||||
@ -1739,6 +1885,7 @@ class PickService extends MainService {
|
||||
matched_order_id: matchedOrderId,
|
||||
waybill_no: waybillNo,
|
||||
total_order_count: totalOrderCount,
|
||||
intercepted_order_count: interceptedWaveOrderIds.size,
|
||||
};
|
||||
|
||||
if (unclaimedOrderIds.length === 0) {
|
||||
@ -1754,8 +1901,10 @@ class PickService extends MainService {
|
||||
}
|
||||
|
||||
// 波次打印校验:存在未打印订单(print_status != fin)时禁止整波领料
|
||||
// (拦截订单的未打印状态不阻隔领料)
|
||||
const unprintedOrderIds = [ ...new Set(waveOrders
|
||||
.filter(item => String(item && item.print_status || '') !== 'fin')
|
||||
.filter(item => String(item && item.print_status || '') !== 'fin'
|
||||
&& !interceptedWaveOrderIds.has(Number(item && item.id || 0)))
|
||||
.map(item => Number(item && item.id || 0))
|
||||
.filter(id => Number.isInteger(id) && id > 0)) ];
|
||||
if (unprintedOrderIds.length > 0) {
|
||||
|
||||
@ -192,6 +192,36 @@ class ReturnUnpackMethodService extends MainService {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询拆包录像列表(查,按拆包单维度校验仓库隔离)。
|
||||
*
|
||||
* @param {Object} data 请求体。
|
||||
* @param {Object} [data.pagination] 分页参数。
|
||||
* @param {Object} [data.where] 筛选条件(unpack_id 必填,camera_id/status 可选)。
|
||||
* @param {Object} [data.sort] 排序参数。
|
||||
* @return {Promise<Object>} 统一 success 包装。
|
||||
*/
|
||||
async videoList(data = {}) {
|
||||
const { service } = this;
|
||||
const { pagination, sort } = data;
|
||||
const { where, whereValue } = this.prepareWhereContext(data, {});
|
||||
|
||||
const unpackId = Number((whereValue && whereValue.unpack_id) || 0);
|
||||
|
||||
return this._call(async () => {
|
||||
if (!Number.isFinite(unpackId) || unpackId <= 0) {
|
||||
throw service.systems.returnUnpack.createBusinessError('unpack_id 必填且必须为正整数', 400);
|
||||
}
|
||||
// 拆包单仓库隔离校验(不存在 404 / 跨仓库 403)
|
||||
await service.systems.returnUnpack._findByIdChecked(unpackId);
|
||||
return service.systems.returnUnpack.videoList(
|
||||
{ ...where, unpack_id: unpackId },
|
||||
pagination,
|
||||
sort
|
||||
);
|
||||
}, '查询录像列表失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询拆包单详情(查)。
|
||||
*
|
||||
|
||||
@ -526,6 +526,7 @@ class WarehouseService extends MainService {
|
||||
is_sn_mgmt,
|
||||
is_shelf_life_mgmt,
|
||||
is_batch_mgmt,
|
||||
need_recheck,
|
||||
prohibited_id,
|
||||
brand_name,
|
||||
managementFlags,
|
||||
@ -568,6 +569,7 @@ class WarehouseService extends MainService {
|
||||
is_sn_mgmt,
|
||||
is_shelf_life_mgmt,
|
||||
is_batch_mgmt,
|
||||
need_recheck,
|
||||
prohibited_id,
|
||||
brand_name,
|
||||
managementFlags,
|
||||
@ -761,6 +763,7 @@ class WarehouseService extends MainService {
|
||||
?? goodsCode
|
||||
?? '';
|
||||
const storeId = pickValue([ 'store_id', 'storeId' ]) ?? this.ctx?.user?.store_id;
|
||||
const needRecheckRaw = pickValue([ '是否需要复核', 'need_recheck', 'needRecheck' ]);
|
||||
|
||||
return {
|
||||
...row,
|
||||
@ -775,12 +778,31 @@ class WarehouseService extends MainService {
|
||||
gross_weight: pickValue([ '毛重', 'gross_weight', 'grossWeight' ]),
|
||||
tag_price: pickValue([ '标价', 'tag_price', 'tagPrice' ]),
|
||||
retail_price: pickValue([ '零售价', 'retail_price', 'retailPrice' ]),
|
||||
...(needRecheckRaw !== undefined && { need_recheck: this._normalizeNeedRecheckValue(needRecheckRaw) }),
|
||||
barcode: this._normalizeBarcodeField(
|
||||
pickValue([ '条码', 'bar_code', 'barCode', 'barcodeList', 'barcode_list', 'barcode' ])
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 归一化「是否需要复核」字段值:需要 → Y,不需要 → N。
|
||||
* 支持中文(需要/需要复核/不需要/无需复核)、Y/N、1/0、布尔值。
|
||||
*
|
||||
* @param {string|number|boolean} raw 原始值
|
||||
* @return {string} 'Y' 或 'N'
|
||||
*/
|
||||
_normalizeNeedRecheckValue(raw) {
|
||||
const normalized = String(raw ?? '').trim();
|
||||
if ([ '需要', '需要复核', 'Y', 'y', '1' ].includes(normalized) || raw === true) {
|
||||
return 'Y';
|
||||
}
|
||||
if ([ '不需要', '无需', '无需复核', 'N', 'n', '0' ].includes(normalized) || raw === false) {
|
||||
return 'N';
|
||||
}
|
||||
throw new Error(`是否需要复核值不合法: ${raw},仅支持 需要/不需要`);
|
||||
}
|
||||
|
||||
/**
|
||||
* 归一化条码字段,只接受逗号分隔的字符串格式,返回去重后的条码数组。
|
||||
* 与 stock.warehouse.export 导出格式对齐(导出使用逗号分隔)。
|
||||
|
||||
@ -543,6 +543,12 @@ class OrderPrintSystemService extends OrderBaseService {
|
||||
};
|
||||
}
|
||||
|
||||
// 波次元信息映射(source / wave_type),供自定义区「波次总单数×数量」行尾规则使用
|
||||
const waveMetaMap = new Map();
|
||||
for (const waveRow of waveRows) {
|
||||
waveMetaMap.set(Number(waveRow.wave_id), waveRow);
|
||||
}
|
||||
|
||||
const hitWaveIdSet = new Set(waveRows.map(row => Number(row.wave_id)));
|
||||
const missingWaveIds = normalizedWaveIds.filter(waveId => !hitWaveIdSet.has(waveId));
|
||||
const hitWaveIds = normalizedWaveIds.filter(waveId => hitWaveIdSet.has(waveId));
|
||||
@ -677,11 +683,14 @@ class OrderPrintSystemService extends OrderBaseService {
|
||||
const waveTotalOrders = Number(waveTotalOrderCountMap.get(waveIdForCount) || 0);
|
||||
const waveIndex = Number(waveOrderIndexInfo.wave_index || 0);
|
||||
const platformsIndex = Number(waveOrderIndexInfo.platforms_index || 0);
|
||||
const waveMetaRow = waveMetaMap.get(waveIdForCount) || {};
|
||||
const effectiveOrderRowWithWaveIndex = {
|
||||
...effectiveOrderRow,
|
||||
wave_total_orders: waveTotalOrders > 0 ? waveTotalOrders : 0,
|
||||
wave_index: waveIndex > 0 ? waveIndex : 0,
|
||||
platforms_index: platformsIndex > 0 ? platformsIndex : 0,
|
||||
wave_source: Number(waveMetaRow.source || 0),
|
||||
wave_type: Number(waveMetaRow.wave_type || 0),
|
||||
};
|
||||
const storeId = Number(orderRow && orderRow.store_id || 0);
|
||||
const policyConfig = policyConfigMap.get(storeId) || {};
|
||||
@ -830,6 +839,12 @@ class OrderPrintSystemService extends OrderBaseService {
|
||||
|
||||
const waveRows = await this.queryWavesByIds(normalizedWarehouseId, validOrderWaveIds);
|
||||
|
||||
// 波次元信息映射(source / wave_type),供自定义区「波次总单数×数量」行尾规则使用
|
||||
const waveMetaMap = new Map();
|
||||
for (const waveRow of waveRows) {
|
||||
waveMetaMap.set(Number(waveRow.wave_id), waveRow);
|
||||
}
|
||||
|
||||
const orderIdsForExpress = validOrderRows
|
||||
.map(row => Number(row && row.id || 0))
|
||||
.filter(orderId => Number.isInteger(orderId) && orderId > 0);
|
||||
@ -881,11 +896,14 @@ class OrderPrintSystemService extends OrderBaseService {
|
||||
const waveTotalOrders = Number(waveTotalOrderCountMap.get(waveIdForCount) || 0);
|
||||
const waveIndex = Number(waveOrderIndexInfo.wave_index || 0);
|
||||
const platformsIndex = Number(waveOrderIndexInfo.platforms_index || 0);
|
||||
const waveMetaRow = waveMetaMap.get(waveIdForCount) || {};
|
||||
const effectiveOrderRowWithWaveIndex = {
|
||||
...effectiveOrderRow,
|
||||
wave_total_orders: waveTotalOrders > 0 ? waveTotalOrders : 0,
|
||||
wave_index: waveIndex > 0 ? waveIndex : 0,
|
||||
platforms_index: platformsIndex > 0 ? platformsIndex : 0,
|
||||
wave_source: Number(waveMetaRow.source || 0),
|
||||
wave_type: Number(waveMetaRow.wave_type || 0),
|
||||
};
|
||||
const storeId = Number(orderRow && orderRow.store_id || 0);
|
||||
const policyConfig = policyConfigMap.get(storeId) || {};
|
||||
@ -1121,6 +1139,12 @@ class OrderPrintSystemService extends OrderBaseService {
|
||||
.filter(waveId => Number.isInteger(waveId) && waveId > 0)));
|
||||
const waveRows = await this.queryWavesByIds(normalizedWarehouseId, validOrderWaveIds);
|
||||
|
||||
// 波次元信息映射(source / wave_type),供自定义区「波次总单数×数量」行尾规则使用
|
||||
const waveMetaMap = new Map();
|
||||
for (const waveRow of waveRows) {
|
||||
waveMetaMap.set(Number(waveRow.wave_id), waveRow);
|
||||
}
|
||||
|
||||
const orderIdsForIndex = validOrderRows.map(row => Number(row.id)).filter(id => id > 0);
|
||||
const waveOrderIndexMap = await this.queryWaveOrderIndexMapByOrderIds(
|
||||
orderIdsForIndex, normalizedWarehouseId, validOrderWaveIds
|
||||
@ -1141,11 +1165,14 @@ class OrderPrintSystemService extends OrderBaseService {
|
||||
const waveTotalOrders = Number(waveTotalOrderCountMap.get(waveIdForCount) || 0);
|
||||
const waveIndex = Number(waveOrderIndexInfo.wave_index || 0);
|
||||
const platformsIndex = Number(waveOrderIndexInfo.platforms_index || 0);
|
||||
const waveMetaRow = waveMetaMap.get(waveIdForCount) || {};
|
||||
const effectiveOrderRowWithWaveIndex = {
|
||||
...effectiveOrderRow,
|
||||
wave_total_orders: waveTotalOrders > 0 ? waveTotalOrders : 0,
|
||||
wave_index: waveIndex > 0 ? waveIndex : 0,
|
||||
platforms_index: platformsIndex > 0 ? platformsIndex : 0,
|
||||
wave_source: Number(waveMetaRow.source || 0),
|
||||
wave_type: Number(waveMetaRow.wave_type || 0),
|
||||
};
|
||||
|
||||
const storeId = Number(orderRow.store_id || 0);
|
||||
@ -1750,7 +1777,7 @@ class OrderPrintSystemService extends OrderBaseService {
|
||||
}
|
||||
|
||||
const querySql = `
|
||||
SELECT wave_id, wave_no
|
||||
SELECT wave_id, wave_no, source, wave_type
|
||||
FROM wms_wave_batch
|
||||
WHERE warehouse_id = :warehouseId
|
||||
AND wave_id IN (:waveIds)
|
||||
@ -1955,7 +1982,7 @@ class OrderPrintSystemService extends OrderBaseService {
|
||||
* 返回 business_key=1 的主运单,按 order_id、business_key、id 升序排列。
|
||||
*
|
||||
* @param {number[]} orderIds 订单 ID 列表。
|
||||
* @param warehouseId
|
||||
* @param {number} warehouseId 仓库ID。
|
||||
* @return {Promise<Array<Object>>} 匹配的运单记录数组,字段包含 id、order_id、business_key、waybill_code、
|
||||
* logistics_code、logistics_name、logistics_interface_id、logistics_interface_name、platform_code、
|
||||
* warehouse_id、printinfo、signature、encryptprintinfo、ver。
|
||||
|
||||
@ -536,12 +536,30 @@ class ReturnUnpackService extends Service {
|
||||
order,
|
||||
offset: (page - 1) * pageSize,
|
||||
limit: pageSize,
|
||||
raw: true,
|
||||
raw: false,
|
||||
include: [
|
||||
{
|
||||
model: ctx.model.ReturnUnpackVideo,
|
||||
as: 'videos',
|
||||
attributes: [ 'id', 'video_url', 'camera_id', 'status' ],
|
||||
where: { deleted_at: null },
|
||||
required: false,
|
||||
include: [
|
||||
{
|
||||
model: ctx.model.Camera,
|
||||
as: 'camera',
|
||||
attributes: [ 'id', 'custom_name', 'channel_name' ],
|
||||
required: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const list = [];
|
||||
for (const row of rows) {
|
||||
list.push(await this._enrichRow(row));
|
||||
const plain = row && typeof row.toJSON === 'function' ? row.toJSON() : row;
|
||||
list.push(this._flattenVideos(await this._enrichRow(plain)));
|
||||
}
|
||||
|
||||
return {
|
||||
@ -609,6 +627,69 @@ class ReturnUnpackService extends Service {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询拆包录像列表(unpack_id 维度,仓库隔离由方法层校验)。
|
||||
*
|
||||
* @param {Object} where 标准化 where 条件对象(unpack_id 必填)。
|
||||
* @param {Object} [pagination] 分页参数。
|
||||
* @param {Object} [sort] 排序参数。
|
||||
* @return {Promise<Object>} { list, pagination }。
|
||||
*/
|
||||
async videoList(where = {}, pagination = {}, sort = {}) {
|
||||
const { ctx, app } = this;
|
||||
const { Op } = app.Sequelize;
|
||||
|
||||
const page = Math.max(1, parseInt(pagination.page) || 1);
|
||||
const pageSize = Math.min(500, Math.max(1, parseInt(pagination.pageSize) || 20));
|
||||
|
||||
const queryWhere = this._buildVideoListWhere(where, Op);
|
||||
const order = this._buildVideoListOrder(sort);
|
||||
|
||||
const { count, rows } = await ctx.model.ReturnUnpackVideo.findAndCountAll({
|
||||
where: queryWhere,
|
||||
include: [
|
||||
{
|
||||
model: ctx.model.Camera,
|
||||
as: 'camera',
|
||||
required: false,
|
||||
},
|
||||
],
|
||||
order,
|
||||
offset: (page - 1) * pageSize,
|
||||
limit: pageSize,
|
||||
raw: false,
|
||||
});
|
||||
|
||||
const list = rows
|
||||
.map(row => (row && typeof row.toJSON === 'function' ? row.toJSON() : row))
|
||||
.map(row => {
|
||||
const camera = row.camera || {};
|
||||
return {
|
||||
id: row.id,
|
||||
unpack_id: row.unpack_id,
|
||||
video_url: row.video_url,
|
||||
status: row.status || null,
|
||||
camera_id: row.camera_id || null,
|
||||
camera_name: (camera.custom_name || camera.channel_name) || null,
|
||||
remark: row.remark || null,
|
||||
created_at: row.created_at ? app.formatDate(row.created_at) : null,
|
||||
updated_at: row.updated_at ? app.formatDate(row.updated_at) : null,
|
||||
};
|
||||
});
|
||||
|
||||
return {
|
||||
list,
|
||||
pagination: {
|
||||
page,
|
||||
pageSize,
|
||||
total: count,
|
||||
totalPages: Math.ceil(count / pageSize),
|
||||
hasPrevious: page > 1,
|
||||
hasNext: page * pageSize < count,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询拆包单详情:主表 + 明细 + 视频 + 退回收到单 + 原订单详情(原单退回时)。
|
||||
*
|
||||
@ -1212,6 +1293,12 @@ class ReturnUnpackService extends Service {
|
||||
|
||||
record.is_original_return = Boolean(record.order_express_id);
|
||||
|
||||
// 视频派生字段(与 order.packing.list 对齐):记录含 videos 数组时计算
|
||||
if (Array.isArray(record.videos)) {
|
||||
record.has_video = record.videos.length > 0 ? 1 : 2;
|
||||
record.video_enable = record.videos.some(v => v.video_url && v.status !== 'failed') ? 1 : 2;
|
||||
}
|
||||
|
||||
// camera_ids 归一化为数组(MySQL JSON 列可能返回字符串)
|
||||
if (record.camera_ids !== undefined && record.camera_ids !== null) {
|
||||
if (typeof record.camera_ids === 'string') {
|
||||
@ -1238,6 +1325,27 @@ class ReturnUnpackService extends Service {
|
||||
return record;
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表场景视频数组扁平化(对齐 order.packing.list 输出口径)。
|
||||
* 仅输出前端需要的精简字段(id/video_url/status/camera_id/camera_name);
|
||||
* detail 等场景的 videos 保持完整关联结构不变。
|
||||
*
|
||||
* @param {Object} row 主表记录(含 videos 关联数组)。
|
||||
* @return {Object} 扁平化后的记录。
|
||||
*/
|
||||
_flattenVideos(row) {
|
||||
if (Array.isArray(row.videos)) {
|
||||
row.videos = row.videos.map(v => ({
|
||||
id: v.id,
|
||||
video_url: v.video_url,
|
||||
status: v.status || null,
|
||||
camera_id: v.camera_id || null,
|
||||
camera_name: (v.camera && (v.camera.custom_name || v.camera.channel_name)) || null,
|
||||
}));
|
||||
}
|
||||
return row;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量附加库存详情(条码/图片等)到明细行。
|
||||
* 统一走 stockWarehouse.getStockDetails 通用方法(带缓存,含 barcodes/image_url/
|
||||
@ -1383,6 +1491,30 @@ class ReturnUnpackService extends Service {
|
||||
_buildListWhere(where = {}, Op) {
|
||||
const queryWhere = {};
|
||||
|
||||
// has_video 筛选:1=有视频记录 2=无视频记录(口径对齐 order.packing.list)
|
||||
if (where.has_video !== undefined && where.has_video !== null) {
|
||||
const hasVideoValue = Number(where.has_video?.value ?? where.has_video);
|
||||
if (hasVideoValue === 1 || hasVideoValue === 2) {
|
||||
const existsSql = 'EXISTS (SELECT 1 FROM wms_return_unpack_video WHERE unpack_id = wms_return_unpack.id AND deleted_at IS NULL)';
|
||||
const cond = hasVideoValue === 1
|
||||
? this.app.Sequelize.literal(existsSql)
|
||||
: this.app.Sequelize.literal(`NOT ${existsSql}`);
|
||||
queryWhere[Op.and] = [ ...(queryWhere[Op.and] || []), cond ];
|
||||
}
|
||||
}
|
||||
|
||||
// video_enable 筛选:1=录像可用 2=录像不可用(口径对齐 order.packing.list)
|
||||
if (where.video_enable !== undefined && where.video_enable !== null) {
|
||||
const videoEnableValue = Number(where.video_enable?.value ?? where.video_enable);
|
||||
if (videoEnableValue === 1 || videoEnableValue === 2) {
|
||||
const existsSql = "EXISTS (SELECT 1 FROM wms_return_unpack_video WHERE unpack_id = wms_return_unpack.id AND deleted_at IS NULL AND video_url != '' AND status != 'failed')";
|
||||
const cond = videoEnableValue === 1
|
||||
? this.app.Sequelize.literal(existsSql)
|
||||
: this.app.Sequelize.literal(`NOT ${existsSql}`);
|
||||
queryWhere[Op.and] = [ ...(queryWhere[Op.and] || []), cond ];
|
||||
}
|
||||
}
|
||||
|
||||
const directFields = [
|
||||
'warehouse_id', 'unpacker_id', 'return_received_id', 'store_id',
|
||||
'order_express_id', 'order_id', 'status', 'detail_status',
|
||||
@ -1437,6 +1569,46 @@ class ReturnUnpackService extends Service {
|
||||
return queryWhere;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建录像列表 where 条件(unpack_id 必填等值;camera_id/status 可选等值)。
|
||||
*
|
||||
* @param {Object} where 标准化条件对象。
|
||||
* @param {Object} Op Sequelize Op 对象。
|
||||
* @return {Object} Sequelize where 条件。
|
||||
*/
|
||||
_buildVideoListWhere(where = {}, Op) {
|
||||
const queryWhere = {};
|
||||
|
||||
if (where.unpack_id !== undefined && where.unpack_id !== null) {
|
||||
queryWhere.unpack_id = this._resolveConditionValue(where.unpack_id, Op);
|
||||
}
|
||||
if (where.camera_id !== undefined && where.camera_id !== null) {
|
||||
queryWhere.camera_id = this._resolveConditionValue(where.camera_id, Op);
|
||||
}
|
||||
if (where.status !== undefined && where.status !== null) {
|
||||
queryWhere.status = this._resolveConditionValue(where.status, Op);
|
||||
}
|
||||
|
||||
return queryWhere;
|
||||
}
|
||||
|
||||
/**
|
||||
* 录像列表排序(默认按 id 升序)。
|
||||
*
|
||||
* @param {Object} sort 排序参数。
|
||||
* @return {Array<Array<string>>} Sequelize order 数组。
|
||||
*/
|
||||
_buildVideoListOrder(sort = {}) {
|
||||
const sortField = sort.sortField || sort.sort_field || 'id';
|
||||
const sortOrderRaw = (sort.sortOrder || sort.sort_order || 'asc').toLowerCase();
|
||||
const sortOrder = sortOrderRaw === 'asc' ? 'ASC' : 'DESC';
|
||||
|
||||
const allowed = new Set([ 'id', 'created_at', 'updated_at', 'camera_id' ]);
|
||||
const safeSortField = allowed.has(sortField) ? sortField : 'id';
|
||||
|
||||
return [[ safeSortField, sortOrder ]];
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析标准化条件值为 Sequelize 可用的条件对象。
|
||||
*
|
||||
|
||||
@ -2218,6 +2218,7 @@ class stockStoreService extends Service {
|
||||
tag_price: item.tag_price || '',
|
||||
retail_price: item.retail_price || '',
|
||||
gross_weight: item.gross_weight || '',
|
||||
need_recheck: String(item.need_recheck || 'Y') === 'Y' ? '需要' : '不需要',
|
||||
store_remask,
|
||||
barcodes: Array.isArray(item.barcodes) ? item.barcodes.join(',') : '',
|
||||
quantity: item.quantity,
|
||||
@ -2253,6 +2254,7 @@ class stockStoreService extends Service {
|
||||
{ header: '标价', key: 'tag_price' },
|
||||
{ header: '零售价', key: 'retail_price' },
|
||||
{ header: '毛重', key: 'gross_weight' },
|
||||
{ header: '是否需要复核', key: 'need_recheck' },
|
||||
{ header: '货主', key: 'store_remask' },
|
||||
{ header: '条码', key: 'barcodes' },
|
||||
{ header: '库存', key: 'quantity' },
|
||||
@ -2343,6 +2345,7 @@ class stockStoreService extends Service {
|
||||
tag_price: item.tag_price || '',
|
||||
retail_price: item.retail_price || '',
|
||||
gross_weight: item.gross_weight || '',
|
||||
need_recheck: String(item.need_recheck || 'Y') === 'Y' ? '需要' : '不需要',
|
||||
store_remask: storeRemask,
|
||||
barcodes: Array.isArray(item.barcodes) ? item.barcodes.join(',') : '',
|
||||
quantity: item.quantity,
|
||||
@ -2378,6 +2381,7 @@ class stockStoreService extends Service {
|
||||
{ header: '标价', key: 'tag_price' },
|
||||
{ header: '零售价', key: 'retail_price' },
|
||||
{ header: '毛重', key: 'gross_weight' },
|
||||
{ header: '是否需要复核', key: 'need_recheck' },
|
||||
{ header: '货主', key: 'store_remask' },
|
||||
{ header: '条码', key: 'barcodes' },
|
||||
{ header: '库存', key: 'quantity' },
|
||||
@ -2530,7 +2534,7 @@ class stockStoreService extends Service {
|
||||
const { ctx, app } = this;
|
||||
const { Op } = app.Sequelize;
|
||||
|
||||
const canChangeFlide = [ 'brand_name', 'prohibited_id', 'gross_weight', 'packing_requirements', 'managementFlags', 'stock_unit' ];
|
||||
const canChangeFlide = [ 'brand_name', 'prohibited_id', 'gross_weight', 'packing_requirements', 'managementFlags', 'stock_unit', 'need_recheck' ];
|
||||
|
||||
const { ids, method, value } = ctx.request.body;
|
||||
|
||||
@ -2601,6 +2605,18 @@ class stockStoreService extends Service {
|
||||
update_by: ctx.user.id || ctx.user.username,
|
||||
};
|
||||
|
||||
} else if (method === 'need_recheck') {
|
||||
// 是否需要复核:Y=需要复核,N=不需要复核
|
||||
const updateValue = String(value).trim().toUpperCase();
|
||||
if (![ 'Y', 'N' ].includes(updateValue)) {
|
||||
return { message: '是否需要复核必须是 Y(需要复核)或 N(不需要复核)', code: 405 };
|
||||
}
|
||||
updateData = {
|
||||
need_recheck: updateValue,
|
||||
update_at: new Date(),
|
||||
update_by: ctx.user.id || ctx.user.username,
|
||||
};
|
||||
|
||||
} else if (method === 'managementFlags') {
|
||||
// 管理标识是对象格式,需要更新三个独立字段
|
||||
if (typeof value !== 'object') {
|
||||
@ -3001,6 +3017,7 @@ class stockStoreService extends Service {
|
||||
'is_batch_mgmt',
|
||||
'is_shelf_life_mgmt',
|
||||
'is_sn_mgmt',
|
||||
'need_recheck',
|
||||
'goods_code',
|
||||
'item_code',
|
||||
'item_name',
|
||||
@ -3055,6 +3072,7 @@ class stockStoreService extends Service {
|
||||
box_width, box_height, box_volume, box_remark, id,
|
||||
box_volume_m3, boxVolumeM3,
|
||||
shelf_life_days, inbound_min_days, outbound_min_days, remaining_threshold_days,
|
||||
need_recheck,
|
||||
} = data;
|
||||
const normalizedVolume = volume ?? volume_cm3 ?? volumeCm3;
|
||||
const normalizedBoxVolume = box_volume ?? box_volume_m3 ?? boxVolumeM3;
|
||||
@ -3128,6 +3146,7 @@ class stockStoreService extends Service {
|
||||
is_sn_mgmt: is_sn_mgmt || false,
|
||||
is_shelf_life_mgmt: is_shelf_life_mgmt || false,
|
||||
is_batch_mgmt: is_batch_mgmt || false,
|
||||
need_recheck,
|
||||
prohibited_id: prohibited_id_tmp,
|
||||
brand_name,
|
||||
...(managementFlags && { management_flags: managementFlags }),
|
||||
@ -3211,6 +3230,7 @@ class stockStoreService extends Service {
|
||||
enable_box_spec, box_unit, quantity_per_box,
|
||||
box_gross_weight, box_net_weight, box_length,
|
||||
box_width, box_height, box_volume, box_remark,
|
||||
need_recheck,
|
||||
} = data;
|
||||
|
||||
// 1. 参数验证
|
||||
@ -3244,6 +3264,7 @@ class stockStoreService extends Service {
|
||||
is_sn_mgmt: is_sn_mgmt || false,
|
||||
is_shelf_life_mgmt: is_shelf_life_mgmt || false,
|
||||
is_batch_mgmt: is_batch_mgmt || false,
|
||||
need_recheck: need_recheck || 'Y',
|
||||
prohibited_id,
|
||||
brand_name,
|
||||
...(managementFlags && { management_flags: managementFlags }),
|
||||
@ -3304,6 +3325,11 @@ class stockStoreService extends Service {
|
||||
throw new Error('启用箱规时,每箱数量必须大于0');
|
||||
}
|
||||
|
||||
// 是否需要复核:仅允许 Y(需要)/ N(不需要)
|
||||
if (data.need_recheck !== undefined && data.need_recheck !== null && ![ 'Y', 'N' ].includes(String(data.need_recheck).trim())) {
|
||||
throw new Error('need_recheck 必须是 Y(需要复核)或 N(不需要复核)');
|
||||
}
|
||||
|
||||
// 数值类型验证
|
||||
const numericFields = [ 'length', 'width', 'height', 'volume', 'gross_weight', 'net_weight' ];
|
||||
for (const field of numericFields) {
|
||||
|
||||
@ -0,0 +1,254 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* wms_wave_batch.wave_no 唯一化。
|
||||
*
|
||||
* 背景:并发创建波次时「查当日最大序号+1」存在竞态,可能产生 wave_no 相同的多行
|
||||
* (不同 wave_id、不同订单组),导致两组订单共用一个波次号。
|
||||
*
|
||||
* 本迁移:
|
||||
* 1. 修复存量重复波次号:同一 wave_no 保留最早(wave_id 最小)一行,
|
||||
* 其余行按「前缀+日期+下一个空闲序号」重新编号,并同步引用方数据
|
||||
* (订单表四个车道、拣货任务波次关联表、打印记录、打包任务)的 wave_no;
|
||||
* 2. 移除冗余的非唯一索引 idx_wave_no(若存在);
|
||||
* 3. 新增唯一索引 uniq_wave_no(若已人工添加则跳过,保证幂等)。
|
||||
*/
|
||||
|
||||
const TABLE_NAME = 'wms_wave_batch';
|
||||
|
||||
/**
|
||||
* 归一化索引字段名(Sequelize 各版本返回 string 或 { attribute } 对象)。
|
||||
*
|
||||
* @param {Array<Object|string>} fields 索引字段列表。
|
||||
* @return {Array<string>} 字段名字符串列表。
|
||||
*/
|
||||
function normalizeIndexFields(fields) {
|
||||
return (Array.isArray(fields) ? fields : [])
|
||||
.map(field => String(
|
||||
typeof field === 'string' ? field : (field && (field.attribute || field.name || ''))
|
||||
).trim())
|
||||
.filter(Boolean);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断索引列表是否包含指定名称的非唯一/唯一 wave_no 索引。
|
||||
*
|
||||
* @param {Array<Object>} indexes showIndex 结果。
|
||||
* @param {string} indexName 索引名称。
|
||||
* @param {boolean} unique 是否唯一索引。
|
||||
* @return {boolean} 是否存在。
|
||||
*/
|
||||
function hasWaveNoIndex(indexes, indexName, unique) {
|
||||
return (Array.isArray(indexes) ? indexes : []).some(index => {
|
||||
if (!index || index.name !== indexName) {
|
||||
return false;
|
||||
}
|
||||
const fields = normalizeIndexFields(index.fields);
|
||||
return fields.length === 1 && fields[0] === 'wave_no' && Boolean(index.unique) === unique;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询存量重复的波次号。
|
||||
*
|
||||
* @param {Object} queryInterface Sequelize 查询接口。
|
||||
* @return {Promise<Array<{wave_no: string, cnt: number}>>} 重复波次号列表。
|
||||
*/
|
||||
async function fetchDuplicateWaveNos(queryInterface) {
|
||||
return await queryInterface.sequelize.query(
|
||||
`SELECT wave_no, COUNT(*) AS cnt
|
||||
FROM ${TABLE_NAME}
|
||||
GROUP BY wave_no
|
||||
HAVING COUNT(*) > 1
|
||||
ORDER BY wave_no ASC`,
|
||||
{ type: queryInterface.sequelize.QueryTypes.SELECT }
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算「前缀+日期」片段下下一个空闲波次号。
|
||||
*
|
||||
* @param {Object} queryInterface Sequelize 查询接口。
|
||||
* @param {string} prefixDate 波次号前缀+日期片段(如 B20260822)。
|
||||
* @return {Promise<string>} 下一个空闲波次号。
|
||||
*/
|
||||
async function buildNextFreeWaveNo(queryInterface, prefixDate) {
|
||||
const startPos = String(prefixDate).length + 1;
|
||||
const rows = await queryInterface.sequelize.query(
|
||||
`SELECT IFNULL(MAX(CAST(SUBSTRING(wave_no, :startPos) AS UNSIGNED)), 0) + 1 AS seq
|
||||
FROM ${TABLE_NAME}
|
||||
WHERE wave_no LIKE :pattern`,
|
||||
{
|
||||
replacements: { startPos, pattern: `${prefixDate}%` },
|
||||
type: queryInterface.sequelize.QueryTypes.SELECT,
|
||||
}
|
||||
);
|
||||
const seq = Number(rows && rows[0] && rows[0].seq || 1);
|
||||
return `${prefixDate}${String(seq).padStart(5, '0')}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断波次号是否已存在。
|
||||
*
|
||||
* @param {Object} queryInterface Sequelize 查询接口。
|
||||
* @param {string} waveNo 波次号。
|
||||
* @return {Promise<boolean>} 是否已存在。
|
||||
*/
|
||||
async function waveNoExists(queryInterface, waveNo) {
|
||||
const rows = await queryInterface.sequelize.query(
|
||||
`SELECT wave_id FROM ${TABLE_NAME} WHERE wave_no = :waveNo LIMIT 1`,
|
||||
{ replacements: { waveNo }, type: queryInterface.sequelize.QueryTypes.SELECT }
|
||||
);
|
||||
return Array.isArray(rows) && rows.length > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新指定表内该波次的 wave_no(表不存在时跳过)。
|
||||
*
|
||||
* @param {Object} queryInterface Sequelize 查询接口。
|
||||
* @param {string} tableName 表名。
|
||||
* @param {number} warehouseId 仓库ID。
|
||||
* @param {number} waveId 波次ID。
|
||||
* @param {string} waveNo 新波次号。
|
||||
* @return {Promise<void>} 无返回值。
|
||||
*/
|
||||
async function updateTableWaveNo(queryInterface, tableName, warehouseId, waveId, waveNo) {
|
||||
const checkRows = await queryInterface.sequelize.query(
|
||||
`SELECT TABLE_NAME
|
||||
FROM information_schema.TABLES
|
||||
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = :tableName`,
|
||||
{ replacements: { tableName }, type: queryInterface.sequelize.QueryTypes.SELECT }
|
||||
);
|
||||
if (!Array.isArray(checkRows) || checkRows.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
await queryInterface.sequelize.query(
|
||||
`UPDATE \`${tableName}\`
|
||||
SET wave_no = :waveNo
|
||||
WHERE warehouse_id = :warehouseId
|
||||
AND wave_id = :waveId
|
||||
AND wave_no <> :waveNo`,
|
||||
{ replacements: { waveNo, warehouseId, waveId } }
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步某波次被重编号后所有引用方表中的 wave_no。
|
||||
*
|
||||
* @param {Object} queryInterface Sequelize 查询接口。
|
||||
* @param {number} warehouseId 仓库ID。
|
||||
* @param {number} waveId 波次ID。
|
||||
* @param {string} waveNo 新波次号。
|
||||
* @return {Promise<void>} 无返回值。
|
||||
*/
|
||||
async function syncWaveNoReferences(queryInterface, warehouseId, waveId, waveNo) {
|
||||
if (Number.isInteger(warehouseId) && warehouseId > 0) {
|
||||
await updateTableWaveNo(queryInterface, `wms_order_delivery_${warehouseId}`, warehouseId, waveId, waveNo);
|
||||
await updateTableWaveNo(queryInterface, `wms_order_delivery_${warehouseId}_history`, warehouseId, waveId, waveNo);
|
||||
await updateTableWaveNo(queryInterface, `wms_order_delivery_${warehouseId}_dispatch`, warehouseId, waveId, waveNo);
|
||||
await updateTableWaveNo(queryInterface, `wms_order_delivery_${warehouseId}_outsourced`, warehouseId, waveId, waveNo);
|
||||
}
|
||||
await updateTableWaveNo(queryInterface, 'wms_wave_pick_task_wave', warehouseId, waveId, waveNo);
|
||||
await updateTableWaveNo(queryInterface, 'wms_print_record', warehouseId, waveId, waveNo);
|
||||
await updateTableWaveNo(queryInterface, 'wms_pack_task', warehouseId, waveId, waveNo);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
async up(queryInterface) {
|
||||
// 1. 修复存量重复波次号:同一 wave_no 保留最早一行,其余重新编号
|
||||
const duplicateRows = await fetchDuplicateWaveNos(queryInterface);
|
||||
for (const dup of (Array.isArray(duplicateRows) ? duplicateRows : [])) {
|
||||
const waveNo = String(dup && dup.wave_no || '').trim();
|
||||
if (!waveNo) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const rows = await queryInterface.sequelize.query(
|
||||
`SELECT wave_id, warehouse_id
|
||||
FROM ${TABLE_NAME}
|
||||
WHERE wave_no = :waveNo
|
||||
ORDER BY wave_id ASC`,
|
||||
{ replacements: { waveNo }, type: queryInterface.sequelize.QueryTypes.SELECT }
|
||||
);
|
||||
if (!Array.isArray(rows) || rows.length <= 1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const prefixDate = waveNo.replace(/\d+$/, '');
|
||||
if (!prefixDate) {
|
||||
throw new Error(`波次号 ${waveNo} 无字母前缀,无法自动重编号,请人工处理`);
|
||||
}
|
||||
|
||||
// 保留最早(wave_id 最小)的一行,其余行重新编号
|
||||
for (let index = 1; index < rows.length; index += 1) {
|
||||
const row = rows[index];
|
||||
const waveId = Number(row && row.wave_id || 0);
|
||||
const warehouseId = Number(row && row.warehouse_id || 0);
|
||||
if (!Number.isInteger(waveId) || waveId <= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
let nextWaveNo = await buildNextFreeWaveNo(queryInterface, prefixDate);
|
||||
let guard = 0;
|
||||
while (guard < 100 && await waveNoExists(queryInterface, nextWaveNo)) {
|
||||
nextWaveNo = await buildNextFreeWaveNo(queryInterface, prefixDate);
|
||||
guard += 1;
|
||||
}
|
||||
if (guard >= 100) {
|
||||
throw new Error(`波次号 ${waveNo} 重新编号失败:无法找到空闲编号`);
|
||||
}
|
||||
|
||||
await queryInterface.sequelize.query(
|
||||
`UPDATE ${TABLE_NAME}
|
||||
SET wave_no = :nextWaveNo, update_time = NOW()
|
||||
WHERE wave_id = :waveId`,
|
||||
{ replacements: { nextWaveNo, waveId } }
|
||||
);
|
||||
|
||||
// 同步引用方数据
|
||||
await syncWaveNoReferences(queryInterface, warehouseId, waveId, nextWaveNo);
|
||||
}
|
||||
}
|
||||
|
||||
// 2. 二次校验:修复后不应再有重复波次号
|
||||
const residualRows = await fetchDuplicateWaveNos(queryInterface);
|
||||
if ((Array.isArray(residualRows) ? residualRows : []).length > 0) {
|
||||
const residual = residualRows.map(row => String(row && row.wave_no || '').trim()).filter(Boolean);
|
||||
throw new Error(`wms_wave_batch 修复后仍存在重复波次号: ${residual.join(', ')}`);
|
||||
}
|
||||
|
||||
// 3. 读取索引现状
|
||||
const indexes = await queryInterface.showIndex(TABLE_NAME);
|
||||
|
||||
// 4. 移除冗余非唯一索引(若存在)
|
||||
if (hasWaveNoIndex(indexes, 'idx_wave_no', false)) {
|
||||
await queryInterface.removeIndex(TABLE_NAME, 'idx_wave_no');
|
||||
}
|
||||
|
||||
// 5. 新增唯一索引(若已人工添加则跳过,保证幂等)
|
||||
if (!hasWaveNoIndex(indexes, 'uniq_wave_no', true)) {
|
||||
await queryInterface.addIndex(TABLE_NAME, [ 'wave_no' ], {
|
||||
unique: true,
|
||||
name: 'uniq_wave_no',
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
async down(queryInterface) {
|
||||
const indexes = await queryInterface.showIndex(TABLE_NAME);
|
||||
|
||||
// 回滚:移除唯一索引
|
||||
if (hasWaveNoIndex(indexes, 'uniq_wave_no', true)) {
|
||||
await queryInterface.removeIndex(TABLE_NAME, 'uniq_wave_no');
|
||||
}
|
||||
|
||||
// 回滚:恢复非唯一索引(若不存在)
|
||||
if (!hasWaveNoIndex(indexes, 'idx_wave_no', false)) {
|
||||
await queryInterface.addIndex(TABLE_NAME, [ 'wave_no' ], {
|
||||
unique: false,
|
||||
name: 'idx_wave_no',
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
@ -0,0 +1,82 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* 退回拆包录像分页列表权限迁移(returnUnpack.videoList)。
|
||||
*
|
||||
* 权限明细:
|
||||
* 560 — returnUnpack.videoList API:退回拆包录像列表
|
||||
*
|
||||
* 角色授权(与查询类 546-549 一致):
|
||||
* → 客服组-员工(30) → 客服组-主管(28)(客服员工及以上)
|
||||
* 经理(8)/仓库管理员(2)/超级管理员(7) 已持有 * 通配符,自动拥有所有权限,无需处理
|
||||
*
|
||||
* 幂等:INSERT IGNORE 创建权限记录;角色权限数组追加后去重排序,已存在跳过。
|
||||
*/
|
||||
|
||||
const TABLE = 'wms_permission';
|
||||
const ROLE_TABLE = 'wms_role';
|
||||
const COLUMNS = 'id, path, component, name, redirect, meta_title, meta_icon, hidden, always_show, parent_id, type, sort, status, created_at, update_at';
|
||||
|
||||
/** 权限ID → 授权角色ID列表(不含通配符角色) */
|
||||
const PERMISSION_ROLES = {
|
||||
560: [ 30, 28 ],
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
async up(queryInterface, Sequelize) {
|
||||
// ── 1. 创建 API 权限记录(固定 ID 560)──
|
||||
await queryInterface.sequelize.query(
|
||||
`INSERT IGNORE INTO \`${TABLE}\` (${COLUMNS}) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, NOW(), NOW())`,
|
||||
{ replacements: [ 560, 'returnUnpack.videoList', null, 'returnUnpack.videoList', null, 'API:退回拆包录像列表', null, 0, 0, null, 'api', 0, 1 ] }
|
||||
);
|
||||
|
||||
// ── 2. 角色授权注入 ──
|
||||
for (const permId of Object.keys(PERMISSION_ROLES).map(Number)) {
|
||||
for (const roleId of PERMISSION_ROLES[permId]) {
|
||||
const rows = await queryInterface.sequelize.query(
|
||||
`SELECT id, permissions FROM \`${ROLE_TABLE}\` WHERE id = ?`,
|
||||
{ replacements: [ roleId ], type: queryInterface.sequelize.QueryTypes.SELECT }
|
||||
);
|
||||
const record = Array.isArray(rows) ? rows[0] : null;
|
||||
if (!record) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 通配符角色跳过
|
||||
if (record.permissions === '*') {
|
||||
continue;
|
||||
}
|
||||
|
||||
let perms;
|
||||
try {
|
||||
perms = JSON.parse(record.permissions || '[]');
|
||||
} catch (err) {
|
||||
continue;
|
||||
}
|
||||
if (!Array.isArray(perms)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (perms.includes(permId)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
perms.push(permId);
|
||||
perms.sort((a, b) => a - b);
|
||||
|
||||
await queryInterface.sequelize.query(
|
||||
`UPDATE \`${ROLE_TABLE}\` SET permissions = ? WHERE id = ?`,
|
||||
{ replacements: [ JSON.stringify(perms), roleId ] }
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
async down(queryInterface, Sequelize) {
|
||||
await queryInterface.sequelize.query(
|
||||
`DELETE FROM \`${TABLE}\` WHERE id = 560`
|
||||
);
|
||||
},
|
||||
};
|
||||
@ -0,0 +1,17 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
async up(queryInterface, Sequelize) {
|
||||
await queryInterface.addColumn('wms_stock_warehouse', 'need_recheck', {
|
||||
type: Sequelize.CHAR(1),
|
||||
allowNull: false,
|
||||
defaultValue: 'Y',
|
||||
comment: '是否需要复核:Y=需要复核,N=不需要复核',
|
||||
after: 'is_batch_mgmt',
|
||||
});
|
||||
},
|
||||
|
||||
async down(queryInterface) {
|
||||
await queryInterface.removeColumn('wms_stock_warehouse', 'need_recheck');
|
||||
},
|
||||
};
|
||||
@ -1,4 +1,108 @@
|
||||
[
|
||||
{
|
||||
"version": "2026.08.23-stock.warehouse-need-recheck",
|
||||
"date": "2026-08-23",
|
||||
"type": "enhanced",
|
||||
"summary": "wms_stock_warehouse 新增 need_recheck(是否需要复核)字段:Y=需要复核(默认),N=不需要复核,非空。编辑(saveWarehouseStock/createWarehouseStock/getInfo/handleBatchChange)、导入(import 支持中文 需要/不需要 或 Y/N,缺省新建默认 Y、更新保留原值)、导出(仓库/外仓导出新增「是否需要复核」列,与导入列名对齐)全链路支持。",
|
||||
"methods": [
|
||||
"stock.warehouse.getInfo",
|
||||
"stock.warehouse.saveWarehouseStock",
|
||||
"stock.warehouse.createWarehouseStock",
|
||||
"stock.warehouse.import",
|
||||
"stock.warehouse.handleBatchChange",
|
||||
"stock.warehouse.export",
|
||||
"stock.warehouse.externalExport"
|
||||
],
|
||||
"notes": [
|
||||
"database/migrations/20260823150000-add-need-recheck-to-wms-stock-warehouse.js 新增迁移(CHAR(1) NOT NULL DEFAULT 'Y',comment: 是否需要复核:Y=需要复核,N=不需要复核)",
|
||||
"app/model/stock_warehouse.js 新增 need_recheck 字段定义(默认 Y、非空)",
|
||||
"app/service/systems/stock_store.js getInfo attributes 增加 need_recheck;saveWarehouseStock 解构/更新数据增加 need_recheck;createWarehouseStock 解构并默认 'Y';validateSaveParams 校验非 Y/N 值报错;handleBatchChange 白名单增加 need_recheck 并校验 Y/N;exportWarehouseStock/exportExternalWarehouseStock 行数据输出中文 需要/不需要 并新增「是否需要复核」导出列",
|
||||
"app/service/systemMethods/stock/warehouse.js saveWarehouseStock 解构并透传 need_recheck;_normalizeWarehouseImportRow 解析「是否需要复核/need_recheck/needRecheck」列并新增 _normalizeNeedRecheckValue 归一化(需要→Y,不需要→N,非法值报错,缺省不覆盖)",
|
||||
"同步更新 methods/system.json 中 getInfo/saveWarehouseStock/createWarehouseStock/import/handleBatchChange 的字段说明"
|
||||
],
|
||||
"module": "stock"
|
||||
},
|
||||
{
|
||||
"version": "2026.08.23-pick.intercepted-skip-claim-pick",
|
||||
"date": "2026-08-23",
|
||||
"type": "fixed",
|
||||
"summary": "拦截订单不再阻隔领料/拣货且不参与作业数量:pick.waveClaimScan 打印校验与领料更新跳过拦截订单(拦截未打印不阻隔领料、拦截订单不置为 claim_status=fin,响应 data 新增 intercepted_order_count);pick.query 领料前置校验仅统计非拦截未领料订单(拦截未领料不阻隔拣货,fail data 新增 intercepted_order_count);pick.createWavePickTask 新增 excludeUnclaimed 选项,普通波次(source=0)创建拣货任务计算拣货数量(order_count/任务订单/筐)时剔除未领料订单。",
|
||||
"methods": [
|
||||
"pick.waveClaimScan",
|
||||
"pick.query",
|
||||
"pick.wavePickComplete"
|
||||
],
|
||||
"notes": [
|
||||
"app/service/systemMethods/pick.js waveClaimScan 波次订单查询 attributes 增加 intercept_status,拦截订单集合不参与 unclaimed/unprinted 统计且不参与 claim_status=fin 更新",
|
||||
"app/service/systemMethods/pick.js 新增 getWaveClaimGateStats 辅助方法(统计 total/intercepted/unclaimed,unclaimed 仅计非拦截订单),query 领料门禁改用该统计",
|
||||
"app/service/systemMethods/pick.js createWavePickTask 新增 params.excludeUnclaimed(默认 false):为 true 时 attributes 增加 claim_status 并剔除 claim_status != fin 订单(未领料不参与 order_count/任务订单/筐数量);query 与 wavePickComplete 对普通波次(source=0)传 excludeUnclaimed=true(wavePickComplete 波次查询 SELECT 增加 source)",
|
||||
"同步更新 methods/system.json 中 pick.query 与 pick.waveClaimScan 的 description、400 错误说明与 response 字段"
|
||||
],
|
||||
"module": "pick"
|
||||
},
|
||||
{
|
||||
"version": "2026.08.23-returnUnpack.list-video-fields",
|
||||
"date": "2026-08-23",
|
||||
"type": "enhanced",
|
||||
"summary": "returnUnpack.list 对齐打包记录补齐视频字段:列表关联查询视频副表,每条记录新增 has_video(1=有视频记录/2=无)、video_enable(1=录像可用/2=不可用)派生字段与 videos 视频数组(id/video_url/status/camera_id/camera_name),并新增 has_video / video_enable 列表筛选(EXISTS 字面量,口径与 order.packing.list 一致)。",
|
||||
"methods": [
|
||||
"returnUnpack.list"
|
||||
],
|
||||
"notes": [
|
||||
"app/service/systems/return_unpack.js list 改 raw:false 并 include ReturnUnpackVideo as videos(deleted_at IS NULL 过滤 + Camera 关联精简字段),行数据经 _flattenVideos 输出精简视频数组;_enrichRow 对含 videos 数组的记录派生 has_video/video_enable(create 幂等复用与 detail 返回同步受益,videos 结构不变);_buildListWhere 新增 has_video/video_enable 筛选(1/2,EXISTS/NOT EXISTS 字面量)",
|
||||
"同步更新 methods/system.json 中 returnUnpack.list 的 params(where.has_video / where.video_enable)与 response list 字段说明"
|
||||
],
|
||||
"module": "returnUnpack"
|
||||
},
|
||||
{
|
||||
"version": "2026.08.22-order.print-custom-area-wave-multiply-qty",
|
||||
"date": "2026-08-22",
|
||||
"type": "enhanced",
|
||||
"summary": "面单自定义区商品明细行尾新增「波次总单数×该行商品数量」:当波次 wms_wave_batch.source=0(普通波次)且 wave_type=1 时,每条商品明细行尾追加 波次总单数 × 该行商品数量(如 500 单 × 3 件 = 1500);策略抓取波次(source=1/2)与其他波次类型不追加。",
|
||||
"methods": [
|
||||
"order.print.getOrderPrintData",
|
||||
"order.print.getWavePlatformPrintData",
|
||||
"order.print.getPrintDataByWaybillCodes"
|
||||
],
|
||||
"notes": [
|
||||
"app/service/systems/order_print.js queryWavesByIds 查询增加 source/wave_type 字段;getWavePlatformPrintData / getOrderPrintData / getPrintDataByWaybillCodes 三条路径构建 waveMetaMap 并在订单行附加 wave_source / wave_type",
|
||||
"app/lib/printer_data_builder.js buildWaybillCustomProductInfoLines 明细行构建时 waveSource=0 且 waveType=1 且 wave_total_orders>0 时行尾追加 波次总单数×qtyNumber(商品数量与乘数之间以两个空格分隔);7 个平台映射(快手/拼多多/抖音/菜鸟/小红书/视频号/京东)同步传入 waveSource/waveType",
|
||||
"更新 test/app/lib/printer_data_builder_package_material.test.js:新增 T15(source=0 且 wave_type=1 行尾乘数)与 T16(source=1 不追加乘数)",
|
||||
"同步更新 methods/system.json 中三个打印方法的 description"
|
||||
],
|
||||
"module": "order"
|
||||
},
|
||||
{
|
||||
"version": "2026.08.22-order.print-custom-area-total-qty",
|
||||
"date": "2026-08-22",
|
||||
"type": "enhanced",
|
||||
"summary": "面单打印自定义区首行在快递渠道名后新增「商品总数【n】」:n 优先取订单级商品总数(items_total,权威字段),其次商品明细数量累加,最后 items_count(商品种类数)兜底,避免订单 items 快照宽松文本(stock_id+数量)陈旧不完整导致数量偏差;覆盖菜鸟/京东/拼多多/抖音/快手/视频号/小红书全平台自定义区。",
|
||||
"methods": [
|
||||
"order.print.getOrderPrintData",
|
||||
"order.print.getWavePlatformPrintData",
|
||||
"order.print.getPrintDataByWaybillCodes"
|
||||
],
|
||||
"notes": [
|
||||
"app/lib/printer_data_builder.js buildWaybillCustomProductInfoLines 头部行在快递渠道名后追加 商品总数【n】:fallbackTotalQty(items_total)>0 时优先,否则 safeItems 逐项 resolveItemQuantity 累加,再否则 fallbackItemsCount(items_count)兜底;7 个平台映射(快手/拼多多/抖音/菜鸟/小红书/视频号/京东)分别传入 fallbackTotalQty=items_total、fallbackItemsCount=items_count",
|
||||
"更新 test/app/lib/printer_data_builder_package_material.test.js(T10 包材前缀断言排除商品总数标签、新增 T11 商品总数累加、T12 items_total 兜底优先、T13 items 快照宽松文本不完整时取 items_total、T14 无 items_total 时回退明细累加)与 test/app/service/systems/order_print.getWavePlatformPrintData.test.js(W023 头部行断言追加 商品总数【2】)",
|
||||
"同步更新 methods/system.json 中三个打印方法的 description"
|
||||
],
|
||||
"module": "order"
|
||||
},
|
||||
{
|
||||
"version": "2026.08.22-pick.query-wave-claim-gate-source0",
|
||||
"date": "2026-08-22",
|
||||
"type": "enhanced",
|
||||
"summary": "pick.query 新增领料前置校验(仅普通波次 source=0):扫描命中普通波次时,若波次内存在未领料订单(claim_status != fin)则返回 400 并携带 action=wave_claim 提示「订单未领料,请先领料后再拣货」,阻隔开始拣货(中止拣货任务创建);已全部领料或策略抓取波次(source=1/2)不拦截。",
|
||||
"methods": [
|
||||
"pick.query"
|
||||
],
|
||||
"notes": [
|
||||
"app/service/systemMethods/pick.js query 波次查询 SELECT 增加 source 字段并记录 targetWaveSource;目标波次信息校验后插入领料前置校验: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.22-stock.warehouse.import-barcode-sync",
|
||||
"date": "2026-08-22",
|
||||
|
||||
@ -11678,7 +11678,7 @@
|
||||
"list": [
|
||||
{
|
||||
"method": "order.print.getWavePlatformPrintData",
|
||||
"description": "按波次 IDs 获取平台打印中间态数据,自动过滤快递未完全分配的波次,返回 waveGroups(波次 -> 平台 -> 订单)结构",
|
||||
"description": "按波次 IDs 获取平台打印中间态数据,自动过滤快递未完全分配的波次,返回 waveGroups(波次 -> 平台 -> 订单)结构。自定义区首行在快递渠道名后追加「商品总数【n】」(n 优先取订单级商品总数 items_total,其次商品明细数量累加,最后商品种类数 items_count 兜底);当波次 source=0 且 wave_type=1 时,商品明细行尾追加「波次总单数×该行商品数量」。",
|
||||
"isNeedAuth": false,
|
||||
"isNeedLogin": true,
|
||||
"headers": [
|
||||
@ -12162,7 +12162,7 @@
|
||||
},
|
||||
{
|
||||
"method": "order.print.getOrderPrintData",
|
||||
"description": "按订单ID拉取平台打印中间态数据,与 getWavePlatformPrintData 返回结构一致。不限制打印锁定状态,所有订单(包括已锁定)统一返回。仓库ID统一从当前上下文获取,无需调用方传入。自动过滤快递未完全分配的订单(post_status !== 'fin'),返回 waveGroups(波次 -> 平台 -> 订单)结构。",
|
||||
"description": "按订单ID拉取平台打印中间态数据,与 getWavePlatformPrintData 返回结构一致。不限制打印锁定状态,所有订单(包括已锁定)统一返回。仓库ID统一从当前上下文获取,无需调用方传入。自动过滤快递未完全分配的订单(post_status !== 'fin'),返回 waveGroups(波次 -> 平台 -> 订单)结构。自定义区首行在快递渠道名后追加「商品总数【n】」(n 优先取订单级商品总数 items_total,其次商品明细数量累加,最后商品种类数 items_count 兜底);当波次 source=0 且 wave_type=1 时,商品明细行尾追加「波次总单数×该行商品数量」。",
|
||||
"isNeedAuth": false,
|
||||
"isNeedLogin": true,
|
||||
"headers": [
|
||||
@ -12383,7 +12383,7 @@
|
||||
},
|
||||
{
|
||||
"method": "order.print.getPrintDataByWaybillCodes",
|
||||
"description": "按运单号数组拉取平台打印中间态数据,与 getOrderPrintData 返回结构一致。支持子单号(business_key>1):主面单与现有逻辑一致,子面单使用主订单数据构建打印数据并在自定义区追加「子单号【{business_key}】-{主单号}」行。仓库ID统一从当前上下文获取。自动过滤快递未完全分配的订单(post_status !== 'fin'),返回 waveGroups(波次 -> 平台 -> 订单)结构。",
|
||||
"description": "按运单号数组拉取平台打印中间态数据,与 getOrderPrintData 返回结构一致。支持子单号(business_key>1):主面单与现有逻辑一致,子面单使用主订单数据构建打印数据并在自定义区追加「子单号【{business_key}】-{主单号}」行。仓库ID统一从当前上下文获取。自动过滤快递未完全分配的订单(post_status !== 'fin'),返回 waveGroups(波次 -> 平台 -> 订单)结构。自定义区首行在快递渠道名后追加「商品总数【n】」(n 优先取订单级商品总数 items_total,其次商品明细数量累加,最后商品种类数 items_count 兜底);当波次 source=0 且 wave_type=1 时,商品明细行尾追加「波次总单数×该行商品数量」。",
|
||||
"isNeedAuth": false,
|
||||
"isNeedLogin": true,
|
||||
"headers": [
|
||||
@ -17098,7 +17098,14 @@
|
||||
}
|
||||
],
|
||||
"params": [],
|
||||
"response": [],
|
||||
"response": [
|
||||
{
|
||||
"name": "need_recheck",
|
||||
"type": "string",
|
||||
"required": true,
|
||||
"description": "是否需要复核:Y=需要复核,N=不需要复核"
|
||||
}
|
||||
],
|
||||
"errors": []
|
||||
},
|
||||
{
|
||||
@ -17170,7 +17177,15 @@
|
||||
"description": "Bearer token"
|
||||
}
|
||||
],
|
||||
"params": [],
|
||||
"params": [
|
||||
{
|
||||
"name": "need_recheck",
|
||||
"type": "string",
|
||||
"required": false,
|
||||
"source": "body",
|
||||
"description": "是否需要复核:Y=需要复核,N=不需要复核(非 Y/N 值会报错)"
|
||||
}
|
||||
],
|
||||
"response": [],
|
||||
"errors": []
|
||||
},
|
||||
@ -17187,7 +17202,15 @@
|
||||
"description": "Bearer token"
|
||||
}
|
||||
],
|
||||
"params": [],
|
||||
"params": [
|
||||
{
|
||||
"name": "need_recheck",
|
||||
"type": "string",
|
||||
"required": false,
|
||||
"source": "body",
|
||||
"description": "是否需要复核:Y=需要复核,N=不需要复核;缺省默认 Y(需要复核)"
|
||||
}
|
||||
],
|
||||
"response": [],
|
||||
"errors": []
|
||||
},
|
||||
@ -17257,6 +17280,12 @@
|
||||
"type": "number",
|
||||
"description": "零售价"
|
||||
},
|
||||
{
|
||||
"name": "是否需要复核 / need_recheck / needRecheck",
|
||||
"type": "string",
|
||||
"required": false,
|
||||
"description": "是否需要复核,支持中文 需要/不需要 或 Y/N;缺省时新建按需要复核(Y)处理,更新保留原值"
|
||||
},
|
||||
{
|
||||
"name": "条码 / bar_code / barCode / barcodeList / barcode_list / barcode",
|
||||
"type": "string",
|
||||
@ -17607,14 +17636,14 @@
|
||||
"type": "string",
|
||||
"required": true,
|
||||
"source": "body",
|
||||
"description": "要修改的字段名,可选值:brand_name、prohibited_id、gross_weight、packing_requirements、managementFlags、stock_unit"
|
||||
"description": "要修改的字段名,可选值:brand_name、prohibited_id、gross_weight、packing_requirements、managementFlags、stock_unit、need_recheck"
|
||||
},
|
||||
{
|
||||
"name": "value",
|
||||
"type": "string|number|object",
|
||||
"required": true,
|
||||
"source": "body",
|
||||
"description": "修改值,类型依 method 而定:brand_name/packing_requirements/stock_unit 为 string(<=255 字符);prohibited_id 为 number(整数);gross_weight 为 number(正整数,单位 g);managementFlags 为 object,必须包含 is_sn_mgmt/is_shelf_life_mgmt/is_batch_mgmt,值为 'Y' 或 'N'"
|
||||
"description": "修改值,类型依 method 而定:brand_name/packing_requirements/stock_unit 为 string(<=255 字符);prohibited_id 为 number(整数);gross_weight 为 number(正整数,单位 g);managementFlags 为 object,必须包含 is_sn_mgmt/is_shelf_life_mgmt/is_batch_mgmt,值为 'Y' 或 'N';need_recheck 为 string,仅支持 'Y'(需要复核)/ 'N'(不需要复核)"
|
||||
},
|
||||
{
|
||||
"name": "values",
|
||||
@ -18694,7 +18723,7 @@
|
||||
"list": [
|
||||
{
|
||||
"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;若活动任务归属他人则返回冲突提示。新增领单前置校验:扫描命中的波次属于普通波次(wms_wave_batch.source=0)时,若波次内存在未领料订单(claim_status != fin,拦截订单除外)则返回 400 并携带 action=wave_claim 提示「订单未领料,请先领料后再拣货」(pick.waveClaimScan),中止拣货任务创建;拦截订单未领料不阻隔拣货,且创建任务计算拣货数量时剔除未领料订单(拦截订单也不入任务)。",
|
||||
"isNeedAuth": false,
|
||||
"isNeedLogin": true,
|
||||
"headers": [
|
||||
@ -18737,7 +18766,7 @@
|
||||
"errors": [
|
||||
{
|
||||
"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 为空、缺少仓库上下文、目标波次信息不完整、散单波次无可用订单);普通波次(source=0)存在非拦截未领料订单时中止建任务并提示「订单未领料,请先领料后再拣货」(失败 data 含 action=wave_claim、wave_id、wave_no、wave_type、wave_source、pick_mode、unclaimed_order_count、intercepted_order_count、total_order_count,拦截订单未领料不阻隔)。"
|
||||
},
|
||||
{
|
||||
"code": 401,
|
||||
@ -19560,7 +19589,7 @@
|
||||
},
|
||||
{
|
||||
"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 幂等结果并提示已领料。",
|
||||
"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、intercepted_order_count,拦截订单未打印不阻隔领料);拦截订单整体跳过领料(不置为 fin);策略抓取波次(source=1/2)无需领料,返回 400 并提示「该波次为抓取波次,无需领料」(失败 data 含 no_claim_needed=true、wave_id、wave_no);面单号查不到订单或订单不在待处理订单表返回 404 提示无记录;波次内订单已全部领料时返回 already_claimed 幂等结果并提示已领料。",
|
||||
"isNeedAuth": false,
|
||||
"isNeedLogin": true,
|
||||
"isNeedRight": false,
|
||||
@ -19630,6 +19659,12 @@
|
||||
"required": true,
|
||||
"description": "波次下订单总数"
|
||||
},
|
||||
{
|
||||
"name": "intercepted_order_count",
|
||||
"type": "number",
|
||||
"required": true,
|
||||
"description": "波次下拦截订单数(拦截订单跳过领料,其未打印/未领料状态不阻隔领料与拣货)"
|
||||
},
|
||||
{
|
||||
"name": "claimed_order_count",
|
||||
"type": "number",
|
||||
@ -19652,7 +19687,7 @@
|
||||
"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);其余不支持类型返回通用提示。"
|
||||
"message": "参数错误(waybill_no 为空、缺少仓库上下文、订单未分配波次、波次下无可用订单);波次下存在未打印订单(拦截订单除外)返回「波次未打印,禁止领料」(data 含 wave_id、wave_no、unprinted_order_count、intercepted_order_count);策略抓取波次(source=1/2)返回「该波次为抓取波次,无需领料」(data 含 no_claim_needed=true、wave_id、wave_no);其余不支持类型返回通用提示。"
|
||||
},
|
||||
{
|
||||
"code": 401,
|
||||
@ -36896,6 +36931,20 @@
|
||||
"source": "body.where",
|
||||
"description": "原订单ID(等值)"
|
||||
},
|
||||
{
|
||||
"name": "where.has_video",
|
||||
"type": "number",
|
||||
"required": false,
|
||||
"source": "body.where",
|
||||
"description": "是否有视频记录(等值):1=有视频记录 2=无视频记录"
|
||||
},
|
||||
{
|
||||
"name": "where.video_enable",
|
||||
"type": "number",
|
||||
"required": false,
|
||||
"source": "body.where",
|
||||
"description": "录像是否可用(等值):1=可用(存在 video_url 非空且 status!=failed 的记录) 2=不可用"
|
||||
},
|
||||
{
|
||||
"name": "sort",
|
||||
"type": "object",
|
||||
@ -36909,7 +36958,7 @@
|
||||
"name": "list",
|
||||
"type": "array",
|
||||
"required": true,
|
||||
"description": "拆包单列表,每条含主表字段 + is_original_return 派生字段 + 格式化时间字段 + camera_ids 数组"
|
||||
"description": "拆包单列表,每条含主表字段 + is_original_return 派生字段 + 格式化时间字段 + camera_ids 数组 + 视频派生字段 has_video(1=有视频记录/2=无)与 video_enable(1=录像可用/2=不可用)+ videos 视频数组(id/video_url/status/camera_id/camera_name)"
|
||||
},
|
||||
{
|
||||
"name": "pagination",
|
||||
|
||||
@ -898,7 +898,8 @@ describe('test/app/service/systems/order_print.getWavePlatformPrintData.test.js'
|
||||
|
||||
const customContent = result.print_data.contents.find(content => content && content.data && Array.isArray(content.data.list));
|
||||
assert.ok(customContent);
|
||||
assert.equal(customContent.data.list[0].text, 'W023 中通\r');
|
||||
// 头部行:波次号 + 快递渠道名 + 商品总数【n】(无商品明细时回退 items_total/items_count)
|
||||
assert.equal(customContent.data.list[0].text, 'W023 中通 商品总数【2】\r');
|
||||
});
|
||||
|
||||
it('should render detail lines from non-json string items', () => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user