This commit is contained in:
张成
2026-02-28 17:58:03 +08:00
parent a40219c7e4
commit 8a953eb769
2 changed files with 33 additions and 9 deletions

View File

@@ -218,8 +218,8 @@ class ChatManager {
}
/** AI 回复后写入 chat_reply_intent_logoptions 含 sn_code/platform/friendId/encryptFriendId 时落库 */
_saveReplyIntentLog(options, hr_message_text, jobInfo, action, reply_content, replied, reason) {
/** AI 回复后写入 chat_reply_intent_logoptions 含 sn_code/platform/friendId/encryptFriendIdsecurityId 为 HR 消息唯一 id */
_saveReplyIntentLog(options, hr_message_text, jobInfo, action, reply_content, replied, reason, securityId) {
if (!options || options.sn_code == null) return;
try {
const model = db.getModel('chat_reply_intent_log');
@@ -228,6 +228,7 @@ class ChatManager {
platform: options.platform || 'boss',
friendId: options.friendId ?? null,
encrypt_friend_id: options.encryptFriendId || '',
security_id: securityId || null,
hr_message_text: hr_message_text || null,
action: action || '',
reply_content: reply_content || null,
@@ -276,13 +277,13 @@ class ChatManager {
const hrList = this._filterHrReplyableMessages(messages, geek_uid);
if (hrList.length === 0) {
this._saveReplyIntentLog(options, '', jobInfo, '', '', false, '无HR可回复消息已过滤系统与己方');
this._saveReplyIntentLog(options, '', jobInfo, '', '', false, '无HR可回复消息已过滤系统与己方', null);
return { replied: false, reason: '无HR可回复消息已过滤系统与己方' };
}
const last = hrList[hrList.length - 1];
if (!last.from || last.from.uid !== hr_uid) {
this._saveReplyIntentLog(options, '', jobInfo, '', '', false, '最后一条可回复消息不是HR');
this._saveReplyIntentLog(options, '', jobInfo, '', '', false, '最后一条可回复消息不是HR', null);
return { replied: false, reason: '最后一条可回复消息不是HR' };
}
@@ -291,7 +292,25 @@ class ChatManager {
(typeof body.text === 'string' && body.text) ||
(typeof last.pushText === 'string' && last.pushText) ||
'';
const security_id = last.securityId || last.security_id || '';
if (security_id && options) {
try {
const logModel = db.getModel('chat_reply_intent_log');
const existing = await logModel.findOne({ where: { security_id } });
if (existing) {
return {
replied: !!existing.replied,
action: existing.action || 'text',
reply_content: existing.reply_content || '',
hr_message_text: existing.hr_message_text || hr_message_text,
reason: existing.reason || null
};
}
} catch (e) {
console.warn('[聊天管理] 查询 chat_reply_intent_log 失败:', e.message);
}
}
const { action, reply_content } = await ai_service.replyIntentAndContent({
jobInfo,
@@ -299,19 +318,18 @@ class ChatManager {
previousMessages: hrList.slice(-5).map(m => (m.body && m.body.text) || m.pushText || '')
});
if (action === 'no_reply') {
this._saveReplyIntentLog(options, hr_message_text, jobInfo, action, reply_content, false, 'HR表示暂不匹配/无需回复');
this._saveReplyIntentLog(options, hr_message_text, jobInfo, action, reply_content, false, 'HR表示暂不匹配/无需回复', security_id || null);
return { replied: false, reason: 'HR表示暂不匹配/无需回复' };
}
const needContent = action === 'text';
if (needContent && (!reply_content || !reply_content.trim())) {
this._saveReplyIntentLog(options, hr_message_text, jobInfo, action, reply_content, false, 'AI 未生成有效回复文案');
this._saveReplyIntentLog(options, hr_message_text, jobInfo, action, reply_content, false, 'AI 未生成有效回复文案', security_id || null);
return { replied: false, reason: 'AI 未生成有效回复文案' };
}
this._saveReplyIntentLog(options, hr_message_text, jobInfo, action, reply_content, true, null);
this._saveReplyIntentLog(options, hr_message_text, jobInfo, action, reply_content, true, null, security_id || null);
return {
replied: true,
action: action || 'text',