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);
|