完善保险端前后端
This commit is contained in:
@@ -0,0 +1,146 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
up: async (queryInterface, Sequelize) => {
|
||||
await queryInterface.createTable('operation_logs', {
|
||||
id: {
|
||||
type: Sequelize.INTEGER,
|
||||
autoIncrement: true,
|
||||
primaryKey: true
|
||||
},
|
||||
user_id: {
|
||||
type: Sequelize.INTEGER,
|
||||
allowNull: false,
|
||||
references: {
|
||||
model: 'users',
|
||||
key: 'id'
|
||||
},
|
||||
onUpdate: 'CASCADE',
|
||||
onDelete: 'CASCADE'
|
||||
},
|
||||
operation_type: {
|
||||
type: Sequelize.ENUM(
|
||||
'login', // 登录
|
||||
'logout', // 登出
|
||||
'create', // 创建
|
||||
'update', // 更新
|
||||
'delete', // 删除
|
||||
'view', // 查看
|
||||
'export', // 导出
|
||||
'import', // 导入
|
||||
'approve', // 审批
|
||||
'reject', // 拒绝
|
||||
'system_config', // 系统配置
|
||||
'user_manage', // 用户管理
|
||||
'role_manage', // 角色管理
|
||||
'other' // 其他
|
||||
),
|
||||
allowNull: false,
|
||||
comment: '操作类型'
|
||||
},
|
||||
operation_module: {
|
||||
type: Sequelize.STRING(50),
|
||||
allowNull: false,
|
||||
comment: '操作模块(如:用户管理、设备管理、预警管理等)'
|
||||
},
|
||||
operation_content: {
|
||||
type: Sequelize.TEXT,
|
||||
allowNull: false,
|
||||
comment: '操作内容描述'
|
||||
},
|
||||
operation_target: {
|
||||
type: Sequelize.STRING(100),
|
||||
allowNull: true,
|
||||
comment: '操作目标(如:用户ID、设备ID等)'
|
||||
},
|
||||
request_method: {
|
||||
type: Sequelize.ENUM('GET', 'POST', 'PUT', 'DELETE', 'PATCH'),
|
||||
allowNull: true,
|
||||
comment: 'HTTP请求方法'
|
||||
},
|
||||
request_url: {
|
||||
type: Sequelize.STRING(500),
|
||||
allowNull: true,
|
||||
comment: '请求URL'
|
||||
},
|
||||
request_params: {
|
||||
type: Sequelize.TEXT,
|
||||
allowNull: true,
|
||||
comment: '请求参数(JSON格式)'
|
||||
},
|
||||
response_status: {
|
||||
type: Sequelize.INTEGER,
|
||||
allowNull: true,
|
||||
comment: '响应状态码'
|
||||
},
|
||||
ip_address: {
|
||||
type: Sequelize.STRING(45),
|
||||
allowNull: true,
|
||||
comment: 'IP地址(支持IPv6)'
|
||||
},
|
||||
user_agent: {
|
||||
type: Sequelize.TEXT,
|
||||
allowNull: true,
|
||||
comment: '用户代理信息'
|
||||
},
|
||||
execution_time: {
|
||||
type: Sequelize.INTEGER,
|
||||
allowNull: true,
|
||||
comment: '执行时间(毫秒)'
|
||||
},
|
||||
status: {
|
||||
type: Sequelize.ENUM('success', 'failed', 'error'),
|
||||
defaultValue: 'success',
|
||||
comment: '操作状态'
|
||||
},
|
||||
error_message: {
|
||||
type: Sequelize.TEXT,
|
||||
allowNull: true,
|
||||
comment: '错误信息'
|
||||
},
|
||||
created_at: {
|
||||
type: Sequelize.DATE,
|
||||
allowNull: false,
|
||||
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP')
|
||||
},
|
||||
updated_at: {
|
||||
type: Sequelize.DATE,
|
||||
allowNull: false,
|
||||
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP')
|
||||
}
|
||||
}, {
|
||||
charset: 'utf8mb4',
|
||||
collate: 'utf8mb4_unicode_ci',
|
||||
comment: '系统操作日志表'
|
||||
});
|
||||
|
||||
// 创建索引
|
||||
await queryInterface.addIndex('operation_logs', ['user_id'], {
|
||||
name: 'idx_operation_logs_user_id'
|
||||
});
|
||||
|
||||
await queryInterface.addIndex('operation_logs', ['operation_type'], {
|
||||
name: 'idx_operation_logs_operation_type'
|
||||
});
|
||||
|
||||
await queryInterface.addIndex('operation_logs', ['operation_module'], {
|
||||
name: 'idx_operation_logs_operation_module'
|
||||
});
|
||||
|
||||
await queryInterface.addIndex('operation_logs', ['created_at'], {
|
||||
name: 'idx_operation_logs_created_at'
|
||||
});
|
||||
|
||||
await queryInterface.addIndex('operation_logs', ['status'], {
|
||||
name: 'idx_operation_logs_status'
|
||||
});
|
||||
|
||||
await queryInterface.addIndex('operation_logs', ['ip_address'], {
|
||||
name: 'idx_operation_logs_ip_address'
|
||||
});
|
||||
},
|
||||
|
||||
down: async (queryInterface, Sequelize) => {
|
||||
await queryInterface.dropTable('operation_logs');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,190 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
up: async (queryInterface, Sequelize) => {
|
||||
// 创建设备表
|
||||
await queryInterface.createTable('devices', {
|
||||
id: {
|
||||
type: Sequelize.INTEGER,
|
||||
primaryKey: true,
|
||||
autoIncrement: true,
|
||||
comment: '设备ID'
|
||||
},
|
||||
device_code: {
|
||||
type: Sequelize.STRING(50),
|
||||
allowNull: false,
|
||||
unique: true,
|
||||
comment: '设备编号'
|
||||
},
|
||||
device_name: {
|
||||
type: Sequelize.STRING(100),
|
||||
allowNull: false,
|
||||
comment: '设备名称'
|
||||
},
|
||||
device_type: {
|
||||
type: Sequelize.STRING(50),
|
||||
allowNull: false,
|
||||
comment: '设备类型'
|
||||
},
|
||||
device_model: {
|
||||
type: Sequelize.STRING(100),
|
||||
comment: '设备型号'
|
||||
},
|
||||
manufacturer: {
|
||||
type: Sequelize.STRING(100),
|
||||
comment: '制造商'
|
||||
},
|
||||
installation_location: {
|
||||
type: Sequelize.STRING(200),
|
||||
comment: '安装位置'
|
||||
},
|
||||
installation_date: {
|
||||
type: Sequelize.DATE,
|
||||
comment: '安装日期'
|
||||
},
|
||||
status: {
|
||||
type: Sequelize.ENUM('normal', 'warning', 'error', 'offline'),
|
||||
defaultValue: 'normal',
|
||||
comment: '设备状态'
|
||||
},
|
||||
farm_id: {
|
||||
type: Sequelize.INTEGER,
|
||||
comment: '所属养殖场ID'
|
||||
},
|
||||
pen_id: {
|
||||
type: Sequelize.INTEGER,
|
||||
comment: '所属栏舍ID'
|
||||
},
|
||||
created_by: {
|
||||
type: Sequelize.INTEGER,
|
||||
comment: '创建人ID'
|
||||
},
|
||||
updated_by: {
|
||||
type: Sequelize.INTEGER,
|
||||
comment: '更新人ID'
|
||||
},
|
||||
created_at: {
|
||||
type: Sequelize.DATE,
|
||||
defaultValue: Sequelize.NOW,
|
||||
comment: '创建时间'
|
||||
},
|
||||
updated_at: {
|
||||
type: Sequelize.DATE,
|
||||
defaultValue: Sequelize.NOW,
|
||||
comment: '更新时间'
|
||||
}
|
||||
}, {
|
||||
comment: '设备信息表'
|
||||
});
|
||||
|
||||
// 创建设备预警表
|
||||
await queryInterface.createTable('device_alerts', {
|
||||
id: {
|
||||
type: Sequelize.INTEGER,
|
||||
primaryKey: true,
|
||||
autoIncrement: true,
|
||||
comment: '预警ID'
|
||||
},
|
||||
device_id: {
|
||||
type: Sequelize.INTEGER,
|
||||
allowNull: false,
|
||||
comment: '设备ID',
|
||||
references: {
|
||||
model: 'devices',
|
||||
key: 'id'
|
||||
},
|
||||
onUpdate: 'CASCADE',
|
||||
onDelete: 'CASCADE'
|
||||
},
|
||||
alert_type: {
|
||||
type: Sequelize.STRING(50),
|
||||
allowNull: false,
|
||||
comment: '预警类型'
|
||||
},
|
||||
alert_level: {
|
||||
type: Sequelize.ENUM('low', 'medium', 'high', 'critical'),
|
||||
allowNull: false,
|
||||
comment: '预警级别'
|
||||
},
|
||||
alert_title: {
|
||||
type: Sequelize.STRING(200),
|
||||
allowNull: false,
|
||||
comment: '预警标题'
|
||||
},
|
||||
alert_content: {
|
||||
type: Sequelize.TEXT,
|
||||
comment: '预警内容'
|
||||
},
|
||||
alert_time: {
|
||||
type: Sequelize.DATE,
|
||||
allowNull: false,
|
||||
defaultValue: Sequelize.NOW,
|
||||
comment: '预警时间'
|
||||
},
|
||||
status: {
|
||||
type: Sequelize.ENUM('pending', 'processing', 'resolved', 'ignored'),
|
||||
defaultValue: 'pending',
|
||||
comment: '处理状态'
|
||||
},
|
||||
handler_id: {
|
||||
type: Sequelize.INTEGER,
|
||||
comment: '处理人ID',
|
||||
references: {
|
||||
model: 'users',
|
||||
key: 'id'
|
||||
},
|
||||
onUpdate: 'CASCADE',
|
||||
onDelete: 'SET NULL'
|
||||
},
|
||||
handle_time: {
|
||||
type: Sequelize.DATE,
|
||||
comment: '处理时间'
|
||||
},
|
||||
handle_remark: {
|
||||
type: Sequelize.TEXT,
|
||||
comment: '处理备注'
|
||||
},
|
||||
farm_id: {
|
||||
type: Sequelize.INTEGER,
|
||||
comment: '所属养殖场ID'
|
||||
},
|
||||
pen_id: {
|
||||
type: Sequelize.INTEGER,
|
||||
comment: '所属栏舍ID'
|
||||
},
|
||||
is_read: {
|
||||
type: Sequelize.BOOLEAN,
|
||||
defaultValue: false,
|
||||
comment: '是否已读'
|
||||
},
|
||||
read_time: {
|
||||
type: Sequelize.DATE,
|
||||
comment: '阅读时间'
|
||||
},
|
||||
created_at: {
|
||||
type: Sequelize.DATE,
|
||||
defaultValue: Sequelize.NOW,
|
||||
comment: '创建时间'
|
||||
},
|
||||
updated_at: {
|
||||
type: Sequelize.DATE,
|
||||
defaultValue: Sequelize.NOW,
|
||||
comment: '更新时间'
|
||||
}
|
||||
}, {
|
||||
comment: '设备预警表'
|
||||
});
|
||||
|
||||
// 添加索引
|
||||
await queryInterface.addIndex('device_alerts', ['device_id']);
|
||||
await queryInterface.addIndex('device_alerts', ['alert_level']);
|
||||
await queryInterface.addIndex('device_alerts', ['status']);
|
||||
await queryInterface.addIndex('device_alerts', ['alert_time']);
|
||||
await queryInterface.addIndex('device_alerts', ['farm_id']);
|
||||
},
|
||||
|
||||
down: async (queryInterface, Sequelize) => {
|
||||
await queryInterface.dropTable('device_alerts');
|
||||
await queryInterface.dropTable('devices');
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user