Files
yunrui_asset/backend/models/OperationLog.js
T
zhang1106 73cbe4ac1b feat: 添加操作日志、危险操作确认和业务关联功能
1. 新增操作日志记录功能,记录关键操作
2. 实现危险操作确认对话框,防止误删
3. 添加业务和库房管理模块
4. 支持设备标记为空闲状态
5. 完善API文档和健康检查
6. 优化前端删除操作的确认流程
7. 添加Swagger API文档支持
8. 实现设备与业务的关联功能
9. 改进设备模型,添加空闲相关字段
10. 优化用户、角色管理操作日志
2026-03-20 17:15:14 +08:00

90 lines
2.0 KiB
JavaScript

const { DataTypes } = require('sequelize');
const { sequelize } = require('../db');
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
},
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'] }
]
});
module.exports = OperationLog;