From ec67245b2c23a0ec428f1463d0fc43c379ddd495 Mon Sep 17 00:00:00 2001 From: liufumingren Date: Mon, 27 Jul 2026 04:50:23 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20start=5Ftime=20=E5=87=8F5=E7=A7=92=20end?= =?UTF-8?q?=5Ftime=20=E4=B8=8D=E5=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/service/hikvision.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/app/service/hikvision.js b/app/service/hikvision.js index ec5f9e0..1515ab0 100644 --- a/app/service/hikvision.js +++ b/app/service/hikvision.js @@ -10,15 +10,14 @@ const BaseService = require('./base'); class HikvisionService extends BaseService { /** * 将 MySQL DATETIME(存储为 UTC)转为 ISO 8601 北京时间 (+08:00) - * DB 存: "2026-07-26 11:08:19" (UTC) → 输出: "2026-07-26T19:08:19+08:00" + * @param {string} datetime - DB 时间 + * @param {number} offsetMs - 额外偏移(ms),负数=提前 */ - _toISO(datetime) { + _toISO(datetime, offsetMs = 0) { if (!datetime) return null; const str = String(datetime).trim(); - // 按 UTC 解析 const utc = new Date(str + 'Z'); - // 转为北京时间,往前 5 秒覆盖扫描操作 - const cst = new Date(utc.getTime() + 8 * 3600000 - 5000); + const cst = new Date(utc.getTime() + 8 * 3600000 + offsetMs); return cst.toISOString().replace('Z', '+08:00'); } @@ -120,7 +119,7 @@ class HikvisionService extends BaseService { wave_no: task.wave_no, waybill_code: task.waybill_code, task_status: task.task_status, - start_time: this._toISO(task.start_time), + start_time: this._toISO(task.start_time, -5000), end_time: this._toISO(task.end_time), operator: task.operator_text, camera: { @@ -368,7 +367,7 @@ class HikvisionService extends BaseService { workbench_id: task.workbench_id, wave_no: task.wave_no, waybill_code: task.waybill_code, - start_time: this._toISO(task.start_time), + start_time: this._toISO(task.start_time, -5000), end_time: this._toISO(task.end_time), camera: { id: matchedCamera.id,