feat: 添加设备位置冲突检查功能并优化操作日志

feat(api): 在设备API中添加checkPosition接口用于检查U位冲突
feat(frontend): 在设备表单和空闲设备管理中实现U位冲突检查
refactor(backend): 重构操作日志功能,添加设备描述生成和元数据构建工具
fix(backend): 修复批量导入机柜时的ID验证规则
feat(backend): 为机柜导入添加创建和跳过机柜的详细返回信息
fix(backend): 修复设备删除时未检查关联接线的问题
feat(backend): 添加机柜导入模板生成脚本
perf(frontend): 优化机柜管理页面的导入结果展示
fix(frontend): 修复设备端口删除时的关联接线检查
This commit is contained in:
zhang1106
2026-03-26 14:35:08 +08:00
parent 0b7732e427
commit d9c46245df
14 changed files with 2152 additions and 384 deletions
+69 -1
View File
@@ -32,6 +32,72 @@ const getClientInfo = (req) => {
return { ipAddress, userAgent };
};
const DEVICE_TYPE_MAP = {
server: '服务器',
switch: '交换机',
router: '路由器',
storage: '存储设备',
firewall: '防火墙',
loadbalancer: '负载均衡器',
other: '其他设备'
};
const generateDeviceDescription = (operation, device, options = {}) => {
const {
includeRack = true,
includePosition = true,
includeSerial = true,
includeIp = true,
includeModel = true
} = options;
const deviceType = DEVICE_TYPE_MAP[device.type] || device.type || '设备';
const parts = [`${deviceType}${device.name}`];
if (device.deviceId) {
parts.push(`编号:${device.deviceId}`);
}
if (includeModel && device.model) {
parts.push(`型号:${device.model}`);
}
if (includeSerial && device.serialNumber) {
parts.push(`序列号:${device.serialNumber}`);
}
if (includeIp && device.ipAddress) {
parts.push(`IP:${device.ipAddress}`);
}
if (includeRack && device.rackName) {
if (includePosition && device.position !== undefined) {
parts.push(`位置:机柜【${device.rackName}】U${device.position}`);
} else {
parts.push(`机柜【${device.rackName}`);
}
}
return `${operation}${parts.join('')}`;
};
const buildDeviceMetadata = (device, extra = {}) => {
return {
deviceId: device.deviceId || null,
deviceName: device.name || null,
deviceType: device.type || null,
deviceModel: device.model || null,
serialNumber: device.serialNumber || null,
ipAddress: device.ipAddress || null,
rackId: device.rackId || null,
rackName: device.rackName || null,
position: device.position !== undefined ? device.position : null,
roomId: device.roomId || null,
roomName: device.roomName || null,
...extra
};
};
async function logOperation({
module,
operationType,
@@ -119,5 +185,7 @@ module.exports = {
logOperation,
logDeviceOperation,
logUserOperation,
logRoleOperation
logRoleOperation,
generateDeviceDescription,
buildDeviceMetadata
};