82 lines
2.0 KiB
TypeScript
82 lines
2.0 KiB
TypeScript
import { prisma } from '../lib/prisma';
|
||
|
||
/**
|
||
* 初始化超级管理员账户
|
||
* 将指定的4个账户设置为超级管理员
|
||
*/
|
||
async function main() {
|
||
const superAdminEmails = [
|
||
'dingtalk_xlnjr3v2@temp.com', // 南亭
|
||
'admin@youyidian3d.com', // admin
|
||
'dingtalk_e4v7vk0t@temp.com', // 魔礼红
|
||
'222@qq.com', // 222
|
||
];
|
||
|
||
console.log('开始初始化超级管理员...\n');
|
||
|
||
for (const email of superAdminEmails) {
|
||
try {
|
||
const user = await prisma.user.findUnique({
|
||
where: { email },
|
||
});
|
||
|
||
if (!user) {
|
||
console.log(`❌ 用户不存在: ${email}`);
|
||
continue;
|
||
}
|
||
|
||
if (user.role !== 'ADMIN') {
|
||
console.log(`⚠️ 用户不是管理员,跳过: ${email} (角色: ${user.role})`);
|
||
continue;
|
||
}
|
||
|
||
if (user.isSuperAdmin) {
|
||
console.log(`✓ 已经是超级管理员: ${email} (${user.username})`);
|
||
continue;
|
||
}
|
||
|
||
await prisma.user.update({
|
||
where: { email },
|
||
data: { isSuperAdmin: true },
|
||
});
|
||
|
||
console.log(`✅ 已设置为超级管理员: ${email} (${user.username})`);
|
||
} catch (error) {
|
||
console.error(`❌ 处理用户失败 ${email}:`, error);
|
||
}
|
||
}
|
||
|
||
// 统计结果
|
||
const superAdminCount = await prisma.user.count({
|
||
where: { isSuperAdmin: true },
|
||
});
|
||
|
||
console.log(`\n完成!当前超级管理员数量: ${superAdminCount} / 4`);
|
||
|
||
// 列出所有超级管理员
|
||
const superAdmins = await prisma.user.findMany({
|
||
where: { isSuperAdmin: true },
|
||
select: {
|
||
email: true,
|
||
username: true,
|
||
realName: true,
|
||
role: true,
|
||
},
|
||
});
|
||
|
||
console.log('\n当前超级管理员列表:');
|
||
superAdmins.forEach((admin, index) => {
|
||
console.log(` ${index + 1}. ${admin.email} (${admin.realName || admin.username})`);
|
||
});
|
||
}
|
||
|
||
main()
|
||
.catch((error) => {
|
||
console.error('执行失败:', error);
|
||
process.exit(1);
|
||
})
|
||
.finally(async () => {
|
||
await prisma.$disconnect();
|
||
});
|
||
|