1. 新增操作日志记录功能,记录关键操作 2. 实现危险操作确认对话框,防止误删 3. 添加业务和库房管理模块 4. 支持设备标记为空闲状态 5. 完善API文档和健康检查 6. 优化前端删除操作的确认流程 7. 添加Swagger API文档支持 8. 实现设备与业务的关联功能 9. 改进设备模型,添加空闲相关字段 10. 优化用户、角色管理操作日志
110 lines
2.0 KiB
JavaScript
110 lines
2.0 KiB
JavaScript
const { DataTypes } = require('sequelize');
|
|
const { sequelize } = require('../db');
|
|
const Rack = require('./Rack');
|
|
const Warehouse = require('./Warehouse');
|
|
|
|
const Device = sequelize.define('Device', {
|
|
deviceId: {
|
|
type: DataTypes.STRING,
|
|
primaryKey: true,
|
|
allowNull: false,
|
|
unique: true
|
|
},
|
|
name: {
|
|
type: DataTypes.STRING,
|
|
allowNull: true
|
|
},
|
|
type: {
|
|
type: DataTypes.STRING,
|
|
allowNull: true
|
|
},
|
|
model: {
|
|
type: DataTypes.STRING,
|
|
allowNull: true
|
|
},
|
|
serialNumber: {
|
|
type: DataTypes.STRING,
|
|
allowNull: true,
|
|
unique: true
|
|
},
|
|
rackId: {
|
|
type: DataTypes.STRING,
|
|
allowNull: true
|
|
},
|
|
position: {
|
|
type: DataTypes.INTEGER,
|
|
allowNull: true
|
|
},
|
|
height: {
|
|
type: DataTypes.INTEGER,
|
|
allowNull: true,
|
|
defaultValue: 1
|
|
},
|
|
powerConsumption: {
|
|
type: DataTypes.FLOAT,
|
|
allowNull: true,
|
|
defaultValue: 0
|
|
},
|
|
status: {
|
|
type: DataTypes.STRING,
|
|
defaultValue: 'offline'
|
|
},
|
|
isIdle: {
|
|
type: DataTypes.BOOLEAN,
|
|
defaultValue: false
|
|
},
|
|
idleDate: {
|
|
type: DataTypes.DATE,
|
|
allowNull: true
|
|
},
|
|
idleReason: {
|
|
type: DataTypes.STRING,
|
|
allowNull: true
|
|
},
|
|
warehouseId: {
|
|
type: DataTypes.STRING,
|
|
allowNull: true
|
|
},
|
|
sourceType: {
|
|
type: DataTypes.ENUM('rack', 'warehouse'),
|
|
defaultValue: 'rack'
|
|
},
|
|
purchaseDate: {
|
|
type: DataTypes.DATE,
|
|
allowNull: true
|
|
},
|
|
warrantyExpiry: {
|
|
type: DataTypes.DATE,
|
|
allowNull: true
|
|
},
|
|
ipAddress: {
|
|
type: DataTypes.STRING,
|
|
allowNull: true
|
|
},
|
|
description: {
|
|
type: DataTypes.TEXT,
|
|
allowNull: true
|
|
},
|
|
customFields: {
|
|
type: DataTypes.JSON,
|
|
defaultValue: {},
|
|
allowNull: true
|
|
}
|
|
}, {
|
|
tableName: 'devices',
|
|
timestamps: true,
|
|
indexes: [
|
|
{ fields: ['status'] },
|
|
{ fields: ['type'] },
|
|
{ fields: ['rackId'] },
|
|
{ fields: ['createdAt'] },
|
|
{ fields: ['status', 'type'] },
|
|
{ fields: ['name'] }
|
|
]
|
|
});
|
|
|
|
Device.belongsTo(Rack, { foreignKey: 'rackId' });
|
|
Device.belongsTo(Warehouse, { foreignKey: 'warehouseId' });
|
|
|
|
module.exports = Device;
|