From 5d1e34ff656530d5c32879489725626bf7f3f4d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=88=90?= Date: Wed, 10 Dec 2025 09:58:22 +0800 Subject: [PATCH] 1 --- api/middleware/schedule/config.js | 16 +++++++- api/middleware/schedule/taskHandlers.js | 51 ++++++++++++++++++++++--- 2 files changed, 60 insertions(+), 7 deletions(-) diff --git a/api/middleware/schedule/config.js b/api/middleware/schedule/config.js index 0591c85..0ae135e 100644 --- a/api/middleware/schedule/config.js +++ b/api/middleware/schedule/config.js @@ -22,10 +22,16 @@ class ScheduleConfig { // 单日操作限制 this.dailyLimits = { maxSearch: 20, // 每天最多搜索20次 - maxApply: 50, // 每天最多投递50份简历 + maxApply: 50, // 每天最多投递50份简历(默认值) maxChat: 100, // 每天最多发送100条聊天 }; + // 平台特定的每日投递限制 + this.platformDailyLimits = { + boss: 150, // Boss直聘:每天最多投递150次 + liepin: 50 // 猎聘:每天最多投递50次(默认值) + }; + // 任务超时配置(毫秒) this.taskTimeouts = { auto_deliver: 30 * 60 * 1000, // 自动投递任务:30分钟(包含多个子任务) @@ -102,9 +108,15 @@ class ScheduleConfig { /** * 获取日限制 * @param {string} operation - 操作类型 + * @param {string} platform - 平台类型(可选,用于平台特定的限制) * @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; } } diff --git a/api/middleware/schedule/taskHandlers.js b/api/middleware/schedule/taskHandlers.js index 1fdf1ac..89cadf8 100644 --- a/api/middleware/schedule/taskHandlers.js +++ b/api/middleware/schedule/taskHandlers.js @@ -56,6 +56,48 @@ class TaskHandlers { const pla_account = db.getModel('pla_account'); const resume_info = db.getModel('resume_info'); 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小时内没有获取) const twoHoursAgo = new Date(Date.now() - 2 * 60 * 60 * 1000); @@ -167,7 +209,7 @@ class TaskHandlers { applyStatus: 'pending' }, order: [['create_time', 'DESC']], - limit: (maxCount || 10) * 3 // 获取更多职位用于筛选 + limit: actualMaxCount * 3 // 获取更多职位用于筛选(受每日投递上限限制) }); if (!pendingJobs || pendingJobs.length === 0) { @@ -199,8 +241,7 @@ class TaskHandlers { const maxSalary = filterRules.maxSalary || 0; // 获取一个月内已投递的公司列表(用于过滤) - const apply_records = db.getModel('apply_records'); - const Sequelize = require('sequelize'); + // 注意:apply_records 和 Sequelize 已在方法开头定义 const oneMonthAgo = new Date(); oneMonthAgo.setMonth(oneMonthAgo.getMonth() - 1); @@ -287,8 +328,8 @@ class TaskHandlers { // 按总分降序排序 scoredJobs.sort((a, b) => b.matchScore - a.matchScore); - // 取前 maxCount 个职位 - const jobsToDeliver = scoredJobs.slice(0, maxCount || 10); + // 取前 actualMaxCount 个职位(受每日投递上限限制) + const jobsToDeliver = scoredJobs.slice(0, actualMaxCount); console.log(`[任务处理器] 职位评分完成,共 ${pendingJobs.length} 个职位,评分后 ${scoredJobs.length} 个符合条件,将投递 ${jobsToDeliver.length} 个`);