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.
 
 

70 lines
2.3 KiB

// 检查chat_online_status表的当前状态
const { Sequelize } = require('sequelize');
// 数据库配置 - 与server-mysql.js保持一致
const sequelize = new Sequelize('chat', 'root', '', {
host: 'localhost',
port: 3306,
dialect: 'mysql',
pool: {
max: 10,
min: 0,
acquire: 30000,
idle: 10000
},
define: {
freezeTableName: true,
timestamps: false
},
logging: console.log
});
async function checkOnlineStatus() {
try {
console.log('正在连接数据库...');
await sequelize.authenticate();
console.log('数据库连接成功');
// 查询所有客服的在线状态
console.log('\n查询chat_online_status表中所有客服(type=2)的记录:');
const [managerStatuses] = await sequelize.query(
'SELECT * FROM chat_online_status WHERE type = 2 ORDER BY userId, type',
{ type: Sequelize.QueryTypes.SELECT }
);
if (managerStatuses.length === 0) {
console.log('没有找到客服的在线状态记录');
} else {
console.log(`找到 ${managerStatuses.length} 条客服在线状态记录:`);
managerStatuses.forEach(record => {
console.log(`- userId: ${record.userId || 'NULL'}, type: ${record.type}, is_online: ${record.is_online}, connection_id: ${record.connection_id}, last_heartbeat: ${record.last_heartbeat}, updated_at: ${record.updated_at}`);
});
}
// 查询表中所有记录(包括用户和客服)以了解整体情况
console.log('\n查询chat_online_status表中所有记录:');
const [allStatuses] = await sequelize.query(
'SELECT * FROM chat_online_status ORDER BY type, userId',
{ type: Sequelize.QueryTypes.SELECT }
);
console.log(`总共 ${allStatuses.length} 条记录`);
// 检查是否存在userId为NULL的记录
const nullUserIdRecords = allStatuses.filter(record => record.userId === null);
if (nullUserIdRecords.length > 0) {
console.log(`\n发现 ${nullUserIdRecords.length} 条userId为NULL的记录:`);
nullUserIdRecords.forEach(record => {
console.log(`- userId: NULL, type: ${record.type}, is_online: ${record.is_online}`);
});
}
} catch (error) {
console.error('检查在线状态时出错:', error);
} finally {
await sequelize.close();
}
}
// 执行检查
checkOnlineStatus();