95 lines
2.8 KiB
TypeScript
95 lines
2.8 KiB
TypeScript
/**
|
||
* 查询数据库中的管理员账户信息
|
||
*
|
||
* 使用方法:
|
||
* npx tsx scripts/query-admin-accounts.ts
|
||
*/
|
||
|
||
import { PrismaClient } from '@prisma/client';
|
||
|
||
const prisma = new PrismaClient();
|
||
|
||
async function main() {
|
||
console.log('正在查询管理员账户信息...\n');
|
||
|
||
try {
|
||
// 查询所有管理员账户(role = 'ADMIN')
|
||
const admins = await prisma.user.findMany({
|
||
where: {
|
||
role: 'ADMIN',
|
||
},
|
||
select: {
|
||
id: true,
|
||
email: true,
|
||
username: true,
|
||
role: true,
|
||
isActive: true,
|
||
canDownload: true,
|
||
department: true,
|
||
managedDepartment: true,
|
||
createdAt: true,
|
||
},
|
||
orderBy: {
|
||
createdAt: 'asc',
|
||
},
|
||
});
|
||
|
||
if (admins.length === 0) {
|
||
console.log('未找到管理员账户');
|
||
console.log('\n提示:可以使用以下默认账户(如果存在):');
|
||
console.log(' 邮箱/用户名: admin');
|
||
console.log(' 密码: admin123456');
|
||
return;
|
||
}
|
||
|
||
console.log(`找到 ${admins.length} 个管理员账户:\n`);
|
||
|
||
admins.forEach((admin, index) => {
|
||
console.log(`--- 管理员 ${index + 1} ---`);
|
||
console.log(`邮箱: ${admin.email}`);
|
||
console.log(`用户名: ${admin.username}`);
|
||
console.log(`角色: ${admin.role}`);
|
||
const isActive = admin.isActive ? '是' : '否';
|
||
console.log(`是否激活: ${isActive}`);
|
||
const canDownload = admin.canDownload ? '是' : '否';
|
||
console.log(`可下载: ${canDownload}`);
|
||
const department = admin.department || '未设置';
|
||
console.log(`部门: ${department}`);
|
||
const managedDept = admin.managedDepartment || '无(超级管理员)';
|
||
console.log(`管理部门: ${managedDept}`);
|
||
console.log(`创建时间: ${admin.createdAt.toLocaleString('zh-CN')}`);
|
||
console.log('');
|
||
});
|
||
|
||
// 区分超级管理员和部门管理员
|
||
const superAdmins = admins.filter((admin) => !admin.managedDepartment);
|
||
const deptAdmins = admins.filter((admin) => admin.managedDepartment);
|
||
|
||
console.log('\n--- 统计信息 ---');
|
||
console.log(`超级管理员(无managedDepartment): ${superAdmins.length} 个`);
|
||
console.log(`部门管理员(有managedDepartment): ${deptAdmins.length} 个`);
|
||
|
||
if (superAdmins.length > 0) {
|
||
console.log('\n超级管理员列表:');
|
||
superAdmins.forEach((admin) => {
|
||
console.log(` - ${admin.email} (${admin.username})`);
|
||
});
|
||
}
|
||
|
||
console.log('\n注意:密码已加密存储,无法直接查看');
|
||
console.log('如需重置密码,请通过数据库直接修改或使用注册功能创建新账户');
|
||
} catch (error) {
|
||
console.error('查询失败:', error);
|
||
}
|
||
}
|
||
|
||
main()
|
||
.catch((error) => {
|
||
console.error('执行失败:', error);
|
||
process.exit(1);
|
||
})
|
||
.finally(async () => {
|
||
await prisma.$disconnect();
|
||
});
|
||
|