Files
yunrui_asset/backend/models/OperationLog.js
T
zhang1106 ea1a855112 feat: 使用concurrently实现跨平台同时启动前后端
refactor(models): 优化模型初始化逻辑避免重复同步
refactor(OperationLog): 将createdAt索引改为operateTime
docs: 添加一次性启动解决方案文档
2026-01-20 15:19:09 +08:00

90 lines
1.8 KiB
JavaScript

const { DataTypes } = require('sequelize');
const { sequelize } = require('../db');
const OperationLog = sequelize.define('OperationLog', {
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true
},
userId: {
type: DataTypes.STRING,
allowNull: false,
comment: '操作人ID'
},
username: {
type: DataTypes.STRING,
allowNull: false,
comment: '操作人用户名'
},
realName: {
type: DataTypes.STRING,
allowNull: true,
comment: '操作人真实姓名'
},
action: {
type: DataTypes.STRING,
allowNull: false,
comment: '操作类型'
},
module: {
type: DataTypes.STRING,
allowNull: true,
comment: '操作模块'
},
description: {
type: DataTypes.TEXT,
allowNull: true,
comment: '操作描述'
},
targetId: {
type: DataTypes.STRING,
allowNull: true,
comment: '目标对象ID'
},
targetName: {
type: DataTypes.STRING,
allowNull: true,
comment: '目标对象名称'
},
oldValue: {
type: DataTypes.TEXT,
allowNull: true,
comment: '旧值'
},
newValue: {
type: DataTypes.TEXT,
allowNull: true,
comment: '新值'
},
ip: {
type: DataTypes.STRING,
allowNull: true,
comment: '操作IP'
},
status: {
type: DataTypes.ENUM('success', 'failed'),
defaultValue: 'success',
comment: '操作状态'
},
errorMessage: {
type: DataTypes.TEXT,
allowNull: true,
comment: '错误信息'
}
}, {
tableName: 'operation_logs',
timestamps: true,
createdAt: 'operateTime',
updatedAt: false,
indexes: [
{ fields: ['userId'] },
{ fields: ['action'] },
{ fields: ['module'] },
{ fields: ['operateTime'] },
{ fields: ['userId', 'operateTime'] }
]
});
module.exports = OperationLog;