1
This commit is contained in:
parent
adb1a16599
commit
e23bf4f15e
@ -11,7 +11,7 @@ module.exports = app => {
|
|||||||
comment: '主键ID',
|
comment: '主键ID',
|
||||||
},
|
},
|
||||||
transaction_type: {
|
transaction_type: {
|
||||||
type: ENUM('INBOUND', 'OUTBOUND', 'TRANSFER_OUT', 'TRANSFER_IN'),
|
type: ENUM('INBOUND', 'OUTBOUND'),
|
||||||
allowNull: false,
|
allowNull: false,
|
||||||
comment: '出入库类型',
|
comment: '出入库类型',
|
||||||
},
|
},
|
||||||
@ -30,16 +30,6 @@ module.exports = app => {
|
|||||||
allowNull: false,
|
allowNull: false,
|
||||||
comment: '商品库存ID,关联 wms_stock_warehouse.id',
|
comment: '商品库存ID,关联 wms_stock_warehouse.id',
|
||||||
},
|
},
|
||||||
storage_id: {
|
|
||||||
type: BIGINT(20).UNSIGNED,
|
|
||||||
allowNull: true,
|
|
||||||
comment: '库位库存ID,关联 wms_storage.id',
|
|
||||||
},
|
|
||||||
space_id: {
|
|
||||||
type: BIGINT(20).UNSIGNED,
|
|
||||||
allowNull: true,
|
|
||||||
comment: '库位ID',
|
|
||||||
},
|
|
||||||
quantity: {
|
quantity: {
|
||||||
type: INTEGER(12),
|
type: INTEGER(12),
|
||||||
allowNull: false,
|
allowNull: false,
|
||||||
@ -70,11 +60,6 @@ module.exports = app => {
|
|||||||
allowNull: true,
|
allowNull: true,
|
||||||
comment: '批次号',
|
comment: '批次号',
|
||||||
},
|
},
|
||||||
inventory_type: {
|
|
||||||
type: ENUM('ZP', 'CC', 'JS', 'XS', 'ZT', 'DJ', 'FP'),
|
|
||||||
defaultValue: 'ZP',
|
|
||||||
comment: '库存类型',
|
|
||||||
},
|
|
||||||
order_type: {
|
order_type: {
|
||||||
type: STRING(50),
|
type: STRING(50),
|
||||||
allowNull: true,
|
allowNull: true,
|
||||||
@ -159,15 +144,11 @@ module.exports = app => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
StockTransaction.associate = function() {
|
StockTransaction.associate = function() {
|
||||||
const { StockWarehouse, Storage } = app.model;
|
const { StockWarehouse } = app.model;
|
||||||
StockTransaction.belongsTo(StockWarehouse, {
|
StockTransaction.belongsTo(StockWarehouse, {
|
||||||
foreignKey: 'stock_id',
|
foreignKey: 'stock_id',
|
||||||
as: 'stockItem',
|
as: 'stockItem',
|
||||||
});
|
});
|
||||||
StockTransaction.belongsTo(Storage, {
|
|
||||||
foreignKey: 'storage_id',
|
|
||||||
as: 'storageRecord',
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return StockTransaction;
|
return StockTransaction;
|
||||||
|
|||||||
@ -14,7 +14,7 @@ class inventoryServer extends MainService {
|
|||||||
warehouseCode: info.data.stock.warehouse_code,
|
warehouseCode: info.data.stock.warehouse_code,
|
||||||
itemCode: info.data.stock.item_code,
|
itemCode: info.data.stock.item_code,
|
||||||
itemId: info.data.stock.id,
|
itemId: info.data.stock.id,
|
||||||
quantity: info.data.storage.quantity - info.data.storage.lockedQuantity,
|
quantity: info.data.storage.quantity,
|
||||||
lockQuantity: info.data.storage.lockedQuantity,
|
lockQuantity: info.data.storage.lockedQuantity,
|
||||||
inventoryType: 'ZP',
|
inventoryType: 'ZP',
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1391,6 +1391,8 @@ class OrderStorageAllocationService extends MainService {
|
|||||||
*/
|
*/
|
||||||
async syncOrderIds(data = {}) {
|
async syncOrderIds(data = {}) {
|
||||||
const { ctx } = this;
|
const { ctx } = this;
|
||||||
|
const unallocatedPostStatus = 'none';
|
||||||
|
const fastFailReason = `快递状态未分配,禁止同步`;
|
||||||
const requestData = data && typeof data === 'object' ? data : {};
|
const requestData = data && typeof data === 'object' ? data : {};
|
||||||
const normalizeNumber = (value, defaultValue = 0) => {
|
const normalizeNumber = (value, defaultValue = 0) => {
|
||||||
const numericValue = Number(value);
|
const numericValue = Number(value);
|
||||||
@ -1532,6 +1534,7 @@ class OrderStorageAllocationService extends MainService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const skippedOrders = [];
|
const skippedOrders = [];
|
||||||
|
const fastFailedOrders = [];
|
||||||
const syncableOrders = [];
|
const syncableOrders = [];
|
||||||
|
|
||||||
for (const orderId of orderIds) {
|
for (const orderId of orderIds) {
|
||||||
@ -1556,9 +1559,26 @@ class OrderStorageAllocationService extends MainService {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const normalizedPostStatus = String(orderRow.post_status || '').trim() || unallocatedPostStatus;
|
||||||
|
if (normalizedPostStatus === unallocatedPostStatus) {
|
||||||
|
fastFailedOrders.push({
|
||||||
|
order_id: orderId,
|
||||||
|
status: 'failed',
|
||||||
|
create_channel: normalizeCreateChannel(orderRow.create_channel),
|
||||||
|
post_status: normalizedPostStatus,
|
||||||
|
failed_reason: 'express_unallocated',
|
||||||
|
message: fastFailReason,
|
||||||
|
});
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
syncableOrders.push(orderRow);
|
syncableOrders.push(orderRow);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const fastFailedOrderIds = fastFailedOrders
|
||||||
|
.map(order => normalizeNumber(order.order_id, 0))
|
||||||
|
.filter(orderId => orderId > 0);
|
||||||
|
|
||||||
const syncableOrderIds = syncableOrders
|
const syncableOrderIds = syncableOrders
|
||||||
.map(order => normalizeNumber(order.id, 0))
|
.map(order => normalizeNumber(order.id, 0))
|
||||||
.filter(orderId => orderId > 0);
|
.filter(orderId => orderId > 0);
|
||||||
@ -1580,6 +1600,31 @@ class OrderStorageAllocationService extends MainService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (fastFailedOrderIds.length > 0) {
|
||||||
|
await orderModel.update({
|
||||||
|
sync_status: 'error',
|
||||||
|
sync_message: fastFailReason,
|
||||||
|
inspection_status: STORAGE_STATUS_ERROR,
|
||||||
|
step: ORDER_STEP_EXCEPTION,
|
||||||
|
order_flag: fastFailReason,
|
||||||
|
updated_at: now,
|
||||||
|
}, {
|
||||||
|
where: {
|
||||||
|
id: {
|
||||||
|
[ctx.app.Sequelize.Op.in]: fastFailedOrderIds,
|
||||||
|
},
|
||||||
|
warehouse_id: warehouseId,
|
||||||
|
},
|
||||||
|
transaction,
|
||||||
|
});
|
||||||
|
|
||||||
|
ctx.logger.warn('[OrderStorageAllocationService.syncOrderIds] 命中快递状态未分配快速失败,已阻断同步派发', {
|
||||||
|
warehouseId,
|
||||||
|
orderIds: fastFailedOrderIds,
|
||||||
|
reason: fastFailReason,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
await transaction.commit();
|
await transaction.commit();
|
||||||
|
|
||||||
const routeContext = {
|
const routeContext = {
|
||||||
@ -1619,8 +1664,10 @@ class OrderStorageAllocationService extends MainService {
|
|||||||
skipped_orders: skippedOrders,
|
skipped_orders: skippedOrders,
|
||||||
create_channel_groups: createChannelGroups,
|
create_channel_groups: createChannelGroups,
|
||||||
dispatch_results: dispatchResults,
|
dispatch_results: dispatchResults,
|
||||||
|
failed_orders: fastFailedOrders,
|
||||||
orders: [
|
orders: [
|
||||||
...skippedOrders,
|
...skippedOrders,
|
||||||
|
...fastFailedOrders,
|
||||||
...syncableOrders.map(order => ({
|
...syncableOrders.map(order => ({
|
||||||
order_id: normalizeNumber(order.id, 0),
|
order_id: normalizeNumber(order.id, 0),
|
||||||
delivery_order_code: String(order.delivery_order_code || '').trim(),
|
delivery_order_code: String(order.delivery_order_code || '').trim(),
|
||||||
@ -1632,6 +1679,7 @@ class OrderStorageAllocationService extends MainService {
|
|||||||
],
|
],
|
||||||
pending_count: syncableOrderIds.length,
|
pending_count: syncableOrderIds.length,
|
||||||
skipped_count: skippedOrders.length,
|
skipped_count: skippedOrders.length,
|
||||||
|
failed_count: fastFailedOrders.length,
|
||||||
create_channel_count: createChannelGroups.length,
|
create_channel_count: createChannelGroups.length,
|
||||||
dispatch_count: dispatchResults.length,
|
dispatch_count: dispatchResults.length,
|
||||||
dispatch_success_count: dispatchResults.filter(item => item.status === 'success').length,
|
dispatch_success_count: dispatchResults.filter(item => item.status === 'success').length,
|
||||||
@ -1640,7 +1688,9 @@ class OrderStorageAllocationService extends MainService {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
code: 200,
|
code: 200,
|
||||||
message: syncableOrderIds.length > 0 ? '同步已受理,已生成按来源分组的同步计划' : '没有需要同步的订单',
|
message: syncableOrderIds.length > 0
|
||||||
|
? '同步已受理,已生成按来源分组的同步计划'
|
||||||
|
: (fastFailedOrders.length > 0 ? '同步失败:存在快递状态未分配订单' : '没有需要同步的订单'),
|
||||||
data: responseData,
|
data: responseData,
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@ -121,11 +121,8 @@ class StockTransactionService extends Service {
|
|||||||
* @param {number} data.warehouse_id 仓库ID
|
* @param {number} data.warehouse_id 仓库ID
|
||||||
* @param {number} data.store_id 货主ID
|
* @param {number} data.store_id 货主ID
|
||||||
* @param {number} data.stock_id 商品库存ID
|
* @param {number} data.stock_id 商品库存ID
|
||||||
* @param {number} [data.storage_id] 库位库存ID
|
|
||||||
* @param {number} [data.space_id] 库位ID
|
|
||||||
* @param {number} data.quantity 变动数量
|
* @param {number} data.quantity 变动数量
|
||||||
* @param {string} [data.batch_no] 批次号
|
* @param {string} [data.batch_no] 批次号
|
||||||
* @param {string} [data.inventory_type] 库存类型
|
|
||||||
* @param {string} [data.order_type] 关联单据类型
|
* @param {string} [data.order_type] 关联单据类型
|
||||||
* @param {string} [data.order_no] 关联单据号
|
* @param {string} [data.order_no] 关联单据号
|
||||||
* @param {number} [data.order_id] 关联单据ID
|
* @param {number} [data.order_id] 关联单据ID
|
||||||
@ -179,11 +176,8 @@ class StockTransactionService extends Service {
|
|||||||
warehouse_id: data.warehouse_id,
|
warehouse_id: data.warehouse_id,
|
||||||
store_id: data.store_id,
|
store_id: data.store_id,
|
||||||
stock_id: data.stock_id,
|
stock_id: data.stock_id,
|
||||||
storage_id: data.storage_id ?? null,
|
|
||||||
space_id: data.space_id ?? null,
|
|
||||||
quantity,
|
quantity,
|
||||||
batch_no: normalizedBatchNo,
|
batch_no: normalizedBatchNo,
|
||||||
inventory_type: data.inventory_type || 'ZP',
|
|
||||||
order_type: normalizedOrderType,
|
order_type: normalizedOrderType,
|
||||||
order_no: normalizedOrderReference.orderNo,
|
order_no: normalizedOrderReference.orderNo,
|
||||||
order_id: normalizedOrderId,
|
order_id: normalizedOrderId,
|
||||||
@ -260,8 +254,8 @@ class StockTransactionService extends Service {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// 不按批次:按 stock_id + space_id + transaction_type + inventory_type 合并
|
// 不按批次:按 stock_id + transaction_type + warehouse/store + order_type 合并
|
||||||
const groupFields = [ 'stock_id', 'space_id', 'transaction_type', 'inventory_type', 'warehouse_id', 'store_id', 'order_type' ];
|
const groupFields = [ 'stock_id', 'transaction_type', 'warehouse_id', 'store_id', 'order_type' ];
|
||||||
|
|
||||||
// 先查总数(分组后的组数)
|
// 先查总数(分组后的组数)
|
||||||
const countResult = await ctx.model.StockTransaction.count({
|
const countResult = await ctx.model.StockTransaction.count({
|
||||||
@ -275,9 +269,7 @@ class StockTransactionService extends Service {
|
|||||||
where: baseWhere,
|
where: baseWhere,
|
||||||
attributes: [
|
attributes: [
|
||||||
'stock_id',
|
'stock_id',
|
||||||
'space_id',
|
|
||||||
'transaction_type',
|
'transaction_type',
|
||||||
'inventory_type',
|
|
||||||
'warehouse_id',
|
'warehouse_id',
|
||||||
'store_id',
|
'store_id',
|
||||||
'order_type',
|
'order_type',
|
||||||
|
|||||||
@ -1186,7 +1186,7 @@ class InventoryService extends Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 写入移库双向库存流水(移库出/移库入)。
|
* 写入移库双向库位流水(移库出/移库入)。
|
||||||
*
|
*
|
||||||
* 说明:
|
* 说明:
|
||||||
* 1) before/after 与锁定字段均写同值快照,避免被识别为普通出入库数量变化;
|
* 1) before/after 与锁定字段均写同值快照,避免被识别为普通出入库数量变化;
|
||||||
@ -1212,7 +1212,7 @@ class InventoryService extends Service {
|
|||||||
const totalSnapshotQuantity = Number(data.totalSnapshotQuantity) || 0;
|
const totalSnapshotQuantity = Number(data.totalSnapshotQuantity) || 0;
|
||||||
const totalSnapshotLockedQuantity = Number(data.totalSnapshotLockedQuantity) || 0;
|
const totalSnapshotLockedQuantity = Number(data.totalSnapshotLockedQuantity) || 0;
|
||||||
|
|
||||||
await ctx.service.systems.stockTransaction.create({
|
await ctx.model.StorageTransaction.create({
|
||||||
transaction_type: 'TRANSFER_OUT',
|
transaction_type: 'TRANSFER_OUT',
|
||||||
warehouse_id: data.srcRecord.warehouse_id,
|
warehouse_id: data.srcRecord.warehouse_id,
|
||||||
store_id: data.srcRecord.store_id,
|
store_id: data.srcRecord.store_id,
|
||||||
@ -1232,11 +1232,13 @@ class InventoryService extends Service {
|
|||||||
after_quantity: totalSnapshotQuantity,
|
after_quantity: totalSnapshotQuantity,
|
||||||
before_locked_quantity: totalSnapshotLockedQuantity,
|
before_locked_quantity: totalSnapshotLockedQuantity,
|
||||||
after_locked_quantity: totalSnapshotLockedQuantity,
|
after_locked_quantity: totalSnapshotLockedQuantity,
|
||||||
|
source_order_codes: null,
|
||||||
|
created_at: new Date(),
|
||||||
}, {
|
}, {
|
||||||
transaction: data.transaction,
|
transaction: data.transaction,
|
||||||
});
|
});
|
||||||
|
|
||||||
await ctx.service.systems.stockTransaction.create({
|
await ctx.model.StorageTransaction.create({
|
||||||
transaction_type: 'TRANSFER_IN',
|
transaction_type: 'TRANSFER_IN',
|
||||||
warehouse_id: data.srcRecord.warehouse_id,
|
warehouse_id: data.srcRecord.warehouse_id,
|
||||||
store_id: data.srcRecord.store_id,
|
store_id: data.srcRecord.store_id,
|
||||||
@ -1256,6 +1258,8 @@ class InventoryService extends Service {
|
|||||||
after_quantity: totalSnapshotQuantity,
|
after_quantity: totalSnapshotQuantity,
|
||||||
before_locked_quantity: totalSnapshotLockedQuantity,
|
before_locked_quantity: totalSnapshotLockedQuantity,
|
||||||
after_locked_quantity: totalSnapshotLockedQuantity,
|
after_locked_quantity: totalSnapshotLockedQuantity,
|
||||||
|
source_order_codes: null,
|
||||||
|
created_at: new Date(),
|
||||||
}, {
|
}, {
|
||||||
transaction: data.transaction,
|
transaction: data.transaction,
|
||||||
});
|
});
|
||||||
|
|||||||
@ -458,14 +458,14 @@ class StorageReportService extends Service {
|
|||||||
t.transaction_type,
|
t.transaction_type,
|
||||||
t.store_id,
|
t.store_id,
|
||||||
t.stock_id,
|
t.stock_id,
|
||||||
COALESCE(t.space_id, 0) AS space_id,
|
0 AS space_id,
|
||||||
t.quantity,
|
t.quantity,
|
||||||
t.before_quantity,
|
t.before_quantity,
|
||||||
t.after_quantity,
|
t.after_quantity,
|
||||||
t.before_locked_quantity,
|
t.before_locked_quantity,
|
||||||
t.after_locked_quantity,
|
t.after_locked_quantity,
|
||||||
t.batch_no,
|
t.batch_no,
|
||||||
t.inventory_type,
|
'' AS inventory_type,
|
||||||
t.order_type,
|
t.order_type,
|
||||||
t.order_no,
|
t.order_no,
|
||||||
t.order_id,
|
t.order_id,
|
||||||
@ -781,13 +781,13 @@ class StorageReportService extends Service {
|
|||||||
const rangeRowsSql = `
|
const rangeRowsSql = `
|
||||||
SELECT
|
SELECT
|
||||||
t.stock_id,
|
t.stock_id,
|
||||||
COALESCE(t.space_id, 0) AS space_id,
|
0 AS space_id,
|
||||||
t.store_id,
|
t.store_id,
|
||||||
SUM(CASE WHEN t.transaction_type = 'INBOUND' THEN t.quantity ELSE 0 END) AS inbound_total,
|
SUM(CASE WHEN t.transaction_type = 'INBOUND' THEN t.quantity ELSE 0 END) AS inbound_total,
|
||||||
SUM(CASE WHEN t.transaction_type = 'OUTBOUND' THEN t.quantity ELSE 0 END) AS outbound_total
|
SUM(CASE WHEN t.transaction_type = 'OUTBOUND' THEN t.quantity ELSE 0 END) AS outbound_total
|
||||||
FROM wms_stock_transaction t
|
FROM wms_stock_transaction t
|
||||||
WHERE ${rangeWhereClauses.join(' AND ')}
|
WHERE ${rangeWhereClauses.join(' AND ')}
|
||||||
GROUP BY t.stock_id, COALESCE(t.space_id, 0), t.store_id
|
GROUP BY t.stock_id, t.store_id
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const rangeRows = await ctx.model.query(rangeRowsSql, {
|
const rangeRows = await ctx.model.query(rangeRowsSql, {
|
||||||
@ -801,14 +801,14 @@ class StorageReportService extends Service {
|
|||||||
SELECT
|
SELECT
|
||||||
t.id,
|
t.id,
|
||||||
t.stock_id,
|
t.stock_id,
|
||||||
COALESCE(t.space_id, 0) AS space_id,
|
0 AS space_id,
|
||||||
t.store_id,
|
t.store_id,
|
||||||
t.before_quantity,
|
t.before_quantity,
|
||||||
t.after_quantity,
|
t.after_quantity,
|
||||||
t.created_at
|
t.created_at
|
||||||
FROM wms_stock_transaction t
|
FROM wms_stock_transaction t
|
||||||
WHERE ${rangeWhereClauses.join(' AND ')}
|
WHERE ${rangeWhereClauses.join(' AND ')}
|
||||||
ORDER BY t.stock_id ASC, t.store_id ASC, t.created_at ASC, t.id ASC, COALESCE(t.space_id, 0) ASC
|
ORDER BY t.stock_id ASC, t.store_id ASC, t.created_at ASC, t.id ASC
|
||||||
`, {
|
`, {
|
||||||
replacements: rangeReplacements,
|
replacements: rangeReplacements,
|
||||||
type: app.Sequelize.QueryTypes.SELECT,
|
type: app.Sequelize.QueryTypes.SELECT,
|
||||||
@ -839,13 +839,13 @@ class StorageReportService extends Service {
|
|||||||
SELECT
|
SELECT
|
||||||
t.id,
|
t.id,
|
||||||
t.stock_id,
|
t.stock_id,
|
||||||
COALESCE(t.space_id, 0) AS space_id,
|
0 AS space_id,
|
||||||
t.store_id,
|
t.store_id,
|
||||||
t.after_quantity,
|
t.after_quantity,
|
||||||
t.created_at
|
t.created_at
|
||||||
FROM wms_stock_transaction t
|
FROM wms_stock_transaction t
|
||||||
WHERE ${preStartWhereClauses.join(' AND ')}
|
WHERE ${preStartWhereClauses.join(' AND ')}
|
||||||
ORDER BY t.stock_id ASC, t.store_id ASC, COALESCE(t.space_id, 0) ASC, t.created_at DESC, t.id DESC
|
ORDER BY t.stock_id ASC, t.store_id ASC, t.created_at DESC, t.id DESC
|
||||||
`, {
|
`, {
|
||||||
replacements: preStartReplacements,
|
replacements: preStartReplacements,
|
||||||
type: app.Sequelize.QueryTypes.SELECT,
|
type: app.Sequelize.QueryTypes.SELECT,
|
||||||
|
|||||||
@ -0,0 +1,96 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断表字段是否存在。
|
||||||
|
* @param {import('sequelize').QueryInterface} queryInterface 查询接口。
|
||||||
|
* @param {string} tableName 表名。
|
||||||
|
* @param {string} columnName 字段名。
|
||||||
|
* @return {Promise<boolean>} 字段是否存在。
|
||||||
|
*/
|
||||||
|
const hasColumn = async (queryInterface, tableName, columnName) => {
|
||||||
|
const tableDef = await queryInterface.describeTable(tableName);
|
||||||
|
return Object.prototype.hasOwnProperty.call(tableDef, columnName);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 收敛 wms_stock_transaction 字段与枚举:
|
||||||
|
* 1) transaction_type 仅保留 INBOUND/OUTBOUND;
|
||||||
|
* 2) 删除 storage_id/space_id/inventory_type 三列。
|
||||||
|
*
|
||||||
|
* @param {import('sequelize').QueryInterface} queryInterface 查询接口。
|
||||||
|
* @param {import('sequelize')} Sequelize Sequelize 实例。
|
||||||
|
* @return {Promise<void>} 无返回值。
|
||||||
|
*/
|
||||||
|
module.exports.up = async (queryInterface, Sequelize) => {
|
||||||
|
await queryInterface.sequelize.query(
|
||||||
|
`UPDATE wms_stock_transaction
|
||||||
|
SET transaction_type = 'OUTBOUND'
|
||||||
|
WHERE transaction_type = 'TRANSFER_OUT'`
|
||||||
|
);
|
||||||
|
|
||||||
|
await queryInterface.sequelize.query(
|
||||||
|
`UPDATE wms_stock_transaction
|
||||||
|
SET transaction_type = 'INBOUND'
|
||||||
|
WHERE transaction_type = 'TRANSFER_IN'`
|
||||||
|
);
|
||||||
|
|
||||||
|
await queryInterface.changeColumn('wms_stock_transaction', 'transaction_type', {
|
||||||
|
type: Sequelize.ENUM('INBOUND', 'OUTBOUND'),
|
||||||
|
allowNull: false,
|
||||||
|
comment: '出入库类型',
|
||||||
|
});
|
||||||
|
|
||||||
|
if (await hasColumn(queryInterface, 'wms_stock_transaction', 'storage_id')) {
|
||||||
|
await queryInterface.removeColumn('wms_stock_transaction', 'storage_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (await hasColumn(queryInterface, 'wms_stock_transaction', 'space_id')) {
|
||||||
|
await queryInterface.removeColumn('wms_stock_transaction', 'space_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (await hasColumn(queryInterface, 'wms_stock_transaction', 'inventory_type')) {
|
||||||
|
await queryInterface.removeColumn('wms_stock_transaction', 'inventory_type');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 回滚恢复 wms_stock_transaction 字段与枚举:
|
||||||
|
* 1) 恢复 storage_id/space_id/inventory_type 三列;
|
||||||
|
* 2) transaction_type 恢复 TRANSFER_OUT/TRANSFER_IN 枚举值。
|
||||||
|
*
|
||||||
|
* @param {import('sequelize').QueryInterface} queryInterface 查询接口。
|
||||||
|
* @param {import('sequelize')} Sequelize Sequelize 实例。
|
||||||
|
* @return {Promise<void>} 无返回值。
|
||||||
|
*/
|
||||||
|
module.exports.down = async (queryInterface, Sequelize) => {
|
||||||
|
if (!(await hasColumn(queryInterface, 'wms_stock_transaction', 'storage_id'))) {
|
||||||
|
await queryInterface.addColumn('wms_stock_transaction', 'storage_id', {
|
||||||
|
type: Sequelize.BIGINT(20).UNSIGNED,
|
||||||
|
allowNull: true,
|
||||||
|
comment: '库位库存ID,关联 wms_storage.id',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(await hasColumn(queryInterface, 'wms_stock_transaction', 'space_id'))) {
|
||||||
|
await queryInterface.addColumn('wms_stock_transaction', 'space_id', {
|
||||||
|
type: Sequelize.BIGINT(20).UNSIGNED,
|
||||||
|
allowNull: true,
|
||||||
|
comment: '库位ID',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(await hasColumn(queryInterface, 'wms_stock_transaction', 'inventory_type'))) {
|
||||||
|
await queryInterface.addColumn('wms_stock_transaction', 'inventory_type', {
|
||||||
|
type: Sequelize.ENUM('ZP', 'CC', 'JS', 'XS', 'ZT', 'DJ', 'FP'),
|
||||||
|
allowNull: true,
|
||||||
|
defaultValue: 'ZP',
|
||||||
|
comment: '库存类型',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
await queryInterface.changeColumn('wms_stock_transaction', 'transaction_type', {
|
||||||
|
type: Sequelize.ENUM('INBOUND', 'OUTBOUND', 'TRANSFER_OUT', 'TRANSFER_IN'),
|
||||||
|
allowNull: false,
|
||||||
|
comment: '出入库类型',
|
||||||
|
});
|
||||||
|
};
|
||||||
@ -467,10 +467,10 @@ describe('test/app/service/systems/order_storage_allocation.test.js', () => {
|
|||||||
it('should group syncable orders by create_channel and mark them pending sync', async () => {
|
it('should group syncable orders by create_channel and mark them pending sync', async () => {
|
||||||
const { service, captures } = createHarness({
|
const { service, captures } = createHarness({
|
||||||
orders: [
|
orders: [
|
||||||
{ id: 1, warehouse_id: 100000, express_code: 'WB-001', sync_status: 'error', create_channel: 'QM' },
|
{ id: 1, warehouse_id: 100000, express_code: 'WB-001', post_status: 'padding', sync_status: 'error', create_channel: 'QM' },
|
||||||
{ id: 2, warehouse_id: 100000, express_code: 'WB-002', sync_status: 'padding', create_channel: 'API' },
|
{ id: 2, warehouse_id: 100000, express_code: 'WB-002', post_status: 'padding', sync_status: 'padding', create_channel: 'API' },
|
||||||
{ id: 3, warehouse_id: 100000, express_code: '', sync_status: 'padding', create_channel: 'MANUAL' },
|
{ id: 3, warehouse_id: 100000, express_code: '', post_status: 'padding', sync_status: 'padding', create_channel: 'MANUAL' },
|
||||||
{ id: 4, warehouse_id: 100000, express_code: 'WB-004', sync_status: 'fin', create_channel: 'QM' },
|
{ id: 4, warehouse_id: 100000, express_code: 'WB-004', post_status: 'padding', sync_status: 'fin', create_channel: 'QM' },
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -487,6 +487,8 @@ describe('test/app/service/systems/order_storage_allocation.test.js', () => {
|
|||||||
assert.deepEqual(result.data.create_channel_groups[1].order_ids, [ 2 ]);
|
assert.deepEqual(result.data.create_channel_groups[1].order_ids, [ 2 ]);
|
||||||
assert.deepEqual(result.data.create_channel_groups[2].order_ids, [ 3 ]);
|
assert.deepEqual(result.data.create_channel_groups[2].order_ids, [ 3 ]);
|
||||||
assert.deepEqual(result.data.skipped_orders.map(item => item.skipped_reason), [ 'already_synced', 'not_found' ]);
|
assert.deepEqual(result.data.skipped_orders.map(item => item.skipped_reason), [ 'already_synced', 'not_found' ]);
|
||||||
|
assert.equal(result.data.failed_count, 0);
|
||||||
|
assert.deepEqual(result.data.failed_orders, []);
|
||||||
assert.equal(captures.qm.groupedOrder.create_channel, 'QM');
|
assert.equal(captures.qm.groupedOrder.create_channel, 'QM');
|
||||||
assert.deepEqual(captures.qm.groupedOrder.order_ids, [ 1 ]);
|
assert.deepEqual(captures.qm.groupedOrder.order_ids, [ 1 ]);
|
||||||
assert.equal(captures.qm.context.warehouseId, 100000);
|
assert.equal(captures.qm.context.warehouseId, 100000);
|
||||||
@ -496,6 +498,42 @@ describe('test/app/service/systems/order_storage_allocation.test.js', () => {
|
|||||||
assert.equal(captures.manual.context.warehouseId, 100000);
|
assert.equal(captures.manual.context.warehouseId, 100000);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should fail fast when post_status is none and skip async dispatch', async () => {
|
||||||
|
const { service, captures, orders } = createHarness({
|
||||||
|
orders: [
|
||||||
|
{ id: 11, warehouse_id: 100000, express_code: '', post_status: 'none', sync_status: 'padding', create_channel: 'QM' },
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = await service.syncOrderIds({
|
||||||
|
order_ids: [ 11 ],
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.equal(result.code, 200);
|
||||||
|
assert.equal(result.message, '同步失败:存在快递状态未分配订单');
|
||||||
|
assert.deepEqual(result.data.pending_order_ids, []);
|
||||||
|
assert.equal(result.data.dispatch_count, 0);
|
||||||
|
assert.equal(result.data.failed_count, 1);
|
||||||
|
assert.deepEqual(result.data.failed_orders, [
|
||||||
|
{
|
||||||
|
order_id: 11,
|
||||||
|
status: 'failed',
|
||||||
|
create_channel: 'QM',
|
||||||
|
post_status: 'none',
|
||||||
|
failed_reason: 'express_unallocated',
|
||||||
|
message: '快递状态未分配,禁止同步',
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
assert.equal(captures.qm, null);
|
||||||
|
assert.equal(captures.api, null);
|
||||||
|
assert.equal(captures.manual, null);
|
||||||
|
assert.equal(orders[0].sync_status, 'error');
|
||||||
|
assert.equal(orders[0].sync_message, '快递状态未分配,禁止同步');
|
||||||
|
assert.equal(orders[0].inspection_status, 'error');
|
||||||
|
assert.equal(orders[0].step, 3);
|
||||||
|
assert.equal(orders[0].order_flag, '快递状态未分配,禁止同步');
|
||||||
|
});
|
||||||
|
|
||||||
it('should always use the current user warehouse context and ignore request warehouse ids', async () => {
|
it('should always use the current user warehouse context and ignore request warehouse ids', async () => {
|
||||||
const { service, captures } = createHarness({
|
const { service, captures } = createHarness({
|
||||||
orders: [
|
orders: [
|
||||||
|
|||||||
@ -9,7 +9,7 @@ const StorageInventoryService = require('../../../../app/service/systems/storage
|
|||||||
*/
|
*/
|
||||||
function createTransferHarness() {
|
function createTransferHarness() {
|
||||||
const calls = {
|
const calls = {
|
||||||
stockTransactions: [],
|
storageTransactions: [],
|
||||||
storageUpdates: [],
|
storageUpdates: [],
|
||||||
locationSpaceUpdates: [],
|
locationSpaceUpdates: [],
|
||||||
commitCount: 0,
|
commitCount: 0,
|
||||||
@ -84,6 +84,12 @@ function createTransferHarness() {
|
|||||||
calls.locationSpaceUpdates.push({ values, options });
|
calls.locationSpaceUpdates.push({ values, options });
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
StorageTransaction: {
|
||||||
|
async create(payload, options) {
|
||||||
|
calls.storageTransactions.push({ payload, options });
|
||||||
|
return { id: calls.storageTransactions.length, ...payload };
|
||||||
|
},
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const ctx = {
|
const ctx = {
|
||||||
@ -109,17 +115,15 @@ function createTransferHarness() {
|
|||||||
},
|
},
|
||||||
service: {
|
service: {
|
||||||
systems: {
|
systems: {
|
||||||
stockTransaction: {
|
operationLog: {
|
||||||
async create(payload, options) {
|
async createOperationLog() {
|
||||||
calls.stockTransactions.push({ payload, options });
|
return null;
|
||||||
return { id: calls.stockTransactions.length, ...payload };
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
operationLog: {
|
|
||||||
async createOperationLog() {},
|
|
||||||
},
|
|
||||||
notice: {
|
notice: {
|
||||||
async send() {},
|
async send() {
|
||||||
|
return null;
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -137,7 +141,7 @@ function createTransferHarness() {
|
|||||||
*/
|
*/
|
||||||
function createTransferByProductHarness() {
|
function createTransferByProductHarness() {
|
||||||
const calls = {
|
const calls = {
|
||||||
stockTransactions: [],
|
storageTransactions: [],
|
||||||
storageUpdates: [],
|
storageUpdates: [],
|
||||||
storageCreates: [],
|
storageCreates: [],
|
||||||
locationSpaceUpdates: [],
|
locationSpaceUpdates: [],
|
||||||
@ -241,6 +245,12 @@ function createTransferByProductHarness() {
|
|||||||
calls.locationSpaceUpdates.push({ values, options });
|
calls.locationSpaceUpdates.push({ values, options });
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
StorageTransaction: {
|
||||||
|
async create(payload, options) {
|
||||||
|
calls.storageTransactions.push({ payload, options });
|
||||||
|
return { id: calls.storageTransactions.length, ...payload };
|
||||||
|
},
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const ctx = {
|
const ctx = {
|
||||||
@ -266,17 +276,15 @@ function createTransferByProductHarness() {
|
|||||||
},
|
},
|
||||||
service: {
|
service: {
|
||||||
systems: {
|
systems: {
|
||||||
stockTransaction: {
|
operationLog: {
|
||||||
async create(payload, options) {
|
async createOperationLog() {
|
||||||
calls.stockTransactions.push({ payload, options });
|
return null;
|
||||||
return { id: calls.stockTransactions.length, ...payload };
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
operationLog: {
|
|
||||||
async createOperationLog() {},
|
|
||||||
},
|
|
||||||
notice: {
|
notice: {
|
||||||
async send() {},
|
async send() {
|
||||||
|
return null;
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -301,10 +309,10 @@ describe('test/app/service/systems/storage.inventory.transfer.test.js', () => {
|
|||||||
assert.equal(result.code, 200);
|
assert.equal(result.code, 200);
|
||||||
assert.equal(calls.commitCount, 1);
|
assert.equal(calls.commitCount, 1);
|
||||||
assert.equal(calls.rollbackCount, 0);
|
assert.equal(calls.rollbackCount, 0);
|
||||||
assert.equal(calls.stockTransactions.length, 2);
|
assert.equal(calls.storageTransactions.length, 2);
|
||||||
|
|
||||||
const transferOut = calls.stockTransactions[0];
|
const transferOut = calls.storageTransactions[0];
|
||||||
const transferIn = calls.stockTransactions[1];
|
const transferIn = calls.storageTransactions[1];
|
||||||
|
|
||||||
assert.equal(transferOut.payload.transaction_type, 'TRANSFER_OUT');
|
assert.equal(transferOut.payload.transaction_type, 'TRANSFER_OUT');
|
||||||
assert.equal(transferOut.payload.storage_id, 11);
|
assert.equal(transferOut.payload.storage_id, 11);
|
||||||
@ -346,10 +354,10 @@ describe('test/app/service/systems/storage.inventory.transfer.test.js', () => {
|
|||||||
assert.equal(result.code, 200);
|
assert.equal(result.code, 200);
|
||||||
assert.equal(calls.commitCount, 1);
|
assert.equal(calls.commitCount, 1);
|
||||||
assert.equal(calls.rollbackCount, 0);
|
assert.equal(calls.rollbackCount, 0);
|
||||||
assert.equal(calls.stockTransactions.length, 4);
|
assert.equal(calls.storageTransactions.length, 4);
|
||||||
|
|
||||||
const transferOutTransactions = calls.stockTransactions.filter(item => item.payload.transaction_type === 'TRANSFER_OUT');
|
const transferOutTransactions = calls.storageTransactions.filter(item => item.payload.transaction_type === 'TRANSFER_OUT');
|
||||||
const transferInTransactions = calls.stockTransactions.filter(item => item.payload.transaction_type === 'TRANSFER_IN');
|
const transferInTransactions = calls.storageTransactions.filter(item => item.payload.transaction_type === 'TRANSFER_IN');
|
||||||
|
|
||||||
assert.equal(transferOutTransactions.length, 2);
|
assert.equal(transferOutTransactions.length, 2);
|
||||||
assert.equal(transferInTransactions.length, 2);
|
assert.equal(transferInTransactions.length, 2);
|
||||||
@ -359,7 +367,7 @@ describe('test/app/service/systems/storage.inventory.transfer.test.js', () => {
|
|||||||
assert.equal(outTotalQuantity, 5);
|
assert.equal(outTotalQuantity, 5);
|
||||||
assert.equal(inTotalQuantity, 5);
|
assert.equal(inTotalQuantity, 5);
|
||||||
|
|
||||||
for (const tx of calls.stockTransactions) {
|
for (const tx of calls.storageTransactions) {
|
||||||
assert.equal(tx.payload.before_quantity, tx.payload.after_quantity);
|
assert.equal(tx.payload.before_quantity, tx.payload.after_quantity);
|
||||||
assert.equal(tx.payload.before_locked_quantity, tx.payload.after_locked_quantity);
|
assert.equal(tx.payload.before_locked_quantity, tx.payload.after_locked_quantity);
|
||||||
assert.equal(tx.payload.before_quantity, 50);
|
assert.equal(tx.payload.before_quantity, 50);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user