84 lines
1.7 KiB
JavaScript
84 lines
1.7 KiB
JavaScript
|
|
const { DataTypes } = require('sequelize');
|
||
|
|
const sequelize = require('../config/db');
|
||
|
|
|
||
|
|
const OperationLog = sequelize.define('OperationLog', {
|
||
|
|
id: {
|
||
|
|
type: DataTypes.INTEGER,
|
||
|
|
primaryKey: true,
|
||
|
|
autoIncrement: true,
|
||
|
|
comment: '日志ID'
|
||
|
|
},
|
||
|
|
userId: {
|
||
|
|
type: DataTypes.INTEGER,
|
||
|
|
allowNull: true,
|
||
|
|
comment: '操作用户ID'
|
||
|
|
},
|
||
|
|
username: {
|
||
|
|
type: DataTypes.STRING(50),
|
||
|
|
allowNull: true,
|
||
|
|
comment: '操作用户名'
|
||
|
|
},
|
||
|
|
module: {
|
||
|
|
type: DataTypes.STRING(50),
|
||
|
|
allowNull: false,
|
||
|
|
comment: '操作模块'
|
||
|
|
},
|
||
|
|
action: {
|
||
|
|
type: DataTypes.STRING(50),
|
||
|
|
allowNull: false,
|
||
|
|
comment: '操作类型'
|
||
|
|
},
|
||
|
|
description: {
|
||
|
|
type: DataTypes.TEXT,
|
||
|
|
allowNull: true,
|
||
|
|
comment: '操作描述'
|
||
|
|
},
|
||
|
|
method: {
|
||
|
|
type: DataTypes.STRING(10),
|
||
|
|
allowNull: true,
|
||
|
|
comment: '请求方法'
|
||
|
|
},
|
||
|
|
url: {
|
||
|
|
type: DataTypes.STRING(500),
|
||
|
|
allowNull: true,
|
||
|
|
comment: '请求URL'
|
||
|
|
},
|
||
|
|
ip: {
|
||
|
|
type: DataTypes.STRING(50),
|
||
|
|
allowNull: true,
|
||
|
|
comment: 'IP地址'
|
||
|
|
},
|
||
|
|
params: {
|
||
|
|
type: DataTypes.TEXT,
|
||
|
|
allowNull: true,
|
||
|
|
comment: '请求参数'
|
||
|
|
},
|
||
|
|
result: {
|
||
|
|
type: DataTypes.TEXT,
|
||
|
|
allowNull: true,
|
||
|
|
comment: '操作结果'
|
||
|
|
},
|
||
|
|
status: {
|
||
|
|
type: DataTypes.ENUM('success', 'fail'),
|
||
|
|
allowNull: false,
|
||
|
|
defaultValue: 'success',
|
||
|
|
comment: '操作状态'
|
||
|
|
},
|
||
|
|
duration: {
|
||
|
|
type: DataTypes.INTEGER,
|
||
|
|
allowNull: true,
|
||
|
|
comment: '执行时长(毫秒)'
|
||
|
|
},
|
||
|
|
createTime: {
|
||
|
|
type: DataTypes.DATE,
|
||
|
|
defaultValue: DataTypes.NOW,
|
||
|
|
comment: '创建时间'
|
||
|
|
}
|
||
|
|
}, {
|
||
|
|
tableName: 'operation_logs',
|
||
|
|
timestamps: false,
|
||
|
|
comment: '操作日志表'
|
||
|
|
});
|
||
|
|
|
||
|
|
module.exports = OperationLog;
|