links search

This commit is contained in:
2025-03-31 16:46:33 +08:00
parent d75110d6b8
commit e7b3b735e0
11 changed files with 689 additions and 303 deletions

View File

@@ -1,5 +1,5 @@
import { executeQuery, executeQuerySingle, buildFilter, buildPagination, buildOrderBy } from './clickhouse';
import type { Event, EventsSummary, TimeSeriesData, GeoData, DeviceAnalytics, DeviceType } from './types';
import type { Event, EventsSummary, TimeSeriesData, GeoData, DeviceAnalytics, DeviceType, EventsQueryParams } from './types';
// 时间粒度枚举
export enum TimeGranularity {
@@ -10,20 +10,7 @@ export enum TimeGranularity {
}
// 获取事件列表
export async function getEvents(params: {
startTime?: string;
endTime?: string;
eventType?: string;
linkId?: string;
linkSlug?: string;
userId?: string;
teamId?: string;
projectId?: string;
page?: number;
pageSize?: number;
sortBy?: string;
sortOrder?: 'asc' | 'desc';
}): Promise<{ events: Event[]; total: number }> {
export async function getEvents(params: Partial<EventsQueryParams>): Promise<{ events: Event[]; total: number }> {
const filter = buildFilter(params);
const pagination = buildPagination(params.page, params.pageSize);
const orderBy = buildOrderBy(params.sortBy, params.sortOrder);
@@ -40,7 +27,48 @@ export async function getEvents(params: {
// 获取事件列表
const query = `
SELECT *
SELECT
event_id,
event_time,
event_type,
event_attributes,
link_id,
link_slug,
link_label,
link_title,
link_original_url,
link_attributes,
link_created_at,
link_expires_at,
link_tags,
user_id,
user_name,
user_email,
user_attributes,
team_id,
team_name,
team_attributes,
project_id,
project_name,
project_attributes,
visitor_id,
session_id,
ip_address,
country,
city,
device_type,
browser,
os,
user_agent,
referrer,
utm_source,
utm_medium,
utm_campaign,
time_spent_sec,
is_bounce,
is_qr_scan,
conversion_type,
conversion_value
FROM events
${filter}
${orderBy}
@@ -49,7 +77,19 @@ export async function getEvents(params: {
const events = await executeQuery<Event>(query);
return { events, total };
// 处理 JSON 字符串字段
return {
events: events.map(event => ({
...event,
event_attributes: JSON.parse(event.event_attributes as unknown as string),
link_attributes: JSON.parse(event.link_attributes as unknown as string),
link_tags: JSON.parse(event.link_tags as unknown as string),
user_attributes: JSON.parse(event.user_attributes as unknown as string),
team_attributes: JSON.parse(event.team_attributes as unknown as string),
project_attributes: JSON.parse(event.project_attributes as unknown as string)
})),
total
};
}
// 获取事件概览