'use strict'; /** * 对外 API 请求记录表(OMS → 外部 WMS 的调用,如 index.ping / singleitem.synchronize) * 与入站 request_logs 区分,用于排查推送失败、鉴权异常、地址不可达等问题 */ module.exports = { async up(queryInterface, Sequelize) { await queryInterface.createTable( 'api_outbound_logs', { id: { type: Sequelize.BIGINT.UNSIGNED, allowNull: false, autoIncrement: true, primaryKey: true, }, principal_id: { type: Sequelize.BIGINT.UNSIGNED, allowNull: true, comment: '所属主体ID' }, warehouse_id: { type: Sequelize.BIGINT.UNSIGNED, allowNull: true, comment: '关联仓库ID' }, warehouse_api_id: { type: Sequelize.BIGINT.UNSIGNED, allowNull: true, comment: '使用的接口配置ID' }, api_type: { type: Sequelize.STRING(50), defaultValue: 'qimen', comment: '接口类型(类奇门JSON接口等)' }, method: { type: Sequelize.STRING(100), allowNull: false, comment: 'WMS 方法名,如 index.ping / singleitem.synchronize' }, url: { type: Sequelize.TEXT, allowNull: true, comment: '完整请求地址(含 query,sign 已脱敏)' }, request_headers: { type: Sequelize.TEXT, allowNull: true, comment: '请求头 JSON' }, request_body: { type: Sequelize.TEXT, allowNull: true, comment: '请求报文 JSON(敏感字段已脱敏)' }, response_status: { type: Sequelize.INTEGER, allowNull: true, comment: 'HTTP 状态码' }, response_body: { type: Sequelize.TEXT, allowNull: true, comment: '响应报文(超长截断)' }, is_success: { type: Sequelize.TINYINT, defaultValue: 0, comment: '传输层是否成功(HTTP 2xx 且可解析)' }, business_code: { type: Sequelize.STRING(32), allowNull: true, comment: 'WMS 业务码' }, business_message: { type: Sequelize.STRING(255), allowNull: true, comment: 'WMS 业务提示' }, error: { type: Sequelize.TEXT, allowNull: true, comment: '异常信息(网络/DNS/超时/非JSON等)' }, duration: { type: Sequelize.INTEGER, 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: '对外API请求记录表' } ); await queryInterface.addIndex('api_outbound_logs', { fields: [ 'principal_id' ], name: 'idx_oblog_principal' }); await queryInterface.addIndex('api_outbound_logs', { fields: [ 'warehouse_id' ], name: 'idx_oblog_warehouse' }); await queryInterface.addIndex('api_outbound_logs', { fields: [ 'warehouse_api_id' ], name: 'idx_oblog_api' }); await queryInterface.addIndex('api_outbound_logs', { fields: [ 'created_at' ], name: 'idx_oblog_created' }); }, async down(queryInterface) { await queryInterface.dropTable('api_outbound_logs'); }, };