You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
81 lines
2.8 KiB
81 lines
2.8 KiB
// 检查特定会话和消息的脚本
|
|
const { Sequelize } = require('sequelize');
|
|
require('dotenv').config();
|
|
|
|
// 数据库配置
|
|
const sequelize = new Sequelize(process.env.DB_DATABASE || 'wechat_app', process.env.DB_USER || 'root', process.env.DB_PASSWORD || '', {
|
|
host: process.env.DB_HOST || 'localhost',
|
|
dialect: 'mysql',
|
|
port: process.env.DB_PORT || 3306,
|
|
logging: console.log,
|
|
dialectOptions: {
|
|
multipleStatements: true
|
|
}
|
|
});
|
|
|
|
// 查询特定会话和相关消息
|
|
async function checkSpecificConversation() {
|
|
try {
|
|
console.log('=== 开始检查特定会话和消息 ===');
|
|
|
|
// 使用我们刚才创建的会话ID
|
|
const targetConversationId = '6a64f35e-2219-41d5-b14e-d6e029529c11';
|
|
console.log(`🔍 查询会话ID: ${targetConversationId}`);
|
|
|
|
// 1. 检查会话是否存在
|
|
const [conversations] = await sequelize.query(
|
|
'SELECT * FROM chat_conversations WHERE conversation_id = ?',
|
|
{ replacements: [targetConversationId] }
|
|
);
|
|
|
|
if (conversations && conversations.length > 0) {
|
|
console.log('✅ 会话存在:');
|
|
console.log(JSON.stringify(conversations[0], null, 2));
|
|
} else {
|
|
console.log('❌ 会话不存在');
|
|
}
|
|
|
|
// 2. 检查是否有相关消息
|
|
const [messages] = await sequelize.query(
|
|
'SELECT * FROM chat_messages WHERE conversation_id = ? ORDER BY created_at ASC',
|
|
{ replacements: [targetConversationId] }
|
|
);
|
|
|
|
if (messages && messages.length > 0) {
|
|
console.log(`\n✅ 找到 ${messages.length} 条消息:`);
|
|
messages.forEach((msg, index) => {
|
|
console.log(`\n--- 消息 ${index + 1} ---`);
|
|
console.log(`发送方类型: ${msg.sender_type === 1 ? '客户' : '客服'}`);
|
|
console.log(`发送方ID: ${msg.sender_id}`);
|
|
console.log(`内容: ${msg.content}`);
|
|
console.log(`创建时间: ${msg.created_at}`);
|
|
});
|
|
} else {
|
|
console.log('\n❌ 未找到该会话的消息记录');
|
|
}
|
|
|
|
// 3. 检查最近的所有消息,不限于特定会话
|
|
const [allRecentMessages] = await sequelize.query(
|
|
'SELECT * FROM chat_messages ORDER BY created_at DESC LIMIT 10'
|
|
);
|
|
|
|
if (allRecentMessages && allRecentMessages.length > 0) {
|
|
console.log('\n🔍 最近10条消息:');
|
|
allRecentMessages.forEach(msg => {
|
|
console.log(`${msg.created_at} | 会话ID: ${msg.conversation_id} | 发送方: ${msg.sender_id} | 内容: ${msg.content.substring(0, 30)}...`);
|
|
});
|
|
} else {
|
|
console.log('\n❌ 数据库中没有任何消息记录');
|
|
}
|
|
|
|
console.log('\n=== 检查完成 ===');
|
|
|
|
} catch (error) {
|
|
console.error('❌ 查询出错:', error.message);
|
|
} finally {
|
|
await sequelize.close();
|
|
}
|
|
}
|
|
|
|
// 运行查询
|
|
checkSpecificConversation();
|
|
|