88 lines
2.8 KiB
JavaScript
88 lines
2.8 KiB
JavaScript
const BaseHandler = require('./baseHandler');
|
|
const ConfigManager = require('../services/configManager');
|
|
const command = require('../command');
|
|
const config = require('../config');
|
|
|
|
/**
|
|
* 自动搜索处理器
|
|
* 负责搜索职位列表
|
|
*/
|
|
class SearchHandler extends BaseHandler {
|
|
/**
|
|
* 处理自动搜索任务
|
|
* @param {object} task - 任务对象
|
|
* @returns {Promise<object>} 执行结果
|
|
*/
|
|
async handle(task) {
|
|
return await this.execute(task, async () => {
|
|
return await this.doSearch(task);
|
|
}, {
|
|
checkAuth: true,
|
|
checkOnline: true,
|
|
recordDeviceMetrics: true
|
|
});
|
|
}
|
|
|
|
/**
|
|
* 执行搜索逻辑
|
|
*/
|
|
async doSearch(task) {
|
|
const { sn_code, taskParams } = task;
|
|
const { keyword, platform = 'boss', pageCount = 3 } = taskParams;
|
|
|
|
console.log(`[自动搜索] 开始 - 设备: ${sn_code}, 关键词: ${keyword}`);
|
|
|
|
// 1. 获取账户配置
|
|
const accountConfig = await this.getAccountConfig(sn_code, ['keyword', 'platform_type', 'search_config']);
|
|
|
|
if (!accountConfig) {
|
|
return {
|
|
jobsFound: 0,
|
|
message: '未找到账户配置'
|
|
};
|
|
}
|
|
|
|
// 2. 解析搜索配置
|
|
const searchConfig = ConfigManager.parseSearchConfig(accountConfig.search_config);
|
|
|
|
// 3. 检查搜索时间范围
|
|
const timeRange = ConfigManager.getTimeRange(searchConfig);
|
|
if (timeRange) {
|
|
const timeRangeValidator = require('../services/timeRangeValidator');
|
|
const timeCheck = timeRangeValidator.checkTimeRange(timeRange);
|
|
|
|
if (!timeCheck.allowed) {
|
|
return {
|
|
jobsFound: 0,
|
|
message: timeCheck.reason
|
|
};
|
|
}
|
|
}
|
|
|
|
// 4. 创建搜索指令
|
|
const searchCommand = {
|
|
command_type: 'getJobList',
|
|
command_name: `自动搜索职位 - ${keyword || accountConfig.keyword}`,
|
|
command_params: JSON.stringify({
|
|
sn_code,
|
|
keyword: keyword || accountConfig.keyword || '',
|
|
platform: platform || accountConfig.platform_type || 'boss',
|
|
pageCount: pageCount || searchConfig.page_count || 3
|
|
}),
|
|
priority: config.getTaskPriority('search_jobs') || 8
|
|
};
|
|
|
|
// 5. 执行搜索指令
|
|
const result = await command.executeCommands(task.id, [searchCommand], this.mqttClient);
|
|
|
|
console.log(`[自动搜索] 完成 - 设备: ${sn_code}, 结果: ${JSON.stringify(result)}`);
|
|
|
|
return {
|
|
jobsFound: result.jobCount || 0,
|
|
message: '搜索完成'
|
|
};
|
|
}
|
|
}
|
|
|
|
module.exports = SearchHandler;
|