'use strict'; /** * 视频补录请求记录表模型(wms_video_record_request)。 * * 站内信查询打包视频 / 退件拆包视频时发现"视频不可用"(无视频记录或全部 failed), * 登记一条补录请求(状态机 pending → requested → recording → completed / failed), * 同时向录制服务推送强制录制;后续查询命中可用视频时由业务层回写 completed + video_url。 * * @param {import('egg').Application} app Egg 应用实例。 * @return {import('sequelize').ModelCtor} Sequelize 模型。 */ module.exports = app => { const { BIGINT, INTEGER, STRING, DATE, ENUM, TINYINT } = app.Sequelize; const VideoRecordRequest = app.model.define('video_record_request', { id: { type: BIGINT(20).UNSIGNED, primaryKey: true, autoIncrement: true, 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: '触发查询的运单号', }, group_id: { type: STRING(100), allowNull: true, comment: '触发查询的群ID(站内信外部群ID,回信必填)', }, group_name: { type: STRING(100), allowNull: true, comment: '触发查询的群名称', }, user_id: { type: STRING(100), allowNull: true, comment: '触发查询的用户ID(站内信外部用户ID,回信必填)', }, user_name: { type: STRING(100), 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, comment: '创建时间', }, updated_at: { type: DATE, allowNull: false, comment: '更新时间', }, deleted_at: { type: DATE, allowNull: true, comment: '软删除时间', }, }, { tableName: 'wms_video_record_request', comment: '视频补录请求记录表', timestamps: true, createdAt: 'created_at', updatedAt: 'updated_at', paranoid: true, deletedAt: 'deleted_at', indexes: [ { name: 'idx_warehouse_biz', fields: [ 'warehouse_id', 'biz_type', 'biz_id' ] }, { name: 'idx_waybill_code', fields: [ 'waybill_code' ] }, { name: 'idx_status_notified_last_request', fields: [ 'status', 'is_notified', 'last_request_at' ] }, { name: 'idx_deleted_at', fields: [ 'deleted_at' ] }, ], }); return VideoRecordRequest; };