diff --git a/app/api/events/summary/route.ts b/app/api/events/summary/route.ts index 66722c7..6263f53 100644 --- a/app/api/events/summary/route.ts +++ b/app/api/events/summary/route.ts @@ -6,10 +6,18 @@ export async function GET(request: NextRequest) { try { const searchParams = request.nextUrl.searchParams; + // 获取可能存在的多个团队、项目和标签ID + const teamIds = searchParams.getAll('teamId'); + const projectIds = searchParams.getAll('projectId'); + const tagIds = searchParams.getAll('tagId'); + const summary = await getEventsSummary({ startTime: searchParams.get('startTime') || undefined, endTime: searchParams.get('endTime') || undefined, - linkId: searchParams.get('linkId') || undefined + linkId: searchParams.get('linkId') || undefined, + teamIds: teamIds.length > 0 ? teamIds : undefined, + projectIds: projectIds.length > 0 ? projectIds : undefined, + tagIds: tagIds.length > 0 ? tagIds : undefined }); const response: ApiResponse = { diff --git a/lib/analytics.ts b/lib/analytics.ts index 168c8b2..ddd41d5 100644 --- a/lib/analytics.ts +++ b/lib/analytics.ts @@ -57,6 +57,9 @@ export async function getEventsSummary(params: { startTime?: string; endTime?: string; linkId?: string; + teamIds?: string[]; + projectIds?: string[]; + tagIds?: string[]; }): Promise { const filter = buildFilter(params); diff --git a/lib/clickhouse.ts b/lib/clickhouse.ts index f990b57..1fcedea 100644 --- a/lib/clickhouse.ts +++ b/lib/clickhouse.ts @@ -56,16 +56,29 @@ export function buildFilter(params: Partial): string { filters.push(`user_id = '${params.userId}'`); } - // 团队ID过滤 - if (params.teamId) { + // 团队ID过滤 - 支持多选 + if (params.teamIds && params.teamIds.length > 0) { + const teamValues = params.teamIds.map(id => `'${id}'`).join(', '); + filters.push(`team_id IN (${teamValues})`); + } else if (params.teamId) { filters.push(`team_id = '${params.teamId}'`); } - // 项目ID过滤 - if (params.projectId) { + // 项目ID过滤 - 支持多选 + if (params.projectIds && params.projectIds.length > 0) { + const projectValues = params.projectIds.map(id => `'${id}'`).join(', '); + filters.push(`project_id IN (${projectValues})`); + } else if (params.projectId) { filters.push(`project_id = '${params.projectId}'`); } + // 标签ID过滤 - 支持多选 + if (params.tagIds && params.tagIds.length > 0) { + // 假设我们在link_tags字段存储标签ID的JSON数组 + const tagConditions = params.tagIds.map(id => `arrayExists(x -> x = '${id}', JSONExtractArrayRaw(link_tags))`); + filters.push(`(${tagConditions.join(' OR ')})`); + } + return filters.length > 0 ? `WHERE ${filters.join(' AND ')}` : ''; } diff --git a/lib/types.ts b/lib/types.ts index 167e6c5..df637a8 100644 --- a/lib/types.ts +++ b/lib/types.ts @@ -45,7 +45,10 @@ export interface EventsQueryParams { linkSlug?: string; userId?: string; teamId?: string; + teamIds?: string[]; // 团队ID数组,支持多选 projectId?: string; + projectIds?: string[]; // 项目ID数组,支持多选 + tagIds?: string[]; // 标签ID数组,支持多选 page?: number; pageSize?: number; sortBy?: string;