const axios = require('axios');
|
|
// 测试Player phone字段修改后的功能
|
async function testPlayerPhoneFix() {
|
const baseURL = 'http://localhost:8080/api';
|
|
console.log('=== 测试Player phone字段修改后的功能 ===\n');
|
|
try {
|
// 1. 测试GraphQL查询 - 获取选手信息
|
console.log('1. 测试GraphQL查询选手信息...');
|
const graphqlQuery = {
|
query: `
|
query {
|
players(page: 1, size: 5) {
|
content {
|
id
|
name
|
phone
|
userInfo {
|
id
|
phone
|
}
|
}
|
totalElements
|
}
|
}
|
`
|
};
|
|
const graphqlResponse = await axios.post(`${baseURL}/graphql`, graphqlQuery, {
|
headers: {
|
'Content-Type': 'application/json'
|
}
|
});
|
|
if (graphqlResponse.data.data && graphqlResponse.data.data.players) {
|
const players = graphqlResponse.data.data.players.content;
|
console.log(`✓ 成功获取 ${players.length} 个选手信息`);
|
|
// 检查phone字段的数据一致性
|
players.forEach((player, index) => {
|
console.log(` 选手${index + 1}: ${player.name}`);
|
console.log(` Player.phone (已废弃): ${player.phone || 'null'}`);
|
console.log(` User.phone (正确来源): ${player.userInfo?.phone || 'null'}`);
|
|
// 检查数据一致性
|
if (player.userInfo?.phone) {
|
console.log(` ✓ 从User实体成功获取phone: ${player.userInfo.phone}`);
|
} else {
|
console.log(` ⚠ User实体中没有phone数据`);
|
}
|
console.log('');
|
});
|
} else {
|
console.log('✗ GraphQL查询失败或返回空数据');
|
console.log('响应:', JSON.stringify(graphqlResponse.data, null, 2));
|
}
|
|
} catch (error) {
|
console.error('测试过程中发生错误:');
|
if (error.response) {
|
console.error('状态码:', error.response.status);
|
console.error('响应数据:', JSON.stringify(error.response.data, null, 2));
|
} else {
|
console.error('错误信息:', error.message);
|
}
|
}
|
|
try {
|
// 2. 测试活动选手列表API
|
console.log('\n2. 测试活动选手列表API...');
|
const listResponse = await axios.get(`${baseURL}/activity-players/applications`, {
|
params: {
|
page: 1,
|
size: 5
|
}
|
});
|
|
if (listResponse.data && listResponse.data.content) {
|
const applications = listResponse.data.content;
|
console.log(`✓ 成功获取 ${applications.length} 个选手申请记录`);
|
|
applications.forEach((app, index) => {
|
console.log(` 申请${index + 1}: ${app.playerName}`);
|
console.log(` 手机号: ${app.phone || 'null'}`);
|
console.log(` 项目: ${app.projectName || 'null'}`);
|
console.log('');
|
});
|
} else {
|
console.log('✗ 活动选手列表API返回空数据');
|
}
|
|
} catch (error) {
|
console.error('\n活动选手列表API测试失败:');
|
if (error.response) {
|
console.error('状态码:', error.response.status);
|
console.error('响应数据:', JSON.stringify(error.response.data, null, 2));
|
} else {
|
console.error('错误信息:', error.message);
|
}
|
}
|
|
console.log('\n=== 测试完成 ===');
|
console.log('\n总结:');
|
console.log('1. Player实体的phone字段已标记为@Deprecated');
|
console.log('2. 所有SQL查询已修改为从User表获取phone');
|
console.log('3. DTO类已修改为从User实体获取phone');
|
console.log('4. GraphQL schema中Player.phone已标记为废弃');
|
console.log('5. 建议前端逐步迁移到使用userInfo.phone字段');
|
}
|
|
// 运行测试
|
testPlayerPhoneFix();
|