'use strict'; /** * 创建视频补录请求记录表 wms_video_record_request。 * * 背景:站内信查询"打包视频/退件拆包视频"时若视频不可用(无视频记录或全部 failed), * 除回复用户外还需登记一条补录请求并推送录制服务重新录制,本表用于记录请求与状态机。 * * 状态机:pending(待推送) → requested(已推送) → recording(录制中) → completed(已完成) / failed(失败) * * 字段:仓库/货主隔离、业务对象(biz_type=pack/unpack + biz_id)、运单号、状态、推送次数、 * 录制电脑、失败原因、回写视频地址、结果通知标记、备注、软删除 deleted_at(paranoid)。 * * 索引:idx_warehouse_biz(按业务对象查在途请求)、idx_waybill_code(按单号追溯)、 * idx_status(按状态筛选)、idx_deleted_at(软删除优化)。 */ const TABLE_NAME = 'wms_video_record_request'; module.exports = { // eslint-disable-next-line no-unused-vars async up(queryInterface, Sequelize) { const { BIGINT, INTEGER, STRING, DATE, ENUM, TINYINT } = Sequelize; await queryInterface.createTable(TABLE_NAME, { id: { type: BIGINT(20).UNSIGNED, primaryKey: true, autoIncrement: true, allowNull: false, comment: '主键ID', }, warehouse_id: { type: BIGINT(20).UNSIGNED, allowNull: false, comment: '仓库ID', }, store_id: { type: BIGINT(20).UNSIGNED, allowNull: false, defaultValue: 0, comment: '货主ID,0=未知', }, biz_type: { type: ENUM('pack', 'unpack'), allowNull: false, comment: '业务类型:pack-打包视频 unpack-退件拆包视频', }, biz_id: { type: BIGINT(20).UNSIGNED, allowNull: false, comment: '业务ID:pack=wms_pack_task.id,unpack=wms_return_unpack.id', }, waybill_code: { type: STRING(64), allowNull: true, comment: '触发查询的运单号', }, source: { type: STRING(20), allowNull: false, defaultValue: 'inbox', comment: '触发来源:inbox-站内信查询', }, status: { type: ENUM('pending', 'requested', 'recording', 'completed', 'failed'), allowNull: false, defaultValue: 'pending', comment: '状态机:pending-待推送 requested-已推送 recording-录制中 completed-已完成 failed-失败', }, request_count: { type: INTEGER.UNSIGNED, allowNull: false, defaultValue: 0, comment: '推送录制服务次数', }, last_request_at: { type: DATE, allowNull: true, comment: '最近一次请求录制服务时间(含推送失败)', }, print_computer_id: { type: BIGINT(20).UNSIGNED, allowNull: true, comment: '录制电脑ID,关联 wms_print_computer.id', }, request_error: { type: STRING(500), allowNull: true, comment: '推送失败原因(无录制电脑/电脑不在线/打印服务异常)', }, video_url: { type: STRING(500), allowNull: true, comment: '录制完成后回写的视频地址', }, is_notified: { type: TINYINT(1), allowNull: false, defaultValue: 0, comment: '录制结果是否已通知查询方:0=未通知,1=已通知', }, notified_at: { type: DATE, allowNull: true, comment: '录制结果通知时间', }, remark: { type: STRING(500), allowNull: true, comment: '备注', }, created_at: { type: DATE, allowNull: false }, updated_at: { type: DATE, allowNull: false }, deleted_at: { type: DATE, allowNull: true, comment: '软删除时间' }, }); await queryInterface.addIndex(TABLE_NAME, [ 'warehouse_id', 'biz_type', 'biz_id' ], { name: 'idx_warehouse_biz' }); await queryInterface.addIndex(TABLE_NAME, [ 'waybill_code' ], { name: 'idx_waybill_code' }); await queryInterface.addIndex(TABLE_NAME, [ 'status' ], { name: 'idx_status' }); await queryInterface.addIndex(TABLE_NAME, [ 'deleted_at' ], { name: 'idx_deleted_at' }); }, // eslint-disable-next-line no-unused-vars async down(queryInterface, Sequelize) { await queryInterface.dropTable(TABLE_NAME); }, };