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.
85 lines
2.8 KiB
85 lines
2.8 KiB
// 测试聊天流程脚本
|
|
const mysql = require('mysql2/promise');
|
|
|
|
// 数据库配置
|
|
const dbConfig = {
|
|
host: '1.95.162.61',
|
|
port: 3306,
|
|
user: 'root',
|
|
password: 'schl@2025',
|
|
database: 'wechat_app'
|
|
};
|
|
|
|
async function testChatFlow() {
|
|
let connection;
|
|
try {
|
|
// 连接数据库
|
|
connection = await mysql.createConnection(dbConfig);
|
|
console.log('✅ 数据库连接成功');
|
|
|
|
// 1. 检查chat_conversations表中是否有会话
|
|
const [conversations] = await connection.execute(
|
|
'SELECT * FROM chat_conversations ORDER BY created_at DESC LIMIT 5'
|
|
);
|
|
|
|
if (conversations.length > 0) {
|
|
console.log('\n✅ 最近的5个会话:');
|
|
conversations.forEach((conv, index) => {
|
|
console.log(`\n会话 ${index + 1}:`);
|
|
console.log(` conversation_id: ${conv.conversation_id}`);
|
|
console.log(` userId: ${conv.userId}`);
|
|
console.log(` managerId: ${conv.managerId}`);
|
|
console.log(` status: ${conv.status}`);
|
|
console.log(` created_at: ${conv.created_at}`);
|
|
});
|
|
|
|
// 2. 检查最新会话的消息
|
|
const latestConversationId = conversations[0].conversation_id;
|
|
const [messages] = await connection.execute(
|
|
'SELECT * FROM chat_messages WHERE conversation_id = ? ORDER BY created_at DESC LIMIT 10',
|
|
[latestConversationId]
|
|
);
|
|
|
|
console.log(`\n🔍 查询会话 ${latestConversationId} 的消息:`);
|
|
if (messages.length > 0) {
|
|
console.log(`✅ 找到 ${messages.length} 条消息:`);
|
|
messages.forEach((msg, index) => {
|
|
console.log(`\n消息 ${index + 1}:`);
|
|
console.log(` message_id: ${msg.message_id}`);
|
|
console.log(` content: ${msg.content}`);
|
|
console.log(` senderId: ${msg.senderId}`);
|
|
console.log(` receiverId: ${msg.receiverId}`);
|
|
console.log(` senderType: ${msg.senderType}`);
|
|
console.log(` created_at: ${msg.created_at}`);
|
|
});
|
|
} else {
|
|
console.log('❌ 未找到该会话的消息记录');
|
|
}
|
|
} else {
|
|
console.log('❌ 未找到任何会话记录');
|
|
}
|
|
|
|
// 3. 检查所有消息(最近10条)
|
|
const [allMessages] = await connection.execute(
|
|
'SELECT * FROM chat_messages ORDER BY created_at DESC LIMIT 10'
|
|
);
|
|
|
|
console.log('\n📊 最近的10条消息(所有会话):');
|
|
if (allMessages.length > 0) {
|
|
console.log(`✅ 找到 ${allMessages.length} 条消息记录`);
|
|
} else {
|
|
console.log('❌ 数据库中没有任何消息记录');
|
|
}
|
|
|
|
} catch (error) {
|
|
console.error('❌ 测试过程中发生错误:', error);
|
|
} finally {
|
|
if (connection) {
|
|
await connection.end();
|
|
console.log('\n✅ 数据库连接已关闭');
|
|
}
|
|
}
|
|
}
|
|
|
|
// 执行测试
|
|
testChatFlow();
|
|
|