diff --git a/backend/app/routers/yichens.py b/backend/app/routers/yichens.py index 9b55df7..b230fc1 100644 --- a/backend/app/routers/yichens.py +++ b/backend/app/routers/yichens.py @@ -250,3 +250,73 @@ async def get_today_category_stats(db: Session = Depends(get_coolbot_db)): """ results = db.execute(text(query)).fetchall() return [{"category": r[0] or "未分类", "count": r[1]} for r in results] + + +@router.get("/stats/dragons-today") +def get_dragons_stats_today( + db: Session = Depends(get_coolbot_db) +): + """获取今日龙钞详细统计数据(按号码分类)""" + from sqlalchemy import text + + # 查询今日龙钞数据,按分类统计 + result = db.execute(text(""" + SELECT + category, + COUNT(*) as total, + SUM(CASE WHEN content LIKE '%带4%' OR title LIKE '%带4%' THEN 1 ELSE 0 END) as dai4, + SUM(CASE WHEN content NOT LIKE '%带4%' AND title NOT LIKE '%带4%' AND (content LIKE '%无4%' OR title LIKE '%无4%') THEN 1 ELSE 0 END) as wu4, + SUM(CASE WHEN (content LIKE '%无47%' OR title LIKE '%无47%') AND (content NOT LIKE '%无247%' AND title NOT LIKE '%无247%') THEN 1 ELSE 0 END) as wu47, + SUM(CASE WHEN (content LIKE '%无247%' OR title LIKE '%无247%') AND (content NOT LIKE '%无347%' AND title NOT LIKE '%无347%') THEN 1 ELSE 0 END) as wu247, + SUM(CASE WHEN content LIKE '%无347%' OR title LIKE '%无347%' THEN 1 ELSE 0 END) as wu347 + FROM yichen_posts + WHERE created_at >= CURRENT_DATE + AND (category LIKE '%龙%' OR category LIKE '%龙钞%') + GROUP BY category + """)) + + rows = result.fetchall() + + # 汇总统计 + dai4_count = sum(r[2] or 0 for r in rows) + wu4_count = sum(r[3] or 0 for r in rows) + wu47_count = sum(r[4] or 0 for r in rows) + wu247_count = sum(r[5] or 0 for r in rows) + wu347_count = sum(r[6] or 0 for r in rows) + + # 查询出售和求购分类 + deals_result = db.execute(text(""" + SELECT + SUM(CASE WHEN content LIKE '%带4%' OR title LIKE '%带4%' THEN 1 ELSE 0 END) as dai4_deals, + SUM(CASE WHEN (content NOT LIKE '%带4%' AND title NOT LIKE '%带4%') AND (content LIKE '%无4%' OR title LIKE '%无4%') THEN 1 ELSE 0 END) as wu4_deals, + SUM(CASE WHEN (content LIKE '%无47%' OR title LIKE '%无47%') AND (content NOT LIKE '%无247%' AND title NOT LIKE '%无247%') THEN 1 ELSE 0 END) as wu47_deals, + SUM(CASE WHEN (content LIKE '%无247%' OR title LIKE '%无247%') AND (content NOT LIKE '%无347%' AND title NOT LIKE '%无347%') THEN 1 ELSE 0 END) as wu247_deals, + SUM(CASE WHEN content LIKE '%无347%' OR title LIKE '%无347%' THEN 1 ELSE 0 END) as wu347_deals + FROM yichen_posts + WHERE created_at >= CURRENT_DATE + AND (category LIKE '%龙%' OR category LIKE '%龙钞%') + AND category NOT LIKE '%求购%' + """)) + deals_row = deals_result.fetchone() + + wants_result = db.execute(text(""" + SELECT + SUM(CASE WHEN content LIKE '%带4%' OR title LIKE '%带4%' THEN 1 ELSE 0 END) as dai4_wants, + SUM(CASE WHEN (content NOT LIKE '%带4%' AND title NOT LIKE '%带4%') AND (content LIKE '%无4%' OR title LIKE '%无4%') THEN 1 ELSE 0 END) as wu4_wants, + SUM(CASE WHEN (content LIKE '%无47%' OR title LIKE '%无47%') AND (content NOT LIKE '%无247%' AND title NOT LIKE '%无247%') THEN 1 ELSE 0 END) as wu47_wants, + SUM(CASE WHEN (content LIKE '%无247%' OR title LIKE '%无247%') AND (content NOT LIKE '%无347%' AND title NOT LIKE '%无347%') THEN 1 ELSE 0 END) as wu247_wants, + SUM(CASE WHEN content LIKE '%无347%' OR title LIKE '%无347%' THEN 1 ELSE 0 END) as wu347_wants + FROM yichen_posts + WHERE created_at >= CURRENT_DATE + AND (category LIKE '%龙%' OR category LIKE '%龙钞%') + AND category LIKE '%求购%' + """)) + wants_row = wants_result.fetchone() + + return { + "dai4": {"total": dai4_count, "deals": deals_row[0] or 0, "wants": wants_row[0] or 0}, + "wu4": {"total": wu4_count, "deals": deals_row[1] or 0, "wants": wants_row[1] or 0}, + "wu47": {"total": wu47_count, "deals": deals_row[2] or 0, "wants": wants_row[2] or 0}, + "wu247": {"total": wu247_count, "deals": deals_row[3] or 0, "wants": wants_row[3] or 0}, + "wu347": {"total": wu347_count, "deals": deals_row[4] or 0, "wants": wants_row[4] or 0} + } diff --git a/frontend/src/pages/Home.jsx b/frontend/src/pages/Home.jsx index e258a7b..8ba57f9 100644 --- a/frontend/src/pages/Home.jsx +++ b/frontend/src/pages/Home.jsx @@ -8,6 +8,7 @@ export default function Home() { const [yichensStats, setYichensStats] = useState({ total: 0, deals: 0, wants: 0, dragons: 0, horses: 0, tianma: 0 }) const [seekStats, setSeekStats] = useState({ seekCount: 0, matchedCount: 0 }) const [recentPosts, setRecentPosts] = useState([]) + const [dragonStats, setDragonStats] = useState({}) const currentPath = window.location.hash.slice(1) || '/' useEffect(() => { @@ -64,6 +65,10 @@ export default function Home() { }).catch(() => {}) // 获取最新一尘帖子 + fetch('/api/yichens/stats/dragons-today').then(res => res.json()).then(data => { + setDragonStats(data || {}) + }).catch(() => {}) + fetch('/api/yichens/posts?limit=10&offset=0').then(res => res.json()).then(data => { setRecentPosts(Array.isArray(data) ? data : []) }).catch(() => {}) @@ -254,6 +259,33 @@ export default function Home() { + {/* 今日龙钞数据 */} +