'use strict'; module.exports = app => { const { BIGINT, STRING, DATE, INTEGER, JSON: JSON_TYPE } = app.Sequelize; const NotificationSendLog = app.model.define('notification_send_log', { id: { type: BIGINT.UNSIGNED, primaryKey: true, autoIncrement: true, allowNull: false, comment: '主键ID', }, trace_id: { type: STRING(100), allowNull: false, comment: '通知追踪ID', }, webhook_id: { type: BIGINT.UNSIGNED, allowNull: true, comment: 'Webhook 配置ID', }, store_id: { type: BIGINT.UNSIGNED, allowNull: true, comment: '触发主体ID', }, warehouse_id: { type: BIGINT.UNSIGNED, allowNull: true, comment: '仓库ID', }, owner_store_id: { type: BIGINT.UNSIGNED, allowNull: true, comment: '货主ID', }, business_name: { type: STRING(100), allowNull: false, comment: '业务名称', }, event: { type: STRING(100), allowNull: false, comment: '事件名', }, hook_type: { type: STRING(50), allowNull: true, comment: 'Webhook 类型', }, hook_url: { type: STRING(500), allowNull: true, comment: 'Webhook 地址', }, request_payload: { type: JSON_TYPE, allowNull: true, comment: '请求载荷', }, response_payload: { type: JSON_TYPE, allowNull: true, comment: '返回载荷', }, http_status: { type: INTEGER(11), allowNull: true, comment: 'HTTP 状态码', }, status: { type: STRING(20), allowNull: false, defaultValue: 'failed', comment: '发送状态', }, error_message: { type: STRING(1000), allowNull: true, comment: '失败原因', }, retry_count: { type: INTEGER(11), allowNull: false, defaultValue: 0, comment: '重试次数', }, created_by: { type: BIGINT.UNSIGNED, allowNull: true, comment: '创建人', }, created_at: { type: DATE, allowNull: false, defaultValue: app.Sequelize.literal('CURRENT_TIMESTAMP'), comment: '创建时间', }, }, { tableName: 'wms_notification_send_log', freezeTableName: true, underscored: true, timestamps: false, comment: '统一通知发送失败日志表', indexes: [ { name: 'idx_notification_send_log_trace_id', fields: [ 'trace_id' ], }, { name: 'idx_notification_send_log_event_status', fields: [ 'event', 'status' ], }, { name: 'idx_notification_send_log_webhook_id', fields: [ 'webhook_id' ], }, { name: 'idx_notification_send_log_created_at', fields: [ 'created_at' ], }, ], }); return NotificationSendLog; };