refactor: 统一代码风格并迁移至 ESLint 新配置

style(backend): 格式化模型文件代码
style(frontend): 调整组件代码格式
chore: 删除旧 ESLint 配置并添加新配置
refactor(backend): 重构模型定义语法
style: 统一箭头函数和对象属性简写
This commit is contained in:
zhang1106
2026-03-27 19:12:16 +08:00
parent 6a8d4144ff
commit 63f0cb570e
166 changed files with 15483 additions and 11170 deletions
+90 -87
View File
@@ -1,94 +1,97 @@
const { DataTypes } = require('sequelize');
const { sequelize } = require('../db');
const BackupLog = sequelize.define('BackupLog', {
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true
const BackupLog = sequelize.define(
'BackupLog',
{
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
},
logType: {
type: DataTypes.ENUM('auto', 'manual'),
allowNull: false,
comment: '备份类型:auto自动,manual手动',
},
status: {
type: DataTypes.ENUM('pending', 'running', 'success', 'failed'),
allowNull: false,
defaultValue: 'pending',
comment: '状态:pending待执行,running执行中,success成功,failed失败',
},
description: {
type: DataTypes.STRING,
allowNull: true,
comment: '备份描述',
},
backupType: {
type: DataTypes.ENUM('full', 'incremental'),
allowNull: true,
comment: '备份类型:full全量,incremental增量',
},
filename: {
type: DataTypes.STRING,
allowNull: true,
comment: '备份文件名',
},
filePath: {
type: DataTypes.STRING,
allowNull: true,
comment: '备份文件路径',
},
fileSize: {
type: DataTypes.BIGINT,
allowNull: true,
comment: '文件大小(字节)',
},
errorMessage: {
type: DataTypes.TEXT,
allowNull: true,
comment: '错误信息',
},
startTime: {
type: DataTypes.DATE,
allowNull: true,
comment: '开始时间',
},
endTime: {
type: DataTypes.DATE,
allowNull: true,
comment: '结束时间',
},
duration: {
type: DataTypes.INTEGER,
allowNull: true,
comment: '执行时长(毫秒)',
},
includeFiles: {
type: DataTypes.BOOLEAN,
defaultValue: false,
comment: '是否包含文件',
},
compressed: {
type: DataTypes.BOOLEAN,
defaultValue: false,
comment: '是否压缩',
},
remoteUploads: {
type: DataTypes.JSON,
allowNull: true,
comment: '远端上传结果',
},
},
logType: {
type: DataTypes.ENUM('auto', 'manual'),
allowNull: false,
comment: '备份类型:auto自动,manual手动'
},
status: {
type: DataTypes.ENUM('pending', 'running', 'success', 'failed'),
allowNull: false,
defaultValue: 'pending',
comment: '状态:pending待执行,running执行中,success成功,failed失败'
},
description: {
type: DataTypes.STRING,
allowNull: true,
comment: '备份描述'
},
backupType: {
type: DataTypes.ENUM('full', 'incremental'),
allowNull: true,
comment: '备份类型:full全量,incremental增量'
},
filename: {
type: DataTypes.STRING,
allowNull: true,
comment: '备份文件名'
},
filePath: {
type: DataTypes.STRING,
allowNull: true,
comment: '备份文件路径'
},
fileSize: {
type: DataTypes.BIGINT,
allowNull: true,
comment: '文件大小(字节)'
},
errorMessage: {
type: DataTypes.TEXT,
allowNull: true,
comment: '错误信息'
},
startTime: {
type: DataTypes.DATE,
allowNull: true,
comment: '开始时间'
},
endTime: {
type: DataTypes.DATE,
allowNull: true,
comment: '结束时间'
},
duration: {
type: DataTypes.INTEGER,
allowNull: true,
comment: '执行时长(毫秒)'
},
includeFiles: {
type: DataTypes.BOOLEAN,
defaultValue: false,
comment: '是否包含文件'
},
compressed: {
type: DataTypes.BOOLEAN,
defaultValue: false,
comment: '是否压缩'
},
remoteUploads: {
type: DataTypes.JSON,
allowNull: true,
comment: '远端上传结果'
{
tableName: 'backup_logs',
timestamps: true,
comment: '备份日志表',
indexes: [
{ fields: ['logType'] },
{ fields: ['status'] },
{ fields: ['createdAt'] },
{ fields: ['logType', 'createdAt'] },
],
}
}, {
tableName: 'backup_logs',
timestamps: true,
comment: '备份日志表',
indexes: [
{ fields: ['logType'] },
{ fields: ['status'] },
{ fields: ['createdAt'] },
{ fields: ['logType', 'createdAt'] }
]
});
);
module.exports = BackupLog;
+34 -33
View File
@@ -1,40 +1,41 @@
const { DataTypes } = require('sequelize');
const { sequelize } = require('../db');
const Business = sequelize.define('Business', {
businessId: {
type: DataTypes.STRING,
primaryKey: true,
allowNull: false,
unique: true
const Business = sequelize.define(
'Business',
{
businessId: {
type: DataTypes.STRING,
primaryKey: true,
allowNull: false,
unique: true,
},
name: {
type: DataTypes.STRING,
allowNull: false,
},
description: {
type: DataTypes.TEXT,
allowNull: true,
},
status: {
type: DataTypes.ENUM('active', 'offline'),
defaultValue: 'active',
},
offlineDate: {
type: DataTypes.DATE,
allowNull: true,
},
offlineReason: {
type: DataTypes.STRING,
allowNull: true,
},
},
name: {
type: DataTypes.STRING,
allowNull: false
},
description: {
type: DataTypes.TEXT,
allowNull: true
},
status: {
type: DataTypes.ENUM('active', 'offline'),
defaultValue: 'active'
},
offlineDate: {
type: DataTypes.DATE,
allowNull: true
},
offlineReason: {
type: DataTypes.STRING,
allowNull: true
{
tableName: 'businesses',
timestamps: true,
indexes: [{ fields: ['status'] }, { fields: ['name'] }],
}
}, {
tableName: 'businesses',
timestamps: true,
indexes: [
{ fields: ['status'] },
{ fields: ['name'] }
]
});
);
module.exports = Business;
+62 -58
View File
@@ -2,66 +2,70 @@ 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
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,
},
},
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'] },
],
}
}, {
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' });
+78 -74
View File
@@ -1,81 +1,85 @@
const { DataTypes } = require('sequelize');
const { sequelize } = require('../db');
const Consumable = sequelize.define('Consumable', {
consumableId: {
type: DataTypes.STRING,
primaryKey: true,
allowNull: false
const Consumable = sequelize.define(
'Consumable',
{
consumableId: {
type: DataTypes.STRING,
primaryKey: true,
allowNull: false,
},
name: {
type: DataTypes.STRING,
allowNull: false,
},
category: {
type: DataTypes.STRING,
allowNull: false,
},
unit: {
type: DataTypes.STRING,
allowNull: false,
defaultValue: '个',
},
currentStock: {
type: DataTypes.INTEGER,
allowNull: false,
defaultValue: 0,
},
minStock: {
type: DataTypes.INTEGER,
allowNull: false,
defaultValue: 10,
},
maxStock: {
type: DataTypes.INTEGER,
allowNull: false,
defaultValue: 0,
comment: '最大库存,0表示无限制',
},
unitPrice: {
type: DataTypes.DECIMAL(10, 2),
allowNull: false,
defaultValue: 0,
},
supplier: {
type: DataTypes.STRING,
},
location: {
type: DataTypes.STRING,
comment: '存放位置',
},
description: {
type: DataTypes.TEXT,
},
snList: {
type: DataTypes.JSON,
allowNull: true,
defaultValue: [],
comment: 'SN序列号列表,JSON数组格式',
},
status: {
type: DataTypes.STRING,
defaultValue: 'active',
},
version: {
type: DataTypes.INTEGER,
allowNull: false,
defaultValue: 0,
comment: '乐观锁版本号',
},
},
name: {
type: DataTypes.STRING,
allowNull: false
},
category: {
type: DataTypes.STRING,
allowNull: false
},
unit: {
type: DataTypes.STRING,
allowNull: false,
defaultValue: '个'
},
currentStock: {
type: DataTypes.INTEGER,
allowNull: false,
defaultValue: 0
},
minStock: {
type: DataTypes.INTEGER,
allowNull: false,
defaultValue: 10
},
maxStock: {
type: DataTypes.INTEGER,
allowNull: false,
defaultValue: 0,
comment: '最大库存,0表示无限制'
},
unitPrice: {
type: DataTypes.DECIMAL(10, 2),
allowNull: false,
defaultValue: 0
},
supplier: {
type: DataTypes.STRING
},
location: {
type: DataTypes.STRING,
comment: '存放位置'
},
description: {
type: DataTypes.TEXT
},
snList: {
type: DataTypes.JSON,
allowNull: true,
defaultValue: [],
comment: 'SN序列号列表,JSON数组格式'
},
status: {
type: DataTypes.STRING,
defaultValue: 'active'
},
version: {
type: DataTypes.INTEGER,
allowNull: false,
defaultValue: 0,
comment: '乐观锁版本号'
{
tableName: 'consumables',
timestamps: true,
indexes: [
{ fields: ['category'] },
{ fields: ['status'] },
{ fields: ['category', 'status'] },
{ fields: ['updatedAt'] },
],
}
}, {
tableName: 'consumables',
timestamps: true,
indexes: [
{ fields: ['category'] },
{ fields: ['status'] },
{ fields: ['category', 'status'] },
{ fields: ['updatedAt'] }
]
});
);
module.exports = Consumable;
+32 -28
View File
@@ -1,35 +1,39 @@
const { DataTypes } = require('sequelize');
const { sequelize } = require('../db');
const ConsumableCategory = sequelize.define('ConsumableCategory', {
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true
const ConsumableCategory = sequelize.define(
'ConsumableCategory',
{
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
},
name: {
type: DataTypes.STRING,
allowNull: false,
unique: true,
comment: '分类名称',
},
description: {
type: DataTypes.STRING,
comment: '分类描述',
},
sortOrder: {
type: DataTypes.INTEGER,
defaultValue: 0,
comment: '排序顺序',
},
status: {
type: DataTypes.STRING,
defaultValue: 'active',
comment: '状态: active-启用, inactive-停用',
},
},
name: {
type: DataTypes.STRING,
allowNull: false,
unique: true,
comment: '分类名称'
},
description: {
type: DataTypes.STRING,
comment: '分类描述'
},
sortOrder: {
type: DataTypes.INTEGER,
defaultValue: 0,
comment: '排序顺序'
},
status: {
type: DataTypes.STRING,
defaultValue: 'active',
comment: '状态: active-启用, inactive-停用'
{
tableName: 'consumable_categories',
timestamps: true,
}
}, {
tableName: 'consumable_categories',
timestamps: true
});
);
module.exports = ConsumableCategory;
+109 -105
View File
@@ -1,112 +1,116 @@
const { DataTypes } = require('sequelize');
const { sequelize } = require('../db');
const ConsumableLog = sequelize.define('ConsumableLog', {
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true
const ConsumableLog = sequelize.define(
'ConsumableLog',
{
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
},
consumableId: {
type: DataTypes.STRING,
allowNull: false,
comment: '耗材ID',
},
consumableName: {
type: DataTypes.STRING,
allowNull: false,
comment: '耗材名称',
},
operationType: {
type: DataTypes.ENUM('in', 'out', 'create', 'update', 'delete', 'adjust', 'import'),
allowNull: false,
comment: '操作类型',
},
quantity: {
type: DataTypes.INTEGER,
defaultValue: 0,
comment: '变动数量(入库为正,出库为负)',
},
previousStock: {
type: DataTypes.INTEGER,
allowNull: false,
comment: '操作前库存',
},
currentStock: {
type: DataTypes.INTEGER,
allowNull: false,
comment: '操作后库存',
},
operator: {
type: DataTypes.STRING,
comment: '操作人',
},
reason: {
type: DataTypes.STRING,
comment: '操作原因',
},
notes: {
type: DataTypes.TEXT,
comment: '备注',
},
relatedId: {
type: DataTypes.STRING,
comment: '关联ID(如订单号、盘点ID等)',
},
isEditable: {
type: DataTypes.BOOLEAN,
defaultValue: true,
comment: '是否可编辑(创建、导入的记录可编辑,系统生成的出入库记录不可编辑)',
},
originalLogId: {
type: DataTypes.INTEGER,
allowNull: true,
comment: '原始日志ID(用于追踪修改历史链)',
},
modifiedBy: {
type: DataTypes.STRING,
allowNull: true,
comment: '修改人',
},
modifiedAt: {
type: DataTypes.DATE,
allowNull: true,
comment: '修改时间',
},
modificationReason: {
type: DataTypes.STRING,
allowNull: true,
comment: '修改原因',
},
isConsumableDeleted: {
type: DataTypes.BOOLEAN,
defaultValue: false,
comment: '关联耗材是否已被删除',
},
consumableSnapshot: {
type: DataTypes.JSON,
allowNull: true,
comment: '耗材快照信息(分类、单位、供应商等),用于耗材删除后追溯',
},
snList: {
type: DataTypes.JSON,
allowNull: true,
defaultValue: [],
comment: '本次操作的SN序列号列表',
},
},
consumableId: {
type: DataTypes.STRING,
allowNull: false,
comment: '耗材ID'
},
consumableName: {
type: DataTypes.STRING,
allowNull: false,
comment: '耗材名称'
},
operationType: {
type: DataTypes.ENUM('in', 'out', 'create', 'update', 'delete', 'adjust', 'import'),
allowNull: false,
comment: '操作类型'
},
quantity: {
type: DataTypes.INTEGER,
defaultValue: 0,
comment: '变动数量(入库为正,出库为负)'
},
previousStock: {
type: DataTypes.INTEGER,
allowNull: false,
comment: '操作前库存'
},
currentStock: {
type: DataTypes.INTEGER,
allowNull: false,
comment: '操作后库存'
},
operator: {
type: DataTypes.STRING,
comment: '操作人'
},
reason: {
type: DataTypes.STRING,
comment: '操作原因'
},
notes: {
type: DataTypes.TEXT,
comment: '备注'
},
relatedId: {
type: DataTypes.STRING,
comment: '关联ID(如订单号、盘点ID等)'
},
isEditable: {
type: DataTypes.BOOLEAN,
defaultValue: true,
comment: '是否可编辑(创建、导入的记录可编辑,系统生成的出入库记录不可编辑)'
},
originalLogId: {
type: DataTypes.INTEGER,
allowNull: true,
comment: '原始日志ID(用于追踪修改历史链)'
},
modifiedBy: {
type: DataTypes.STRING,
allowNull: true,
comment: '修改人'
},
modifiedAt: {
type: DataTypes.DATE,
allowNull: true,
comment: '修改时间'
},
modificationReason: {
type: DataTypes.STRING,
allowNull: true,
comment: '修改原因'
},
isConsumableDeleted: {
type: DataTypes.BOOLEAN,
defaultValue: false,
comment: '关联耗材是否已被删除'
},
consumableSnapshot: {
type: DataTypes.JSON,
allowNull: true,
comment: '耗材快照信息(分类、单位、供应商等),用于耗材删除后追溯'
},
snList: {
type: DataTypes.JSON,
allowNull: true,
defaultValue: [],
comment: '本次操作的SN序列号列表'
{
tableName: 'consumable_logs',
timestamps: true,
comment: '耗材操作日志表',
indexes: [
{ fields: ['consumableId'] },
{ fields: ['operationType'] },
{ fields: ['createdAt'] },
{ fields: ['consumableId', 'createdAt'] },
{ fields: ['originalLogId'] },
{ fields: ['isEditable'] },
{ fields: ['isConsumableDeleted'] },
],
}
}, {
tableName: 'consumable_logs',
timestamps: true,
comment: '耗材操作日志表',
indexes: [
{ fields: ['consumableId'] },
{ fields: ['operationType'] },
{ fields: ['createdAt'] },
{ fields: ['consumableId', 'createdAt'] },
{ fields: ['originalLogId'] },
{ fields: ['isEditable'] },
{ fields: ['isConsumableDeleted'] }
]
});
);
module.exports = ConsumableLog;
+79 -75
View File
@@ -5,82 +5,86 @@ const { sequelize } = require('../db');
* 耗材操作日志归档表
* 用于存储被删除耗材的历史操作记录
*/
const ConsumableLogArchive = sequelize.define('ConsumableLogArchive', {
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true
const ConsumableLogArchive = sequelize.define(
'ConsumableLogArchive',
{
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
},
archiveId: {
type: DataTypes.STRING,
allowNull: false,
comment: '归档记录唯一标识',
},
consumableId: {
type: DataTypes.STRING,
allowNull: false,
comment: '被删除的耗材ID',
},
consumableName: {
type: DataTypes.STRING,
allowNull: false,
comment: '耗材名称',
},
consumableSnapshot: {
type: DataTypes.JSON,
allowNull: true,
comment: '耗材快照信息',
},
totalOperations: {
type: DataTypes.INTEGER,
defaultValue: 0,
comment: '操作记录总数',
},
firstOperationAt: {
type: DataTypes.DATE,
comment: '首次操作时间',
},
lastOperationAt: {
type: DataTypes.DATE,
comment: '最后操作时间',
},
totalInQuantity: {
type: DataTypes.INTEGER,
defaultValue: 0,
comment: '总入库数量',
},
totalOutQuantity: {
type: DataTypes.INTEGER,
defaultValue: 0,
comment: '总出库数量',
},
finalStock: {
type: DataTypes.INTEGER,
defaultValue: 0,
comment: '删除时库存',
},
deletedBy: {
type: DataTypes.STRING,
comment: '删除人',
},
deletedAt: {
type: DataTypes.DATE,
comment: '删除时间',
},
deleteReason: {
type: DataTypes.STRING,
comment: '删除原因',
},
},
archiveId: {
type: DataTypes.STRING,
allowNull: false,
comment: '归档记录唯一标识'
},
consumableId: {
type: DataTypes.STRING,
allowNull: false,
comment: '被删除的耗材ID'
},
consumableName: {
type: DataTypes.STRING,
allowNull: false,
comment: '耗材名称'
},
consumableSnapshot: {
type: DataTypes.JSON,
allowNull: true,
comment: '耗材快照信息'
},
totalOperations: {
type: DataTypes.INTEGER,
defaultValue: 0,
comment: '操作记录总数'
},
firstOperationAt: {
type: DataTypes.DATE,
comment: '首次操作时间'
},
lastOperationAt: {
type: DataTypes.DATE,
comment: '最后操作时间'
},
totalInQuantity: {
type: DataTypes.INTEGER,
defaultValue: 0,
comment: '总入库数量'
},
totalOutQuantity: {
type: DataTypes.INTEGER,
defaultValue: 0,
comment: '总出库数量'
},
finalStock: {
type: DataTypes.INTEGER,
defaultValue: 0,
comment: '删除时库存'
},
deletedBy: {
type: DataTypes.STRING,
comment: '删除人'
},
deletedAt: {
type: DataTypes.DATE,
comment: '删除时间'
},
deleteReason: {
type: DataTypes.STRING,
comment: '删除原因'
{
tableName: 'consumable_log_archives',
timestamps: true,
comment: '耗材操作日志归档表',
indexes: [
{ fields: ['consumableId'] },
{ fields: ['archiveId'] },
{ fields: ['deletedAt'] },
{ fields: ['consumableId', 'deletedAt'] },
],
}
}, {
tableName: 'consumable_log_archives',
timestamps: true,
comment: '耗材操作日志归档表',
indexes: [
{ fields: ['consumableId'] },
{ fields: ['archiveId'] },
{ fields: ['deletedAt'] },
{ fields: ['consumableId', 'deletedAt'] }
]
});
);
module.exports = ConsumableLogArchive;
+61 -61
View File
@@ -2,75 +2,75 @@ const { DataTypes } = require('sequelize');
const { sequelize } = require('../db');
const Consumable = require('./Consumable');
const ConsumableRecord = sequelize.define('ConsumableRecord', {
recordId: {
type: DataTypes.UUID,
primaryKey: true,
defaultValue: DataTypes.UUIDV4,
allowNull: false
const ConsumableRecord = sequelize.define(
'ConsumableRecord',
{
recordId: {
type: DataTypes.UUID,
primaryKey: true,
defaultValue: DataTypes.UUIDV4,
allowNull: false,
},
consumableId: {
type: DataTypes.STRING,
allowNull: false,
references: {
model: Consumable,
key: 'consumableId',
},
},
type: {
type: DataTypes.ENUM('in', 'out'),
allowNull: false,
},
quantity: {
type: DataTypes.INTEGER,
allowNull: false,
},
previousStock: {
type: DataTypes.INTEGER,
allowNull: false,
},
currentStock: {
type: DataTypes.INTEGER,
allowNull: false,
},
operator: {
type: DataTypes.STRING,
allowNull: false,
},
reason: {
type: DataTypes.STRING,
},
recipient: {
type: DataTypes.STRING,
},
notes: {
type: DataTypes.TEXT,
},
snList: {
type: DataTypes.JSON,
allowNull: true,
defaultValue: [],
comment: '本次操作的SN序列号列表',
},
},
consumableId: {
type: DataTypes.STRING,
allowNull: false,
references: {
model: Consumable,
key: 'consumableId'
}
},
type: {
type: DataTypes.ENUM('in', 'out'),
allowNull: false
},
quantity: {
type: DataTypes.INTEGER,
allowNull: false
},
previousStock: {
type: DataTypes.INTEGER,
allowNull: false
},
currentStock: {
type: DataTypes.INTEGER,
allowNull: false
},
operator: {
type: DataTypes.STRING,
allowNull: false
},
reason: {
type: DataTypes.STRING
},
recipient: {
type: DataTypes.STRING
},
notes: {
type: DataTypes.TEXT
},
snList: {
type: DataTypes.JSON,
allowNull: true,
defaultValue: [],
comment: '本次操作的SN序列号列表'
{
tableName: 'consumable_records',
timestamps: true,
indexes: [{ fields: ['consumableId'] }, { fields: ['type'] }, { fields: ['createdAt'] }],
}
}, {
tableName: 'consumable_records',
timestamps: true,
indexes: [
{ fields: ['consumableId'] },
{ fields: ['type'] },
{ fields: ['createdAt'] }
]
});
);
ConsumableRecord.belongsTo(Consumable, {
ConsumableRecord.belongsTo(Consumable, {
foreignKey: 'consumableId',
as: 'consumable',
onDelete: 'CASCADE'
onDelete: 'CASCADE',
});
Consumable.hasMany(ConsumableRecord, {
Consumable.hasMany(ConsumableRecord, {
foreignKey: 'consumableId',
as: 'records',
onDelete: 'CASCADE'
onDelete: 'CASCADE',
});
module.exports = ConsumableRecord;
+101 -97
View File
@@ -3,105 +3,109 @@ 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
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,
},
},
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'] },
],
}
}, {
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' });
+39 -35
View File
@@ -3,52 +3,56 @@ const { sequelize } = require('../db');
const Device = require('./Device');
const Business = require('./Business');
const DeviceBusiness = sequelize.define('DeviceBusiness', {
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true
const DeviceBusiness = sequelize.define(
'DeviceBusiness',
{
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
},
deviceId: {
type: DataTypes.STRING,
allowNull: false,
references: {
model: Device,
key: 'deviceId',
},
},
businessId: {
type: DataTypes.STRING,
allowNull: false,
references: {
model: Business,
key: 'businessId',
},
},
isPrimary: {
type: DataTypes.BOOLEAN,
defaultValue: false,
},
},
deviceId: {
type: DataTypes.STRING,
allowNull: false,
references: {
model: Device,
key: 'deviceId'
}
},
businessId: {
type: DataTypes.STRING,
allowNull: false,
references: {
model: Business,
key: 'businessId'
}
},
isPrimary: {
type: DataTypes.BOOLEAN,
defaultValue: false
{
tableName: 'device_business',
timestamps: true,
indexes: [
{ fields: ['deviceId'] },
{ fields: ['businessId'] },
{ unique: true, fields: ['deviceId', 'businessId'] },
],
}
}, {
tableName: 'device_business',
timestamps: true,
indexes: [
{ fields: ['deviceId'] },
{ fields: ['businessId'] },
{ unique: true, fields: ['deviceId', 'businessId'] }
]
});
);
Device.belongsToMany(Business, {
through: DeviceBusiness,
foreignKey: 'deviceId',
otherKey: 'businessId'
otherKey: 'businessId',
});
Business.belongsToMany(Device, {
through: DeviceBusiness,
foreignKey: 'businessId',
otherKey: 'deviceId'
otherKey: 'deviceId',
});
DeviceBusiness.belongsTo(Business, { foreignKey: 'businessId' });
+53 -49
View File
@@ -1,55 +1,59 @@
const { DataTypes } = require('sequelize');
const { sequelize } = require('../db');
const DeviceField = sequelize.define('DeviceField', {
fieldId: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
allowNull: false
const DeviceField = sequelize.define(
'DeviceField',
{
fieldId: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
allowNull: false,
},
fieldName: {
type: DataTypes.STRING,
allowNull: false,
unique: true,
},
displayName: {
type: DataTypes.STRING,
allowNull: false,
},
fieldType: {
type: DataTypes.STRING,
allowNull: false,
defaultValue: 'string',
},
required: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false,
},
options: {
type: DataTypes.JSON,
allowNull: true,
},
order: {
type: DataTypes.INTEGER,
allowNull: false,
defaultValue: 0,
},
visible: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: true,
},
isSystem: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false,
comment: '是否为系统字段,系统字段不可删除',
},
},
fieldName: {
type: DataTypes.STRING,
allowNull: false,
unique: true
},
displayName: {
type: DataTypes.STRING,
allowNull: false
},
fieldType: {
type: DataTypes.STRING,
allowNull: false,
defaultValue: 'string'
},
required: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false
},
options: {
type: DataTypes.JSON,
allowNull: true
},
order: {
type: DataTypes.INTEGER,
allowNull: false,
defaultValue: 0
},
visible: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: true
},
isSystem: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false,
comment: '是否为系统字段,系统字段不可删除'
{
tableName: 'deviceFields',
timestamps: true,
}
}, {
tableName: 'deviceFields',
timestamps: true
});
);
module.exports = DeviceField;
module.exports = DeviceField;
+64 -60
View File
@@ -1,68 +1,72 @@
const { DataTypes } = require('sequelize');
const { sequelize } = require('../db');
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'
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,
},
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'] },
],
}
}, {
tableName: 'device_ports',
timestamps: true,
indexes: [
{ fields: ['deviceId'] },
{ fields: ['nicId'] },
{ fields: ['status'] },
{ fields: ['portType'] },
{ fields: ['portSpeed'] },
{ unique: true, fields: ['deviceId', 'portName'] }
]
});
);
module.exports = DevicePort;
+58 -58
View File
@@ -1,65 +1,65 @@
const { DataTypes } = require('sequelize');
const { sequelize } = require('../db');
const FaultCategory = sequelize.define('FaultCategory', {
categoryId: {
type: DataTypes.STRING,
primaryKey: true,
allowNull: false,
unique: true
const FaultCategory = sequelize.define(
'FaultCategory',
{
categoryId: {
type: DataTypes.STRING,
primaryKey: true,
allowNull: false,
unique: true,
},
name: {
type: DataTypes.STRING,
allowNull: false,
unique: true,
comment: '分类名称',
},
description: {
type: DataTypes.TEXT,
comment: '分类说明 - 说明此类故障代表什么问题',
},
priority: {
type: DataTypes.INTEGER,
defaultValue: 0,
comment: '排序优先级',
},
defaultPriority: {
type: DataTypes.STRING,
defaultValue: 'medium',
comment: '默认优先级: critical/high/medium/low',
},
expectedDuration: {
type: DataTypes.INTEGER,
comment: '预计处理时长(小时)',
},
solutions: {
type: DataTypes.JSON,
defaultValue: [],
comment: '常见解决方案',
},
isSystem: {
type: DataTypes.BOOLEAN,
defaultValue: false,
comment: '是否系统内置分类',
},
isActive: {
type: DataTypes.BOOLEAN,
defaultValue: true,
comment: '是否启用',
},
metadata: {
type: DataTypes.JSON,
defaultValue: {},
comment: '扩展字段',
},
},
name: {
type: DataTypes.STRING,
allowNull: false,
unique: true,
comment: '分类名称'
},
description: {
type: DataTypes.TEXT,
comment: '分类说明 - 说明此类故障代表什么问题'
},
priority: {
type: DataTypes.INTEGER,
defaultValue: 0,
comment: '排序优先级'
},
defaultPriority: {
type: DataTypes.STRING,
defaultValue: 'medium',
comment: '默认优先级: critical/high/medium/low'
},
expectedDuration: {
type: DataTypes.INTEGER,
comment: '预计处理时长(小时)'
},
solutions: {
type: DataTypes.JSON,
defaultValue: [],
comment: '常见解决方案'
},
isSystem: {
type: DataTypes.BOOLEAN,
defaultValue: false,
comment: '是否系统内置分类'
},
isActive: {
type: DataTypes.BOOLEAN,
defaultValue: true,
comment: '是否启用'
},
metadata: {
type: DataTypes.JSON,
defaultValue: {},
comment: '扩展字段'
{
tableName: 'fault_categories',
timestamps: true,
indexes: [{ fields: ['name'] }, { fields: ['isActive'] }, { fields: ['priority'] }],
}
}, {
tableName: 'fault_categories',
timestamps: true,
indexes: [
{ fields: ['name'] },
{ fields: ['isActive'] },
{ fields: ['priority'] }
]
});
);
module.exports = FaultCategory;
+93 -93
View File
@@ -2,101 +2,101 @@ const { DataTypes } = require('sequelize');
const { sequelize } = require('../db');
const User = require('./User');
const InventoryPlan = sequelize.define('InventoryPlan', {
planId: {
type: DataTypes.STRING,
primaryKey: true,
allowNull: false,
unique: true
const InventoryPlan = sequelize.define(
'InventoryPlan',
{
planId: {
type: DataTypes.STRING,
primaryKey: true,
allowNull: false,
unique: true,
},
name: {
type: DataTypes.STRING,
allowNull: false,
},
type: {
type: DataTypes.STRING,
allowNull: false,
defaultValue: 'full',
comment: 'full:全面盘点, partial:局部盘点, sample:抽样盘点',
},
description: {
type: DataTypes.TEXT,
allowNull: true,
},
status: {
type: DataTypes.STRING,
defaultValue: 'draft',
comment: 'draft:草稿, pending:待执行, in_progress:进行中, completed:已完成, cancelled:已取消',
},
scheduledDate: {
type: DataTypes.DATE,
allowNull: true,
},
completedDate: {
type: DataTypes.DATE,
allowNull: true,
},
targetRooms: {
type: DataTypes.JSON,
defaultValue: [],
comment: '目标机房ID列表',
},
targetRacks: {
type: DataTypes.JSON,
defaultValue: [],
comment: '目标机柜ID列表',
},
totalDevices: {
type: DataTypes.INTEGER,
defaultValue: 0,
comment: '盘点设备总数',
},
checkedDevices: {
type: DataTypes.INTEGER,
defaultValue: 0,
comment: '已盘点设备数',
},
normalDevices: {
type: DataTypes.INTEGER,
defaultValue: 0,
comment: '正常设备数',
},
abnormalDevices: {
type: DataTypes.INTEGER,
defaultValue: 0,
comment: '异常设备数',
},
missedDevices: {
type: DataTypes.INTEGER,
defaultValue: 0,
comment: '漏盘设备数',
},
extraDevices: {
type: DataTypes.INTEGER,
defaultValue: 0,
comment: '多出设备数',
},
createdBy: {
type: DataTypes.STRING,
allowNull: true,
references: {
model: User,
key: 'userId',
},
},
remark: {
type: DataTypes.TEXT,
allowNull: true,
},
},
name: {
type: DataTypes.STRING,
allowNull: false
},
type: {
type: DataTypes.STRING,
allowNull: false,
defaultValue: 'full',
comment: 'full:全面盘点, partial:局部盘点, sample:抽样盘点'
},
description: {
type: DataTypes.TEXT,
allowNull: true
},
status: {
type: DataTypes.STRING,
defaultValue: 'draft',
comment: 'draft:草稿, pending:待执行, in_progress:进行中, completed:已完成, cancelled:已取消'
},
scheduledDate: {
type: DataTypes.DATE,
allowNull: true
},
completedDate: {
type: DataTypes.DATE,
allowNull: true
},
targetRooms: {
type: DataTypes.JSON,
defaultValue: [],
comment: '目标机房ID列表'
},
targetRacks: {
type: DataTypes.JSON,
defaultValue: [],
comment: '目标机柜ID列表'
},
totalDevices: {
type: DataTypes.INTEGER,
defaultValue: 0,
comment: '盘点设备总数'
},
checkedDevices: {
type: DataTypes.INTEGER,
defaultValue: 0,
comment: '已盘点设备数'
},
normalDevices: {
type: DataTypes.INTEGER,
defaultValue: 0,
comment: '正常设备数'
},
abnormalDevices: {
type: DataTypes.INTEGER,
defaultValue: 0,
comment: '异常设备数'
},
missedDevices: {
type: DataTypes.INTEGER,
defaultValue: 0,
comment: '漏盘设备数'
},
extraDevices: {
type: DataTypes.INTEGER,
defaultValue: 0,
comment: '多出设备数'
},
createdBy: {
type: DataTypes.STRING,
allowNull: true,
references: {
model: User,
key: 'userId'
}
},
remark: {
type: DataTypes.TEXT,
allowNull: true
{
tableName: 'inventory_plans',
timestamps: true,
indexes: [{ fields: ['status'] }, { fields: ['scheduledDate'] }, { fields: ['createdAt'] }],
}
}, {
tableName: 'inventory_plans',
timestamps: true,
indexes: [
{ fields: ['status'] },
{ fields: ['scheduledDate'] },
{ fields: ['createdAt'] }
]
});
);
InventoryPlan.belongsTo(User, { foreignKey: 'createdBy', as: 'Creator' });
User.hasMany(InventoryPlan, { foreignKey: 'createdBy' });
+98 -93
View File
@@ -1,100 +1,105 @@
const { DataTypes } = require('sequelize');
const { sequelize } = require('../db');
const InventoryRecord = sequelize.define('InventoryRecord', {
recordId: {
type: DataTypes.STRING,
primaryKey: true,
allowNull: false,
unique: true
const InventoryRecord = sequelize.define(
'InventoryRecord',
{
recordId: {
type: DataTypes.STRING,
primaryKey: true,
allowNull: false,
unique: true,
},
taskId: {
type: DataTypes.STRING,
allowNull: false,
},
planId: {
type: DataTypes.STRING,
allowNull: false,
},
deviceId: {
type: DataTypes.STRING,
allowNull: false,
},
deviceName: {
type: DataTypes.STRING,
allowNull: true,
},
deviceType: {
type: DataTypes.STRING,
allowNull: true,
},
serialNumber: {
type: DataTypes.STRING,
allowNull: true,
comment: '系统记录的序列号',
},
actualSerialNumber: {
type: DataTypes.STRING,
allowNull: true,
comment: '实际盘点序列号',
},
rackId: {
type: DataTypes.STRING,
allowNull: true,
comment: '系统记录的机柜',
},
actualRackId: {
type: DataTypes.STRING,
allowNull: true,
comment: '实际盘点机柜',
},
position: {
type: DataTypes.INTEGER,
allowNull: true,
comment: '系统记录的位置',
},
actualPosition: {
type: DataTypes.INTEGER,
allowNull: true,
comment: '实际盘点位置',
},
status: {
type: DataTypes.STRING,
defaultValue: 'pending',
comment: 'pending:待盘点, normal:正常, abnormal:异常, missed:未盘点, not_found:未找到',
},
abnormalType: {
type: DataTypes.STRING,
allowNull: true,
comment:
'serial_mismatch:序列号不符, position_mismatch:位置不符, device_missing:设备缺失, extra_device:多出设备',
},
checkedBy: {
type: DataTypes.STRING,
allowNull: true,
},
checkedAt: {
type: DataTypes.DATE,
allowNull: true,
},
remark: {
type: DataTypes.TEXT,
allowNull: true,
},
photoUrl: {
type: DataTypes.STRING,
allowNull: true,
comment: '盘点照片',
},
},
taskId: {
type: DataTypes.STRING,
allowNull: false
},
planId: {
type: DataTypes.STRING,
allowNull: false
},
deviceId: {
type: DataTypes.STRING,
allowNull: false
},
deviceName: {
type: DataTypes.STRING,
allowNull: true
},
deviceType: {
type: DataTypes.STRING,
allowNull: true
},
serialNumber: {
type: DataTypes.STRING,
allowNull: true,
comment: '系统记录的序列号'
},
actualSerialNumber: {
type: DataTypes.STRING,
allowNull: true,
comment: '实际盘点序列号'
},
rackId: {
type: DataTypes.STRING,
allowNull: true,
comment: '系统记录的机柜'
},
actualRackId: {
type: DataTypes.STRING,
allowNull: true,
comment: '实际盘点机柜'
},
position: {
type: DataTypes.INTEGER,
allowNull: true,
comment: '系统记录的位置'
},
actualPosition: {
type: DataTypes.INTEGER,
allowNull: true,
comment: '实际盘点位置'
},
status: {
type: DataTypes.STRING,
defaultValue: 'pending',
comment: 'pending:待盘点, normal:正常, abnormal:异常, missed:未盘点, not_found:未找到'
},
abnormalType: {
type: DataTypes.STRING,
allowNull: true,
comment: 'serial_mismatch:序列号不符, position_mismatch:位置不符, device_missing:设备缺失, extra_device:多出设备'
},
checkedBy: {
type: DataTypes.STRING,
allowNull: true
},
checkedAt: {
type: DataTypes.DATE,
allowNull: true
},
remark: {
type: DataTypes.TEXT,
allowNull: true
},
photoUrl: {
type: DataTypes.STRING,
allowNull: true,
comment: '盘点照片'
{
tableName: 'inventory_records',
timestamps: true,
indexes: [
{ fields: ['taskId'] },
{ fields: ['planId'] },
{ fields: ['deviceId'] },
{ fields: ['status'] },
{ fields: ['checkedBy'] },
],
}
}, {
tableName: 'inventory_records',
timestamps: true,
indexes: [
{ fields: ['taskId'] },
{ fields: ['planId'] },
{ fields: ['deviceId'] },
{ fields: ['status'] },
{ fields: ['checkedBy'] }
]
});
);
module.exports = InventoryRecord;
+74 -74
View File
@@ -1,81 +1,81 @@
const { DataTypes } = require('sequelize');
const { sequelize } = require('../db');
const InventoryTask = sequelize.define('InventoryTask', {
taskId: {
type: DataTypes.STRING,
primaryKey: true,
allowNull: false,
unique: true
const InventoryTask = sequelize.define(
'InventoryTask',
{
taskId: {
type: DataTypes.STRING,
primaryKey: true,
allowNull: false,
unique: true,
},
planId: {
type: DataTypes.STRING,
allowNull: false,
},
targetType: {
type: DataTypes.STRING,
allowNull: false,
comment: 'room:机房, rack:机柜, device:设备',
},
targetId: {
type: DataTypes.STRING,
allowNull: false,
comment: '目标ID(机房ID/机柜ID/设备ID',
},
targetName: {
type: DataTypes.STRING,
allowNull: true,
comment: '目标名称',
},
status: {
type: DataTypes.STRING,
defaultValue: 'pending',
comment: 'pending:待执行, in_progress:进行中, completed:已完成, skipped:已跳过',
},
totalDevices: {
type: DataTypes.INTEGER,
defaultValue: 0,
comment: '设备总数',
},
checkedDevices: {
type: DataTypes.INTEGER,
defaultValue: 0,
comment: '已盘点设备数',
},
normalDevices: {
type: DataTypes.INTEGER,
defaultValue: 0,
comment: '正常设备数',
},
abnormalDevices: {
type: DataTypes.INTEGER,
defaultValue: 0,
comment: '异常设备数',
},
assignedTo: {
type: DataTypes.STRING,
allowNull: true,
},
assignedAt: {
type: DataTypes.DATE,
allowNull: true,
},
completedAt: {
type: DataTypes.DATE,
allowNull: true,
},
remark: {
type: DataTypes.TEXT,
allowNull: true,
},
},
planId: {
type: DataTypes.STRING,
allowNull: false
},
targetType: {
type: DataTypes.STRING,
allowNull: false,
comment: 'room:机房, rack:机柜, device:设备'
},
targetId: {
type: DataTypes.STRING,
allowNull: false,
comment: '目标ID(机房ID/机柜ID/设备ID'
},
targetName: {
type: DataTypes.STRING,
allowNull: true,
comment: '目标名称'
},
status: {
type: DataTypes.STRING,
defaultValue: 'pending',
comment: 'pending:待执行, in_progress:进行中, completed:已完成, skipped:已跳过'
},
totalDevices: {
type: DataTypes.INTEGER,
defaultValue: 0,
comment: '设备总数'
},
checkedDevices: {
type: DataTypes.INTEGER,
defaultValue: 0,
comment: '已盘点设备数'
},
normalDevices: {
type: DataTypes.INTEGER,
defaultValue: 0,
comment: '正常设备数'
},
abnormalDevices: {
type: DataTypes.INTEGER,
defaultValue: 0,
comment: '异常设备数'
},
assignedTo: {
type: DataTypes.STRING,
allowNull: true
},
assignedAt: {
type: DataTypes.DATE,
allowNull: true
},
completedAt: {
type: DataTypes.DATE,
allowNull: true
},
remark: {
type: DataTypes.TEXT,
allowNull: true
{
tableName: 'inventory_tasks',
timestamps: true,
indexes: [{ fields: ['planId'] }, { fields: ['status'] }, { fields: ['assignedTo'] }],
}
}, {
tableName: 'inventory_tasks',
timestamps: true,
indexes: [
{ fields: ['planId'] },
{ fields: ['status'] },
{ fields: ['assignedTo'] }
]
});
);
module.exports = InventoryTask;
+62 -58
View File
@@ -1,65 +1,69 @@
const { DataTypes } = require('sequelize');
const { sequelize } = require('../db');
const NetworkCard = sequelize.define('NetworkCard', {
nicId: {
type: DataTypes.STRING,
primaryKey: true,
allowNull: false,
unique: true
const NetworkCard = sequelize.define(
'NetworkCard',
{
nicId: {
type: DataTypes.STRING,
primaryKey: true,
allowNull: false,
unique: true,
},
deviceId: {
type: DataTypes.STRING,
allowNull: false,
references: {
model: 'devices',
key: 'deviceId',
},
},
name: {
type: DataTypes.STRING,
allowNull: false,
comment: '网卡名称,如"网卡1"、"eth0"、"Primary NIC"',
},
description: {
type: DataTypes.TEXT,
allowNull: true,
comment: '网卡描述信息',
},
slotNumber: {
type: DataTypes.INTEGER,
allowNull: true,
comment: '插槽编号',
},
portCount: {
type: DataTypes.INTEGER,
defaultValue: 0,
comment: '端口数量',
},
model: {
type: DataTypes.STRING,
allowNull: true,
comment: '网卡型号',
},
manufacturer: {
type: DataTypes.STRING,
allowNull: true,
comment: '制造商',
},
status: {
type: DataTypes.ENUM('normal', 'warning', 'fault', 'offline'),
defaultValue: 'normal',
allowNull: false,
comment: '网卡状态',
},
},
deviceId: {
type: DataTypes.STRING,
allowNull: false,
references: {
model: 'devices',
key: 'deviceId'
}
},
name: {
type: DataTypes.STRING,
allowNull: false,
comment: '网卡名称,如"网卡1"、"eth0"、"Primary NIC"'
},
description: {
type: DataTypes.TEXT,
allowNull: true,
comment: '网卡描述信息'
},
slotNumber: {
type: DataTypes.INTEGER,
allowNull: true,
comment: '插槽编号'
},
portCount: {
type: DataTypes.INTEGER,
defaultValue: 0,
comment: '端口数量'
},
model: {
type: DataTypes.STRING,
allowNull: true,
comment: '网卡型号'
},
manufacturer: {
type: DataTypes.STRING,
allowNull: true,
comment: '制造商'
},
status: {
type: DataTypes.ENUM('normal', 'warning', 'fault', 'offline'),
defaultValue: 'normal',
allowNull: false,
comment: '网卡状态'
{
tableName: 'network_cards',
timestamps: true,
indexes: [
{ fields: ['deviceId'] },
{ fields: ['slotNumber'] },
{ unique: true, fields: ['deviceId', 'name'] },
],
}
}, {
tableName: 'network_cards',
timestamps: true,
indexes: [
{ fields: ['deviceId'] },
{ fields: ['slotNumber'] },
{ unique: true, fields: ['deviceId', 'name'] }
]
});
);
module.exports = NetworkCard;
+83 -78
View File
@@ -5,85 +5,90 @@ const generateRecordId = () => {
return `OPLOG_${Date.now().toString(36)}_${Math.random().toString(36).substr(2, 9)}`;
};
const OperationLog = sequelize.define('OperationLog', {
recordId: {
type: DataTypes.STRING,
primaryKey: true,
allowNull: false,
unique: true
const OperationLog = sequelize.define(
'OperationLog',
{
recordId: {
type: DataTypes.STRING,
primaryKey: true,
allowNull: false,
unique: true,
},
module: {
type: DataTypes.STRING,
allowNull: false,
comment: '模块:device/user/role/consumable/rack/room',
},
operationType: {
type: DataTypes.STRING,
allowNull: false,
comment:
'操作类型: create/update/delete/batch_delete/batch_update/status_change/move/permission_change',
},
operationDescription: {
type: DataTypes.TEXT,
comment: '操作描述',
},
targetId: {
type: DataTypes.STRING,
comment: '目标对象ID',
},
targetName: {
type: DataTypes.STRING,
comment: '目标对象名称(冗余便于展示)',
},
operatorId: {
type: DataTypes.STRING,
allowNull: false,
comment: '操作人ID',
},
operatorName: {
type: DataTypes.STRING,
allowNull: false,
comment: '操作人姓名',
},
operatorRole: {
type: DataTypes.STRING,
comment: '操作人角色',
},
beforeState: {
type: DataTypes.JSON,
comment: '操作前状态',
},
afterState: {
type: DataTypes.JSON,
comment: '操作后状态',
},
result: {
type: DataTypes.STRING,
defaultValue: 'success',
comment: '操作结果: success/failed',
},
ipAddress: {
type: DataTypes.STRING,
comment: 'IP地址',
},
userAgent: {
type: DataTypes.STRING,
comment: '用户代理',
},
metadata: {
type: DataTypes.JSON,
defaultValue: {},
comment: '扩展字段',
},
},
module: {
type: DataTypes.STRING,
allowNull: false,
comment: '模块:device/user/role/consumable/rack/room'
},
operationType: {
type: DataTypes.STRING,
allowNull: false,
comment: '操作类型: create/update/delete/batch_delete/batch_update/status_change/move/permission_change'
},
operationDescription: {
type: DataTypes.TEXT,
comment: '操作描述'
},
targetId: {
type: DataTypes.STRING,
comment: '目标对象ID'
},
targetName: {
type: DataTypes.STRING,
comment: '目标对象名称(冗余便于展示)'
},
operatorId: {
type: DataTypes.STRING,
allowNull: false,
comment: '操作人ID'
},
operatorName: {
type: DataTypes.STRING,
allowNull: false,
comment: '操作人姓名'
},
operatorRole: {
type: DataTypes.STRING,
comment: '操作人角色'
},
beforeState: {
type: DataTypes.JSON,
comment: '操作前状态'
},
afterState: {
type: DataTypes.JSON,
comment: '操作后状态'
},
result: {
type: DataTypes.STRING,
defaultValue: 'success',
comment: '操作结果: success/failed'
},
ipAddress: {
type: DataTypes.STRING,
comment: 'IP地址'
},
userAgent: {
type: DataTypes.STRING,
comment: '用户代理'
},
metadata: {
type: DataTypes.JSON,
defaultValue: {},
comment: '扩展字段'
{
tableName: 'operation_logs',
timestamps: true,
indexes: [
{ fields: ['module'] },
{ fields: ['operationType'] },
{ fields: ['targetId'] },
{ fields: ['operatorId'] },
{ fields: ['createdAt'] },
],
}
}, {
tableName: 'operation_logs',
timestamps: true,
indexes: [
{ fields: ['module'] },
{ fields: ['operationType'] },
{ fields: ['targetId'] },
{ fields: ['operatorId'] },
{ fields: ['createdAt'] }
]
});
);
module.exports = OperationLog;
+158 -154
View File
@@ -6,168 +6,172 @@ const InventoryTask = require('./InventoryTask');
const Room = require('./Room');
const Rack = require('./Rack');
const PendingDevice = sequelize.define('PendingDevice', {
pendingId: {
type: DataTypes.STRING,
primaryKey: true,
allowNull: false,
unique: true
},
serialNumber: {
type: DataTypes.STRING,
allowNull: false,
comment: '设备序列号'
},
deviceName: {
type: DataTypes.STRING,
allowNull: true,
comment: '设备名称'
},
deviceType: {
type: DataTypes.STRING,
allowNull: true,
defaultValue: 'other',
comment: '设备类型: server, switch, router, storage, other'
},
roomId: {
type: DataTypes.STRING,
allowNull: true,
references: {
model: Room,
key: 'roomId'
const PendingDevice = sequelize.define(
'PendingDevice',
{
pendingId: {
type: DataTypes.STRING,
primaryKey: true,
allowNull: false,
unique: true,
},
comment: '所属机房ID'
},
rackId: {
type: DataTypes.STRING,
allowNull: true,
references: {
model: Rack,
key: 'rackId'
serialNumber: {
type: DataTypes.STRING,
allowNull: false,
comment: '设备序列号',
},
comment: '所属机柜ID'
},
position: {
type: DataTypes.INTEGER,
allowNull: true,
comment: 'U位'
},
height: {
type: DataTypes.INTEGER,
allowNull: true,
defaultValue: 1,
comment: '高度(U)'
},
powerConsumption: {
type: DataTypes.FLOAT,
allowNull: true,
defaultValue: 0,
comment: '功率(W)'
},
model: {
type: DataTypes.STRING,
allowNull: true,
comment: '设备型号'
},
brand: {
type: DataTypes.STRING,
allowNull: true,
comment: '品牌'
},
ipAddress: {
type: DataTypes.STRING,
allowNull: true,
comment: 'IP地址'
},
purchaseDate: {
type: DataTypes.DATE,
allowNull: true,
comment: '购买日期'
},
warrantyExpiry: {
type: DataTypes.DATE,
allowNull: true,
comment: '保修到期'
},
description: {
type: DataTypes.TEXT,
allowNull: true,
comment: '描述'
},
customFields: {
type: DataTypes.JSON,
defaultValue: {},
allowNull: true
},
status: {
type: DataTypes.STRING,
defaultValue: 'pending',
comment: 'pending: 待同步, synced: 已同步, deleted: 已删除'
},
planId: {
type: DataTypes.STRING,
allowNull: true,
references: {
model: InventoryPlan,
key: 'planId'
deviceName: {
type: DataTypes.STRING,
allowNull: true,
comment: '设备名称',
},
comment: '关联的盘点计划ID'
},
taskId: {
type: DataTypes.STRING,
allowNull: true,
references: {
model: InventoryTask,
key: 'taskId'
deviceType: {
type: DataTypes.STRING,
allowNull: true,
defaultValue: 'other',
comment: '设备类型: server, switch, router, storage, other',
},
comment: '关联的盘点任务ID'
},
createdBy: {
type: DataTypes.STRING,
allowNull: true,
references: {
model: User,
key: 'userId'
roomId: {
type: DataTypes.STRING,
allowNull: true,
references: {
model: Room,
key: 'roomId',
},
comment: '所属机房ID',
},
comment: '创建人'
},
syncedAt: {
type: DataTypes.DATE,
allowNull: true,
comment: '同步时间'
},
syncedBy: {
type: DataTypes.STRING,
allowNull: true,
references: {
model: User,
key: 'userId'
rackId: {
type: DataTypes.STRING,
allowNull: true,
references: {
model: Rack,
key: 'rackId',
},
comment: '所属机柜ID',
},
position: {
type: DataTypes.INTEGER,
allowNull: true,
comment: 'U位',
},
height: {
type: DataTypes.INTEGER,
allowNull: true,
defaultValue: 1,
comment: '高度(U)',
},
powerConsumption: {
type: DataTypes.FLOAT,
allowNull: true,
defaultValue: 0,
comment: '功率(W)',
},
model: {
type: DataTypes.STRING,
allowNull: true,
comment: '设备型号',
},
brand: {
type: DataTypes.STRING,
allowNull: true,
comment: '品牌',
},
ipAddress: {
type: DataTypes.STRING,
allowNull: true,
comment: 'IP地址',
},
purchaseDate: {
type: DataTypes.DATE,
allowNull: true,
comment: '购买日期',
},
warrantyExpiry: {
type: DataTypes.DATE,
allowNull: true,
comment: '保修到期',
},
description: {
type: DataTypes.TEXT,
allowNull: true,
comment: '描述',
},
customFields: {
type: DataTypes.JSON,
defaultValue: {},
allowNull: true,
},
status: {
type: DataTypes.STRING,
defaultValue: 'pending',
comment: 'pending: 待同步, synced: 已同步, deleted: 已删除',
},
planId: {
type: DataTypes.STRING,
allowNull: true,
references: {
model: InventoryPlan,
key: 'planId',
},
comment: '关联的盘点计划ID',
},
taskId: {
type: DataTypes.STRING,
allowNull: true,
references: {
model: InventoryTask,
key: 'taskId',
},
comment: '关联的盘点任务ID',
},
createdBy: {
type: DataTypes.STRING,
allowNull: true,
references: {
model: User,
key: 'userId',
},
comment: '创建人',
},
syncedAt: {
type: DataTypes.DATE,
allowNull: true,
comment: '同步时间',
},
syncedBy: {
type: DataTypes.STRING,
allowNull: true,
references: {
model: User,
key: 'userId',
},
comment: '同步人',
},
syncedDeviceId: {
type: DataTypes.STRING,
allowNull: true,
comment: '同步后生成的设备ID',
},
remark: {
type: DataTypes.TEXT,
allowNull: true,
comment: '备注',
},
comment: '同步人'
},
syncedDeviceId: {
type: DataTypes.STRING,
allowNull: true,
comment: '同步后生成的设备ID'
},
remark: {
type: DataTypes.TEXT,
allowNull: true,
comment: '备注'
{
tableName: 'pending_devices',
timestamps: true,
indexes: [
{ fields: ['serialNumber'] },
{ fields: ['status'] },
{ fields: ['planId'] },
{ fields: ['taskId'] },
{ fields: ['createdBy'] },
{ fields: ['roomId'] },
{ fields: ['rackId'] },
],
}
}, {
tableName: 'pending_devices',
timestamps: true,
indexes: [
{ fields: ['serialNumber'] },
{ fields: ['status'] },
{ fields: ['planId'] },
{ fields: ['taskId'] },
{ fields: ['createdBy'] },
{ fields: ['roomId'] },
{ fields: ['rackId'] }
]
});
);
PendingDevice.belongsTo(User, { foreignKey: 'createdBy', as: 'Creator' });
PendingDevice.belongsTo(User, { foreignKey: 'syncedBy', as: 'Syncer' });
+45 -41
View File
@@ -1,48 +1,52 @@
const { DataTypes } = require('sequelize');
const { sequelize } = require('../db');
const Permission = sequelize.define('Permission', {
permissionId: {
type: DataTypes.STRING,
primaryKey: true,
allowNull: false
const Permission = sequelize.define(
'Permission',
{
permissionId: {
type: DataTypes.STRING,
primaryKey: true,
allowNull: false,
},
permissionName: {
type: DataTypes.STRING,
allowNull: false,
},
permissionCode: {
type: DataTypes.STRING,
allowNull: false,
unique: true,
},
parentId: {
type: DataTypes.STRING,
allowNull: true,
},
type: {
type: DataTypes.ENUM('menu', 'button'),
defaultValue: 'button',
},
path: {
type: DataTypes.STRING,
allowNull: true,
},
icon: {
type: DataTypes.STRING,
allowNull: true,
},
sort: {
type: DataTypes.INTEGER,
defaultValue: 0,
},
status: {
type: DataTypes.ENUM('active', 'inactive'),
defaultValue: 'active',
},
},
permissionName: {
type: DataTypes.STRING,
allowNull: false
},
permissionCode: {
type: DataTypes.STRING,
allowNull: false,
unique: true
},
parentId: {
type: DataTypes.STRING,
allowNull: true
},
type: {
type: DataTypes.ENUM('menu', 'button'),
defaultValue: 'button'
},
path: {
type: DataTypes.STRING,
allowNull: true
},
icon: {
type: DataTypes.STRING,
allowNull: true
},
sort: {
type: DataTypes.INTEGER,
defaultValue: 0
},
status: {
type: DataTypes.ENUM('active', 'inactive'),
defaultValue: 'active'
{
tableName: 'permissions',
timestamps: true,
}
}, {
tableName: 'permissions',
timestamps: true
});
);
module.exports = Permission;
+44 -44
View File
@@ -2,54 +2,54 @@ const { DataTypes } = require('sequelize');
const { sequelize } = require('../db');
const Room = require('./Room');
const Rack = sequelize.define('Rack', {
rackId: {
type: DataTypes.STRING,
primaryKey: true,
allowNull: false,
unique: true
const Rack = sequelize.define(
'Rack',
{
rackId: {
type: DataTypes.STRING,
primaryKey: true,
allowNull: false,
unique: true,
},
name: {
type: DataTypes.STRING,
allowNull: false,
},
height: {
type: DataTypes.INTEGER,
allowNull: false,
defaultValue: 45, // 标准机柜高度(U数)
},
maxPower: {
type: DataTypes.FLOAT,
allowNull: false,
},
currentPower: {
type: DataTypes.FLOAT,
defaultValue: 0,
},
status: {
type: DataTypes.STRING,
defaultValue: 'active',
},
roomId: {
type: DataTypes.STRING,
allowNull: false,
references: {
model: Room,
key: 'roomId',
},
},
},
name: {
type: DataTypes.STRING,
allowNull: false
},
height: {
type: DataTypes.INTEGER,
allowNull: false,
defaultValue: 45 // 标准机柜高度(U数)
},
maxPower: {
type: DataTypes.FLOAT,
allowNull: false
},
currentPower: {
type: DataTypes.FLOAT,
defaultValue: 0
},
status: {
type: DataTypes.STRING,
defaultValue: 'active'
},
roomId: {
type: DataTypes.STRING,
allowNull: false,
references: {
model: Room,
key: 'roomId'
}
{
tableName: 'racks',
timestamps: true,
indexes: [{ fields: ['roomId'] }, { fields: ['status'] }, { fields: ['roomId', 'status'] }],
}
}, {
tableName: 'racks',
timestamps: true,
indexes: [
{ fields: ['roomId'] },
{ fields: ['status'] },
{ fields: ['roomId', 'status'] }
]
});
);
// 关联关系
Rack.belongsTo(Room, { foreignKey: 'roomId' });
Room.hasMany(Rack, { foreignKey: 'roomId' });
module.exports = Rack;
module.exports = Rack;
+37 -33
View File
@@ -1,40 +1,44 @@
const { DataTypes } = require('sequelize');
const { sequelize } = require('../db');
const Role = sequelize.define('Role', {
roleId: {
type: DataTypes.STRING,
primaryKey: true,
allowNull: false
const Role = sequelize.define(
'Role',
{
roleId: {
type: DataTypes.STRING,
primaryKey: true,
allowNull: false,
},
roleName: {
type: DataTypes.STRING,
allowNull: false,
},
roleCode: {
type: DataTypes.STRING,
allowNull: false,
unique: true,
},
description: {
type: DataTypes.STRING,
allowNull: true,
},
status: {
type: DataTypes.ENUM('active', 'inactive'),
defaultValue: 'active',
},
permissions: {
type: DataTypes.JSON,
defaultValue: [],
},
sort: {
type: DataTypes.INTEGER,
defaultValue: 0,
},
},
roleName: {
type: DataTypes.STRING,
allowNull: false
},
roleCode: {
type: DataTypes.STRING,
allowNull: false,
unique: true
},
description: {
type: DataTypes.STRING,
allowNull: true
},
status: {
type: DataTypes.ENUM('active', 'inactive'),
defaultValue: 'active'
},
permissions: {
type: DataTypes.JSON,
defaultValue: []
},
sort: {
type: DataTypes.INTEGER,
defaultValue: 0
{
tableName: 'roles',
timestamps: true,
}
}, {
tableName: 'roles',
timestamps: true
});
);
module.exports = Role;
+38 -37
View File
@@ -1,43 +1,44 @@
const { DataTypes } = require('sequelize');
const { sequelize } = require('../db');
const Room = sequelize.define('Room', {
roomId: {
type: DataTypes.STRING,
primaryKey: true,
allowNull: false,
unique: true
const Room = sequelize.define(
'Room',
{
roomId: {
type: DataTypes.STRING,
primaryKey: true,
allowNull: false,
unique: true,
},
name: {
type: DataTypes.STRING,
allowNull: false,
},
location: {
type: DataTypes.STRING,
allowNull: false,
},
area: {
type: DataTypes.FLOAT,
allowNull: false,
},
capacity: {
type: DataTypes.INTEGER,
allowNull: false,
},
status: {
type: DataTypes.STRING,
defaultValue: 'active',
},
description: {
type: DataTypes.TEXT,
},
},
name: {
type: DataTypes.STRING,
allowNull: false
},
location: {
type: DataTypes.STRING,
allowNull: false
},
area: {
type: DataTypes.FLOAT,
allowNull: false
},
capacity: {
type: DataTypes.INTEGER,
allowNull: false
},
status: {
type: DataTypes.STRING,
defaultValue: 'active'
},
description: {
type: DataTypes.TEXT
{
tableName: 'rooms',
timestamps: true,
indexes: [{ fields: ['status'] }, { fields: ['name'] }],
}
}, {
tableName: 'rooms',
timestamps: true,
indexes: [
{ fields: ['status'] },
{ fields: ['name'] }
]
});
);
module.exports = Room;
module.exports = Room;
+42 -40
View File
@@ -1,47 +1,49 @@
const { DataTypes } = require('sequelize');
const { sequelize } = require('../db');
const SystemSetting = sequelize.define('SystemSetting', {
settingKey: {
type: DataTypes.STRING(100),
primaryKey: true,
allowNull: false,
comment: '设置键名'
const SystemSetting = sequelize.define(
'SystemSetting',
{
settingKey: {
type: DataTypes.STRING(100),
primaryKey: true,
allowNull: false,
comment: '设置键名',
},
settingValue: {
type: DataTypes.TEXT,
allowNull: true,
comment: '设置值(JSON格式)',
},
settingType: {
type: DataTypes.STRING(20),
allowNull: false,
defaultValue: 'string',
comment: '设置类型: string, number, boolean, json, array',
},
category: {
type: DataTypes.STRING(50),
allowNull: false,
defaultValue: 'general',
comment: '设置分类: general, appearance, backup, about',
},
description: {
type: DataTypes.STRING(255),
allowNull: true,
comment: '设置描述',
},
isEditable: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: true,
comment: '是否可编辑',
},
},
settingValue: {
type: DataTypes.TEXT,
allowNull: true,
comment: '设置值(JSON格式)'
},
settingType: {
type: DataTypes.STRING(20),
allowNull: false,
defaultValue: 'string',
comment: '设置类型: string, number, boolean, json, array'
},
category: {
type: DataTypes.STRING(50),
allowNull: false,
defaultValue: 'general',
comment: '设置分类: general, appearance, backup, about'
},
description: {
type: DataTypes.STRING(255),
allowNull: true,
comment: '设置描述'
},
isEditable: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: true,
comment: '是否可编辑'
{
tableName: 'system_settings',
timestamps: true,
indexes: [{ fields: ['category'] }],
}
}, {
tableName: 'system_settings',
timestamps: true,
indexes: [
{ fields: ['category'] }
]
});
);
module.exports = SystemSetting;
+125 -121
View File
@@ -3,129 +3,133 @@ const { sequelize } = require('../db');
const User = require('./User');
const Device = require('./Device');
const Ticket = sequelize.define('Ticket', {
ticketId: {
type: DataTypes.STRING,
primaryKey: true,
allowNull: false,
unique: true
const Ticket = sequelize.define(
'Ticket',
{
ticketId: {
type: DataTypes.STRING,
primaryKey: true,
allowNull: false,
unique: true,
},
title: {
type: DataTypes.STRING,
allowNull: false,
comment: '工单标题',
},
deviceId: {
type: DataTypes.STRING,
allowNull: true,
comment: '关联设备ID',
},
deviceName: {
type: DataTypes.STRING,
allowNull: false,
comment: '设备名称',
},
deviceModel: {
type: DataTypes.STRING,
comment: '设备型号',
},
serialNumber: {
type: DataTypes.STRING,
comment: '设备序列号',
},
faultCategory: {
type: DataTypes.STRING,
allowNull: false,
comment: '故障分类',
},
faultSubCategory: {
type: DataTypes.STRING,
comment: '故障子分类',
},
priority: {
type: DataTypes.STRING,
defaultValue: 'medium',
comment: '优先级: critical/high/medium/low',
},
status: {
type: DataTypes.STRING,
defaultValue: 'pending',
comment: '工单状态: pending/in_progress/completed/closed/cancelled',
},
description: {
type: DataTypes.TEXT,
comment: '故障描述',
},
expectedCompletionDate: {
type: DataTypes.DATE,
comment: '期望完成时间',
},
reporterId: {
type: DataTypes.STRING,
allowNull: false,
comment: '报修人ID',
},
reporterName: {
type: DataTypes.STRING,
allowNull: false,
comment: '报修人姓名',
},
assigneeId: {
type: DataTypes.STRING,
comment: '处理人ID',
},
assigneeName: {
type: DataTypes.STRING,
comment: '处理人姓名',
},
location: {
type: DataTypes.STRING,
comment: '设备位置',
},
resolution: {
type: DataTypes.TEXT,
comment: '解决方案',
},
completionDate: {
type: DataTypes.DATE,
comment: '实际完成时间',
},
evaluation: {
type: DataTypes.TEXT,
comment: '用户评价',
},
evaluationRating: {
type: DataTypes.INTEGER,
comment: '评价星级(1-5)',
},
attachments: {
type: DataTypes.JSON,
defaultValue: [],
comment: '附件列表',
},
tags: {
type: DataTypes.JSON,
defaultValue: [],
comment: '标签',
},
metadata: {
type: DataTypes.JSON,
defaultValue: {},
comment: '扩展字段',
},
},
title: {
type: DataTypes.STRING,
allowNull: false,
comment: '工单标题'
},
deviceId: {
type: DataTypes.STRING,
allowNull: true,
comment: '关联设备ID'
},
deviceName: {
type: DataTypes.STRING,
allowNull: false,
comment: '设备名称'
},
deviceModel: {
type: DataTypes.STRING,
comment: '设备型号'
},
serialNumber: {
type: DataTypes.STRING,
comment: '设备序列号'
},
faultCategory: {
type: DataTypes.STRING,
allowNull: false,
comment: '故障分类'
},
faultSubCategory: {
type: DataTypes.STRING,
comment: '故障子分类'
},
priority: {
type: DataTypes.STRING,
defaultValue: 'medium',
comment: '优先级: critical/high/medium/low'
},
status: {
type: DataTypes.STRING,
defaultValue: 'pending',
comment: '工单状态: pending/in_progress/completed/closed/cancelled'
},
description: {
type: DataTypes.TEXT,
comment: '故障描述'
},
expectedCompletionDate: {
type: DataTypes.DATE,
comment: '期望完成时间'
},
reporterId: {
type: DataTypes.STRING,
allowNull: false,
comment: '报修人ID'
},
reporterName: {
type: DataTypes.STRING,
allowNull: false,
comment: '报修人姓名'
},
assigneeId: {
type: DataTypes.STRING,
comment: '处理人ID'
},
assigneeName: {
type: DataTypes.STRING,
comment: '处理人姓名'
},
location: {
type: DataTypes.STRING,
comment: '设备位置'
},
resolution: {
type: DataTypes.TEXT,
comment: '解决方案'
},
completionDate: {
type: DataTypes.DATE,
comment: '实际完成时间'
},
evaluation: {
type: DataTypes.TEXT,
comment: '用户评价'
},
evaluationRating: {
type: DataTypes.INTEGER,
comment: '评价星级(1-5)'
},
attachments: {
type: DataTypes.JSON,
defaultValue: [],
comment: '附件列表'
},
tags: {
type: DataTypes.JSON,
defaultValue: [],
comment: '标签'
},
metadata: {
type: DataTypes.JSON,
defaultValue: {},
comment: '扩展字段'
{
tableName: 'tickets',
timestamps: true,
indexes: [
{ fields: ['deviceId'] },
{ fields: ['status'] },
{ fields: ['faultCategory'] },
{ fields: ['priority'] },
{ fields: ['reporterId'] },
{ fields: ['assigneeId'] },
{ fields: ['createdAt'] },
],
}
}, {
tableName: 'tickets',
timestamps: true,
indexes: [
{ fields: ['deviceId'] },
{ fields: ['status'] },
{ fields: ['faultCategory'] },
{ fields: ['priority'] },
{ fields: ['reporterId'] },
{ fields: ['assigneeId'] },
{ fields: ['createdAt'] }
]
});
);
Ticket.belongsTo(User, { foreignKey: 'reporterId', as: 'reporter', constraints: false });
Ticket.belongsTo(User, { foreignKey: 'assigneeId', as: 'assignee', constraints: false });
+50 -46
View File
@@ -1,53 +1,57 @@
const { DataTypes } = require('sequelize');
const { sequelize } = require('../db');
const TicketField = sequelize.define('TicketField', {
fieldId: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
allowNull: false
const TicketField = sequelize.define(
'TicketField',
{
fieldId: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
allowNull: false,
},
fieldName: {
type: DataTypes.STRING,
allowNull: false,
unique: true,
},
displayName: {
type: DataTypes.STRING,
allowNull: false,
},
fieldType: {
type: DataTypes.STRING,
allowNull: false,
defaultValue: 'string',
},
required: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false,
},
options: {
type: DataTypes.JSON,
allowNull: true,
},
order: {
type: DataTypes.INTEGER,
allowNull: false,
defaultValue: 0,
},
visible: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: true,
},
placeholder: {
type: DataTypes.STRING,
allowNull: true,
},
},
fieldName: {
type: DataTypes.STRING,
allowNull: false,
unique: true
},
displayName: {
type: DataTypes.STRING,
allowNull: false
},
fieldType: {
type: DataTypes.STRING,
allowNull: false,
defaultValue: 'string'
},
required: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false
},
options: {
type: DataTypes.JSON,
allowNull: true
},
order: {
type: DataTypes.INTEGER,
allowNull: false,
defaultValue: 0
},
visible: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: true
},
placeholder: {
type: DataTypes.STRING,
allowNull: true
{
tableName: 'ticketFields',
timestamps: true,
}
}, {
tableName: 'ticketFields',
timestamps: true
});
);
module.exports = TicketField;
+87 -83
View File
@@ -1,90 +1,94 @@
const { DataTypes } = require('sequelize');
const { sequelize } = require('../db');
const TicketOperationRecord = sequelize.define('TicketOperationRecord', {
recordId: {
type: DataTypes.STRING,
primaryKey: true,
allowNull: false,
unique: true
const TicketOperationRecord = sequelize.define(
'TicketOperationRecord',
{
recordId: {
type: DataTypes.STRING,
primaryKey: true,
allowNull: false,
unique: true,
},
ticketId: {
type: DataTypes.STRING,
allowNull: false,
comment: '关联工单ID',
},
operationType: {
type: DataTypes.STRING,
allowNull: false,
comment: '操作类型: create/update/status_change/assignment/comment/attachment',
},
operationDescription: {
type: DataTypes.TEXT,
comment: '操作描述',
},
operatorId: {
type: DataTypes.STRING,
allowNull: false,
comment: '操作人ID',
},
operatorName: {
type: DataTypes.STRING,
allowNull: false,
comment: '操作人姓名',
},
operatorRole: {
type: DataTypes.STRING,
comment: '操作人角色',
},
operationSteps: {
type: DataTypes.JSON,
defaultValue: [],
comment: '操作步骤详情',
},
spareParts: {
type: DataTypes.JSON,
defaultValue: [],
comment: '使用的备件列表',
},
beforeState: {
type: DataTypes.JSON,
comment: '操作前状态',
},
afterState: {
type: DataTypes.JSON,
comment: '操作后状态',
},
duration: {
type: DataTypes.INTEGER,
comment: '操作耗时(分钟)',
},
result: {
type: DataTypes.STRING,
comment: '操作结果: success/failed/partial',
},
notes: {
type: DataTypes.TEXT,
comment: '备注信息',
},
attachments: {
type: DataTypes.JSON,
defaultValue: [],
comment: '附件',
},
metadata: {
type: DataTypes.JSON,
defaultValue: {},
comment: '扩展字段',
},
},
ticketId: {
type: DataTypes.STRING,
allowNull: false,
comment: '关联工单ID'
},
operationType: {
type: DataTypes.STRING,
allowNull: false,
comment: '操作类型: create/update/status_change/assignment/comment/attachment'
},
operationDescription: {
type: DataTypes.TEXT,
comment: '操作描述'
},
operatorId: {
type: DataTypes.STRING,
allowNull: false,
comment: '操作人ID'
},
operatorName: {
type: DataTypes.STRING,
allowNull: false,
comment: '操作人姓名'
},
operatorRole: {
type: DataTypes.STRING,
comment: '操作人角色'
},
operationSteps: {
type: DataTypes.JSON,
defaultValue: [],
comment: '操作步骤详情'
},
spareParts: {
type: DataTypes.JSON,
defaultValue: [],
comment: '使用的备件列表'
},
beforeState: {
type: DataTypes.JSON,
comment: '操作前状态'
},
afterState: {
type: DataTypes.JSON,
comment: '操作后状态'
},
duration: {
type: DataTypes.INTEGER,
comment: '操作耗时(分钟)'
},
result: {
type: DataTypes.STRING,
comment: '操作结果: success/failed/partial'
},
notes: {
type: DataTypes.TEXT,
comment: '备注信息'
},
attachments: {
type: DataTypes.JSON,
defaultValue: [],
comment: '附件'
},
metadata: {
type: DataTypes.JSON,
defaultValue: {},
comment: '扩展字段'
{
tableName: 'ticket_operation_records',
timestamps: true,
indexes: [
{ fields: ['ticketId'] },
{ fields: ['operatorId'] },
{ fields: ['operationType'] },
{ fields: ['createdAt'] },
],
}
}, {
tableName: 'ticket_operation_records',
timestamps: true,
indexes: [
{ fields: ['ticketId'] },
{ fields: ['operatorId'] },
{ fields: ['operationType'] },
{ fields: ['createdAt'] }
]
});
);
module.exports = TicketOperationRecord;
+61 -61
View File
@@ -1,68 +1,68 @@
const { DataTypes } = require('sequelize');
const { sequelize } = require('../db');
const User = sequelize.define('User', {
userId: {
type: DataTypes.STRING,
primaryKey: true,
allowNull: false
const User = sequelize.define(
'User',
{
userId: {
type: DataTypes.STRING,
primaryKey: true,
allowNull: false,
},
username: {
type: DataTypes.STRING,
allowNull: false,
unique: true,
},
password: {
type: DataTypes.STRING,
allowNull: false,
},
email: {
type: DataTypes.STRING,
allowNull: true,
validate: {
isEmail: true,
},
},
phone: {
type: DataTypes.STRING,
allowNull: true,
},
realName: {
type: DataTypes.STRING,
allowNull: true,
},
avatar: {
type: DataTypes.STRING,
allowNull: true,
},
status: {
type: DataTypes.ENUM('active', 'inactive', 'locked', 'pending'),
defaultValue: 'active',
},
lastLoginTime: {
type: DataTypes.DATE,
allowNull: true,
},
lastLoginIp: {
type: DataTypes.STRING,
allowNull: true,
},
loginCount: {
type: DataTypes.INTEGER,
defaultValue: 0,
},
remark: {
type: DataTypes.TEXT,
allowNull: true,
},
},
username: {
type: DataTypes.STRING,
allowNull: false,
unique: true
},
password: {
type: DataTypes.STRING,
allowNull: false
},
email: {
type: DataTypes.STRING,
allowNull: true,
validate: {
isEmail: true
}
},
phone: {
type: DataTypes.STRING,
allowNull: true
},
realName: {
type: DataTypes.STRING,
allowNull: true
},
avatar: {
type: DataTypes.STRING,
allowNull: true
},
status: {
type: DataTypes.ENUM('active', 'inactive', 'locked', 'pending'),
defaultValue: 'active'
},
lastLoginTime: {
type: DataTypes.DATE,
allowNull: true
},
lastLoginIp: {
type: DataTypes.STRING,
allowNull: true
},
loginCount: {
type: DataTypes.INTEGER,
defaultValue: 0
},
remark: {
type: DataTypes.TEXT,
allowNull: true
{
tableName: 'users',
timestamps: true,
indexes: [{ fields: ['status'] }, { fields: ['username'] }, { fields: ['email'] }],
}
}, {
tableName: 'users',
timestamps: true,
indexes: [
{ fields: ['status'] },
{ fields: ['username'] },
{ fields: ['email'] }
]
});
);
module.exports = User;
+13 -9
View File
@@ -3,16 +3,20 @@ const { sequelize } = require('../db');
const User = require('./User');
const Role = require('./Role');
const UserRole = sequelize.define('UserRole', {
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true
const UserRole = sequelize.define(
'UserRole',
{
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
},
},
{
tableName: 'user_roles',
timestamps: true,
}
}, {
tableName: 'user_roles',
timestamps: true
});
);
UserRole.belongsTo(User, { foreignKey: 'UserId', onDelete: 'CASCADE' });
UserRole.belongsTo(Role, { foreignKey: 'RoleId', onDelete: 'CASCADE' });
+35 -34
View File
@@ -1,41 +1,42 @@
const { DataTypes } = require('sequelize');
const { sequelize } = require('../db');
const Warehouse = sequelize.define('Warehouse', {
warehouseId: {
type: DataTypes.STRING,
primaryKey: true,
allowNull: false,
unique: true
const Warehouse = sequelize.define(
'Warehouse',
{
warehouseId: {
type: DataTypes.STRING,
primaryKey: true,
allowNull: false,
unique: true,
},
name: {
type: DataTypes.STRING,
allowNull: false,
},
location: {
type: DataTypes.STRING,
allowNull: true,
},
capacity: {
type: DataTypes.INTEGER,
allowNull: true,
defaultValue: 100,
},
status: {
type: DataTypes.ENUM('active', 'inactive'),
defaultValue: 'active',
},
description: {
type: DataTypes.TEXT,
allowNull: true,
},
},
name: {
type: DataTypes.STRING,
allowNull: false
},
location: {
type: DataTypes.STRING,
allowNull: true
},
capacity: {
type: DataTypes.INTEGER,
allowNull: true,
defaultValue: 100
},
status: {
type: DataTypes.ENUM('active', 'inactive'),
defaultValue: 'active'
},
description: {
type: DataTypes.TEXT,
allowNull: true
{
tableName: 'warehouses',
timestamps: true,
indexes: [{ fields: ['status'] }, { fields: ['name'] }],
}
}, {
tableName: 'warehouses',
timestamps: true,
indexes: [
{ fields: ['status'] },
{ fields: ['name'] }
]
});
);
module.exports = Warehouse;
+19 -19
View File
@@ -25,7 +25,7 @@ const initDefaultFaultCategories = async () => {
defaultPriority: 'high',
expectedDuration: 4,
solutions: ['重启服务', '回滚版本', '修复配置', '重装系统'],
isSystem: true
isSystem: true,
},
{
categoryId: 'CAT002',
@@ -38,7 +38,7 @@ const initDefaultFaultCategories = async () => {
defaultPriority: 'critical',
expectedDuration: 8,
solutions: ['更换部件', '联系厂商', '现场维修'],
isSystem: true
isSystem: true,
},
{
categoryId: 'CAT003',
@@ -51,7 +51,7 @@ const initDefaultFaultCategories = async () => {
defaultPriority: 'high',
expectedDuration: 2,
solutions: ['检查网线', '重启交换机', '修复配置', '联系运营商'],
isSystem: true
isSystem: true,
},
{
categoryId: 'CAT004',
@@ -64,7 +64,7 @@ const initDefaultFaultCategories = async () => {
defaultPriority: 'medium',
expectedDuration: 6,
solutions: ['修复Bug', '优化性能', '更新版本', '配置调整'],
isSystem: true
isSystem: true,
},
{
categoryId: 'CAT005',
@@ -77,7 +77,7 @@ const initDefaultFaultCategories = async () => {
defaultPriority: 'critical',
expectedDuration: 1,
solutions: ['隔离系统', '调查取证', '修复漏洞', '更新安全策略'],
isSystem: true
isSystem: true,
},
{
categoryId: 'CAT006',
@@ -90,7 +90,7 @@ const initDefaultFaultCategories = async () => {
defaultPriority: 'medium',
expectedDuration: 4,
solutions: ['资源扩容', '优化SQL', '清理缓存', '负载均衡'],
isSystem: true
isSystem: true,
},
{
categoryId: 'CAT007',
@@ -103,7 +103,7 @@ const initDefaultFaultCategories = async () => {
defaultPriority: 'low',
expectedDuration: 2,
solutions: ['调整配置', '参数优化', '功能启用'],
isSystem: true
isSystem: true,
},
{
categoryId: 'CAT008',
@@ -116,7 +116,7 @@ const initDefaultFaultCategories = async () => {
defaultPriority: 'low',
expectedDuration: 4,
solutions: ['系统更新', '安全检查', '日志清理', '硬件检测'],
isSystem: true
isSystem: true,
},
{
categoryId: 'CAT009',
@@ -129,7 +129,7 @@ const initDefaultFaultCategories = async () => {
defaultPriority: 'high',
expectedDuration: 6,
solutions: ['数据恢复', '数据修复', '重新同步', '备份还原'],
isSystem: true
isSystem: true,
},
{
categoryId: 'CAT010',
@@ -142,8 +142,8 @@ const initDefaultFaultCategories = async () => {
defaultPriority: 'critical',
expectedDuration: 2,
solutions: ['切换电源', '更换UPS', '联系供电', '检查线路'],
isSystem: true
}
isSystem: true,
},
];
for (const category of defaultCategories) {
@@ -157,14 +157,14 @@ const initDefaultFaultCategories = async () => {
};
const initAssociations = () => {
Ticket.hasMany(TicketOperationRecord, {
foreignKey: 'ticketId',
as: 'operationRecords',
constraints: false
});
TicketOperationRecord.belongsTo(Ticket, {
Ticket.hasMany(TicketOperationRecord, {
foreignKey: 'ticketId',
constraints: false
as: 'operationRecords',
constraints: false,
});
TicketOperationRecord.belongsTo(Ticket, {
foreignKey: 'ticketId',
constraints: false,
});
};
@@ -185,5 +185,5 @@ module.exports = {
initAssociations,
Ticket,
TicketOperationRecord,
FaultCategory
FaultCategory,
};