This commit is contained in:
张成
2025-12-30 14:37:33 +08:00
parent 6d73a80e50
commit dcaf0cb428
12 changed files with 2046 additions and 55 deletions

View File

@@ -213,58 +213,17 @@ class CommandManager {
* @private
*/
async _execute_command_with_timeout(command_id, command_type, command_name, command_params, sn_code, mqttClient, start_time) {
// 将驼峰命名转换为下划线命名
const to_snake_case = (str) => {
if (str.includes('_')) {
return str;
}
return str.replace(/([A-Z])/g, '_$1').toLowerCase().replace(/^_/, '');
};
const method_name = to_snake_case(command_type);
// 获取指令超时时间从配置中获取默认5分钟
const timeout = ScheduleConfig.taskTimeouts[command_type] ||
ScheduleConfig.taskTimeouts[method_name] ||
5 * 60 * 1000;
const timeout = ScheduleConfig.taskTimeouts[command_type] || 5 * 60 * 1000;
// 构建指令执行 Promise
const command_promise = (async () => {
// 指令类型映射表(内部指令类型 -> jobManager方法名)
const commandMethodMap = {
// get_job_list 指令对应MQTT Action: "get_job_list"
'get_job_list': 'get_job_list',
'getJobList': 'get_job_list',
// search_jobs_with_params 指令对应MQTT Action: "search_job_list"
'search_jobs_with_params': 'search_jobs_with_params',
'searchJobsWithParams': 'search_jobs_with_params',
// search_and_deliver 指令内部调用search_jobs_with_params和deliver_resume
'search_and_deliver': 'search_and_deliver',
'searchAndDeliver': 'search_and_deliver',
// deliver_resume 指令对应MQTT Action: "deliver_resume"
'deliver_resume': 'deliver_resume',
'deliverResume': 'deliver_resume'
// search_jobs 指令对应MQTT Action: "search_jobs"
'search_jobs': 'search_jobs',
'searchJobs': 'search_jobs'
};
// 优先使用映射表
const mappedMethod = commandMethodMap[command_type] || commandMethodMap[method_name];
if (mappedMethod && jobManager[mappedMethod]) {
return await jobManager[mappedMethod](sn_code, mqttClient, command_params);
}
// 其次尝试转换后的方法名
if (command_type && jobManager[method_name]) {
return await jobManager[method_name](sn_code, mqttClient, command_params);
}
// 最后尝试原始指令类型
// 直接使用 command_type 调用 jobManager 的方法,不做映射
// command_type 和 jobManager 的方法名保持一致
if (jobManager[command_type]) {
return await jobManager[command_type](sn_code, mqttClient, command_params);
} else {
throw new Error(`未知的指令类型: ${command_type} (尝试的方法名: ${method_name}, 映射方法: ${mappedMethod})`);
throw new Error(`未知的指令类型: ${command_type}, jobManager 中不存在对应方法`);
}
})();