- 添加网卡(NetworkCard)模型及相关路由 - 实现端口(DevicePort)管理功能 - 新增接线(Cable)管理功能 - 添加前端网卡和端口管理界面 - 更新机柜可视化页面显示接线 - 添加设备详情抽屉展示端口和接线信息 - 更新部署文档包含数据库迁移指南 - 添加批量创建端口功能 - 设备删除时自动清理相关接线
77 lines
1.8 KiB
JavaScript
77 lines
1.8 KiB
JavaScript
const { DataTypes } = require('sequelize');
|
|
const { sequelize } = require('../db');
|
|
const Device = require('./Device');
|
|
const NetworkCard = require('./NetworkCard');
|
|
|
|
const DevicePort = sequelize.define('DevicePort', {
|
|
portId: {
|
|
type: DataTypes.STRING,
|
|
primaryKey: true,
|
|
allowNull: false,
|
|
unique: true
|
|
},
|
|
deviceId: {
|
|
type: DataTypes.STRING,
|
|
allowNull: false,
|
|
references: {
|
|
model: 'devices',
|
|
key: 'deviceId'
|
|
}
|
|
},
|
|
nicId: {
|
|
type: DataTypes.STRING,
|
|
allowNull: true,
|
|
references: {
|
|
model: 'network_cards',
|
|
key: 'nicId'
|
|
},
|
|
comment: '所属网卡ID,可为空(向后兼容)'
|
|
},
|
|
portName: {
|
|
type: DataTypes.STRING,
|
|
allowNull: false
|
|
},
|
|
portType: {
|
|
type: DataTypes.ENUM('RJ45', 'SFP', 'SFP+', 'SFP28', 'QSFP', 'QSFP28'),
|
|
defaultValue: 'RJ45',
|
|
allowNull: false
|
|
},
|
|
portSpeed: {
|
|
type: DataTypes.ENUM('100M', '1G', '10G', '25G', '40G', '100G'),
|
|
defaultValue: '1G',
|
|
allowNull: false
|
|
},
|
|
status: {
|
|
type: DataTypes.ENUM('free', 'occupied', 'fault'),
|
|
defaultValue: 'free',
|
|
allowNull: false
|
|
},
|
|
vlanId: {
|
|
type: DataTypes.INTEGER,
|
|
allowNull: true
|
|
},
|
|
description: {
|
|
type: DataTypes.TEXT,
|
|
allowNull: true
|
|
}
|
|
}, {
|
|
tableName: 'device_ports',
|
|
timestamps: true,
|
|
indexes: [
|
|
{ fields: ['deviceId'] },
|
|
{ fields: ['nicId'] },
|
|
{ fields: ['status'] },
|
|
{ fields: ['portType'] },
|
|
{ fields: ['portSpeed'] },
|
|
{ unique: true, fields: ['deviceId', 'portName'] }
|
|
]
|
|
});
|
|
|
|
DevicePort.belongsTo(Device, { foreignKey: 'deviceId', as: 'device' });
|
|
Device.hasMany(DevicePort, { foreignKey: 'deviceId', as: 'ports' });
|
|
|
|
DevicePort.belongsTo(NetworkCard, { foreignKey: 'nicId', as: 'networkCard' });
|
|
NetworkCard.hasMany(DevicePort, { foreignKey: 'nicId', as: 'ports' });
|
|
|
|
module.exports = DevicePort;
|