11
This commit is contained in:
@@ -109,6 +109,11 @@ class DeviceWorkStatusNotifier {
|
||||
};
|
||||
}
|
||||
|
||||
// 如果有等待消息(投递间隔等待等),添加到工作状态
|
||||
if (options.waitingMessage) {
|
||||
workStatus.waitingMessage = options.waitingMessage;
|
||||
}
|
||||
|
||||
// 格式化显示文案(服务端统一处理,客户端直接显示)
|
||||
workStatus.displayText = this._formatDisplayText(workStatus);
|
||||
|
||||
@@ -141,24 +146,37 @@ class DeviceWorkStatusNotifier {
|
||||
// 通过MQTT发布设备工作状态
|
||||
// 主题格式: device_work_status_{sn_code}
|
||||
const topic = `device_work_status_${sn_code}`;
|
||||
const message = JSON.stringify({
|
||||
const messagePayload = {
|
||||
action: 'device_work_status',
|
||||
data: workStatus,
|
||||
timestamp: new Date().toISOString()
|
||||
});
|
||||
};
|
||||
const message = JSON.stringify(messagePayload);
|
||||
|
||||
await mqttClient.publish(topic, message);
|
||||
|
||||
// 输出详细日志
|
||||
console.log(`[设备工作状态] 已推送到 ${sn_code}:`);
|
||||
console.log(` - Topic: ${topic}`);
|
||||
console.log(` - 显示文本: ${workStatus.displayText}`);
|
||||
|
||||
if (workStatus.currentActivity) {
|
||||
const activity = workStatus.currentActivity;
|
||||
const activityInfo = activity.type === 'command'
|
||||
? `指令[${activity.name}]`
|
||||
: `任务[${activity.name}]`;
|
||||
console.log(`[设备工作状态] 已推送到 ${sn_code}: ${activityInfo} - ${workStatus.displayText}`);
|
||||
console.log(` - 当前活动: ${activityInfo}`);
|
||||
} else {
|
||||
console.log(`[设备工作状态] 已推送到 ${sn_code}: ${workStatus.displayText}`);
|
||||
console.log(` - 当前活动: 无`);
|
||||
}
|
||||
|
||||
if (workStatus.waitingMessage) {
|
||||
console.log(` - 等待消息: ${workStatus.waitingMessage.message}`);
|
||||
}
|
||||
|
||||
console.log(` - 待执行: ${workStatus.pendingQueue.totalCount}个`);
|
||||
console.log(` - 下次执行: ${workStatus.pendingQueue.nextExecuteTimeText}`);
|
||||
console.log(` - 消息大小: ${message.length} 字节`);
|
||||
} catch (error) {
|
||||
// 通知失败不影响任务执行,只记录日志
|
||||
console.warn(`[设备工作状态] 推送失败:`, error.message);
|
||||
@@ -270,6 +288,11 @@ class DeviceWorkStatusNotifier {
|
||||
parts.push('当前活动: 无');
|
||||
}
|
||||
|
||||
// 如果有等待消息,添加到显示文本
|
||||
if (workStatus.waitingMessage) {
|
||||
parts.push(workStatus.waitingMessage.message);
|
||||
}
|
||||
|
||||
// 待执行数量
|
||||
parts.push(`待执行: ${workStatus.pendingQueue.totalCount}个`);
|
||||
|
||||
|
||||
@@ -572,7 +572,35 @@ class ScheduledJobs {
|
||||
|
||||
if (elapsedTime < interval_ms) {
|
||||
const remainingMinutes = Math.ceil((interval_ms - elapsedTime) / (60 * 1000));
|
||||
console.log(`[自动投递] 设备 ${userData.sn_code} 距离上次投递仅 ${Math.round(elapsedTime / (60 * 1000))} 分钟,还需等待 ${remainingMinutes} 分钟(间隔: ${deliver_interval} 分钟)`);
|
||||
const elapsedMinutes = Math.round(elapsedTime / (60 * 1000));
|
||||
const message = `距离上次投递仅 ${elapsedMinutes} 分钟,还需等待 ${remainingMinutes} 分钟(间隔: ${deliver_interval} 分钟)`;
|
||||
console.log(`[自动投递] 设备 ${userData.sn_code} ${message}`);
|
||||
|
||||
// 推送等待状态到客户端
|
||||
try {
|
||||
const deviceWorkStatusNotifier = require('./deviceWorkStatusNotifier');
|
||||
|
||||
// 获取当前任务状态摘要
|
||||
const taskStatusSummary = this.taskQueue ? this.taskQueue.getTaskStatusSummary(userData.sn_code) : {
|
||||
sn_code: userData.sn_code,
|
||||
pendingCount: 0,
|
||||
totalPendingCount: 0,
|
||||
pendingTasks: []
|
||||
};
|
||||
|
||||
// 添加等待消息到工作状态
|
||||
await deviceWorkStatusNotifier.sendDeviceWorkStatus(userData.sn_code, taskStatusSummary, {
|
||||
waitingMessage: {
|
||||
type: 'deliver_interval',
|
||||
message: message,
|
||||
remainingMinutes: remainingMinutes,
|
||||
nextDeliverTime: new Date(lastDeliverTime.getTime() + interval_ms).toISOString()
|
||||
}
|
||||
});
|
||||
} catch (pushError) {
|
||||
console.warn(`[自动投递] 推送等待消息失败:`, pushError.message);
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user