This commit is contained in:
张成
2025-12-30 16:45:09 +08:00
parent fb9aa5b155
commit 914999c9fc
7 changed files with 47 additions and 17 deletions

View File

@@ -49,7 +49,7 @@ class ScheduleConfig {
dailyReset: '0 0 * * *', // 每天凌晨重置统计
monitoringInterval: '*/1 * * * *', // 监控检查间隔1分钟
autoSearch: '0 0 */1 * * *', // 自动搜索任务每1小时执行一次
autoDeliver: '0 */1 * * * *', // 自动投递任务:每1分钟执行一次
autoDeliver: '0 */2 * * * *', // 自动投递任务:每2分钟执行一次
autoChat: '0 */15 * * * *', // 自动沟通任务每15分钟执行一次
autoActive: '0 0 */2 * * *' // 自动活跃任务每2小时执行一次
};

View File

@@ -131,7 +131,6 @@ class AutoActiveTask extends BaseTask {
// 5. 执行所有层级的冲突检查
const conflictCheck = await this.canExecuteTask(sn_code, taskQueue);
if (!conflictCheck.allowed) {
console.log(`[自动活跃] 设备 ${sn_code} 冲突检查未通过: ${conflictCheck.reason}`);
return { success: false, reason: conflictCheck.reason };
}

View File

@@ -130,7 +130,6 @@ class AutoChatTask extends BaseTask {
// 5. 执行所有层级的冲突检查
const conflictCheck = await this.canExecuteTask(sn_code, taskQueue);
if (!conflictCheck.allowed) {
console.log(`[自动沟通] 设备 ${sn_code} 冲突检查未通过: ${conflictCheck.reason}`);
return { success: false, reason: conflictCheck.reason };
}

View File

@@ -238,7 +238,6 @@ class AutoDeliverTask extends BaseTask {
// 5. 执行所有层级的冲突检查
const conflictCheck = await this.canExecuteTask(sn_code, taskQueue);
if (!conflictCheck.allowed) {
console.log(`[自动投递] 设备 ${sn_code} 冲突检查未通过: ${conflictCheck.reason}`);
return { success: false, reason: conflictCheck.reason };
}
@@ -305,7 +304,7 @@ class AutoDeliverTask extends BaseTask {
*/
async notifyWaitingStatus(sn_code, intervalCheck, taskQueue) {
try {
const deviceWorkStatusNotifier = require('../deviceWorkStatusNotifier');
const deviceWorkStatusNotifier = require('../notifiers/deviceWorkStatusNotifier');
// 获取当前任务状态摘要
const taskStatusSummary = taskQueue.getTaskStatusSummary(sn_code);

View File

@@ -176,7 +176,6 @@ class AutoSearchTask extends BaseTask {
// 5. 执行所有层级的冲突检查
const conflictCheck = await this.canExecuteTask(sn_code, taskQueue);
if (!conflictCheck.allowed) {
console.log(`[自动搜索] 设备 ${sn_code} 冲突检查未通过: ${conflictCheck.reason}`);
return { success: false, reason: conflictCheck.reason };
}

View File

@@ -61,16 +61,53 @@ class BaseTask {
* 检查设备是否在线、是否登录、是否忙碌
*/
async checkDeviceStatus(sn_code) {
// 1. 检查设备是否在线
const device = deviceManager.devices.get(sn_code);
// 1. 优先检查内存中的设备状态
let device = deviceManager.devices.get(sn_code);
// 2. 如果内存中没有,降级到数据库查询(可能是刚启动还没收到心跳)
if (!device) {
return {
allowed: false,
reason: `设备 ${sn_code} 离线(从未发送心跳)`
};
try {
const pla_account = db.getModel('pla_account');
const dbDevice = await pla_account.findOne({
where: { sn_code, is_delete: 0 },
attributes: ['sn_code', 'is_online', 'is_logged_in']
});
if (!dbDevice) {
return {
allowed: false,
reason: `设备 ${sn_code} 不存在`
};
}
// 检查数据库中的在线状态
if (!dbDevice.is_online) {
return {
allowed: false,
reason: `设备 ${sn_code} 离线(数据库状态)`
};
}
// 检查数据库中的登录状态
if (this.config.requiresLogin && !dbDevice.is_logged_in) {
return {
allowed: false,
reason: `设备 ${sn_code} 未登录平台账号(数据库状态)`
};
}
// 数据库检查通过,允许执行
return { allowed: true };
} catch (error) {
console.error(`[${this.taskType}] 查询设备状态失败:`, error);
return {
allowed: false,
reason: `设备 ${sn_code} 状态查询失败`
};
}
}
// 2. 检查心跳超时
// 3. 检查心跳超时
const offlineThreshold = 3 * 60 * 1000; // 3分钟
const now = Date.now();
const lastHeartbeat = device.lastHeartbeat || 0;
@@ -84,7 +121,7 @@ class BaseTask {
};
}
// 3. 检查登录状态(如果任务需要)
// 4. 检查登录状态(如果任务需要)
if (this.config.requiresLogin && !device.isLoggedIn) {
return {
allowed: false,