feat: 新增网卡、端口和接线管理功能
- 添加网卡(NetworkCard)模型及相关路由 - 实现端口(DevicePort)管理功能 - 新增接线(Cable)管理功能 - 添加前端网卡和端口管理界面 - 更新机柜可视化页面显示接线 - 添加设备详情抽屉展示端口和接线信息 - 更新部署文档包含数据库迁移指南 - 添加批量创建端口功能 - 设备删除时自动清理相关接线
This commit is contained in:
@@ -893,15 +893,35 @@ router.delete('/:deviceId', async (req, res) => {
|
||||
});
|
||||
|
||||
if (deleted) {
|
||||
// 更新机柜当前功率
|
||||
const rack = await Rack.findByPk(device.rackId);
|
||||
if (rack) {
|
||||
await rack.update({
|
||||
currentPower: Math.max(0, rack.currentPower - device.powerConsumption)
|
||||
});
|
||||
const Cable = require('../models/Cable');
|
||||
|
||||
const deletedCables = await Cable.destroy({
|
||||
where: {
|
||||
[Op.or]: [
|
||||
{ sourceDeviceId: req.params.deviceId },
|
||||
{ targetDeviceId: req.params.deviceId }
|
||||
]
|
||||
}
|
||||
});
|
||||
|
||||
if (deletedCables > 0) {
|
||||
console.log(`已删除 ${deletedCables} 条相关接线`);
|
||||
}
|
||||
|
||||
res.status(204).json();
|
||||
if (device.rackId) {
|
||||
const rack = await Rack.findByPk(device.rackId);
|
||||
if (rack) {
|
||||
await rack.update({
|
||||
currentPower: Math.max(0, rack.currentPower - device.powerConsumption)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
res.status(200).json({
|
||||
message: '删除成功',
|
||||
deviceId: req.params.deviceId,
|
||||
deletedCablesCount: deletedCables
|
||||
});
|
||||
} else {
|
||||
res.status(404).json({ error: '设备不存在' });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user