Compare commits
No commits in common. "43c60dd934f3b67368f4c0246602184983f34d5e" and "0e50ff667108fd83649ae185da6642590d46f48c" have entirely different histories.
43c60dd934
...
0e50ff6671
@ -424,15 +424,12 @@ 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,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';
|
||||
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';
|
||||
this.systemInit(_noNeedLogin, _noNeedRight, _noNeedLog, _noNeedAuth);
|
||||
}
|
||||
|
||||
@ -1945,7 +1945,7 @@ class PendingOrderService extends OrderBaseService {
|
||||
2. **利用你的中国地理知识**:如果地址包含村/镇/街道/社区名称,请检索你的知识库推测它所属的省市区。例如:
|
||||
- "和丰一社" + 常见于广东地区村组命名 → 推测为广东省 东莞市/广州市等
|
||||
- 根据地址中的方言特征、命名习惯推测所在区域
|
||||
3. 如果实在无法确定,province填"",city和area同理填"",收件人和name同理填"",mobile同理填""。
|
||||
3. 如果实在无法确定,province填"暂未识别",city和area同理填"暂未识别"
|
||||
4. detailAddress去除省市区部分,只保留街道/村/门牌号
|
||||
5. 只返回纯JSON,不含解释或markdown
|
||||
|
||||
@ -2089,8 +2089,19 @@ class PendingOrderService extends OrderBaseService {
|
||||
throw new Error('订单明细 items 不能为空');
|
||||
}
|
||||
|
||||
// 2. 适配明细格式并校验(转为 addOrder 所需的驼峰格式)
|
||||
// 手工单:item_id 即为仓库 stock_id,无需查 stock_store 做映射
|
||||
// 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 所需的驼峰格式)
|
||||
const orderLineItems = rawItems.map((item, idx) => {
|
||||
if (!item || typeof item !== 'object') {
|
||||
throw new Error(`第${idx + 1}行明细格式无效`);
|
||||
@ -2104,20 +2115,22 @@ class PendingOrderService extends OrderBaseService {
|
||||
throw new Error(`第${idx + 1}行计划数量 plan_qty 必须为正整数`);
|
||||
}
|
||||
return {
|
||||
itemCode: String(item.item_code || '').trim(),
|
||||
itemCode: String(item.item_code || '').trim()
|
||||
|| String(itemInfoMap.get(itemId)?.item_code || '').trim(),
|
||||
itemId,
|
||||
itemName: String(item.item_name || '').trim() || '商品',
|
||||
itemName: String(item.item_name || '').trim()
|
||||
|| String(itemInfoMap.get(itemId)?.item_name || '').trim()
|
||||
|| '商品',
|
||||
planQty,
|
||||
stockId: itemId,
|
||||
orderLineNo: String(item.order_line_no || String(idx + 1)).trim(),
|
||||
actualPrice: Number(item.actual_price) || 0,
|
||||
};
|
||||
});
|
||||
|
||||
// 3. 自动生成订单号(如未传)
|
||||
// 4. 自动生成订单号(如未传)
|
||||
const deliveryOrderCode = String(requestData.delivery_order_code || '').trim()
|
||||
|| `SYS${Date.now()}${Math.floor(Math.random() * 9000) + 1000}`;
|
||||
// 4. 适配为 addOrder 所需的奇门嵌套格式
|
||||
// 5. 适配为 addOrder 所需的奇门嵌套格式
|
||||
const adaptedData = {
|
||||
request: {
|
||||
deliveryOrder: {
|
||||
@ -4404,96 +4417,6 @@ 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;
|
||||
|
||||
@ -18,14 +18,11 @@ class RecheckOrderService extends OrderBaseService {
|
||||
|
||||
/**
|
||||
* 扫描关键词并返回以波次为单位的复核视图。
|
||||
* 支持运单号、波次号、车号三种匹配模式,并根据波次拣货模式自动分派散单/团购视图。
|
||||
* - 运单号/波次号命中散单波次(pick_mode=2/3/4):返回扁平化订单列表 list_type='single',
|
||||
* 支持运单号、波次号、车号三种匹配模式。
|
||||
* - 运单号/波次号匹配(散单):返回匹配订单所在波次的所有订单,list_type='single',
|
||||
* 顶层携带波次/拣货人/策略/任务ID等汇总信息,list 为扁平订单数组
|
||||
* - 运单号/波次号命中团购波次(pick_mode=1/5):自动转为团购模式,
|
||||
* 返回嵌套波次结构 list_type='group',每项含波次号、波次内订单明细(含 stock 商品明细)及相关汇总信息
|
||||
* - 车号匹配(团单):返回拣货任务下所有团购波次及订单,list_type='group',保持嵌套结构,
|
||||
* 顶层携带 picker_id、picker_name、task_id
|
||||
* - 运单号命中但订单无波次信息时,退回单订单详情模式(list 每项含 detail/items/expresses/logs)
|
||||
* 顶层携带 task_id
|
||||
* @param {Object} data 请求体。
|
||||
* @param {string} [data.keyword] 通用扫描关键词。
|
||||
* @param {string} [data.value] 通用扫描关键词别名。
|
||||
@ -36,7 +33,7 @@ class RecheckOrderService extends OrderBaseService {
|
||||
* @param {string} [data.waveNo] 波次号别名。
|
||||
* @param {string} [data.cart_code] 车号。
|
||||
* @param {string} [data.cartCode] 车号别名。
|
||||
* @return {Promise<Object>} 扫描结果,包含 match_type、list_type、picker_id、picker_name、task_id(散单/团单均有)与 list 数组。
|
||||
* @return {Promise<Object>} 扫描结果,包含 match_type、list_type、task_id(散单/团单均有)与 list 数组。
|
||||
*/
|
||||
async scanOrder(data = {}) {
|
||||
const warehouseId = this.getWarehouseId();
|
||||
@ -61,41 +58,6 @@ class RecheckOrderService extends OrderBaseService {
|
||||
const orderWaveNo = String(order.wave_no || '').trim();
|
||||
|
||||
if (orderWaveId > 0 && orderWaveNo) {
|
||||
// 检查波次是否为团购模式(pick_mode=1 团购小波次 / pick_mode=5 团购大波次)
|
||||
const pickMode = await this.getPickModeByWaveId(orderWaveId, warehouseId);
|
||||
if (pickMode === 1 || pickMode === 5) {
|
||||
const groupTaskId = await this.getTaskIdByWaveId(orderWaveId, warehouseId);
|
||||
if (groupTaskId > 0) {
|
||||
const [ groupWaveList, pickerInfo ] = await Promise.all([
|
||||
this.buildGroupWaveList(groupTaskId, warehouseId),
|
||||
this.getPickerInfoByTaskId(groupTaskId, warehouseId),
|
||||
]);
|
||||
return {
|
||||
match_type: matchType,
|
||||
list_type: 'group',
|
||||
waybill_no: keyword,
|
||||
picker_id: pickerInfo.picker_id,
|
||||
picker_name: pickerInfo.picker_name,
|
||||
task_id: groupTaskId,
|
||||
list: groupWaveList,
|
||||
};
|
||||
}
|
||||
// 找不到拣货任务时退回单订单详情模式
|
||||
this.assertOrderCanRecheck(order);
|
||||
const detailResult = await this.detail({ id: orderId });
|
||||
return {
|
||||
match_type: matchType,
|
||||
list_type: 'single',
|
||||
waybill_no: keyword,
|
||||
list: [{
|
||||
...(detailResult.detail || {}),
|
||||
items: Array.isArray(detailResult.items) ? detailResult.items : [],
|
||||
expresses: Array.isArray(detailResult.expresses) ? detailResult.expresses : [],
|
||||
logs: Array.isArray(detailResult.logs) ? detailResult.logs : [],
|
||||
}],
|
||||
};
|
||||
}
|
||||
|
||||
const scanView = await this.buildSingleWaveScanView(orderWaveId, orderWaveNo, warehouseId);
|
||||
if (scanView) {
|
||||
return {
|
||||
@ -129,33 +91,12 @@ class RecheckOrderService extends OrderBaseService {
|
||||
};
|
||||
}
|
||||
|
||||
// 波次号匹配 → 直接按波次号查找波次及订单(散单/团购分流)
|
||||
// 散单处理:波次号匹配 → 直接按波次号查找波次及订单
|
||||
if (matchType === 'wave') {
|
||||
const waveId = Number(waveMatchContext?.wave?.wave_id || 0);
|
||||
const waveNo = String(waveMatchContext?.wave?.wave_no || '').trim();
|
||||
|
||||
if (waveId > 0 && waveNo) {
|
||||
// 检查波次是否为团购模式(pick_mode=1 团购小波次 / pick_mode=5 团购大波次)
|
||||
const pickMode = await this.getPickModeByWaveId(waveId, warehouseId);
|
||||
if (pickMode === 1 || pickMode === 5) {
|
||||
const groupTaskId = await this.getTaskIdByWaveId(waveId, warehouseId);
|
||||
if (groupTaskId > 0) {
|
||||
const [ groupWaveList, pickerInfo ] = await Promise.all([
|
||||
this.buildGroupWaveList(groupTaskId, warehouseId),
|
||||
this.getPickerInfoByTaskId(groupTaskId, warehouseId),
|
||||
]);
|
||||
return {
|
||||
match_type: matchType,
|
||||
list_type: 'group',
|
||||
picker_id: pickerInfo.picker_id,
|
||||
picker_name: pickerInfo.picker_name,
|
||||
task_id: groupTaskId,
|
||||
list: groupWaveList,
|
||||
};
|
||||
}
|
||||
throw new Error('团购波次未找到对应拣货任务,无法加载复核视图');
|
||||
}
|
||||
|
||||
const scanView = await this.buildSingleWaveScanView(waveId, waveNo, warehouseId);
|
||||
if (scanView) {
|
||||
return {
|
||||
@ -179,15 +120,10 @@ class RecheckOrderService extends OrderBaseService {
|
||||
const taskId = Number(cartMatchContext?.task?.task_id || 0);
|
||||
|
||||
if (taskId > 0) {
|
||||
const [ groupWaveList, pickerInfo ] = await Promise.all([
|
||||
this.buildGroupWaveList(taskId, warehouseId),
|
||||
this.getPickerInfoByTaskId(taskId, warehouseId),
|
||||
]);
|
||||
const groupWaveList = await this.buildGroupWaveList(taskId, warehouseId);
|
||||
return {
|
||||
match_type: 'cart',
|
||||
list_type: 'group',
|
||||
picker_id: pickerInfo.picker_id,
|
||||
picker_name: pickerInfo.picker_name,
|
||||
task_id: taskId,
|
||||
list: groupWaveList,
|
||||
};
|
||||
@ -206,8 +142,8 @@ class RecheckOrderService extends OrderBaseService {
|
||||
* - 团购模式(pick_mode 1/5):返回任务下所有团购波次及订单的分组列表
|
||||
* @param {Object} data 请求体。
|
||||
* @param {number} data.task_id 拣货任务ID。
|
||||
* @return {Promise<Object>} 扫描视图,包含 match_type、list_type、picker_id、picker_name、task_id、list 等字段,
|
||||
* 散单模式额外包含 pick_mode、total_orders、reviewed_count、unreviewed_count。
|
||||
* @return {Promise<Object>} 扫描视图,包含 match_type、list_type、task_id、list 等字段,
|
||||
* 散单模式额外包含 picker_id、picker_name、pick_mode、total_orders、reviewed_count、unreviewed_count。
|
||||
*/
|
||||
async scanTask(data = {}) {
|
||||
const requestData = this.isPlainObject(data) ? data : {};
|
||||
@ -262,16 +198,11 @@ class RecheckOrderService extends OrderBaseService {
|
||||
|
||||
// 团购模式(pick_mode 1 或 5):复用 buildGroupWaveList
|
||||
if (pickMode === 1 || pickMode === 5) {
|
||||
const [ groupWaveList, pickerInfo ] = await Promise.all([
|
||||
this.buildGroupWaveList(taskId, warehouseId),
|
||||
this.getPickerInfoByTaskId(taskId, warehouseId),
|
||||
]);
|
||||
const groupWaveList = await this.buildGroupWaveList(taskId, warehouseId);
|
||||
|
||||
return {
|
||||
match_type: 'task',
|
||||
list_type: 'group',
|
||||
picker_id: pickerInfo.picker_id,
|
||||
picker_name: pickerInfo.picker_name,
|
||||
task_id: taskId,
|
||||
list: groupWaveList,
|
||||
};
|
||||
@ -387,10 +318,6 @@ class RecheckOrderService extends OrderBaseService {
|
||||
const reviewedCount = orders.filter(o => o.recheck_status === 'fin').length;
|
||||
const unreviewedCount = orders.length - reviewedCount;
|
||||
|
||||
// 计算打印汇总
|
||||
const printedCount = orders.filter(o => o.is_printed === true).length;
|
||||
const unprintedCount = orders.length - printedCount;
|
||||
|
||||
return {
|
||||
picker_id: pickerInfo.picker_id,
|
||||
picker_name: pickerInfo.picker_name,
|
||||
@ -404,8 +331,6 @@ class RecheckOrderService extends OrderBaseService {
|
||||
total_orders: orders.length,
|
||||
reviewed_count: reviewedCount,
|
||||
unreviewed_count: unreviewedCount,
|
||||
printed_count: printedCount,
|
||||
unprinted_count: unprintedCount,
|
||||
list: orders,
|
||||
};
|
||||
}
|
||||
@ -413,44 +338,20 @@ class RecheckOrderService extends OrderBaseService {
|
||||
/**
|
||||
* 构建单个波次的复核视图(散单/团单内部共用)。
|
||||
* 查询波次信息、拣货模式、以及波次下全部订单列表。
|
||||
* 当 waveNo 为空但 waveId 有效时,通过 waveId 反查 wms_wave_batch 补全 waveNo。
|
||||
* @param {number} waveId 波次ID。
|
||||
* @param {string} waveNo 波次号,可为空字符串,为空时自动反查补全。
|
||||
* @param {string} waveNo 波次号。
|
||||
* @param {number} warehouseId 仓库ID。
|
||||
* @return {Promise<Object|null>} 波次视图对象,包含 wave_id、wave_no、wave_type、pick_mode、order_count、orders;
|
||||
* 当 waveId 无效或 waveNo 无法补全时返回 null。
|
||||
* @return {Promise<Object|null>} 波次视图对象,包含 wave_id、wave_no、wave_type、pick_mode、order_count、orders。
|
||||
*/
|
||||
async buildSingleWaveView(waveId, waveNo, warehouseId) {
|
||||
const { ctx } = this;
|
||||
const normalizedWaveId = Number(waveId || 0);
|
||||
const normalizedWaveNo = String(waveNo || '').trim();
|
||||
|
||||
if (normalizedWaveId <= 0) {
|
||||
if (normalizedWaveId <= 0 || !normalizedWaveNo) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 解析 waveNo,为空时通过 waveId 反查 wms_wave_batch 补全
|
||||
let normalizedWaveNo = String(waveNo || '').trim();
|
||||
if (!normalizedWaveNo) {
|
||||
const fallbackRows = await ctx.model.query(
|
||||
`
|
||||
SELECT wave_no
|
||||
FROM wms_wave_batch
|
||||
WHERE wave_id = :waveId
|
||||
AND warehouse_id = :warehouseId
|
||||
LIMIT 1
|
||||
`,
|
||||
{
|
||||
replacements: { waveId: normalizedWaveId, warehouseId },
|
||||
type: ctx.model.QueryTypes.SELECT,
|
||||
}
|
||||
);
|
||||
const fallbackRow = Array.isArray(fallbackRows) && fallbackRows.length > 0 ? fallbackRows[0] : null;
|
||||
if (!fallbackRow || !fallbackRow.wave_no) {
|
||||
return null;
|
||||
}
|
||||
normalizedWaveNo = String(fallbackRow.wave_no).trim();
|
||||
}
|
||||
|
||||
// 查询波次批次信息
|
||||
const waveRows = await ctx.model.query(
|
||||
`
|
||||
@ -508,16 +409,9 @@ class RecheckOrderService extends OrderBaseService {
|
||||
/**
|
||||
* 构建团购波次列表视图(团单模式)。
|
||||
* 根据拣货任务ID查找关联的所有波次,每个波次展开为一项。
|
||||
* 波次内非拦截订单的商品明细按 stock_id 合并,plan_qty 累加,直接输出 stocks 数组;
|
||||
* 拦截订单单独输出 intercepted 列表。
|
||||
* @param {number} taskId 拣货任务ID。
|
||||
* @param {number} warehouseId 仓库ID。
|
||||
* @return {Promise<Array<Object>>} 波次视图列表,每项包含 wave_id、wave_no、wave_type、wave_status、
|
||||
* pick_mode、total_orders、processed_orders、creator、create_time、update_time、
|
||||
* order_count、box_no、reviewed_count、unreviewed_count、printed_count、unprinted_count、
|
||||
* stocks(非拦截订单合并后的商品明细)、
|
||||
* intercepted(拦截订单列表,仅当波次中存在拦截订单时出现,每项含 wave_index、order_id、
|
||||
* delivery_order_code、intercept_status 等字段)。
|
||||
* @return {Promise<Array<Object>>} 波次视图列表。
|
||||
*/
|
||||
async buildGroupWaveList(taskId, warehouseId) {
|
||||
const { ctx } = this;
|
||||
@ -572,7 +466,7 @@ class RecheckOrderService extends OrderBaseService {
|
||||
const twWaveId = Number(tw.wave_id || 0);
|
||||
const twWaveNo = String(tw.wave_no || '').trim();
|
||||
|
||||
if (twWaveId <= 0) {
|
||||
if (twWaveId <= 0 || !twWaveNo) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -588,80 +482,12 @@ class RecheckOrderService extends OrderBaseService {
|
||||
this.assertOrderCanRecheck(order);
|
||||
}
|
||||
|
||||
// 分离拦截订单与非拦截订单
|
||||
const interceptedOrders = [];
|
||||
const normalOrders = [];
|
||||
for (const order of orders) {
|
||||
const interceptStatus = String(order.intercept_status || '').trim();
|
||||
if (interceptStatus === 'intercepted') {
|
||||
interceptedOrders.push(order);
|
||||
} else {
|
||||
normalOrders.push(order);
|
||||
}
|
||||
}
|
||||
|
||||
// 团购波次中所有订单商品一致,取第一个正常订单的商品明细作为样板
|
||||
const sampleOrder = normalOrders.length > 0 ? normalOrders[0] : null;
|
||||
const sampleStock = sampleOrder ? (Array.isArray(sampleOrder.stock) ? sampleOrder.stock : []) : [];
|
||||
const stocks = sampleStock.map(item => ({
|
||||
stock_id: Number(item.stock_id || 0),
|
||||
item_code: String(item.item_code || '').trim(),
|
||||
item_name: String(item.item_name || '').trim(),
|
||||
sku_property: String(item.sku_property || '').trim(),
|
||||
packing_requirements: String(item.packing_requirements || '').trim(),
|
||||
barcodes: Array.isArray(item.barcodes) ? [ ...item.barcodes ] : [],
|
||||
images: Array.isArray(item.images) ? [ ...item.images ] : [],
|
||||
has_shared_barcode: Boolean(item.has_shared_barcode),
|
||||
plan_qty: Number(item.plan_qty || 0),
|
||||
}));
|
||||
|
||||
// 构建拦截订单列表
|
||||
const intercepted = interceptedOrders.map(order => ({
|
||||
wave_index: Number(order.wave_index || 0),
|
||||
order_id: Number(order.order_id || 0),
|
||||
delivery_order_code: String(order.delivery_order_code || '').trim(),
|
||||
intercept_status: String(order.intercept_status || '').trim(),
|
||||
}));
|
||||
|
||||
// 提取正常(非拦截)订单的 ID 列表
|
||||
const orderIds = normalOrders.map(order => Number(order.order_id || 0)).filter(id => id > 0);
|
||||
|
||||
// 计算波次内复核统计(基于非拦截订单的 recheck_status 实时聚合)
|
||||
const reviewedCount = normalOrders.filter(o => String(o.recheck_status || '').trim() === 'fin').length;
|
||||
const unreviewedCount = normalOrders.length - reviewedCount;
|
||||
|
||||
// 计算波次内打印统计(基于非拦截订单的 is_printed 字段)
|
||||
const printedCount = normalOrders.filter(o => o.is_printed === true).length;
|
||||
const unprintedCount = normalOrders.length - printedCount;
|
||||
|
||||
// 使用任务级别的 pick_mode 覆盖(团单模式下以任务为准)
|
||||
const result = {
|
||||
wave_id: waveView.wave_id,
|
||||
wave_no: waveView.wave_no,
|
||||
wave_type: waveView.wave_type,
|
||||
wave_status: waveView.wave_status,
|
||||
return {
|
||||
...waveView,
|
||||
pick_mode: pickMode,
|
||||
total_orders: waveView.total_orders,
|
||||
processed_orders: waveView.processed_orders,
|
||||
creator: waveView.creator,
|
||||
create_time: waveView.create_time,
|
||||
update_time: waveView.update_time,
|
||||
order_count: waveView.order_count,
|
||||
box_no: Number(tw.box_no || 0),
|
||||
order_ids: orderIds,
|
||||
stocks,
|
||||
reviewed_count: reviewedCount,
|
||||
unreviewed_count: unreviewedCount,
|
||||
printed_count: printedCount,
|
||||
unprinted_count: unprintedCount,
|
||||
};
|
||||
|
||||
// 仅当存在拦截订单时才追加 intercepted 字段
|
||||
if (intercepted.length > 0) {
|
||||
result.intercepted = intercepted;
|
||||
}
|
||||
|
||||
return result;
|
||||
});
|
||||
|
||||
const waveViews = await Promise.all(waveViewPromises);
|
||||
@ -728,64 +554,6 @@ class RecheckOrderService extends OrderBaseService {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据波次ID查询关联的拣货任务ID。
|
||||
* 优先查 wms_wave_pick_task.wave_id,其次查 wms_wave_pick_task_wave 关联表。
|
||||
* @param {number} waveId 波次ID。
|
||||
* @param {number} warehouseId 仓库ID。
|
||||
* @return {Promise<number>} 拣货任务ID,未找到返回 0。
|
||||
*/
|
||||
async getTaskIdByWaveId(waveId, warehouseId) {
|
||||
const { ctx } = this;
|
||||
const normalizedWaveId = Number(waveId || 0);
|
||||
|
||||
if (normalizedWaveId <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 先按 wave_id 直接查拣货任务
|
||||
const taskRows = await ctx.model.query(
|
||||
`
|
||||
SELECT id AS task_id
|
||||
FROM wms_wave_pick_task
|
||||
WHERE wave_id = :waveId
|
||||
AND warehouse_id = :warehouseId
|
||||
ORDER BY create_time DESC
|
||||
LIMIT 1
|
||||
`,
|
||||
{
|
||||
replacements: { waveId: normalizedWaveId, warehouseId },
|
||||
type: ctx.model.QueryTypes.SELECT,
|
||||
}
|
||||
);
|
||||
|
||||
if (Array.isArray(taskRows) && taskRows.length > 0) {
|
||||
return Number(taskRows[0].task_id || 0);
|
||||
}
|
||||
|
||||
// 通过 wms_wave_pick_task_wave 关联查询
|
||||
const twRows = await ctx.model.query(
|
||||
`
|
||||
SELECT tw.task_id
|
||||
FROM wms_wave_pick_task_wave tw
|
||||
WHERE tw.wave_id = :waveId
|
||||
AND tw.warehouse_id = :warehouseId
|
||||
ORDER BY tw.task_id DESC
|
||||
LIMIT 1
|
||||
`,
|
||||
{
|
||||
replacements: { waveId: normalizedWaveId, warehouseId },
|
||||
type: ctx.model.QueryTypes.SELECT,
|
||||
}
|
||||
);
|
||||
|
||||
if (Array.isArray(twRows) && twRows.length > 0) {
|
||||
return Number(twRows[0].task_id || 0);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询波次下所有订单的基本信息列表。
|
||||
* 包含运单号、打印状态、复核状态、波次内序号(优先从 wms_order_wave_index 读取真实 wave_index,
|
||||
@ -1166,42 +934,6 @@ class RecheckOrderService extends OrderBaseService {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过拣货任务ID查询拣货人信息。
|
||||
* @param {number} taskId 拣货任务ID。
|
||||
* @param {number} warehouseId 仓库ID。
|
||||
* @return {Promise<{ picker_id: number|null, picker_name: string }>} 拣货人信息。
|
||||
*/
|
||||
async getPickerInfoByTaskId(taskId, warehouseId) {
|
||||
const { ctx } = this;
|
||||
const normalizedTaskId = Number(taskId || 0);
|
||||
|
||||
if (normalizedTaskId <= 0) {
|
||||
return { picker_id: null, picker_name: '' };
|
||||
}
|
||||
|
||||
const rows = await ctx.model.query(
|
||||
`
|
||||
SELECT pick_user_id, pick_user_name
|
||||
FROM wms_wave_pick_task
|
||||
WHERE id = :taskId
|
||||
AND warehouse_id = :warehouseId
|
||||
LIMIT 1
|
||||
`,
|
||||
{
|
||||
replacements: { taskId: normalizedTaskId, warehouseId },
|
||||
type: ctx.model.QueryTypes.SELECT,
|
||||
}
|
||||
);
|
||||
|
||||
const row = Array.isArray(rows) && rows.length > 0 ? rows[0] : null;
|
||||
|
||||
return {
|
||||
picker_id: row && row.pick_user_id != null ? Number(row.pick_user_id) : null,
|
||||
picker_name: String(row && row.pick_user_name || '').trim(),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询波次关联的策略信息。
|
||||
* 当前 wms_wave_batch 与 wms_wave_pick_task 均未直接存储 strategy_id,
|
||||
@ -1229,25 +961,15 @@ class RecheckOrderService extends OrderBaseService {
|
||||
|
||||
/**
|
||||
* 确认订单已复核,并写入复核任务记录。
|
||||
* 支持两种模式:传入 wave_id 时走团购波次批量复核,否则走单订单复核。
|
||||
* @param {Object} data 请求体。
|
||||
* @param {number|string} [data.wave_id] 波次ID,传入时触发团购波次批量复核。
|
||||
* @param {number|string} [data.order_id] 订单ID。
|
||||
* @param {number|string} [data.id] 订单ID别名。
|
||||
* @param {number|string} [data.orderId] 订单ID别名。
|
||||
* @return {Promise<Object>} 复核确认结果。
|
||||
*/
|
||||
async confirmRecheck(data = {}) {
|
||||
const requestData = this.isPlainObject(data) ? data : {};
|
||||
const warehouseId = this.getWarehouseId();
|
||||
|
||||
// 团购波次批量复核
|
||||
const { wave_id: waveId } = requestData;
|
||||
if (waveId) {
|
||||
return await this.confirmRecheckByWaveId(Number(waveId), warehouseId);
|
||||
}
|
||||
|
||||
const { ctx } = this;
|
||||
const warehouseId = this.getWarehouseId();
|
||||
const orderId = this.resolveOrderId(data);
|
||||
const orderModel = await this.getOrderModelByTableType('current', warehouseId);
|
||||
const orderWhere = this.buildOrderWhere([ orderId ], warehouseId);
|
||||
@ -1345,15 +1067,6 @@ class RecheckOrderService extends OrderBaseService {
|
||||
// 更新波次拣货任务订单复核状态,并判断是否需要解绑车任务
|
||||
await this.updateTaskOrderReviewAndTryUnbindCart(orderId, warehouseId, operator, now);
|
||||
|
||||
// 写入操作日志
|
||||
await this._writeRecheckActionLog({
|
||||
orderId,
|
||||
waybillNo,
|
||||
warehouseId,
|
||||
operator,
|
||||
now,
|
||||
});
|
||||
|
||||
return {
|
||||
order_id: orderId,
|
||||
waybill_no: waybillNo,
|
||||
@ -1363,331 +1076,6 @@ class RecheckOrderService extends OrderBaseService {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 团购波次批量复核:将波次下所有非拦截订单标记为已复核,并更新波次批次状态为复核完成。
|
||||
* @param {number} waveId 波次ID。
|
||||
* @param {number} warehouseId 仓库ID。
|
||||
* @return {Promise<Object>} 批量复核结果,包含 wave_id、success_count、
|
||||
* intercepted_count、total_count。
|
||||
*/
|
||||
async confirmRecheckByWaveId(waveId, warehouseId) {
|
||||
const { ctx } = this;
|
||||
const normalizedWaveId = Number(waveId);
|
||||
|
||||
if (!Number.isFinite(normalizedWaveId) || normalizedWaveId <= 0) {
|
||||
throw new Error('波次ID无效');
|
||||
}
|
||||
|
||||
// 查询波次信息,判断是否为团购波次
|
||||
const waveRows = await ctx.model.query(
|
||||
`SELECT wave_id, wave_no, wave_type
|
||||
FROM wms_wave_batch
|
||||
WHERE wave_id = :waveId
|
||||
AND warehouse_id = :warehouseId
|
||||
LIMIT 1`,
|
||||
{
|
||||
replacements: { waveId: normalizedWaveId, warehouseId },
|
||||
type: ctx.model.QueryTypes.SELECT,
|
||||
}
|
||||
);
|
||||
|
||||
const waveRow = Array.isArray(waveRows) && waveRows.length > 0 ? waveRows[0] : null;
|
||||
|
||||
if (!waveRow) {
|
||||
throw new Error('未找到对应波次');
|
||||
}
|
||||
|
||||
const waveType = Number(waveRow.wave_type || 0);
|
||||
const pickMode = await this.getPickModeByWaveId(normalizedWaveId, warehouseId);
|
||||
const isGroupBuy = waveType === 1 || pickMode === 1;
|
||||
|
||||
if (!isGroupBuy) {
|
||||
throw new Error('该波次不是团购波次,不允许批量复核');
|
||||
}
|
||||
|
||||
// 查询波次下所有订单
|
||||
const orderModel = await this.getOrderModelByTableType('current', warehouseId);
|
||||
const orderRows = await orderModel.findAll({
|
||||
where: {
|
||||
wave_id: normalizedWaveId,
|
||||
warehouse_id: warehouseId,
|
||||
},
|
||||
attributes: [
|
||||
'id',
|
||||
'delivery_order_code',
|
||||
'pre_delivery_order_code',
|
||||
'intercept_status',
|
||||
'pick_status',
|
||||
'recheck_status',
|
||||
],
|
||||
raw: true,
|
||||
});
|
||||
|
||||
const orderList = Array.isArray(orderRows) ? orderRows : [];
|
||||
|
||||
if (orderList.length === 0) {
|
||||
throw new Error('波次下没有订单');
|
||||
}
|
||||
|
||||
// 分离拦截订单与非拦截订单
|
||||
const normalOrders = [];
|
||||
const interceptedOrders = [];
|
||||
|
||||
for (const order of orderList) {
|
||||
if (String(order.intercept_status || '').trim() === 'intercepted') {
|
||||
interceptedOrders.push(order);
|
||||
} else {
|
||||
normalOrders.push(order);
|
||||
}
|
||||
}
|
||||
|
||||
if (normalOrders.length === 0) {
|
||||
return {
|
||||
wave_id: normalizedWaveId,
|
||||
success_count: 0,
|
||||
intercepted_count: interceptedOrders.length,
|
||||
total_count: orderList.length,
|
||||
};
|
||||
}
|
||||
|
||||
// 验证所有非拦截订单允许复核
|
||||
for (const order of normalOrders) {
|
||||
this.assertOrderCanRecheck(order);
|
||||
}
|
||||
|
||||
const now = new Date();
|
||||
const normalOrderIds = normalOrders
|
||||
.map(o => Number(o.id))
|
||||
.filter(id => id > 0);
|
||||
|
||||
// 批量更新订单复核状态
|
||||
await orderModel.update(
|
||||
{
|
||||
recheck_status: 'fin',
|
||||
recheck_time: now,
|
||||
updated_at: now,
|
||||
},
|
||||
{
|
||||
where: this.buildOrderWhere(normalOrderIds, warehouseId),
|
||||
}
|
||||
);
|
||||
|
||||
// 批量插入复核任务记录
|
||||
const operator = this.getOrderLogOperator();
|
||||
const operatorNo = String(operator.id || '').trim();
|
||||
const operatorName = String(operator.name || '').trim();
|
||||
|
||||
if (normalOrders.length > 0) {
|
||||
const valuePlaceholders = [];
|
||||
const replacements = {};
|
||||
let idx = 0;
|
||||
|
||||
for (const order of normalOrders) {
|
||||
const orderId = Number(order.id);
|
||||
const reviewNo = this.buildRecheckReviewNo(orderId, now);
|
||||
const orderNo = String(order.delivery_order_code || order.pre_delivery_order_code || '').trim();
|
||||
const i = idx++;
|
||||
|
||||
valuePlaceholders.push(
|
||||
`(:reviewNo${i}, :warehouseId${i}, :orderId${i}, :orderNo${i}, :waybillNo${i}, `
|
||||
+ `:taskStatus${i}, :scanStatus${i}, :reviewEmpNo${i}, :reviewEmpName${i}, `
|
||||
+ `:scanEmpNo${i}, :scanEmpName${i}, :scanTime${i}, :finishTime${i}, :remark${i})`
|
||||
);
|
||||
|
||||
replacements[`reviewNo${i}`] = reviewNo;
|
||||
replacements[`warehouseId${i}`] = warehouseId;
|
||||
replacements[`orderId${i}`] = orderId;
|
||||
replacements[`orderNo${i}`] = orderNo;
|
||||
replacements[`waybillNo${i}`] = '';
|
||||
replacements[`taskStatus${i}`] = 2;
|
||||
replacements[`scanStatus${i}`] = 1;
|
||||
replacements[`reviewEmpNo${i}`] = operatorNo;
|
||||
replacements[`reviewEmpName${i}`] = operatorName;
|
||||
replacements[`scanEmpNo${i}`] = operatorNo;
|
||||
replacements[`scanEmpName${i}`] = operatorName;
|
||||
replacements[`scanTime${i}`] = now;
|
||||
replacements[`finishTime${i}`] = now;
|
||||
replacements[`remark${i}`] = '系统复核完成';
|
||||
}
|
||||
|
||||
const insertSQL = `
|
||||
INSERT INTO wms_recheck_task (
|
||||
review_no,
|
||||
warehouse_id,
|
||||
order_id,
|
||||
order_no,
|
||||
waybill_no,
|
||||
task_status,
|
||||
scan_status,
|
||||
review_emp_no,
|
||||
review_emp_name,
|
||||
scan_emp_no,
|
||||
scan_emp_name,
|
||||
scan_time,
|
||||
finish_time,
|
||||
remark
|
||||
) VALUES ${valuePlaceholders.join(', ')}
|
||||
`;
|
||||
|
||||
await ctx.model.query(insertSQL, {
|
||||
replacements,
|
||||
type: ctx.model.QueryTypes.INSERT,
|
||||
});
|
||||
}
|
||||
|
||||
// 批量更新 wms_wave_pick_task_order 复核状态,并检查解绑车任务
|
||||
await this.updateTaskOrdersReviewBatch(normalOrderIds, warehouseId, operator, now);
|
||||
|
||||
// 更新 wms_wave_batch 波次复核状态:标记复核完成、记录操作人与复核时间
|
||||
await ctx.model.query(
|
||||
`UPDATE wms_wave_batch
|
||||
SET wave_status = 5,
|
||||
check_operator = :operatorName,
|
||||
check_time = :now,
|
||||
processed_orders = :processedCount,
|
||||
update_time = :now
|
||||
WHERE wave_id = :waveId
|
||||
AND warehouse_id = :warehouseId`,
|
||||
{
|
||||
replacements: {
|
||||
waveId: normalizedWaveId,
|
||||
warehouseId,
|
||||
operatorName: operatorName || operatorNo,
|
||||
processedCount: normalOrders.length,
|
||||
now,
|
||||
},
|
||||
type: ctx.model.QueryTypes.UPDATE,
|
||||
}
|
||||
);
|
||||
|
||||
// 写入操作日志
|
||||
await this._writeRecheckActionLog({
|
||||
waveId: normalizedWaveId,
|
||||
waveNo: String(waveRow.wave_no || '').trim(),
|
||||
warehouseId,
|
||||
operator,
|
||||
normalOrderCount: normalOrders.length,
|
||||
interceptedOrderCount: interceptedOrders.length,
|
||||
totalOrderCount: orderList.length,
|
||||
now,
|
||||
});
|
||||
|
||||
return {
|
||||
wave_id: normalizedWaveId,
|
||||
success_count: normalOrders.length,
|
||||
intercepted_count: interceptedOrders.length,
|
||||
total_count: orderList.length,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 写入复核操作日志到 wms_wave_pick_action_log(内部方法)。
|
||||
*
|
||||
* @param {Object} params 日志参数。
|
||||
* @param {number} [params.orderId] 订单ID(单订单复核场景)。
|
||||
* @param {string} [params.waybillNo] 运单号(单订单复核场景)。
|
||||
* @param {number} [params.waveId] 波次ID(团购批量复核场景)。
|
||||
* @param {string} [params.waveNo] 波次号(团购批量复核场景)。
|
||||
* @param {number} params.warehouseId 仓库ID。
|
||||
* @param {{ id: string|null, name: string }} params.operator 操作人信息。
|
||||
* @param {number} [params.normalOrderCount] 复核成功的订单数(批量场景)。
|
||||
* @param {number} [params.interceptedOrderCount] 拦截的订单数(批量场景)。
|
||||
* @param {number} [params.totalOrderCount] 总订单数(批量场景)。
|
||||
* @param {Date} params.now 操作时间。
|
||||
* @return {Promise<void>} 无返回值。
|
||||
*/
|
||||
async _writeRecheckActionLog(params = {}) {
|
||||
const {
|
||||
orderId,
|
||||
waybillNo,
|
||||
waveId,
|
||||
waveNo,
|
||||
warehouseId,
|
||||
operator,
|
||||
normalOrderCount,
|
||||
interceptedOrderCount,
|
||||
totalOrderCount,
|
||||
now,
|
||||
} = params;
|
||||
|
||||
const operatorId = operator && operator.id ? Number(operator.id) : 0;
|
||||
const operatorName = operator && operator.name ? String(operator.name).trim() : 'system';
|
||||
const isBatch = waveId !== undefined && waveId !== null;
|
||||
const tag = isBatch ? 'recheck_batch' : 'recheck';
|
||||
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 ? 'recheck_batch' : 'recheck',
|
||||
requestId,
|
||||
operatorId,
|
||||
deviceId: null,
|
||||
seqNo: 1,
|
||||
snapshot: JSON.stringify(isBatch
|
||||
? {
|
||||
wave_id: waveId,
|
||||
wave_no: waveNo || '',
|
||||
success_count: normalOrderCount,
|
||||
intercepted_count: interceptedOrderCount,
|
||||
total_count: totalOrderCount,
|
||||
operator_name: operatorName,
|
||||
recheck_time: now instanceof Date ? now.toISOString() : String(now || ''),
|
||||
}
|
||||
: {
|
||||
order_id: orderId,
|
||||
waybill_no: waybillNo || '',
|
||||
operator_name: operatorName,
|
||||
recheck_time: now instanceof Date ? now.toISOString() : String(now || ''),
|
||||
}),
|
||||
},
|
||||
type: this.ctx.model.QueryTypes.INSERT,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新波次拣货任务订单的复核状态,若任务下所有订单均已复核完成则自动解绑车任务。
|
||||
* @param {number} orderId 订单ID。
|
||||
@ -1788,105 +1176,6 @@ class RecheckOrderService extends OrderBaseService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量更新波次拣货任务订单的复核状态,并按任务维度检查是否需要解绑车任务。
|
||||
* 与单订单版本不同,本方法一次性更新所有相关任务订单的 review_status,
|
||||
* 再按去重后的 task_id 逐任务判断是否所有订单均已复核完成。
|
||||
* @param {number[]} orderIds 订单ID列表。
|
||||
* @param {number} warehouseId 仓库ID。
|
||||
* @param {{ id: string|null, name: string }} operator 操作人信息。
|
||||
* @param {Date} now 当前时间。
|
||||
* @return {Promise<void>} 无返回值。
|
||||
*/
|
||||
async updateTaskOrdersReviewBatch(orderIds, warehouseId, operator, now) {
|
||||
const { ctx } = this;
|
||||
|
||||
if (!Array.isArray(orderIds) || orderIds.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const taskOrderColumnSet = await this.getTableColumnSet('wms_wave_pick_task_order');
|
||||
const hasReviewStatus = taskOrderColumnSet.has('review_status');
|
||||
|
||||
if (!hasReviewStatus) {
|
||||
return;
|
||||
}
|
||||
|
||||
const hasReviewUserId = taskOrderColumnSet.has('review_user_id');
|
||||
const hasReviewResult = taskOrderColumnSet.has('review_result');
|
||||
const hasReviewTime = taskOrderColumnSet.has('review_time');
|
||||
const operatorUserId = Number(operator.id) || 0;
|
||||
|
||||
const reviewSetClauses = [ 'review_status = 1' ];
|
||||
|
||||
if (hasReviewUserId) reviewSetClauses.push('review_user_id = :operatorUserId');
|
||||
if (hasReviewResult) reviewSetClauses.push('review_result = 1');
|
||||
if (hasReviewTime) reviewSetClauses.push('review_time = :now');
|
||||
reviewSetClauses.push('update_time = NOW()');
|
||||
|
||||
await ctx.model.query(
|
||||
`UPDATE wms_wave_pick_task_order
|
||||
SET ${reviewSetClauses.join(',\n ')}
|
||||
WHERE order_id IN (:orderIds)
|
||||
AND warehouse_id = :warehouseId`,
|
||||
{
|
||||
replacements: { orderIds, warehouseId, operatorUserId, now },
|
||||
type: ctx.model.QueryTypes.UPDATE,
|
||||
}
|
||||
);
|
||||
|
||||
// 查询受影响的去重 task_id
|
||||
const taskRows = await ctx.model.query(
|
||||
`SELECT DISTINCT task_id
|
||||
FROM wms_wave_pick_task_order
|
||||
WHERE order_id IN (:orderIds)
|
||||
AND warehouse_id = :warehouseId`,
|
||||
{
|
||||
replacements: { orderIds, warehouseId },
|
||||
type: ctx.model.QueryTypes.SELECT,
|
||||
}
|
||||
);
|
||||
|
||||
const taskIds = (Array.isArray(taskRows) ? taskRows : [])
|
||||
.map(r => Number(r.task_id || 0))
|
||||
.filter(id => id > 0);
|
||||
|
||||
// 逐任务判断是否所有订单均已复核完成
|
||||
for (const taskId of taskIds) {
|
||||
const unreviewedRows = await ctx.model.query(
|
||||
`SELECT COUNT(*) AS cnt
|
||||
FROM wms_wave_pick_task_order
|
||||
WHERE task_id = :taskId
|
||||
AND warehouse_id = :warehouseId
|
||||
AND review_status != 1`,
|
||||
{
|
||||
replacements: { taskId, warehouseId },
|
||||
type: ctx.model.QueryTypes.SELECT,
|
||||
}
|
||||
);
|
||||
|
||||
const unreviewedCount = Number(
|
||||
(Array.isArray(unreviewedRows) && unreviewedRows.length > 0 ? unreviewedRows[0]?.cnt : 0)
|
||||
);
|
||||
|
||||
if (unreviewedCount > 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 任务下所有订单均已复核完成,解绑车任务
|
||||
try {
|
||||
await this.unbindCartForTask(taskId, warehouseId, operatorUserId);
|
||||
ctx.logger.info(
|
||||
`[confirmRecheck] 批量复核-车任务解绑成功, taskId=${taskId}, operatorUserId=${operatorUserId}`
|
||||
);
|
||||
} catch (unbindError) {
|
||||
ctx.logger.warn(
|
||||
`[confirmRecheck] 批量复核-解绑车任务失败, taskId=${taskId}, error=${unbindError.message}`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解绑车任务:清空波次拣货任务的车绑定、停用拣货车绑定记录、释放拣货车。
|
||||
* @param {number} taskId 波次拣货任务ID。
|
||||
@ -2196,20 +1485,7 @@ class RecheckOrderService extends OrderBaseService {
|
||||
const { ctx } = this;
|
||||
const warehouseId = this.getWarehouseId();
|
||||
const taskOrderColumnSet = await this.getTableColumnSet('wms_wave_pick_task_order');
|
||||
|
||||
/**
|
||||
* 通过车号查找匹配的拣货任务行。
|
||||
* 匹配优先级:
|
||||
* 1. wms_wave_pick_task.current_cart_code_snapshot(任务主表车号快照)
|
||||
* 2. wms_wave_pick_task_order.cart_code_snapshot(任务订单行车号快照,仅散单模式有数据)
|
||||
* 3. wms_pick_task_cart_binding(车任务绑定表,所有模式均有记录,回退兜底)
|
||||
* @param {string} cartCode 车号。
|
||||
* @param {number} warehouseId 仓库ID。
|
||||
* @return {Promise<Object|null>} 任务行,未找到返回 null。
|
||||
*/
|
||||
const findTaskByCartCode = async (cartCode, warehouseId) => {
|
||||
// 第一优先级:任务主表车号快照 + 任务订单行车号快照
|
||||
const primaryRows = await ctx.model.query(
|
||||
const taskRows = await ctx.model.query(
|
||||
`
|
||||
SELECT
|
||||
t.id AS task_id,
|
||||
@ -2233,44 +1509,15 @@ class RecheckOrderService extends OrderBaseService {
|
||||
LIMIT 1
|
||||
`,
|
||||
{
|
||||
replacements: { warehouseId, cartCode },
|
||||
replacements: {
|
||||
warehouseId,
|
||||
cartCode,
|
||||
},
|
||||
type: ctx.model.QueryTypes.SELECT,
|
||||
}
|
||||
);
|
||||
|
||||
if (Array.isArray(primaryRows) && primaryRows.length > 0) {
|
||||
return primaryRows[0];
|
||||
}
|
||||
|
||||
// 第二优先级(回退):车任务绑定表(覆盖小团购等无 wms_wave_pick_task_order 记录的场景)
|
||||
const bindingRows = await ctx.model.query(
|
||||
`
|
||||
SELECT
|
||||
t.id AS task_id,
|
||||
t.task_no,
|
||||
t.pick_mode,
|
||||
t.status,
|
||||
t.review_status,
|
||||
t.current_cart_code_snapshot
|
||||
FROM wms_pick_task_cart_binding b
|
||||
INNER JOIN wms_wave_pick_task t
|
||||
ON t.id = b.task_id
|
||||
WHERE b.cart_code_snapshot = :cartCode
|
||||
AND b.warehouse_id = :warehouseId
|
||||
AND b.is_active = 1
|
||||
ORDER BY b.create_time DESC, b.id DESC
|
||||
LIMIT 1
|
||||
`,
|
||||
{
|
||||
replacements: { warehouseId, cartCode },
|
||||
type: ctx.model.QueryTypes.SELECT,
|
||||
}
|
||||
);
|
||||
|
||||
return (Array.isArray(bindingRows) && bindingRows.length > 0) ? bindingRows[0] : null;
|
||||
};
|
||||
|
||||
const taskRow = await findTaskByCartCode(cartCode, warehouseId);
|
||||
const taskRow = Array.isArray(taskRows) && taskRows.length > 0 ? taskRows[0] : null;
|
||||
const taskId = Number(taskRow && taskRow.task_id || 0);
|
||||
if (!Number.isInteger(taskId) || taskId <= 0) {
|
||||
return {
|
||||
@ -2281,28 +1528,6 @@ class RecheckOrderService extends OrderBaseService {
|
||||
};
|
||||
}
|
||||
|
||||
const pickMode = Number(taskRow.pick_mode || 0);
|
||||
|
||||
// 团购模式(小波次 pick_mode=1 / 大波次 pick_mode=5):
|
||||
// wms_wave_pick_task_order 表无记录,直接返回 task 信息,
|
||||
// 以 task_id 作为 order_id 保证 pickOrderMatchByKeyword 的 cartMatch.order_id > 0 检查通过
|
||||
if (pickMode === 1 || pickMode === 5) {
|
||||
const task = {
|
||||
task_id: taskId,
|
||||
task_no: String(taskRow.task_no || '').trim(),
|
||||
pick_mode: pickMode,
|
||||
status: Number(taskRow.status || 0),
|
||||
review_status: Number(taskRow.review_status || 0),
|
||||
current_cart_code_snapshot: String(taskRow.current_cart_code_snapshot || '').trim(),
|
||||
};
|
||||
return {
|
||||
order_id: taskId,
|
||||
task,
|
||||
task_orders: [],
|
||||
matched_order_ids: [],
|
||||
};
|
||||
}
|
||||
|
||||
const pickStatusSelect = taskOrderColumnSet.has('pick_status')
|
||||
? 'pto.pick_status'
|
||||
: 'NULL AS pick_status';
|
||||
|
||||
@ -1022,15 +1022,6 @@ 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,
|
||||
@ -1950,11 +1941,7 @@ class WaveService extends OrderBaseService {
|
||||
|
||||
for (const row of itemRows) {
|
||||
const normalized = this.normalizeOrderItemRow(row);
|
||||
const hasIdentity = normalized.stock_id > 0
|
||||
|| normalized.item_code
|
||||
|| normalized.item_name;
|
||||
|
||||
if (!hasIdentity || normalized.quantity <= 0) {
|
||||
if (!normalized.item_code || normalized.quantity <= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -6655,14 +6642,6 @@ class WaveService extends OrderBaseService {
|
||||
});
|
||||
}
|
||||
|
||||
await this.rebuildOrderWaveIndex({
|
||||
warehouseId,
|
||||
waveId,
|
||||
orderIds: grabbedOrderIds,
|
||||
orderModel,
|
||||
transaction,
|
||||
});
|
||||
|
||||
await transaction.commit();
|
||||
|
||||
await this.batchCreateOrderOperationLogs(grabbedOrderIds.map(orderId => ({
|
||||
@ -10625,34 +10604,10 @@ 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,
|
||||
@ -10801,14 +10756,13 @@ class WaveService extends OrderBaseService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建任务波次关联写入行。
|
||||
* 构建任务与波次关联写入行。
|
||||
*
|
||||
* @param {Object} options 构建参数。
|
||||
* @param {number} options.taskId 任务ID。
|
||||
* @param {Object} options.plan 预处理计划。
|
||||
* @param {Array<number>} options.selectedWaveIds 已选波次ID。
|
||||
* @param {Map<number, string>} [options.waveNoMap] wave_id → wave_no 映射。
|
||||
* @return {Array<Object>} 任务波次关联行。
|
||||
* @return {Array<Object>} 任务波次行。
|
||||
*/
|
||||
buildTaskWaveRows(options = {}) {
|
||||
const taskId = Number(options && options.taskId || 0);
|
||||
@ -10817,14 +10771,11 @@ 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: waveNoMap.get(waveId) || null,
|
||||
wave_no: null,
|
||||
box_no: index + 1,
|
||||
status: 0,
|
||||
bind_time: null,
|
||||
@ -11594,12 +11545,11 @@ class WaveService extends OrderBaseService {
|
||||
/**
|
||||
* 公共拣货任务取消流程。
|
||||
*
|
||||
* 仅允许取消状态为 0/1/2/3 的任务。取消后会回收拣货车绑定。
|
||||
*
|
||||
* 按任务来源区分行为:
|
||||
* - source=1(PDA 抓取):释放关联波次(清空订单 wave_id、删除 wms_wave_batch),
|
||||
* 使订单可重新参与后续策略抓取;状态为 2/3 时还会回退拣货状态。
|
||||
* - source=2(后台/扫描创建):不释放波次,仅作废任务(更新状态为 9、解绑拣货车)。
|
||||
* 仅允许取消状态为 0/1/2/3 的任务。取消后会回收拣货车绑定、
|
||||
* 删除任务关联波次并将订单 wave_id 清空,使订单可重新参与后续策略抓取。
|
||||
* 当任务状态为 2(待复核)或 3(已完成)时,还会回退已拣货订单的
|
||||
* wms_wave_pick_task_order.pick_status 和 order_delivery.pick_status,
|
||||
* 使订单恢复为未拣货状态。
|
||||
*
|
||||
* @param {Object} [params={}] 取消参数。
|
||||
* @param {Array<number>} params.taskIds 任务ID列表。
|
||||
@ -11667,7 +11617,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, source
|
||||
SELECT id, task_no, warehouse_id, status, current_cart_id
|
||||
FROM wms_wave_pick_task
|
||||
WHERE id = :taskId
|
||||
AND warehouse_id = :warehouseId
|
||||
@ -11735,7 +11685,6 @@ 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(`
|
||||
@ -11772,12 +11721,8 @@ 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) {
|
||||
if (!isScanCreated) {
|
||||
// PDA 抓取:释放波次
|
||||
releasedWaveRows = await this.ctx.model.query(`
|
||||
SELECT wave_id, wave_no
|
||||
FROM wms_wave_batch
|
||||
@ -11815,9 +11760,7 @@ class WaveService extends OrderBaseService {
|
||||
},
|
||||
transaction,
|
||||
});
|
||||
}
|
||||
|
||||
// 清理任务-波次关联(所有来源都需要)
|
||||
await this.ctx.model.query(`
|
||||
DELETE FROM wms_wave_pick_task_wave
|
||||
WHERE task_id = :taskId
|
||||
@ -11831,8 +11774,8 @@ class WaveService extends OrderBaseService {
|
||||
});
|
||||
}
|
||||
|
||||
// 当任务状态为待复核(2)或已完成(3)时,回退订单拣货状态(仅 PDA 抓取)
|
||||
if (!isScanCreated && [ 2, 3 ].includes(taskStatus)) {
|
||||
// 当任务状态为待复核(2)或已完成(3)时,回退订单拣货状态
|
||||
if ([ 2, 3 ].includes(taskStatus)) {
|
||||
await this.ctx.model.query(`
|
||||
UPDATE wms_wave_pick_task_order
|
||||
SET pick_status = 0,
|
||||
@ -11944,9 +11887,8 @@ class WaveService extends OrderBaseService {
|
||||
seq_no: 1,
|
||||
snapshot: JSON.stringify({
|
||||
task_no: taskNo,
|
||||
source: taskSource,
|
||||
released_wave_ids: isScanCreated ? [] : waveIds,
|
||||
released_order_count: isScanCreated ? 0 : taskOrderIds.length,
|
||||
released_wave_ids: waveIds,
|
||||
released_order_count: taskOrderIds.length,
|
||||
}),
|
||||
}], transaction);
|
||||
|
||||
@ -11962,19 +11904,14 @@ class WaveService extends OrderBaseService {
|
||||
review_time: null,
|
||||
review_result: null,
|
||||
event_type: 'task_cancelled',
|
||||
event_desc: isScanCreated
|
||||
? `任务取消(未释放波次): ${taskNo || taskId}`
|
||||
: `任务取消并释放波次: ${taskNo || taskId}`,
|
||||
event_desc: `任务取消并释放波次: ${taskNo || taskId}`,
|
||||
operator_id: Number.isInteger(operatorId) ? operatorId : 0,
|
||||
operator_name: operatorName,
|
||||
snapshot: JSON.stringify({
|
||||
task_no: taskNo,
|
||||
source: taskSource,
|
||||
released_wave_ids: isScanCreated ? [] : waveIds,
|
||||
released_order_count: isScanCreated ? 0 : taskOrderIds.length,
|
||||
released_wave_nos: isScanCreated
|
||||
? []
|
||||
: (Array.isArray(releasedWaveRows) ? releasedWaveRows : [])
|
||||
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),
|
||||
}),
|
||||
|
||||
@ -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: 2,
|
||||
source: 1,
|
||||
});
|
||||
|
||||
return this.success('ok', {
|
||||
|
||||
@ -1124,16 +1124,7 @@ class DeliveryOrderService extends Service {
|
||||
continue;
|
||||
}
|
||||
let wms_stock = null;
|
||||
// 手工单:调用方直接传入 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) {
|
||||
if (!line.itemId) {
|
||||
// 查找唯一键(appKey 为空时不作为条件,兼容内部手动建单场景)
|
||||
const stockWhere = {
|
||||
item_code: line.itemCode,
|
||||
@ -1148,16 +1139,32 @@ class DeliveryOrderService extends Service {
|
||||
wms_stock = await app.model.StockStore.findByPk(line.itemId, { transaction });
|
||||
}
|
||||
|
||||
if (!wms_stock) {
|
||||
// MANUAL 渠道降级:信任调用方提供的 itemId,跳过 StockStore 校验
|
||||
const isManualFallback = createChannel === 'MANUAL' && line.itemId && !wms_stock;
|
||||
|
||||
if (!wms_stock && !isManualFallback) {
|
||||
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) {
|
||||
if (!stockId && !isManualNoStock) {
|
||||
errors.push(`第${i + 1}行: 商品《${wms_stock.item_name}》库存记录不存在`);
|
||||
continue;
|
||||
}
|
||||
@ -1168,7 +1175,8 @@ class DeliveryOrderService extends Service {
|
||||
}
|
||||
processedItemIds.add(itemId);
|
||||
|
||||
// 锁定库存
|
||||
// 锁定库存(MANUAL 降级时跳过)
|
||||
if (!isManualNoStock) {
|
||||
const lockResult = await ctx.service.systems.stockStore.lockItemStorages(
|
||||
stockId,
|
||||
planQty,
|
||||
@ -1182,9 +1190,13 @@ class DeliveryOrderService extends Service {
|
||||
|
||||
const totalQtyForStock = (stockQuantityMap.get(stockId) || 0) + planQty;
|
||||
stockQuantityMap.set(stockId, totalQtyForStock);
|
||||
}
|
||||
|
||||
const weight = parseFloat(wms_stock.gross_weight) || 0;
|
||||
// 优先使用商品主数据重量,缺失时降级为0;MANUAL 降级时重量为 0
|
||||
const weight = isManualNoStock ? 0 : (parseFloat(wms_stock.gross_weight) || 0);
|
||||
if (!isManualNoStock) {
|
||||
stockWeightMap.set(stockId, weight);
|
||||
}
|
||||
// ========== 库存检查逻辑结束 ==========
|
||||
|
||||
// 所有检查通过,准备订单行数据
|
||||
|
||||
@ -212,16 +212,11 @@ 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 称重重量(kg)。
|
||||
* @return {Promise<Object>} 单订单返回 {order_id, waybill_code, weighing_weight};
|
||||
* 团购批量返回 {wave_id, wave_no, weighing_weight, success_count, total_count}。
|
||||
* @param {string} [payload.waybillCode] 运单号。
|
||||
* @param {number|string} payload.weighingWeight 称重重量。
|
||||
* @return {Promise<{order_id:number, waybill_code:string, weighing_weight:number}>} 更新结果。
|
||||
*/
|
||||
async updateWeighingWeight(payload = {}) {
|
||||
const requestData = payload && typeof payload === 'object' ? payload : {};
|
||||
@ -235,79 +230,7 @@ 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;
|
||||
|
||||
// 无法获取仓库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);
|
||||
const rows = await this.findValidOrderExpressRows(normalizedOrderId, warehouseId);
|
||||
|
||||
if (rows.length === 0) {
|
||||
throw this.createBusinessError('未找到有效的订单运单记录', 404);
|
||||
@ -317,274 +240,37 @@ class OrderExpressService extends Service {
|
||||
if (rows.length === 1) {
|
||||
targetRow = rows[0];
|
||||
} else {
|
||||
if (!waybillCode) {
|
||||
if (!normalizedWaybillCode) {
|
||||
throw this.createBusinessError('多运单订单必须传入 waybill_code', 400);
|
||||
}
|
||||
|
||||
targetRow = rows.find(
|
||||
row => String(row && row.waybill_code || '').trim() === waybillCode
|
||||
) || null;
|
||||
targetRow = rows.find(row => String(row && row.waybill_code || '').trim() === normalizedWaybillCode) || 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: weight },
|
||||
{ where: { id: Number(targetRow.id) } }
|
||||
);
|
||||
const updateResult = await orderExpressModel.update({
|
||||
weighing_weight: normalizedWeight,
|
||||
}, {
|
||||
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: weight,
|
||||
weighing_weight: normalizedWeight,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量更新团购波次下所有订单运单的称重重量(内部方法)。
|
||||
*
|
||||
* @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,14 +173,9 @@ 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。
|
||||
@ -237,7 +232,7 @@ class OrderPrintSystemService extends OrderBaseService {
|
||||
[Op.in]: orderItemIds,
|
||||
},
|
||||
},
|
||||
attributes: [ 'id', 'order_id', 'item_code', 'item_name', 'plan_qty', 'item_snapshot', 'stock_id' ],
|
||||
attributes: [ 'id', 'order_id', 'item_code', 'item_name', 'plan_qty', 'item_snapshot' ],
|
||||
raw: true,
|
||||
})
|
||||
: [];
|
||||
@ -284,10 +279,6 @@ 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) || [];
|
||||
@ -321,12 +312,6 @@ 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,
|
||||
@ -334,7 +319,6 @@ 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()
|
||||
@ -346,65 +330,6 @@ 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, operatorName, warehouseId } = this.resolveOperatorContext();
|
||||
const { operatorId, warehouseId } = this.resolveOperatorContext();
|
||||
if (!Number.isInteger(operatorId) || operatorId <= 0) {
|
||||
throw this.createBusinessError('未获取到操作人上下文', 401);
|
||||
}
|
||||
@ -1682,12 +1682,11 @@ class PickSystemService extends Service {
|
||||
throw this.createBusinessError('任务已完成或已取消,无法再次提交', 400);
|
||||
}
|
||||
|
||||
// source=1(PDA抓取创建)的任务必须先绑定拣货车才能提交
|
||||
// source=2(扫描进任务/后台抓取)不强制要求绑定拣货车
|
||||
// source=2 表示后台抓取创建的任务,必须先绑定拣货车才能提交
|
||||
const taskSource = Number(taskRow && taskRow.source || 0);
|
||||
const taskCartId = Number(taskRow && taskRow.current_cart_id || 0);
|
||||
if (taskSource === 1 && taskCartId <= 0) {
|
||||
throw this.createBusinessError('PDA抓取任务必须先绑定拣货车才能提交', 400);
|
||||
if (taskSource === 2 && taskCartId <= 0) {
|
||||
throw this.createBusinessError('后台抓取任务必须先绑定拣货车才能提交', 400);
|
||||
}
|
||||
|
||||
const transaction = await ctx.model.transaction();
|
||||
@ -1842,19 +1841,6 @@ 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,
|
||||
@ -1872,103 +1858,6 @@ 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 扫码查询拣货车信息。
|
||||
*
|
||||
|
||||
@ -1,243 +0,0 @@
|
||||
'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 与新增记录。'
|
||||
);
|
||||
};
|
||||
@ -1,169 +0,0 @@
|
||||
'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,20 +3143,5 @@
|
||||
"仅同步文档,不修改任何业务代码或实现。"
|
||||
],
|
||||
"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.5",
|
||||
"version": "0.3.19",
|
||||
"updatedAt": "2026-06-08",
|
||||
"headers": [
|
||||
{
|
||||
@ -4736,88 +4736,6 @@
|
||||
"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 模型未加载或数据库写入失败"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
@ -15,7 +15,6 @@ const DEFAULT_EGG_MINIMAL_INCLUDE_PATHS = [
|
||||
'native/addons/**',
|
||||
'package.json',
|
||||
'package-lock.json',
|
||||
'printer_data_template/**',
|
||||
];
|
||||
const DEFAULT_POST_DEPLOY_COMMANDS = [
|
||||
'npm install --production',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user