- 添加网卡(NetworkCard)模型及相关路由 - 实现端口(DevicePort)管理功能 - 新增接线(Cable)管理功能 - 添加前端网卡和端口管理界面 - 更新机柜可视化页面显示接线 - 添加设备详情抽屉展示端口和接线信息 - 更新部署文档包含数据库迁移指南 - 添加批量创建端口功能 - 设备删除时自动清理相关接线
70 lines
1.5 KiB
JavaScript
70 lines
1.5 KiB
JavaScript
const { DataTypes } = require('sequelize');
|
|
const { sequelize } = require('../db');
|
|
const Device = require('./Device');
|
|
|
|
const Cable = sequelize.define('Cable', {
|
|
cableId: {
|
|
type: DataTypes.STRING,
|
|
primaryKey: true,
|
|
allowNull: false,
|
|
unique: true
|
|
},
|
|
sourceDeviceId: {
|
|
type: DataTypes.STRING,
|
|
allowNull: false,
|
|
references: {
|
|
model: 'devices',
|
|
key: 'deviceId'
|
|
}
|
|
},
|
|
sourcePort: {
|
|
type: DataTypes.STRING,
|
|
allowNull: false
|
|
},
|
|
targetDeviceId: {
|
|
type: DataTypes.STRING,
|
|
allowNull: false,
|
|
references: {
|
|
model: 'devices',
|
|
key: 'deviceId'
|
|
}
|
|
},
|
|
targetPort: {
|
|
type: DataTypes.STRING,
|
|
allowNull: false
|
|
},
|
|
cableType: {
|
|
type: DataTypes.ENUM('ethernet', 'fiber', 'copper'),
|
|
defaultValue: 'ethernet',
|
|
allowNull: false
|
|
},
|
|
cableLength: {
|
|
type: DataTypes.DECIMAL(5, 2),
|
|
allowNull: true
|
|
},
|
|
status: {
|
|
type: DataTypes.ENUM('normal', 'fault', 'disconnected'),
|
|
defaultValue: 'normal',
|
|
allowNull: false
|
|
},
|
|
description: {
|
|
type: DataTypes.TEXT,
|
|
allowNull: true
|
|
}
|
|
}, {
|
|
tableName: 'cables',
|
|
timestamps: true,
|
|
indexes: [
|
|
{ fields: ['sourceDeviceId'] },
|
|
{ fields: ['targetDeviceId'] },
|
|
{ fields: ['status'] },
|
|
{ fields: ['cableType'] },
|
|
{ fields: ['sourceDeviceId', 'targetDeviceId'] }
|
|
]
|
|
});
|
|
|
|
Cable.belongsTo(Device, { foreignKey: 'sourceDeviceId', as: 'sourceDevice' });
|
|
Cable.belongsTo(Device, { foreignKey: 'targetDeviceId', as: 'targetDevice' });
|
|
|
|
module.exports = Cable;
|