From 7909035cf4f4443bd25191760c5971361ca5fdcf Mon Sep 17 00:00:00 2001 From: liufumingren Date: Mon, 27 Jul 2026 04:26:06 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20taskComplete=20=E7=94=A8=20id=20?= =?UTF-8?q?=E7=B2=BE=E5=87=86=E6=9B=B4=E6=96=B0=EF=BC=8C=E9=81=BF=E5=85=8D?= =?UTF-8?q?=20forceRecord=20=E5=B9=B6=E5=8F=91=E8=A6=86=E7=9B=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/service/hikvision.js | 45 +++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/app/service/hikvision.js b/app/service/hikvision.js index 53ff880..34bde42 100644 --- a/app/service/hikvision.js +++ b/app/service/hikvision.js @@ -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',