WMS_MAIN/app/model/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

156 lines
4.5 KiB
JavaScript
Raw Permalink 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),
* 同时向录制服务推送强制录制;后续查询命中可用视频时由业务层回写 completed + video_url。
*
* @param {import('egg').Application} app Egg 应用实例。
* @return {import('sequelize').ModelCtor<import('sequelize').Model>} 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;
};