This commit is contained in:
张成
2026-03-17 10:50:49 +08:00
parent f5082c157c
commit f071215ad5
3 changed files with 103 additions and 10 deletions

View File

@@ -205,17 +205,27 @@ class ChatManager {
return false; return false;
} }
/** 统一 uid 为可比较的字符串(支持 number 或 { low, high } */
_normalizeUid(uid) {
if (uid == null) return null;
if (typeof uid === 'number' || typeof uid === 'string') return String(uid);
if (typeof uid === 'object' && typeof uid.low === 'number') return String(uid.low);
return null;
}
/** 过滤出 HR 发的、非系统、可回复的消息列表(已排除自己发的) */ /** 过滤出 HR 发的、非系统、可回复的消息列表(已排除自己发的) */
_filterHrReplyableMessages(messages, geek_uid) { _filterHrReplyableMessages(messages, geek_uid) {
if (!geek_uid || !Array.isArray(messages)) return []; if (!geek_uid || !Array.isArray(messages)) return [];
let list = messages.filter(msg => { const geekStr = this._normalizeUid(geek_uid);
if (!msg.from || msg.from.uid === geek_uid) return false; if (!geekStr) return [];
const list = messages.filter(msg => {
if (!msg.from) return false;
const fromStr = this._normalizeUid(msg.from.uid);
if (fromStr === geekStr) return false; // 自己发的,排除
if (this._isSystemMessage(msg)) return false; if (this._isSystemMessage(msg)) return false;
return true; return true;
}); });
return list;
return list
} }
/** AI 回复后写入 chat_reply_intent_logoptions 含 sn_code/platform/friendId/encryptFriendIdsecurityId 为 HR 消息唯一 id */ /** AI 回复后写入 chat_reply_intent_logoptions 含 sn_code/platform/friendId/encryptFriendIdsecurityId 为 HR 消息唯一 id */
@@ -299,12 +309,14 @@ class ChatManager {
const logModel = db.getModel('chat_reply_intent_log'); const logModel = db.getModel('chat_reply_intent_log');
const existing = await logModel.findOne({ where: { security_id } }); const existing = await logModel.findOne({ where: { security_id } });
if (existing) { if (existing) {
// 已回复过的 HR 消息:不再重复发,避免每次扫描都发一条
if (existing.replied) {
return { replied: false, reason: '该条HR消息已回复过跳过' };
}
// 之前记录为不回复:直接沿用,不再调 AI
return { return {
replied: !!existing.replied, replied: false,
action: existing.action || 'text', reason: existing.reason || '已记录为不回复'
reply_content: existing.reply_content || '',
hr_message_text: existing.hr_message_text || hr_message_text,
reason: existing.reason || null
}; };
} }
} catch (e) { } catch (e) {

View File

@@ -13,6 +13,8 @@ class MqttDispatcher {
this.mqttClient = mqttClient; this.mqttClient = mqttClient;
this.actionHandlers = new Map(); this.actionHandlers = new Map();
this.subscribedTopics = new Set(); this.subscribedTopics = new Set();
// 去重防抖:记录最近处理过的 Boss 消息 securityId -> timestamp
this.bossMessageDedupMap = new Map();
} }
/** /**
@@ -345,6 +347,23 @@ class MqttDispatcher {
raw: payload raw: payload
}; };
// 去重防抖:按 securityId或 cmid在一定时间窗口内只处理一次
const securityId = firstMsg && firstMsg.securityId;
const cmidObj = firstMsg && firstMsg.cmid;
const cmid = cmidObj && typeof cmidObj.low === 'number' ? `${cmidObj.high}:${cmidObj.low}` : null;
const dedupKey = securityId || cmid;
const now = Date.now();
const windowMs = 2 * 60 * 1000; // 2 分钟内视为重复
if (dedupKey) {
const lastTs = this.bossMessageDedupMap.get(dedupKey);
if (lastTs && now - lastTs < windowMs) {
console.log('[MQTT Boss 消息] 检测到重复消息,跳过处理:', { sn_code, dedupKey });
return;
}
this.bossMessageDedupMap.set(dedupKey, now);
}
console.log('[MQTT Boss 消息] 解析结果:', { console.log('[MQTT Boss 消息] 解析结果:', {
sn_code: normalized.sn_code, sn_code: normalized.sn_code,
type: normalized.type, type: normalized.type,

File diff suppressed because one or more lines are too long