fix: taskComplete 用 id 精准更新,避免 forceRecord 并发覆盖

This commit is contained in:
liufumingren 2026-07-27 04:26:06 +08:00
parent 788dfa0973
commit 7909035cf4

View File

@ -230,28 +230,39 @@ class HikvisionService extends BaseService {
}
if (success && status === 'completed') {
// 录像成功
await app.mysql.get('wms').update('wms_pack_task_video',
{
video_url: fileUrl || output || '',
status: 'completed',
remark: `大小:${(size / 1024 / 1024).toFixed(2)}MB, 时长:${duration}s, 倍速:${speed}x`,
},
{ where: { pack_task_id: packTaskId, deleted_at: null } }
);
// 取最新的录像记录 ID 精准更新,避免 forceRecord 并发覆盖
const [latestVideo] = await app.mysql.get('wms').select('wms_pack_task_video', {
where: { pack_task_id: packTaskId, deleted_at: null },
orders: [['id', 'desc']],
limit: 1,
});
if (latestVideo) {
await app.mysql.get('wms').update('wms_pack_task_video',
{
video_url: fileUrl || output || '',
status: 'completed',
remark: `大小:${(size / 1024 / 1024).toFixed(2)}MB, 时长:${duration}s, 倍速:${speed}x`,
},
{ where: { id: latestVideo.id } }
);
}
console.log(`[Hikvision] 录像完成: pack_task=${packTaskId}, url=${fileUrl}, size=${size}`);
return this.successResponse('hikvision.taskComplete',
{ packTaskId, status: 'completed' }, '录像完成');
} else {
// 录像失败
await app.mysql.get('wms').update('wms_pack_task_video',
{
status: 'failed',
remark: errorMsg || '录像失败',
},
{ where: { pack_task_id: packTaskId, deleted_at: null } }
);
// 录像失败 - 同样精准更新最新记录
const [latestVideo] = await app.mysql.get('wms').select('wms_pack_task_video', {
where: { pack_task_id: packTaskId, deleted_at: null },
orders: [['id', 'desc']],
limit: 1,
});
if (latestVideo) {
await app.mysql.get('wms').update('wms_pack_task_video',
{ status: 'failed', remark: errorMsg || '录像失败' },
{ where: { id: latestVideo.id } }
);
}
console.log(`[Hikvision] 录像失败: pack_task=${packTaskId}, error=${errorMsg}`);
return this.successResponse('hikvision.taskComplete',