1
This commit is contained in:
@@ -6,18 +6,7 @@ const dayjs = require('dayjs');
|
||||
*/
|
||||
class ScheduleConfig {
|
||||
constructor() {
|
||||
// 工作时间配置
|
||||
this.workHours = {
|
||||
start: 6,
|
||||
end: 23
|
||||
};
|
||||
|
||||
// 频率限制配置(毫秒)
|
||||
this.rateLimits = {
|
||||
search: 30 * 60 * 1000, // 搜索间隔:30分钟
|
||||
apply: 5 * 60 * 1000, // 投递间隔:5分钟
|
||||
chat: 1 * 60 * 1000, // 聊天间隔:1分钟
|
||||
};
|
||||
|
||||
|
||||
// 单日操作限制
|
||||
this.dailyLimits = {
|
||||
@@ -62,15 +51,6 @@ class ScheduleConfig {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否在工作时间
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isWorkingHours() {
|
||||
const now = dayjs();
|
||||
const hour = now.hour();
|
||||
return hour >= this.workHours.start && hour < this.workHours.end;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取任务超时时间
|
||||
@@ -97,15 +77,6 @@ class ScheduleConfig {
|
||||
return priority;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取操作频率限制
|
||||
* @param {string} operation - 操作类型
|
||||
* @returns {number} 间隔时间(毫秒)
|
||||
*/
|
||||
getRateLimit(operation) {
|
||||
return this.rateLimits[operation] || 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取日限制
|
||||
* @param {string} operation - 操作类型
|
||||
|
||||
@@ -100,19 +100,8 @@ class DeviceManager {
|
||||
* 检查是否可以执行操作
|
||||
*/
|
||||
canExecuteOperation(sn_code, operation_type) {
|
||||
|
||||
|
||||
// 检查频率限制
|
||||
// 检查日限制(频率限制已由各任务使用账号配置中的间隔时间,不再使用全局配置)
|
||||
const device = this.devices.get(sn_code);
|
||||
if (device) {
|
||||
const lastTime = device[`last${operation_type.charAt(0).toUpperCase() + operation_type.slice(1)}`] || 0;
|
||||
const interval = config.getRateLimit(operation_type);
|
||||
if (Date.now() - lastTime < interval) {
|
||||
return { allowed: false, reason: '操作过于频繁' };
|
||||
}
|
||||
}
|
||||
|
||||
// 检查日限制
|
||||
if (device && device.dailyCounts) {
|
||||
const today = utils.getTodayString();
|
||||
if (device.dailyCounts.date !== today) {
|
||||
|
||||
Reference in New Issue
Block a user