From dd0ce03369ceeaa254e7f3c4c4bbd4289b2c42cb Mon Sep 17 00:00:00 2001 From: zhang1106 <849185023@qq.com> Date: Fri, 10 Apr 2026 14:25:35 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E8=AE=BE=E5=A4=87=E7=AE=A1=E7=90=86):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8DU=E4=BD=8D=E4=BD=8D=E7=BD=AE=E6=A3=80?= =?UTF-8?q?=E6=9F=A5=E7=9A=84=E6=95=B0=E5=80=BC=E7=B1=BB=E5=9E=8B=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 确保位置和高度参数被正确转换为整数类型,避免字符串比较问题 添加调试日志帮助追踪U位检查流程 --- backend/routes/devices.js | 9 +++++---- backend/routes/idleDevices.js | 11 +++++++---- frontend/src/pages/IdleDeviceManagement.jsx | 3 +++ 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/backend/routes/devices.js b/backend/routes/devices.js index b2e3525..8734c27 100644 --- a/backend/routes/devices.js +++ b/backend/routes/devices.js @@ -45,13 +45,14 @@ async function checkPositionAvailable( excludeDeviceId = null, transaction = null ) { - if (!position || position <= 0) { + const pos = parseInt(position, 10); + if (!pos || pos <= 0) { return { available: true, reason: null }; } - const deviceHeight = height || 1; - const startU = position; - const endU = position + deviceHeight - 1; + const deviceHeight = parseInt(height, 10) || 1; + const startU = pos; + const endU = pos + deviceHeight - 1; const queryOptions = { where: { diff --git a/backend/routes/idleDevices.js b/backend/routes/idleDevices.js index da2abf5..3b9cab2 100644 --- a/backend/routes/idleDevices.js +++ b/backend/routes/idleDevices.js @@ -536,7 +536,9 @@ router.put('/:deviceId/shelve', async (req, res) => { } const deviceHeight = height || device.height || 1; + console.log('上架设备 - 位置检查参数:', { rackId, position, deviceHeight, deviceId, existingDeviceId: device.deviceId }); const positionCheck = await checkPositionAvailable(rackId, position, deviceHeight, deviceId, t); + console.log('上架设备 - 位置检查结果:', positionCheck); if (!positionCheck.available) { await t.rollback(); return res.status(400).json({ error: positionCheck.reason }); @@ -832,13 +834,14 @@ async function checkPositionAvailable( excludeDeviceId = null, transaction = null ) { - if (!position || position <= 0) { + const pos = parseInt(position, 10); + if (!pos || pos <= 0) { return { available: true, reason: null }; } - const deviceHeight = height || 1; - const startU = position; - const endU = position + deviceHeight - 1; + const deviceHeight = parseInt(height, 10) || 1; + const startU = pos; + const endU = pos + deviceHeight - 1; const queryOptions = { where: { diff --git a/frontend/src/pages/IdleDeviceManagement.jsx b/frontend/src/pages/IdleDeviceManagement.jsx index d8131c6..13a0506 100644 --- a/frontend/src/pages/IdleDeviceManagement.jsx +++ b/frontend/src/pages/IdleDeviceManagement.jsx @@ -183,7 +183,9 @@ const IdleDeviceManagement = () => { } try { + console.log('检查U位冲突:', { rackId, position, height, deviceId: shelvingDevice?.deviceId }); const result = await deviceAPI.checkPosition(rackId, { position, height: height || 1 }); + console.log('U位检查结果:', result); if (!result.available) { setShelvePositionConflict(result.reason); } else { @@ -1018,6 +1020,7 @@ const IdleDeviceManagement = () => { placeholder="请输入高度" min={1} style={{ borderRadius: '8px' }} + onChange={handleShelveHeightChange} />