1
This commit is contained in:
parent
21949b9a14
commit
43c60dd934
@ -424,12 +424,15 @@ class OrderIndexService extends OrderBaseService {
|
||||
* 规则:
|
||||
* - 单运单订单:忽略传入 waybill_code,直接更新唯一记录。
|
||||
* - 多运单订单:必须传入 waybill_code 且匹配到订单下记录。
|
||||
* - 团购波次(wave_type = 1):将同一重量批量设置到该波次下所有订单的运单上。
|
||||
*
|
||||
* @param {Object} data 请求体。
|
||||
* @param {string} [data.waybill_code] 运单号,多运单场景必填。
|
||||
* @param {number|string} data.order_id 订单ID。
|
||||
* @param {number|string} data.weighing_weight 称重重量(kg)。
|
||||
* @return {Promise<Object>} 统一成功/失败结构。
|
||||
* 单订单:{data: {order_id, waybill_code, weighing_weight}};
|
||||
* 团购批量:{data: {wave_id, wave_no, weighing_weight, success_count, total_count}}。
|
||||
*/
|
||||
async updateExpressWeighingWeight(data = {}) {
|
||||
const requestData = this.isPlainObject(data) ? data : {};
|
||||
|
||||
@ -40,9 +40,9 @@ class PendingOrderService extends OrderBaseService {
|
||||
constructor(ctx) {
|
||||
super(ctx);
|
||||
const _noNeedLogin = '';
|
||||
const _noNeedRight = 'list,pendingOrder,reverseReviewOrder,markPendingOutboundOrder,cancelOrder,allocateExpressCode,allocateStorage,allocateStorageProgress,cancelAllocateStorage,syncOrderIds,updateOrderPlatform,updateOrderExpress,updateAddress,cloneOrder,createOrder,downloadCreateTemplate,parseAddress,batchIntercept,batchInterceptTaskProgress,batchLock,batchLockTaskProgress,batchUnlock,batchUnlockTaskProgress,batchUnintercept,batchUninterceptTaskProgress';
|
||||
const _noNeedLog = 'list,markPendingOutboundOrder,cancelOrder,allocateExpressCode,allocateStorage,allocateStorageProgress,cancelAllocateStorage,syncOrderIds,parseAddress,batchIntercept,batchInterceptTaskProgress,batchLock,batchLockTaskProgress,batchUnlock,batchUnlockTaskProgress,batchUnintercept,batchUninterceptTaskProgress';
|
||||
const _noNeedAuth = 'list,pendingOrder,reverseReviewOrder,markPendingOutboundOrder,cancelOrder,allocateExpressCode,allocateStorage,allocateStorageProgress,cancelAllocateStorage,syncOrderIds,updateOrderPlatform,updateOrderExpress,updateAddress,cloneOrder,createOrder,downloadCreateTemplate,parseAddress,batchIntercept,batchInterceptTaskProgress,batchLock,batchLockTaskProgress,batchUnlock,batchUnlockTaskProgress,batchUnintercept,batchUninterceptTaskProgress';
|
||||
const _noNeedRight = 'list,pendingOrder,reverseReviewOrder,markPendingOutboundOrder,cancelOrder,allocateExpressCode,allocateStorage,allocateStorageProgress,cancelAllocateStorage,syncOrderIds,updateOrderPlatform,updateOrderExpress,updateAddress,cloneOrder,createOrder,downloadCreateTemplate,parseAddress,batchIntercept,batchInterceptTaskProgress,batchLock,batchLockTaskProgress,batchUnlock,batchUnlockTaskProgress,batchUnintercept,batchUninterceptTaskProgress,manualWaybill';
|
||||
const _noNeedLog = 'list,markPendingOutboundOrder,cancelOrder,allocateExpressCode,allocateStorage,allocateStorageProgress,cancelAllocateStorage,syncOrderIds,parseAddress,batchIntercept,batchInterceptTaskProgress,batchLock,batchLockTaskProgress,batchUnlock,batchUnlockTaskProgress,batchUnintercept,batchUninterceptTaskProgress,manualWaybill';
|
||||
const _noNeedAuth = 'list,pendingOrder,reverseReviewOrder,markPendingOutboundOrder,cancelOrder,allocateExpressCode,allocateStorage,allocateStorageProgress,cancelAllocateStorage,syncOrderIds,updateOrderPlatform,updateOrderExpress,updateAddress,cloneOrder,createOrder,downloadCreateTemplate,parseAddress,batchIntercept,batchInterceptTaskProgress,batchLock,batchLockTaskProgress,batchUnlock,batchUnlockTaskProgress,batchUnintercept,batchUninterceptTaskProgress,manualWaybill';
|
||||
this.systemInit(_noNeedLogin, _noNeedRight, _noNeedLog, _noNeedAuth);
|
||||
}
|
||||
|
||||
@ -1945,7 +1945,7 @@ class PendingOrderService extends OrderBaseService {
|
||||
2. **利用你的中国地理知识**:如果地址包含村/镇/街道/社区名称,请检索你的知识库推测它所属的省市区。例如:
|
||||
- "和丰一社" + 常见于广东地区村组命名 → 推测为广东省 东莞市/广州市等
|
||||
- 根据地址中的方言特征、命名习惯推测所在区域
|
||||
3. 如果实在无法确定,province填"暂未识别",city和area同理填"暂未识别"
|
||||
3. 如果实在无法确定,province填"",city和area同理填"",收件人和name同理填"",mobile同理填""。
|
||||
4. detailAddress去除省市区部分,只保留街道/村/门牌号
|
||||
5. 只返回纯JSON,不含解释或markdown
|
||||
|
||||
@ -2089,19 +2089,8 @@ class PendingOrderService extends OrderBaseService {
|
||||
throw new Error('订单明细 items 不能为空');
|
||||
}
|
||||
|
||||
// 2. 批量查询商品信息(利用 getItemInfoWithCache 的 Redis 缓存)
|
||||
const itemIds = rawItems
|
||||
.map(item => Number(item && item.item_id))
|
||||
.filter(id => Number.isInteger(id) && id > 0);
|
||||
const itemInfoMap = new Map();
|
||||
for (const itemId of itemIds) {
|
||||
const info = await this.service.systems.stockStore.getItemInfoWithCache(itemId);
|
||||
if (info && !info.__isNull) {
|
||||
itemInfoMap.set(itemId, info);
|
||||
}
|
||||
}
|
||||
|
||||
// 3. 适配明细格式并校验(转为 addOrder 所需的驼峰格式)
|
||||
// 2. 适配明细格式并校验(转为 addOrder 所需的驼峰格式)
|
||||
// 手工单:item_id 即为仓库 stock_id,无需查 stock_store 做映射
|
||||
const orderLineItems = rawItems.map((item, idx) => {
|
||||
if (!item || typeof item !== 'object') {
|
||||
throw new Error(`第${idx + 1}行明细格式无效`);
|
||||
@ -2115,22 +2104,20 @@ class PendingOrderService extends OrderBaseService {
|
||||
throw new Error(`第${idx + 1}行计划数量 plan_qty 必须为正整数`);
|
||||
}
|
||||
return {
|
||||
itemCode: String(item.item_code || '').trim()
|
||||
|| String(itemInfoMap.get(itemId)?.item_code || '').trim(),
|
||||
itemCode: String(item.item_code || '').trim(),
|
||||
itemId,
|
||||
itemName: String(item.item_name || '').trim()
|
||||
|| String(itemInfoMap.get(itemId)?.item_name || '').trim()
|
||||
|| '商品',
|
||||
itemName: String(item.item_name || '').trim() || '商品',
|
||||
planQty,
|
||||
stockId: itemId,
|
||||
orderLineNo: String(item.order_line_no || String(idx + 1)).trim(),
|
||||
actualPrice: Number(item.actual_price) || 0,
|
||||
};
|
||||
});
|
||||
|
||||
// 4. 自动生成订单号(如未传)
|
||||
// 3. 自动生成订单号(如未传)
|
||||
const deliveryOrderCode = String(requestData.delivery_order_code || '').trim()
|
||||
|| `SYS${Date.now()}${Math.floor(Math.random() * 9000) + 1000}`;
|
||||
// 5. 适配为 addOrder 所需的奇门嵌套格式
|
||||
// 4. 适配为 addOrder 所需的奇门嵌套格式
|
||||
const adaptedData = {
|
||||
request: {
|
||||
deliveryOrder: {
|
||||
@ -4417,6 +4404,96 @@ class PendingOrderService extends OrderBaseService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 手工录入运单号。
|
||||
*
|
||||
* 为指定待处理订单创建一条运单记录(wms_order_express 表),
|
||||
* 仅允许 step 在 [1,2,3] 且 outbound_status 不为 'padding' 的订单操作。
|
||||
*
|
||||
* @param {Object} data 请求体。
|
||||
* @param {number|string} data.order_id 订单ID(必填)。
|
||||
* @param {string} data.waybill_code 运单号(必填)。
|
||||
* @return {Promise<Object>} 统一 success 包装,含创建的运单记录。
|
||||
*/
|
||||
async manualWaybill(data = {}) {
|
||||
const requestData = this.isPlainObject(data) ? data : {};
|
||||
const warehouseId = this.getWarehouseId();
|
||||
const operator = this.getOrderLogOperator();
|
||||
const logWarehouseId = this.getOrderLogWarehouseId(warehouseId);
|
||||
|
||||
// 1. 参数校验
|
||||
const orderId = Number(requestData.order_id);
|
||||
if (!Number.isInteger(orderId) || orderId <= 0) {
|
||||
throw new Error('order_id 必须为正整数');
|
||||
}
|
||||
|
||||
const waybillCode = String(requestData.waybill_code || '').trim();
|
||||
if (!waybillCode) {
|
||||
throw new Error('waybill_code(运单号)不能为空');
|
||||
}
|
||||
|
||||
// 2. 查询订单并校验状态(待处理:step in [1,2,3] 且 outbound_status != 'padding')
|
||||
const model = await this.getOrderModel('order', warehouseId);
|
||||
const where = this.buildOrderWhere([orderId], warehouseId);
|
||||
const order = await model.findOne({
|
||||
where,
|
||||
attributes: ['id', 'step', 'outbound_status', 'warehouse_id'],
|
||||
raw: true,
|
||||
});
|
||||
|
||||
if (!order) {
|
||||
throw new Error(`订单 ${orderId} 不存在或不属于当前仓库`);
|
||||
}
|
||||
|
||||
const allowedSteps = new Set([1, 2, 3]);
|
||||
if (!allowedSteps.has(order.step)) {
|
||||
throw new Error(`订单 ${orderId} 当前步骤为 ${order.step},仅允许待处理状态(step 1/2/3)的订单手工录入运单号`);
|
||||
}
|
||||
|
||||
if (order.outbound_status === PENDING_OUTBOUND_STATUS) {
|
||||
throw new Error(`订单 ${orderId} 已标记待出库,不允许手工录入运单号`);
|
||||
}
|
||||
|
||||
// 3. 创建运单记录
|
||||
const orderExpressModel = this.ctx.model && this.ctx.model.OrderExpress;
|
||||
if (!orderExpressModel) {
|
||||
throw new Error('OrderExpress 模型未加载');
|
||||
}
|
||||
|
||||
const expressRecord = await orderExpressModel.create({
|
||||
order_id: orderId,
|
||||
waybill_code: waybillCode,
|
||||
create_at: new Date(),
|
||||
});
|
||||
|
||||
// 4. 记录操作日志
|
||||
try {
|
||||
await this.ctx.service.systems.operationLog.createOperationLog({
|
||||
businessType: 'order',
|
||||
businessId: logWarehouseId,
|
||||
operationCode: 'ORDER_MANUAL_WAYBILL',
|
||||
operator,
|
||||
extras: {
|
||||
warehouseId: logWarehouseId,
|
||||
orderId,
|
||||
waybillCode,
|
||||
expressRecordId: expressRecord.id,
|
||||
message: `手工录入运单号:订单 ${orderId},运单号 ${waybillCode}`,
|
||||
},
|
||||
beforeChanges: null,
|
||||
});
|
||||
} catch (logErr) {
|
||||
this.ctx.logger.warn('[PendingOrderService.manualWaybill] 写入操作日志失败,不影响业务', logErr);
|
||||
}
|
||||
|
||||
return this.success('ok', {
|
||||
id: expressRecord.id,
|
||||
order_id: orderId,
|
||||
waybill_code: waybillCode,
|
||||
create_at: expressRecord.create_at,
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = PendingOrderService;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -1022,6 +1022,15 @@ class WaveService extends OrderBaseService {
|
||||
}
|
||||
}
|
||||
|
||||
if (allWaveIds.length > 0 && allOrderIds.length > 0) {
|
||||
await this.replaceOrderWaveIndexByWaveIds({
|
||||
warehouseId,
|
||||
waveIds: allWaveIds,
|
||||
orderModel: model,
|
||||
transaction,
|
||||
});
|
||||
}
|
||||
|
||||
await transaction.commit();
|
||||
await this.batchCreateOrderOperationLogs(fetchedOrderLogItems, {
|
||||
warehouseId,
|
||||
@ -1941,7 +1950,11 @@ class WaveService extends OrderBaseService {
|
||||
|
||||
for (const row of itemRows) {
|
||||
const normalized = this.normalizeOrderItemRow(row);
|
||||
if (!normalized.item_code || normalized.quantity <= 0) {
|
||||
const hasIdentity = normalized.stock_id > 0
|
||||
|| normalized.item_code
|
||||
|| normalized.item_name;
|
||||
|
||||
if (!hasIdentity || normalized.quantity <= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -6642,6 +6655,14 @@ class WaveService extends OrderBaseService {
|
||||
});
|
||||
}
|
||||
|
||||
await this.rebuildOrderWaveIndex({
|
||||
warehouseId,
|
||||
waveId,
|
||||
orderIds: grabbedOrderIds,
|
||||
orderModel,
|
||||
transaction,
|
||||
});
|
||||
|
||||
await transaction.commit();
|
||||
|
||||
await this.batchCreateOrderOperationLogs(grabbedOrderIds.map(orderId => ({
|
||||
@ -10604,10 +10625,34 @@ class WaveService extends OrderBaseService {
|
||||
const taskId = Number(taskCreateResult.task_id || 0);
|
||||
const taskNo = String(taskCreateResult.task_no || '').trim();
|
||||
|
||||
// 查询所有选中波次的 wave_no,用于填充任务波次关联记录
|
||||
let waveNoMap = new Map();
|
||||
if (selectedWaveIds.length > 0) {
|
||||
const waveNoRows = await this.ctx.model.query(
|
||||
`SELECT wave_id, wave_no
|
||||
FROM wms_wave_batch
|
||||
WHERE wave_id IN (:waveIds)
|
||||
AND warehouse_id = :warehouseId`,
|
||||
{
|
||||
replacements: { waveIds: selectedWaveIds, warehouseId },
|
||||
type: this.ctx.model.QueryTypes.SELECT,
|
||||
transaction,
|
||||
}
|
||||
);
|
||||
for (const row of Array.isArray(waveNoRows) ? waveNoRows : []) {
|
||||
const wid = Number(row && row.wave_id || 0);
|
||||
const wno = String(row && row.wave_no || '').trim();
|
||||
if (wid > 0 && wno) {
|
||||
waveNoMap.set(wid, wno);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const taskWaveRows = this.buildTaskWaveRows({
|
||||
taskId,
|
||||
plan: effectivePlan,
|
||||
selectedWaveIds,
|
||||
waveNoMap,
|
||||
});
|
||||
const taskOrderRows = this.buildTaskOrderRows({
|
||||
taskId,
|
||||
@ -10756,13 +10801,14 @@ class WaveService extends OrderBaseService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建任务与波次关联写入行。
|
||||
* 构建任务波次关联写入行。
|
||||
*
|
||||
* @param {Object} options 构建参数。
|
||||
* @param {number} options.taskId 任务ID。
|
||||
* @param {Object} options.plan 预处理计划。
|
||||
* @param {Array<number>} options.selectedWaveIds 已选波次ID。
|
||||
* @return {Array<Object>} 任务波次行。
|
||||
* @param {Map<number, string>} [options.waveNoMap] wave_id → wave_no 映射。
|
||||
* @return {Array<Object>} 任务波次关联行。
|
||||
*/
|
||||
buildTaskWaveRows(options = {}) {
|
||||
const taskId = Number(options && options.taskId || 0);
|
||||
@ -10771,11 +10817,14 @@ class WaveService extends OrderBaseService {
|
||||
const selectedWaveIds = Array.isArray(options && options.selectedWaveIds)
|
||||
? options.selectedWaveIds
|
||||
: [];
|
||||
const waveNoMap = options && options.waveNoMap instanceof Map
|
||||
? options.waveNoMap
|
||||
: new Map();
|
||||
|
||||
return selectedWaveIds.map((waveId, index) => ({
|
||||
task_id: taskId,
|
||||
wave_id: waveId,
|
||||
wave_no: null,
|
||||
wave_no: waveNoMap.get(waveId) || null,
|
||||
box_no: index + 1,
|
||||
status: 0,
|
||||
bind_time: null,
|
||||
@ -11545,11 +11594,12 @@ class WaveService extends OrderBaseService {
|
||||
/**
|
||||
* 公共拣货任务取消流程。
|
||||
*
|
||||
* 仅允许取消状态为 0/1/2/3 的任务。取消后会回收拣货车绑定、
|
||||
* 删除任务关联波次并将订单 wave_id 清空,使订单可重新参与后续策略抓取。
|
||||
* 当任务状态为 2(待复核)或 3(已完成)时,还会回退已拣货订单的
|
||||
* wms_wave_pick_task_order.pick_status 和 order_delivery.pick_status,
|
||||
* 使订单恢复为未拣货状态。
|
||||
* 仅允许取消状态为 0/1/2/3 的任务。取消后会回收拣货车绑定。
|
||||
*
|
||||
* 按任务来源区分行为:
|
||||
* - source=1(PDA 抓取):释放关联波次(清空订单 wave_id、删除 wms_wave_batch),
|
||||
* 使订单可重新参与后续策略抓取;状态为 2/3 时还会回退拣货状态。
|
||||
* - source=2(后台/扫描创建):不释放波次,仅作废任务(更新状态为 9、解绑拣货车)。
|
||||
*
|
||||
* @param {Object} [params={}] 取消参数。
|
||||
* @param {Array<number>} params.taskIds 任务ID列表。
|
||||
@ -11617,7 +11667,7 @@ class WaveService extends OrderBaseService {
|
||||
for (const taskId of normalizedTaskIds) {
|
||||
const requestId = `wave_pick_task_cancel_${warehouseId}_${taskId}_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`;
|
||||
const taskRows = await this.ctx.model.query(`
|
||||
SELECT id, task_no, warehouse_id, status, current_cart_id
|
||||
SELECT id, task_no, warehouse_id, status, current_cart_id, source
|
||||
FROM wms_wave_pick_task
|
||||
WHERE id = :taskId
|
||||
AND warehouse_id = :warehouseId
|
||||
@ -11685,6 +11735,7 @@ class WaveService extends OrderBaseService {
|
||||
throw error;
|
||||
}
|
||||
|
||||
const taskSource = Number(taskRow.source || 0);
|
||||
const taskNo = String(taskRow.task_no || '').trim();
|
||||
|
||||
const taskWaveRows = await this.ctx.model.query(`
|
||||
@ -11721,46 +11772,52 @@ class WaveService extends OrderBaseService {
|
||||
.map(row => Number(row && row.order_id || 0))
|
||||
.filter(orderId => Number.isInteger(orderId) && orderId > 0)) ];
|
||||
|
||||
// source=2(后台/扫描创建)不释放波次,仅清理任务-波次关联
|
||||
const isScanCreated = taskSource === 2;
|
||||
let releasedWaveRows = [];
|
||||
if (waveIds.length > 0) {
|
||||
releasedWaveRows = await this.ctx.model.query(`
|
||||
SELECT wave_id, wave_no
|
||||
FROM wms_wave_batch
|
||||
WHERE warehouse_id = :warehouseId
|
||||
AND wave_id IN (:waveIds)
|
||||
FOR UPDATE
|
||||
`, {
|
||||
replacements: {
|
||||
warehouseId,
|
||||
waveIds,
|
||||
},
|
||||
type: this.ctx.model.QueryTypes.SELECT,
|
||||
transaction,
|
||||
});
|
||||
if (!isScanCreated) {
|
||||
// PDA 抓取:释放波次
|
||||
releasedWaveRows = await this.ctx.model.query(`
|
||||
SELECT wave_id, wave_no
|
||||
FROM wms_wave_batch
|
||||
WHERE warehouse_id = :warehouseId
|
||||
AND wave_id IN (:waveIds)
|
||||
FOR UPDATE
|
||||
`, {
|
||||
replacements: {
|
||||
warehouseId,
|
||||
waveIds,
|
||||
},
|
||||
type: this.ctx.model.QueryTypes.SELECT,
|
||||
transaction,
|
||||
});
|
||||
|
||||
await orderModel.update({
|
||||
wave_id: 0,
|
||||
wave_no: '',
|
||||
}, {
|
||||
where: {
|
||||
warehouse_id: warehouseId,
|
||||
wave_id: { [Op.in]: waveIds },
|
||||
},
|
||||
transaction,
|
||||
});
|
||||
await orderModel.update({
|
||||
wave_id: 0,
|
||||
wave_no: '',
|
||||
}, {
|
||||
where: {
|
||||
warehouse_id: warehouseId,
|
||||
wave_id: { [Op.in]: waveIds },
|
||||
},
|
||||
transaction,
|
||||
});
|
||||
|
||||
await this.ctx.model.query(`
|
||||
DELETE FROM wms_wave_batch
|
||||
WHERE warehouse_id = :warehouseId
|
||||
AND wave_id IN (:waveIds)
|
||||
`, {
|
||||
replacements: {
|
||||
warehouseId,
|
||||
waveIds,
|
||||
},
|
||||
transaction,
|
||||
});
|
||||
await this.ctx.model.query(`
|
||||
DELETE FROM wms_wave_batch
|
||||
WHERE warehouse_id = :warehouseId
|
||||
AND wave_id IN (:waveIds)
|
||||
`, {
|
||||
replacements: {
|
||||
warehouseId,
|
||||
waveIds,
|
||||
},
|
||||
transaction,
|
||||
});
|
||||
}
|
||||
|
||||
// 清理任务-波次关联(所有来源都需要)
|
||||
await this.ctx.model.query(`
|
||||
DELETE FROM wms_wave_pick_task_wave
|
||||
WHERE task_id = :taskId
|
||||
@ -11774,8 +11831,8 @@ class WaveService extends OrderBaseService {
|
||||
});
|
||||
}
|
||||
|
||||
// 当任务状态为待复核(2)或已完成(3)时,回退订单拣货状态
|
||||
if ([ 2, 3 ].includes(taskStatus)) {
|
||||
// 当任务状态为待复核(2)或已完成(3)时,回退订单拣货状态(仅 PDA 抓取)
|
||||
if (!isScanCreated && [ 2, 3 ].includes(taskStatus)) {
|
||||
await this.ctx.model.query(`
|
||||
UPDATE wms_wave_pick_task_order
|
||||
SET pick_status = 0,
|
||||
@ -11887,8 +11944,9 @@ class WaveService extends OrderBaseService {
|
||||
seq_no: 1,
|
||||
snapshot: JSON.stringify({
|
||||
task_no: taskNo,
|
||||
released_wave_ids: waveIds,
|
||||
released_order_count: taskOrderIds.length,
|
||||
source: taskSource,
|
||||
released_wave_ids: isScanCreated ? [] : waveIds,
|
||||
released_order_count: isScanCreated ? 0 : taskOrderIds.length,
|
||||
}),
|
||||
}], transaction);
|
||||
|
||||
@ -11904,16 +11962,21 @@ class WaveService extends OrderBaseService {
|
||||
review_time: null,
|
||||
review_result: null,
|
||||
event_type: 'task_cancelled',
|
||||
event_desc: `任务取消并释放波次: ${taskNo || taskId}`,
|
||||
event_desc: isScanCreated
|
||||
? `任务取消(未释放波次): ${taskNo || taskId}`
|
||||
: `任务取消并释放波次: ${taskNo || taskId}`,
|
||||
operator_id: Number.isInteger(operatorId) ? operatorId : 0,
|
||||
operator_name: operatorName,
|
||||
snapshot: JSON.stringify({
|
||||
task_no: taskNo,
|
||||
released_wave_ids: waveIds,
|
||||
released_order_count: taskOrderIds.length,
|
||||
released_wave_nos: (Array.isArray(releasedWaveRows) ? releasedWaveRows : [])
|
||||
.map(row => String(row && row.wave_no || '').trim())
|
||||
.filter(Boolean),
|
||||
source: taskSource,
|
||||
released_wave_ids: isScanCreated ? [] : waveIds,
|
||||
released_order_count: isScanCreated ? 0 : taskOrderIds.length,
|
||||
released_wave_nos: isScanCreated
|
||||
? []
|
||||
: (Array.isArray(releasedWaveRows) ? releasedWaveRows : [])
|
||||
.map(row => String(row && row.wave_no || '').trim())
|
||||
.filter(Boolean),
|
||||
}),
|
||||
}], transaction);
|
||||
|
||||
|
||||
@ -93,7 +93,7 @@ class PickService extends MainService {
|
||||
* @param {string} params.operatorName 操作人名称。
|
||||
* @param {Array<number>} params.orderIds 波次订单ID集合。
|
||||
* @param {string} [params.remark=''] 备注。
|
||||
* @param {number} [params.source=2] 任务来源:1-PDA扫码补任务,2-后台抓取,默认为2。
|
||||
* @param {number} [params.source=2] 任务来源:1-PDA抓取创建,2-扫描进任务/后台抓取,默认为2。
|
||||
* @return {Promise<{task_id: number, task_no: string}>} 创建结果。
|
||||
*/
|
||||
async createWavePickTask(params = {}) {
|
||||
@ -651,7 +651,7 @@ class PickService extends MainService {
|
||||
operatorName,
|
||||
orderIds: selectedOrderIds,
|
||||
remark: `pick.query keyword=${normalizedKeyword}`,
|
||||
source: 1,
|
||||
source: 2,
|
||||
});
|
||||
|
||||
return this.success('ok', {
|
||||
|
||||
@ -1124,7 +1124,16 @@ class DeliveryOrderService extends Service {
|
||||
continue;
|
||||
}
|
||||
let wms_stock = null;
|
||||
if (!line.itemId) {
|
||||
// 手工单:调用方直接传入 stockId 时跳过 stock_store 查表,直接使用
|
||||
if (line.stockId && line.stockId > 0) {
|
||||
wms_stock = {
|
||||
id: line.stockId,
|
||||
stock_id: line.stockId,
|
||||
item_name: line.itemName || '',
|
||||
item_code: line.itemCode || '',
|
||||
gross_weight: 0,
|
||||
};
|
||||
} else if (!line.itemId) {
|
||||
// 查找唯一键(appKey 为空时不作为条件,兼容内部手动建单场景)
|
||||
const stockWhere = {
|
||||
item_code: line.itemCode,
|
||||
@ -1139,32 +1148,16 @@ class DeliveryOrderService extends Service {
|
||||
wms_stock = await app.model.StockStore.findByPk(line.itemId, { transaction });
|
||||
}
|
||||
|
||||
// MANUAL 渠道降级:信任调用方提供的 itemId,跳过 StockStore 校验
|
||||
const isManualFallback = createChannel === 'MANUAL' && line.itemId && !wms_stock;
|
||||
|
||||
if (!wms_stock && !isManualFallback) {
|
||||
if (!wms_stock) {
|
||||
errors.push(`商品《${line.itemName}》编码《${line.itemCode}》\n未同步推送到仓库`);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isManualFallback) {
|
||||
// 手工建单降级模式:使用调用方传入的 itemId,stockId 置 0,跳过库存锁定
|
||||
wms_stock = {
|
||||
id: line.itemId,
|
||||
stock_id: 0,
|
||||
item_name: line.itemName || '',
|
||||
item_code: line.itemCode || '',
|
||||
gross_weight: 0,
|
||||
};
|
||||
}
|
||||
|
||||
const itemId = parseInt(wms_stock.id);
|
||||
const stockId = Number(wms_stock.stock_id) || 0;
|
||||
// ========== 核心库存检查逻辑 ==========
|
||||
// MANUAL 降级时 stockId 为 0,跳过库存记录检查与锁定
|
||||
const isManualNoStock = isManualFallback && !stockId;
|
||||
|
||||
if (!stockId && !isManualNoStock) {
|
||||
if (!stockId) {
|
||||
errors.push(`第${i + 1}行: 商品《${wms_stock.item_name}》库存记录不存在`);
|
||||
continue;
|
||||
}
|
||||
@ -1175,28 +1168,23 @@ class DeliveryOrderService extends Service {
|
||||
}
|
||||
processedItemIds.add(itemId);
|
||||
|
||||
// 锁定库存(MANUAL 降级时跳过)
|
||||
if (!isManualNoStock) {
|
||||
const lockResult = await ctx.service.systems.stockStore.lockItemStorages(
|
||||
stockId,
|
||||
planQty,
|
||||
transaction
|
||||
);
|
||||
// 锁定库存
|
||||
const lockResult = await ctx.service.systems.stockStore.lockItemStorages(
|
||||
stockId,
|
||||
planQty,
|
||||
transaction
|
||||
);
|
||||
|
||||
if (!lockResult.success) {
|
||||
errors.push(`SKU${wms_stock.id}商品《${wms_stock.item_name}》编码《${wms_stock.item_code}》\n锁定失败: ${lockResult.error}`);
|
||||
continue;
|
||||
}
|
||||
|
||||
const totalQtyForStock = (stockQuantityMap.get(stockId) || 0) + planQty;
|
||||
stockQuantityMap.set(stockId, totalQtyForStock);
|
||||
if (!lockResult.success) {
|
||||
errors.push(`SKU${wms_stock.id}商品《${wms_stock.item_name}》编码《${wms_stock.item_code}》\n锁定失败: ${lockResult.error}`);
|
||||
continue;
|
||||
}
|
||||
|
||||
// 优先使用商品主数据重量,缺失时降级为0;MANUAL 降级时重量为 0
|
||||
const weight = isManualNoStock ? 0 : (parseFloat(wms_stock.gross_weight) || 0);
|
||||
if (!isManualNoStock) {
|
||||
stockWeightMap.set(stockId, weight);
|
||||
}
|
||||
const totalQtyForStock = (stockQuantityMap.get(stockId) || 0) + planQty;
|
||||
stockQuantityMap.set(stockId, totalQtyForStock);
|
||||
|
||||
const weight = parseFloat(wms_stock.gross_weight) || 0;
|
||||
stockWeightMap.set(stockId, weight);
|
||||
// ========== 库存检查逻辑结束 ==========
|
||||
|
||||
// 所有检查通过,准备订单行数据
|
||||
|
||||
@ -212,11 +212,16 @@ class OrderExpressService extends Service {
|
||||
/**
|
||||
* 更新订单运单称重重量。
|
||||
*
|
||||
* 支持团购波次批量设置:
|
||||
* - 散单(wave_id = 0)或非团购波次:仅更新单个订单的运单重量。
|
||||
* - 团购波次(wave_type = 1):将同一重量批量设置到该波次下所有订单的运单上。
|
||||
*
|
||||
* @param {Object} payload 入参对象。
|
||||
* @param {number|string} payload.orderId 订单ID。
|
||||
* @param {string} [payload.waybillCode] 运单号。
|
||||
* @param {number|string} payload.weighingWeight 称重重量。
|
||||
* @return {Promise<{order_id:number, waybill_code:string, weighing_weight:number}>} 更新结果。
|
||||
* @param {string} [payload.waybillCode] 运单号,多运单场景必填。
|
||||
* @param {number|string} payload.weighingWeight 称重重量(kg)。
|
||||
* @return {Promise<Object>} 单订单返回 {order_id, waybill_code, weighing_weight};
|
||||
* 团购批量返回 {wave_id, wave_no, weighing_weight, success_count, total_count}。
|
||||
*/
|
||||
async updateWeighingWeight(payload = {}) {
|
||||
const requestData = payload && typeof payload === 'object' ? payload : {};
|
||||
@ -230,7 +235,79 @@ class OrderExpressService extends Service {
|
||||
const normalizedWeight = this.normalizeWeighingWeight(weighingWeight);
|
||||
const normalizedWaybillCode = String(waybillCode || '').trim();
|
||||
const warehouseId = this.ctx && this.ctx.user ? this.ctx.user.store_id : null;
|
||||
const rows = await this.findValidOrderExpressRows(normalizedOrderId, warehouseId);
|
||||
|
||||
// 无法获取仓库ID时降级为单个订单逻辑
|
||||
if (!warehouseId) {
|
||||
return await this._updateSingleOrderWeight(
|
||||
normalizedOrderId, normalizedWaybillCode, normalizedWeight, warehouseId
|
||||
);
|
||||
}
|
||||
|
||||
// 查询订单所属波次
|
||||
const orderDeliveryFactory = this.ctx.model && this.ctx.model.OrderDeliveryFactory;
|
||||
if (!orderDeliveryFactory || typeof orderDeliveryFactory.getCurrentModel !== 'function') {
|
||||
throw this.createBusinessError('订单模型未初始化', 500);
|
||||
}
|
||||
|
||||
const orderDeliveryModel = await orderDeliveryFactory.getCurrentModel(warehouseId);
|
||||
const orderRow = await orderDeliveryModel.findOne({
|
||||
where: { id: normalizedOrderId, warehouse_id: warehouseId },
|
||||
attributes: [ 'id', 'wave_id', 'wave_no' ],
|
||||
raw: true,
|
||||
});
|
||||
|
||||
// 订单不存在 → 兼容前端传入 wave_id 的场景,尝试按波次查询
|
||||
if (!orderRow) {
|
||||
return await this._tryWaveCompatibility(
|
||||
normalizedOrderId, normalizedWaybillCode, normalizedWeight, warehouseId, orderDeliveryModel
|
||||
);
|
||||
}
|
||||
|
||||
const waveId = Number(orderRow.wave_id || 0);
|
||||
|
||||
// 散单 → 走单个订单逻辑
|
||||
if (waveId === 0) {
|
||||
return await this._updateSingleOrderWeight(
|
||||
normalizedOrderId, normalizedWaybillCode, normalizedWeight, warehouseId
|
||||
);
|
||||
}
|
||||
|
||||
// 查询波次类型
|
||||
const waveBatchModel = this.ctx.model && this.ctx.model.WaveBatch;
|
||||
if (!waveBatchModel || typeof waveBatchModel.findOne !== 'function') {
|
||||
throw this.createBusinessError('波次模型未初始化', 500);
|
||||
}
|
||||
|
||||
const waveRow = await waveBatchModel.findOne({
|
||||
where: { wave_id: waveId, warehouse_id: warehouseId },
|
||||
attributes: [ 'wave_id', 'wave_no', 'wave_type' ],
|
||||
raw: true,
|
||||
});
|
||||
|
||||
// 波次记录缺失或非团购波次 → 降级为单个订单逻辑
|
||||
if (!waveRow || Number(waveRow.wave_type) !== 1) {
|
||||
return await this._updateSingleOrderWeight(
|
||||
normalizedOrderId, normalizedWaybillCode, normalizedWeight, warehouseId
|
||||
);
|
||||
}
|
||||
|
||||
// 团购波次 → 批量设置同一重量
|
||||
return await this._updateWaveOrderWeight(
|
||||
waveId, String(waveRow.wave_no || ''), normalizedWeight, warehouseId, orderDeliveryModel
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新单个订单运单的称重重量(内部方法)。
|
||||
*
|
||||
* @param {number} orderId 订单ID。
|
||||
* @param {string} waybillCode 运单号。
|
||||
* @param {number} weight 称重重量。
|
||||
* @param {number|null} warehouseId 仓库ID。
|
||||
* @return {Promise<{order_id:number, waybill_code:string, weighing_weight:number}>} 更新结果。
|
||||
*/
|
||||
async _updateSingleOrderWeight(orderId, waybillCode, weight, warehouseId) {
|
||||
const rows = await this.findValidOrderExpressRows(orderId, warehouseId);
|
||||
|
||||
if (rows.length === 0) {
|
||||
throw this.createBusinessError('未找到有效的订单运单记录', 404);
|
||||
@ -240,37 +317,274 @@ class OrderExpressService extends Service {
|
||||
if (rows.length === 1) {
|
||||
targetRow = rows[0];
|
||||
} else {
|
||||
if (!normalizedWaybillCode) {
|
||||
if (!waybillCode) {
|
||||
throw this.createBusinessError('多运单订单必须传入 waybill_code', 400);
|
||||
}
|
||||
|
||||
targetRow = rows.find(row => String(row && row.waybill_code || '').trim() === normalizedWaybillCode) || null;
|
||||
targetRow = rows.find(
|
||||
row => String(row && row.waybill_code || '').trim() === waybillCode
|
||||
) || null;
|
||||
if (!targetRow) {
|
||||
throw this.createBusinessError('waybill_code 未匹配到该订单下的运单记录', 404);
|
||||
}
|
||||
}
|
||||
|
||||
const orderExpressModel = this.ctx.model && this.ctx.model.OrderExpress;
|
||||
const updateResult = await orderExpressModel.update({
|
||||
weighing_weight: normalizedWeight,
|
||||
}, {
|
||||
where: {
|
||||
id: Number(targetRow.id),
|
||||
},
|
||||
});
|
||||
const updateResult = await orderExpressModel.update(
|
||||
{ weighing_weight: weight },
|
||||
{ where: { id: Number(targetRow.id) } }
|
||||
);
|
||||
|
||||
const affectedRows = Array.isArray(updateResult) ? Number(updateResult[0] || 0) : Number(updateResult || 0);
|
||||
const affectedRows = Array.isArray(updateResult)
|
||||
? Number(updateResult[0] || 0)
|
||||
: Number(updateResult || 0);
|
||||
if (!Number.isFinite(affectedRows) || affectedRows <= 0) {
|
||||
throw this.createBusinessError('更新称重重量失败', 500);
|
||||
}
|
||||
|
||||
// 写入操作日志
|
||||
await this._writeWeighActionLog({
|
||||
orderId: Number(targetRow.order_id),
|
||||
waybillCode: String(targetRow.waybill_code || '').trim(),
|
||||
weight,
|
||||
warehouseId,
|
||||
});
|
||||
|
||||
return {
|
||||
order_id: Number(targetRow.order_id),
|
||||
waybill_code: String(targetRow.waybill_code || '').trim(),
|
||||
weighing_weight: normalizedWeight,
|
||||
weighing_weight: weight,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量更新团购波次下所有订单运单的称重重量(内部方法)。
|
||||
*
|
||||
* @param {number} waveId 波次ID。
|
||||
* @param {string} waveNo 波次号。
|
||||
* @param {number} weight 称重重量。
|
||||
* @param {number|null} warehouseId 仓库ID。
|
||||
* @param {Object} orderDeliveryModel 订单 Sequelize 模型实例。
|
||||
* @return {Promise<{wave_id:number, wave_no:string, weighing_weight:number, success_count:number, total_count:number}>}
|
||||
* 批量更新结果。
|
||||
*/
|
||||
async _updateWaveOrderWeight(waveId, waveNo, weight, warehouseId, orderDeliveryModel) {
|
||||
// 查询波次下所有订单
|
||||
const waveOrders = await orderDeliveryModel.findAll({
|
||||
where: { wave_id: waveId, warehouse_id: warehouseId },
|
||||
attributes: [ 'id' ],
|
||||
raw: true,
|
||||
});
|
||||
|
||||
if (!waveOrders || waveOrders.length === 0) {
|
||||
throw this.createBusinessError('波次下未找到订单', 404);
|
||||
}
|
||||
|
||||
const orderIds = waveOrders.map(o => Number(o.id));
|
||||
const totalCount = orderIds.length;
|
||||
|
||||
// 批量更新所有订单的运单称重重量
|
||||
const orderExpressModel = this.ctx.model && this.ctx.model.OrderExpress;
|
||||
if (!orderExpressModel || typeof orderExpressModel.update !== 'function') {
|
||||
throw this.createBusinessError('运单模型未初始化', 500);
|
||||
}
|
||||
|
||||
const { Op } = this.app.Sequelize;
|
||||
const updateResult = await orderExpressModel.update(
|
||||
{ weighing_weight: weight },
|
||||
{
|
||||
where: {
|
||||
order_id: { [Op.in]: orderIds },
|
||||
delete_at: null,
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
const successCount = Array.isArray(updateResult)
|
||||
? Number(updateResult[0] || 0)
|
||||
: Number(updateResult || 0);
|
||||
|
||||
if (!Number.isFinite(successCount) || successCount <= 0) {
|
||||
throw this.createBusinessError('批量更新称重重量失败,波次下无有效运单记录', 500);
|
||||
}
|
||||
|
||||
// 写入操作日志
|
||||
await this._writeWeighActionLog({
|
||||
waveId,
|
||||
waveNo,
|
||||
weight,
|
||||
warehouseId,
|
||||
successCount,
|
||||
totalCount,
|
||||
});
|
||||
|
||||
return {
|
||||
wave_id: waveId,
|
||||
wave_no: waveNo,
|
||||
weighing_weight: weight,
|
||||
success_count: successCount,
|
||||
total_count: totalCount,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 写入称重操作日志到 wms_wave_pick_action_log(内部方法)。
|
||||
*
|
||||
* @param {Object} params 日志参数。
|
||||
* @param {number} [params.orderId] 订单ID(单订单称重场景)。
|
||||
* @param {string} [params.waybillCode] 运单号(单订单称重场景)。
|
||||
* @param {number} [params.waveId] 波次ID(团购批量称重场景)。
|
||||
* @param {string} [params.waveNo] 波次号(团购批量称重场景)。
|
||||
* @param {number} params.weight 称重重量。
|
||||
* @param {number} params.warehouseId 仓库ID。
|
||||
* @param {number} [params.successCount] 批量更新成功数。
|
||||
* @param {number} [params.totalCount] 批量更新总数。
|
||||
* @return {Promise<void>} 无返回值。
|
||||
*/
|
||||
async _writeWeighActionLog(params = {}) {
|
||||
const {
|
||||
orderId,
|
||||
waybillCode,
|
||||
waveId,
|
||||
waveNo,
|
||||
weight,
|
||||
warehouseId,
|
||||
successCount,
|
||||
totalCount,
|
||||
} = params;
|
||||
|
||||
const ctxUser = this.ctx && this.ctx.user ? this.ctx.user : {};
|
||||
const operatorId = Number(ctxUser.employees_id || ctxUser.id || 0);
|
||||
const operatorName = String(
|
||||
ctxUser.employees_name || ctxUser.name || 'system'
|
||||
).trim();
|
||||
|
||||
const isBatch = waveId !== undefined && waveId !== null;
|
||||
const tag = isBatch ? 'weigh_batch' : 'weigh';
|
||||
const requestId = `${tag}_${warehouseId}_${isBatch ? waveId : orderId}_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`;
|
||||
|
||||
await this.ctx.model.query(
|
||||
`INSERT INTO wms_wave_pick_action_log (
|
||||
task_id,
|
||||
warehouse_id,
|
||||
wave_id,
|
||||
order_id,
|
||||
sku_id,
|
||||
location_id,
|
||||
box_no,
|
||||
cart_id,
|
||||
qty_delta,
|
||||
action_type,
|
||||
request_id,
|
||||
operator_id,
|
||||
device_id,
|
||||
seq_no,
|
||||
snapshot
|
||||
) VALUES (
|
||||
:taskId,
|
||||
:warehouseId,
|
||||
:waveId,
|
||||
:orderId,
|
||||
:skuId,
|
||||
:locationId,
|
||||
:boxNo,
|
||||
:cartId,
|
||||
:qtyDelta,
|
||||
:actionType,
|
||||
:requestId,
|
||||
:operatorId,
|
||||
:deviceId,
|
||||
:seqNo,
|
||||
:snapshot
|
||||
)`,
|
||||
{
|
||||
replacements: {
|
||||
taskId: 0,
|
||||
warehouseId: warehouseId || 0,
|
||||
waveId: isBatch ? waveId : null,
|
||||
orderId: isBatch ? null : (orderId || 0),
|
||||
skuId: null,
|
||||
locationId: null,
|
||||
boxNo: null,
|
||||
cartId: null,
|
||||
qtyDelta: 0,
|
||||
actionType: isBatch ? 'weigh_batch' : 'weigh',
|
||||
requestId,
|
||||
operatorId,
|
||||
deviceId: null,
|
||||
seqNo: 1,
|
||||
snapshot: JSON.stringify(isBatch
|
||||
? {
|
||||
wave_id: waveId,
|
||||
wave_no: waveNo || '',
|
||||
weighing_weight: weight,
|
||||
success_count: successCount,
|
||||
total_count: totalCount,
|
||||
operator_name: operatorName,
|
||||
}
|
||||
: {
|
||||
order_id: orderId,
|
||||
waybill_code: waybillCode || '',
|
||||
weighing_weight: weight,
|
||||
operator_name: operatorName,
|
||||
}),
|
||||
},
|
||||
type: this.ctx.model.QueryTypes.INSERT,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 兼容处理:当前端将 wave_id 当作 order_id 传入时,尝试按波次 ID 处理。
|
||||
*
|
||||
* 先用传入的 ID 在 wms_wave_batch 中查找波次:
|
||||
* - 波次不存在 → 抛出"订单不存在"错误。
|
||||
* - 波次存在且 wave_type = 1(团购)→ 走团购批量称重逻辑。
|
||||
* - 波次存在但 wave_type ≠ 1 → 无法确定具体订单,抛出错误提示传入正确的 order_id。
|
||||
*
|
||||
* @param {number} waveIdLike 可能是 wave_id 的数值。
|
||||
* @param {string} waybillCode 运单号(兼容参数,本路径不使用)。
|
||||
* @param {number} weight 称重重量。
|
||||
* @param {number|null} warehouseId 仓库ID。
|
||||
* @param {Object} orderDeliveryModel 订单 Sequelize 模型实例。
|
||||
* @return {Promise<Object>} 团购批量更新结果。
|
||||
* @throws {Error} 波次不存在或非团购波次时抛出业务错误。
|
||||
*/
|
||||
async _tryWaveCompatibility(waveIdLike, waybillCode, weight, warehouseId, orderDeliveryModel) {
|
||||
const waveBatchModel = this.ctx.model && this.ctx.model.WaveBatch;
|
||||
if (!waveBatchModel || typeof waveBatchModel.findOne !== 'function') {
|
||||
throw this.createBusinessError('订单不存在', 404);
|
||||
}
|
||||
|
||||
const waveRow = await waveBatchModel.findOne({
|
||||
where: { wave_id: waveIdLike, warehouse_id: warehouseId },
|
||||
attributes: [ 'wave_id', 'wave_no', 'wave_type' ],
|
||||
raw: true,
|
||||
});
|
||||
|
||||
// 波次也不存在 → 报订单不存在
|
||||
if (!waveRow) {
|
||||
throw this.createBusinessError('订单不存在', 404);
|
||||
}
|
||||
|
||||
// 非团购波次 → 无法确定具体订单,提示前端传入正确的 order_id
|
||||
if (Number(waveRow.wave_type) !== 1) {
|
||||
throw this.createBusinessError(
|
||||
`传入的 ID ${waveIdLike} 对应波次(wave_no: ${waveRow.wave_no}),非团购波次,请传入正确的 order_id`,
|
||||
400
|
||||
);
|
||||
}
|
||||
|
||||
// 团购波次 → 批量设置同一重量
|
||||
return await this._updateWaveOrderWeight(
|
||||
waveIdLike,
|
||||
String(waveRow.wave_no || ''),
|
||||
weight,
|
||||
warehouseId,
|
||||
orderDeliveryModel
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定订单快递记录的包材信息。
|
||||
* @param {Object} payload 入参对象。
|
||||
|
||||
@ -173,9 +173,14 @@ class OrderPrintSystemService extends OrderBaseService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量补查打印所需的拣货明细。
|
||||
* 批量补查打印所需的拣货明细,并注入商品多条码。
|
||||
*
|
||||
* 优先使用 wms_picking.space_name,只有缺失时才查询库位表,减少额外 SQL。
|
||||
* 同时从 wms_stock_barcodes 表批量查询每个 stock_id 对应的全部条码,
|
||||
* 注入到打印项的 barcodes 数组中,供 resolveItemBarcodeText 优先读取。
|
||||
*
|
||||
* stock_id 优先读取 wms_order_items.stock_id 列,兜底读取 item_snapshot 内的 stock_id,
|
||||
* 确保不同来源的订单明细都能正确关联到条码数据。
|
||||
*
|
||||
* @param {Array<Object>} orderRows 订单列表。
|
||||
* @param {number} warehouseId 仓库ID。
|
||||
@ -232,7 +237,7 @@ class OrderPrintSystemService extends OrderBaseService {
|
||||
[Op.in]: orderItemIds,
|
||||
},
|
||||
},
|
||||
attributes: [ 'id', 'order_id', 'item_code', 'item_name', 'plan_qty', 'item_snapshot' ],
|
||||
attributes: [ 'id', 'order_id', 'item_code', 'item_name', 'plan_qty', 'item_snapshot', 'stock_id' ],
|
||||
raw: true,
|
||||
})
|
||||
: [];
|
||||
@ -279,6 +284,10 @@ class OrderPrintSystemService extends OrderBaseService {
|
||||
pickingRowsByOrderId.set(orderId, list);
|
||||
}
|
||||
|
||||
// 阶段一:构建所有打印项并收集 stock_id
|
||||
const printItemsByOrderId = new Map();
|
||||
const allStockIds = new Set();
|
||||
|
||||
for (const orderRow of rows) {
|
||||
const orderId = Number(orderRow && orderRow.id || 0);
|
||||
const pickingList = pickingRowsByOrderId.get(orderId) || [];
|
||||
@ -312,6 +321,12 @@ class OrderPrintSystemService extends OrderBaseService {
|
||||
sku: itemSnapshot.sku,
|
||||
}, [ 'barcode', 'item_barcode', 'bar_code', 'item_code', 'sku_code', 'sku' ]);
|
||||
const quantity = Number(pickingRow && pickingRow.quantity || orderItemRow.plan_qty || 0);
|
||||
// 优先使用列 stock_id,兜底使用 item_snapshot 内的 stock_id
|
||||
const stockId = Number(orderItemRow.stock_id || itemSnapshot.stock_id || 0);
|
||||
|
||||
if (stockId > 0) {
|
||||
allStockIds.add(stockId);
|
||||
}
|
||||
|
||||
return {
|
||||
order_item_id: orderItemId,
|
||||
@ -319,6 +334,7 @@ class OrderPrintSystemService extends OrderBaseService {
|
||||
barcode,
|
||||
quantity: quantity > 0 ? quantity : 0,
|
||||
pick_location: pickLocation,
|
||||
stock_id: stockId > 0 ? stockId : undefined,
|
||||
};
|
||||
}).filter(item => {
|
||||
return String(item.item_name || '').trim()
|
||||
@ -330,6 +346,65 @@ class OrderPrintSystemService extends OrderBaseService {
|
||||
continue;
|
||||
}
|
||||
|
||||
printItemsByOrderId.set(orderId, printItems);
|
||||
}
|
||||
|
||||
// 阶段二:批量查询 wms_stock_barcodes 获取所有条码
|
||||
const barcodeMap = new Map();
|
||||
const uniqueStockIds = Array.from(allStockIds);
|
||||
|
||||
if (uniqueStockIds.length > 0) {
|
||||
const stockBarcodeModel = this.ctx.model && this.ctx.model.StockBarcode;
|
||||
|
||||
if (stockBarcodeModel && typeof stockBarcodeModel.findAll === 'function') {
|
||||
const barcodeRows = await stockBarcodeModel.findAll({
|
||||
where: {
|
||||
stock_id: {
|
||||
[Op.in]: uniqueStockIds,
|
||||
},
|
||||
},
|
||||
attributes: [ 'stock_id', 'barcode' ],
|
||||
raw: true,
|
||||
});
|
||||
|
||||
for (const item of Array.isArray(barcodeRows) ? barcodeRows : []) {
|
||||
const stockId = Number(item && item.stock_id || 0);
|
||||
const code = String(item && item.barcode || '').trim();
|
||||
|
||||
if (!stockId || !code) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!barcodeMap.has(stockId)) {
|
||||
barcodeMap.set(stockId, []);
|
||||
}
|
||||
|
||||
barcodeMap.get(stockId).push(code);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 阶段三:注入条码并构建结果映射
|
||||
for (const orderRow of rows) {
|
||||
const orderId = Number(orderRow && orderRow.id || 0);
|
||||
const printItems = printItemsByOrderId.get(orderId);
|
||||
|
||||
if (!printItems) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 为每条打印项注入 barcodes 数组,供 resolveItemBarcodeText 优先读取
|
||||
for (const item of printItems) {
|
||||
const stockId = item.stock_id;
|
||||
|
||||
if (stockId && barcodeMap.has(stockId)) {
|
||||
item.barcodes = barcodeMap.get(stockId);
|
||||
}
|
||||
|
||||
// 清理内部字段,避免污染 JSON 输出
|
||||
delete item.stock_id;
|
||||
}
|
||||
|
||||
resultMap.set(orderId, {
|
||||
...orderRow,
|
||||
items: JSON.stringify(printItems),
|
||||
|
||||
@ -1668,7 +1668,7 @@ class PickSystemService extends Service {
|
||||
throw this.createBusinessError('mode 参数不合法,仅支持 1(全部确认) 或 2(部分确认)', 400);
|
||||
}
|
||||
|
||||
const { operatorId, warehouseId } = this.resolveOperatorContext();
|
||||
const { operatorId, operatorName, warehouseId } = this.resolveOperatorContext();
|
||||
if (!Number.isInteger(operatorId) || operatorId <= 0) {
|
||||
throw this.createBusinessError('未获取到操作人上下文', 401);
|
||||
}
|
||||
@ -1682,11 +1682,12 @@ class PickSystemService extends Service {
|
||||
throw this.createBusinessError('任务已完成或已取消,无法再次提交', 400);
|
||||
}
|
||||
|
||||
// source=2 表示后台抓取创建的任务,必须先绑定拣货车才能提交
|
||||
// source=1(PDA抓取创建)的任务必须先绑定拣货车才能提交
|
||||
// source=2(扫描进任务/后台抓取)不强制要求绑定拣货车
|
||||
const taskSource = Number(taskRow && taskRow.source || 0);
|
||||
const taskCartId = Number(taskRow && taskRow.current_cart_id || 0);
|
||||
if (taskSource === 2 && taskCartId <= 0) {
|
||||
throw this.createBusinessError('后台抓取任务必须先绑定拣货车才能提交', 400);
|
||||
if (taskSource === 1 && taskCartId <= 0) {
|
||||
throw this.createBusinessError('PDA抓取任务必须先绑定拣货车才能提交', 400);
|
||||
}
|
||||
|
||||
const transaction = await ctx.model.transaction();
|
||||
@ -1841,6 +1842,19 @@ class PickSystemService extends Service {
|
||||
}
|
||||
|
||||
await transaction.commit();
|
||||
|
||||
// 写入操作日志
|
||||
await this._writePickCompleteActionLog({
|
||||
taskId,
|
||||
warehouseId,
|
||||
operatorId,
|
||||
operatorName,
|
||||
targetOrderIds,
|
||||
mode,
|
||||
isCompleted: progress.isCompleted,
|
||||
progress,
|
||||
});
|
||||
|
||||
return {
|
||||
task_id: taskId,
|
||||
mode,
|
||||
@ -1858,6 +1872,103 @@ class PickSystemService extends Service {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 写入拣货完成操作日志到 wms_wave_pick_action_log(内部方法)。
|
||||
*
|
||||
* @param {Object} params 日志参数。
|
||||
* @param {number} params.taskId 波次拣货任务ID。
|
||||
* @param {number} params.warehouseId 仓库ID。
|
||||
* @param {number} params.operatorId 操作人ID。
|
||||
* @param {string} params.operatorName 操作人名称。
|
||||
* @param {Array<number>} params.targetOrderIds 确认完成的订单ID列表。
|
||||
* @param {number} params.mode 提交模式(1全部确认 2部分确认)。
|
||||
* @param {boolean} params.isCompleted 任务是否全部完成。
|
||||
* @param {Object} params.progress 任务进度信息。
|
||||
* @return {Promise<void>} 无返回值。
|
||||
*/
|
||||
async _writePickCompleteActionLog(params = {}) {
|
||||
const {
|
||||
taskId,
|
||||
warehouseId,
|
||||
operatorId,
|
||||
operatorName,
|
||||
targetOrderIds,
|
||||
mode,
|
||||
isCompleted,
|
||||
progress,
|
||||
} = params;
|
||||
|
||||
const requestId = `pick_complete_${warehouseId}_${taskId}_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`;
|
||||
|
||||
await this.ctx.model.query(
|
||||
`INSERT INTO wms_wave_pick_action_log (
|
||||
task_id,
|
||||
warehouse_id,
|
||||
wave_id,
|
||||
order_id,
|
||||
sku_id,
|
||||
location_id,
|
||||
box_no,
|
||||
cart_id,
|
||||
qty_delta,
|
||||
action_type,
|
||||
request_id,
|
||||
operator_id,
|
||||
device_id,
|
||||
seq_no,
|
||||
snapshot
|
||||
) VALUES (
|
||||
:taskId,
|
||||
:warehouseId,
|
||||
:waveId,
|
||||
:orderId,
|
||||
:skuId,
|
||||
:locationId,
|
||||
:boxNo,
|
||||
:cartId,
|
||||
:qtyDelta,
|
||||
:actionType,
|
||||
:requestId,
|
||||
:operatorId,
|
||||
:deviceId,
|
||||
:seqNo,
|
||||
:snapshot
|
||||
)`,
|
||||
{
|
||||
replacements: {
|
||||
taskId: taskId || 0,
|
||||
warehouseId: warehouseId || 0,
|
||||
waveId: null,
|
||||
orderId: Array.isArray(targetOrderIds) && targetOrderIds.length > 0 ? targetOrderIds[0] : null,
|
||||
skuId: null,
|
||||
locationId: null,
|
||||
boxNo: null,
|
||||
cartId: null,
|
||||
qtyDelta: 0,
|
||||
actionType: 'pick_complete',
|
||||
requestId,
|
||||
operatorId: operatorId || 0,
|
||||
deviceId: null,
|
||||
seqNo: 1,
|
||||
snapshot: JSON.stringify({
|
||||
task_id: taskId,
|
||||
mode,
|
||||
confirmed_order_ids: targetOrderIds,
|
||||
confirmed_order_count: Array.isArray(targetOrderIds) ? targetOrderIds.length : 0,
|
||||
is_completed: isCompleted,
|
||||
progress: {
|
||||
total_orders: progress && progress.totalOrders,
|
||||
picked_orders: progress && progress.pickedOrders,
|
||||
pending_orders: progress && progress.pendingOrders,
|
||||
},
|
||||
operator_name: operatorName || 'system',
|
||||
}),
|
||||
},
|
||||
type: this.ctx.model.QueryTypes.INSERT,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* PDA 扫码查询拣货车信息。
|
||||
*
|
||||
|
||||
243
database/migrations/20260608-add-api-permissions.js
Normal file
243
database/migrations/20260608-add-api-permissions.js
Normal file
@ -0,0 +1,243 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* 补齐 wms_permission 表的 API 权限记录:
|
||||
* 1. 新增约 50 条 type='api' 的权限记录(幂等:先查后插)
|
||||
* 2. 修正 28 条现有记录的 meta_title(原值统一为"获取审核信息接口")
|
||||
*
|
||||
* 幂等设计:
|
||||
* - 新增:先查询 path + type='api' 是否已存在,已存在则跳过
|
||||
* - 修正:UPDATE ... WHERE id = N AND meta_title = '获取审核信息接口'
|
||||
*/
|
||||
|
||||
const TABLE = 'wms_permission';
|
||||
|
||||
/**
|
||||
* 批量查询指定 path 是否已存在 type='api' 的记录。
|
||||
* @param {import('sequelize').QueryInterface} queryInterface 查询接口
|
||||
* @param {string[]} paths 待查询的 path 列表
|
||||
* @return {Promise<Set<string>>} 已存在的 path 集合
|
||||
*/
|
||||
const getExistingApiPaths = async (queryInterface, paths) => {
|
||||
const placeholders = paths.map(() => '?').join(', ');
|
||||
const [ rows ] = await queryInterface.sequelize.query(
|
||||
`SELECT path FROM \`${TABLE}\` WHERE type = 'api' AND path IN (${placeholders})`,
|
||||
{ replacements: paths }
|
||||
);
|
||||
return new Set(rows.map(r => r.path));
|
||||
};
|
||||
|
||||
/**
|
||||
* 正向迁移。
|
||||
* @param {import('sequelize').QueryInterface} queryInterface 查询接口
|
||||
* @return {Promise<void>} 无返回值
|
||||
*/
|
||||
module.exports.up = async queryInterface => {
|
||||
// ─── 1. 新增 50 条 API 权限 ─────────────────────────────────
|
||||
const newPermissions = [
|
||||
// warehouse 模块
|
||||
{ path: 'warehouse.getWarehouseZones', meta_title: '获取所有仓库' },
|
||||
{ path: 'warehouse.create', meta_title: '创建实体库' },
|
||||
{ path: 'warehouse.update', meta_title: '更新仓库元素' },
|
||||
{ path: 'warehouse.delete', meta_title: '删除仓库元素' },
|
||||
{ path: 'warehouse.toggleActive', meta_title: '切换仓库元素启用状态' },
|
||||
{ path: 'warehouse.getPath', meta_title: '获取仓库路径' },
|
||||
{ path: 'warehouse.getPickPath', meta_title: '获取拣货路径' },
|
||||
{ path: 'warehouse.updateRackPosition', meta_title: '更新货架位置' },
|
||||
{ path: 'warehouse.recalculatePickPath', meta_title: '重算拣货路径' },
|
||||
{ path: 'warehouse.updateNeighbors', meta_title: '更新相邻仓位' },
|
||||
{ path: 'warehouse.getAreaRacks', meta_title: '获取区域货架' },
|
||||
{ path: 'warehouse.getWarehouseTree', meta_title: '获取仓库树' },
|
||||
{ path: 'warehouse.getChildren', meta_title: '获取仓库子元素' },
|
||||
{ path: 'warehouse.updateSpaceInfo', meta_title: '修改仓位信息' },
|
||||
{ path: 'warehouse.batchUpdateSpaceInfo', meta_title: '批量修改仓位信息' },
|
||||
{ path: 'warehouse.exportRackSpaces', meta_title: '导出货架仓位' },
|
||||
// shops 模块
|
||||
{ path: 'shops.list', meta_title: '店铺列表' },
|
||||
{ path: 'shops.add', meta_title: '新增店铺' },
|
||||
{ path: 'shops.del', meta_title: '删除店铺' },
|
||||
{ path: 'shops.edit', meta_title: '编辑店铺' },
|
||||
{ path: 'shops.GetAuthorizeSessionKey', meta_title: '获取授权SessionKey' },
|
||||
// stock.warehouse 模块
|
||||
{ path: 'stock.warehouse.saveWarehouseStock', meta_title: '保存商品资料' },
|
||||
{ path: 'stock.warehouse.createWarehouseStock', meta_title: '创建仓库商品' },
|
||||
{ path: 'stock.warehouse.import', meta_title: '商品导入' },
|
||||
{ path: 'stock.warehouse.saveWarehouseStockBarcode', meta_title: '修改商品条码' },
|
||||
{ path: 'stock.warehouse.bindItem', meta_title: '绑定货主商品' },
|
||||
{ path: 'stock.warehouse.unbindItem', meta_title: '解绑货主商品' },
|
||||
{ path: 'stock.warehouse.handleBatchDelete', meta_title: '批量删除仓库商品' },
|
||||
{ path: 'stock.warehouse.handleBatchChange', meta_title: '批量修改商品' },
|
||||
// index 模块
|
||||
{ path: 'index.ReferenceFile', meta_title: '图片引用设置' },
|
||||
{ path: 'index.test', meta_title: '测试接口' },
|
||||
{ path: 'index.getShopList', meta_title: '获取仓库店铺列表' },
|
||||
{ path: 'index.getShopExpressList', meta_title: '获取店铺签约快递' },
|
||||
{ path: 'index.createPlatformOauthReservation', meta_title: '创建平台授权预留码' },
|
||||
// order 模块
|
||||
{ path: 'order.bindExpressPackageMaterial', meta_title: '绑定快递包材' },
|
||||
{ path: 'order.pullReviewDataByWaybill', meta_title: '按运单拉取复核数据' },
|
||||
// order.wave 模块
|
||||
{ path: 'order.wave.waveStrategyCreate', meta_title: '波次策略新增' },
|
||||
{ path: 'order.wave.waveStrategyUpdate', meta_title: '波次策略修改' },
|
||||
{ path: 'order.wave.wavePickTaskCancel', meta_title: '拣货任务取消' },
|
||||
{ path: 'order.wave.previewWaveStrategyNextFetchOrderCount', meta_title: '预演策略抓取数量' },
|
||||
// order.* 明细模块
|
||||
{ path: 'order.pendingOrder.detail', meta_title: '待处理订单明细' },
|
||||
{ path: 'order.archiveOrder.detail', meta_title: '归档订单明细' },
|
||||
{ path: 'order.deliveryOrder.detail', meta_title: '配送订单明细' },
|
||||
{ path: 'order.deliveryExpectionOrder.detail', meta_title: '配送异常订单明细' },
|
||||
{ path: 'order.entrustOrder.detail', meta_title: '委托外仓订单明细' },
|
||||
{ path: 'order.reviewOrder.detail', meta_title: '待审核订单明细' },
|
||||
{ path: 'order.outboundOrder.detail', meta_title: '待出库订单明细' },
|
||||
{ path: 'order.expectionOrder.detail', meta_title: '异常订单明细' },
|
||||
// storage.inventory 模块
|
||||
{ path: 'storage.inventory.quickPutaway', meta_title: '快递入库' },
|
||||
// store 模块
|
||||
{ path: 'store.getStoreRoles', meta_title: '获取审核信息' },
|
||||
{ path: 'store.auditApply', meta_title: '提交审核' },
|
||||
// storeWarehouse.store 模块
|
||||
{ path: 'storeWarehouse.store.adjustPrintQuantity', meta_title: '货主余额变更' },
|
||||
{ path: 'storeWarehouse.store.queryPrintQuantityLogs', meta_title: '货主面单余额查询' },
|
||||
];
|
||||
|
||||
const allPaths = newPermissions.map(p => p.path);
|
||||
const existingPaths = await getExistingApiPaths(queryInterface, allPaths);
|
||||
|
||||
const toInsert = newPermissions.filter(p => !existingPaths.has(p.path));
|
||||
|
||||
if (toInsert.length > 0) {
|
||||
// 构建批量 INSERT 语句,name 与 path 保持一致
|
||||
const values = toInsert
|
||||
.map(
|
||||
p => `('${p.path.replace(/'/g, "\\'")}', '${p.path.replace(/'/g, "\\'")}', '${p.meta_title.replace(/'/g, "\\'")}', 'api', 1, NOW(), NOW())`
|
||||
)
|
||||
.join(',\n');
|
||||
|
||||
await queryInterface.sequelize.query(`
|
||||
INSERT INTO \`${TABLE}\` (path, name, meta_title, type, status, created_at, update_at)
|
||||
VALUES ${values}
|
||||
`);
|
||||
}
|
||||
|
||||
console.log(
|
||||
`[Migration] wms_permission API 权限新增:共 ${newPermissions.length} 条,` +
|
||||
`已存在 ${newPermissions.length - toInsert.length} 条,实际插入 ${toInsert.length} 条`
|
||||
);
|
||||
|
||||
// ─── 2. 修正 28 条现有记录的 meta_title ────────────────────
|
||||
const corrections = [
|
||||
{ id: 52, meta_title: '获取审核信息' },
|
||||
{ id: 84, meta_title: '获取COS上传配置' },
|
||||
{ id: 85, meta_title: '获取快递列表' },
|
||||
{ id: 86, meta_title: '自动翻译新键' },
|
||||
{ id: 87, meta_title: '上传成功通知' },
|
||||
{ id: 88, meta_title: '获取订单模型列表' },
|
||||
{ id: 89, meta_title: '绑定货主商品到仓库' },
|
||||
{ id: 90, meta_title: '创建禁售规则' },
|
||||
{ id: 91, meta_title: '创建单位' },
|
||||
{ id: 92, meta_title: '创建仓库商品' },
|
||||
{ id: 93, meta_title: '删除禁售规则' },
|
||||
{ id: 94, meta_title: '删除单位' },
|
||||
{ id: 95, meta_title: '批量修改商品' },
|
||||
{ id: 96, meta_title: '批量删除商品' },
|
||||
{ id: 97, meta_title: '保存商品资料' },
|
||||
{ id: 98, meta_title: '修改商品条码' },
|
||||
{ id: 99, meta_title: '解除绑定货主商品' },
|
||||
{ id: 100, meta_title: '添加收货明细' },
|
||||
{ id: 101, meta_title: '删除收货明细' },
|
||||
{ id: 102, meta_title: '保存收货单' },
|
||||
{ id: 103, meta_title: '创建货架' },
|
||||
{ id: 104, meta_title: '创建货架含仓位' },
|
||||
{ id: 105, meta_title: '重算拣货路径' },
|
||||
{ id: 106, meta_title: '更新相邻仓位' },
|
||||
{ id: 107, meta_title: '更新货架位置' },
|
||||
{ id: 108, meta_title: '获取商品信息' },
|
||||
{ id: 306, meta_title: '获取订单模型列表' },
|
||||
{ id: 307, meta_title: '获取区域货架' },
|
||||
];
|
||||
|
||||
let correctedCount = 0;
|
||||
for (const { id, meta_title } of corrections) {
|
||||
const [ result ] = await queryInterface.sequelize.query(
|
||||
`UPDATE \`${TABLE}\` SET meta_title = :meta_title, update_at = NOW()
|
||||
WHERE id = :id AND meta_title = '获取审核信息接口'`,
|
||||
{ replacements: { id, meta_title } }
|
||||
);
|
||||
// result 为 affectedRows(MySQL)或 rowCount
|
||||
if (result && (result.affectedRows > 0 || result.rowCount > 0 || result.changedRows > 0)) {
|
||||
correctedCount++;
|
||||
}
|
||||
}
|
||||
|
||||
console.log(
|
||||
`[Migration] wms_permission meta_title 修正:共 ${corrections.length} 条,` +
|
||||
`实际修正 ${correctedCount} 条`
|
||||
);
|
||||
|
||||
// ─── 3. 修正 10 条 meta_title 为 "path+接口" 格式的记录 ──────
|
||||
const pathLikeCorrections = [
|
||||
{ id: 347, path: 'warehouse.getChildren', meta_title: '获取仓库子元素' },
|
||||
{ id: 348, path: 'warehouse.toggleActive', meta_title: '切换仓库启用状态' },
|
||||
{ id: 349, path: 'warehouse.getPath', meta_title: '获取仓库路径' },
|
||||
{ id: 350, path: 'warehouse.getPickPath', meta_title: '获取拣货路径' },
|
||||
{ id: 351, path: 'storage.receiving.save', meta_title: '保存收货单' },
|
||||
{ id: 367, path: 'shops.list', meta_title: '店铺列表' },
|
||||
{ id: 368, path: 'shops.add', meta_title: '新增店铺' },
|
||||
{ id: 369, path: 'shops.del', meta_title: '删除店铺' },
|
||||
{ id: 370, path: 'shops.edit', meta_title: '编辑店铺' },
|
||||
{ id: 371, path: 'shop.GetAuthorizeSessionKey', meta_title: '获取授权SessionKey' },
|
||||
];
|
||||
|
||||
let pathLikeCorrectedCount = 0;
|
||||
for (const { id, meta_title } of pathLikeCorrections) {
|
||||
const [ result ] = await queryInterface.sequelize.query(
|
||||
`UPDATE \`${TABLE}\` SET meta_title = :meta_title, update_at = NOW()
|
||||
WHERE id = :id AND meta_title LIKE '%接口'`,
|
||||
{ replacements: { id, meta_title } }
|
||||
);
|
||||
if (result && (result.affectedRows > 0 || result.rowCount > 0 || result.changedRows > 0)) {
|
||||
pathLikeCorrectedCount++;
|
||||
}
|
||||
}
|
||||
|
||||
console.log(
|
||||
`[Migration] wms_permission "path+接口" 格式修正:共 ${pathLikeCorrections.length} 条,` +
|
||||
`实际修正 ${pathLikeCorrectedCount} 条`
|
||||
);
|
||||
|
||||
// ── 3b. 修正 setting.permission.add/delete/update 的 meta_title ──
|
||||
const permissionCrudCorrections = [
|
||||
{ id: 119, path: 'setting.permission.add', meta_title: '新增权限' },
|
||||
{ id: 120, path: 'setting.permission.delete', meta_title: '删除权限' },
|
||||
{ id: 121, path: 'setting.permission.update', meta_title: '修改权限' },
|
||||
];
|
||||
|
||||
let permCrudCorrectedCount = 0;
|
||||
for (const { id, path, meta_title } of permissionCrudCorrections) {
|
||||
const [ result ] = await queryInterface.sequelize.query(
|
||||
`UPDATE \`${TABLE}\` SET meta_title = :meta_title, update_at = NOW()
|
||||
WHERE id = :id AND meta_title = :oldMetaTitle`,
|
||||
{ replacements: { id, meta_title, oldMetaTitle: path } }
|
||||
);
|
||||
if (result && (result.affectedRows > 0 || result.rowCount > 0 || result.changedRows > 0)) {
|
||||
permCrudCorrectedCount++;
|
||||
}
|
||||
}
|
||||
|
||||
console.log(
|
||||
`[Migration] wms_permission setting.permission CRUD 修正:共 ${permissionCrudCorrections.length} 条,` +
|
||||
`实际修正 ${permCrudCorrectedCount} 条`
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* 回滚迁移:无法安全回滚 meta_title 修正与新增记录(可能已被后续业务引用),
|
||||
* 仅输出提示信息。
|
||||
* @return {Promise<void>} 无返回值
|
||||
*/
|
||||
module.exports.down = async () => {
|
||||
console.log(
|
||||
'[Migration] wms_permission API 权限补齐脚本无安全回滚方案,' +
|
||||
'如需回滚请手动处理 meta_title 与新增记录。'
|
||||
);
|
||||
};
|
||||
@ -0,0 +1,169 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* 系统角色(is_system=1)预设权限迁移
|
||||
*
|
||||
* 背景:
|
||||
* wms_permission 表已扩容到 349 条(6 种类型),当前系统角色的 permissions
|
||||
* 字段(JSON 数组)覆盖范围不足,新增的 API/pda_pages/workerstation_pages 等
|
||||
* 权限未被纳入旧的角色预设中。
|
||||
*
|
||||
* 范围:
|
||||
* - 仅更新 is_system=1 的角色(12 个,排除 id=2 仓库管理员和 id=7 超级管理员,
|
||||
* 二者保持 "*" 不变)
|
||||
* - 仅使用 status=1 的活跃权限
|
||||
* - 不修改 wms_permission 表
|
||||
*
|
||||
* 幂等设计:
|
||||
* UPDATE wms_role SET permissions = ? WHERE id = ? AND is_system = 1
|
||||
*/
|
||||
|
||||
const TABLE = 'wms_role';
|
||||
|
||||
/** @type {{id: number, role_code: string, permissions: string, desc: string}[]} */
|
||||
const ROLE_UPDATES = [
|
||||
{
|
||||
id: 5,
|
||||
role_code: 'store_admin_default',
|
||||
name: '货主管理员',
|
||||
// 货主管理员:web_pages(设置4,货主17,成员审核50,货主列表244,店铺模块366), block(商家基础数据48), api(货主/店铺相关 52,53,308,363,364,365,367-372,376,379,380)
|
||||
permissions: '[4,17,48,50,52,53,244,308,363,364,365,366,367,368,369,370,371,372,376,379,380]',
|
||||
old: '[4,48,50,52,53]',
|
||||
},
|
||||
{
|
||||
id: 8,
|
||||
role_code: '2',
|
||||
name: '经理',
|
||||
// 经理:全部 status=1 权限(206条),排除权限管理(5,7,119,120,121)、测试(187,245,378)
|
||||
permissions: '[1,4,6,8,9,11,12,13,14,15,16,17,18,19,20,21,22,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,43,44,45,46,47,48,49,50,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,244,254,255,256,257,258,259,260,261,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,278,279,281,283,290,291,292,293,294,295,296,297,298,299,300,303,304,305,306,307,308,309,333,334,335,336,337,338,339,340,341,342,343,344,345,346,347,348,349,350,351,352,353,354,355,356,357,358,359,360,361,363,364,365,366,367,368,369,370,371,372,373,374,375,376,377,379,380,381,382,383,384]',
|
||||
old: '[4-121,244]',
|
||||
},
|
||||
{
|
||||
id: 26,
|
||||
role_code: 'warehouse',
|
||||
name: '仓库组-主管',
|
||||
// 仓库组-主管:全部活跃权限排除权限管理(5,6,7,119,120,121)、财务(28,31-37)、数据模块(16)、测试(187,245,378)
|
||||
permissions: '[1,4,8,9,11,12,13,14,15,17,18,19,20,21,22,24,25,26,27,29,30,38,39,40,41,43,44,45,46,47,48,49,50,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,244,254,255,256,257,258,259,260,261,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,278,279,281,283,290,291,292,293,294,295,296,297,298,299,300,303,304,305,306,307,308,309,333,334,335,336,337,338,339,340,341,342,343,344,345,346,347,348,349,350,351,352,353,354,355,356,357,358,359,360,361,363,364,365,366,367,368,369,370,371,372,373,374,375,376,377,379,380,381,382,383,384]',
|
||||
old: '[4-121]',
|
||||
},
|
||||
{
|
||||
id: 27,
|
||||
role_code: 'warehouse_role',
|
||||
name: '仓库组-员工',
|
||||
// 仓库组-员工:同仓库组-主管,排除权限管理、财务、数据模块、测试
|
||||
permissions: '[1,4,8,9,11,12,13,14,15,17,18,19,20,21,22,24,25,26,27,29,30,38,39,40,41,43,44,45,46,47,48,49,50,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,244,254,255,256,257,258,259,260,261,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,278,279,281,283,290,291,292,293,294,295,296,297,298,299,300,303,304,305,306,307,308,309,333,334,335,336,337,338,339,340,341,342,343,344,345,346,347,348,349,350,351,352,353,354,355,356,357,358,359,360,361,363,364,365,366,367,368,369,370,371,372,373,374,375,376,377,379,380,381,382,383,384]',
|
||||
old: '[4-121]',
|
||||
},
|
||||
{
|
||||
id: 28,
|
||||
role_code: '05',
|
||||
name: '客服组-主管',
|
||||
// 客服组-主管:排除权限管理(5,6,7,119,120,121)、财务(28,31-37)、数据(16)、测试(187,245,378)、PDA拣货/复核/打包/补货、工位称重/退件
|
||||
permissions: '[1,4,8,9,11,12,13,14,15,17,18,19,20,21,22,24,25,26,27,29,30,38,39,40,41,43,44,45,46,47,48,49,50,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,244,254,255,256,278,281,283,290,291,292,293,294,295,296,297,298,299,300,303,304,305,306,307,308,309,333,334,335,336,337,338,339,340,341,342,343,344,345,346,347,348,349,350,351,352,353,354,355,356,357,358,361,363,364,365,366,367,368,369,370,371,372,373,374,375,376,377,379,380,381,382,383,384]',
|
||||
old: '[1,4-121,244-336]',
|
||||
},
|
||||
{
|
||||
id: 30,
|
||||
role_code: '04',
|
||||
name: '客服组-员工',
|
||||
// 客服组-员工:同客服组-主管
|
||||
permissions: '[1,4,8,9,11,12,13,14,15,17,18,19,20,21,22,24,25,26,27,29,30,38,39,40,41,43,44,45,46,47,48,49,50,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,244,254,255,256,278,281,283,290,291,292,293,294,295,296,297,298,299,300,303,304,305,306,307,308,309,333,334,335,336,337,338,339,340,341,342,343,344,345,346,347,348,349,350,351,352,353,354,355,356,357,358,361,363,364,365,366,367,368,369,370,371,372,373,374,375,376,377,379,380,381,382,383,384]',
|
||||
old: '[1,4-121,244-336]',
|
||||
},
|
||||
{
|
||||
id: 29,
|
||||
role_code: '03',
|
||||
name: '生产组-主管',
|
||||
// 生产组-主管:全部活跃权限排除权限管理(5,6,7,119,120,121)、财务(28,31-37)、数据(16)、测试(187,245,378)
|
||||
permissions: '[1,4,8,9,11,12,13,14,15,17,18,19,20,21,22,24,25,26,27,29,30,38,39,40,41,43,44,45,46,47,48,49,50,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,244,254,255,256,257,258,259,260,261,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,278,279,281,283,290,291,292,293,294,295,296,297,298,299,300,303,304,305,306,307,308,309,333,334,335,336,337,338,339,340,341,342,343,344,345,346,347,348,349,350,351,352,353,354,355,356,357,358,359,360,361,363,364,365,366,367,368,369,370,371,372,373,374,375,376,377,379,380,381,382,383,384]',
|
||||
old: '[4-121]',
|
||||
},
|
||||
{
|
||||
id: 31,
|
||||
role_code: '002',
|
||||
name: '生产组-员工',
|
||||
// 生产组-员工:同生产组-主管
|
||||
permissions: '[1,4,8,9,11,12,13,14,15,17,18,19,20,21,22,24,25,26,27,29,30,38,39,40,41,43,44,45,46,47,48,49,50,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,244,254,255,256,257,258,259,260,261,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,278,279,281,283,290,291,292,293,294,295,296,297,298,299,300,303,304,305,306,307,308,309,333,334,335,336,337,338,339,340,341,342,343,344,345,346,347,348,349,350,351,352,353,354,355,356,357,358,359,360,361,363,364,365,366,367,368,369,370,371,372,373,374,375,376,377,379,380,381,382,383,384]',
|
||||
old: '[4-121]',
|
||||
},
|
||||
{
|
||||
id: 32,
|
||||
role_code: '021',
|
||||
name: '生产组-拣货',
|
||||
// 生产组-拣货:排除复核发货(266-269)、打包(270-276)、权限管理(5,6,7,119,120,121)、财务(28,31-37)、数据(16)、测试(187,245,378)、工位站(356,359,360)
|
||||
permissions: '[1,4,8,9,11,12,13,14,15,17,18,19,20,21,22,24,25,26,27,29,30,38,39,40,41,43,44,45,46,47,48,49,50,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,244,254,255,256,257,258,259,260,261,262,263,264,265,277,278,279,281,283,290,291,292,293,294,295,296,297,298,299,300,303,304,305,306,307,308,309,333,334,335,336,337,338,339,340,341,342,343,344,345,346,347,348,349,350,351,352,353,354,355,357,358,361,363,364,365,366,367,368,369,370,371,372,373,374,375,376,377,379,380,381,382,383,384]',
|
||||
old: '[4-121]',
|
||||
},
|
||||
{
|
||||
id: 33,
|
||||
role_code: '0113',
|
||||
name: '拣货组组员',
|
||||
// 拣货组组员:同生产组-拣货
|
||||
permissions: '[1,4,8,9,11,12,13,14,15,17,18,19,20,21,22,24,25,26,27,29,30,38,39,40,41,43,44,45,46,47,48,49,50,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,244,254,255,256,257,258,259,260,261,262,263,264,265,277,278,279,281,283,290,291,292,293,294,295,296,297,298,299,300,303,304,305,306,307,308,309,333,334,335,336,337,338,339,340,341,342,343,344,345,346,347,348,349,350,351,352,353,354,355,357,358,361,363,364,365,366,367,368,369,370,371,372,373,374,375,376,377,379,380,381,382,383,384]',
|
||||
old: '[4-121]',
|
||||
},
|
||||
{
|
||||
id: 34,
|
||||
role_code: '024',
|
||||
name: '生产组-复核',
|
||||
// 生产组-复核:排除拣货(257-265)、打包(270-276)、权限管理(5,6,7,119,120,121)、财务(28,31-37)、数据(16)、测试(187,245,378)
|
||||
permissions: '[1,4,8,9,11,12,13,14,15,17,18,19,20,21,22,24,25,26,27,29,30,38,39,40,41,43,44,45,46,47,48,49,50,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,244,254,255,256,266,267,268,269,277,278,279,281,283,290,291,292,293,294,295,296,297,298,299,300,303,304,305,306,307,308,309,333,334,335,336,337,338,339,340,341,342,343,344,345,346,347,348,349,350,351,352,353,354,355,356,357,358,359,360,361,363,364,365,366,367,368,369,370,371,372,373,374,375,376,377,379,380,381,382,383,384]',
|
||||
old: '[4-121]',
|
||||
},
|
||||
{
|
||||
id: 36,
|
||||
role_code: '0211',
|
||||
name: '其他普工',
|
||||
// 其他普工:排除设置模块(4-9,40,41,80,81,336,366,375)、财务、数据、测试、系统、敏感API、仓库管理API、视频
|
||||
permissions: '[1,11,12,13,14,15,17,18,19,20,21,22,24,25,26,27,29,30,38,39,43,44,45,46,48,49,50,54,55,57,58,61,62,63,64,65,66,67,68,69,70,71,72,74,75,76,77,78,79,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,108,244,254,255,256,257,258,259,260,261,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,278,279,281,283,290,291,292,293,294,295,296,297,298,299,300,303,304,305,306,307,309,333,334,335,337,338,339,340,341,342,343,344,345,346,347,348,349,350,351,352,353,354,355,357,358,361,364,365,370,373,374,376,377,379,380,381,382,383,384]',
|
||||
old: '[4-121]',
|
||||
}
|
||||
];
|
||||
|
||||
/**
|
||||
* 正向迁移:更新 12 个系统角色的 permissions 字段。
|
||||
* @param {import('sequelize').QueryInterface} queryInterface 查询接口
|
||||
* @return {Promise<void>} 无返回值
|
||||
*/
|
||||
module.exports.up = async queryInterface => {
|
||||
let updatedCount = 0;
|
||||
|
||||
for (const role of ROLE_UPDATES) {
|
||||
const [ result ] = await queryInterface.sequelize.query(
|
||||
`UPDATE \`${TABLE}\` SET permissions = :permissions, updated_at = NOW()
|
||||
WHERE id = :id AND is_system = 1`,
|
||||
{ replacements: { id: role.id, permissions: role.permissions } }
|
||||
);
|
||||
if (result && (result.affectedRows > 0 || result.rowCount > 0 || result.changedRows > 0)) {
|
||||
updatedCount++;
|
||||
}
|
||||
}
|
||||
|
||||
console.log(
|
||||
`[Migration] wms_role 预设权限更新:共 ${ROLE_UPDATES.length} 个角色,实际更新 ${updatedCount} 个`
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* 回滚迁移:恢复到旧的 permissions 值。
|
||||
* @param {import('sequelize').QueryInterface} queryInterface 查询接口
|
||||
* @return {Promise<void>} 无返回值
|
||||
*/
|
||||
module.exports.down = async queryInterface => {
|
||||
let revertedCount = 0;
|
||||
|
||||
for (const role of ROLE_UPDATES) {
|
||||
const [ result ] = await queryInterface.sequelize.query(
|
||||
`UPDATE \`${TABLE}\` SET permissions = :permissions, updated_at = NOW()
|
||||
WHERE id = :id AND is_system = 1`,
|
||||
{ replacements: { id: role.id, permissions: role.old } }
|
||||
);
|
||||
if (result && (result.affectedRows > 0 || result.rowCount > 0 || result.changedRows > 0)) {
|
||||
revertedCount++;
|
||||
}
|
||||
}
|
||||
|
||||
console.log(
|
||||
`[Migration] wms_role 预设权限回滚:共 ${ROLE_UPDATES.length} 个角色,实际回滚 ${revertedCount} 个`
|
||||
);
|
||||
};
|
||||
@ -3143,5 +3143,20 @@
|
||||
"仅同步文档,不修改任何业务代码或实现。"
|
||||
],
|
||||
"type": "updated"
|
||||
},
|
||||
{
|
||||
"version": "2026.06.08-system-15",
|
||||
"date": "2026-06-08",
|
||||
"summary": "新增 order.pendingOrder.manualWaybill 接口(手工录入运单号)",
|
||||
"methods": [
|
||||
"order.pendingOrder.manualWaybill"
|
||||
],
|
||||
"notes": [
|
||||
"为待处理订单手动录入运单号,写入 wms_order_express 表",
|
||||
"仅允许 step 在 [1,2,3] 且 outbound_status 不为 'padding' 的订单操作",
|
||||
"免权限(isNeedAuth: false),需登录",
|
||||
"成功返回运单记录的 id、order_id、waybill_code、create_at"
|
||||
],
|
||||
"type": "added"
|
||||
}
|
||||
]
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
{
|
||||
"module": "system",
|
||||
"description": "系统接口标准入口,method 对应系统内置方法,全部使用 POST 请求,参数统一放在 body 内",
|
||||
"version": "0.3.19",
|
||||
"version": "0.3.5",
|
||||
"updatedAt": "2026-06-08",
|
||||
"headers": [
|
||||
{
|
||||
@ -4736,6 +4736,88 @@
|
||||
"message": "task_id 参数不能为空"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"method": "order.pendingOrder.manualWaybill",
|
||||
"description": "手工录入运单号。为指定待处理订单创建一条运单记录(wms_order_express 表),仅允许 step 在 [1,2,3] 且 outbound_status 不为 'padding' 的订单操作。",
|
||||
"isNeedAuth": false,
|
||||
"isNeedLogin": true,
|
||||
"headers": [
|
||||
{
|
||||
"name": "Authorization",
|
||||
"type": "string",
|
||||
"required": true,
|
||||
"description": "Bearer token"
|
||||
}
|
||||
],
|
||||
"params": [
|
||||
{
|
||||
"name": "order_id",
|
||||
"type": "number",
|
||||
"required": true,
|
||||
"source": "body",
|
||||
"description": "订单 ID,必须为正整数"
|
||||
},
|
||||
{
|
||||
"name": "waybill_code",
|
||||
"type": "string",
|
||||
"required": true,
|
||||
"source": "body",
|
||||
"description": "运单号,非空字符串"
|
||||
}
|
||||
],
|
||||
"response": [
|
||||
{
|
||||
"name": "id",
|
||||
"type": "number",
|
||||
"required": true,
|
||||
"description": "创建的运单记录 ID"
|
||||
},
|
||||
{
|
||||
"name": "order_id",
|
||||
"type": "number",
|
||||
"required": true,
|
||||
"description": "订单 ID"
|
||||
},
|
||||
{
|
||||
"name": "waybill_code",
|
||||
"type": "string",
|
||||
"required": true,
|
||||
"description": "运单号"
|
||||
},
|
||||
{
|
||||
"name": "create_at",
|
||||
"type": "string",
|
||||
"required": true,
|
||||
"description": "创建时间"
|
||||
}
|
||||
],
|
||||
"errors": [
|
||||
{
|
||||
"code": 400,
|
||||
"message": "order_id 必须为正整数"
|
||||
},
|
||||
{
|
||||
"code": 400,
|
||||
"message": "waybill_code(运单号)不能为空"
|
||||
},
|
||||
{
|
||||
"code": 400,
|
||||
"message": "订单不存在或不属于当前仓库"
|
||||
},
|
||||
{
|
||||
"code": 400,
|
||||
"message": "订单当前步骤不在允许范围,仅允许待处理状态(step 1/2/3)的订单手工录入运单号"
|
||||
},
|
||||
{
|
||||
"code": 400,
|
||||
"message": "订单已标记待出库,不允许手工录入运单号"
|
||||
},
|
||||
{
|
||||
"code": 500,
|
||||
"message": "内部错误:OrderExpress 模型未加载或数据库写入失败"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user