fix(设备管理): 修复U位位置检查的数值类型问题

确保位置和高度参数被正确转换为整数类型,避免字符串比较问题
添加调试日志帮助追踪U位检查流程
This commit is contained in:
zhang1106
2026-04-10 14:25:35 +08:00
parent f2bcda1cd4
commit dd0ce03369
3 changed files with 15 additions and 8 deletions
+5 -4
View File
@@ -45,13 +45,14 @@ async function checkPositionAvailable(
excludeDeviceId = null, excludeDeviceId = null,
transaction = null transaction = null
) { ) {
if (!position || position <= 0) { const pos = parseInt(position, 10);
if (!pos || pos <= 0) {
return { available: true, reason: null }; return { available: true, reason: null };
} }
const deviceHeight = height || 1; const deviceHeight = parseInt(height, 10) || 1;
const startU = position; const startU = pos;
const endU = position + deviceHeight - 1; const endU = pos + deviceHeight - 1;
const queryOptions = { const queryOptions = {
where: { where: {
+7 -4
View File
@@ -536,7 +536,9 @@ router.put('/:deviceId/shelve', async (req, res) => {
} }
const deviceHeight = height || device.height || 1; const deviceHeight = height || device.height || 1;
console.log('上架设备 - 位置检查参数:', { rackId, position, deviceHeight, deviceId, existingDeviceId: device.deviceId });
const positionCheck = await checkPositionAvailable(rackId, position, deviceHeight, deviceId, t); const positionCheck = await checkPositionAvailable(rackId, position, deviceHeight, deviceId, t);
console.log('上架设备 - 位置检查结果:', positionCheck);
if (!positionCheck.available) { if (!positionCheck.available) {
await t.rollback(); await t.rollback();
return res.status(400).json({ error: positionCheck.reason }); return res.status(400).json({ error: positionCheck.reason });
@@ -832,13 +834,14 @@ async function checkPositionAvailable(
excludeDeviceId = null, excludeDeviceId = null,
transaction = null transaction = null
) { ) {
if (!position || position <= 0) { const pos = parseInt(position, 10);
if (!pos || pos <= 0) {
return { available: true, reason: null }; return { available: true, reason: null };
} }
const deviceHeight = height || 1; const deviceHeight = parseInt(height, 10) || 1;
const startU = position; const startU = pos;
const endU = position + deviceHeight - 1; const endU = pos + deviceHeight - 1;
const queryOptions = { const queryOptions = {
where: { where: {
@@ -183,7 +183,9 @@ const IdleDeviceManagement = () => {
} }
try { try {
console.log('检查U位冲突:', { rackId, position, height, deviceId: shelvingDevice?.deviceId });
const result = await deviceAPI.checkPosition(rackId, { position, height: height || 1 }); const result = await deviceAPI.checkPosition(rackId, { position, height: height || 1 });
console.log('U位检查结果:', result);
if (!result.available) { if (!result.available) {
setShelvePositionConflict(result.reason); setShelvePositionConflict(result.reason);
} else { } else {
@@ -1018,6 +1020,7 @@ const IdleDeviceManagement = () => {
placeholder="请输入高度" placeholder="请输入高度"
min={1} min={1}
style={{ borderRadius: '8px' }} style={{ borderRadius: '8px' }}
onChange={handleShelveHeightChange}
/> />
</Form.Item> </Form.Item>
</Col> </Col>