- 新增四步向导流程,简化接线创建过程 - 添加线缆标签、颜色、安装信息等新字段 - 实现端口可视化面板和冲突检测功能 - 新增耗材日志设备关联字段 - 添加耗材导入后台任务管理 - 更新线缆管理文档和使用指南
100 lines
2.2 KiB
JavaScript
100 lines
2.2 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,
|
|
},
|
|
cableLabel: {
|
|
type: DataTypes.STRING,
|
|
allowNull: true,
|
|
comment: '线缆标签/编号',
|
|
},
|
|
cableColor: {
|
|
type: DataTypes.STRING,
|
|
allowNull: true,
|
|
comment: '线缆颜色(便于识别)',
|
|
},
|
|
installedBy: {
|
|
type: DataTypes.STRING,
|
|
allowNull: true,
|
|
comment: '安装人',
|
|
},
|
|
installedAt: {
|
|
type: DataTypes.DATE,
|
|
allowNull: true,
|
|
comment: '安装时间',
|
|
},
|
|
lastTestedAt: {
|
|
type: DataTypes.DATE,
|
|
allowNull: true,
|
|
comment: '上次测试时间',
|
|
},
|
|
},
|
|
{
|
|
tableName: 'cables',
|
|
timestamps: true,
|
|
indexes: [
|
|
{ fields: ['sourceDeviceId'] },
|
|
{ fields: ['targetDeviceId'] },
|
|
{ fields: ['status'] },
|
|
{ fields: ['cableType'] },
|
|
{ fields: ['sourceDeviceId', 'targetDeviceId'] },
|
|
{ fields: ['cableLabel'] },
|
|
],
|
|
}
|
|
);
|
|
|
|
Cable.belongsTo(Device, { foreignKey: 'sourceDeviceId', as: 'sourceDevice' });
|
|
Cable.belongsTo(Device, { foreignKey: 'targetDeviceId', as: 'targetDevice' });
|
|
|
|
module.exports = Cable;
|