1
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
|
||||
const db = require('../middleware/dbProxy');
|
||||
const scheduleManager = require('../middleware/schedule/index.js');
|
||||
const locationService = require('./location_service');
|
||||
const locationService = require('./locationService');
|
||||
const authorizationService = require('./authorization_service');
|
||||
const { addRemainingDays, addRemainingDaysToAccounts } = require('../utils/account_utils');
|
||||
|
||||
@@ -486,10 +486,10 @@ class PlaAccountService {
|
||||
finalParams.keyword = account.keyword;
|
||||
}
|
||||
|
||||
// 构建指令对象
|
||||
// 构建指令对象(与前端/后端/下发统一:只用一个名字 command_type)
|
||||
const command = {
|
||||
command_type: commandTypeSnake,
|
||||
command_name: commandName || commandType,
|
||||
command_name: commandTypeSnake,
|
||||
command_params: JSON.stringify(finalParams)
|
||||
};
|
||||
|
||||
@@ -497,7 +497,7 @@ class PlaAccountService {
|
||||
const task = await task_status.create({
|
||||
sn_code: account.sn_code,
|
||||
taskType: commandTypeSnake,
|
||||
taskName: commandName || commandType,
|
||||
taskName: commandTypeSnake,
|
||||
taskParams: JSON.stringify(finalParams)
|
||||
});
|
||||
|
||||
@@ -567,10 +567,6 @@ class PlaAccountService {
|
||||
throw new Error('指令不存在');
|
||||
}
|
||||
|
||||
// 检查指令状态
|
||||
if (command.status !== 'failed') {
|
||||
throw new Error('只能重试失败的指令');
|
||||
}
|
||||
|
||||
// 获取任务信息
|
||||
const task = await task_status.findByPk(command.task_id);
|
||||
@@ -627,15 +623,39 @@ class PlaAccountService {
|
||||
command_params: JSON.stringify(commandParams)
|
||||
};
|
||||
|
||||
// 执行指令
|
||||
const result = await scheduleManager.command.executeCommand(task.id, commandObj, scheduleManager.mqttClient);
|
||||
// 执行指令并同步更新当前指令记录状态
|
||||
const start_time = new Date();
|
||||
try {
|
||||
const result = await scheduleManager.command.executeCommand(task.id, commandObj, scheduleManager.mqttClient);
|
||||
const end_time = new Date();
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: '指令重试成功',
|
||||
commandId: command.id,
|
||||
result: result
|
||||
};
|
||||
await command.update({
|
||||
status: 'completed',
|
||||
start_time: start_time,
|
||||
end_time: end_time,
|
||||
duration: end_time.getTime() - start_time.getTime(),
|
||||
result: JSON.stringify(result || {})
|
||||
});
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: '指令重试成功',
|
||||
commandId: command.id,
|
||||
result: result
|
||||
};
|
||||
} catch (error) {
|
||||
const end_time = new Date();
|
||||
await command.update({
|
||||
status: 'failed',
|
||||
start_time: start_time,
|
||||
end_time: end_time,
|
||||
duration: end_time.getTime() - start_time.getTime(),
|
||||
error_message: error.message || '指令重试失败',
|
||||
error_stack: error.stack || ''
|
||||
});
|
||||
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user