feat: fetchTasks 支持拆包任务录像(wms_return_unpack_video)
This commit is contained in:
parent
e605bd80e3
commit
7923c3ea9a
@ -21,9 +21,105 @@ class HikvisionService extends BaseService {
|
|||||||
return cst.toISOString().replace('Z', '+08:00');
|
return cst.toISOString().replace('Z', '+08:00');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 组装录像任务落参,并在事务内创建录像占位记录(防止并发重复)
|
||||||
|
* @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 中 pack_mode=1 且无录像记录的任务
|
* 查询 wms_pack_task(打包)与 wms_return_unpack(拆包)中无录像记录的任务
|
||||||
* 返回任务信息 + 摄像头信息 + 服务器信息
|
* 返回任务信息 + 摄像头信息 + 服务器信息
|
||||||
*/
|
*/
|
||||||
async fetchTasks(data) {
|
async fetchTasks(data) {
|
||||||
@ -55,8 +151,24 @@ class HikvisionService extends BaseService {
|
|||||||
LIMIT 20`,
|
LIMIT 20`,
|
||||||
[warehouseId]
|
[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) {
|
if ((!tasks || tasks.length === 0) && (!tasks2 || tasks2.length === 0)) {
|
||||||
return this.successResponse('hikvision.fetchTasks', [], '暂无待录像任务');
|
return this.successResponse('hikvision.fetchTasks', [], '暂无待录像任务');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,86 +182,47 @@ class HikvisionService extends BaseService {
|
|||||||
where: { warehouse_id: warehouseId, deleted_at: null, status: 1 },
|
where: { warehouse_id: warehouseId, deleted_at: null, status: 1 },
|
||||||
});
|
});
|
||||||
|
|
||||||
// 4. 组装返回数据:每个任务的每个摄像头返回一条
|
// 4. 组装返回数据:每个任务的每个摄像头返回一条(先打包后拆包)
|
||||||
|
const packCfg = {
|
||||||
|
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,
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
const unpackCfg = {
|
||||||
|
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,
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
|
||||||
const result = [];
|
const result = [];
|
||||||
for (const task of tasks) {
|
for (const task of tasks || []) {
|
||||||
let deviceIds = [];
|
result.push(...await this._collectVideoItems(task, { ...packCfg, cameras, servers }));
|
||||||
try {
|
}
|
||||||
deviceIds = typeof task.device_ids === 'string'
|
for (const task of tasks2 || []) {
|
||||||
? JSON.parse(task.device_ids)
|
result.push(...await this._collectVideoItems(task, { ...unpackCfg, cameras, servers }));
|
||||||
: (task.device_ids || []);
|
|
||||||
} catch (e) {
|
|
||||||
deviceIds = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
// 事务:原子化检查+插入,防止并发重复
|
|
||||||
const conn = await app.mysql.get('wms').beginTransaction();
|
|
||||||
try {
|
|
||||||
for (const deviceId of deviceIds) {
|
|
||||||
// 按设备ID匹配摄像头
|
|
||||||
const matchedCamera = cameras.find(c => c.id === deviceId)
|
|
||||||
|| cameras.find(c => c.custom_name && c.custom_name.includes(`${task.workbench_id}号`))
|
|
||||||
|| cameras[0];
|
|
||||||
|
|
||||||
if (!matchedCamera) continue;
|
|
||||||
|
|
||||||
const matchedServer = servers.find(s => s.id === matchedCamera.server_id) || servers[0];
|
|
||||||
if (!matchedServer) continue;
|
|
||||||
|
|
||||||
// 事务内 SELECT ... FOR UPDATE 锁定检查,防止并发重复
|
|
||||||
const [existing] = await conn.query(
|
|
||||||
`SELECT id FROM wms_pack_task_video
|
|
||||||
WHERE pack_task_id = ? AND camera_id = ? AND deleted_at IS NULL
|
|
||||||
FOR UPDATE`,
|
|
||||||
[task.id, matchedCamera.id]
|
|
||||||
);
|
|
||||||
if (!existing || existing.length === 0) {
|
|
||||||
await conn.insert('wms_pack_task_video', {
|
|
||||||
pack_task_id: task.id,
|
|
||||||
camera_id: matchedCamera.id,
|
|
||||||
video_url: '',
|
|
||||||
status: 'created',
|
|
||||||
});
|
|
||||||
console.log(`[Hikvision] 创建录像记录: pack_task=${task.id}, camera=${matchedCamera.id}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
result.push({
|
|
||||||
pack_task_id: task.id,
|
|
||||||
device_id: deviceId,
|
|
||||||
uniqueCode: `${task.id}_${deviceId}`,
|
|
||||||
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,
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`[Hikvision] 仓库 ${warehouseId} 返回 ${result.length} 个待录像任务`);
|
console.log(`[Hikvision] 仓库 ${warehouseId} 返回 ${result.length} 个待录像任务`);
|
||||||
@ -167,47 +240,59 @@ class HikvisionService extends BaseService {
|
|||||||
*/
|
*/
|
||||||
async receiveTask(data) {
|
async receiveTask(data) {
|
||||||
const { app } = this;
|
const { app } = this;
|
||||||
const { taskId, uniqueCode, ok, message } = data || {};
|
const { taskId, uniqueCode, ok, message, task_type } = data || {};
|
||||||
|
|
||||||
if (!uniqueCode) {
|
if (!uniqueCode) {
|
||||||
return this.errorResponse('hikvision.receiveTask', '缺少 uniqueCode');
|
return this.errorResponse('hikvision.receiveTask', '缺少 uniqueCode');
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 从 uniqueCode 解析 pack_task_id(格式: {task_id}_{device_id})
|
// 判断任务类型:优先用回信 task_type,缺失时回退 uniqueCode 前缀
|
||||||
const parts = uniqueCode.split('_');
|
// (拆包: unpack_{task_id}_{camera_id};打包: {task_id}_{device_id})
|
||||||
const packTaskId = parseInt(parts[0]);
|
let isUnpack;
|
||||||
|
if (task_type === 'pack' || task_type === 'unpack') {
|
||||||
if (!packTaskId) {
|
isUnpack = task_type === 'unpack';
|
||||||
return this.errorResponse('hikvision.receiveTask', '无法解析 pack_task_id');
|
} else {
|
||||||
|
isUnpack = uniqueCode.startsWith('unpack_');
|
||||||
}
|
}
|
||||||
|
const parts = uniqueCode.split('_');
|
||||||
|
const taskIdNum = parseInt(isUnpack ? parts[1] : parts[0]);
|
||||||
|
|
||||||
|
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) {
|
if (ok) {
|
||||||
// 任务接收成功 → 创建录像记录,状态 recording
|
// 任务接收成功 → 创建录像记录,状态 recording
|
||||||
const existingVideo = await app.mysql.get('wms').get('wms_pack_task_video', {
|
const existingVideo = await app.mysql.get('wms').get(videoTable, {
|
||||||
pack_task_id: packTaskId,
|
[fkColumn]: taskIdNum,
|
||||||
deleted_at: null,
|
deleted_at: null,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!existingVideo) {
|
if (!existingVideo) {
|
||||||
await app.mysql.get('wms').insert('wms_pack_task_video', {
|
await app.mysql.get('wms').insert(videoTable, {
|
||||||
pack_task_id: packTaskId,
|
[fkColumn]: taskIdNum,
|
||||||
video_url: '',
|
video_url: '',
|
||||||
status: 'recording',
|
status: 'recording',
|
||||||
remark: message || '任务已接收',
|
remark: message || '任务已接收',
|
||||||
|
created_at: app.mysql.literals.now,
|
||||||
|
updated_at: app.mysql.literals.now,
|
||||||
});
|
});
|
||||||
} else if (existingVideo.status === 'created') {
|
} else if (existingVideo.status === 'created') {
|
||||||
await app.mysql.get('wms').update('wms_pack_task_video',
|
await app.mysql.get('wms').update(videoTable,
|
||||||
{ status: 'recording', remark: message || '任务已接收' },
|
{ status: 'recording', remark: message || '任务已接收', updated_at: app.mysql.literals.now },
|
||||||
{ where: { id: existingVideo.id } }
|
{ where: { id: existingVideo.id } }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`[Hikvision] 录像开始: pack_task=${packTaskId}, taskId=${taskId}`);
|
console.log(`[Hikvision] 录像开始: ${fkColumn}=${taskIdNum}, taskId=${taskId}`);
|
||||||
return this.successResponse('hikvision.receiveTask', { packTaskId, status: 'recording' }, '录像已开始');
|
return this.successResponse('hikvision.receiveTask', { [fkColumn]: taskIdNum, status: 'recording' }, '录像已开始');
|
||||||
} else {
|
} else {
|
||||||
// 任务接收失败
|
// 任务接收失败
|
||||||
console.log(`[Hikvision] 任务接收失败: pack_task=${packTaskId}, message=${message}`);
|
console.log(`[Hikvision] 任务接收失败: ${fkColumn}=${taskIdNum}, message=${message}`);
|
||||||
return this.errorResponse('hikvision.receiveTask', message || '任务接收失败');
|
return this.errorResponse('hikvision.receiveTask', message || '任务接收失败');
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -223,58 +308,70 @@ class HikvisionService extends BaseService {
|
|||||||
*/
|
*/
|
||||||
async taskComplete(data) {
|
async taskComplete(data) {
|
||||||
const { app } = this;
|
const { app } = this;
|
||||||
const { taskId, uniqueCode, status, success, output, size, duration, speed, fileUrl, error: errorMsg } = data || {};
|
const { taskId, uniqueCode, status, success, output, size, duration, speed, fileUrl, error: errorMsg, task_type } = data || {};
|
||||||
|
|
||||||
if (!uniqueCode) {
|
if (!uniqueCode) {
|
||||||
return this.errorResponse('hikvision.taskComplete', '缺少 uniqueCode');
|
return this.errorResponse('hikvision.taskComplete', '缺少 uniqueCode');
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const parts = uniqueCode.split('_');
|
// 判断任务类型:优先用回信 task_type,缺失时回退 uniqueCode 前缀
|
||||||
const packTaskId = parseInt(parts[0]);
|
// (拆包: unpack_{task_id}_{camera_id};打包: {task_id}_{device_id})
|
||||||
|
let isUnpack;
|
||||||
if (!packTaskId) {
|
if (task_type === 'pack' || task_type === 'unpack') {
|
||||||
return this.errorResponse('hikvision.taskComplete', '无法解析 pack_task_id');
|
isUnpack = task_type === 'unpack';
|
||||||
|
} else {
|
||||||
|
isUnpack = uniqueCode.startsWith('unpack_');
|
||||||
}
|
}
|
||||||
|
const parts = uniqueCode.split('_');
|
||||||
|
const taskIdNum = parseInt(isUnpack ? parts[1] : parts[0]);
|
||||||
|
|
||||||
|
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';
|
||||||
|
|
||||||
if (success && status === 'completed') {
|
if (success && status === 'completed') {
|
||||||
// 取最新的录像记录 ID 精准更新,避免 forceRecord 并发覆盖
|
// 取最新的录像记录 ID 精准更新,避免 forceRecord 并发覆盖
|
||||||
const [latestVideo] = await app.mysql.get('wms').select('wms_pack_task_video', {
|
const [latestVideo] = await app.mysql.get('wms').select(videoTable, {
|
||||||
where: { pack_task_id: packTaskId, deleted_at: null },
|
where: { [fkColumn]: taskIdNum, deleted_at: null },
|
||||||
orders: [['id', 'desc']],
|
orders: [['id', 'desc']],
|
||||||
limit: 1,
|
limit: 1,
|
||||||
});
|
});
|
||||||
if (latestVideo) {
|
if (latestVideo) {
|
||||||
await app.mysql.get('wms').update('wms_pack_task_video',
|
await app.mysql.get('wms').update(videoTable,
|
||||||
{
|
{
|
||||||
video_url: fileUrl || output || '',
|
video_url: fileUrl || output || '',
|
||||||
status: 'completed',
|
status: 'completed',
|
||||||
remark: `大小:${(size / 1024 / 1024).toFixed(2)}MB, 时长:${duration}s, 倍速:${speed}x`,
|
remark: `大小:${(size / 1024 / 1024).toFixed(2)}MB, 时长:${duration}s, 倍速:${speed}x`,
|
||||||
|
updated_at: app.mysql.literals.now,
|
||||||
},
|
},
|
||||||
{ where: { id: latestVideo.id } }
|
{ where: { id: latestVideo.id } }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`[Hikvision] 录像完成: pack_task=${packTaskId}, url=${fileUrl}, size=${size}`);
|
console.log(`[Hikvision] 录像完成: ${fkColumn}=${taskIdNum}, url=${fileUrl}, size=${size}`);
|
||||||
return this.successResponse('hikvision.taskComplete',
|
return this.successResponse('hikvision.taskComplete',
|
||||||
{ packTaskId, status: 'completed' }, '录像完成');
|
{ [fkColumn]: taskIdNum, status: 'completed' }, '录像完成');
|
||||||
} else {
|
} else {
|
||||||
// 录像失败 - 同样精准更新最新记录
|
// 录像失败 - 同样精准更新最新记录
|
||||||
const [latestVideo] = await app.mysql.get('wms').select('wms_pack_task_video', {
|
const [latestVideo] = await app.mysql.get('wms').select(videoTable, {
|
||||||
where: { pack_task_id: packTaskId, deleted_at: null },
|
where: { [fkColumn]: taskIdNum, deleted_at: null },
|
||||||
orders: [['id', 'desc']],
|
orders: [['id', 'desc']],
|
||||||
limit: 1,
|
limit: 1,
|
||||||
});
|
});
|
||||||
if (latestVideo) {
|
if (latestVideo) {
|
||||||
await app.mysql.get('wms').update('wms_pack_task_video',
|
await app.mysql.get('wms').update(videoTable,
|
||||||
{ status: 'failed', remark: errorMsg || '录像失败' },
|
{ status: 'failed', remark: errorMsg || '录像失败', updated_at: app.mysql.literals.now },
|
||||||
{ where: { id: latestVideo.id } }
|
{ where: { id: latestVideo.id } }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`[Hikvision] 录像失败: pack_task=${packTaskId}, error=${errorMsg}`);
|
console.log(`[Hikvision] 录像失败: ${fkColumn}=${taskIdNum}, error=${errorMsg}`);
|
||||||
return this.successResponse('hikvision.taskComplete',
|
return this.successResponse('hikvision.taskComplete',
|
||||||
{ packTaskId, status: 'failed', error: errorMsg }, '录像失败已记录');
|
{ [fkColumn]: taskIdNum, status: 'failed', error: errorMsg }, '录像失败已记录');
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('[Hikvision] taskComplete 错误:', error);
|
console.error('[Hikvision] taskComplete 错误:', error);
|
||||||
@ -362,6 +459,8 @@ class HikvisionService extends BaseService {
|
|||||||
camera_id: matchedCamera.id,
|
camera_id: matchedCamera.id,
|
||||||
video_url: '',
|
video_url: '',
|
||||||
status: 'created',
|
status: 'created',
|
||||||
|
created_at: app.mysql.literals.now,
|
||||||
|
updated_at: app.mysql.literals.now,
|
||||||
});
|
});
|
||||||
await conn.commit();
|
await conn.commit();
|
||||||
console.log(`[Hikvision] 强制录制-重置录像行: pack_task=${task.id}`);
|
console.log(`[Hikvision] 强制录制-重置录像行: pack_task=${task.id}`);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user