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