1
This commit is contained in:
@@ -212,8 +212,6 @@ class MqttDispatcher {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`[MQTT心跳] 收到设备 ${sn_code} 的心跳消息`);
|
|
||||||
|
|
||||||
// 移除 device_status 模型依赖
|
// 移除 device_status 模型依赖
|
||||||
// const device_status = db.getModel('device_status');
|
// const device_status = db.getModel('device_status');
|
||||||
// let device = await device_status.findByPk(sn_code);
|
// let device = await device_status.findByPk(sn_code);
|
||||||
@@ -286,7 +284,6 @@ class MqttDispatcher {
|
|||||||
},
|
},
|
||||||
{ where: { sn_code } }
|
{ where: { sn_code } }
|
||||||
);
|
);
|
||||||
console.log(`[MQTT心跳] 设备 ${sn_code} 状态已更新到数据库 - 在线: true, 登录: ${updateData.isLoggedIn || false}`);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`[MQTT心跳] 更新数据库状态失败:`, error);
|
console.error(`[MQTT心跳] 更新数据库状态失败:`, error);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ class ScheduleConfig {
|
|||||||
dailyReset: '0 0 * * *', // 每天凌晨重置统计
|
dailyReset: '0 0 * * *', // 每天凌晨重置统计
|
||||||
monitoringInterval: '*/1 * * * *', // 监控检查间隔:1分钟
|
monitoringInterval: '*/1 * * * *', // 监控检查间隔:1分钟
|
||||||
autoSearch: '0 0 */1 * * *', // 自动搜索任务:每1小时执行一次
|
autoSearch: '0 0 */1 * * *', // 自动搜索任务:每1小时执行一次
|
||||||
autoDeliver: '0 */1 * * * *', // 自动投递任务:每1分钟执行一次
|
autoDeliver: '0 */2 * * * *', // 自动投递任务:每2分钟执行一次
|
||||||
autoChat: '0 */15 * * * *', // 自动沟通任务:每15分钟执行一次
|
autoChat: '0 */15 * * * *', // 自动沟通任务:每15分钟执行一次
|
||||||
autoActive: '0 0 */2 * * *' // 自动活跃任务:每2小时执行一次
|
autoActive: '0 0 */2 * * *' // 自动活跃任务:每2小时执行一次
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -131,7 +131,6 @@ class AutoActiveTask extends BaseTask {
|
|||||||
// 5. 执行所有层级的冲突检查
|
// 5. 执行所有层级的冲突检查
|
||||||
const conflictCheck = await this.canExecuteTask(sn_code, taskQueue);
|
const conflictCheck = await this.canExecuteTask(sn_code, taskQueue);
|
||||||
if (!conflictCheck.allowed) {
|
if (!conflictCheck.allowed) {
|
||||||
console.log(`[自动活跃] 设备 ${sn_code} 冲突检查未通过: ${conflictCheck.reason}`);
|
|
||||||
return { success: false, reason: conflictCheck.reason };
|
return { success: false, reason: conflictCheck.reason };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -130,7 +130,6 @@ class AutoChatTask extends BaseTask {
|
|||||||
// 5. 执行所有层级的冲突检查
|
// 5. 执行所有层级的冲突检查
|
||||||
const conflictCheck = await this.canExecuteTask(sn_code, taskQueue);
|
const conflictCheck = await this.canExecuteTask(sn_code, taskQueue);
|
||||||
if (!conflictCheck.allowed) {
|
if (!conflictCheck.allowed) {
|
||||||
console.log(`[自动沟通] 设备 ${sn_code} 冲突检查未通过: ${conflictCheck.reason}`);
|
|
||||||
return { success: false, reason: conflictCheck.reason };
|
return { success: false, reason: conflictCheck.reason };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -238,7 +238,6 @@ class AutoDeliverTask extends BaseTask {
|
|||||||
// 5. 执行所有层级的冲突检查
|
// 5. 执行所有层级的冲突检查
|
||||||
const conflictCheck = await this.canExecuteTask(sn_code, taskQueue);
|
const conflictCheck = await this.canExecuteTask(sn_code, taskQueue);
|
||||||
if (!conflictCheck.allowed) {
|
if (!conflictCheck.allowed) {
|
||||||
console.log(`[自动投递] 设备 ${sn_code} 冲突检查未通过: ${conflictCheck.reason}`);
|
|
||||||
return { success: false, reason: conflictCheck.reason };
|
return { success: false, reason: conflictCheck.reason };
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -305,7 +304,7 @@ class AutoDeliverTask extends BaseTask {
|
|||||||
*/
|
*/
|
||||||
async notifyWaitingStatus(sn_code, intervalCheck, taskQueue) {
|
async notifyWaitingStatus(sn_code, intervalCheck, taskQueue) {
|
||||||
try {
|
try {
|
||||||
const deviceWorkStatusNotifier = require('../deviceWorkStatusNotifier');
|
const deviceWorkStatusNotifier = require('../notifiers/deviceWorkStatusNotifier');
|
||||||
|
|
||||||
// 获取当前任务状态摘要
|
// 获取当前任务状态摘要
|
||||||
const taskStatusSummary = taskQueue.getTaskStatusSummary(sn_code);
|
const taskStatusSummary = taskQueue.getTaskStatusSummary(sn_code);
|
||||||
|
|||||||
@@ -176,7 +176,6 @@ class AutoSearchTask extends BaseTask {
|
|||||||
// 5. 执行所有层级的冲突检查
|
// 5. 执行所有层级的冲突检查
|
||||||
const conflictCheck = await this.canExecuteTask(sn_code, taskQueue);
|
const conflictCheck = await this.canExecuteTask(sn_code, taskQueue);
|
||||||
if (!conflictCheck.allowed) {
|
if (!conflictCheck.allowed) {
|
||||||
console.log(`[自动搜索] 设备 ${sn_code} 冲突检查未通过: ${conflictCheck.reason}`);
|
|
||||||
return { success: false, reason: conflictCheck.reason };
|
return { success: false, reason: conflictCheck.reason };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -61,16 +61,53 @@ class BaseTask {
|
|||||||
* 检查设备是否在线、是否登录、是否忙碌
|
* 检查设备是否在线、是否登录、是否忙碌
|
||||||
*/
|
*/
|
||||||
async checkDeviceStatus(sn_code) {
|
async checkDeviceStatus(sn_code) {
|
||||||
// 1. 检查设备是否在线
|
// 1. 优先检查内存中的设备状态
|
||||||
const device = deviceManager.devices.get(sn_code);
|
let device = deviceManager.devices.get(sn_code);
|
||||||
|
|
||||||
|
// 2. 如果内存中没有,降级到数据库查询(可能是刚启动还没收到心跳)
|
||||||
if (!device) {
|
if (!device) {
|
||||||
|
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 {
|
return {
|
||||||
allowed: false,
|
allowed: false,
|
||||||
reason: `设备 ${sn_code} 离线(从未发送心跳)`
|
reason: `设备 ${sn_code} 不存在`
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. 检查心跳超时
|
// 检查数据库中的在线状态
|
||||||
|
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} 状态查询失败`
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. 检查心跳超时
|
||||||
const offlineThreshold = 3 * 60 * 1000; // 3分钟
|
const offlineThreshold = 3 * 60 * 1000; // 3分钟
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
const lastHeartbeat = device.lastHeartbeat || 0;
|
const lastHeartbeat = device.lastHeartbeat || 0;
|
||||||
@@ -84,7 +121,7 @@ class BaseTask {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. 检查登录状态(如果任务需要)
|
// 4. 检查登录状态(如果任务需要)
|
||||||
if (this.config.requiresLogin && !device.isLoggedIn) {
|
if (this.config.requiresLogin && !device.isLoggedIn) {
|
||||||
return {
|
return {
|
||||||
allowed: false,
|
allowed: false,
|
||||||
|
|||||||
Reference in New Issue
Block a user