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,