feat: 添加mock数据
This commit is contained in:
@@ -923,4 +923,78 @@ export const eventHandlers = [
|
||||
}
|
||||
});
|
||||
}),
|
||||
|
||||
// ==================== 历史事件对比相关 ====================
|
||||
|
||||
// 获取历史事件相关股票
|
||||
http.get('/api/historical-events/:eventId/stocks', async ({ params }) => {
|
||||
await delay(500);
|
||||
|
||||
const { eventId } = params;
|
||||
|
||||
console.log('[Mock] 获取历史事件相关股票, eventId:', eventId);
|
||||
|
||||
// 生成历史事件相关股票数据
|
||||
const generateHistoricalEventStocks = (count = 10) => {
|
||||
const stocks = [];
|
||||
const sectors = ['半导体', '新能源', '医药', '消费电子', '人工智能', '5G通信'];
|
||||
const stockNames = [
|
||||
'中芯国际', '长江存储', '华为海思', '紫光国微', '兆易创新',
|
||||
'宁德时代', '比亚迪', '隆基绿能', '阳光电源', '亿纬锂能',
|
||||
'恒瑞医药', '迈瑞医疗', '药明康德', '泰格医药', '康龙化成',
|
||||
'立讯精密', '歌尔声学', '京东方A', 'TCL科技', '海康威视',
|
||||
'科大讯飞', '商汤科技', '寒武纪', '海光信息', '中兴通讯'
|
||||
];
|
||||
|
||||
for (let i = 0; i < count; i++) {
|
||||
const stockCode = `${Math.random() > 0.5 ? '6' : '0'}${String(Math.floor(Math.random() * 100000)).padStart(5, '0')}`;
|
||||
const changePct = (Math.random() * 15 - 3).toFixed(2); // -3% ~ +12%
|
||||
const correlation = (Math.random() * 0.4 + 0.6).toFixed(2); // 0.6 ~ 1.0
|
||||
|
||||
stocks.push({
|
||||
id: `stock_${i}`,
|
||||
stock_code: `${stockCode}.${Math.random() > 0.5 ? 'SH' : 'SZ'}`,
|
||||
stock_name: stockNames[i % stockNames.length],
|
||||
sector: sectors[Math.floor(Math.random() * sectors.length)],
|
||||
correlation: parseFloat(correlation),
|
||||
event_day_change_pct: parseFloat(changePct),
|
||||
relation_desc: {
|
||||
data: [
|
||||
{
|
||||
query_part: `该公司是${sectors[Math.floor(Math.random() * sectors.length)]}行业龙头,受事件影响显著,市场关注度高,订单量同比增长${Math.floor(Math.random() * 50 + 20)}%`,
|
||||
sentences: `根据行业研究报告,该公司在${sectors[Math.floor(Math.random() * sectors.length)]}领域具有核心技术优势,产能利用率达到${Math.floor(Math.random() * 20 + 80)}%,随着事件的深入发展,公司业绩有望持续受益。机构预测未来三年复合增长率将达到${Math.floor(Math.random() * 30 + 15)}%以上`,
|
||||
match_score: correlation > 0.8 ? '好' : (correlation > 0.6 ? '中' : '一般'),
|
||||
author: ['中信证券', '国泰君安', '华泰证券', '招商证券'][Math.floor(Math.random() * 4)],
|
||||
declare_date: new Date(Date.now() - Math.floor(Math.random() * 90) * 24 * 60 * 60 * 1000).toISOString(),
|
||||
report_title: `${stockNames[i % stockNames.length]}深度研究报告`
|
||||
}
|
||||
]
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 按相关度降序排序
|
||||
return stocks.sort((a, b) => b.correlation - a.correlation);
|
||||
};
|
||||
|
||||
try {
|
||||
const stocks = generateHistoricalEventStocks(15);
|
||||
|
||||
return HttpResponse.json({
|
||||
success: true,
|
||||
data: stocks,
|
||||
message: '获取历史事件相关股票成功'
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('[Mock] 获取历史事件相关股票失败:', error);
|
||||
return HttpResponse.json(
|
||||
{
|
||||
success: false,
|
||||
error: '获取历史事件相关股票失败',
|
||||
data: []
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}),
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user