// app/model/operation_log.js 'use strict'; module.exports = app => { const { STRING, BIGINT, DATE, ENUM, JSON, TEXT } = app.Sequelize; const OperationLog = app.model.define('operation_log', { id: { type: BIGINT(20), primaryKey: true, autoIncrement: true, comment: '主键ID', }, business_type: { type: STRING(50), allowNull: false, comment: '业务类型: product, order, stock, wave, express, storage', }, business_id: { type: STRING(100), allowNull: false, comment: '业务ID', }, operation_code: { type: STRING(50), allowNull: false, comment: '操作编码', }, operator_id: { type: STRING(100), allowNull: true, comment: '操作人ID(用户ID/系统ID)', }, operator_name: { type: STRING(100), allowNull: true, comment: '操作人名称', }, external_log_type: { type: ENUM('REQUEST', 'API', 'QIMEN', 'NONE'), allowNull: false, defaultValue: 'NONE', comment: '外部日志类型', }, external_log_id: { type: BIGINT(20), allowNull: true, comment: '外部日志ID', }, warehouse_id: { type: BIGINT(20).UNSIGNED, allowNull: false, comment: '仓库ID', }, before_changes: { type: JSON, allowNull: true, comment: '变更前数据', }, platform_code: { type: STRING(20), allowNull: true, comment: '操作端', }, created_at: { type: DATE, allowNull: false, defaultValue: app.Sequelize.literal('CURRENT_TIMESTAMP'), comment: '创建时间', }, message: { type: TEXT, allowNull: true, comment: '日志信息', }, }, { tableName: 'wms_operation_log', // 数据库中的实际表名 timestamps: false, // 不使用默认的 createdAt 和 updatedAt comment: 'WMS业务操作日志表', indexes: [ { unique: true, name: 'uk_business_operation', fields: [ 'business_type', 'business_id', 'id' ], }, { name: 'idx_business_type_id_time', fields: [ 'business_type', 'business_id', 'created_at' ], }, { name: 'idx_operation_code_time', fields: [ 'operation_code', 'created_at' ], }, { name: 'idx_operator_time', fields: [ 'operator_id', 'created_at' ], }, { name: 'idx_warehouse_time', fields: [ 'warehouse_id', 'created_at' ], }, { name: 'idx_external_log', fields: [ 'external_log_type', 'external_log_id' ], }, { name: 'idx_created_at', fields: [ 'created_at' ], }, ], }); return OperationLog; };