WMS_MAIN/database/migrations/20260910100000-create-wms-video-record-request.js
liufumingren 839d4e2d7f feat(video): 视频补录请求状态收敛与结果通知拆分
1) 新增 wms_video_record_request 模型与迁移(群/人员信息列、状态+通知扫描索引);索引调整为 (status,is_notified,last_request_at) 并移除单列 idx_status。

2) systems/video_record_request.js:settleStatuses 只收敛状态(可用/全部失败/超时/参数缺失),notifyResults 只做结果通知;成功结果按原查询链路(queryPackVideo/queryReturn)取回并回原群,失败/超时回原群并转人工通知(仓库群客服群,未命中不外发)。

3) schedule/notify_video_record_result.js:每 1 分钟串行执行「状态收敛 → 结果通知」,带重入锁,仅在有变化时打日志。

4) inbox/functions.js:查询打包/拆包视频时同步补录请求状态(有视频置 completed),无可用视频时登记补录请求并推送录制服务。

5) config.inbox 新增 videoRecordNotifyLimit / videoRecordNotifyTimeoutMs。
2026-09-11 02:49:27 +08:00

128 lines
4.4 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';
/**
* 创建视频补录请求记录表 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);
},
};