This commit is contained in:
张成
2025-12-10 09:58:22 +08:00
parent e77f004dcc
commit 5d1e34ff65
2 changed files with 60 additions and 7 deletions

View File

@@ -22,10 +22,16 @@ class ScheduleConfig {
// 单日操作限制 // 单日操作限制
this.dailyLimits = { this.dailyLimits = {
maxSearch: 20, // 每天最多搜索20次 maxSearch: 20, // 每天最多搜索20次
maxApply: 50, // 每天最多投递50份简历 maxApply: 50, // 每天最多投递50份简历(默认值)
maxChat: 100, // 每天最多发送100条聊天 maxChat: 100, // 每天最多发送100条聊天
}; };
// 平台特定的每日投递限制
this.platformDailyLimits = {
boss: 150, // Boss直聘每天最多投递150次
liepin: 50 // 猎聘每天最多投递50次默认值
};
// 任务超时配置(毫秒) // 任务超时配置(毫秒)
this.taskTimeouts = { this.taskTimeouts = {
auto_deliver: 30 * 60 * 1000, // 自动投递任务30分钟包含多个子任务 auto_deliver: 30 * 60 * 1000, // 自动投递任务30分钟包含多个子任务
@@ -102,9 +108,15 @@ class ScheduleConfig {
/** /**
* 获取日限制 * 获取日限制
* @param {string} operation - 操作类型 * @param {string} operation - 操作类型
* @param {string} platform - 平台类型(可选,用于平台特定的限制)
* @returns {number} 日限制次数 * @returns {number} 日限制次数
*/ */
getDailyLimit(operation) { getDailyLimit(operation, platform = null) {
// 如果是投递操作且指定了平台,使用平台特定的限制
if (operation === 'apply' && platform && this.platformDailyLimits[platform]) {
return this.platformDailyLimits[platform];
}
// 否则使用通用限制
return this.dailyLimits[`max${operation.charAt(0).toUpperCase() + operation.slice(1)}`] || Infinity; return this.dailyLimits[`max${operation.charAt(0).toUpperCase() + operation.slice(1)}`] || Infinity;
} }
} }

View File

@@ -56,6 +56,48 @@ class TaskHandlers {
const pla_account = db.getModel('pla_account'); const pla_account = db.getModel('pla_account');
const resume_info = db.getModel('resume_info'); const resume_info = db.getModel('resume_info');
const job_types = db.getModel('job_types'); const job_types = db.getModel('job_types');
const apply_records = db.getModel('apply_records');
const Sequelize = require('sequelize');
const { op } = Sequelize;
// 检查今日投递次数限制
const currentPlatform = platform || 'boss';
const dailyLimit = config.getDailyLimit('apply', currentPlatform);
// 获取今日开始时间00:00:00
const today = new Date();
today.setHours(0, 0, 0, 0);
// 查询今日已投递次数
const todayApplyCount = await apply_records.count({
where: {
sn_code: sn_code,
platform: currentPlatform,
applyTime: {
[op.gte]: today
}
}
});
console.log(`[任务处理器] 今日已投递 ${todayApplyCount} 次,限制: ${dailyLimit}`);
// 如果已达到每日投递上限,则跳过
if (todayApplyCount >= dailyLimit) {
console.log(`[任务处理器] 已达到每日投递上限(${dailyLimit}次),跳过投递`);
return {
success: false,
deliveredCount: 0,
message: `已达到每日投递上限(${dailyLimit}次),今日已投递 ${todayApplyCount}`
};
}
// 计算本次可投递的数量(不超过剩余限额)
const remainingQuota = dailyLimit - todayApplyCount;
const actualMaxCount = Math.min(maxCount || 10, remainingQuota);
if (actualMaxCount < (maxCount || 10)) {
console.log(`[任务处理器] 受每日投递上限限制,本次最多投递 ${actualMaxCount} 个职位(剩余限额: ${remainingQuota}`);
}
// 1. 检查并获取在线简历如果2小时内没有获取 // 1. 检查并获取在线简历如果2小时内没有获取
const twoHoursAgo = new Date(Date.now() - 2 * 60 * 60 * 1000); const twoHoursAgo = new Date(Date.now() - 2 * 60 * 60 * 1000);
@@ -167,7 +209,7 @@ class TaskHandlers {
applyStatus: 'pending' applyStatus: 'pending'
}, },
order: [['create_time', 'DESC']], order: [['create_time', 'DESC']],
limit: (maxCount || 10) * 3 // 获取更多职位用于筛选 limit: actualMaxCount * 3 // 获取更多职位用于筛选(受每日投递上限限制)
}); });
if (!pendingJobs || pendingJobs.length === 0) { if (!pendingJobs || pendingJobs.length === 0) {
@@ -199,8 +241,7 @@ class TaskHandlers {
const maxSalary = filterRules.maxSalary || 0; const maxSalary = filterRules.maxSalary || 0;
// 获取一个月内已投递的公司列表(用于过滤) // 获取一个月内已投递的公司列表(用于过滤)
const apply_records = db.getModel('apply_records'); // 注意:apply_records 和 Sequelize 已在方法开头定义
const Sequelize = require('sequelize');
const oneMonthAgo = new Date(); const oneMonthAgo = new Date();
oneMonthAgo.setMonth(oneMonthAgo.getMonth() - 1); oneMonthAgo.setMonth(oneMonthAgo.getMonth() - 1);
@@ -287,8 +328,8 @@ class TaskHandlers {
// 按总分降序排序 // 按总分降序排序
scoredJobs.sort((a, b) => b.matchScore - a.matchScore); scoredJobs.sort((a, b) => b.matchScore - a.matchScore);
// 取前 maxCount 个职位 // 取前 actualMaxCount 个职位(受每日投递上限限制)
const jobsToDeliver = scoredJobs.slice(0, maxCount || 10); const jobsToDeliver = scoredJobs.slice(0, actualMaxCount);
console.log(`[任务处理器] 职位评分完成,共 ${pendingJobs.length} 个职位,评分后 ${scoredJobs.length} 个符合条件,将投递 ${jobsToDeliver.length}`); console.log(`[任务处理器] 职位评分完成,共 ${pendingJobs.length} 个职位,评分后 ${scoredJobs.length} 个符合条件,将投递 ${jobsToDeliver.length}`);