const mysql = require('mysql2/promise');
|
|
// 从application.yml读取的数据库配置
|
const dbConfig = {
|
host: '139.155.104.10',
|
port: 3306,
|
user: 'ryc',
|
password: 'KiYap3E8X8RLcM6T',
|
database: 'ryc',
|
connectTimeout: 60000,
|
acquireTimeout: 60000,
|
timeout: 60000
|
};
|
|
async function verifyUserJudgeMapping() {
|
console.log('=== 验证用户ID=152的评委权限 ===\n');
|
|
let connection;
|
try {
|
// 连接数据库
|
console.log('正在连接数据库...');
|
connection = await mysql.createConnection(dbConfig);
|
console.log('✅ 数据库连接成功\n');
|
|
// 1. 查询用户ID=152的基本信息
|
console.log('1. 查询用户ID=152的基本信息:');
|
const [userRows] = await connection.execute(
|
'SELECT id, name, phone, state, create_time FROM t_user WHERE id = ?',
|
[152]
|
);
|
|
if (userRows.length === 0) {
|
console.log('❌ 用户ID=152不存在');
|
return;
|
}
|
|
const user = userRows[0];
|
console.log('✅ 用户信息:');
|
console.log(` ID: ${user.id}`);
|
console.log(` 姓名: ${user.name}`);
|
console.log(` 手机号: ${user.phone}`);
|
console.log(` 状态: ${user.state}`);
|
console.log(` 创建时间: ${user.create_time}`);
|
|
// 2. 查询该用户对应的评委记录
|
console.log('\n2. 查询用户ID=152对应的评委记录:');
|
const [judgeRows] = await connection.execute(
|
'SELECT id, name, user_id, phone, state, title, company, create_time FROM t_judge WHERE user_id = ?',
|
[152]
|
);
|
|
if (judgeRows.length === 0) {
|
console.log('❌ 用户ID=152没有对应的评委记录');
|
|
// 检查是否有同手机号的评委记录
|
console.log('\n3. 检查是否有同手机号的评委记录:');
|
const [judgeByPhoneRows] = await connection.execute(
|
'SELECT id, name, user_id, phone, state FROM t_judge WHERE phone = ?',
|
[user.phone]
|
);
|
|
if (judgeByPhoneRows.length > 0) {
|
console.log('⚠️ 发现同手机号的评委记录:');
|
judgeByPhoneRows.forEach(judge => {
|
console.log(` 评委ID: ${judge.id}, 用户ID: ${judge.user_id}, 姓名: ${judge.name}, 状态: ${judge.state}`);
|
});
|
} else {
|
console.log('❌ 没有找到同手机号的评委记录');
|
}
|
return;
|
}
|
|
const judge = judgeRows[0];
|
console.log('✅ 评委信息:');
|
console.log(` 评委ID: ${judge.id}`);
|
console.log(` 用户ID: ${judge.user_id}`);
|
console.log(` 姓名: ${judge.name}`);
|
console.log(` 手机号: ${judge.phone}`);
|
console.log(` 状态: ${judge.state}`);
|
console.log(` 职位: ${judge.title || '未设置'}`);
|
console.log(` 公司: ${judge.company || '未设置'}`);
|
console.log(` 创建时间: ${judge.create_time}`);
|
|
// 验证是否是评委ID=72
|
if (judge.id === 72) {
|
console.log('✅ 确认:用户ID=152对应评委ID=72');
|
} else {
|
console.log(`⚠️ 注意:用户ID=152对应评委ID=${judge.id},不是72`);
|
}
|
|
// 3. 检查评委状态
|
console.log('\n3. 检查评委状态:');
|
if (judge.state === 1) {
|
console.log('✅ 评委状态正常(state=1)');
|
} else {
|
console.log(`❌ 评委状态异常(state=${judge.state})`);
|
}
|
|
// 4. 查询评委参与的活动
|
console.log('\n4. 查询评委参与的活动:');
|
const [activityJudgeRows] = await connection.execute(
|
'SELECT aj.activity_id, a.name as activity_name, aj.stage_id FROM t_activity_judge aj LEFT JOIN t_activity a ON aj.activity_id = a.id WHERE aj.judge_id = ? LIMIT 5',
|
[judge.id]
|
);
|
|
if (activityJudgeRows.length > 0) {
|
console.log('✅ 评委参与的活动:');
|
activityJudgeRows.forEach(activity => {
|
console.log(` 活动ID: ${activity.activity_id}, 活动名称: ${activity.activity_name || '未知'}, 阶段ID: ${activity.stage_id}`);
|
});
|
} else {
|
console.log('⚠️ 评委没有参与任何活动');
|
}
|
|
// 5. 查询最近的微信登录记录
|
console.log('\n5. 查询用户最近的微信登录记录:');
|
const [wxLoginRows] = await connection.execute(
|
'SELECT id, wx_openid, user_id, login_time, phone_authorized FROM t_wx_login_record WHERE user_id = ? ORDER BY login_time DESC LIMIT 3',
|
[152]
|
);
|
|
if (wxLoginRows.length > 0) {
|
console.log('✅ 最近的微信登录记录:');
|
wxLoginRows.forEach(record => {
|
console.log(` 记录ID: ${record.id}, OpenID: ${record.wx_openid}, 登录时间: ${record.login_time}, 手机授权: ${record.phone_authorized}`);
|
});
|
} else {
|
console.log('⚠️ 没有找到微信登录记录');
|
}
|
|
// 6. 总结
|
console.log('\n=== 总结 ===');
|
if (judge.state === 1) {
|
console.log('✅ 用户ID=152确实有有效的评委权限');
|
console.log('✅ 如果后端仍然拒绝访问,可能是UserContextUtil的逻辑有问题');
|
} else {
|
console.log('❌ 评委记录存在但状态异常,这可能是权限被拒绝的原因');
|
}
|
|
} catch (error) {
|
console.error('❌ 数据库查询失败:', error.message);
|
console.error('错误详情:', error);
|
} finally {
|
if (connection) {
|
await connection.end();
|
console.log('\n数据库连接已关闭');
|
}
|
}
|
}
|
|
// 运行验证
|
if (require.main === module) {
|
verifyUserJudgeMapping();
|
}
|
|
module.exports = { verifyUserJudgeMapping };
|