WuYongJie ba98bf22cc feat: 添加许可证系统、Agent部署模块和Harbor镜像管理
- 新增许可证服务器 (license-server/)
- 新增 Agent 部署模块 (flnxi-agent/)
- 添加许可证验证和激活页面
- 添加 Harbor 镜像同步脚本
- 更新素材系统支持许可证验证
2025-12-15 21:19:46 +08:00

79 lines
2.2 KiB
TypeScript

import { NextResponse } from 'next/server';
import { getAdminSession } from '@/lib/auth';
import { prisma } from '@/lib/db';
export async function GET() {
const session = await getAdminSession();
if (!session) {
return NextResponse.json({ error: '未授权' }, { status: 401 });
}
try {
// 客户统计
const customerCount = await prisma.customer.count();
// 许可证统计
const licenseCount = await prisma.license.count();
const licensesByType = await prisma.license.groupBy({
by: ['licenseType'],
_count: true,
});
const licensesByStatus = await prisma.license.groupBy({
by: ['status'],
_count: true,
});
// 激活统计
const activationCount = await prisma.activation.count();
const activeActivations = await prisma.activation.count({
where: { isActive: true },
});
// 待处理告警
const pendingAlerts = await prisma.alert.count({
where: { status: 'pending' },
});
// 最近激活
const recentActivations = await prisma.activation.findMany({
take: 10,
orderBy: { activatedAt: 'desc' },
include: {
license: {
include: {
customer: true,
},
},
},
});
return NextResponse.json({
customers: { total: customerCount },
licenses: {
total: licenseCount,
byType: Object.fromEntries(
licensesByType.map((item) => [item.licenseType, item._count])
),
byStatus: Object.fromEntries(
licensesByStatus.map((item) => [item.status, item._count])
),
},
activations: {
total: activationCount,
active: activeActivations,
},
alerts: { pending: pendingAlerts },
recentActivations: recentActivations.map((a) => ({
id: a.id,
licenseKey: a.license.licenseKey,
licenseType: a.license.licenseType,
activatedAt: a.activatedAt.toISOString(),
companyName: a.license.customer?.companyName || null,
})),
});
} catch (error) {
console.error('获取仪表盘数据失败:', error);
return NextResponse.json({ error: '服务器错误' }, { status: 500 });
}
}