oms/backend/database/migrations/20260911000500-create-api-outbound-logs.js
liufumingren cbd16752a5 feat(backend): 商品、店铺、组合商品、仓库与库存模块
- 商品/商品图片、店铺、店铺商品、组合商品及明细
- 仓库、仓库商品(WMS itemId 映射)、仓库接口配置与字段定义(warehouseApi/warehouseApiField)
- 库存:stock_items、product_stocks(ZC/CC 双维度)与库存重算工具(utils/recalcStock.js)
- 库存单据与对接日志:stock orders、api_outbound_logs
- 相关迁移:shops/shop_products/stock_orders/warehouses/warehouse_apis/warehouse_products/product_stocks/files-images 等表与字段
2026-09-13 02:23:39 +08:00

57 lines
3.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'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');
},
};