Codex Assistant
1 天以前 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
const axios = require('axios');
 
const API_BASE_URL = 'http://localhost:8080/api/graphql';
const LOGIN_URL = 'http://localhost:8080/api/auth/web-login';
 
// 登录函数
async function login(phone, password) {
    try {
        const response = await axios.post(LOGIN_URL, {
            phone: phone,
            password: password
        });
 
        if (response.data.token) {
            return response.data;
        } else {
            console.error('登录失败: 没有返回token');
            return null;
        }
    } catch (error) {
        console.error('登录请求失败:', error.message);
        return null;
    }
}
 
// 查询所有员工
async function getAllEmployees(token) {
    const query = `
        query {
            employees {
                id
                name
                phone
                roleId
                description
                state
                createTime
                updateTime
            }
        }
    `;
 
    try {
        const response = await axios.post(API_BASE_URL, {
            query: query
        }, {
            headers: {
                'Authorization': `Bearer ${token}`
            }
        });
 
        if (response.data.errors) {
            console.error('查询员工失败:', response.data.errors);
            return [];
        }
 
        return response.data.data.employees;
    } catch (error) {
        console.error('查询员工请求失败:', error.message);
        return [];
    }
}
 
async function main() {
    console.log('开始检查手机号使用情况...');
    
    // 使用管理员账号登录
    const loginResult = await login('17898163888', '123456');
    if (!loginResult) {
        console.error('登录失败');
        return;
    }
    
    console.log('登录成功');
    
    // 获取所有员工
    const employees = await getAllEmployees(loginResult.token);
    console.log(`\n找到 ${employees.length} 个员工:`);
    
    employees.forEach(emp => {
        console.log(`员工ID: ${emp.id}, 姓名: ${emp.name}, 手机号: ${emp.phone}, 角色: ${emp.roleId}, 状态: ${emp.state}`);
    });
    
    // 检查特定手机号
    const targetPhones = ['13981970816', '13512331233'];
    
    targetPhones.forEach(targetPhone => {
        const existingEmployee = employees.find(emp => emp.phone === targetPhone);
        
        if (existingEmployee) {
            console.log(`\n❌ 手机号 ${targetPhone} 已被员工使用:`);
            console.log(`   员工ID: ${existingEmployee.id}`);
            console.log(`   员工姓名: ${existingEmployee.name}`);
            console.log(`   角色: ${existingEmployee.roleId}`);
        } else {
            console.log(`\n✅ 手机号 ${targetPhone} 未被任何员工使用`);
        }
    });
}
 
main().catch(console.error);