v1.2.63 - 首页增加今日龙钞数据模块

This commit is contained in:
甲辰生产 2026-04-08 15:20:15 +08:00
parent 47e18948f1
commit d207d6d329
2 changed files with 102 additions and 0 deletions

View File

@ -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}
}

View File

@ -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() {
</div>
</div>
{/* 今日龙钞数据 */}
<div style={{ marginBottom: '20px' }}>
<div style={{ color: 'rgba(255,255,255,0.7)', fontSize: '14px', marginBottom: '12px', paddingLeft: '4px' }}>🐉 今日龙钞数据</div>
<div style={{ display: 'grid', gridTemplateColumns: 'repeat(5, 1fr)', gap: '8px' }}>
<div style={{ background: 'linear-gradient(135deg, rgba(239,68,68,0.15) 0%, rgba(239,68,68,0.05) 100%)', borderRadius: '8px', padding: '10px 6px', border: '1px solid rgba(239,68,68,0.2)', textAlign: 'center' }}>
<div style={{ color: '#ef4444', fontSize: '16px', fontWeight: '700' }}>{dragonStats.dai4?.total || 0}</div>
<div style={{ color: 'rgba(255,255,255,0.5)', fontSize: '10px' }}>带4</div>
</div>
<div style={{ background: 'linear-gradient(135deg, rgba(34,197,94,0.15) 0%, rgba(34,197,94,0.05) 100%)', borderRadius: '8px', padding: '10px 6px', border: '1px solid rgba(34,197,94,0.2)', textAlign: 'center' }}>
<div style={{ color: '#22c55e', fontSize: '16px', fontWeight: '700' }}>{dragonStats.wu4?.total || 0}</div>
<div style={{ color: 'rgba(255,255,255,0.5)', fontSize: '10px' }}>无4</div>
</div>
<div style={{ background: 'linear-gradient(135deg, rgba(59,130,246,0.15) 0%, rgba(59,130,246,0.05) 100%)', borderRadius: '8px', padding: '10px 6px', border: '1px solid rgba(59,130,246,0.2)', textAlign: 'center' }}>
<div style={{ color: '#3b82f6', fontSize: '16px', fontWeight: '700' }}>{dragonStats.wu47?.total || 0}</div>
<div style={{ color: 'rgba(255,255,255,0.5)', fontSize: '10px' }}>无47</div>
</div>
<div style={{ background: 'linear-gradient(135deg, rgba(168,85,247,0.15) 0%, rgba(168,85,247,0.05) 100%)', borderRadius: '8px', padding: '10px 6px', border: '1px solid rgba(168,85,247,0.2)', textAlign: 'center' }}>
<div style={{ color: '#a855f7', fontSize: '16px', fontWeight: '700' }}>{dragonStats.wu247?.total || 0}</div>
<div style={{ color: 'rgba(255,255,255,0.5)', fontSize: '10px' }}>无247</div>
</div>
<div style={{ background: 'linear-gradient(135deg, rgba(236,72,153,0.15) 0%, rgba(236,72,153,0.05) 100%)', borderRadius: '8px', padding: '10px 6px', border: '1px solid rgba(236,72,153,0.2)', textAlign: 'center' }}>
<div style={{ color: '#ec4899', fontSize: '16px', fontWeight: '700' }}>{dragonStats.wu347?.total || 0}</div>
<div style={{ color: 'rgba(255,255,255,0.5)', fontSize: '10px' }}>无347</div>
</div>
</div>
</div>
{/* 最新一尘发帖 */}
<div>
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: '12px', paddingLeft: '4px' }}>