Codex Assistant
23 小时以前 58d9f460b2f8c34430285115e2557d18333c5cab
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
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();