获取概览卡片数据 (/api/analytics/dashboard-cards)

返回包含留言总数、平均互动率和情感分析三个核心指标的卡片数据及环比变化
支持时间范围和项目ID过滤
获取留言趋势数据 (/api/analytics/comment-trend)
返回一段时间内留言数量的变化趋势,用于绘制柱状图
支持时间范围、项目ID和平台过滤
获取平台分布数据 (/api/analytics/platform-distribution)
返回不同社交平台上的评论或互动分布情况
支持时间范围、项目ID和事件类型过滤
获取情感分析详情 (/api/analytics/sentiment-analysis)
返回正面、中性、负面评论的比例和平均情感得分
支持时间范围、项目ID和平台过滤
获取热门文章数据 (/api/analytics/popular-posts)
返回按互动数量或互动率排序的热门帖文列表
支持时间范围、项目ID、平台过滤,以及排序字段和限制返回数量
This commit is contained in:
2025-03-13 21:54:21 +08:00
parent f9ba8a73ba
commit 23bcb4cb8b
4 changed files with 1746 additions and 0 deletions

View File

@@ -2529,6 +2529,532 @@ export const openAPISpec = {
}
}
},
'/api/analytics/dashboard-cards': {
get: {
summary: '获取概览卡片数据',
description: '返回包含留言总数、平均互动率和情感分析三个核心指标的卡片数据及环比变化',
tags: ['Analytics'],
parameters: [
{
name: 'timeRange',
in: 'query',
description: '时间范围(天)',
schema: {
type: 'string',
enum: ['7', '30', '90'],
default: '30'
}
},
{
name: 'projectId',
in: 'query',
description: '项目ID过滤',
schema: {
type: 'string'
}
}
],
responses: {
'200': {
description: '成功响应',
content: {
'application/json': {
schema: {
type: 'object',
properties: {
success: { type: 'boolean', example: true },
data: {
type: 'object',
properties: {
comments_count: {
type: 'object',
properties: {
current: { type: 'number', example: 256 },
change_percentage: { type: 'number', example: 12.5 }
}
},
engagement_rate: {
type: 'object',
properties: {
current: { type: 'number', example: 5.8 },
change_percentage: { type: 'number', example: -2.3 }
}
},
sentiment_score: {
type: 'object',
properties: {
current: { type: 'number', example: 0.75 },
change_percentage: { type: 'number', example: 8.7 }
}
}
}
}
}
}
}
}
},
'400': {
description: '参数错误',
content: {
'application/json': {
schema: {
type: 'object',
properties: {
success: { type: 'boolean', example: false },
error: { type: 'string', example: 'Invalid timeRange. Must be 7, 30, or 90.' }
}
}
}
}
},
'500': {
description: '服务器错误',
content: {
'application/json': {
schema: {
type: 'object',
properties: {
success: { type: 'boolean', example: false },
error: { type: 'string', example: 'Failed to fetch dashboard card data' },
message: { type: 'string', example: 'Internal server error' }
}
}
}
}
}
}
}
},
'/api/analytics/comment-trend': {
get: {
summary: '获取留言趋势数据',
description: '返回一段时间内留言数量的变化趋势,用于绘制柱状图',
tags: ['Analytics'],
parameters: [
{
name: 'timeRange',
in: 'query',
description: '时间范围(天)',
schema: {
type: 'string',
enum: ['7', '30', '90'],
default: '30'
}
},
{
name: 'projectId',
in: 'query',
description: '项目ID过滤',
schema: {
type: 'string'
}
},
{
name: 'platform',
in: 'query',
description: '平台过滤',
schema: {
type: 'string',
enum: ['Twitter', 'Instagram', 'TikTok', 'Facebook', 'YouTube']
}
}
],
responses: {
'200': {
description: '成功响应',
content: {
'application/json': {
schema: {
type: 'object',
properties: {
success: { type: 'boolean', example: true },
data: {
type: 'array',
items: {
type: 'object',
properties: {
date: { type: 'string', format: 'date', example: '2025-03-01' },
count: { type: 'number', example: 32 }
}
}
},
metadata: {
type: 'object',
properties: {
max_count: { type: 'number', example: 58 },
total_count: { type: 'number', example: 256 }
}
}
}
}
}
}
},
'400': {
description: '参数错误',
content: {
'application/json': {
schema: {
type: 'object',
properties: {
success: { type: 'boolean', example: false },
error: { type: 'string', example: 'Invalid timeRange. Must be 7, 30, or 90.' }
}
}
}
}
},
'500': {
description: '服务器错误',
content: {
'application/json': {
schema: {
type: 'object',
properties: {
success: { type: 'boolean', example: false },
error: { type: 'string', example: 'Failed to fetch comment trend data' },
message: { type: 'string', example: 'Internal server error' }
}
}
}
}
}
}
}
},
'/api/analytics/platform-distribution': {
get: {
summary: '获取平台分布数据',
description: '返回不同社交平台上的评论或互动分布情况,用于绘制柱状图',
tags: ['Analytics'],
parameters: [
{
name: 'timeRange',
in: 'query',
description: '时间范围(天)',
schema: {
type: 'string',
enum: ['7', '30', '90'],
default: '30'
}
},
{
name: 'projectId',
in: 'query',
description: '项目ID过滤',
schema: {
type: 'string'
}
},
{
name: 'eventType',
in: 'query',
description: '事件类型',
schema: {
type: 'string',
enum: ['comment', 'like', 'view', 'share'],
default: 'comment'
}
}
],
responses: {
'200': {
description: '成功响应',
content: {
'application/json': {
schema: {
type: 'object',
properties: {
success: { type: 'boolean', example: true },
data: {
type: 'array',
items: {
type: 'object',
properties: {
platform: { type: 'string', example: 'Instagram' },
count: { type: 'number', example: 128 },
percentage: { type: 'number', example: 42.5 }
}
}
},
metadata: {
type: 'object',
properties: {
total: { type: 'number', example: 312 },
event_type: { type: 'string', example: 'comment' }
}
}
}
}
}
}
},
'400': {
description: '参数错误',
content: {
'application/json': {
schema: {
type: 'object',
properties: {
success: { type: 'boolean', example: false },
error: { type: 'string', example: 'Invalid eventType. Must be one of: comment, like, view, share' }
}
}
}
}
},
'500': {
description: '服务器错误',
content: {
'application/json': {
schema: {
type: 'object',
properties: {
success: { type: 'boolean', example: false },
error: { type: 'string', example: 'Failed to fetch platform distribution data' },
message: { type: 'string', example: 'Internal server error' }
}
}
}
}
}
}
}
},
'/api/analytics/sentiment-analysis': {
get: {
summary: '获取情感分析详情',
description: '返回正面、中性、负面评论的比例和平均情感得分',
tags: ['Analytics'],
parameters: [
{
name: 'timeRange',
in: 'query',
description: '时间范围(天)',
schema: {
type: 'string',
enum: ['7', '30', '90'],
default: '30'
}
},
{
name: 'projectId',
in: 'query',
description: '项目ID过滤',
schema: {
type: 'string'
}
},
{
name: 'platform',
in: 'query',
description: '平台过滤',
schema: {
type: 'string',
enum: ['Twitter', 'Instagram', 'TikTok', 'Facebook', 'YouTube']
}
}
],
responses: {
'200': {
description: '成功响应',
content: {
'application/json': {
schema: {
type: 'object',
properties: {
success: { type: 'boolean', example: true },
data: {
type: 'object',
properties: {
positive: {
type: 'object',
properties: {
count: { type: 'number', example: 156 },
percentage: { type: 'number', example: 65.2 }
}
},
neutral: {
type: 'object',
properties: {
count: { type: 'number', example: 45 },
percentage: { type: 'number', example: 20.8 }
}
},
negative: {
type: 'object',
properties: {
count: { type: 'number', example: 28 },
percentage: { type: 'number', example: 14.0 }
}
},
total: { type: 'number', example: 229 },
average_score: { type: 'number', example: 0.68 }
}
}
}
}
}
}
},
'400': {
description: '参数错误',
content: {
'application/json': {
schema: {
type: 'object',
properties: {
success: { type: 'boolean', example: false },
error: { type: 'string', example: 'Invalid timeRange. Must be 7, 30, or 90.' }
}
}
}
}
},
'500': {
description: '服务器错误',
content: {
'application/json': {
schema: {
type: 'object',
properties: {
success: { type: 'boolean', example: false },
error: { type: 'string', example: 'Failed to fetch sentiment analysis data' },
message: { type: 'string', example: 'Internal server error' }
}
}
}
}
}
}
}
},
'/api/analytics/popular-posts': {
get: {
summary: '获取热门文章数据',
description: '返回按互动数量或互动率排序的热门帖文列表',
tags: ['Analytics'],
parameters: [
{
name: 'timeRange',
in: 'query',
description: '时间范围(天)',
schema: {
type: 'string',
enum: ['7', '30', '90'],
default: '30'
}
},
{
name: 'projectId',
in: 'query',
description: '项目ID过滤',
schema: {
type: 'string'
}
},
{
name: 'platform',
in: 'query',
description: '平台过滤',
schema: {
type: 'string',
enum: ['Twitter', 'Instagram', 'TikTok', 'Facebook', 'YouTube']
}
},
{
name: 'sortBy',
in: 'query',
description: '排序字段',
schema: {
type: 'string',
enum: ['engagement_count', 'engagement_rate'],
default: 'engagement_count'
}
},
{
name: 'limit',
in: 'query',
description: '返回数量',
schema: {
type: 'integer',
default: 10,
maximum: 50
}
}
],
responses: {
'200': {
description: '成功响应',
content: {
'application/json': {
schema: {
type: 'object',
properties: {
success: { type: 'boolean', example: true },
data: {
type: 'array',
items: {
type: 'object',
properties: {
post_id: { type: 'string', example: 'post_123' },
title: { type: 'string', example: '新产品发布' },
platform: { type: 'string', example: 'Instagram' },
influencer_id: { type: 'string', example: 'inf_456' },
influencer_name: { type: 'string', example: '时尚KOL' },
publish_date: { type: 'string', example: '2025-03-10 10:30:00' },
engagement_count: { type: 'number', example: 2350 },
views_count: { type: 'number', example: 15600 },
engagement_rate: { type: 'number', example: 0.1506 },
is_high_engagement: { type: 'boolean', example: true }
}
}
},
metadata: {
type: 'object',
properties: {
total: { type: 'number', example: 45 },
high_engagement_count: { type: 'number', example: 8 }
}
}
}
}
}
}
},
'400': {
description: '参数错误',
content: {
'application/json': {
schema: {
type: 'object',
properties: {
success: { type: 'boolean', example: false },
error: { type: 'string', example: 'Invalid sortBy. Must be engagement_count or engagement_rate.' }
}
}
}
}
},
'500': {
description: '服务器错误',
content: {
'application/json': {
schema: {
type: 'object',
properties: {
success: { type: 'boolean', example: false },
error: { type: 'string', example: 'Failed to fetch popular posts data' },
message: { type: 'string', example: 'Internal server error' }
}
}
}
}
}
}
}
},
},
components: {
schemas: {