1
This commit is contained in:
@@ -166,6 +166,25 @@ class TaskHandlers {
|
||||
const accountConfig = account.toJSON();
|
||||
const resumeInfo = resume.toJSON();
|
||||
|
||||
// 检查投递时间范围
|
||||
if (accountConfig.deliver_config) {
|
||||
const deliverConfig = typeof accountConfig.deliver_config === 'string'
|
||||
? JSON.parse(accountConfig.deliver_config)
|
||||
: accountConfig.deliver_config;
|
||||
|
||||
if (deliverConfig.time_range) {
|
||||
const timeCheck = this.checkTimeRange(deliverConfig.time_range);
|
||||
if (!timeCheck.allowed) {
|
||||
console.log(`[任务处理器] 自动投递任务 - ${timeCheck.reason}`);
|
||||
return {
|
||||
success: true,
|
||||
deliveredCount: 0,
|
||||
message: timeCheck.reason
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 获取职位类型配置
|
||||
let jobTypeConfig = null;
|
||||
if (accountConfig.job_type_id) {
|
||||
@@ -471,6 +490,51 @@ class TaskHandlers {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查当前时间是否在指定的时间范围内
|
||||
* @param {Object} timeRange - 时间范围配置 {start_time: '09:00', end_time: '18:00', workdays_only: 1}
|
||||
* @returns {Object} {allowed: boolean, reason: string}
|
||||
*/
|
||||
checkTimeRange(timeRange) {
|
||||
if (!timeRange || !timeRange.start_time || !timeRange.end_time) {
|
||||
return { allowed: true, reason: '未配置时间范围' };
|
||||
}
|
||||
|
||||
const now = new Date();
|
||||
const currentHour = now.getHours();
|
||||
const currentMinute = now.getMinutes();
|
||||
const currentTime = currentHour * 60 + currentMinute; // 转换为分钟数
|
||||
|
||||
// 解析开始时间和结束时间
|
||||
const [startHour, startMinute] = timeRange.start_time.split(':').map(Number);
|
||||
const [endHour, endMinute] = timeRange.end_time.split(':').map(Number);
|
||||
const startTime = startHour * 60 + startMinute;
|
||||
const endTime = endHour * 60 + endMinute;
|
||||
|
||||
// 检查是否仅工作日
|
||||
if (timeRange.workdays_only === 1) {
|
||||
const dayOfWeek = now.getDay(); // 0=周日, 1=周一, ..., 6=周六
|
||||
if (dayOfWeek === 0 || dayOfWeek === 6) {
|
||||
return { allowed: false, reason: '当前是周末,不在允许的时间范围内' };
|
||||
}
|
||||
}
|
||||
|
||||
// 检查当前时间是否在时间范围内
|
||||
if (startTime <= endTime) {
|
||||
// 正常情况:09:00 - 18:00
|
||||
if (currentTime < startTime || currentTime >= endTime) {
|
||||
return { allowed: false, reason: `当前时间 ${now.getHours().toString().padStart(2, '0')}:${now.getMinutes().toString().padStart(2, '0')} 不在允许的时间范围内 (${timeRange.start_time} - ${timeRange.end_time})` };
|
||||
}
|
||||
} else {
|
||||
// 跨天情况:22:00 - 06:00
|
||||
if (currentTime < startTime && currentTime >= endTime) {
|
||||
return { allowed: false, reason: `当前时间 ${now.getHours().toString().padStart(2, '0')}:${now.getMinutes().toString().padStart(2, '0')} 不在允许的时间范围内 (${timeRange.start_time} - ${timeRange.end_time})` };
|
||||
}
|
||||
}
|
||||
|
||||
return { allowed: true, reason: '在允许的时间范围内' };
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理自动沟通任务(待实现)
|
||||
* 功能:自动与HR进行沟通,回复消息等
|
||||
@@ -483,6 +547,49 @@ class TaskHandlers {
|
||||
const startTime = Date.now();
|
||||
|
||||
try {
|
||||
// 获取账号配置
|
||||
const pla_account = db.getModel('pla_account');
|
||||
const account = await pla_account.findOne({
|
||||
where: { sn_code: sn_code }
|
||||
});
|
||||
|
||||
if (!account) {
|
||||
throw new Error(`账号不存在: ${sn_code}`);
|
||||
}
|
||||
|
||||
const accountData = account.toJSON();
|
||||
|
||||
// 检查是否开启自动沟通
|
||||
if (!accountData.auto_chat) {
|
||||
console.log(`[任务处理器] 设备 ${sn_code} 未开启自动沟通`);
|
||||
return {
|
||||
success: true,
|
||||
message: '未开启自动沟通',
|
||||
chatCount: 0
|
||||
};
|
||||
}
|
||||
|
||||
// 解析沟通策略配置
|
||||
let chatStrategy = {};
|
||||
if (accountData.chat_strategy) {
|
||||
chatStrategy = typeof accountData.chat_strategy === 'string'
|
||||
? JSON.parse(accountData.chat_strategy)
|
||||
: accountData.chat_strategy;
|
||||
}
|
||||
|
||||
// 检查沟通时间范围
|
||||
if (chatStrategy.time_range) {
|
||||
const timeCheck = this.checkTimeRange(chatStrategy.time_range);
|
||||
if (!timeCheck.allowed) {
|
||||
console.log(`[任务处理器] 自动沟通任务 - ${timeCheck.reason}`);
|
||||
return {
|
||||
success: true,
|
||||
message: timeCheck.reason,
|
||||
chatCount: 0
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: 实现自动沟通逻辑
|
||||
// 1. 获取待回复的聊天列表
|
||||
// 2. 根据消息内容生成回复
|
||||
|
||||
Reference in New Issue
Block a user