555 lines
24 KiB
JavaScript
555 lines
24 KiB
JavaScript
const BaseService = require('./base');
|
||
|
||
/**
|
||
* 海康录像任务服务
|
||
* 客户端通过 WebSocket 调用:
|
||
* hikvision.fetchTasks - 拉取待录像的打包任务
|
||
* hikvision.receiveTask - 确认接收任务,更新状态为 recording
|
||
* hikvision.taskComplete - 任务完成回调,写入结果
|
||
*/
|
||
class HikvisionService extends BaseService {
|
||
/**
|
||
* 将 MySQL DATETIME(存储为 UTC)转为 ISO 8601 北京时间 (+08:00)
|
||
* @param {string} datetime - DB 时间
|
||
* @param {number} offsetMs - 额外偏移(ms),负数=提前
|
||
*/
|
||
_toISO(datetime, offsetMs = 0) {
|
||
if (!datetime) return null;
|
||
const str = String(datetime).trim();
|
||
const utc = new Date(str + 'Z');
|
||
const cst = new Date(utc.getTime() + 8 * 3600000 + offsetMs);
|
||
return cst.toISOString().replace('Z', '+08:00');
|
||
}
|
||
|
||
/**
|
||
* 获取任务类型配置(打包/拆包共用)
|
||
* @param {string} taskType - 'pack' | 'unpack'
|
||
*/
|
||
_getTaskCfg(taskType) {
|
||
if (taskType === 'unpack') {
|
||
return {
|
||
taskType: 'unpack',
|
||
taskTable: 'wms_return_unpack',
|
||
videoTable: 'wms_return_unpack_video',
|
||
fkColumn: 'unpack_id',
|
||
cameraIdsField: 'camera_ids',
|
||
codePrefix: 'unpack_',
|
||
workbenchMatch: false,
|
||
buildFields: (task, cameraId) => ({
|
||
task_type: 'unpack',
|
||
unpack_id: task.id,
|
||
device_id: cameraId,
|
||
order_id: task.order_id,
|
||
warehouse_id: task.warehouse_id,
|
||
unpack_no: task.unpack_no,
|
||
waybill_code: task.waybill_code,
|
||
}),
|
||
};
|
||
}
|
||
return {
|
||
taskType: 'pack',
|
||
taskTable: 'wms_pack_task',
|
||
videoTable: 'wms_pack_task_video',
|
||
fkColumn: 'pack_task_id',
|
||
cameraIdsField: 'device_ids',
|
||
codePrefix: '',
|
||
workbenchMatch: true,
|
||
buildFields: (task, cameraId) => ({
|
||
task_type: 'pack',
|
||
pack_task_id: task.id,
|
||
device_id: cameraId,
|
||
order_id: task.order_id,
|
||
warehouse_id: task.warehouse_id,
|
||
workbench_id: task.workbench_id,
|
||
wave_no: task.wave_no,
|
||
waybill_code: task.waybill_code,
|
||
}),
|
||
};
|
||
}
|
||
|
||
/**
|
||
* 组装录像任务落参,并在事务内创建录像占位记录(防止并发重复)
|
||
* @param {Object} task 任务行(wms_pack_task 或 wms_return_unpack)
|
||
* @param {Object} cfg 任务类型配置
|
||
* - videoTable: 录像表名
|
||
* - fkColumn: 外键列名(pack_task_id / unpack_id)
|
||
* - cameraIdsField: 摄像头ID字段名(device_ids / camera_ids)
|
||
* - codePrefix: uniqueCode 前缀(打包为空,拆包为 unpack_)
|
||
* - workbenchMatch: 是否启用工作台名匹配摄像头
|
||
* - buildFields: (task, cameraId) => 落参基础字段
|
||
* - cameras / servers: 仓库摄像头与服务器列表
|
||
* @returns {Promise<Object[]>} 落参数组
|
||
*/
|
||
async _collectVideoItems(task, cfg) {
|
||
const { app } = this;
|
||
|
||
let cameraIds = [];
|
||
try {
|
||
cameraIds = typeof task[cfg.cameraIdsField] === 'string'
|
||
? JSON.parse(task[cfg.cameraIdsField])
|
||
: (task[cfg.cameraIdsField] || []);
|
||
} catch (e) {
|
||
cameraIds = [];
|
||
}
|
||
|
||
const items = [];
|
||
// 事务:原子化检查+插入,防止并发重复
|
||
const conn = await app.mysql.get('wms').beginTransaction();
|
||
try {
|
||
for (const cameraId of cameraIds) {
|
||
// 按设备ID匹配摄像头
|
||
let matchedCamera = cfg.cameras.find(c => c.id === cameraId);
|
||
if (!matchedCamera && cfg.workbenchMatch && task.workbench_id) {
|
||
matchedCamera = cfg.cameras.find(
|
||
c => c.custom_name && c.custom_name.includes(`${task.workbench_id}号`)
|
||
);
|
||
}
|
||
if (!matchedCamera) matchedCamera = cfg.cameras[0];
|
||
if (!matchedCamera) continue;
|
||
|
||
const matchedServer = cfg.servers.find(s => s.id === matchedCamera.server_id) || cfg.servers[0];
|
||
if (!matchedServer) continue;
|
||
|
||
// 事务内 SELECT ... FOR UPDATE 锁定检查,防止并发重复
|
||
const [existing] = await conn.query(
|
||
`SELECT id FROM ${cfg.videoTable}
|
||
WHERE ${cfg.fkColumn} = ? AND camera_id = ? AND deleted_at IS NULL
|
||
FOR UPDATE`,
|
||
[task.id, matchedCamera.id]
|
||
);
|
||
if (!existing || existing.length === 0) {
|
||
await conn.insert(cfg.videoTable, {
|
||
[cfg.fkColumn]: task.id,
|
||
camera_id: matchedCamera.id,
|
||
video_url: '',
|
||
status: 'created',
|
||
created_at: app.mysql.literals.now,
|
||
updated_at: app.mysql.literals.now,
|
||
});
|
||
console.log(`[Hikvision] 创建录像记录: ${cfg.videoTable}=${task.id}, camera=${matchedCamera.id}`);
|
||
}
|
||
|
||
items.push({
|
||
...cfg.buildFields(task, cameraId),
|
||
uniqueCode: `${cfg.codePrefix}${task.id}_${cameraId}`,
|
||
task_status: task.task_status,
|
||
start_time: this._toISO(task.start_time, -5000),
|
||
end_time: this._toISO(task.end_time),
|
||
operator: task.operator_text,
|
||
camera: {
|
||
id: matchedCamera.id,
|
||
channel_id: matchedCamera.channel_id,
|
||
channel_name: matchedCamera.channel_name,
|
||
ip: matchedCamera.ip,
|
||
port: matchedCamera.port,
|
||
model: matchedCamera.model,
|
||
custom_name: matchedCamera.custom_name,
|
||
},
|
||
server: {
|
||
id: matchedServer.id,
|
||
brand: matchedServer.brand,
|
||
internal_ip: matchedServer.internal_ip,
|
||
internal_port: matchedServer.internal_port || 80,
|
||
username: matchedServer.username,
|
||
password: matchedServer.password,
|
||
},
|
||
});
|
||
}
|
||
await conn.commit();
|
||
} catch (txError) {
|
||
await conn.rollback();
|
||
throw txError;
|
||
}
|
||
return items;
|
||
}
|
||
|
||
/**
|
||
* 拉取待录像任务
|
||
* 查询 wms_pack_task(打包)与 wms_return_unpack(拆包)中无录像记录的任务
|
||
* 返回任务信息 + 摄像头信息 + 服务器信息
|
||
*/
|
||
async fetchTasks(data) {
|
||
const { app } = this;
|
||
const { print_computer_info } = this.ctx;
|
||
|
||
if (!print_computer_info) {
|
||
return this.errorResponse('hikvision.fetchTasks', '未绑定打印电脑信息');
|
||
}
|
||
|
||
const warehouseId = print_computer_info.warehouse;
|
||
|
||
try {
|
||
// 1. 查询该仓库待录像的打包任务(pack_mode=1, 状态不是已完成, 未删除)
|
||
const tasks = await app.mysql.get('wms').query(
|
||
`SELECT t.id, t.order_id, t.warehouse_id, t.workbench_id,
|
||
t.wave_no, t.waybill_code, t.device_ids, t.status AS task_status,
|
||
t.start_time, t.end_time, t.operator_text
|
||
FROM wms_pack_task t
|
||
WHERE t.warehouse_id = ?
|
||
AND t.deleted_at IS NULL
|
||
AND t.end_time IS NOT NULL
|
||
AND t.device_ids IS NOT NULL
|
||
AND t.device_ids != '[]'
|
||
AND t.id NOT IN (
|
||
SELECT v.pack_task_id FROM wms_pack_task_video v WHERE v.deleted_at IS NULL
|
||
)
|
||
ORDER BY t.id DESC
|
||
LIMIT 20`,
|
||
[warehouseId]
|
||
);
|
||
const tasks2 = await app.mysql.get('wms').query(
|
||
`SELECT t.id, t.order_id, t.warehouse_id, t.unpack_no,
|
||
t.waybill_code, t.camera_ids, t.status AS task_status,
|
||
t.start_time, t.end_time, t.unpacker_name AS operator_text
|
||
FROM wms_return_unpack t
|
||
WHERE t.warehouse_id = ?
|
||
AND t.end_time IS NOT NULL
|
||
AND t.camera_ids IS NOT NULL
|
||
AND t.camera_ids != '[]'
|
||
AND t.id NOT IN (
|
||
SELECT v.unpack_id FROM wms_return_unpack_video v WHERE v.deleted_at IS NULL
|
||
)
|
||
ORDER BY t.id DESC
|
||
LIMIT 20`,
|
||
[warehouseId]
|
||
);
|
||
|
||
if ((!tasks || tasks.length === 0) && (!tasks2 || tasks2.length === 0)) {
|
||
return this.successResponse('hikvision.fetchTasks', [], '暂无待录像任务');
|
||
}
|
||
|
||
// 2. 获取该仓库的摄像头服务器信息
|
||
const servers = await app.mysql.get('wms').select('wms_camera_server', {
|
||
where: { warehouse_id: warehouseId, deleted_at: null, status: 1 },
|
||
});
|
||
|
||
// 3. 获取该仓库的摄像头列表
|
||
const cameras = await app.mysql.get('wms').select('wms_camera', {
|
||
where: { warehouse_id: warehouseId, deleted_at: null, status: 1 },
|
||
});
|
||
|
||
// 4. 组装返回数据:每个任务的每个摄像头返回一条(先打包后拆包)
|
||
const packCfg = this._getTaskCfg('pack');
|
||
const unpackCfg = this._getTaskCfg('unpack');
|
||
|
||
const result = [];
|
||
for (const task of tasks || []) {
|
||
result.push(...await this._collectVideoItems(task, { ...packCfg, cameras, servers }));
|
||
}
|
||
for (const task of tasks2 || []) {
|
||
result.push(...await this._collectVideoItems(task, { ...unpackCfg, cameras, servers }));
|
||
}
|
||
|
||
console.log(`[Hikvision] 仓库 ${warehouseId} 返回 ${result.length} 个待录像任务`);
|
||
return this.successResponse('hikvision.fetchTasks', result, '查询成功');
|
||
|
||
} catch (error) {
|
||
console.error('[Hikvision] fetchTasks 错误:', error);
|
||
return this.errorResponse('hikvision.fetchTasks', error.message);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 客户端确认接收任务
|
||
* 创建 wms_pack_task_video 记录,状态改为 recording
|
||
*/
|
||
async receiveTask(data) {
|
||
const { app } = this;
|
||
const { taskId, uniqueCode, ok, message, task_type } = data || {};
|
||
|
||
if (!uniqueCode) {
|
||
return this.errorResponse('hikvision.receiveTask', '缺少 uniqueCode');
|
||
}
|
||
|
||
try {
|
||
// 判断任务类型:优先用回信 task_type,缺失时回退 uniqueCode 前缀
|
||
// (拆包: unpack_{task_id}_{camera_id};打包: {task_id}_{device_id})
|
||
let isUnpack;
|
||
if (task_type === 'pack' || task_type === 'unpack') {
|
||
isUnpack = task_type === 'unpack';
|
||
} else {
|
||
isUnpack = uniqueCode.startsWith('unpack_');
|
||
}
|
||
const parts = uniqueCode.split('_');
|
||
const taskIdNum = parseInt(isUnpack ? parts[1] : parts[0]);
|
||
const cameraIdNum = parseInt(parts[parts.length - 1]);
|
||
|
||
if (!taskIdNum) {
|
||
return this.errorResponse('hikvision.receiveTask', `无法解析任务ID: ${uniqueCode}`);
|
||
}
|
||
|
||
const videoTable = isUnpack ? 'wms_return_unpack_video' : 'wms_pack_task_video';
|
||
const fkColumn = isUnpack ? 'unpack_id' : 'pack_task_id';
|
||
|
||
if (ok) {
|
||
// 任务接收成功 → 定位该摄像头录像行,状态改为 recording
|
||
const whereCond = { [fkColumn]: taskIdNum, deleted_at: null };
|
||
if (!isNaN(cameraIdNum)) whereCond.camera_id = cameraIdNum;
|
||
|
||
const existingVideo = await app.mysql.get('wms').get(videoTable, whereCond);
|
||
|
||
if (!existingVideo) {
|
||
const insertRow = {
|
||
[fkColumn]: taskIdNum,
|
||
video_url: '',
|
||
status: 'recording',
|
||
remark: message || '任务已接收',
|
||
created_at: app.mysql.literals.now,
|
||
updated_at: app.mysql.literals.now,
|
||
};
|
||
if (!isNaN(cameraIdNum)) insertRow.camera_id = cameraIdNum;
|
||
await app.mysql.get('wms').insert(videoTable, insertRow);
|
||
} else if (existingVideo.status === 'created') {
|
||
await app.mysql.get('wms').update(videoTable,
|
||
{ status: 'recording', remark: message || '任务已接收', updated_at: app.mysql.literals.now },
|
||
{ where: { id: existingVideo.id } }
|
||
);
|
||
}
|
||
|
||
console.log(`[Hikvision] 录像开始: ${fkColumn}=${taskIdNum}, taskId=${taskId}`);
|
||
return this.successResponse('hikvision.receiveTask', { [fkColumn]: taskIdNum, status: 'recording' }, '录像已开始');
|
||
} else {
|
||
// 任务接收失败
|
||
console.log(`[Hikvision] 任务接收失败: ${fkColumn}=${taskIdNum}, message=${message}`);
|
||
return this.errorResponse('hikvision.receiveTask', message || '任务接收失败');
|
||
}
|
||
} catch (error) {
|
||
console.error('[Hikvision] receiveTask 错误:', error);
|
||
return this.errorResponse('hikvision.receiveTask', error.message);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 客户端回调:录像任务完成
|
||
* 成功 → 写入 video_url,状态 completed
|
||
* 失败 → 写入 remark,状态 failed
|
||
*/
|
||
async taskComplete(data) {
|
||
const { app } = this;
|
||
const { taskId, uniqueCode, status, success, output, size, duration, speed, fileUrl, error: errorMsg, task_type } = data || {};
|
||
|
||
if (!uniqueCode) {
|
||
return this.errorResponse('hikvision.taskComplete', '缺少 uniqueCode');
|
||
}
|
||
|
||
try {
|
||
// 判断任务类型:优先用回信 task_type,缺失时回退 uniqueCode 前缀
|
||
// (拆包: unpack_{task_id}_{camera_id};打包: {task_id}_{device_id})
|
||
let isUnpack;
|
||
if (task_type === 'pack' || task_type === 'unpack') {
|
||
isUnpack = task_type === 'unpack';
|
||
} else {
|
||
isUnpack = uniqueCode.startsWith('unpack_');
|
||
}
|
||
const parts = uniqueCode.split('_');
|
||
const taskIdNum = parseInt(isUnpack ? parts[1] : parts[0]);
|
||
const cameraIdNum = parseInt(parts[parts.length - 1]);
|
||
|
||
if (!taskIdNum) {
|
||
return this.errorResponse('hikvision.taskComplete', `无法解析任务ID: ${uniqueCode}`);
|
||
}
|
||
|
||
const videoTable = isUnpack ? 'wms_return_unpack_video' : 'wms_pack_task_video';
|
||
const fkColumn = isUnpack ? 'unpack_id' : 'pack_task_id';
|
||
|
||
// 按任务ID+摄像头ID精确定位录像行,避免多摄像头/forceRecord 并发错位
|
||
const whereCond = { [fkColumn]: taskIdNum, deleted_at: null };
|
||
if (!isNaN(cameraIdNum)) whereCond.camera_id = cameraIdNum;
|
||
|
||
if (success && status === 'completed') {
|
||
// 取该摄像头最新的录像记录 ID 精准更新
|
||
const [latestVideo] = await app.mysql.get('wms').select(videoTable, {
|
||
where: whereCond,
|
||
orders: [['id', 'desc']],
|
||
limit: 1,
|
||
});
|
||
if (latestVideo) {
|
||
await app.mysql.get('wms').update(videoTable,
|
||
{
|
||
video_url: fileUrl || output || '',
|
||
status: 'completed',
|
||
remark: `大小:${(size / 1024 / 1024).toFixed(2)}MB, 时长:${duration}s, 倍速:${speed}x`,
|
||
updated_at: app.mysql.literals.now,
|
||
},
|
||
{ where: { id: latestVideo.id } }
|
||
);
|
||
}
|
||
|
||
console.log(`[Hikvision] 录像完成: ${fkColumn}=${taskIdNum}, url=${fileUrl}, size=${size}`);
|
||
return this.successResponse('hikvision.taskComplete',
|
||
{ [fkColumn]: taskIdNum, status: 'completed' }, '录像完成');
|
||
} else {
|
||
// 录像失败 - 同样按摄像头精准更新最新记录
|
||
const [latestVideo] = await app.mysql.get('wms').select(videoTable, {
|
||
where: whereCond,
|
||
orders: [['id', 'desc']],
|
||
limit: 1,
|
||
});
|
||
if (latestVideo) {
|
||
await app.mysql.get('wms').update(videoTable,
|
||
{ status: 'failed', remark: errorMsg || '录像失败', updated_at: app.mysql.literals.now },
|
||
{ where: { id: latestVideo.id } }
|
||
);
|
||
}
|
||
|
||
console.log(`[Hikvision] 录像失败: ${fkColumn}=${taskIdNum}, error=${errorMsg}`);
|
||
return this.successResponse('hikvision.taskComplete',
|
||
{ [fkColumn]: taskIdNum, status: 'failed', error: errorMsg }, '录像失败已记录');
|
||
}
|
||
} catch (error) {
|
||
console.error('[Hikvision] taskComplete 错误:', error);
|
||
return this.errorResponse('hikvision.taskComplete', error.message);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 强制录制:外部 HTTP 调用,按任务ID强制推送录制任务
|
||
* 支持打包(pack_task_id)与拆包(unpack_id + task_type='unpack')
|
||
* 事务内重置已有录像行,推送成功后提交
|
||
*/
|
||
async forceRecord(data) {
|
||
const { app } = this;
|
||
const { pack_task_id, unpack_id, task_type } = data || {};
|
||
|
||
// 任务类型判断:task_type 优先;否则按入参 ID 判断
|
||
const isUnpack = task_type === 'unpack' || (!pack_task_id && !!unpack_id);
|
||
const taskId = isUnpack ? unpack_id : pack_task_id;
|
||
|
||
if (!taskId) {
|
||
return { status: 'fail', message: isUnpack ? '缺少 unpack_id' : '缺少 pack_task_id' };
|
||
}
|
||
|
||
try {
|
||
const cfg = this._getTaskCfg(isUnpack ? 'unpack' : 'pack');
|
||
|
||
// 1. 查询任务(拆包主表无 deleted_at 列)
|
||
const getCond = { id: taskId };
|
||
if (!isUnpack) getCond.deleted_at = null;
|
||
const task = await app.mysql.get('wms').get(cfg.taskTable, getCond);
|
||
|
||
if (!task) {
|
||
return { status: 'fail', message: isUnpack ? '拆包任务不存在' : '打包任务不存在' };
|
||
}
|
||
|
||
if (!task.end_time || !task[cfg.cameraIdsField] || task[cfg.cameraIdsField] === '[]') {
|
||
return { status: 'fail', message: '任务未完成或无摄像头信息' };
|
||
}
|
||
|
||
// 2. 查询摄像头和服务器
|
||
const cameras = await app.mysql.get('wms').select('wms_camera', {
|
||
where: { warehouse_id: task.warehouse_id, deleted_at: null, status: 1 },
|
||
});
|
||
const servers = await app.mysql.get('wms').select('wms_camera_server', {
|
||
where: { warehouse_id: task.warehouse_id, deleted_at: null, status: 1 },
|
||
});
|
||
|
||
// 3. 找到同仓库的录制电脑
|
||
const warehousePattern = `warehouse:${task.warehouse_id}:printer:*`;
|
||
const onlineKeys = [];
|
||
let cursor = '0';
|
||
do {
|
||
const [nextCursor, keys] = await app.redis.scan(cursor, 'MATCH', warehousePattern, 'COUNT', 100);
|
||
cursor = nextCursor;
|
||
onlineKeys.push(...keys);
|
||
} while (cursor !== '0');
|
||
|
||
let recordingUniqueId = null;
|
||
for (const key of onlineKeys) {
|
||
const info = await app.redis.get(key);
|
||
if (!info) continue;
|
||
const parsed = JSON.parse(info);
|
||
if (parsed.is_recording === 1) {
|
||
recordingUniqueId = parsed.uniqueId;
|
||
break;
|
||
}
|
||
}
|
||
|
||
if (!recordingUniqueId) {
|
||
console.log(`[Hikvision] forceRecord 失败: 仓库 ${task.warehouse_id} 无录制电脑在线, 在线电脑: ${onlineKeys.length}台`);
|
||
return { status: 'fail', message: '该仓库无录制电脑在线' };
|
||
}
|
||
|
||
// 4. 事务:先删除全部旧行,再逐摄像头插入并推送
|
||
const cameraIds = typeof task[cfg.cameraIdsField] === 'string'
|
||
? JSON.parse(task[cfg.cameraIdsField]) : (task[cfg.cameraIdsField] || []);
|
||
|
||
const conn = await app.mysql.get('wms').beginTransaction();
|
||
try {
|
||
await conn.delete(cfg.videoTable, { [cfg.fkColumn]: task.id });
|
||
|
||
for (const cameraId of cameraIds) {
|
||
let matchedCamera = cameras.find(c => c.id === cameraId);
|
||
if (!matchedCamera && cfg.workbenchMatch && task.workbench_id) {
|
||
matchedCamera = cameras.find(
|
||
c => c.custom_name && c.custom_name.includes(`${task.workbench_id}号`)
|
||
);
|
||
}
|
||
if (!matchedCamera) matchedCamera = cameras[0];
|
||
if (!matchedCamera) continue;
|
||
const matchedServer = servers.find(s => s.id === matchedCamera.server_id) || servers[0];
|
||
if (!matchedServer) continue;
|
||
|
||
await conn.insert(cfg.videoTable, {
|
||
[cfg.fkColumn]: task.id,
|
||
camera_id: matchedCamera.id,
|
||
video_url: '',
|
||
status: 'created',
|
||
created_at: app.mysql.literals.now,
|
||
updated_at: app.mysql.literals.now,
|
||
});
|
||
|
||
// 5. 推送录制任务
|
||
const payload = {
|
||
...cfg.buildFields(task, cameraId),
|
||
uniqueCode: `${cfg.codePrefix}${task.id}_${cameraId}`,
|
||
start_time: this._toISO(task.start_time, -5000),
|
||
end_time: this._toISO(task.end_time),
|
||
operator: task.operator_text,
|
||
camera: {
|
||
id: matchedCamera.id,
|
||
channel_id: matchedCamera.channel_id,
|
||
channel_name: matchedCamera.channel_name,
|
||
ip: matchedCamera.ip,
|
||
port: matchedCamera.port,
|
||
model: matchedCamera.model,
|
||
},
|
||
server: {
|
||
id: matchedServer.id,
|
||
brand: matchedServer.brand,
|
||
internal_ip: matchedServer.internal_ip,
|
||
internal_port: matchedServer.internal_port || 80,
|
||
username: matchedServer.username,
|
||
password: matchedServer.password,
|
||
},
|
||
};
|
||
|
||
const sendRes = await app.ws.sendTo(recordingUniqueId, JSON.stringify({
|
||
method: 'hikvision.receiveTask',
|
||
data: payload,
|
||
}));
|
||
|
||
if (sendRes !== 1) {
|
||
await conn.rollback();
|
||
return { status: 'fail', message: '推送失败,录制电脑可能已断开' };
|
||
}
|
||
|
||
console.log(`[Hikvision] 强制录制-已推送: ${cfg.fkColumn}=${task.id}, camera=${cameraId}`);
|
||
}
|
||
|
||
await conn.commit();
|
||
console.log(`[Hikvision] 强制录制-重置录像行: ${cfg.fkColumn}=${task.id}`);
|
||
} catch (txError) {
|
||
await conn.rollback();
|
||
throw txError;
|
||
}
|
||
|
||
return { status: 'success', message: '强制录制任务已推送', [cfg.fkColumn]: task.id };
|
||
} catch (error) {
|
||
console.error('[Hikvision] forceRecord 错误:', error);
|
||
return { status: 'fail', message: error.message };
|
||
}
|
||
}
|
||
}
|
||
|
||
module.exports = HikvisionService;
|